From cb8022c55d520a251dca6d3ee872de50cbacc451 Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Wed, 12 Jun 2024 18:06:37 +0200 Subject: [PATCH] WaveRubber: use static_cast --- src/analyzer/waverubber.cpp | 22 +++++++++++----------- src/analyzer/waverubber.h | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/analyzer/waverubber.cpp b/src/analyzer/waverubber.cpp index 478f4f2f2..9ff42c56b 100644 --- a/src/analyzer/waverubber.cpp +++ b/src/analyzer/waverubber.cpp @@ -35,7 +35,7 @@ void WaveRubber::resizeEvent(QResizeEvent *e) { } -void WaveRubber::analyze(QPainter &p, const Scope &s, bool new_frame) { +void WaveRubber::analyze(QPainter &p, const Scope &s, const bool new_frame) { if (!new_frame || engine_->state() == EngineBase::State::Paused) { p.drawPixmap(0, 0, canvas_); @@ -53,28 +53,28 @@ void WaveRubber::analyze(QPainter &p, const Scope &s, bool new_frame) { // Get pointer to amplitude data const float *amplitude_data = s.data(); - int mid_y = height() / 4; - int num_samples = s.size(); + const int mid_y = height() / 4; + const int num_samples = static_cast(s.size()); - float x_scale = static_cast(width()) / num_samples; - float prev_y = mid_y; + const float x_scale = static_cast(width()) / static_cast(num_samples); + float prev_y = static_cast(mid_y); // Draw the waveform for (int i = 0; i < num_samples; ++i) { // Normalize amplitude to 0-1 range - float color_factor = amplitude_data[i] / 2.0f + 0.5f; - int rgb_value = static_cast(255 - color_factor * 255); + const float color_factor = amplitude_data[i] / 2.0F + 0.5F; + const int rgb_value = static_cast(255 - color_factor * 255); QColor highlight_color = palette().color(QPalette::Highlight); // Blend blue and green with highlight color from QT palette based on amplitude QColor blended_color = QColor(rgb_value, highlight_color.green(), highlight_color.blue()); canvas_painter.setPen(blended_color); - int x = static_cast(i * x_scale); - int y = static_cast(mid_y - (s[i] * mid_y)); + const int x = static_cast(static_cast(i) * x_scale); + const int y = static_cast(static_cast(mid_y) - (s[i] * static_cast(mid_y))); - canvas_painter.drawLine(x, prev_y + mid_y, x + x_scale, y + mid_y); // Draw - prev_y = y; + canvas_painter.drawLine(x, static_cast(prev_y + static_cast(mid_y)), static_cast(static_cast(x) + x_scale), static_cast(static_cast(y + mid_y))); // Draw + prev_y = static_cast(y); } canvas_painter.end(); diff --git a/src/analyzer/waverubber.h b/src/analyzer/waverubber.h index 12246e0e5..ee211e449 100644 --- a/src/analyzer/waverubber.h +++ b/src/analyzer/waverubber.h @@ -32,7 +32,7 @@ class WaveRubber : public AnalyzerBase { protected: void resizeEvent(QResizeEvent *e) override; - void analyze(QPainter &p, const Scope &s, bool new_frame) override; + void analyze(QPainter &p, const Scope &s, const bool new_frame) override; void transform(Scope &scope) override; void demo(QPainter &p) override;