Loading...
Searching...
No Matches
score-lib-process/Process/Process.hpp
1#pragma once
2#include <Process/Dataflow/PortForward.hpp>
3#include <Process/ExpandMode.hpp>
4#include <Process/Preset.hpp>
5#include <Process/ProcessFlags.hpp>
6#include <Process/TimeValue.hpp>
7
8#include <Magnetism/MagneticInfo.hpp>
9
10#include <score/model/Component.hpp>
11#include <score/model/EntityImpl.hpp>
12#include <score/model/Identifier.hpp>
13#include <score/model/ModelMetadata.hpp>
14#include <score/plugins/SerializableInterface.hpp>
15#include <score/selection/Selectable.hpp>
16#include <score/selection/Selection.hpp>
17#include <score/serialization/VisitorInterface.hpp>
18#include <score/tools/Metadata.hpp>
19
20#include <ossia/detail/small_vector.hpp>
21
22#include <QString>
23
24#include <score_lib_process_export.h>
25#include <smallfun.hpp>
26
27#include <optional>
28#include <vector>
29#include <verdigris>
30
32namespace ossia
33{
34class value;
35}
36namespace Process
37{
38class Port;
39class Inlet;
40class ControlInlet;
41class Outlet;
42class AudioInlet;
43class AudioOutlet;
44class MidiInlet;
45class MidiOutlet;
46class ProcessModelFactory;
47class LayerFactory;
48class ProcessModel;
49class LayerFactory;
50struct Inlets;
51struct Outlets;
52
58class SCORE_LIB_PROCESS_EXPORT ProcessModel
59 : public score::Entity<ProcessModel>
60 , public score::SerializableInterface<ProcessModel>
61{
62 W_OBJECT(ProcessModel)
63 SCORE_SERIALIZE_FRIENDS
64public:
65 Selectable selection{this};
67 TimeVal duration, const Id<ProcessModel>& id, const QString& name,
68 QObject* parent);
69
70 ProcessModel(DataStream::Deserializer& vis, QObject* parent);
71 ProcessModel(JSONObject::Deserializer& vis, QObject* parent);
72
73 virtual ~ProcessModel();
74
75 // If the process can have multiple distinct implementations
76 // for which presets are incompatible, e.g. VST, Faust...
77 // This allows to differentiate them
78 virtual QString effect() const noexcept;
79
80 // A user-friendly text to show to the users
81 virtual QString prettyName() const noexcept;
82 virtual QString prettyShortName() const noexcept = 0;
83 virtual QString category() const noexcept = 0;
84 virtual QStringList tags() const noexcept = 0;
85 virtual ProcessFlags flags() const noexcept = 0;
86
89 void setParentDuration(ExpandMode mode, const TimeVal& t) noexcept;
90
91 virtual TimeVal contentDuration() const noexcept;
92
93 void setDuration(const TimeVal& other) noexcept;
94 const TimeVal& duration() const noexcept;
95
97 QPointF position() const noexcept;
98 QSizeF size() const noexcept;
99
100 void setPosition(const QPointF& v);
101 void setSize(const QSizeF& v);
102
103 void positionChanged(QPointF p) E_SIGNAL(SCORE_LIB_PROCESS_EXPORT, positionChanged, p)
104 void sizeChanged(QSizeF p) E_SIGNAL(SCORE_LIB_PROCESS_EXPORT, sizeChanged, p)
105
106 PROPERTY(
107 QPointF, position W_READ position W_WRITE setPosition W_NOTIFY positionChanged)
108 PROPERTY(QSizeF, size W_READ size W_WRITE setSize W_NOTIFY sizeChanged)
109
110
111 virtual ProcessStateDataInterface* startStateData() const noexcept;
112 virtual ProcessStateDataInterface* endStateData() const noexcept;
113
115 virtual Selection selectableChildren() const noexcept;
116 virtual Selection selectedChildren() const noexcept;
117 virtual void setSelection(const Selection& s) const noexcept;
118
119 double getSlotHeight() const noexcept;
120 void setSlotHeight(double) noexcept;
121
122 const Process::Inlets& inlets() const noexcept { return m_inlets; }
123 const Process::Outlets& outlets() const noexcept { return m_outlets; }
124
125 Process::Inlet* inlet(const Id<Process::Port>&) const noexcept;
126 Process::Outlet* outlet(const Id<Process::Port>&) const noexcept;
127
128 virtual void loadPreset(const Preset& preset);
129 virtual Preset savePreset() const noexcept;
130 virtual std::vector<Process::Preset> builtinPresets() const noexcept;
131
132 // Called when an ancestor was moved in the timeline
133 virtual void ancestorStartDateChanged();
134 virtual void ancestorTempoChanged();
135
136 virtual void forEachControl(
137 smallfun::function<void(Process::ControlInlet&, const ossia::value&)>) const;
138
139 // Magnetism
140 virtual std::optional<Process::MagneticInfo>
141 magneticPosition(const QObject* o, const TimeVal t) const noexcept;
142
143 // Clip duration things
144 bool loops() const noexcept { return m_loops; }
145 void setLoops(bool b);
146 void loopsChanged(bool b) E_SIGNAL(SCORE_LIB_PROCESS_EXPORT, loopsChanged, b)
147 PROPERTY(bool, loops W_READ loops W_WRITE setLoops W_NOTIFY loopsChanged)
148
149 TimeVal startOffset() const noexcept { return m_startOffset; }
150 void setStartOffset(TimeVal b);
151 void startOffsetChanged(TimeVal b)
152 E_SIGNAL(SCORE_LIB_PROCESS_EXPORT, startOffsetChanged, b)
153 PROPERTY(
154 TimeVal,
155 startOffset W_READ startOffset W_WRITE setStartOffset W_NOTIFY startOffsetChanged)
156
157 TimeVal loopDuration() const noexcept { return m_loopDuration; }
158 void setLoopDuration(TimeVal b);
159 void loopDurationChanged(TimeVal b)
160 E_SIGNAL(SCORE_LIB_PROCESS_EXPORT, loopDurationChanged, b)
161 PROPERTY(
162 TimeVal, loopDuration W_READ loopDuration W_WRITE setLoopDuration W_NOTIFY
163 loopDurationChanged)
164
165 virtual void setCreatingControls(bool ok);
166 bool creatingControls() const noexcept;
167 void creatingControlsChanged(bool b)
168 E_SIGNAL(SCORE_LIB_PROCESS_EXPORT, creatingControlsChanged, b)
169 PROPERTY(
170 bool, creatingControls W_READ creatingControls W_WRITE setCreatingControls W_NOTIFY
171 creatingControlsChanged)
172
173 // FIXME ugh
174 QWidget* externalUI{};
175
177 void startExecution() E_SIGNAL(SCORE_LIB_PROCESS_EXPORT, startExecution)
178 void stopExecution() E_SIGNAL(SCORE_LIB_PROCESS_EXPORT, stopExecution)
179 void resetExecution() E_SIGNAL(SCORE_LIB_PROCESS_EXPORT, resetExecution)
180
181 void durationChanged(const TimeVal& arg_1)
182 E_SIGNAL(SCORE_LIB_PROCESS_EXPORT, durationChanged, arg_1)
183 void useParentDurationChanged(bool arg_1)
184 E_SIGNAL(SCORE_LIB_PROCESS_EXPORT, useParentDurationChanged, arg_1)
185
186 void slotHeightChanged(double arg_1)
187 E_SIGNAL(SCORE_LIB_PROCESS_EXPORT, slotHeightChanged, arg_1)
188 void prettyNameChanged() E_SIGNAL(SCORE_LIB_PROCESS_EXPORT, prettyNameChanged)
189
190 void inletsChanged() E_SIGNAL(SCORE_LIB_PROCESS_EXPORT, inletsChanged)
191 void outletsChanged() E_SIGNAL(SCORE_LIB_PROCESS_EXPORT, outletsChanged)
192
193 void controlAdded(const Id<Process::Port>& arg_1)
194 E_SIGNAL(SCORE_LIB_PROCESS_EXPORT, controlAdded, arg_1)
195 void controlRemoved(const Process::Port& arg_1)
196 E_SIGNAL(SCORE_LIB_PROCESS_EXPORT, controlRemoved, arg_1)
197 void controlOutletAdded(const Id<Process::Port>& arg_1)
198 E_SIGNAL(SCORE_LIB_PROCESS_EXPORT, controlOutletAdded, arg_1)
199 void controlOutletRemoved(const Process::Port& arg_1)
200 E_SIGNAL(SCORE_LIB_PROCESS_EXPORT, controlOutletRemoved, arg_1)
201
202 void benchmark(double arg_1) E_SIGNAL(SCORE_LIB_PROCESS_EXPORT, benchmark, arg_1)
203 void externalUIVisible(bool v) const
204 E_SIGNAL(SCORE_LIB_PROCESS_EXPORT, externalUIVisible, v)
205
206protected:
207 // Used to scale the process.
208 // This should be commutative :
209 // setDurationWithScale(2); setDurationWithScale(3);
210 // yields the same result as :
211 // setDurationWithScale(3); setDurationWithScale(2);
212 virtual void setDurationAndScale(const TimeVal& newDuration) noexcept;
213
214 // Does nothing if newDuration < currentDuration
215 virtual void setDurationAndGrow(const TimeVal& newDuration) noexcept;
216
217 // Does nothing if newDuration > currentDuration
218 virtual void setDurationAndShrink(const TimeVal& newDuration) noexcept;
219
220 Process::Inlets m_inlets;
221 Process::Outlets m_outlets;
222
223private:
224 TimeVal m_duration{};
225 double m_slotHeight{};
226 TimeVal m_startOffset{};
227 TimeVal m_loopDuration{};
228 QPointF m_position{};
229 QSizeF m_size{};
230 bool m_loops{};
231};
232
233SCORE_LIB_PROCESS_EXPORT
234ProcessModel* parentProcess(QObject* obj) noexcept;
235SCORE_LIB_PROCESS_EXPORT
236const ProcessModel* parentProcess(const QObject* obj) noexcept;
237
238SCORE_LIB_PROCESS_EXPORT
239QString processLocalTreeAddress(const Process::ProcessModel& proc);
240}
241DEFAULT_MODEL_METADATA(Process::ProcessModel, "Process")
242
243Q_DECLARE_METATYPE(Id<Process::ProcessModel>)
244W_REGISTER_ARGTYPE(Id<Process::ProcessModel>)
245W_REGISTER_ARGTYPE(OptionalId<Process::ProcessModel>)
246
247Q_DECLARE_METATYPE(Process::ProcessModel*)
248Q_DECLARE_METATYPE(const Process::ProcessModel*)
249W_REGISTER_ARGTYPE(Process::ProcessModel*)
250W_REGISTER_ARGTYPE(const Process::ProcessModel*)
251W_REGISTER_ARGTYPE(QPointer<const Process::ProcessModel>)
252W_REGISTER_ARGTYPE(QPointer<Process::ProcessModel>)
253
254Q_DECLARE_METATYPE(std::shared_ptr<Process::Preset>)
255W_REGISTER_ARGTYPE(std::shared_ptr<Process::Preset>)
Definition DataStreamVisitor.hpp:202
Definition JSONVisitor.hpp:423
Definition Port.hpp:203
Definition Port.hpp:177
Definition Port.hpp:273
Definition Port.hpp:102
The Process class.
Definition score-lib-process/Process/Process.hpp:61
void startExecution()
Execution.
Definition ProcessStateDataInterface.hpp:24
The Selectable class.
Definition Selectable.hpp:14
Definition Selection.hpp:12
The id_base_t class.
Definition Identifier.hpp:57
Base for complex model objects.
Definition EntityBase.hpp:24
Generic serialization method for abstract classes.
Definition SerializableInterface.hpp:21
Base classes and tools to implement processes and layers.
Definition JSONVisitor.hpp:1324
ProcessFlags
Various settings for processes.
Definition ProcessFlags.hpp:17
STL namespace.
Definition PortForward.hpp:23
Definition PortForward.hpp:27
Definition Preset.hpp:32
Definition TimeValue.hpp:21