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.
57{
59 return;
60
62
63 auto coroutine_func = [](std::vector<TimedEvent> events,
64 uint64_t rate,
65 std::function<void()> on_complete_callback,
68
69 for (
size_t iteration = 0; iteration <
repeat_count; ++iteration) {
70 for (const auto& event : events) {
71 if (promise.should_terminate) {
72 break;
73 }
74
76 try {
77 if (event.action) {
78 event.action();
79 }
80 } catch (const std::exception& e) {
84 "Exception in EventChain action: {}", e.what());
85 } catch (...) {
89 "Unknown exception in EventChain action");
90 }
91 }
92
93 if (promise.should_terminate) {
94 break;
95 }
96 }
97
98 if (on_complete_callback) {
99 try {
100 on_complete_callback();
101 } catch (const std::exception& e) {
105 "Exception in EventChain on_complete: {}", e.what());
106 } catch (...) {
110 "Unknown exception in EventChain on_complete");
111 }
112 }
113 };
114
116 m_routine = std::make_shared<Vruta::SoundRoutine>(
119}
#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.
bool m_on_complete_fired
Flag to ensure on_complete is only fired once.
size_t repeat_count() const
Gets the repeat count for the entire chain.
std::string m_name
Optional name for the event chain.
std::shared_ptr< Vruta::SoundRoutine > m_routine
The underlying computational routine that implements the chain.
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::audio_promise > GetAudioPromise
Audio domain promise accessor.
uint64_t seconds_to_samples(double seconds, uint32_t sample_rate)
Convert seconds to samples at a given sample rate.