Loading...
Searching...
No Matches
ScriptableScenarioComponent.hpp
1#pragma once
2#include <Scenario/Document/Components/IntervalComponent.hpp>
3#include <Scenario/Document/Components/ScenarioComponent.hpp>
4
5#include <LocalTree/ScriptableProcessComponent.hpp>
6
7#include <ossia/detail/algorithms.hpp>
8#include <ossia/editor/scenario/time_sync.hpp>
9
10#include <nano_observer.hpp>
11
12#include <atomic>
13#include <thread>
14
15namespace ossia
16{
17class time_sync;
18}
19
20namespace LocalTree
21{
23class SCORE_PLUGIN_SCENARIO_EXPORT ScriptableTimeSync final
24 : public score::GenericComponent<const score::DocumentContext>
25{
26 COMMON_COMPONENT_METADATA("eeb9acf5-466a-473d-baf9-861427364dcf")
27public:
28 static constexpr bool is_unique = true;
31 const score::DocumentContext& ctx, QObject* parent);
33
34 ossia::net::node_base* node() const noexcept { return m_node; }
35
37 struct Execution
38 {
40 void attach(ossia::time_sync* s) noexcept { m_sync.store(s); }
41 void detach() noexcept
42 {
43 m_sync.store(nullptr);
44 while(m_users.load() != 0)
45 std::this_thread::yield();
46 }
47 ossia::time_sync* attached() const noexcept { return m_sync.load(); }
49 bool trigger() noexcept
50 {
51 m_users.fetch_add(1);
52 auto sync = m_sync.load();
53 if(sync)
54 sync->start_trigger_request();
55 m_users.fetch_sub(1);
56 return sync;
57 }
58
59 private:
60 std::atomic<ossia::time_sync*> m_sync{};
61 std::atomic_int m_users{};
62 };
63 const std::shared_ptr<Execution>& execution() const noexcept { return m_execution; }
64
65private:
66 void refresh();
67
68 ScriptableRoots m_roots;
70 ossia::net::node_base* m_node{};
71 GivenName m_given;
72 std::unique_ptr<ParameterBinding> m_trigger;
73 std::shared_ptr<Execution> m_execution = std::make_shared<Execution>();
74};
75
77class SCORE_PLUGIN_SCENARIO_EXPORT ScriptableEvent final
78 : public score::GenericComponent<const score::DocumentContext>
79{
80 COMMON_COMPONENT_METADATA("90d9d6d6-9b98-4e2e-9c4b-8d834706472e")
81public:
82 static constexpr bool is_unique = true;
85 const score::DocumentContext& ctx, QObject* parent);
87
88 ossia::net::node_base* node() const noexcept { return m_node; }
89
90private:
91 void refresh();
92
93 ScriptableRoots m_roots;
94 Scenario::EventModel& m_event;
95 ossia::net::node_base* m_node{};
96 GivenName m_given;
97};
98
100class SCORE_PLUGIN_SCENARIO_EXPORT ScriptableState final
101 : public score::GenericComponent<const score::DocumentContext>
102{
103 COMMON_COMPONENT_METADATA("b03c26f1-9f6d-4dcd-bdbd-6c63d70eee62")
104public:
105 static constexpr bool is_unique = true;
108 const score::DocumentContext& ctx, QObject* parent);
109};
110
112class SCORE_PLUGIN_SCENARIO_EXPORT ScriptableInterval final
113 : public Scenario::GenericIntervalComponent<const score::DocumentContext>
114 , public Nano::Observer
115{
116 COMMON_COMPONENT_METADATA("b49b38e4-5b79-4f24-8c58-873d8987b98e")
117public:
118 static constexpr bool is_unique = true;
119
122 const score::DocumentContext& ctx, QObject* parent);
124
125private:
126 void add(Process::ProcessModel& proc);
127 void remove(const Process::ProcessModel& proc);
128
129 ScriptableRoots m_roots;
130 std::vector<std::pair<Process::ProcessModel*, ScriptableProcessBase*>> m_children;
131};
132
133class SCORE_PLUGIN_SCENARIO_EXPORT ScriptableScenarioBase
134 : public Process::GenericProcessComponent_T<ScriptableProcessBase, Scenario::ProcessModel>
135{
136 COMPONENT_METADATA("4084de06-cbb0-4e3c-915f-6337946f37e2")
137public:
140 const score::DocumentContext& ctx, QObject* parent);
141
142 template <typename Component_T, typename Element>
143 Component_T* make(Element& elt);
144
145 template <typename... Args>
146 bool removing(Args&&...)
147 {
148 return true;
149 }
150 template <typename... Args>
151 void removed(Args&&...)
152 {
153 }
154
155private:
156 ScriptableRoots m_roots;
157};
158
162
163class SCORE_PLUGIN_SCENARIO_EXPORT ScriptableScenarioFactory final
165{
166 SCORE_CONCRETE("74f159f0-0ab8-4a3f-bf2a-16a286d95c54")
167public:
168 bool matches(const Process::ProcessModel& proc) const noexcept override;
171 const score::DocumentContext& ctx, QObject* parent) const override;
172};
173
174SCORE_PLUGIN_SCENARIO_EXPORT ::State::Address scriptableAddress(const Scenario::TimeSyncModel&);
175SCORE_PLUGIN_SCENARIO_EXPORT ::State::Address scriptableAddress(const Scenario::EventModel&);
176}
Definition Scenario/Document/Components/ScenarioComponent.hpp:198
score:/conditions/<name>: a boolean for the event's expression to read.
Definition ScriptableScenarioComponent.hpp:79
Tracks the processes of an interval, and the hierarchy below a scenario.
Definition ScriptableScenarioComponent.hpp:115
Definition ScriptableProcessComponent.hpp:198
For processes containing other processes; others use ScriptableProcessComponent.
Definition ScriptableProcessComponent.hpp:255
Definition ScriptableScenarioComponent.hpp:135
Definition ScriptableScenarioComponent.hpp:165
Registers the state in the ReferenceIndex, since it holds messages.
Definition ScriptableScenarioComponent.hpp:102
score:/triggers/<name>: an impulse that fires the sync.
Definition ScriptableScenarioComponent.hpp:25
Definition Process/ProcessComponent.hpp:34
The Process class.
Definition score-lib-process/Process/Process.hpp:80
Definition EventModel.hpp:36
Definition Scenario/Document/Components/IntervalComponent.hpp:12
Definition IntervalModel.hpp:50
The core hierarchical and temporal process of score.
Definition ScenarioModel.hpp:37
Definition StateModel.hpp:62
Definition TimeSyncModel.hpp:34
A component that has a reference to a specific context object.
Definition lib/score/model/Component.hpp:58
Components used for the execution of a score.
Definition ProcessComponent.cpp:14
Local tree provides a way to extend the tree given through the Engine::Network::LocalDevice.
Definition BaseCallbackWrapper.hpp:9
::State::Address scriptableAddress(const Process::ProcessModel &proc)
score:/controls/<process>[/<port>|/preset]; empty when not published.
Definition ScriptableProcessComponent.cpp:819
Definition ScriptableProcessComponent.hpp:143
Definition ScriptableProcessComponent.hpp:58
void attach(ossia::time_sync *s) noexcept
detach() waits for the triggers in flight; only the GUI thread calls it
Definition ScriptableScenarioComponent.hpp:40
bool trigger() noexcept
False when no execution is attached.
Definition ScriptableScenarioComponent.hpp:49
Definition ObjectMatches.hpp:6
Definition DocumentContext.hpp:18