Loading...
Searching...
No Matches
WaveformInlet.hpp
1#pragma once
2
3#include <Process/Dataflow/Port.hpp>
4#include <Process/Dataflow/Wavetable.hpp>
5
6#include <Dataflow/PortItem.hpp>
7
9
10#include <QGraphicsItem>
11#include <QRectF>
12#include <QString>
13
14#include <optional>
15#include <span>
16#include <vector>
17
18class QMenu;
19
20namespace Dataflow
21{
22struct WaveformInlet;
23struct WavetableInlet;
24}
25
26UUID_METADATA(
27 SCORE_PLUGIN_DATAFLOW_EXPORT, Process::Port, Dataflow::WaveformInlet,
28 "be15516a-a8be-490c-b3a8-82b25f985096")
29UUID_METADATA(
30 SCORE_PLUGIN_DATAFLOW_EXPORT, Process::Port, Dataflow::WavetableInlet,
31 "c2ee4fdc-9a49-4818-965c-cf5bf98cfa49")
32
33namespace Dataflow
34{
69struct SCORE_PLUGIN_DATAFLOW_EXPORT WaveformInlet : Process::ControlInlet
70{
71 W_OBJECT(WaveformInlet)
72public:
73 SCORE_SERIALIZE_FRIENDS
74 MODEL_METADATA_IMPL(WaveformInlet)
75 WaveformInlet(Id<Process::Port> id, QObject* parent);
76 WaveformInlet(DataStream::Deserializer& vis, QObject* parent);
77 WaveformInlet(JSONObject::Deserializer& vis, QObject* parent);
78 WaveformInlet(DataStream::Deserializer&& vis, QObject* parent);
79 WaveformInlet(JSONObject::Deserializer&& vis, QObject* parent);
80 ~WaveformInlet() override;
81
82 void setValue(const ossia::value& value) override;
83 void setWaveform(const Process::WavetableData& waveform);
84 const Process::WavetableData& wavetable() const noexcept { return m_waveform; }
85
87 void setAmplitudeLevels(int levels);
88 int amplitudeLevels() const noexcept { return m_amplitudeLevels; }
90 void setFrameSizeConstraint(std::size_t size);
91 std::size_t frameSizeConstraint() const noexcept { return m_frameSizeConstraint; }
92 bool supportsFrames() const noexcept { return m_bank; }
93 void constraintsChanged() W_SIGNAL(constraintsChanged);
94
95protected:
96 WaveformInlet(Id<Process::Port> id, QObject* parent, bool bank);
97 WaveformInlet(DataStream::Deserializer& vis, QObject* parent, bool bank);
98 WaveformInlet(JSONObject::Deserializer& vis, QObject* parent, bool bank);
99
100private:
101 void initializeLoadedValue();
102 bool accepts(const Process::WavetableData& data) const noexcept;
103
104 Process::WavetableData m_waveform{Process::makeTriangleWavetable()};
105 int m_amplitudeLevels{};
106 std::size_t m_frameSizeConstraint{};
107 bool m_bank{};
108};
109
112struct SCORE_PLUGIN_DATAFLOW_EXPORT WavetableInlet final : WaveformInlet
113{
114 MODEL_METADATA_IMPL(WavetableInlet)
115 WavetableInlet(Id<Process::Port> id, QObject* parent);
116 WavetableInlet(DataStream::Deserializer& vis, QObject* parent);
117 WavetableInlet(JSONObject::Deserializer& vis, QObject* parent);
118 WavetableInlet(DataStream::Deserializer&& vis, QObject* parent);
119 WavetableInlet(JSONObject::Deserializer&& vis, QObject* parent);
120};
121
122SCORE_PLUGIN_DATAFLOW_EXPORT
123void setWaveformItemModel(QGraphicsItem& item, WaveformInlet& model);
124SCORE_PLUGIN_DATAFLOW_EXPORT
125void setWaveformItemRect(QGraphicsItem& item, const QRectF& rect);
126
129{
131 QRectF plot;
133 QRectF frames;
134 std::size_t frame{};
135 QString label;
137 QString readout;
139 bool live{};
140};
141SCORE_PLUGIN_DATAFLOW_EXPORT
142WaveformItemState waveformItemState(const QGraphicsItem& item);
144SCORE_PLUGIN_DATAFLOW_EXPORT
145void fillWaveformItemMenu(QGraphicsItem& item, QMenu& menu);
146
149SCORE_PLUGIN_DATAFLOW_EXPORT
150QString waveformFrameText(std::span<const float> frame);
159SCORE_PLUGIN_DATAFLOW_EXPORT
160std::optional<std::vector<float>>
161waveformFrameFromText(QStringView text, std::size_t size, int levels);
162}
163
164namespace WidgetFactory
165{
166struct SCORE_PLUGIN_DATAFLOW_EXPORT WaveformInletItems
167{
168 static constexpr Process::PortItemLayout layout() noexcept { return {}; }
169 static QWidget* make_widget(
170 const Dataflow::WaveformInlet& inlet, const score::DocumentContext& ctx,
171 QWidget* parent, QObject* context);
172 static QGraphicsItem* make_item(
173 const Dataflow::WaveformInlet& slider, const Dataflow::WaveformInlet& inlet,
174 const score::DocumentContext& ctx, QGraphicsItem* parent, QObject* context);
175};
176}
Definition DataStreamVisitor.hpp:202
Definition JSONVisitor.hpp:423
Definition Port.hpp:247
Definition Port.hpp:106
The id_base_t class.
Definition Identifier.hpp:59
Base classes and tools to implement processes and layers.
Definition JSONVisitor.hpp:1115
Definition WaveformInlet.hpp:70
What a waveform editor item currently shows, in item coordinates.
Definition WaveformInlet.hpp:129
QRectF frames
The frame chooser of a bank; null for a single frame.
Definition WaveformInlet.hpp:133
QRectF plot
Where samples are drawn and edited: one equal column per sample.
Definition WaveformInlet.hpp:131
QString readout
The hovered sample, or with focus the last edited one; empty when none is.
Definition WaveformInlet.hpp:137
Definition WaveformInlet.hpp:113
Definition Port.hpp:93
Definition Wavetable.hpp:29
Definition WaveformInlet.hpp:167
Definition DocumentContext.hpp:18