Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
waveform_canvas_renderer.h
1// SPDX-FileCopyrightText: © 2026 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include <vector>
7
8#include <QColor>
9#include <QtCanvasPainter/qcanvaspainter.h>
10#include <QtCanvasPainter/qcanvaspainteritemrenderer.h>
11
12#include <juce_audio_basics/juce_audio_basics.h>
13
14namespace zrythm::gui::qquick
15{
16
18
25class WaveformCanvasRenderer : public QCanvasPainterItemRenderer
26{
27public:
28 WaveformCanvasRenderer () = default;
29 Q_DISABLE_COPY_MOVE (WaveformCanvasRenderer)
30
31 void synchronize (QCanvasPainterItem * item) override;
32 void paint (QCanvasPainter * painter) override;
33
34private:
35 struct Peak
36 {
37 float min; // normalized 0-1
38 float max; // normalized 0-1
39 };
40
41 using ChannelPeaks = std::vector<Peak>;
42
43 void compute_peaks ();
44
45 // Cached visual state from the item
46 QColor waveform_color_;
47 QColor outline_color_;
48 float canvas_width_ = 0.0f;
49 float canvas_height_ = 0.0f;
50
51 // Cached pointer to the item's serialized audio buffer (owned by the item)
52 const juce::AudioSampleBuffer * audio_buffer_ = nullptr;
53
54 // Cached peak data
55 std::vector<ChannelPeaks> peaks_;
56 int num_channels_ = 0;
57
58 // Change detection
59 uint64_t prev_generation_ = 0;
60 float prev_width_ = 0.0f;
61 float prev_height_ = 0.0f;
62};
63
64} // namespace zrythm::gui::qquick
Generic base for hardware-accelerated waveform rendering.