From 100a520020f671eee92e4ff7e80fbe6607ffe44b Mon Sep 17 00:00:00 2001 From: ronso0 Date: Fri, 27 Dec 2024 00:19:25 +0100 Subject: [PATCH] fixup! RateControl/PositionScratchController: use std::unique_ptr, PollingControlProxy etc. --- src/engine/controls/ratecontrol.cpp | 150 ++++++++++++++-------------- src/engine/controls/ratecontrol.h | 39 ++++---- 2 files changed, 97 insertions(+), 92 deletions(-) diff --git a/src/engine/controls/ratecontrol.cpp b/src/engine/controls/ratecontrol.cpp index 163f304bfe14..89daa21a3cf7 100644 --- a/src/engine/controls/ratecontrol.cpp +++ b/src/engine/controls/ratecontrol.cpp @@ -30,72 +30,116 @@ RateControl::RampMode RateControl::m_eRateRampMode; const double RateControl::kWheelMultiplier = 40.0; const double RateControl::kPausedJogMultiplier = 18.0; -RateControl::RateControl(const QString& group, - UserSettingsPointer pConfig) +RateControl::RateControl(const QString& group, UserSettingsPointer pConfig) : EngineControl(group, pConfig), m_pBpmControl(nullptr), - m_pSyncMode(group, QStringLiteral("sync_mode")), - m_pSlipEnabled(group, QStringLiteral("slip_enabled")), + m_pSampleRate(QStringLiteral("[App]"), QStringLiteral("samplerate")), + m_pRateRatio(std::make_unique( + ConfigKey(group, QStringLiteral("rate_ratio")), + true, + false, + false, + 1.0)), + m_pRateDir(std::make_unique( + ConfigKey(group, QStringLiteral("rate_dir")))), + m_pRateRange(std::make_unique( + ConfigKey(group, QStringLiteral("rateRange")), 0.01, 4.00)), // We need the sample rate so we can guesstimate something close // what latency is. - m_pSampleRate(QStringLiteral("[App]"), QStringLiteral("samplerate")), + // Allow rate slider to go out of bounds so that sync lock rate + // adjustments are not capped. + m_pRateSlider(std::make_unique( + ConfigKey(group, QStringLiteral("rate")), -1.0, 1.0, true)), + // Search rate. Rate used when searching in sound. This overrules the + // playback rate + m_pRateSearch(std::make_unique( + ConfigKey(group, QStringLiteral("rateSearch")), -300., 300.)), + // Temporary rate-change buttons + m_pButtonRateTempDown(std::make_unique( + ConfigKey(group, QStringLiteral("rate_temp_down")))), + m_pButtonRateTempDownSmall(std::make_unique( + ConfigKey(group, QStringLiteral("rate_temp_down_small")))), + m_pButtonRateTempUp(std::make_unique( + ConfigKey(group, QStringLiteral("rate_temp_up")))), + m_pButtonRateTempUpSmall(std::make_unique( + ConfigKey(group, QStringLiteral("rate_temp_up_small")))), + // Permanent rate-change buttons + m_pButtonRatePermDown(std::make_unique( + ConfigKey(group, QStringLiteral("rate_perm_down")))), + m_pButtonRatePermDownSmall(std::make_unique( + ConfigKey(group, QStringLiteral("rate_perm_down_small")))), + m_pButtonRatePermUp(std::make_unique( + ConfigKey(group, QStringLiteral("rate_perm_up")))), + m_pButtonRatePermUpSmall(std::make_unique( + ConfigKey(group, QStringLiteral("rate_perm_up_small")))), + // Reverse button + m_pReverseButton(std::make_unique( + ConfigKey(group, QStringLiteral("reverse")))), + m_pReverseRollButton(std::make_unique( + ConfigKey(group, QStringLiteral("reverseroll")))), + m_pForwardButton(std::make_unique( + ConfigKey(group, QStringLiteral("fwd")))), + m_pBackButton(std::make_unique( + ConfigKey(group, QStringLiteral("back")))), + // Wheel to control playback position/speed + m_pWheel(std::make_unique( + ConfigKey(group, QStringLiteral("wheel")))), + // Scratch controller, this is an accumulator which is useful for + // controllers that return individual +1 or -1s, these get added up + // and cleared when we read + m_pScratch2(std::make_unique( + ConfigKey(group, QStringLiteral("scratch2")))), + m_pScratch2Enable(std::make_unique( + ConfigKey(group, QStringLiteral("scratch2_enable")))), + m_pScratch2Scratching(std::make_unique(ConfigKey( + group, QStringLiteral("scratch2_indicates_scratching")))), + m_pScratchController( + std::make_unique(group)), + m_pJog(std::make_unique( + ConfigKey(group, QStringLiteral("jog")))), + m_pJogFilter(std::make_unique()), + // Vinyl control + m_pVCEnabled(ControlObject::getControl(ConfigKey( + getGroup(), QStringLiteral("vinylcontrol_enabled")))), + m_pVCScratching(ControlObject::getControl(ConfigKey( + getGroup(), QStringLiteral("vinylcontrol_scratching")))), + m_pVCMode(ControlObject::getControl( + ConfigKey(getGroup(), QStringLiteral("vinylcontrol_mode")))), + m_pSyncMode(group, QStringLiteral("sync_mode")), + m_pSlipEnabled(group, QStringLiteral("slip_enabled")), m_wrapAroundCount(0), m_jumpPos(mixxx::audio::FramePos()), m_targetPos(mixxx::audio::FramePos()), m_bTempStarted(false), m_tempRateRatio(0.0), m_dRateTempRampChange(0.0) { - m_pScratchController = std::make_unique(group); - // This is the resulting rate ratio that can be used for display or calculations. // The track original rate ratio is 1. - m_pRateRatio = std::make_unique(ConfigKey(group, QStringLiteral("rate_ratio")), - true, - false, - false, - 1.0); connect(m_pRateRatio.get(), &ControlObject::valueChanged, this, &RateControl::slotRateRatioChanged, Qt::DirectConnection); - m_pRateDir = std::make_unique(ConfigKey(group, QStringLiteral("rate_dir"))); connect(m_pRateDir.get(), &ControlObject::valueChanged, this, &RateControl::slotRateRangeChanged, Qt::DirectConnection); - m_pRateRange = std::make_unique( - ConfigKey(group, QStringLiteral("rateRange")), 0.01, 4.00); connect(m_pRateRange.get(), &ControlObject::valueChanged, this, &RateControl::slotRateRangeChanged, Qt::DirectConnection); - // Allow rate slider to go out of bounds so that sync lock rate - // adjustments are not capped. - m_pRateSlider = std::make_unique( - ConfigKey(group, QStringLiteral("rate")), -1.0, 1.0, true); connect(m_pRateSlider.get(), &ControlObject::valueChanged, this, &RateControl::slotRateSliderChanged, Qt::DirectConnection); - // Search rate. Rate used when searching in sound. This overrules the - // playback rate - m_pRateSearch = std::make_unique( - ConfigKey(group, QStringLiteral("rateSearch")), -300., 300.); - - // Reverse button - m_pReverseButton = std::make_unique( - ConfigKey(group, QStringLiteral("reverse"))); m_pReverseButton->set(0); - // Forward button - m_pForwardButton = std::make_unique(ConfigKey(group, QStringLiteral("fwd"))); connect(m_pForwardButton.get(), &ControlObject::valueChanged, this, @@ -103,8 +147,6 @@ RateControl::RateControl(const QString& group, Qt::DirectConnection); m_pForwardButton->set(0); - // Back button - m_pBackButton = std::make_unique(ConfigKey(group, QStringLiteral("back"))); connect(m_pBackButton.get(), &ControlObject::valueChanged, this, @@ -112,89 +154,51 @@ RateControl::RateControl(const QString& group, Qt::DirectConnection); m_pBackButton->set(0); - m_pReverseRollButton = std::make_unique( - ConfigKey(group, QStringLiteral("reverseroll"))); connect(m_pReverseRollButton.get(), &ControlObject::valueChanged, this, &RateControl::slotReverseRollActivate, Qt::DirectConnection); - m_pVCEnabled = ControlObject::getControl( - ConfigKey(getGroup(), QStringLiteral("vinylcontrol_enabled"))); - m_pVCScratching = ControlObject::getControl( - ConfigKey(getGroup(), QStringLiteral("vinylcontrol_scratching"))); - m_pVCMode = ControlObject::getControl( - ConfigKey(getGroup(), QStringLiteral("vinylcontrol_mode"))); - // Permanent rate-change buttons - m_pButtonRatePermDown = - std::make_unique(ConfigKey(group, QStringLiteral("rate_perm_down"))); + m_pButtonRatePermDown->setKbdRepeatable(true); connect(m_pButtonRatePermDown.get(), &ControlObject::valueChanged, this, &RateControl::slotControlRatePermDown, Qt::DirectConnection); - m_pButtonRatePermDown->setKbdRepeatable(true); - m_pButtonRatePermDownSmall = std::make_unique( - ConfigKey(group, QStringLiteral("rate_perm_down_small"))); + m_pButtonRatePermDownSmall->setKbdRepeatable(true); connect(m_pButtonRatePermDownSmall.get(), &ControlObject::valueChanged, this, &RateControl::slotControlRatePermDownSmall, Qt::DirectConnection); - m_pButtonRatePermDownSmall->setKbdRepeatable(true); - m_pButtonRatePermUp = - std::make_unique(ConfigKey(group, QStringLiteral("rate_perm_up"))); + m_pButtonRatePermUp->setKbdRepeatable(true); connect(m_pButtonRatePermUp.get(), &ControlObject::valueChanged, this, &RateControl::slotControlRatePermUp, Qt::DirectConnection); - m_pButtonRatePermUp->setKbdRepeatable(true); - m_pButtonRatePermUpSmall = std::make_unique( - ConfigKey(group, QStringLiteral("rate_perm_up_small"))); + m_pButtonRatePermUpSmall->setKbdRepeatable(true); connect(m_pButtonRatePermUpSmall.get(), &ControlObject::valueChanged, this, &RateControl::slotControlRatePermUpSmall, Qt::DirectConnection); - m_pButtonRatePermUpSmall->setKbdRepeatable(true); - // Temporary rate-change buttons - m_pButtonRateTempDown = - std::make_unique(ConfigKey(group, QStringLiteral("rate_temp_down"))); - m_pButtonRateTempDownSmall = std::make_unique( - ConfigKey(group, QStringLiteral("rate_temp_down_small"))); - m_pButtonRateTempUp = - std::make_unique(ConfigKey(group, QStringLiteral("rate_temp_up"))); - m_pButtonRateTempUpSmall = std::make_unique( - ConfigKey(group, QStringLiteral("rate_temp_up_small"))); - // Wheel to control playback position/speed - m_pWheel = std::make_unique(ConfigKey(group, QStringLiteral("wheel"))); - // Scratch controller, this is an accumulator which is useful for - // controllers that return individual +1 or -1s, these get added up and - // cleared when we read - m_pScratch2 = std::make_unique(ConfigKey(group, QStringLiteral("scratch2"))); // Scratch enable toggle - m_pScratch2Enable = std::make_unique( - ConfigKey(group, QStringLiteral("scratch2_enable"))); m_pScratch2Enable->set(0); - m_pScratch2Scratching = std::make_unique( - ConfigKey(group, QStringLiteral("scratch2_indicates_scratching"))); // Enable by default, because it was always scratching before introducing // this control. m_pScratch2Scratching->set(1.0); - m_pJog = std::make_unique(ConfigKey(group, QStringLiteral("jog"))); - m_pJogFilter = std::make_unique(); // FIXME: This should be dependent on sample rate/block size or something m_pJogFilter->setFilterLength(25); diff --git a/src/engine/controls/ratecontrol.h b/src/engine/controls/ratecontrol.h index 555f7959747f..49a4e723c516 100644 --- a/src/engine/controls/ratecontrol.h +++ b/src/engine/controls/ratecontrol.h @@ -107,11 +107,15 @@ public slots: // Get the 'Raw' Temp Rate double getTempRate(void); - // Values used when temp and perm rate buttons are pressed - static ControlValueAtomic m_dTemporaryRateChangeCoarse; - static ControlValueAtomic m_dTemporaryRateChangeFine; - static ControlValueAtomic m_dPermanentRateChangeCoarse; - static ControlValueAtomic m_dPermanentRateChangeFine; + // For Sync Lock + BpmControl* m_pBpmControl; + + PollingControlProxy m_pSampleRate; + std::unique_ptr m_pRateRatio; + std::unique_ptr m_pRateDir; + std::unique_ptr m_pRateRange; + std::unique_ptr m_pRateSlider; + std::unique_ptr m_pRateSearch; std::unique_ptr m_pButtonRateTempDown; std::unique_ptr m_pButtonRateTempDownSmall; @@ -123,36 +127,33 @@ public slots: std::unique_ptr m_pButtonRatePermUp; std::unique_ptr m_pButtonRatePermUpSmall; - std::unique_ptr m_pRateRatio; - std::unique_ptr m_pRateDir; - std::unique_ptr m_pRateRange; - std::unique_ptr m_pRateSlider; - std::unique_ptr m_pRateSearch; std::unique_ptr m_pReverseButton; std::unique_ptr m_pReverseRollButton; - std::unique_ptr m_pBackButton; std::unique_ptr m_pForwardButton; + std::unique_ptr m_pBackButton; std::unique_ptr m_pWheel; std::unique_ptr m_pScratch2; + std::unique_ptr m_pScratch2Enable; + std::unique_ptr m_pScratch2Scratching; + std::unique_ptr m_pScratchController; - std::unique_ptr m_pScratch2Enable; std::unique_ptr m_pJog; + std::unique_ptr m_pJogFilter; ControlObject* m_pVCEnabled; ControlObject* m_pVCScratching; ControlObject* m_pVCMode; - std::unique_ptr m_pScratch2Scratching; - std::unique_ptr m_pJogFilter; - - // For Sync Lock - BpmControl* m_pBpmControl; - PollingControlProxy m_pSyncMode; PollingControlProxy m_pSlipEnabled; - PollingControlProxy m_pSampleRate; + + // Values used when temp and perm rate buttons are pressed + static ControlValueAtomic m_dTemporaryRateChangeCoarse; + static ControlValueAtomic m_dTemporaryRateChangeFine; + static ControlValueAtomic m_dPermanentRateChangeCoarse; + static ControlValueAtomic m_dPermanentRateChangeFine; int m_wrapAroundCount; mixxx::audio::FramePos m_jumpPos;