Use dbFS scale for the faders

Make the faders use a linear dbFS scale. They now also change position on first click and can then be dragged.

The `Fader` class now has a new property called `m_faderMinDb`. It's the minimum value before the amplification drops down fully to 0. It is needed because we cannot represent a scale from -inf to maxDB.

Rename `knobPosY` to `calculateKnobPosYFromModel` and move the implementation into the cpp file. The method now first converts the model's current amplification value to dbFS and then computes a ratio based on that values and the minimum and maximum dbFS values.

Add the method `setVolumeByLocalPixelValue` which takes a local y coordinate of the widget and sets the amplification of the model based on a dbFS scale.

Adjust `mousePressEvent` and `mouseMoveEvent` so that they mostly take the local y coordinate of the event and use that to adjust the model via `setVolumeByLocalPixelValue`.

Remove `m_moveStartPoint` and `m_startValue` and they are not needed anymore.
This commit is contained in:
Michael Gregorius
2024-04-05 17:35:17 +02:00
parent 6b494bd7a3
commit 872409afd8
2 changed files with 73 additions and 32 deletions

View File

@@ -119,13 +119,8 @@ private:
void paintLevels(QPaintEvent* ev, QPainter& painter, bool linear = false);
int knobPosY() const
{
float fRange = model()->maxValue() - model()->minValue();
float realVal = model()->value() - model()->minValue();
return height() - ((height() - m_knob.height()) * (realVal / fRange));
}
int calculateKnobPosYFromModel() const;
void setVolumeByLocalPixelValue(int y);
void setPeak(float fPeak, float& targetPeak, float& persistentPeak, QElapsedTimer& lastPeakTimer);
@@ -147,8 +142,8 @@ private:
bool m_levelsDisplayedInDBFS {true};
int m_moveStartPoint {-1};
float m_startValue {0.};
// The dbFS amount after which we drop down to -inf dbFS
float const m_faderMinDb {-60.};
static SimpleTextFloat* s_textFloat;