From 1f9f96deeb3f57a3c2f21969dd459619dbb7269b Mon Sep 17 00:00:00 2001 From: Michael Gregorius Date: Tue, 24 Dec 2024 20:38:32 +0100 Subject: [PATCH] Adjust the wheel behavior for faders with dB models Make the faders of the Crossover Equalizer, Equalizer, Compressor and Delay behave like the mixer faders, i.e. step in sizes of 3 dB, 1dB and 0.1 dB depending on whether a modifier key is pressed or not. Extract some common code to do so and add some `const` keywords. --- src/gui/widgets/Fader.cpp | 44 ++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/src/gui/widgets/Fader.cpp b/src/gui/widgets/Fader.cpp index 9c94a1942..6d224c8fe 100644 --- a/src/gui/widgets/Fader.cpp +++ b/src/gui/widgets/Fader.cpp @@ -214,9 +214,26 @@ void Fader::wheelEvent (QWheelEvent* ev) { const int direction = (ev->angleDelta().y() > 0 ? 1 : -1) * (ev->inverted() ? -1 : 1); + float incrementValue = 1.; + + auto const modKeys = ev->modifiers(); + if (modKeys == Qt::ShiftModifier) + { + // The shift is intended to go through the values in very coarse steps as in: + // "Shift into overdrive" + incrementValue = 3.; + } + else if (modKeys == Qt::ControlModifier) + { + // The control key gives more control, i.e. it enables more fine-grained adjustments + incrementValue = 0.1; + } + + const float increment = incrementValue * direction; + if (modelIsLinear()) { - auto value = model()->value(); + const auto value = model()->value(); if (value <= 0.) { @@ -230,33 +247,18 @@ void Fader::wheelEvent (QWheelEvent* ev) else { // We can safely compute the dB value as the value is greater than 0 - auto valueInDB = ampToDbfs(value); + const auto valueInDB = ampToDbfs(value); - auto incrementValue = 1.; - - auto const modKeys = ev->modifiers(); - if (modKeys == Qt::ShiftModifier) - { - // The shift is intended to go through the values in very coarse steps as in: - // "Shift into overdrive" - incrementValue = 3.; - } - else if (modKeys == Qt::ControlModifier) - { - // The control key gives more control, i.e. it enables more fine-grained adjustments - incrementValue = 0.1; - } - - auto increment = incrementValue * direction; - - auto adjustedValue = valueInDB + increment; + const auto adjustedValue = valueInDB + increment; model()->setValue(adjustedValue < m_faderMinDb ? 0. : dbfsToAmp(adjustedValue)); } } else { - model()->incValue(direction); + const auto adjustedValue = std::clamp(model()->value() + increment, model()->minValue(), model()->maxValue()); + + model()->setValue(adjustedValue); } updateTextFloat();