ScenarioPaletteBaseEvents.hpp
1 #pragma once
2 #include "ScenarioPoint.hpp"
3 
4 #include <Scenario/Document/Interval/Slot.hpp>
5 
6 #include <score/statemachine/StateMachineUtils.hpp>
7 #include <score/tools/Clamp.hpp>
8 
9 namespace score
10 {
11 template <>
12 struct PositionedEvent<Scenario::Point> : public QEvent
13 {
14  PositionedEvent(const Scenario::Point& pt, QEvent::Type type)
15  : QEvent{type}
16  , point(pt)
17  {
18  // Here we artificially prevent to move over the header of the rack
19  // so that the elements won't disappear in the void.
20  if(point.date.impl < 0)
21  point.date.impl = 0;
22  point.y = clamp(point.y, 0.004, 0.99);
23  }
24 
25  ~PositionedEvent() override = default;
26 
27  Scenario::Point point;
28 };
29 }
30 
31 namespace Scenario
32 {
33 class TimeSyncModel;
34 class EventModel;
35 class IntervalModel;
36 class StateModel;
37 class TriggerModel;
38 
39 // We avoid virtual inheritance (with Numbered event);
40 // this replicates a tiny bit of code.
41 template <int N>
42 struct PositionedScenarioEvent : public score::PositionedEvent<Scenario::Point>
43 {
44  static constexpr const int user_type = N;
46  : PositionedEvent<Scenario::Point>{pt, QEvent::Type(QEvent::User + N)}
47  {
48  }
49 };
50 
51 template <typename Element, int N>
53 {
56  , id{tn_id}
57  {
58  }
59 
60  Id<Element> id;
61 };
62 
64 // Events
65 enum ScenarioElement
66 {
67  Nothing,
68  TimeSync,
69  Event,
70  Interval,
71  State,
72  SlotOverlay_e,
73  SlotHandle_e,
74  Trigger,
75  LeftBrace,
76  RightBrace
77 };
78 
79 static const constexpr int ClickOnNothing
80  = ScenarioElement::Nothing + score::Modifier::Click_tag::value;
81 static const constexpr int ClickOnTimeSync
82  = ScenarioElement::TimeSync + score::Modifier::Click_tag::value;
83 static const constexpr int ClickOnEvent
84  = ScenarioElement::Event + score::Modifier::Click_tag::value;
85 static const constexpr int ClickOnInterval
86  = ScenarioElement::Interval + score::Modifier::Click_tag::value;
87 static const constexpr int ClickOnState
88  = ScenarioElement::State + score::Modifier::Click_tag::value;
89 static const constexpr int ClickOnSlotHandle
90  = ScenarioElement::SlotHandle_e + score::Modifier::Click_tag::value;
91 static const constexpr int ClickOnTrigger
92  = ScenarioElement::Trigger + score::Modifier::Click_tag::value;
93 static const constexpr int ClickOnLeftBrace
94  = ScenarioElement::LeftBrace + score::Modifier::Click_tag::value;
95 static const constexpr int ClickOnRightBrace
96  = ScenarioElement::RightBrace + score::Modifier::Click_tag::value;
97 
98 static const constexpr int MoveOnNothing
99  = ScenarioElement::Nothing + score::Modifier::Move_tag::value;
100 static const constexpr int MoveOnTimeSync
101  = ScenarioElement::TimeSync + score::Modifier::Move_tag::value;
102 static const constexpr int MoveOnEvent
103  = ScenarioElement::Event + score::Modifier::Move_tag::value;
104 static const constexpr int MoveOnInterval
105  = ScenarioElement::Interval + score::Modifier::Move_tag::value;
106 static const constexpr int MoveOnState
107  = ScenarioElement::State + score::Modifier::Move_tag::value;
108 static const constexpr int MoveOnSlotHandle
109  = ScenarioElement::SlotHandle_e + score::Modifier::Move_tag::value;
110 static const constexpr int MoveOnTrigger
111  = ScenarioElement::Trigger + score::Modifier::Move_tag::value;
112 static const constexpr int MoveOnLeftBrace
113  = ScenarioElement::LeftBrace + score::Modifier::Move_tag::value;
114 static const constexpr int MoveOnRightBrace
115  = ScenarioElement::RightBrace + score::Modifier::Move_tag::value;
116 
117 static const constexpr int ReleaseOnNothing
118  = ScenarioElement::Nothing + score::Modifier::Release_tag::value;
119 static const constexpr int ReleaseOnTimeSync
120  = ScenarioElement::TimeSync + score::Modifier::Release_tag::value;
121 static const constexpr int ReleaseOnEvent
122  = ScenarioElement::Event + score::Modifier::Release_tag::value;
123 static const constexpr int ReleaseOnInterval
124  = ScenarioElement::Interval + score::Modifier::Release_tag::value;
125 static const constexpr int ReleaseOnState
126  = ScenarioElement::State + score::Modifier::Release_tag::value;
127 static const constexpr int ReleaseOnSlotHandle
128  = ScenarioElement::SlotHandle_e + score::Modifier::Release_tag::value;
129 static const constexpr int ReleaseOnTrigger
130  = ScenarioElement::Trigger + score::Modifier::Release_tag::value;
131 static const constexpr int ReleaseOnLeftBrace
132  = ScenarioElement::LeftBrace + score::Modifier::Release_tag::value;
133 static const constexpr int ReleaseOnRightBrace
134  = ScenarioElement::RightBrace + score::Modifier::Release_tag::value;
135 
136 /* click */
137 using ClickOnNothing_Event = PositionedScenarioEvent<ClickOnNothing>;
138 using ClickOnTimeSync_Event
139  = PositionedWithId_ScenarioEvent<TimeSyncModel, ClickOnTimeSync>;
140 using ClickOnEvent_Event = PositionedWithId_ScenarioEvent<EventModel, ClickOnEvent>;
141 using ClickOnInterval_Event
142  = PositionedWithId_ScenarioEvent<IntervalModel, ClickOnInterval>;
143 using ClickOnState_Event = PositionedWithId_ScenarioEvent<StateModel, ClickOnState>;
145 using ClickOnLeftBrace_Event
146  = PositionedWithId_ScenarioEvent<IntervalModel, ClickOnLeftBrace>;
147 using ClickOnRightBrace_Event
148  = PositionedWithId_ScenarioEvent<IntervalModel, ClickOnRightBrace>;
149 
150 /* move on */
151 using MoveOnNothing_Event = PositionedScenarioEvent<MoveOnNothing>;
152 using MoveOnTimeSync_Event
153  = PositionedWithId_ScenarioEvent<TimeSyncModel, MoveOnTimeSync>;
154 using MoveOnEvent_Event = PositionedWithId_ScenarioEvent<EventModel, MoveOnEvent>;
155 using MoveOnInterval_Event
156  = PositionedWithId_ScenarioEvent<IntervalModel, MoveOnInterval>;
157 using MoveOnState_Event = PositionedWithId_ScenarioEvent<StateModel, MoveOnState>;
159 using MoveOnLeftBrace_Event
160  = PositionedWithId_ScenarioEvent<IntervalModel, MoveOnLeftBrace>;
161 using MoveOnRightBrace_Event
162  = PositionedWithId_ScenarioEvent<IntervalModel, MoveOnRightBrace>;
163 
164 /* release on */
165 using ReleaseOnNothing_Event = PositionedScenarioEvent<ReleaseOnNothing>;
166 using ReleaseOnTimeSync_Event
167  = PositionedWithId_ScenarioEvent<TimeSyncModel, ReleaseOnTimeSync>;
168 using ReleaseOnEvent_Event = PositionedWithId_ScenarioEvent<EventModel, ReleaseOnEvent>;
169 using ReleaseOnInterval_Event
170  = PositionedWithId_ScenarioEvent<IntervalModel, ReleaseOnInterval>;
171 using ReleaseOnState_Event = PositionedWithId_ScenarioEvent<StateModel, ReleaseOnState>;
172 using ReleaseOnTrigger_Event
174 using ReleaseOnLeftBrace_Event
175  = PositionedWithId_ScenarioEvent<IntervalModel, ReleaseOnLeftBrace>;
176 using ReleaseOnRightBrace_Event
177  = PositionedWithId_ScenarioEvent<IntervalModel, ReleaseOnRightBrace>;
178 
179 // using ReleaseOnSlotHandle_Event
180 // = score::NumberedWithPath_Event<IntervalModel, ReleaseOnSlotHandle>;
181 // using MoveOnSlotHandle_Event
182 // = score::NumberedWithPath_Event<IntervalModel, MoveOnSlotHandle>;
183 // using ClickOnSlotHandle_Event
184 // = score::NumberedWithPath_Event<IntervalModel, ClickOnSlotHandle>;
185 struct ClickOnSlotHandle_Event : public score::NumberedEvent<ClickOnSlotHandle>
186 {
187  explicit ClickOnSlotHandle_Event(const SlotPath& p)
188  : NumberedEvent<ClickOnSlotHandle>()
189  , path(p)
190  {
191  }
192 
193  explicit ClickOnSlotHandle_Event(SlotPath&& p)
194  : NumberedEvent<ClickOnSlotHandle>()
195  , path(std::move(p))
196  {
197  }
198 
199  SlotPath path;
200 };
201 
202 struct MoveOnSlotHandle_Event : public score::NumberedEvent<MoveOnSlotHandle>
203 {
204  explicit MoveOnSlotHandle_Event(const SlotPath& p)
205  : NumberedEvent<MoveOnSlotHandle>()
206  , path(p)
207  {
208  }
209 
210  explicit MoveOnSlotHandle_Event(SlotPath&& p)
211  : NumberedEvent<MoveOnSlotHandle>()
212  , path(std::move(p))
213  {
214  }
215 
216  SlotPath path;
217 };
218 
219 // using ReleaseOnSlotHandle_Event
220 // = score::NumberedWithPath_Event<IntervalModel, ReleaseOnSlotHandle>;
221 struct ReleaseOnSlotHandle_Event : public score::NumberedEvent<ReleaseOnSlotHandle>
222 {
223  explicit ReleaseOnSlotHandle_Event(const SlotPath& p)
224  : NumberedEvent<ReleaseOnSlotHandle>()
225  , path(p)
226  {
227  }
228 
229  explicit ReleaseOnSlotHandle_Event(SlotPath&& p)
230  : NumberedEvent<ReleaseOnSlotHandle>()
231  , path(std::move(p))
232  {
233  }
234 
235  SlotPath path;
236 };
237 
238 template <int N>
239 QString debug_StateMachineIDs()
240 {
241  QString txt;
242 
243  auto object = static_cast<ScenarioElement>(N % 10);
244  auto modifier = static_cast<score::Modifier_tagme>((N - object) % 1000 / 100);
245  switch(modifier)
246  {
247  case score::Modifier_tagme::Click:
248  txt += "Click on";
249  break;
250  case score::Modifier_tagme::Move:
251  txt += "Move on";
252  break;
253  case score::Modifier_tagme::Release:
254  txt += "Release on";
255  break;
256  }
257 
258  switch(object)
259  {
260  case ScenarioElement::Nothing:
261  txt += "nothing";
262  break;
263  case ScenarioElement::TimeSync:
264  txt += "Sync";
265  break;
266  case ScenarioElement::Event:
267  txt += "Event";
268  break;
269  case ScenarioElement::Interval:
270  txt += "Interval";
271  break;
272  case ScenarioElement::State:
273  txt += "State";
274  break;
275  case ScenarioElement::SlotOverlay_e:
276  txt += "SlotOverlay_e";
277  break;
278  case ScenarioElement::SlotHandle_e:
279  txt += "SlotHandle_e";
280  break;
281  case ScenarioElement::Trigger:
282  txt += "Trigger";
283  break;
284  case ScenarioElement::LeftBrace:
285  txt += "LeftBrace";
286  break;
287  case ScenarioElement::RightBrace:
288  txt += "RightBrace";
289  break;
290  }
291 
292  return txt;
293 }
294 }
The id_base_t class.
Definition: Identifier.hpp:57
Main plug-in of score.
Definition: score-plugin-dataflow/Dataflow/PortItem.hpp:14
Utilities for OSSIA data structures.
Definition: DeviceInterface.hpp:33
Base toolkit upon which the software is built.
Definition: Application.cpp:90
Definition: ScenarioPaletteBaseEvents.hpp:186
Definition: ScenarioPaletteBaseEvents.hpp:203
Definition: ScenarioPoint.hpp:13
Definition: ScenarioPaletteBaseEvents.hpp:43
Definition: ScenarioPaletteBaseEvents.hpp:53
Definition: ScenarioPaletteBaseEvents.hpp:222
Definition: Slot.hpp:54
Definition: StateMachineUtils.hpp:18
Definition: StateMachineUtils.hpp:28
Definition: StateMachineUtils.hpp:46