Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
waveform_canvas_item.h
1// SPDX-FileCopyrightText: © 2026 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include <QColor>
7#include <QtCanvasPainter/qcanvaspainteritem.h>
8
9#include "juce_wrapper.h"
10
11namespace zrythm::gui::qquick
12{
13
15
23class WaveformCanvasItem : public QCanvasPainterItem
24{
25 Q_OBJECT
26
27 Q_PROPERTY (
28 QColor waveformColor READ waveformColor WRITE setWaveformColor NOTIFY
29 waveformColorChanged)
30 Q_PROPERTY (
31 QColor outlineColor READ outlineColor WRITE setOutlineColor NOTIFY
32 outlineColorChanged)
33
34public:
35 explicit WaveformCanvasItem (QQuickItem * parent = nullptr);
36
37 QCanvasPainterItemRenderer * createItemRenderer () const override;
38
39 QColor waveformColor () const { return waveform_color_; }
40 void setWaveformColor (const QColor &color);
41 QColor outlineColor () const { return outline_color_; }
42 void setOutlineColor (const QColor &color);
43
44 const juce::AudioSampleBuffer * audioBuffer () const
45 {
46 return (audio_buffer_.getNumSamples () > 0) ? &audio_buffer_ : nullptr;
47 }
48
55 uint64_t bufferGeneration () const { return buffer_generation_; }
56
57protected:
63 void notifyBufferChanged ();
64
65 juce::AudioSampleBuffer audio_buffer_;
66
67Q_SIGNALS:
68 void waveformColorChanged ();
69 void outlineColorChanged ();
70
71private:
72 QColor waveform_color_;
73 QColor outline_color_;
74 uint64_t buffer_generation_ = 0;
75};
76
77} // namespace zrythm::gui::qquick
void notifyBufferChanged()
Bumps the generation counter and schedules a repaint.
uint64_t bufferGeneration() const
Monotonically increasing counter bumped on each buffer change.
Renders audio waveform peaks using QCanvasPainter.