Loading...
Searching...
No Matches
IntervalModel.hpp
1#pragma once
2#include <Process/Dataflow/TimeSignature.hpp>
3#include <Process/Instantiations.hpp>
4#include <Process/Process.hpp>
5#include <Process/TimeValue.hpp>
6
7#include <Scenario/Document/Interval/ExecutionState.hpp>
8#include <Scenario/Document/Interval/IntervalDurations.hpp>
9#include <Scenario/Document/Interval/Slot.hpp>
10#include <Scenario/Document/Interval/TimeSignatureMap.hpp>
11#include <Scenario/Document/Metatypes.hpp>
12#include <Scenario/Document/ModelConsistency.hpp>
13
14#include <score/model/Component.hpp>
15#include <score/model/EntityImpl.hpp>
16#include <score/model/EntityMap.hpp>
17#include <score/model/IdentifiedObject.hpp>
18#include <score/model/Identifier.hpp>
19#include <score/selection/Selectable.hpp>
20#include <score/serialization/MapSerialization.hpp>
21#include <score/tools/Metadata.hpp>
22#include <score/tools/std/Optional.hpp>
23
24#include <QObject>
25#include <QPointer>
26
27#include <nano_signal_slot.hpp>
28
29#include <verdigris>
30
31class DataStream;
32class JSONObject;
33namespace Process
34{
35class AudioInlet;
36class AudioOutlet;
37}
38namespace Curve
39{
40class Model;
41}
42namespace Scenario
43{
44class StateModel;
45class TempoProcess;
46
47class SCORE_PLUGIN_SCENARIO_EXPORT IntervalModel final
48 : public score::Entity<IntervalModel>
49 , public Nano::Observer
50{
51 W_OBJECT(IntervalModel)
52
53 SCORE_SERIALIZE_FRIENDS
54 friend struct IntervalSaveData;
55 friend struct SlotPath;
56
57public:
58 std::unique_ptr<Process::AudioInlet> inlet;
59 std::unique_ptr<Process::AudioOutlet> outlet;
60
63
64 Selectable selection{this};
65 ModelConsistency consistency{nullptr};
66 IntervalDurations duration{*this};
67
69 IntervalModel(
70 const Id<IntervalModel>&, double yPos, const score::DocumentContext& ctx,
71 QObject* parent);
72
73 ~IntervalModel();
74
75 // Serialization
76 IntervalModel(
77 DataStream::Deserializer& vis, const score::DocumentContext& ctx, QObject* parent);
78 IntervalModel(
79 JSONObject::Deserializer& vis, const score::DocumentContext& ctx, QObject* parent);
80 IntervalModel(
82 QObject* parent);
83 IntervalModel(
85 QObject* parent);
86
87 const score::DocumentContext& context() const noexcept { return m_context; }
88 const Id<StateModel>& startState() const noexcept;
89 void setStartState(const Id<StateModel>& eventId);
90
91 const Id<StateModel>& endState() const noexcept;
92 void setEndState(const Id<StateModel>& endState);
93
94 const TimeVal& date() const noexcept;
95 void setStartDate(const TimeVal& start);
96 void translate(const TimeVal& deltaTime);
97
104 double dateInFlicks() const noexcept { return date().impl; }
105
106 double heightPercentage() const noexcept;
107
108 void startExecution();
109 void stopExecution();
110 // Resets the execution display recursively
111 void reset();
112
113 void setHeightPercentage(double arg);
114 void setExecutionState(IntervalExecutionState);
115
116 IntervalExecutionState executionState() const;
117
118 // Mode
119 enum ViewMode : bool
120 {
121 Temporal = 0,
122 Nodal = 1
123 };
124 ViewMode viewMode() const noexcept;
125 void setViewMode(ViewMode v);
126 void viewModeChanged(ViewMode v)
127 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, viewModeChanged, v)
128
129 // Node view properties (both small and full view)
134 std::optional<QPointF> nodalCenter() const noexcept;
135 void setNodalCenter(QPointF center);
138 QPointF legacyNodalOffset() const noexcept;
139 double nodalScale() const noexcept;
140 void setNodalScale(double z);
141
142 // Full view properties:
143 ZoomRatio zoom() const noexcept;
144 void setZoom(const ::ZoomRatio& zoom);
145
146 TimeVal midTime() const noexcept;
147 void setMidTime(const TimeVal& value);
148
149 void setSmallViewVisible(bool);
150 bool smallViewVisible() const noexcept;
151
152 const Rack& smallView() const noexcept { return m_smallView; }
153 const FullRack& fullView() const noexcept { return m_fullView; }
154
155 void clearSmallView();
156 void clearFullView();
157 void replaceSmallView(const Rack& other);
158 void replaceFullView(const FullRack& other);
159
160 // Adding and removing slots and layers is only for the small view
161 void addSlot(Slot s);
162 void addSlot(Slot s, int pos);
163 void removeSlot(int pos);
164
165 void addLayer(int slot, Id<Process::ProcessModel>);
166 void removeLayer(int slot, Id<Process::ProcessModel>);
167
168 void putLayerToFront(int slot, Id<Process::ProcessModel>);
169 void putLayerToFront(int slot, std::nullopt_t);
170
171 void swapSlots(int pos1, int pos2, Slot::RackView fullview);
172
173 double getSlotHeight(const SlotId& slot) const;
174 void setSlotHeight(const SlotId& slot, double height);
175 double getHeight() const noexcept;
176
178 double getSlotHeightForProcess(const Id<Process::ProcessModel>& p) const;
179
180 const Slot* findSmallViewSlot(int slot) const;
181 const Slot& getSmallViewSlot(int slot) const;
182 Slot& getSmallViewSlot(int slot);
183
184 const FullSlot* findFullViewSlot(int slot) const;
185 const FullSlot& getFullViewSlot(int slot) const;
186 FullSlot& getFullViewSlot(int slot);
187
188 bool muted() const noexcept { return m_muted; }
189 void setMuted(bool m);
190
191 bool graphal() const noexcept { return m_graphal; }
192 void setGraphal(bool m);
193
194 bool executing() const noexcept { return m_executing; }
195 void setExecuting(bool m);
196
197 // Tempo stuff
198 bool hasTimeSignature() const noexcept { return m_hasSignature; }
199 void setHasTimeSignature(bool b);
200
201 TimeVal contentDuration() const noexcept;
202
203 TempoProcess* tempoCurve() const noexcept;
204
205 void ancestorStartDateChanged();
206 void ancestorTempoChanged();
207
208 void addSignature(TimeVal t, ossia::time_signature sig);
209 void removeSignature(TimeVal t);
210 void setTimeSignatureMap(const TimeSignatureMap& map);
211 const TimeSignatureMap& timeSignatureMap() const noexcept;
212
213 ossia::musical_sync quantizationRate() const noexcept;
214 void setQuantizationRate(ossia::musical_sync b);
215
216 void setStartMarker(TimeVal t);
217 TimeVal startMarker() const noexcept;
218 double startMarkerInFlicks() const noexcept { return startMarker().impl; }
219 inline IntervalDurations* getDurations() noexcept { return &duration; }
220
221 void hasTimeSignatureChanged(bool arg_1)
222 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, hasTimeSignatureChanged, arg_1)
223 void timeSignaturesChanged(const TimeSignatureMap& arg_1)
224 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, timeSignaturesChanged, arg_1)
225 void quantizationRateChanged(ossia::musical_sync arg)
226 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, quantizationRateChanged, arg)
227
228 void requestHeightChange(double y)
229 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, requestHeightChange, y)
230 void heightPercentageChanged(double arg_1)
231 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, heightPercentageChanged, arg_1)
232
233 void dateChanged(const TimeVal& arg_1)
234 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, dateChanged, arg_1)
235 void startMarkerChanged(const TimeVal& arg_1)
236 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, startMarkerChanged, arg_1)
237
238 void focusChanged(bool arg_1)
239 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, focusChanged, arg_1)
240 void executionStateChanged(Scenario::IntervalExecutionState arg_1)
241 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, executionStateChanged, arg_1)
242
243 void executionEvent(Scenario::IntervalExecutionEvent ev)
244 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, executionEvent, ev)
245
246 void smallViewVisibleChanged(bool fv)
247 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, smallViewVisibleChanged, fv)
248
249 void rackChanged(Scenario::Slot::RackView fv)
250 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, rackChanged, fv)
251 void slotAdded(Scenario::SlotId arg_1)
252 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, slotAdded, arg_1)
253 void slotRemoved(Scenario::SlotId arg_1)
254 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, slotRemoved, arg_1)
255 void slotResized(Scenario::SlotId arg_1)
256 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, slotResized, arg_1)
257 void slotsSwapped(int slot1, int slot2, Slot::RackView fv)
258 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, slotsSwapped, slot1, slot2, fv)
259 void heightFinishedChanging()
260 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, heightFinishedChanging)
261
262 void layerAdded(Scenario::SlotId arg_1, Id<Process::ProcessModel> arg_2)
263 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, layerAdded, arg_1, arg_2)
264 void layerRemoved(Scenario::SlotId arg_1, Id<Process::ProcessModel> arg_2)
265 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, layerRemoved, arg_1, arg_2)
266 void frontLayerChanged(int arg_1, OptionalId<Process::ProcessModel> arg_2)
267 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, frontLayerChanged, arg_1, arg_2)
268
269 void mutedChanged(bool arg_1)
270 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, mutedChanged, arg_1)
271 void executingChanged(bool arg_1)
272 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, executingChanged, arg_1)
273
274 void busChanged(bool arg_1) E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, busChanged, arg_1)
275
276 void graphalChanged(bool arg_1)
277 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, graphalChanged, arg_1)
278
279 void nodalCenterChanged(QPointF arg_1)
280 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, nodalCenterChanged, arg_1)
281 void nodalScaleChanged(double arg_1)
282 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, nodalScaleChanged, arg_1)
283
284 PROPERTY(bool, muted READ muted WRITE setMuted NOTIFY mutedChanged)
285 PROPERTY(bool, graphal READ graphal WRITE setGraphal NOTIFY graphalChanged)
286 PROPERTY(
287 double, heightPercentage READ heightPercentage WRITE setHeightPercentage NOTIFY
288 heightPercentageChanged)
289
290 PROPERTY(
291 bool, timeSignature READ hasTimeSignature WRITE setHasTimeSignature NOTIFY
292 hasTimeSignatureChanged)
293
294 PROPERTY(
295 ossia::musical_sync, quantizationRate READ quantizationRate WRITE
296 setQuantizationRate NOTIFY quantizationRateChanged)
297 W_PROPERTY(IntervalDurations*, durations READ getDurations CONSTANT)
298
299 PROPERTY(double, date READ dateInFlicks NOTIFY dateChanged)
300 PROPERTY(
301 double, startMarker READ startMarkerInFlicks NOTIFY startMarkerChanged)
302
303private:
304 void on_addProcess(Process::ProcessModel&);
305 void on_removingProcess(const Process::ProcessModel&);
306 void initConnections();
307
308 // Model for the full view.
309 // Note : it is also present in m_intervalViewModels.
310 const score::DocumentContext& m_context;
311
312 Rack m_smallView;
313 FullRack m_fullView;
314
315 TimeSignatureMap m_signatures;
316
317 Id<StateModel> m_startState;
318 Id<StateModel> m_endState;
319
320 TimeVal m_startMarker;
321
322 TimeVal m_date;
323 double m_heightPercentage{0.5};
324
325 double m_nodalFullViewSlotHeight{100};
326 double m_quantRate{-1.0};
327
328 ::ZoomRatio m_zoom{-1};
329 TimeVal m_center{};
330 QPointF m_nodalOffset{};
331 std::optional<QPointF> m_nodalCenter{};
332 double m_nodalScale{1.0};
333 IntervalExecutionState m_executionState : 2;
334 ViewMode m_viewMode : 1;
335 bool m_smallViewShown : 1;
336 bool m_muted : 1;
337 bool m_executing : 1;
338
339 bool m_hasSignature : 1;
340 bool m_graphal : 1;
341};
342
343SCORE_PLUGIN_SCENARIO_EXPORT
344bool isInFullView(const Scenario::IntervalModel& cstr) noexcept;
345SCORE_PLUGIN_SCENARIO_EXPORT
346bool isInFullView(const Process::ProcessModel& cstr) noexcept;
347
348SCORE_PLUGIN_SCENARIO_EXPORT
349bool isBus(
350 const Scenario::IntervalModel& model, const score::DocumentContext& ctx) noexcept;
351
354SCORE_PLUGIN_SCENARIO_EXPORT
355QSizeF nodeFootprint(const Process::ProcessModel& process) noexcept;
356
358static const constexpr double nodeHorizontalMargin = 40.;
359
363SCORE_PLUGIN_SCENARIO_EXPORT
364QPointF freeProcessPosition(
365 const Scenario::IntervalModel& model, QPointF desired, QSizeF size,
366 bool towardsRight = true, const Process::ProcessModel* ignore = nullptr) noexcept;
367
368SCORE_PLUGIN_SCENARIO_EXPORT
369QPointF newProcessPosition(const Scenario::IntervalModel& model) noexcept;
370
372SCORE_PLUGIN_SCENARIO_EXPORT
374 const Scenario::IntervalModel& model,
375 const Process::ProcessModel& previous) noexcept;
376
380SCORE_PLUGIN_SCENARIO_EXPORT
382 const Scenario::IntervalModel& model, const Process::ProcessModel& next,
383 const Process::ProcessModel* created = nullptr) noexcept;
384
386{
387 const IntervalModel* parent;
388 const IntervalModel* lastFound;
389 TimeVal delta;
390};
391
392SCORE_PLUGIN_SCENARIO_EXPORT
393IntervalModel* closestParentInterval(const QObject*) noexcept;
394
395SCORE_PLUGIN_SCENARIO_EXPORT
396ParentTimeInfo closestParentWithMusicalMetrics(const IntervalModel*);
397SCORE_PLUGIN_SCENARIO_EXPORT
398ParentTimeInfo closestParentWithTempo(const IntervalModel*);
399SCORE_PLUGIN_SCENARIO_EXPORT
400ParentTimeInfo closestParentWithQuantification(const IntervalModel* self);
401
402SCORE_PLUGIN_SCENARIO_EXPORT
403TimeVal timeDelta(const IntervalModel* child, const IntervalModel* parent);
404}
405
406DEFAULT_MODEL_METADATA(Scenario::IntervalModel, "Interval")
407
408Q_DECLARE_METATYPE(Scenario::IntervalModel::ViewMode)
409W_REGISTER_ARGTYPE(Scenario::IntervalModel::ViewMode)
410Q_DECLARE_METATYPE(QPointer<Scenario::IntervalModel>)
411W_REGISTER_ARGTYPE(QPointer<Scenario::IntervalModel>)
412
413TR_TEXT_METADATA(, Scenario::IntervalModel, PrettyName_k, "Interval")
414
415Q_DECLARE_METATYPE(Scenario::IntervalModel*)
416W_REGISTER_ARGTYPE(Scenario::IntervalModel*)
417Q_DECLARE_METATYPE(const Scenario::IntervalModel*)
418W_REGISTER_ARGTYPE(const Scenario::IntervalModel*)
Definition VisitorInterface.hpp:53
Definition DataStreamVisitor.hpp:202
Definition VisitorInterface.hpp:61
Definition JSONVisitor.hpp:423
Metadata to get the name that will be shown in the user interface.
The Process class.
Definition score-lib-process/Process/Process.hpp:75
Definition IntervalModel.hpp:50
score::EntityMap< Process::ProcessModel, true > processes
Definition IntervalModel.hpp:62
Definition ModelConsistency.hpp:11
The Selectable class.
Definition Selectable.hpp:14
The id_base_t class.
Definition Identifier.hpp:59
Base for complex model objects.
Definition EntityBase.hpp:24
The EntityMap class.
Definition EntityMap.hpp:37
Utilities and base classes for 1D curves.
Definition FocusDispatcher.hpp:12
Base classes and tools to implement processes and layers.
Definition JSONVisitor.hpp:1115
Main plug-in of score.
Definition score-plugin-dataflow/Dataflow/PortItem.hpp:13
QPointF newProcessPositionAfter(const IntervalModel &model, const Process::ProcessModel &previous) noexcept
Position for a node created right after previous in the signal chain.
Definition IntervalModel.cpp:1133
QSizeF nodeFootprint(const Process::ProcessModel &process) noexcept
Definition IntervalModel.cpp:1064
QPointF newProcessPositionBefore(const IntervalModel &model, const Process::ProcessModel &next, const Process::ProcessModel *created) noexcept
Definition IntervalModel.cpp:1143
QPointF freeProcessPosition(const IntervalModel &model, QPointF desired, QSizeF size, bool towardsRight, const Process::ProcessModel *ignore) noexcept
Definition IntervalModel.cpp:1086
Base toolkit upon which the software is built.
Definition Application.cpp:113
STL namespace.
Definition dataStructures.hpp:40
Definition IntervalModel.hpp:386
Definition Slot.hpp:86
Definition Slot.hpp:54
Definition TimeValue.hpp:21
Definition DocumentContext.hpp:18