12 : m_Scheduler(scheduler)
13 , m_name(
std::move(name))
15 , m_default_rate(scheduler.get_rate(token))
21 m_events.push_back({ .action = std::move(action), .delay_seconds = delay_seconds });
32 for (
size_t i = 0; i <
count; ++i) {
47 return then([]() { }, delay_seconds);
52 return then(std::move(action), interval_seconds);
62 auto s_coro_func = [](std::vector<TimedEvent> events,
64 std::function<void()> on_complete_callback,
68 for (
size_t iteration = 0; iteration <
repeat_count; ++iteration) {
69 for (
const auto& event : events) {
70 if (promise.should_terminate) {
79 }
catch (
const std::exception& e) {
83 "Exception in EventChain action: {}", e.what());
88 "Unknown exception in EventChain action");
92 if (promise.should_terminate) {
97 if (on_complete_callback) {
99 on_complete_callback();
100 }
catch (
const std::exception& e) {
104 "Exception in EventChain on_complete: {}", e.what());
109 "Unknown exception in EventChain on_complete");
114 auto g_coro_func = [](std::vector<TimedEvent> events,
116 std::function<void()> on_complete_callback,
120 for (
size_t iteration = 0; iteration <
repeat_count; ++iteration) {
121 for (
const auto& event : events) {
122 if (promise.should_terminate) {
131 }
catch (
const std::exception& e) {
135 "Exception in EventChain action: {}", e.what());
140 "Unknown exception in EventChain action");
144 if (promise.should_terminate) {
149 if (on_complete_callback) {
151 on_complete_callback();
152 }
catch (
const std::exception& e) {
156 "Exception in EventChain on_complete: {}", e.what());
161 "Unknown exception in EventChain on_complete");
169 m_routine = std::make_shared<Vruta::SoundRoutine>(
172 m_routine = std::make_shared<Vruta::GraphicsRoutine>(
206 }
catch (
const std::exception& e) {
210 "Exception in EventChain on_complete: {}", e.what());
215 "Unknown exception in EventChain on_complete");
#define MF_RT_ERROR(comp, ctx,...)
Vruta::TaskScheduler & m_Scheduler
Reference to the scheduler that manages timing.
EventChain & every(double interval_seconds, std::function< void()> action)
Convenience method for repeating an action at regular intervals.
size_t m_repeat_count
Number of times to repeat the entire chain.
void cancel()
Cancels the event chain if it's currently executing.
EventChain & then(std::function< void()> action, double delay_seconds=0.F)
Adds an event to the chain with a specified delay.
EventChain & on_complete(std::function< void()> callback)
Sets a callback to execute when the chain stops executing.
EventChain & repeat(size_t count)
Repeat the last event N times.
std::function< void()> m_on_complete
Optional callback to execute when the chain completes.
EventChain(Vruta::TaskScheduler &scheduler, std::string name="", Vruta::ProcessingToken token=Vruta::ProcessingToken::SAMPLE_ACCURATE)
Constructs an EventChain with an explicit scheduler.
EventChain & times(size_t count)
Repeat entire chain N times.
void fire_on_complete()
Internal method to safely fire the on_complete callback.
std::vector< TimedEvent > m_events
Collection of events in this chain.
EventChain & wait(double delay_seconds)
Add a wait/delay without an action.
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.
void start()
Starts executing the event chain.
bool is_active() const
Checks if the event chain is currently active.
A sequential chain of timed events with precise temporal control.
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.
bool cancel_task(const std::shared_ptr< Routine > &routine)
Cancels and removes a task from the scheduler.
Token-based multimodal task scheduling system for unified coroutine processing.
@ CoroutineScheduling
Coroutine scheduling and temporal coordination (Vruta::TaskScheduler)
@ Kriya
Automatable tasks and fluent scheduling api for Nodes and Buffers.
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.
graphics-domain awaiter for frame-accurate timing delays
Templated awaitable for accessing a coroutine's promise object.
Awaitable object for precise sample-accurate timing delays.