Skip to content

Commit

Permalink
RateControl/PositionScratchController: use std::unique_ptr, PollingCo…
Browse files Browse the repository at this point in the history
…ntrolProxy etc.
  • Loading branch information
ronso0 committed Dec 26, 2024
1 parent 70d7999 commit 6fa94f7
Show file tree
Hide file tree
Showing 4 changed files with 301 additions and 253 deletions.
205 changes: 102 additions & 103 deletions src/engine/controls/ratecontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,138 +34,167 @@ 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")),
// We need the sample rate so we can guesstimate something close
// what latency is.
m_pSampleRate(QStringLiteral("[App]"), QStringLiteral("samplerate")),
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 = new PositionScratchController(group);
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 = new ControlObject(ConfigKey(group, "rate_ratio"),
true, false, false, 1.0);
connect(m_pRateRatio, &ControlObject::valueChanged,
this, &RateControl::slotRateRatioChanged,
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 = new ControlObject(ConfigKey(group, "rate_dir"));
connect(m_pRateDir, &ControlObject::valueChanged,
this, &RateControl::slotRateRangeChanged,
m_pRateDir = std::make_unique<ControlObject>(ConfigKey(group, QStringLiteral("rate_dir")));
connect(m_pRateDir.get(),
&ControlObject::valueChanged,
this,
&RateControl::slotRateRangeChanged,
Qt::DirectConnection);
m_pRateRange = new ControlPotmeter(
ConfigKey(group, "rateRange"), 0.01, 4.00);
connect(m_pRateRange, &ControlObject::valueChanged,
this, &RateControl::slotRateRangeChanged,
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 = new ControlPotmeter(
ConfigKey(group, "rate"), -1.0, 1.0, true);
connect(m_pRateSlider, &ControlObject::valueChanged,
this, &RateControl::slotRateSliderChanged,
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 = new ControlPotmeter(ConfigKey(group, "rateSearch"), -300., 300.);
m_pRateSearch = std::make_unique<ControlPotmeter>(
ConfigKey(group, QStringLiteral("rateSearch")), -300., 300.);

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

// Forward button
m_pForwardButton = new ControlPushButton(ConfigKey(group, "fwd"));
connect(m_pForwardButton, &ControlObject::valueChanged,
this, &RateControl::slotControlFastForward,
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 = new ControlPushButton(ConfigKey(group, "back"));
connect(m_pBackButton, &ControlObject::valueChanged,
this, &RateControl::slotControlFastBack,
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 = new ControlPushButton(ConfigKey(group, "reverseroll"));
connect(m_pReverseRollButton, &ControlObject::valueChanged,
this, &RateControl::slotReverseRollActivate,
m_pReverseRollButton = std::make_unique<ControlPushButton>(
ConfigKey(group, QStringLiteral("reverseroll")));
connect(m_pReverseRollButton.get(),
&ControlObject::valueChanged,
this,
&RateControl::slotReverseRollActivate,
Qt::DirectConnection);

m_pSlipEnabled = new ControlProxy(group, "slip_enabled", this);

m_pVCEnabled = ControlObject::getControl(ConfigKey(getGroup(), "vinylcontrol_enabled"));
m_pVCScratching = ControlObject::getControl(ConfigKey(getGroup(), "vinylcontrol_scratching"));
m_pVCMode = ControlObject::getControl(ConfigKey(getGroup(), "vinylcontrol_mode"));
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 =
new ControlPushButton(ConfigKey(group,"rate_perm_down"));
connect(m_pButtonRatePermDown, &ControlObject::valueChanged,
this, &RateControl::slotControlRatePermDown,
std::make_unique<ControlPushButton>(ConfigKey(group, QStringLiteral("rate_perm_down")));
connect(m_pButtonRatePermDown.get(),
&ControlObject::valueChanged,
this,
&RateControl::slotControlRatePermDown,
Qt::DirectConnection);
m_pButtonRatePermDown->setKbdRepeatable(true);

m_pButtonRatePermDownSmall =
new ControlPushButton(ConfigKey(group,"rate_perm_down_small"));
connect(m_pButtonRatePermDownSmall, &ControlObject::valueChanged,
this, &RateControl::slotControlRatePermDownSmall,
m_pButtonRatePermDownSmall = std::make_unique<ControlPushButton>(
ConfigKey(group, QStringLiteral("rate_perm_down_small")));
connect(m_pButtonRatePermDownSmall.get(),
&ControlObject::valueChanged,
this,
&RateControl::slotControlRatePermDownSmall,
Qt::DirectConnection);
m_pButtonRatePermDownSmall->setKbdRepeatable(true);

m_pButtonRatePermUp =
new ControlPushButton(ConfigKey(group,"rate_perm_up"));
connect(m_pButtonRatePermUp, &ControlObject::valueChanged,
this, &RateControl::slotControlRatePermUp,
std::make_unique<ControlPushButton>(ConfigKey(group, QStringLiteral("rate_perm_up")));
connect(m_pButtonRatePermUp.get(),
&ControlObject::valueChanged,
this,
&RateControl::slotControlRatePermUp,
Qt::DirectConnection);
m_pButtonRatePermUp->setKbdRepeatable(true);

m_pButtonRatePermUpSmall =
new ControlPushButton(ConfigKey(group,"rate_perm_up_small"));
connect(m_pButtonRatePermUpSmall, &ControlObject::valueChanged,
this, &RateControl::slotControlRatePermUpSmall,
m_pButtonRatePermUpSmall = std::make_unique<ControlPushButton>(
ConfigKey(group, QStringLiteral("rate_perm_up_small")));
connect(m_pButtonRatePermUpSmall.get(),
&ControlObject::valueChanged,
this,
&RateControl::slotControlRatePermUpSmall,
Qt::DirectConnection);
m_pButtonRatePermUpSmall->setKbdRepeatable(true);

// Temporary rate-change buttons
m_pButtonRateTempDown =
new ControlPushButton(ConfigKey(group,"rate_temp_down"));
m_pButtonRateTempDownSmall =
new ControlPushButton(ConfigKey(group,"rate_temp_down_small"));
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 =
new ControlPushButton(ConfigKey(group,"rate_temp_up"));
m_pButtonRateTempUpSmall =
new ControlPushButton(ConfigKey(group,"rate_temp_up_small"));

// We need the sample rate so we can guesstimate something close
// what latency is.
m_pSampleRate = ControlObject::getControl(
ConfigKey(QStringLiteral("[App]"), QStringLiteral("samplerate")));
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 = new ControlTTRotary(ConfigKey(group, "wheel"));
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 = new ControlObject(ConfigKey(group, "scratch2"));
m_pScratch2 = std::make_unique<ControlObject>(ConfigKey(group, QStringLiteral("scratch2")));

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

m_pScratch2Scratching = new ControlPushButton(ConfigKey(group,
"scratch2_indicates_scratching"));
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 = new ControlObject(ConfigKey(group, "jog"));
m_pJogFilter = new Rotary();
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 All @@ -178,40 +207,6 @@ RateControl::RateControl(const QString& group,
// // Set the Sensitivity
// m_iRateRampSensitivity =
// getConfig()->getValueString(ConfigKey("[Controls]","RateRampSensitivity")).toInt();

m_pSyncMode = new ControlProxy(group, "sync_mode", this);
}

RateControl::~RateControl() {
delete m_pRateRatio;
delete m_pRateSlider;
delete m_pRateRange;
delete m_pRateDir;
delete m_pSyncMode;

delete m_pRateSearch;

delete m_pReverseButton;
delete m_pReverseRollButton;
delete m_pForwardButton;
delete m_pBackButton;

delete m_pButtonRateTempDown;
delete m_pButtonRateTempDownSmall;
delete m_pButtonRateTempUp;
delete m_pButtonRateTempUpSmall;
delete m_pButtonRatePermDown;
delete m_pButtonRatePermDownSmall;
delete m_pButtonRatePermUp;
delete m_pButtonRatePermUpSmall;

delete m_pWheel;
delete m_pScratch2;
delete m_pScratch2Scratching;
delete m_pScratch2Enable;
delete m_pJog;
delete m_pJogFilter;
delete m_pScratchController;
}

void RateControl::setBpmControl(BpmControl* bpmcontrol) {
Expand Down Expand Up @@ -304,11 +299,11 @@ void RateControl::slotRateRatioChanged(double v) {

void RateControl::slotReverseRollActivate(double v) {
if (v > 0.0) {
m_pSlipEnabled->set(1);
m_pSlipEnabled.set(1);
m_pReverseButton->set(1);
} else {
m_pReverseButton->set(0);
m_pSlipEnabled->set(0);
m_pSlipEnabled.set(0);
}
}

Expand Down Expand Up @@ -391,7 +386,7 @@ double RateControl::getJogFactor() const {
}

SyncMode RateControl::getSyncMode() const {
return syncModeFromDouble(m_pSyncMode->get());
return syncModeFromDouble(m_pSyncMode.get());
}

double RateControl::calculateSpeed(double baserate, double speed, bool paused,
Expand Down Expand Up @@ -555,7 +550,7 @@ void RateControl::processTempRate(const int bufferSamples) {
} else if (m_eRateRampMode == RampMode::Linear) {
if (!m_bTempStarted) {
m_bTempStarted = true;
double latrate = bufferSamples / m_pSampleRate->get();
double latrate = bufferSamples / m_pSampleRate.get();
m_dRateTempRampChange = latrate / (m_iRateRampSensitivity / 100.0);
}

Expand Down Expand Up @@ -628,3 +623,7 @@ void RateControl::notifyWrapAround(mixxx::audio::FramePos triggerPos,
m_jumpPos = triggerPos;
m_targetPos = targetPos;
}

void RateControl::notifySeek(mixxx::audio::FramePos position) {
m_pScratchController->notifySeek(position);
}
Loading

0 comments on commit 6fa94f7

Please sign in to comment.