From a6dbdc003956ea3ca74a8098f08df0e7edaff575 Mon Sep 17 00:00:00 2001 From: Michael Gregorius Date: Tue, 24 Dec 2024 15:20:06 +0100 Subject: [PATCH] Let users enter values in dB Let users enter values in dB in the dialog that opens with a double click. The minimum value that can be entered is the minimum value that the fader allows to set, i.e. -120 dB. The maximum value is the maximum value of the model converted to dB. As of now this is ~6 dB. The current value is converted to dB. If it corresponds to "-inf dB", i.e. if the amplification is 0 then the minimum value is used. --- src/gui/widgets/Fader.cpp | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/src/gui/widgets/Fader.cpp b/src/gui/widgets/Fader.cpp index 602fc79e1..b0fc24076 100644 --- a/src/gui/widgets/Fader.cpp +++ b/src/gui/widgets/Fader.cpp @@ -160,16 +160,36 @@ void Fader::mousePressEvent(QMouseEvent* mouseEvent) void Fader::mouseDoubleClickEvent(QMouseEvent* mouseEvent) { bool ok; - // TODO: dbFS handling - auto minv = model()->minValue() * m_conversionFactor; - auto maxv = model()->maxValue() * m_conversionFactor; - float enteredValue = QInputDialog::getDouble(this, tr("Set value"), - tr("Please enter a new value between %1 and %2:").arg(minv).arg(maxv), - model()->getRoundedValue() * m_conversionFactor, minv, maxv, model()->getDigitCount(), &ok); - if (ok) + if (modelIsLinear()) { - model()->setValue(enteredValue / m_conversionFactor); + auto minDB = m_faderMinDb; + auto maxDB = ampToDbfs(model()->maxValue()); + const auto currentValue = model()->value() <= 0. ? m_faderMinDb : ampToDbfs(model()->value()); + + float enteredValue = QInputDialog::getDouble(this, tr("Set value"), + tr("Please enter a new value between %1 and %2:").arg(minDB).arg(maxDB), + currentValue, minDB, maxDB, model()->getDigitCount(), &ok); + + if (ok) + { + model()->setValue(dbfsToAmp(enteredValue)); + } + return; + } + else + { + // The model already is in dB + auto minv = model()->minValue() * m_conversionFactor; + auto maxv = model()->maxValue() * m_conversionFactor; + float enteredValue = QInputDialog::getDouble(this, tr("Set value"), + tr("Please enter a new value between %1 and %2:").arg(minv).arg(maxv), + model()->getRoundedValue() * m_conversionFactor, minv, maxv, model()->getDigitCount(), &ok); + + if (ok) + { + model()->setValue(enteredValue / m_conversionFactor); + } } }