Skip to content

Commit f02c464

Browse files
More flexible painting of fader ticks
Paint the fader ticks in a more systematic and flexible way. This also removes some "magic numbers", e.g. by using `c_faderMinDb` instead of `-120.f` as the lower limit. The upper limit, i.e. the "starting point" is now also computed using the maximum value of the model so that the fader will still paint correctly if it ever changes.
1 parent ccae1b5 commit f02c464

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/gui/widgets/Fader.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,15 @@ void Fader::paintFaderTicks(QPainter& painter)
706706
const QPen zeroPen(QColor(255, 255, 255, 216), 1.5);
707707
const QPen nonZeroPen(QColor(255, 255, 255, 128), 1.);
708708

709-
for (float i = 6.f; i >= -120.f; i-= 6.f)
709+
// We use the maximum dB value of the model to calculate the nearest multiple
710+
// of the step size that we use to paint the ticks so that we know the start point.
711+
// This code will paint ticks with steps that are defined by the step size around
712+
// the 0 dB marker.
713+
const auto maxDB = ampToDbfs(model()->maxValue());
714+
const auto stepSize = 6.f;
715+
const auto startValue = std::floor(maxDB / stepSize) * stepSize;
716+
717+
for (float i = startValue; i >= c_faderMinDb; i-= stepSize)
710718
{
711719
const auto scaledRatio = computeScaledRatio(i);
712720
const auto maxHeight = height() - (height() - m_knob.height()) * scaledRatio - (m_knob.height() / 2);

0 commit comments

Comments
 (0)