Skip to content

Commit

Permalink
Pref ReplayGain overhaul, only apply in slotApply()
Browse files Browse the repository at this point in the history
  • Loading branch information
ronso0 committed May 29, 2024
1 parent 8bb022e commit b8c9f83
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 83 deletions.
109 changes: 36 additions & 73 deletions src/preferences/dialog/dlgprefreplaygain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,22 @@ DlgPrefReplayGain::DlgPrefReplayGain(QWidget* parent, UserSettingsPointer pConfi
m_enabled(kConfigKey, kReplayGainEnabled) {
setupUi(this);

m_analysisButtonGroup.addButton(radioButtonRG1);
m_analysisButtonGroup.addButton(radioButtonRG2);
m_analysisButtonGroup.addButton(radioButtonDisable);

connect(EnableGain, &QCheckBox::stateChanged, this, &DlgPrefReplayGain::slotSetRGEnabled);
connect(&m_analysisButtonGroup,
connect(EnableGain,
&QCheckBox::stateChanged,
this,
&DlgPrefReplayGain::slotRGEnabledChanged);
connect(buttonGroupAnalyzer,
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
&QButtonGroup::idClicked,
#else
QOverload<int>::of(&QButtonGroup::buttonClicked),
#endif
this,
&DlgPrefReplayGain::slotSetRGAnalyzerChanged);
&DlgPrefReplayGain::slotRGAnalyzerChanged);
connect(SliderReplayGainBoost,
&QAbstractSlider::valueChanged,
this,
&DlgPrefReplayGain::slotUpdateReplayGainBoost);
&DlgPrefReplayGain::slotReplayGainBoostChanged);
connect(SliderReplayGainBoost,
&QAbstractSlider::sliderReleased,
this,
Expand All @@ -45,62 +44,64 @@ DlgPrefReplayGain::DlgPrefReplayGain(QWidget* parent, UserSettingsPointer pConfi
connect(SliderDefaultBoost,
&QAbstractSlider::valueChanged,
this,
&DlgPrefReplayGain::slotUpdateDefaultBoost);
&DlgPrefReplayGain::slotDefaultBoostChanged);
connect(SliderDefaultBoost,
&QAbstractSlider::sliderReleased,
this,
&DlgPrefReplayGain::slotApply);
setScrollSafeGuard(SliderDefaultBoost);

connect(checkBoxReanalyze,
&QCheckBox::stateChanged,
this,
&DlgPrefReplayGain::slotSetReanalyze);

loadSettings();
}

DlgPrefReplayGain::~DlgPrefReplayGain() {
}

void DlgPrefReplayGain::loadSettings() {
void DlgPrefReplayGain::slotUpdate() {
bool enabled = m_rgSettings.getReplayGainEnabled();
EnableGain->setChecked(enabled);
slotRGEnabledChanged(enabled);

int iReplayGainBoost = m_rgSettings.getInitialReplayGainBoost();
SliderReplayGainBoost->setValue(iReplayGainBoost);
setLabelCurrentReplayGainBoost(iReplayGainBoost);


int iDefaultBoost = m_rgSettings.getInitialDefaultBoost();
SliderDefaultBoost->setValue(iDefaultBoost);
LabelCurrentDefaultBoost->setText(
QString("%1 dB").arg(iDefaultBoost));

bool gainEnabled = m_rgSettings.getReplayGainEnabled();
EnableGain->setChecked(gainEnabled);
slotDefaultBoostChanged(iDefaultBoost);

bool analyzerEnabled = m_rgSettings.getReplayGainAnalyzerEnabled();
int version = m_rgSettings.getReplayGainAnalyzerVersion();

if (!analyzerEnabled) {
radioButtonDisable->setChecked(true);
} else if (version == 1) {
radioButtonRG1->setChecked(true);
} else {
radioButtonRG2->setChecked(true);
}

checkBoxReanalyze->setEnabled(analyzerEnabled);

bool reanalyse = m_rgSettings.getReplayGainReanalyze();
checkBoxReanalyze->setChecked(reanalyse);
}

void DlgPrefReplayGain::slotApply() {
m_rgSettings.setReplayGainEnabled(EnableGain->isChecked());
m_enabled.set(EnableGain->isChecked() ? 1.0 : 0.0);

slotUpdate();
slotUpdateReplayGainBoost();
slotUpdateDefaultBoost();
double replayGainBoostDb = SliderReplayGainBoost->value();
m_replayGainBoost.set(db2ratio(replayGainBoostDb));
double defaultBoostDb = SliderDefaultBoost->value();
m_defaultBoost.set(db2ratio(defaultBoostDb));

m_rgSettings.setReplayGainAnalyzerEnabled(isReplayGainAnalyzerEnabled());
m_rgSettings.setReplayGainAnalyzerVersion(getReplayGainVersion());
m_rgSettings.setInitialReplayGainBoost(SliderReplayGainBoost->value());
m_rgSettings.setInitialDefaultBoost(SliderDefaultBoost->value());
m_rgSettings.setReplayGainReanalyze(checkBoxReanalyze->isChecked());
}

void DlgPrefReplayGain::slotResetToDefaults() {
EnableGain->setChecked(true);
// Turn ReplayGain Analyzer on by default as it does not give appreciable
// Turn ReplayGain Analyzer on by default as it does not give noticeable
// delay on recent hardware (<5 years old).
radioButtonRG2->setChecked(true);
checkBoxReanalyze->setChecked(false);
Expand All @@ -114,16 +115,11 @@ void DlgPrefReplayGain::slotResetToDefaults() {
SliderDefaultBoost->setValue(iDefaultBoost);
LabelCurrentDefaultBoost->setText(
QString("%1 dB").arg(iDefaultBoost));


slotUpdate();
slotApply();
}

void DlgPrefReplayGain::slotSetRGEnabled() {
m_rgSettings.setReplayGainEnabled(EnableGain->isChecked());
slotUpdate();
slotApply();
void DlgPrefReplayGain::slotRGEnabledChanged(bool enabled) {
SliderReplayGainBoost->setEnabled(enabled);
SliderDefaultBoost->setEnabled(enabled);
}

bool DlgPrefReplayGain::isReplayGainAnalyzerEnabled() const {
Expand All @@ -137,18 +133,12 @@ int DlgPrefReplayGain::getReplayGainVersion() const {
return 2;
}

void DlgPrefReplayGain::slotSetRGAnalyzerChanged() {
m_rgSettings.setReplayGainAnalyzerEnabled(isReplayGainAnalyzerEnabled());
void DlgPrefReplayGain::slotRGAnalyzerChanged() {
checkBoxReanalyze->setEnabled(isReplayGainAnalyzerEnabled());
m_rgSettings.setReplayGainAnalyzerVersion(getReplayGainVersion());
slotApply();
}

void DlgPrefReplayGain::slotUpdateReplayGainBoost() {
int value = SliderReplayGainBoost->value();
m_rgSettings.setInitialReplayGainBoost(value);
void DlgPrefReplayGain::slotReplayGainBoostChanged(int value) {
setLabelCurrentReplayGainBoost(value);
slotApply();
}

void DlgPrefReplayGain::setLabelCurrentReplayGainBoost(int value) {
Expand All @@ -159,34 +149,7 @@ void DlgPrefReplayGain::setLabelCurrentReplayGainBoost(int value) {
QString::number(value)));
}

void DlgPrefReplayGain::slotUpdateDefaultBoost() {
int value = SliderDefaultBoost->value();
m_rgSettings.setInitialDefaultBoost(value);
void DlgPrefReplayGain::slotDefaultBoostChanged(int value) {
LabelCurrentDefaultBoost->setText(
QString("%1 dB").arg(value));
slotApply();
}

void DlgPrefReplayGain::slotUpdate() {
if (m_rgSettings.getReplayGainEnabled()) {
SliderReplayGainBoost->setEnabled(true);
SliderDefaultBoost->setEnabled(true);
} else {
SliderReplayGainBoost->setEnabled(false);
SliderDefaultBoost->setEnabled(false);
}
}

void DlgPrefReplayGain::slotApply() {
double replayGainBoostDb = SliderReplayGainBoost->value();
m_replayGainBoost.set(db2ratio(replayGainBoostDb));
double defaultBoostDb = SliderDefaultBoost->value();
m_defaultBoost.set(db2ratio(defaultBoostDb));
m_enabled.set(EnableGain->isChecked() ? 1.0 : 0.0);
}

void DlgPrefReplayGain::slotSetReanalyze() {
bool checked = checkBoxReanalyze->isChecked();
m_rgSettings.setReplayGainReanalyze(checked);
slotApply();
}
14 changes: 4 additions & 10 deletions src/preferences/dialog/dlgprefreplaygain.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ class DlgPrefReplayGain: public DlgPreferencePage,
virtual ~DlgPrefReplayGain();

public slots:
// Update initial gain increment
void slotUpdateReplayGainBoost();
void slotUpdateDefaultBoost();
void slotSetRGEnabled();
void slotSetRGAnalyzerChanged();
void slotSetReanalyze();
void slotReplayGainBoostChanged(int value);
void slotDefaultBoostChanged(int value);
void slotRGEnabledChanged(bool enabled);
void slotRGAnalyzerChanged();

void slotApply() override;
void slotUpdate() override;
Expand All @@ -32,8 +30,6 @@ class DlgPrefReplayGain: public DlgPreferencePage,
void apply(const QString &);

private:
// Determines whether or not to gray out the preferences
void loadSettings();
void setLabelCurrentReplayGainBoost(int value);
bool isReplayGainAnalyzerEnabled() const;
int getReplayGainVersion() const;
Expand All @@ -42,6 +38,4 @@ class DlgPrefReplayGain: public DlgPreferencePage,
PollingControlProxy m_replayGainBoost;
PollingControlProxy m_defaultBoost;
PollingControlProxy m_enabled;

QButtonGroup m_analysisButtonGroup;
};
21 changes: 21 additions & 0 deletions src/preferences/dialog/dlgprefreplaygaindlg.ui
Original file line number Diff line number Diff line change
Expand Up @@ -231,20 +231,29 @@
<property name="text">
<string>ReplayGain 2.0 (ITU-R BS.1770)</string>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroupAnalyzer</string>
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButtonRG1">
<property name="text">
<string>ReplayGain 1.0</string>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroupAnalyzer</string>
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButtonDisable">
<property name="text">
<string>Disabled</string>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroupAnalyzer</string>
</attribute>
</widget>
</item>
<item>
Expand Down Expand Up @@ -307,6 +316,18 @@ The loudness target is approximate and assumes track pregain and main output lev
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
<tabstops>
<tabstop>EnableGain</tabstop>
<tabstop>SliderReplayGainBoost</tabstop>
<tabstop>SliderDefaultBoost</tabstop>
<tabstop>radioButtonRG1</tabstop>
<tabstop>radioButtonRG2</tabstop>
<tabstop>radioButtonDisable</tabstop>
<tabstop>checkBoxReanalyze</tabstop>
</tabstops>
<resources/>
<connections/>
<buttongroups>
<buttongroup name="buttonGroupAnalyzer"/>
</buttongroups>
</ui>

0 comments on commit b8c9f83

Please sign in to comment.