From 3510dea4ae52fb8a099ec6fb1f19c83ec2440142 Mon Sep 17 00:00:00 2001 From: Michael Gregorius Date: Tue, 24 Dec 2024 20:00:58 +0100 Subject: [PATCH] Extend Fader::wheelEvent Extend `Fader::wheelEvent` for the case where the model is not a dB model (`modelIsLinear() == true`), e.g. for the mixer faders. In that case it works as follows. Each step increments or decrements by 1 dB if no modifier is pressed. With "Shift" pressed the increment value is 3 dB. With "STRG" ("CTRL") pressed the increment value is reduced to 0.1 dB. If the value goes below the minimum positive dB value that is allowed by the fader then the fader is set to "-inf dB", i.e. zero amplification. If the fader is set to "-inf dB" and the users want to increase the value then it is first set to the minimum positive value that is allowed by the fader. If the model is a dB model then the same behavior as before is used. Although it should be considered to adjust this case as well. These models are used by the faders of the Crossover Equalizer, Equalizer, Compressor and Delay and they are not very usable with the mouse wheel. --- src/gui/widgets/Fader.cpp | 49 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/src/gui/widgets/Fader.cpp b/src/gui/widgets/Fader.cpp index 1fdbb9b04..9c94a1942 100644 --- a/src/gui/widgets/Fader.cpp +++ b/src/gui/widgets/Fader.cpp @@ -212,12 +212,57 @@ void Fader::mouseReleaseEvent(QMouseEvent* mouseEvent) void Fader::wheelEvent (QWheelEvent* ev) { - ev->accept(); const int direction = (ev->angleDelta().y() > 0 ? 1 : -1) * (ev->inverted() ? -1 : 1); - model()->incValue(direction); + if (modelIsLinear()) + { + auto value = model()->value(); + + if (value <= 0.) + { + // We are at -inf dB. Do nothing if we user wishes to decrease. + if (direction > 0) + { + // Otherwise set the model to the minimum value supported by the fader. + model()->setValue(dbfsToAmp(m_faderMinDb)); + } + } + else + { + // We can safely compute the dB value as the value is greater than 0 + 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; + + model()->setValue(adjustedValue < m_faderMinDb ? 0. : dbfsToAmp(adjustedValue)); + } + } + else + { + model()->incValue(direction); + } + updateTextFloat(); s_textFloat->setVisibilityTimeOut(1000); + + ev->accept(); }