Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CO Renaming (Pt. 3): Add ControlPotMeter aliasing and move audio_latency_* COs #11998

Merged
merged 11 commits into from
Sep 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1846,6 +1846,7 @@ add_executable(mixxx-test
src/test/controlobjecttest.cpp
src/test/controlobjectaliastest.cpp
src/test/controlobjectscripttest.cpp
src/test/controlpotmetertest.cpp
src/test/coreservicestest.cpp
src/test/coverartcache_test.cpp
src/test/coverartutils_test.cpp
Expand Down
2 changes: 1 addition & 1 deletion res/controllers/Stanton-SCS3m-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ SCS3M.Agent = function(device) {
}

// Light the logo and let it go out to signal an overload
watch("[Master]", 'audio_latency_overload', binarylight(
watch("[App]", 'audio_latency_overload', binarylight(
device.logo.on,
device.logo.off
));
Expand Down
4 changes: 2 additions & 2 deletions res/skins/LateNight/toolbar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,12 @@
<PeakFallTime>100</PeakFallTime>
<PeakFallStep>1</PeakFallStep>
<Connection>
<ConfigKey>[Master],audio_latency_usage</ConfigKey>
<ConfigKey>[App],audio_latency_usage</ConfigKey>
</Connection>
</VuMeter>
</Children>
<Connection>
<ConfigKey>[Master],audio_latency_overload</ConfigKey>
<ConfigKey>[App],audio_latency_overload</ConfigKey>
<BindProperty>highlight</BindProperty>
</Connection>
</WidgetGroup><!-- LatencyMeterBox -->
Expand Down
4 changes: 2 additions & 2 deletions res/skins/Shade/mixer_panel.xml
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@
<PathStatusLight>audio_latency/audio_latency_overload.png</PathStatusLight>
<PathBack>audio_latency/audio_latency_overload_back.png</PathBack>
<Connection>
<ConfigKey>[Master],audio_latency_overload</ConfigKey>
<ConfigKey>[App],audio_latency_overload</ConfigKey>
</Connection>
</StatusLight>

Expand All @@ -537,7 +537,7 @@
<PeakFallStep>1</PeakFallStep>
<Horizontal>true</Horizontal>
<Connection>
<ConfigKey>[Master],audio_latency_usage</ConfigKey>
<ConfigKey>[App],audio_latency_usage</ConfigKey>
</Connection>
</VuMeter>
</Children>
Expand Down
2 changes: 1 addition & 1 deletion res/skins/Tango/topbar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ Description:
<PeakFallTime>100</PeakFallTime>
<PeakFallStep>1</PeakFallStep>
<Connection>
<ConfigKey>[Master],audio_latency_usage</ConfigKey>
<ConfigKey>[App],audio_latency_usage</ConfigKey>
</Connection>
</VuMeter><!-- /latency usage -->
</Children>
Expand Down
140 changes: 62 additions & 78 deletions src/control/controlpotmeter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
#include "control/controlpushbutton.h"
#include "moc_controlpotmeter.cpp"

namespace {

ConfigKey configKeyFromBaseKey(const ConfigKey& key, const QString& suffix) {
return ConfigKey(key.group, QString(key.item) + suffix);
}

} // namespace

ControlPotmeter::ControlPotmeter(const ConfigKey& key,
double dMinValue,
double dMaxValue,
Expand Down Expand Up @@ -58,86 +66,49 @@ void ControlPotmeter::privateValueChanged(double dValue, QObject* pSender) {
}

PotmeterControls::PotmeterControls(const ConfigKey& key)
: m_pControl(new ControlProxy(key, this)),
: m_control(key, this),
// When adding an additional control here, do not forget to also add
// it to the `PotmeterControls::addAlias()` method, too.
m_controlUp(configKeyFromBaseKey(key, QStringLiteral("_up"))),
m_controlDown(configKeyFromBaseKey(key, QStringLiteral("_down"))),
m_controlUpSmall(configKeyFromBaseKey(key, QStringLiteral("_up_small"))),
m_controlDownSmall(configKeyFromBaseKey(key, QStringLiteral("_down_small"))),
m_controlSetDefault(configKeyFromBaseKey(key, QStringLiteral("_set_default"))),
m_controlSetZero(configKeyFromBaseKey(key, QStringLiteral("_set_zero"))),
m_controlSetOne(configKeyFromBaseKey(key, QStringLiteral("_set_one"))),
m_controlSetMinusOne(configKeyFromBaseKey(key, QStringLiteral("_set_minus_one"))),
m_controlToggle(configKeyFromBaseKey(key, QStringLiteral("_toggle"))),
m_controlMinusToggle(configKeyFromBaseKey(key, QStringLiteral("_minus_toggle"))),
m_stepCount(10),
m_smallStepCount(100) {
// These controls are deleted when the ControlPotmeter is since
// PotmeterControls is a member variable of the associated ControlPotmeter
// and the push-button controls are parented to the PotmeterControls.

ControlPushButton* controlUp = new ControlPushButton(
ConfigKey(key.group, QString(key.item) + "_up"));
controlUp->setParent(this);
connect(controlUp,
&ControlPushButton::valueChanged,
this,
&PotmeterControls::incValue);

ControlPushButton* controlDown = new ControlPushButton(
ConfigKey(key.group, QString(key.item) + "_down"));
controlDown->setParent(this);
connect(controlDown,
&ControlPushButton::valueChanged,
this,
&PotmeterControls::decValue);

ControlPushButton* controlUpSmall = new ControlPushButton(
ConfigKey(key.group, QString(key.item) + "_up_small"));
controlUpSmall->setParent(this);
connect(controlUpSmall,
connect(&m_controlUp, &ControlPushButton::valueChanged, this, &PotmeterControls::incValue);
connect(&m_controlDown, &ControlPushButton::valueChanged, this, &PotmeterControls::decValue);
connect(&m_controlUpSmall,
&ControlPushButton::valueChanged,
this,
&PotmeterControls::incSmallValue);

ControlPushButton* controlDownSmall = new ControlPushButton(
ConfigKey(key.group, QString(key.item) + "_down_small"));
controlDownSmall->setParent(this);
connect(controlDownSmall,
connect(&m_controlDownSmall,
&ControlPushButton::valueChanged,
this,
&PotmeterControls::decSmallValue);

m_pControlDefault = new ControlPushButton(
ConfigKey(key.group, QString(key.item) + "_set_default"));
m_pControlDefault->setParent(this);
connect(m_pControlDefault,
connect(&m_controlSetDefault,
&ControlPushButton::valueChanged,
this,
&PotmeterControls::setToDefault);

ControlPushButton* controlZero = new ControlPushButton(
ConfigKey(key.group, QString(key.item) + "_set_zero"));
controlZero->setParent(this);
connect(controlZero,
connect(&m_controlSetZero,
&ControlPushButton::valueChanged,
this,
&PotmeterControls::setToZero);

ControlPushButton* controlOne = new ControlPushButton(
ConfigKey(key.group, QString(key.item) + "_set_one"));
controlOne->setParent(this);
connect(controlOne,
connect(&m_controlSetOne, &ControlPushButton::valueChanged, this, &PotmeterControls::setToOne);
connect(&m_controlSetMinusOne,
&ControlPushButton::valueChanged,
this,
&PotmeterControls::setToOne);

ControlPushButton* controlMinusOne = new ControlPushButton(
ConfigKey(key.group, QString(key.item) + "_set_minus_one"));
controlMinusOne->setParent(this);
connect(controlMinusOne, &ControlPushButton::valueChanged, this, &PotmeterControls::setToMinusOne);

ControlPushButton* controlToggle = new ControlPushButton(
ConfigKey(key.group, QString(key.item) + "_toggle"));
controlToggle->setParent(this);
connect(controlToggle,
&PotmeterControls::setToMinusOne);
connect(&m_controlToggle,
&ControlPushButton::valueChanged,
this,
&PotmeterControls::toggleValue);

ControlPushButton* controlMinusToggle = new ControlPushButton(
ConfigKey(key.group, QString(key.item) + "_minus_toggle"));
controlMinusToggle->setParent(this);
connect(controlMinusToggle,
connect(&m_controlMinusToggle,
&ControlPushButton::valueChanged,
this,
&PotmeterControls::toggleMinusValue);
Expand All @@ -146,76 +117,89 @@ PotmeterControls::PotmeterControls(const ConfigKey& key)
PotmeterControls::~PotmeterControls() {
}

void PotmeterControls::addAlias(const ConfigKey& key) {
m_controlUp.addAlias(configKeyFromBaseKey(key, QStringLiteral("_up")));
m_controlDown.addAlias(configKeyFromBaseKey(key, QStringLiteral("_down")));
m_controlUpSmall.addAlias(configKeyFromBaseKey(key, QStringLiteral("_up_small")));
m_controlDownSmall.addAlias(configKeyFromBaseKey(key, QStringLiteral("_down_small")));
m_controlSetDefault.addAlias(configKeyFromBaseKey(key, QStringLiteral("_set_default")));
m_controlSetZero.addAlias(configKeyFromBaseKey(key, QStringLiteral("_set_zero")));
m_controlSetOne.addAlias(configKeyFromBaseKey(key, QStringLiteral("_set_one")));
m_controlSetMinusOne.addAlias(configKeyFromBaseKey(key, QStringLiteral("_set_minus_one")));
m_controlToggle.addAlias(configKeyFromBaseKey(key, QStringLiteral("_toggle")));
m_controlMinusToggle.addAlias(configKeyFromBaseKey(key, QStringLiteral("_minus_toggle")));
}

void PotmeterControls::incValue(double v) {
if (v > 0) {
double parameter = m_pControl->getParameter();
double parameter = m_control.getParameter();
parameter += 1.0 / m_stepCount;
m_pControl->setParameter(parameter);
m_control.setParameter(parameter);
}
}

void PotmeterControls::decValue(double v) {
if (v > 0) {
double parameter = m_pControl->getParameter();
double parameter = m_control.getParameter();
parameter -= 1.0 / m_stepCount;
m_pControl->setParameter(parameter);
m_control.setParameter(parameter);
}
}

void PotmeterControls::incSmallValue(double v) {
if (v > 0) {
double parameter = m_pControl->getParameter();
double parameter = m_control.getParameter();
parameter += 1.0 / m_smallStepCount;
m_pControl->setParameter(parameter);
m_control.setParameter(parameter);
}
}

void PotmeterControls::decSmallValue(double v) {
if (v > 0) {
double parameter = m_pControl->getParameter();
double parameter = m_control.getParameter();
parameter -= 1.0 / m_smallStepCount;
m_pControl->setParameter(parameter);
m_control.setParameter(parameter);
}
}

void PotmeterControls::setToZero(double v) {
if (v > 0) {
m_pControl->set(0.0);
m_control.set(0.0);
}
}

void PotmeterControls::setToOne(double v) {
if (v > 0) {
m_pControl->set(1.0);
m_control.set(1.0);
}
}

void PotmeterControls::setToMinusOne(double v) {
if (v > 0) {
m_pControl->set(-1.0);
m_control.set(-1.0);
}
}

void PotmeterControls::setToDefault(double v) {
if (v > 0) {
m_pControl->reset();
m_control.reset();
}
}

void PotmeterControls::toggleValue(double v) {
if (v > 0) {
double value = m_pControl->get();
m_pControl->set(value > 0.0 ? 0.0 : 1.0);
double value = m_control.get();
m_control.set(value > 0.0 ? 0.0 : 1.0);
}
}

void PotmeterControls::toggleMinusValue(double v) {
if (v > 0) {
double value = m_pControl->get();
m_pControl->set(value > 0.0 ? -1.0 : 1.0);
double value = m_control.get();
m_control.set(value > 0.0 ? -1.0 : 1.0);
}
}

void PotmeterControls::setIsDefault(bool isDefault) {
m_pControlDefault->forceSet(isDefault ? 1.0 : 0.0);
m_controlSetDefault.forceSet(isDefault ? 1.0 : 0.0);
}
24 changes: 21 additions & 3 deletions src/control/controlpotmeter.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#pragma once

#include "preferences/usersettings.h"
#include "control/controlobject.h"
#include "control/controlproxy.h"
#include "control/controlpushbutton.h"
#include "preferences/usersettings.h"

class ControlPushButton;
class ControlProxy;
Expand All @@ -20,6 +22,8 @@ class PotmeterControls : public QObject {
m_smallStepCount = count;
}

void addAlias(const ConfigKey& key);

public slots:
// Increases the value.
void incValue(double);
Expand All @@ -44,8 +48,17 @@ class PotmeterControls : public QObject {
void setIsDefault(bool isDefault);

private:
ControlProxy* m_pControl;
ControlPushButton* m_pControlDefault;
ControlProxy m_control;
ControlPushButton m_controlUp;
ControlPushButton m_controlDown;
ControlPushButton m_controlUpSmall;
ControlPushButton m_controlDownSmall;
ControlPushButton m_controlSetDefault;
ControlPushButton m_controlSetZero;
ControlPushButton m_controlSetOne;
ControlPushButton m_controlSetMinusOne;
ControlPushButton m_controlToggle;
ControlPushButton m_controlMinusToggle;
int m_stepCount;
double m_smallStepCount;
};
Expand Down Expand Up @@ -73,6 +86,11 @@ class ControlPotmeter : public ControlObject {
// when calling this method
void setRange(double dMinValue, double dMaxValue, bool allowOutOfBounds);

void addAlias(const ConfigKey& key) {
ControlObject::addAlias(key);
m_controls.addAlias(key);
};

private slots:
// Used to check if the current control value matches the default value.
void privateValueChanged(double dValue, QObject* pSender);
Expand Down
15 changes: 12 additions & 3 deletions src/engine/enginemixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

namespace {
const QString kAppGroup = QStringLiteral("[App]");
const QString kLegacyGroup = QStringLiteral("[Master]");
} // namespace

EngineMixer::EngineMixer(
Expand Down Expand Up @@ -81,9 +82,17 @@ EngineMixer::EngineMixer(
m_pMainLatency = new ControlObject(ConfigKey(group, "latency"),
true,
true); // reported latency (sometimes correct)
m_pAudioLatencyOverloadCount = new ControlObject(ConfigKey(group, "audio_latency_overload_count"), true, true);
m_pAudioLatencyUsage = new ControlPotmeter(ConfigKey(group, "audio_latency_usage"), 0.0, 0.25);
m_pAudioLatencyOverload = new ControlPotmeter(ConfigKey(group, "audio_latency_overload"), 0.0, 1.0);
m_pAudioLatencyOverloadCount = new ControlObject(
ConfigKey(kAppGroup, QStringLiteral("audio_latency_overload_count")));
m_pAudioLatencyOverloadCount->addAlias(ConfigKey(
kLegacyGroup, QStringLiteral("audio_latency_overload_count")));
m_pAudioLatencyUsage = new ControlObject(
ConfigKey(kAppGroup, QStringLiteral("audio_latency_usage")));
m_pAudioLatencyUsage->addAlias(ConfigKey(kLegacyGroup, QStringLiteral("audio_latency_usage")));
m_pAudioLatencyOverload = new ControlObject(
ConfigKey(kAppGroup, QStringLiteral("audio_latency_overload")));
m_pAudioLatencyOverload->addAlias(
ConfigKey(kLegacyGroup, QStringLiteral("audio_latency_overload")));

// Sync controller
m_pEngineSync = new EngineSync(pConfig);
Expand Down
4 changes: 2 additions & 2 deletions src/engine/enginemixer.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,8 @@ class EngineMixer : public QObject, public AudioSource {
ControlObject* m_pMainSampleRate;
ControlObject* m_pMainLatency;
ControlObject* m_pAudioLatencyOverloadCount;
ControlPotmeter* m_pAudioLatencyUsage;
ControlPotmeter* m_pAudioLatencyOverload;
ControlObject* m_pAudioLatencyUsage;
ControlObject* m_pAudioLatencyOverload;
EngineTalkoverDucking* m_pTalkoverDucking;
EngineDelay* m_pMainDelay;
EngineDelay* m_pHeadDelay;
Expand Down
6 changes: 3 additions & 3 deletions src/preferences/dialog/dlgprefsound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,9 @@ DlgPrefSound::DlgPrefSound(QWidget* pParent,
loadSettings();
});

m_pMainAudioLatencyOverloadCount =
new ControlProxy("[Master]", "audio_latency_overload_count", this);
m_pMainAudioLatencyOverloadCount->connectValueChanged(this, &DlgPrefSound::bufferUnderflow);
m_pAudioLatencyOverloadCount =
new ControlProxy(kAppGroup, QStringLiteral("audio_latency_overload_count"), this);
m_pAudioLatencyOverloadCount->connectValueChanged(this, &DlgPrefSound::bufferUnderflow);

m_pMainLatency = new ControlProxy("[Master]", "latency", this);
m_pMainLatency->connectValueChanged(this, &DlgPrefSound::mainLatencyChanged);
Expand Down
Loading