Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into effects_refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
daschuer committed Oct 21, 2021
2 parents b8a5f94 + 625cebd commit 7845142
Show file tree
Hide file tree
Showing 66 changed files with 536 additions and 232 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,12 @@ jobs:
BUILDENV_BASEPATH: ${{ matrix.buildenv_basepath }}

- name: "[Ubuntu/macOS] Set compiler cache size limit"
# Set size to 2 GiB
run: ${{ matrix.compiler_cache }} -M 2097152
# A full build without a cache fills the cache with about 300 MB.
# GitHub Actions gives us 5 GB of cache for free.
# 3 operating systems * 2 conditions (Qt5 & Qt6) * 512 MB = 3 GB
# We use a new cache key for every job, so we would run out of
# space frequently if the cache was much bigger.
run: ${{ matrix.compiler_cache }} -M 524288
if: runner.os != 'windows'

- name: "Set up compiler cache"
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
* Add support for m4v files [#4088](https://github.com/mixxxdj/mixxx/pull/4088)
* Adjust ReplayGain: Allow user to update the replaygain value based on a deck pregain value [#4031](https://github.com/mixxxdj/mixxx/pull/4031)
* Automatic analyze and optimize database [#4199](https://github.com/mixxxdj/mixxx/pull/4199)
* Re-import and update metadata after files have been modified when loading tracks [#4218](https://github.com/mixxxdj/mixxx/pull/4218)
* Fix playlists sidebar navigation/activation [#4193](https://github.com/mixxxdj/mixxx/pull/4193) [lp:1939082](https://bugs.launchpad.net/mixxx/+bug/1939082)
* Refactoring of library code
[#2756](https://github.com/mixxxdj/mixxx/pull/2756)
Expand Down
4 changes: 4 additions & 0 deletions res/linux/org.mixxx.Mixxx.metainfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@
Automatic analyze and optimize database
#4199
</li>
<li>
Re-import and update metadata after files have been modified when loading tracks
#4218
</li>
<li>
Fix playlists sidebar navigation/activation
#4193
Expand Down
13 changes: 11 additions & 2 deletions src/analyzer/analyzerbeats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,10 @@ bool AnalyzerBeats::shouldAnalyze(TrackPointer pTrack) const {
if (!pBeats) {
return true;
}
if (!pBeats->getBpm().isValid()) {
if (!pBeats->getBpmInRange(mixxx::audio::kStartFramePos,
mixxx::audio::FramePos{
pTrack->getDuration() * pBeats->getSampleRate()})
.isValid()) {
// Tracks with an invalid bpm <= 0 should be re-analyzed,
// independent of the preference settings. We expect that
// all tracks have a bpm > 0 when analyzed. Users that want
Expand Down Expand Up @@ -230,7 +233,13 @@ void AnalyzerBeats::storeResults(TrackPointer pTrack) {
m_bPreferencesFixedTempo,
m_sampleRate);
qDebug() << "AnalyzerBeats plugin detected" << beats.size()
<< "beats. Average BPM:" << (pBeats ? pBeats->getBpm() : mixxx::Bpm());
<< "beats. Predominant BPM:"
<< (pBeats ? pBeats->getBpmInRange(
mixxx::audio::kStartFramePos,
mixxx::audio::FramePos{
pTrack->getDuration() *
pBeats->getSampleRate()})
: mixxx::Bpm());
} else {
mixxx::Bpm bpm = m_pPlugin->getBpm();
qDebug() << "AnalyzerBeats plugin detected constant BPM: " << bpm;
Expand Down
21 changes: 9 additions & 12 deletions src/analyzer/analyzergain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,11 @@

AnalyzerGain::AnalyzerGain(UserSettingsPointer pConfig)
: m_rgSettings(pConfig),
m_pLeftTempBuffer(nullptr),
m_pRightTempBuffer(nullptr),
m_iBufferSize(0) {
m_pReplayGain = new ReplayGain();
}

AnalyzerGain::~AnalyzerGain() {
delete[] m_pLeftTempBuffer;
delete[] m_pRightTempBuffer;
delete m_pReplayGain;
}

Expand All @@ -40,15 +36,16 @@ bool AnalyzerGain::processSamples(const CSAMPLE *pIn, const int iLen) {

int halfLength = static_cast<int>(iLen / 2);
if (halfLength > m_iBufferSize) {
delete[] m_pLeftTempBuffer;
delete[] m_pRightTempBuffer;
m_pLeftTempBuffer = new CSAMPLE[halfLength];
m_pRightTempBuffer = new CSAMPLE[halfLength];
m_pLeftTempBuffer.resize(halfLength);
m_pRightTempBuffer.resize(halfLength);
}
SampleUtil::deinterleaveBuffer(m_pLeftTempBuffer, m_pRightTempBuffer, pIn, halfLength);
SampleUtil::applyGain(m_pLeftTempBuffer, 32767, halfLength);
SampleUtil::applyGain(m_pRightTempBuffer, 32767, halfLength);
return m_pReplayGain->process(m_pLeftTempBuffer, m_pRightTempBuffer, halfLength);
SampleUtil::deinterleaveBuffer(m_pLeftTempBuffer.data(),
m_pRightTempBuffer.data(),
pIn,
halfLength);
SampleUtil::applyGain(m_pLeftTempBuffer.data(), 32767, halfLength);
SampleUtil::applyGain(m_pRightTempBuffer.data(), 32767, halfLength);
return m_pReplayGain->process(m_pLeftTempBuffer.data(), m_pRightTempBuffer.data(), halfLength);
}

void AnalyzerGain::storeResults(TrackPointer tio) {
Expand Down
6 changes: 4 additions & 2 deletions src/analyzer/analyzergain.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#pragma once

#include <vector>

#include "analyzer/analyzer.h"
#include "preferences/replaygainsettings.h"

Expand All @@ -30,8 +32,8 @@ class AnalyzerGain : public Analyzer {

private:
ReplayGainSettings m_rgSettings;
CSAMPLE* m_pLeftTempBuffer;
CSAMPLE* m_pRightTempBuffer;
std::vector<CSAMPLE> m_pLeftTempBuffer;
std::vector<CSAMPLE> m_pRightTempBuffer;
ReplayGain* m_pReplayGain;
int m_iBufferSize;
};
15 changes: 5 additions & 10 deletions src/effects/backends/lv2/lv2manifest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
LV2Manifest::LV2Manifest(const LilvPlugin* plug,
QHash<QString, LilvNode*>& properties)
: EffectManifest(),
m_minimum(lilv_plugin_get_num_ports(plug)),
m_maximum(lilv_plugin_get_num_ports(plug)),
m_default(lilv_plugin_get_num_ports(plug)),
m_status(AVAILABLE) {
m_pLV2plugin = plug;

Expand All @@ -24,10 +27,8 @@ LV2Manifest::LV2Manifest(const LilvPlugin* plug,
lilv_node_free(info);

int numPorts = lilv_plugin_get_num_ports(plug);
m_minimum = new float[numPorts];
m_maximum = new float[numPorts];
m_default = new float[numPorts];
lilv_plugin_get_port_ranges_float(m_pLV2plugin, m_minimum, m_maximum, m_default);
lilv_plugin_get_port_ranges_float(
m_pLV2plugin, m_minimum.data(), m_maximum.data(), m_default.data());

// Counters to determine the type of the plug in
int inputPorts = 0;
Expand Down Expand Up @@ -153,12 +154,6 @@ LV2Manifest::LV2Manifest(const LilvPlugin* plug,
lilv_nodes_free(features);
}

LV2Manifest::~LV2Manifest() {
delete[] m_minimum;
delete[] m_maximum;
delete[] m_default;
}

QList<int> LV2Manifest::getAudioPortIndices() {
return audioPortIndices;
}
Expand Down
8 changes: 4 additions & 4 deletions src/effects/backends/lv2/lv2manifest.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <lilv/lilv.h>

#include <QSharedPointer>
#include <vector>

#include "effects/backends/effectmanifest.h"
#include "effects/defs.h"
Expand All @@ -17,7 +18,6 @@ class LV2Manifest : public EffectManifest {
};

LV2Manifest(const LilvPlugin* plug, QHash<QString, LilvNode*>& properties);
~LV2Manifest();

QList<int> getAudioPortIndices();
QList<int> getControlPortIndices();
Expand All @@ -40,9 +40,9 @@ class LV2Manifest : public EffectManifest {
QList<int> controlPortIndices;

// Arrays used for storing minimum, maximum and default parameter values
float* m_minimum;
float* m_maximum;
float* m_default;
std::vector<float> m_minimum;
std::vector<float> m_maximum;
std::vector<float> m_default;
Status m_status;
};

Expand Down
28 changes: 9 additions & 19 deletions src/encoder/encoderfdkaac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ EncoderFdkAac::EncoderFdkAac(EncoderCallback* pCallback)
m_pCallback(pCallback),
m_pLibrary(nullptr),
m_pInputFifo(nullptr),
m_pFifoChunkBuffer(nullptr),
m_readRequired(0),
m_aacEnc(),
m_pAacDataBuffer(nullptr),
m_aacInfo(),
m_hasSbr(false) {
// Load the shared library
Expand Down Expand Up @@ -164,8 +162,6 @@ EncoderFdkAac::~EncoderFdkAac() {
kLogger.debug() << "Unloaded libfdk-aac";
}

delete[] m_pAacDataBuffer;
delete[] m_pFifoChunkBuffer;
delete m_pInputFifo;
}

Expand Down Expand Up @@ -283,11 +279,7 @@ int EncoderFdkAac::initEncoder(mixxx::audio::SampleRate sampleRate, QString* pUs
// This initializes the encoder handle but not the encoder itself.
// Actual encoder init is done below.
aacEncOpen(&m_aacEnc, 0, m_channels);
VERIFY_OR_DEBUG_ASSERT(!m_pAacDataBuffer) {
delete[] m_pAacDataBuffer;
m_pAacDataBuffer = nullptr;
}
m_pAacDataBuffer = new unsigned char[kOutBufferBits * m_channels]();
m_pAacDataBuffer.resize(kOutBufferBits * m_channels);

// AAC Object Type: specifies "mode": AAC-LC, HE-AAC, HE-AACv2, DAB AAC, etc...
if (aacEncoder_SetParam(m_aacEnc, AACENC_AOT, m_aacAot) != AACENC_OK) {
Expand Down Expand Up @@ -355,11 +347,7 @@ int EncoderFdkAac::initEncoder(mixxx::audio::SampleRate sampleRate, QString* pUs
}
m_pInputFifo = new FIFO<SAMPLE>(EngineSideChain::SIDECHAIN_BUFFER_SIZE * 2);

VERIFY_OR_DEBUG_ASSERT(!m_pFifoChunkBuffer) {
delete[] m_pFifoChunkBuffer;
m_pFifoChunkBuffer = nullptr;
}
m_pFifoChunkBuffer = new SAMPLE[m_readRequired * sizeof(SAMPLE)]();
m_pFifoChunkBuffer.resize(m_readRequired * sizeof(SAMPLE));
return 0;
}

Expand Down Expand Up @@ -394,12 +382,12 @@ void EncoderFdkAac::encodeBuffer(const CSAMPLE* samples, const int sampleCount)
}

void EncoderFdkAac::processFIFO() {
if (!m_pInputFifo || !m_pFifoChunkBuffer) {
if (!m_pInputFifo || m_pFifoChunkBuffer.empty()) {
return;
}

while (m_pInputFifo->readAvailable() >= m_readRequired) {
m_pInputFifo->read(m_pFifoChunkBuffer, m_readRequired);
m_pInputFifo->read(m_pFifoChunkBuffer.data(), m_readRequired);

// fdk-aac only accept pointers for most buffer settings.
// Declare settings here and point to them below.
Expand All @@ -414,7 +402,8 @@ void EncoderFdkAac::processFIFO() {
// Input Buffer
AACENC_BufDesc inputBuf;
inputBuf.numBufs = 1;
inputBuf.bufs = (void**)&m_pFifoChunkBuffer;
void* chunkBuffer[] = {m_pFifoChunkBuffer.data()};
inputBuf.bufs = chunkBuffer;
inputBuf.bufSizes = &inDataSize;
inputBuf.bufElSizes = &inSampleSize;
inputBuf.bufferIdentifiers = &inDataDescription;
Expand All @@ -426,7 +415,8 @@ void EncoderFdkAac::processFIFO() {
// Output (result) Buffer
AACENC_BufDesc outputBuf;
outputBuf.numBufs = 1;
outputBuf.bufs = (void**)&m_pAacDataBuffer;
void* dataBuffer[] = {m_pAacDataBuffer.data()};
outputBuf.bufs = dataBuffer;
outputBuf.bufSizes = &outDataSize;
outputBuf.bufElSizes = &outElemSize;
outputBuf.bufferIdentifiers = &outDataDescription;
Expand All @@ -445,7 +435,7 @@ void EncoderFdkAac::processFIFO() {
kLogger.warning() << "encoder ignored" << sampleDiff << "samples!";
}

m_pCallback->write(nullptr, m_pAacDataBuffer, 0, outputDesc.numOutBytes);
m_pCallback->write(nullptr, m_pAacDataBuffer.data(), 0, outputDesc.numOutBytes);
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/encoder/encoderfdkaac.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <QLibrary>
#include <QString>
#include <memory>
#include <vector>

#include "encoder/encoder.h"
#include "util/fifo.h"
Expand Down Expand Up @@ -205,10 +206,10 @@ class EncoderFdkAac : public Encoder {
EncoderCallback* m_pCallback;
std::unique_ptr<QLibrary> m_pLibrary;
FIFO<SAMPLE>* m_pInputFifo;
SAMPLE* m_pFifoChunkBuffer;
std::vector<SAMPLE> m_pFifoChunkBuffer;
int m_readRequired;
HANDLE_AACENCODER m_aacEnc;
unsigned char* m_pAacDataBuffer;
std::vector<unsigned char> m_pAacDataBuffer;
AACENC_InfoStruct m_aacInfo;
bool m_hasSbr;
};
13 changes: 9 additions & 4 deletions src/engine/controls/bpmcontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ void BpmControl::adjustBeatsBpm(double deltaBpm) {
return;
}

mixxx::Bpm bpm = pBeats->getBpm();
const mixxx::Bpm bpm = pBeats->getBpmInRange(
mixxx::audio::kStartFramePos, frameInfo().trackEndPosition);
// FIXME: calling bpm.value() without checking bpm.isValid()
const auto centerBpm = mixxx::Bpm(math_max(kBpmAdjustMin, bpm.value() + deltaBpm));
mixxx::Bpm adjustedBpm = BeatUtils::roundBpmWithinRange(
Expand Down Expand Up @@ -956,7 +957,10 @@ void BpmControl::trackLoaded(TrackPointer pNewTrack) {
void BpmControl::trackBeatsUpdated(mixxx::BeatsPointer pBeats) {
if (kLogger.traceEnabled()) {
kLogger.trace() << getGroup() << "BpmControl::trackBeatsUpdated"
<< (pBeats ? pBeats->getBpm() : mixxx::Bpm());
<< (pBeats ? pBeats->getBpmInRange(
mixxx::audio::kStartFramePos,
frameInfo().trackEndPosition)
: mixxx::Bpm());
}
m_pBeats = pBeats;
updateLocalBpm();
Expand Down Expand Up @@ -1009,10 +1013,11 @@ mixxx::Bpm BpmControl::updateLocalBpm() {
mixxx::Bpm prevLocalBpm = mixxx::Bpm(m_pLocalBpm->get());
mixxx::Bpm localBpm;
const mixxx::BeatsPointer pBeats = m_pBeats;
const FrameInfo info = frameInfo();
if (pBeats) {
localBpm = pBeats->getBpmAroundPosition(frameInfo().currentPosition, kLocalBpmSpan);
localBpm = pBeats->getBpmAroundPosition(info.currentPosition, kLocalBpmSpan);
if (!localBpm.isValid()) {
localBpm = pBeats->getBpm();
localBpm = pBeats->getBpmInRange(mixxx::audio::kStartFramePos, info.trackEndPosition);
}
}
if (localBpm != prevLocalBpm) {
Expand Down
2 changes: 1 addition & 1 deletion src/engine/sync/synccontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ void SyncControl::reportPlayerSpeed(double speed, bool scratching) {
mixxx::Bpm SyncControl::fileBpm() const {
mixxx::BeatsPointer pBeats = m_pBeats;
if (pBeats) {
return pBeats->getBpm();
return pBeats->getBpmInRange(mixxx::audio::kStartFramePos, frameInfo().trackEndPosition);
}
return {};
}
Expand Down
4 changes: 4 additions & 0 deletions src/library/autodj/dlgautodj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,3 +388,7 @@ void DlgAutoDJ::shiftTabKeypress() {
QKeyEvent{QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier};
QApplication::sendEvent(this, &backwardFocusKeyEvent);
}

void DlgAutoDJ::setFocus() {
m_pTrackTableView->setFocus();
}
1 change: 1 addition & 0 deletions src/library/autodj/dlgautodj.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class DlgAutoDJ : public QWidget, public Ui::DlgAutoDJ, public LibraryView {

void onShow() override;
bool hasFocus() const override;
void setFocus() override;
void onSearch(const QString& text) override;
void loadSelectedTrack() override;
void loadSelectedTrackToGroup(const QString& group, bool play) override;
Expand Down
1 change: 1 addition & 0 deletions src/library/browse/browsefeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ void BrowseFeature::bindLibraryWidget(WLibrary* libraryWidget,
WLibraryTextBrowser* edit = new WLibraryTextBrowser(libraryWidget);
edit->setHtml(getRootViewHtml());
libraryWidget->registerView("BROWSEHOME", edit);
m_pLibrary->bindFeatureRootView(edit);
}

void BrowseFeature::bindSidebarWidget(WLibrarySidebar* pSidebarWidget) {
Expand Down
5 changes: 4 additions & 1 deletion src/library/dao/trackdao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,10 @@ void bindTrackLibraryValues(
beatsBlob = pBeats->toByteArray();
beatsVersion = pBeats->getVersion();
beatsSubVersion = pBeats->getSubVersion();
bpm = pBeats->getBpm();
const auto trackEndPosition = mixxx::audio::FramePos{
trackMetadata.getStreamInfo().getDuration().toDoubleSeconds() *
pBeats->getSampleRate()};
bpm = pBeats->getBpmInRange(mixxx::audio::kStartFramePos, trackEndPosition);
}
const double bpmValue = bpm.isValid() ? bpm.value() : mixxx::Bpm::kValueUndefined;
pTrackLibraryQuery->bindValue(":bpm", bpmValue);
Expand Down
4 changes: 4 additions & 0 deletions src/library/dlganalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ bool DlgAnalysis::hasFocus() const {
return m_pAnalysisLibraryTableView->hasFocus();
}

void DlgAnalysis::setFocus() {
m_pAnalysisLibraryTableView->setFocus();
}

void DlgAnalysis::onSearch(const QString& text) {
m_pAnalysisLibraryTableModel->search(text);
}
Expand Down
1 change: 1 addition & 0 deletions src/library/dlganalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class DlgAnalysis : public QWidget, public Ui::DlgAnalysis, public virtual Libra
void onSearch(const QString& text) override;
void onShow() override;
bool hasFocus() const override;
void setFocus() override;
void loadSelectedTrack() override;
void loadSelectedTrackToGroup(const QString& group, bool play) override;
void slotAddToAutoDJBottom() override;
Expand Down
Loading

0 comments on commit 7845142

Please sign in to comment.