From 695cee782b730ab2bd540cc7c6bc1e6f544db0b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Sun, 24 Jul 2022 23:43:22 +0200 Subject: [PATCH 1/3] Keep Rubberband Finer selected during testing a Rubberband V2 build --- .../enginebufferscalerubberband.cpp | 1 + .../enginebufferscalerubberband.h | 3 +- src/engine/enginebuffer.cpp | 13 ++---- src/engine/enginebuffer.h | 21 ++++++++- src/preferences/dialog/dlgprefsound.cpp | 44 ++++++++++++------- 5 files changed, 52 insertions(+), 30 deletions(-) diff --git a/src/engine/bufferscalers/enginebufferscalerubberband.cpp b/src/engine/bufferscalers/enginebufferscalerubberband.cpp index 966bde78a594..017ab47318a8 100644 --- a/src/engine/bufferscalers/enginebufferscalerubberband.cpp +++ b/src/engine/bufferscalers/enginebufferscalerubberband.cpp @@ -267,6 +267,7 @@ double EngineBufferScaleRubberBand::scaleBuffer( return framesRead; } +// static bool EngineBufferScaleRubberBand::isEngineFinerAvailable() { return RUBBERBANDV3; } diff --git a/src/engine/bufferscalers/enginebufferscalerubberband.h b/src/engine/bufferscalers/enginebufferscalerubberband.h index 1f9f1ff3c7ad..ec5e2248c888 100644 --- a/src/engine/bufferscalers/enginebufferscalerubberband.h +++ b/src/engine/bufferscalers/enginebufferscalerubberband.h @@ -18,7 +18,8 @@ class EngineBufferScaleRubberBand : public EngineBufferScale { ~EngineBufferScaleRubberBand() override; // Let EngineBuffer know if engine v3 is available - bool isEngineFinerAvailable(); + static bool isEngineFinerAvailable(); + // Enable engine v3 if available void useEngineFiner(bool enable); diff --git a/src/engine/enginebuffer.cpp b/src/engine/enginebuffer.cpp index 063d23c9c6c1..5ea82fc54892 100644 --- a/src/engine/enginebuffer.cpp +++ b/src/engine/enginebuffer.cpp @@ -808,19 +808,12 @@ void EngineBuffer::slotKeylockEngineChanged(double dIndex) { break; case RUBBERBAND_FASTER: default: - if (m_pScaleRB->isEngineFinerAvailable()) { - // trigger reconstruction of RubberBandStretcher with v2 options - m_pScaleRB->useEngineFiner(false); - } + m_pScaleRB->useEngineFiner(false); m_pScaleKeylock = m_pScaleRB; break; case RUBBERBAND_FINER: - if (m_pScaleRB->isEngineFinerAvailable()) { - // trigger reconstruction of RubberBandStretcher with v3 options - m_pScaleRB->useEngineFiner(true); - } else { - m_pKeylockEngine->set(static_cast(RUBBERBAND_FASTER)); - } + m_pScaleRB->useEngineFiner( + true); // in case of Rubberband V2 it falls back to RUBBERBAND_FASTER m_pScaleKeylock = m_pScaleRB; break; } diff --git a/src/engine/enginebuffer.h b/src/engine/enginebuffer.h index f3c2b3ea35fd..551d66cdc055 100644 --- a/src/engine/enginebuffer.h +++ b/src/engine/enginebuffer.h @@ -8,6 +8,7 @@ #include "audio/frame.h" #include "control/controlvalue.h" +#include "engine/bufferscalers/enginebufferscalerubberband.h" #include "engine/cachingreader/cachingreader.h" #include "engine/engineobject.h" #include "engine/sync/syncable.h" @@ -150,9 +151,25 @@ class EngineBuffer : public EngineObject { case RUBBERBAND_FASTER: return tr("Rubberband (better)"); case RUBBERBAND_FINER: - return tr("Rubberband R3 (near-hi-fi quality)"); + if (EngineBufferScaleRubberBand::isEngineFinerAvailable()) { + return tr("Rubberband R3 (near-hi-fi quality)"); + } + [[fallthrough]]; default: - return tr("Unknown (bad value)"); + return tr("Unknown, using Rubberband (better)"); + } + } + + static bool isKeylockEngineAvailable(KeylockEngine engine) { + switch (engine) { + case SOUNDTOUCH: + return true; + case RUBBERBAND_FASTER: + return true; + case RUBBERBAND_FINER: + return EngineBufferScaleRubberBand::isEngineFinerAvailable(); + default: + return false; } } diff --git a/src/preferences/dialog/dlgprefsound.cpp b/src/preferences/dialog/dlgprefsound.cpp index cd0062370db9..a3878f593904 100644 --- a/src/preferences/dialog/dlgprefsound.cpp +++ b/src/preferences/dialog/dlgprefsound.cpp @@ -88,9 +88,11 @@ DlgPrefSound::DlgPrefSound(QWidget* pParent, keylockComboBox->clear(); for (int i = 0; i < EngineBuffer::KEYLOCK_ENGINE_COUNT; ++i) { - keylockComboBox->addItem( - EngineBuffer::getKeylockEngineName( - static_cast(i))); + auto engine = static_cast(i); + if (EngineBuffer::isKeylockEngineAvailable(engine)) { + keylockComboBox->addItem( + EngineBuffer::getKeylockEngineName(engine), i); + } } m_pLatencyCompensation = new ControlProxy("[Master]", "microphoneLatencyCompensation", this); @@ -216,15 +218,6 @@ DlgPrefSound::DlgPrefSound(QWidget* pParent, m_pKeylockEngine = new ControlProxy("[Master]", "keylock_engine", this); - // if EngineBuffer doesn't accept the new engine it resets to RubberBand v2 - m_pKeylockEngine->connectValueChanged( - this, - [this](double value) { - m_pSettings->set(ConfigKey("[Master]", "keylock_engine"), - ConfigValue(value)); - keylockComboBox->setCurrentIndex(static_cast(value)); - }, - Qt::DirectConnection); #ifdef __LINUX__ qDebug() << "RLimit Cur " << RLimit::getCurRtPrio(); @@ -320,9 +313,9 @@ void DlgPrefSound::slotApply() { SoundDeviceError err = SOUNDDEVICE_ERROR_OK; { ScopedWaitCursor cursor; - m_pKeylockEngine->set(keylockComboBox->currentIndex()); + m_pKeylockEngine->set(keylockComboBox->currentData().toDouble()); m_pSettings->set(ConfigKey("[Master]", "keylock_engine"), - ConfigValue(keylockComboBox->currentIndex())); + ConfigValue(keylockComboBox->currentData().toInt())); err = m_pSoundManager->setConfig(m_config); } @@ -506,9 +499,18 @@ void DlgPrefSound::loadSettings(const SoundManagerConfig &config) { } // Default keylock is Rubberband v2 - int keylock_engine = m_pSettings->getValue( - ConfigKey("[Master]", "keylock_engine"), 1); - keylockComboBox->setCurrentIndex(keylock_engine); + int keylock_engine = + m_pSettings->getValue(ConfigKey("[Master]", "keylock_engine"), + static_cast(EngineBuffer::RUBBERBAND_FASTER)); + int index = keylockComboBox->findData(keylock_engine); + if (index >= 0) { + keylockComboBox->setCurrentIndex(index); + } else { + auto engine = static_cast(keylock_engine); + keylockComboBox->addItem( + EngineBuffer::getKeylockEngineName(engine), keylock_engine); + keylockComboBox->setCurrentIndex(keylockComboBox->count() - 1); + } m_loading = false; // DlgPrefSoundItem has it's own inhibit flag @@ -690,6 +692,14 @@ void DlgPrefSound::slotResetToDefaults() { SoundManagerConfig newConfig(m_pSoundManager.get()); newConfig.loadDefaults(m_pSoundManager.get(), SoundManagerConfig::ALL); loadSettings(newConfig); + + int keylock_engine = static_cast(EngineBuffer::RUBBERBAND_FASTER); + int index = keylockComboBox->findData(keylock_engine); + DEBUG_ASSERT(index >= 0); + if (index >= 0) { + keylockComboBox->setCurrentIndex(index); + } + keylockComboBox->setCurrentIndex(EngineBuffer::RUBBERBAND_FASTER); m_pKeylockEngine->set(EngineBuffer::RUBBERBAND_FASTER); From 922ff6b2423b2fe8a38291bb4f0054b1a95b5a0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Wed, 27 Jul 2022 07:40:13 +0200 Subject: [PATCH 2/3] Introduce ngineBuffer::defaultKeylockEngine() for a single source of the default --- src/engine/enginebuffer.cpp | 4 +++- src/engine/enginebuffer.h | 4 ++++ src/engine/enginemaster.cpp | 7 +++---- src/preferences/dialog/dlgprefsound.cpp | 10 ++++------ 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/engine/enginebuffer.cpp b/src/engine/enginebuffer.cpp index 5ea82fc54892..d166615312be 100644 --- a/src/engine/enginebuffer.cpp +++ b/src/engine/enginebuffer.cpp @@ -807,7 +807,6 @@ void EngineBuffer::slotKeylockEngineChanged(double dIndex) { m_pScaleKeylock = m_pScaleST; break; case RUBBERBAND_FASTER: - default: m_pScaleRB->useEngineFiner(false); m_pScaleKeylock = m_pScaleRB; break; @@ -816,6 +815,9 @@ void EngineBuffer::slotKeylockEngineChanged(double dIndex) { true); // in case of Rubberband V2 it falls back to RUBBERBAND_FASTER m_pScaleKeylock = m_pScaleRB; break; + default: + slotKeylockEngineChanged(defaultKeylockEngine()); + break; } } diff --git a/src/engine/enginebuffer.h b/src/engine/enginebuffer.h index 551d66cdc055..f3627e612388 100644 --- a/src/engine/enginebuffer.h +++ b/src/engine/enginebuffer.h @@ -173,6 +173,10 @@ class EngineBuffer : public EngineObject { } } + static KeylockEngine defaultKeylockEngine() { + return RUBBERBAND_FASTER; + } + // Request that the EngineBuffer load a track. Since the process is // asynchronous, EngineBuffer will emit a trackLoaded signal when the load // has completed. diff --git a/src/engine/enginemaster.cpp b/src/engine/enginemaster.cpp index 31a9dc4c054d..ff5d216f4817 100644 --- a/src/engine/enginemaster.cpp +++ b/src/engine/enginemaster.cpp @@ -172,10 +172,9 @@ EngineMaster::EngineMaster( ConfigKey(EngineXfader::kXfaderConfigKey, "xFaderReverse")); m_pXFaderReverse->setButtonMode(ControlPushButton::TOGGLE); - m_pKeylockEngine = new ControlObject(ConfigKey(group, "keylock_engine"), - true, false, true); - m_pKeylockEngine->set(pConfig->getValueString( - ConfigKey(group, "keylock_engine")).toDouble()); + m_pKeylockEngine = new ControlObject(ConfigKey(group, "keylock_engine"), true, false, true); + m_pKeylockEngine->set(pConfig->getValue(ConfigKey(group, "keylock_engine"), + static_cast(EngineBuffer::defaultKeylockEngine()))); // TODO: Make this read only and make EngineMaster decide whether // processing the master mix is necessary. diff --git a/src/preferences/dialog/dlgprefsound.cpp b/src/preferences/dialog/dlgprefsound.cpp index a3878f593904..0050e9e6fb35 100644 --- a/src/preferences/dialog/dlgprefsound.cpp +++ b/src/preferences/dialog/dlgprefsound.cpp @@ -498,10 +498,10 @@ void DlgPrefSound::loadSettings(const SoundManagerConfig &config) { engineClockComboBox->setCurrentIndex(0); } - // Default keylock is Rubberband v2 + // Default keylock engine is Rubberband Faster (v2) int keylock_engine = m_pSettings->getValue(ConfigKey("[Master]", "keylock_engine"), - static_cast(EngineBuffer::RUBBERBAND_FASTER)); + static_cast(EngineBuffer::defaultKeylockEngine())); int index = keylockComboBox->findData(keylock_engine); if (index >= 0) { keylockComboBox->setCurrentIndex(index); @@ -693,15 +693,13 @@ void DlgPrefSound::slotResetToDefaults() { newConfig.loadDefaults(m_pSoundManager.get(), SoundManagerConfig::ALL); loadSettings(newConfig); - int keylock_engine = static_cast(EngineBuffer::RUBBERBAND_FASTER); + int keylock_engine = static_cast(EngineBuffer::defaultKeylockEngine()); int index = keylockComboBox->findData(keylock_engine); DEBUG_ASSERT(index >= 0); if (index >= 0) { keylockComboBox->setCurrentIndex(index); } - - keylockComboBox->setCurrentIndex(EngineBuffer::RUBBERBAND_FASTER); - m_pKeylockEngine->set(EngineBuffer::RUBBERBAND_FASTER); + m_pKeylockEngine->set(keylock_engine); masterMixComboBox->setCurrentIndex(1); m_pMasterEnabled->set(1.0); From 8debe8e50eb64df4be3ecebb2f08ca503adba546 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Wed, 27 Jul 2022 07:43:56 +0200 Subject: [PATCH 3/3] Add a comment about enum KeylockEngine and backward compatibility --- src/engine/enginebuffer.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/engine/enginebuffer.h b/src/engine/enginebuffer.h index f3627e612388..71e3a9424496 100644 --- a/src/engine/enginebuffer.h +++ b/src/engine/enginebuffer.h @@ -75,6 +75,8 @@ class EngineBuffer : public EngineObject { }; Q_DECLARE_FLAGS(SeekRequests, SeekRequest); + // This enum is also used in mixxx.cfg + // Don't remove or swap values to keep backward compatibility enum KeylockEngine { SOUNDTOUCH, RUBBERBAND_FASTER,