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
98 double heightPercentage() const noexcept;
99
100 void startExecution();
101 void stopExecution();
102 // Resets the execution display recursively
103 void reset();
104
105 void setHeightPercentage(double arg);
106 void setExecutionState(IntervalExecutionState);
107
108 IntervalExecutionState executionState() const;
109
110 // Mode
111 enum ViewMode : bool
112 {
113 Temporal = 0,
114 Nodal = 1
115 };
116 ViewMode viewMode() const noexcept;
117 void setViewMode(ViewMode v);
118 void viewModeChanged(ViewMode v)
119 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, viewModeChanged, v)
120
121 // Node view properties (both small and full view)
122 QPointF nodalOffset() const noexcept;
123 void setNodalOffset(QPointF offs);
124 double nodalScale() const noexcept;
125 void setNodalScale(double z);
126
127 // Full view properties:
128 ZoomRatio zoom() const noexcept;
129 void setZoom(const ::ZoomRatio& zoom);
130
131 TimeVal midTime() const noexcept;
132 void setMidTime(const TimeVal& value);
133
134 void setSmallViewVisible(bool);
135 bool smallViewVisible() const noexcept;
136
137 const Rack& smallView() const noexcept { return m_smallView; }
138 const FullRack& fullView() const noexcept { return m_fullView; }
139
140 void clearSmallView();
141 void clearFullView();
142 void replaceSmallView(const Rack& other);
143 void replaceFullView(const FullRack& other);
144
145 // Adding and removing slots and layers is only for the small view
146 void addSlot(Slot s);
147 void addSlot(Slot s, int pos);
148 void removeSlot(int pos);
149
150 void addLayer(int slot, Id<Process::ProcessModel>);
151 void removeLayer(int slot, Id<Process::ProcessModel>);
152
153 void putLayerToFront(int slot, Id<Process::ProcessModel>);
154 void putLayerToFront(int slot, std::nullopt_t);
155
156 void swapSlots(int pos1, int pos2, Slot::RackView fullview);
157
158 double getSlotHeight(const SlotId& slot) const;
159 void setSlotHeight(const SlotId& slot, double height);
160 double getHeight() const noexcept;
161
163 double getSlotHeightForProcess(const Id<Process::ProcessModel>& p) const;
164
165 const Slot* findSmallViewSlot(int slot) const;
166 const Slot& getSmallViewSlot(int slot) const;
167 Slot& getSmallViewSlot(int slot);
168
169 const FullSlot* findFullViewSlot(int slot) const;
170 const FullSlot& getFullViewSlot(int slot) const;
171 FullSlot& getFullViewSlot(int slot);
172
173 bool muted() const noexcept { return m_muted; }
174 void setMuted(bool m);
175
176 bool graphal() const noexcept { return m_graphal; }
177 void setGraphal(bool m);
178
179 bool executing() const noexcept { return m_executing; }
180 void setExecuting(bool m);
181
182 // Tempo stuff
183 bool hasTimeSignature() const noexcept { return m_hasSignature; }
184 void setHasTimeSignature(bool b);
185
186 TimeVal contentDuration() const noexcept;
187
188 TempoProcess* tempoCurve() const noexcept;
189
190 void ancestorStartDateChanged();
191 void ancestorTempoChanged();
192
193 void addSignature(TimeVal t, ossia::time_signature sig);
194 void removeSignature(TimeVal t);
195 void setTimeSignatureMap(const TimeSignatureMap& map);
196 const TimeSignatureMap& timeSignatureMap() const noexcept;
197
198 ossia::musical_sync quantizationRate() const noexcept;
199 void setQuantizationRate(ossia::musical_sync b);
200
201 void setStartMarker(TimeVal t);
202 TimeVal startMarker() const noexcept;
203
204 void hasTimeSignatureChanged(bool arg_1)
205 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, hasTimeSignatureChanged, arg_1)
206 void timeSignaturesChanged(const TimeSignatureMap& arg_1)
207 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, timeSignaturesChanged, arg_1)
208 void quantizationRateChanged(ossia::musical_sync arg)
209 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, quantizationRateChanged, arg)
210
211 void requestHeightChange(double y)
212 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, requestHeightChange, y)
213 void heightPercentageChanged(double arg_1)
214 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, heightPercentageChanged, arg_1)
215
216 void dateChanged(const TimeVal& arg_1)
217 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, dateChanged, arg_1)
218 void startMarkerChanged(const TimeVal& arg_1)
219 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, startMarkerChanged, arg_1)
220
221 void focusChanged(bool arg_1)
222 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, focusChanged, arg_1)
223 void executionStateChanged(Scenario::IntervalExecutionState arg_1)
224 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, executionStateChanged, arg_1)
225
226 void executionEvent(Scenario::IntervalExecutionEvent ev)
227 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, executionEvent, ev)
228
229 void smallViewVisibleChanged(bool fv)
230 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, smallViewVisibleChanged, fv)
231
232 void rackChanged(Scenario::Slot::RackView fv)
233 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, rackChanged, fv)
234 void slotAdded(Scenario::SlotId arg_1)
235 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, slotAdded, arg_1)
236 void slotRemoved(Scenario::SlotId arg_1)
237 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, slotRemoved, arg_1)
238 void slotResized(Scenario::SlotId arg_1)
239 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, slotResized, arg_1)
240 void slotsSwapped(int slot1, int slot2, Slot::RackView fv)
241 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, slotsSwapped, slot1, slot2, fv)
242 void heightFinishedChanging()
243 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, heightFinishedChanging)
244
245 void layerAdded(Scenario::SlotId arg_1, Id<Process::ProcessModel> arg_2)
246 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, layerAdded, arg_1, arg_2)
247 void layerRemoved(Scenario::SlotId arg_1, Id<Process::ProcessModel> arg_2)
248 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, layerRemoved, arg_1, arg_2)
249 void frontLayerChanged(int arg_1, OptionalId<Process::ProcessModel> arg_2)
250 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, frontLayerChanged, arg_1, arg_2)
251
252 void mutedChanged(bool arg_1)
253 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, mutedChanged, arg_1)
254 void executingChanged(bool arg_1)
255 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, executingChanged, arg_1)
256
257 void busChanged(bool arg_1) E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, busChanged, arg_1)
258
259 void graphalChanged(bool arg_1)
260 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, graphalChanged, arg_1)
261
262 void nodalOffsetChanged(QPointF arg_1)
263 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, nodalOffsetChanged, arg_1)
264 void nodalScaleChanged(double arg_1)
265 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, nodalScaleChanged, arg_1)
266
267 PROPERTY(bool, muted READ muted WRITE setMuted NOTIFY mutedChanged)
268 PROPERTY(bool, graphal READ graphal WRITE setGraphal NOTIFY graphalChanged)
269 PROPERTY(
270 double, heightPercentage READ heightPercentage WRITE setHeightPercentage NOTIFY
271 heightPercentageChanged)
272
273 PROPERTY(
274 bool, timeSignature READ hasTimeSignature WRITE setHasTimeSignature NOTIFY
275 hasTimeSignatureChanged)
276
277 PROPERTY(
278 ossia::musical_sync, quantizationRate READ quantizationRate WRITE
279 setQuantizationRate NOTIFY quantizationRateChanged)
280private:
281 void on_addProcess(Process::ProcessModel&);
282 void on_removingProcess(const Process::ProcessModel&);
283 void initConnections();
284
285 // Model for the full view.
286 // Note : it is also present in m_intervalViewModels.
287 const score::DocumentContext& m_context;
288
289 Rack m_smallView;
290 FullRack m_fullView;
291
292 TimeSignatureMap m_signatures;
293
294 Id<StateModel> m_startState;
295 Id<StateModel> m_endState;
296
297 TimeVal m_startMarker;
298
299 TimeVal m_date;
300 double m_heightPercentage{0.5};
301
302 double m_nodalFullViewSlotHeight{100};
303 double m_quantRate{-1.0};
304
305 ::ZoomRatio m_zoom{-1};
306 TimeVal m_center{};
307 QPointF m_nodalOffset{};
308 double m_nodalScale{1.0};
309 IntervalExecutionState m_executionState : 2;
310 ViewMode m_viewMode : 1;
311 bool m_smallViewShown : 1;
312 bool m_muted : 1;
313 bool m_executing : 1;
314
315 bool m_hasSignature : 1;
316 bool m_graphal : 1;
317};
318
319SCORE_PLUGIN_SCENARIO_EXPORT
320bool isInFullView(const Scenario::IntervalModel& cstr) noexcept;
321SCORE_PLUGIN_SCENARIO_EXPORT
322bool isInFullView(const Process::ProcessModel& cstr) noexcept;
323
324SCORE_PLUGIN_SCENARIO_EXPORT
325bool isBus(
326 const Scenario::IntervalModel& model, const score::DocumentContext& ctx) noexcept;
327
328SCORE_PLUGIN_SCENARIO_EXPORT
329QPointF newProcessPosition(const Scenario::IntervalModel& model) noexcept;
330
332{
333 const IntervalModel* parent;
334 const IntervalModel* lastFound;
335 TimeVal delta;
336};
337
338SCORE_PLUGIN_SCENARIO_EXPORT
339IntervalModel* closestParentInterval(const QObject*) noexcept;
340
341SCORE_PLUGIN_SCENARIO_EXPORT
342ParentTimeInfo closestParentWithMusicalMetrics(const IntervalModel*);
343SCORE_PLUGIN_SCENARIO_EXPORT
344ParentTimeInfo closestParentWithTempo(const IntervalModel*);
345SCORE_PLUGIN_SCENARIO_EXPORT
346ParentTimeInfo closestParentWithQuantification(const IntervalModel* self);
347
348SCORE_PLUGIN_SCENARIO_EXPORT
349TimeVal timeDelta(const IntervalModel* child, const IntervalModel* parent);
350}
351
352DEFAULT_MODEL_METADATA(Scenario::IntervalModel, "Interval")
353
354Q_DECLARE_METATYPE(Scenario::IntervalModel::ViewMode)
355W_REGISTER_ARGTYPE(Scenario::IntervalModel::ViewMode)
356Q_DECLARE_METATYPE(QPointer<Scenario::IntervalModel>)
357W_REGISTER_ARGTYPE(QPointer<Scenario::IntervalModel>)
358
359TR_TEXT_METADATA(, Scenario::IntervalModel, PrettyName_k, "Interval")
360
361Q_DECLARE_METATYPE(Scenario::IntervalModel*)
362W_REGISTER_ARGTYPE(Scenario::IntervalModel*)
363Q_DECLARE_METATYPE(const Scenario::IntervalModel*)
364W_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:61
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:57
Base for complex model objects.
Definition EntityBase.hpp:24
The EntityMap class.
Definition EntityMap.hpp:36
Utilities and base classes for 1D curves.
Definition FocusDispatcher.hpp:12
Base classes and tools to implement processes and layers.
Definition JSONVisitor.hpp:1324
Main plug-in of score.
Definition score-plugin-dataflow/Dataflow/PortItem.hpp:13
Base toolkit upon which the software is built.
Definition Application.cpp:90
Definition dataStructures.hpp:40
Definition IntervalModel.hpp:332
Definition Slot.hpp:54
Definition TimeValue.hpp:21
Definition DocumentContext.hpp:18