Starts executing the event chain.
This method begins the execution of the event chain, scheduling each event to occur at its specified time. The events are executed in the order they were added, with the specified delays between them.
The timing is sample-accurate, ensuring that each event occurs at precisely the right moment in the computational timeline.
56{
58 return;
59
61
62 auto s_coro_func = [](std::vector<TimedEvent> events,
63 uint64_t rate,
64 std::function<void()> on_complete_callback,
67
68 for (
size_t iteration = 0; iteration <
repeat_count; ++iteration) {
69 for (const auto& event : events) {
70 if (promise.should_terminate) {
71 break;
72 }
73
75 try {
76 if (event.action) {
77 event.action();
78 }
79 } catch (const std::exception& e) {
83 "Exception in EventChain action: {}", e.what());
84 } catch (...) {
88 "Unknown exception in EventChain action");
89 }
90 }
91
92 if (promise.should_terminate) {
93 break;
94 }
95 }
96
97 if (on_complete_callback) {
98 try {
99 on_complete_callback();
100 } catch (const std::exception& e) {
104 "Exception in EventChain on_complete: {}", e.what());
105 } catch (...) {
109 "Unknown exception in EventChain on_complete");
110 }
111 }
112 };
113
114 auto g_coro_func = [](std::vector<TimedEvent> events,
115 uint64_t rate,
116 std::function<void()> on_complete_callback,
119
120 for (
size_t iteration = 0; iteration <
repeat_count; ++iteration) {
121 for (const auto& event : events) {
122 if (promise.should_terminate) {
123 break;
124 }
125
127 try {
128 if (event.action) {
129 event.action();
130 }
131 } catch (const std::exception& e) {
135 "Exception in EventChain action: {}", e.what());
136 } catch (...) {
140 "Unknown exception in EventChain action");
141 }
142 }
143
144 if (promise.should_terminate) {
145 break;
146 }
147 }
148
149 if (on_complete_callback) {
150 try {
151 on_complete_callback();
152 } catch (const std::exception& e) {
156 "Exception in EventChain on_complete: {}", e.what());
157 } catch (...) {
161 "Unknown exception in EventChain on_complete");
162 }
163 }
164 };
165
167
169 m_routine = std::make_shared<Vruta::SoundRoutine>(
171 } else {
172 m_routine = std::make_shared<Vruta::GraphicsRoutine>(
174 }
175
177}
#define MF_RT_ERROR(comp, ctx,...)
Vruta::TaskScheduler & m_Scheduler
Reference to the scheduler that manages timing.
size_t m_repeat_count
Number of times to repeat the entire chain.
std::function< void()> m_on_complete
Optional callback to execute when the chain completes.
std::vector< TimedEvent > m_events
Collection of events in this chain.
Vruta::ProcessingToken m_token
Processing token to determine which scheduler rate to use.
bool m_on_complete_fired
Flag to ensure on_complete is only fired once.
std::shared_ptr< Vruta::Routine > m_routine
The underlying computational routine that implements the chain.
size_t repeat_count() const
Gets the repeat count for the entire chain.
std::string m_name
Optional name for the event chain.
A C++20 coroutine-based graphics processing task with frame-accurate timing.
A C++20 coroutine-based audio processing task with sample-accurate timing.
void add_task(const std::shared_ptr< Routine > &routine, const std::string &name="", bool initialize=false)
Add a routine to the scheduler based on its processing token.
uint64_t get_next_task_id() const
Generates a unique task ID for new tasks.
@ CoroutineScheduling
Coroutine scheduling and temporal coordination (Vruta::TaskScheduler)
@ Kriya
Automatable tasks and fluent scheduling api for Nodes and Buffers.
GetPromiseBase< Vruta::graphics_promise > GetGraphicsPromise
Graphics domain promise accessor.
GetPromiseBase< Vruta::audio_promise > GetAudioPromise
Audio domain promise accessor.
uint64_t seconds_to_samples(double seconds, uint32_t sample_rate=s_registered_sample_rate)
Convert seconds to samples at a given sample rate.
@ SAMPLE_ACCURATE
Coroutine is sample-accurate.
uint64_t seconds_to_frames(double seconds, uint32_t frame_rate=s_registered_frame_rate)
Convert seconds to frames at a given frame rate.