From 324725f1f299c4abade38c4f9a6d4c29d88afe1c Mon Sep 17 00:00:00 2001 From: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Sun, 26 Mar 2023 19:00:36 -0700 Subject: [PATCH] audiovisualwaveform: ceil rather than round when drawing samples This may help with waveform visibility when tracks are set to smaller heights --- app/audio/audiovisualwaveform.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/audio/audiovisualwaveform.cpp b/app/audio/audiovisualwaveform.cpp index fbe4d6120..0558eb600 100644 --- a/app/audio/audiovisualwaveform.cpp +++ b/app/audio/audiovisualwaveform.cpp @@ -384,6 +384,12 @@ AudioVisualWaveform::Sample AudioVisualWaveform::ReSumSamples(const SamplePerCha return summed_samples; } +template +inline int round_away_from_zero(T t) +{ + return (t < 0) ? std::floor(t) : std::ceil(t); +} + void AudioVisualWaveform::DrawSample(QPainter *painter, const Sample& sample, int x, int y, int height, bool rectified) { if (sample.empty()) { @@ -400,7 +406,7 @@ void AudioVisualWaveform::DrawSample(QPainter *painter, const Sample& sample, in if (rectified) { int channel_bottom = y + channel_height * (i + 1); - int diff = qRound((max - min) * channel_half_height); + int diff = round_away_from_zero((max - min) * channel_half_height); painter->drawLine(x, channel_bottom - diff, @@ -412,9 +418,9 @@ void AudioVisualWaveform::DrawSample(QPainter *painter, const Sample& sample, in // We subtract the sample so that positive Y values go up on the screen rather than down, // which is how waveforms are usually rendered painter->drawLine(x, - channel_mid - qRound(min * static_cast(channel_half_height)), + channel_mid - round_away_from_zero(min * static_cast(channel_half_height)), x, - channel_mid - qRound(max * static_cast(channel_half_height))); + channel_mid - round_away_from_zero(max * static_cast(channel_half_height))); } } }