Loading...
Searching...
No Matches
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
9namespace score
10{
11template <>
12struct 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
31namespace Scenario
32{
33class TimeSyncModel;
34class EventModel;
35class IntervalModel;
36class StateModel;
37class TriggerModel;
38
39// We avoid virtual inheritance (with Numbered event);
40// this replicates a tiny bit of code.
41template <int N>
42struct 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
51template <typename Element, int N>
53{
56 , id{tn_id}
57 {
58 }
59
60 Id<Element> id;
61};
62
64// Events
65enum 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
79static const constexpr int ClickOnNothing
80 = ScenarioElement::Nothing + score::Modifier::Click_tag::value;
81static const constexpr int ClickOnTimeSync
82 = ScenarioElement::TimeSync + score::Modifier::Click_tag::value;
83static const constexpr int ClickOnEvent
84 = ScenarioElement::Event + score::Modifier::Click_tag::value;
85static const constexpr int ClickOnInterval
86 = ScenarioElement::Interval + score::Modifier::Click_tag::value;
87static const constexpr int ClickOnState
88 = ScenarioElement::State + score::Modifier::Click_tag::value;
89static const constexpr int ClickOnSlotHandle
90 = ScenarioElement::SlotHandle_e + score::Modifier::Click_tag::value;
91static const constexpr int ClickOnTrigger
92 = ScenarioElement::Trigger + score::Modifier::Click_tag::value;
93static const constexpr int ClickOnLeftBrace
94 = ScenarioElement::LeftBrace + score::Modifier::Click_tag::value;
95static const constexpr int ClickOnRightBrace
96 = ScenarioElement::RightBrace + score::Modifier::Click_tag::value;
97
98static const constexpr int MoveOnNothing
99 = ScenarioElement::Nothing + score::Modifier::Move_tag::value;
100static const constexpr int MoveOnTimeSync
101 = ScenarioElement::TimeSync + score::Modifier::Move_tag::value;
102static const constexpr int MoveOnEvent
103 = ScenarioElement::Event + score::Modifier::Move_tag::value;
104static const constexpr int MoveOnInterval
105 = ScenarioElement::Interval + score::Modifier::Move_tag::value;
106static const constexpr int MoveOnState
107 = ScenarioElement::State + score::Modifier::Move_tag::value;
108static const constexpr int MoveOnSlotHandle
109 = ScenarioElement::SlotHandle_e + score::Modifier::Move_tag::value;
110static const constexpr int MoveOnTrigger
111 = ScenarioElement::Trigger + score::Modifier::Move_tag::value;
112static const constexpr int MoveOnLeftBrace
113 = ScenarioElement::LeftBrace + score::Modifier::Move_tag::value;
114static const constexpr int MoveOnRightBrace
115 = ScenarioElement::RightBrace + score::Modifier::Move_tag::value;
116
117static const constexpr int ReleaseOnNothing
118 = ScenarioElement::Nothing + score::Modifier::Release_tag::value;
119static const constexpr int ReleaseOnTimeSync
120 = ScenarioElement::TimeSync + score::Modifier::Release_tag::value;
121static const constexpr int ReleaseOnEvent
122 = ScenarioElement::Event + score::Modifier::Release_tag::value;
123static const constexpr int ReleaseOnInterval
124 = ScenarioElement::Interval + score::Modifier::Release_tag::value;
125static const constexpr int ReleaseOnState
126 = ScenarioElement::State + score::Modifier::Release_tag::value;
127static const constexpr int ReleaseOnSlotHandle
128 = ScenarioElement::SlotHandle_e + score::Modifier::Release_tag::value;
129static const constexpr int ReleaseOnTrigger
130 = ScenarioElement::Trigger + score::Modifier::Release_tag::value;
131static const constexpr int ReleaseOnLeftBrace
132 = ScenarioElement::LeftBrace + score::Modifier::Release_tag::value;
133static const constexpr int ReleaseOnRightBrace
134 = ScenarioElement::RightBrace + score::Modifier::Release_tag::value;
135
136/* click */
137using ClickOnNothing_Event = PositionedScenarioEvent<ClickOnNothing>;
138using ClickOnTimeSync_Event
139 = PositionedWithId_ScenarioEvent<TimeSyncModel, ClickOnTimeSync>;
140using ClickOnEvent_Event = PositionedWithId_ScenarioEvent<EventModel, ClickOnEvent>;
141using ClickOnInterval_Event
142 = PositionedWithId_ScenarioEvent<IntervalModel, ClickOnInterval>;
143using ClickOnState_Event = PositionedWithId_ScenarioEvent<StateModel, ClickOnState>;
145using ClickOnLeftBrace_Event
146 = PositionedWithId_ScenarioEvent<IntervalModel, ClickOnLeftBrace>;
147using ClickOnRightBrace_Event
148 = PositionedWithId_ScenarioEvent<IntervalModel, ClickOnRightBrace>;
149
150/* move on */
151using MoveOnNothing_Event = PositionedScenarioEvent<MoveOnNothing>;
152using MoveOnTimeSync_Event
153 = PositionedWithId_ScenarioEvent<TimeSyncModel, MoveOnTimeSync>;
154using MoveOnEvent_Event = PositionedWithId_ScenarioEvent<EventModel, MoveOnEvent>;
155using MoveOnInterval_Event
156 = PositionedWithId_ScenarioEvent<IntervalModel, MoveOnInterval>;
157using MoveOnState_Event = PositionedWithId_ScenarioEvent<StateModel, MoveOnState>;
159using MoveOnLeftBrace_Event
160 = PositionedWithId_ScenarioEvent<IntervalModel, MoveOnLeftBrace>;
161using MoveOnRightBrace_Event
162 = PositionedWithId_ScenarioEvent<IntervalModel, MoveOnRightBrace>;
163
164/* release on */
165using ReleaseOnNothing_Event = PositionedScenarioEvent<ReleaseOnNothing>;
166using ReleaseOnTimeSync_Event
167 = PositionedWithId_ScenarioEvent<TimeSyncModel, ReleaseOnTimeSync>;
168using ReleaseOnEvent_Event = PositionedWithId_ScenarioEvent<EventModel, ReleaseOnEvent>;
169using ReleaseOnInterval_Event
170 = PositionedWithId_ScenarioEvent<IntervalModel, ReleaseOnInterval>;
171using ReleaseOnState_Event = PositionedWithId_ScenarioEvent<StateModel, ReleaseOnState>;
172using ReleaseOnTrigger_Event
174using ReleaseOnLeftBrace_Event
175 = PositionedWithId_ScenarioEvent<IntervalModel, ReleaseOnLeftBrace>;
176using 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>;
185struct ClickOnSlotHandle_Event : public score::NumberedEvent<ClickOnSlotHandle>
186{
187 explicit ClickOnSlotHandle_Event(const SlotPath& p)
188 : NumberedEvent<ClickOnSlotHandle>()
189 , path(p)
190 {
191 }
192
194 : NumberedEvent<ClickOnSlotHandle>()
195 , path(std::move(p))
196 {
197 }
198
199 SlotPath path;
200};
201
202struct 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>;
221struct ReleaseOnSlotHandle_Event : public score::NumberedEvent<ReleaseOnSlotHandle>
222{
223 explicit ReleaseOnSlotHandle_Event(const SlotPath& p)
224 : NumberedEvent<ReleaseOnSlotHandle>()
225 , path(p)
226 {
227 }
228
230 : NumberedEvent<ReleaseOnSlotHandle>()
231 , path(std::move(p))
232 {
233 }
234
235 SlotPath path;
236};
237
238template <int N>
239QString 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:13
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