Skip to content

Commit

Permalink
fixup! RateControl/PositionScratchController: use std::unique_ptr, Po…
Browse files Browse the repository at this point in the history
…llingControlProxy etc.
  • Loading branch information
ronso0 committed Dec 26, 2024
1 parent 6fa94f7 commit 100a520
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 92 deletions.
150 changes: 77 additions & 73 deletions src/engine/controls/ratecontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,171 +30,175 @@ 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<ControlObject>(
ConfigKey(group, QStringLiteral("rate_ratio")),
true,
false,
false,
1.0)),
m_pRateDir(std::make_unique<ControlObject>(
ConfigKey(group, QStringLiteral("rate_dir")))),
m_pRateRange(std::make_unique<ControlPotmeter>(
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<ControlPotmeter>(
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<ControlPotmeter>(
ConfigKey(group, QStringLiteral("rateSearch")), -300., 300.)),
// Temporary rate-change buttons
m_pButtonRateTempDown(std::make_unique<ControlPushButton>(
ConfigKey(group, QStringLiteral("rate_temp_down")))),
m_pButtonRateTempDownSmall(std::make_unique<ControlPushButton>(
ConfigKey(group, QStringLiteral("rate_temp_down_small")))),
m_pButtonRateTempUp(std::make_unique<ControlPushButton>(
ConfigKey(group, QStringLiteral("rate_temp_up")))),
m_pButtonRateTempUpSmall(std::make_unique<ControlPushButton>(
ConfigKey(group, QStringLiteral("rate_temp_up_small")))),
// Permanent rate-change buttons
m_pButtonRatePermDown(std::make_unique<ControlPushButton>(
ConfigKey(group, QStringLiteral("rate_perm_down")))),
m_pButtonRatePermDownSmall(std::make_unique<ControlPushButton>(
ConfigKey(group, QStringLiteral("rate_perm_down_small")))),
m_pButtonRatePermUp(std::make_unique<ControlPushButton>(
ConfigKey(group, QStringLiteral("rate_perm_up")))),
m_pButtonRatePermUpSmall(std::make_unique<ControlPushButton>(
ConfigKey(group, QStringLiteral("rate_perm_up_small")))),
// Reverse button
m_pReverseButton(std::make_unique<ControlPushButton>(
ConfigKey(group, QStringLiteral("reverse")))),
m_pReverseRollButton(std::make_unique<ControlPushButton>(
ConfigKey(group, QStringLiteral("reverseroll")))),
m_pForwardButton(std::make_unique<ControlPushButton>(
ConfigKey(group, QStringLiteral("fwd")))),
m_pBackButton(std::make_unique<ControlPushButton>(
ConfigKey(group, QStringLiteral("back")))),
// Wheel to control playback position/speed
m_pWheel(std::make_unique<ControlTTRotary>(
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<ControlObject>(
ConfigKey(group, QStringLiteral("scratch2")))),
m_pScratch2Enable(std::make_unique<ControlPushButton>(
ConfigKey(group, QStringLiteral("scratch2_enable")))),
m_pScratch2Scratching(std::make_unique<ControlPushButton>(ConfigKey(
group, QStringLiteral("scratch2_indicates_scratching")))),
m_pScratchController(
std::make_unique<PositionScratchController>(group)),
m_pJog(std::make_unique<ControlObject>(
ConfigKey(group, QStringLiteral("jog")))),
m_pJogFilter(std::make_unique<Rotary>()),
// 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<PositionScratchController>(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<ControlObject>(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<ControlObject>(ConfigKey(group, QStringLiteral("rate_dir")));
connect(m_pRateDir.get(),
&ControlObject::valueChanged,
this,
&RateControl::slotRateRangeChanged,
Qt::DirectConnection);
m_pRateRange = std::make_unique<ControlPotmeter>(
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<ControlPotmeter>(
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<ControlPotmeter>(
ConfigKey(group, QStringLiteral("rateSearch")), -300., 300.);

// Reverse button
m_pReverseButton = std::make_unique<ControlPushButton>(
ConfigKey(group, QStringLiteral("reverse")));
m_pReverseButton->set(0);

// Forward button
m_pForwardButton = std::make_unique<ControlPushButton>(ConfigKey(group, QStringLiteral("fwd")));
connect(m_pForwardButton.get(),
&ControlObject::valueChanged,
this,
&RateControl::slotControlFastForward,
Qt::DirectConnection);
m_pForwardButton->set(0);

// Back button
m_pBackButton = std::make_unique<ControlPushButton>(ConfigKey(group, QStringLiteral("back")));
connect(m_pBackButton.get(),
&ControlObject::valueChanged,
this,
&RateControl::slotControlFastBack,
Qt::DirectConnection);
m_pBackButton->set(0);

m_pReverseRollButton = std::make_unique<ControlPushButton>(
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<ControlPushButton>(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<ControlPushButton>(
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<ControlPushButton>(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<ControlPushButton>(
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<ControlPushButton>(ConfigKey(group, QStringLiteral("rate_temp_down")));
m_pButtonRateTempDownSmall = std::make_unique<ControlPushButton>(
ConfigKey(group, QStringLiteral("rate_temp_down_small")));
m_pButtonRateTempUp =
std::make_unique<ControlPushButton>(ConfigKey(group, QStringLiteral("rate_temp_up")));
m_pButtonRateTempUpSmall = std::make_unique<ControlPushButton>(
ConfigKey(group, QStringLiteral("rate_temp_up_small")));

// Wheel to control playback position/speed
m_pWheel = std::make_unique<ControlTTRotary>(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<ControlObject>(ConfigKey(group, QStringLiteral("scratch2")));

// Scratch enable toggle
m_pScratch2Enable = std::make_unique<ControlPushButton>(
ConfigKey(group, QStringLiteral("scratch2_enable")));
m_pScratch2Enable->set(0);

m_pScratch2Scratching = std::make_unique<ControlPushButton>(
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<ControlObject>(ConfigKey(group, QStringLiteral("jog")));
m_pJogFilter = std::make_unique<Rotary>();
// FIXME: This should be dependent on sample rate/block size or something
m_pJogFilter->setFilterLength(25);

Expand Down
39 changes: 20 additions & 19 deletions src/engine/controls/ratecontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<double> m_dTemporaryRateChangeCoarse;
static ControlValueAtomic<double> m_dTemporaryRateChangeFine;
static ControlValueAtomic<double> m_dPermanentRateChangeCoarse;
static ControlValueAtomic<double> m_dPermanentRateChangeFine;
// For Sync Lock
BpmControl* m_pBpmControl;

PollingControlProxy m_pSampleRate;
std::unique_ptr<ControlObject> m_pRateRatio;
std::unique_ptr<ControlObject> m_pRateDir;
std::unique_ptr<ControlObject> m_pRateRange;
std::unique_ptr<ControlPotmeter> m_pRateSlider;
std::unique_ptr<ControlPotmeter> m_pRateSearch;

std::unique_ptr<ControlPushButton> m_pButtonRateTempDown;
std::unique_ptr<ControlPushButton> m_pButtonRateTempDownSmall;
Expand All @@ -123,36 +127,33 @@ public slots:
std::unique_ptr<ControlPushButton> m_pButtonRatePermUp;
std::unique_ptr<ControlPushButton> m_pButtonRatePermUpSmall;

std::unique_ptr<ControlObject> m_pRateRatio;
std::unique_ptr<ControlObject> m_pRateDir;
std::unique_ptr<ControlObject> m_pRateRange;
std::unique_ptr<ControlPotmeter> m_pRateSlider;
std::unique_ptr<ControlPotmeter> m_pRateSearch;
std::unique_ptr<ControlPushButton> m_pReverseButton;
std::unique_ptr<ControlPushButton> m_pReverseRollButton;
std::unique_ptr<ControlObject> m_pBackButton;
std::unique_ptr<ControlObject> m_pForwardButton;
std::unique_ptr<ControlObject> m_pBackButton;

std::unique_ptr<ControlTTRotary> m_pWheel;
std::unique_ptr<ControlObject> m_pScratch2;
std::unique_ptr<ControlPushButton> m_pScratch2Enable;
std::unique_ptr<ControlObject> m_pScratch2Scratching;

std::unique_ptr<PositionScratchController> m_pScratchController;

std::unique_ptr<ControlPushButton> m_pScratch2Enable;
std::unique_ptr<ControlObject> m_pJog;
std::unique_ptr<Rotary> m_pJogFilter;

ControlObject* m_pVCEnabled;
ControlObject* m_pVCScratching;
ControlObject* m_pVCMode;

std::unique_ptr<ControlObject> m_pScratch2Scratching;
std::unique_ptr<Rotary> 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<double> m_dTemporaryRateChangeCoarse;
static ControlValueAtomic<double> m_dTemporaryRateChangeFine;
static ControlValueAtomic<double> m_dPermanentRateChangeCoarse;
static ControlValueAtomic<double> m_dPermanentRateChangeFine;

int m_wrapAroundCount;
mixxx::audio::FramePos m_jumpPos;
Expand Down

0 comments on commit 100a520

Please sign in to comment.