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_wrapper.h"
13
14namespace zrythm::gui::qquick
15{
16
18
25class WaveformCanvasRenderer : public QCanvasPainterItemRenderer
26{
27public:
28 WaveformCanvasRenderer () = default;
29 ~WaveformCanvasRenderer () override = default;
30
31 void initializeResources (QCanvasPainter * painter) override;
32 void synchronize (QCanvasPainterItem * item) override;
33 void paint (QCanvasPainter * painter) override;
34
35private:
36 struct Peak
37 {
38 float min; // normalized 0-1
39 float max; // normalized 0-1
40 };
41
42 using ChannelPeaks = std::vector<Peak>;
43
44 void compute_peaks ();
45
46 // Cached visual state from the item
47 QColor waveform_color_;
48 QColor outline_color_;
49 float canvas_width_ = 0.0f;
50 float canvas_height_ = 0.0f;
51
52 // Cached pointer to the item's serialized audio buffer (owned by the item)
53 const juce::AudioSampleBuffer * audio_buffer_ = nullptr;
54
55 // Cached peak data
56 std::vector<ChannelPeaks> peaks_;
57 int num_channels_ = 0;
58
59 // Change detection
60 uint64_t prev_generation_ = 0;
61 float prev_width_ = 0.0f;
62 float prev_height_ = 0.0f;
63};
64
65} // namespace zrythm::gui::qquick
Generic base for hardware-accelerated waveform rendering.