MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ start()

void MayaFlux::Kriya::EventChain::start ( )

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.

Definition at line 55 of file Chain.cpp.

56{
57 if (m_events.empty())
58 return;
59
60 auto s_coro_func = [](std::vector<TimedEvent> events,
61 uint64_t rate,
63 auto& promise = co_await Kriya::GetAudioPromise {};
64
65 for (size_t iteration = 0; iteration < repeat_count; ++iteration) {
66 for (const auto& event : events) {
67 if (promise.should_terminate) {
68 break;
69 }
70
71 co_await SampleDelay { Vruta::seconds_to_samples(event.delay_seconds, rate) };
72 try {
73 if (event.action) {
74 event.action();
75 }
76 } catch (const std::exception& e) {
80 "Exception in EventChain action: {}", e.what());
81 } catch (...) {
85 "Unknown exception in EventChain action");
86 }
87 }
88
89 if (promise.should_terminate) {
90 break;
91 }
92 }
93 };
94
95 auto g_coro_func = [](std::vector<TimedEvent> events,
96 uint64_t rate,
98 auto& promise = co_await Kriya::GetGraphicsPromise {};
99
100 for (size_t iteration = 0; iteration < repeat_count; ++iteration) {
101 for (const auto& event : events) {
102 if (promise.should_terminate) {
103 break;
104 }
105
106 co_await FrameDelay { Vruta::seconds_to_frames(event.delay_seconds, rate) };
107 try {
108 if (event.action) {
109 event.action();
110 }
111 } catch (const std::exception& e) {
115 "Exception in EventChain action: {}", e.what());
116 } catch (...) {
120 "Unknown exception in EventChain action");
121 }
122 }
123
124 if (promise.should_terminate) {
125 break;
126 }
127 }
128 };
129
130 std::string task_name = m_name.empty() ? "EventChain_" + std::to_string(m_Scheduler.get_next_task_id()) : m_name;
131
133 m_routine = std::make_shared<Vruta::SoundRoutine>(
134 s_coro_func(m_events, m_default_rate, m_repeat_count));
135 } else {
136 m_routine = std::make_shared<Vruta::GraphicsRoutine>(
137 g_coro_func(m_events, m_default_rate, m_repeat_count));
138 }
139
140 if (m_on_complete) {
141 m_routine->on_complete(m_on_complete);
142 }
143
144 m_Scheduler.add_task(m_routine, task_name, true);
145}
#define MF_RT_ERROR(comp, ctx,...)
float rate
Vruta::TaskScheduler & m_Scheduler
Reference to the scheduler that manages timing.
Definition Chain.hpp:189
size_t m_repeat_count
Number of times to repeat the entire chain.
Definition Chain.hpp:225
std::function< void()> m_on_complete
Optional callback to execute when the chain completes.
Definition Chain.hpp:215
std::vector< TimedEvent > m_events
Collection of events in this chain.
Definition Chain.hpp:181
Vruta::ProcessingToken m_token
Processing token to determine which scheduler rate to use.
Definition Chain.hpp:198
std::shared_ptr< Vruta::Routine > m_routine
The underlying computational routine that implements the chain.
Definition Chain.hpp:206
size_t repeat_count() const
Gets the repeat count for the entire chain.
Definition Chain.hpp:161
std::string m_name
Optional name for the event chain.
Definition Chain.hpp:223
A C++20 coroutine-based graphics processing task with frame-accurate timing.
Definition Routine.hpp:512
A C++20 coroutine-based audio processing task with sample-accurate timing.
Definition Routine.hpp:327
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.
Definition Scheduler.cpp:94
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.

References MayaFlux::Vruta::TaskScheduler::add_task(), MayaFlux::Journal::CoroutineScheduling, MayaFlux::Vruta::TaskScheduler::get_next_task_id(), MayaFlux::Journal::Kriya, m_default_rate, m_events, m_name, m_on_complete, m_repeat_count, m_routine, m_Scheduler, m_token, MF_RT_ERROR, rate, repeat_count(), MayaFlux::Vruta::SAMPLE_ACCURATE, MayaFlux::Vruta::seconds_to_frames(), and MayaFlux::Vruta::seconds_to_samples().

+ Here is the call graph for this function: