Zrythm v2.0.0-alpha.1
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 "gui/qquick/clip_canvas_item_base.h"
7
8#include <QColor>
9
10#include <juce_audio_basics/juce_audio_basics.h>
11
12namespace zrythm::gui::qquick
13{
14
16
24class WaveformCanvasItem : public ClipCanvasItemBase
25{
26 Q_OBJECT
27
28 Q_PROPERTY (
29 QColor waveformColor READ waveformColor WRITE setWaveformColor NOTIFY
30 waveformColorChanged)
31 Q_PROPERTY (
32 QColor outlineColor READ outlineColor WRITE setOutlineColor NOTIFY
33 outlineColorChanged)
34
35public:
36 explicit WaveformCanvasItem (QQuickItem * parent = nullptr);
37
38 QCanvasPainterItemRenderer * createItemRenderer () const override;
39
40 QColor waveformColor () const { return waveform_color_; }
41 void setWaveformColor (const QColor &color);
42 QColor outlineColor () const { return outline_color_; }
43 void setOutlineColor (const QColor &color);
44
45 const juce::AudioSampleBuffer * audioBuffer () const
46 {
47 return (audio_buffer_.getNumSamples () > 0) ? &audio_buffer_ : nullptr;
48 }
49
56 uint64_t bufferGeneration () const { return buffer_generation_; }
57
58protected:
64 void notifyBufferChanged ();
65
66 juce::AudioSampleBuffer audio_buffer_;
67
68Q_SIGNALS:
69 void waveformColorChanged ();
70 void outlineColorChanged ();
71
72private:
73 QColor waveform_color_;
74 QColor outline_color_;
75 uint64_t buffer_generation_ = 0;
76};
77
78} // 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.