diff --git a/plugins/AudioFileProcessor/AudioFileProcessorWaveView.cpp b/plugins/AudioFileProcessor/AudioFileProcessorWaveView.cpp index 7c5f9387eec..b41af33e016 100644 --- a/plugins/AudioFileProcessor/AudioFileProcessorWaveView.cpp +++ b/plugins/AudioFileProcessor/AudioFileProcessorWaveView.cpp @@ -338,10 +338,12 @@ void AudioFileProcessorWaveView::updateGraph() m_graph.fill(Qt::transparent); QPainter p(&m_graph); p.setPen(QColor(255, 255, 255)); + + const auto dataOffset = m_reversed ? m_sample->sampleSize() - m_to : m_from; const auto rect = QRect{0, 0, m_graph.width(), m_graph.height()}; const auto waveform = SampleWaveform::Parameters{ - m_sample->data() + m_from, static_cast(range()), m_sample->amplification(), m_sample->reversed()}; + m_sample->data() + dataOffset, static_cast(range()), m_sample->amplification(), m_sample->reversed()}; SampleWaveform::visualize(waveform, p, rect); } @@ -467,9 +469,11 @@ void AudioFileProcessorWaveView::reverse() - m_sample->endFrame() - m_sample->startFrame() ); + + const int fromTmp = m_from; setFrom(m_sample->sampleSize() - m_to); - setTo(m_sample->sampleSize() - m_from); + setTo(m_sample->sampleSize() - fromTmp); m_reversed = ! m_reversed; } diff --git a/src/gui/SampleWaveform.cpp b/src/gui/SampleWaveform.cpp index ca356e72713..165ede4ee89 100644 --- a/src/gui/SampleWaveform.cpp +++ b/src/gui/SampleWaveform.cpp @@ -44,12 +44,12 @@ void SampleWaveform::visualize(Parameters parameters, QPainter& painter, const Q const float resolution = std::max(1.0f, framesPerPixel / maxFramesPerPixel); const float framesPerResolution = framesPerPixel / resolution; - const size_t numPixels = std::min(parameters.size, width); + size_t numPixels = std::min(parameters.size, static_cast(width)); auto min = std::vector(numPixels, 1); auto max = std::vector(numPixels, -1); auto squared = std::vector(numPixels, 0); - const size_t maxFrames = numPixels * static_cast(framesPerPixel); + const size_t maxFrames = static_cast(numPixels * framesPerPixel); auto pixelIndex = std::size_t{0}; @@ -67,12 +67,9 @@ void SampleWaveform::visualize(Parameters parameters, QPainter& painter, const Q squared[pixelIndex] += value * value; } - while (pixelIndex < numPixels) + if (pixelIndex < numPixels) { - max[pixelIndex] = 0.0; - min[pixelIndex] = 0.0; - - pixelIndex++; + numPixels = pixelIndex; } for (auto i = std::size_t{0}; i < numPixels; i++)