14 : m_Scheduler(scheduler)
15 , m_name(
std::move(name))
16 , m_default_rate(scheduler.get_rate())
22 m_events.push_back({ std::move(action), delay_seconds });
33 for (
size_t i = 0; i <
count; ++i) {
48 return then([]() { }, delay_seconds);
53 return then(std::move(action), interval_seconds);
63 auto coroutine_func = [](std::vector<TimedEvent> events,
65 std::function<void()> on_complete_callback,
69 for (
size_t iteration = 0; iteration <
repeat_count; ++iteration) {
70 for (
const auto& event : events) {
71 if (promise.should_terminate) {
80 }
catch (
const std::exception& e) {
84 "Exception in EventChain action: {}", e.what());
89 "Unknown exception in EventChain action");
93 if (promise.should_terminate) {
98 if (on_complete_callback) {
100 on_complete_callback();
101 }
catch (
const std::exception& e) {
105 "Exception in EventChain on_complete: {}", e.what());
110 "Unknown exception in EventChain on_complete");
116 m_routine = std::make_shared<Vruta::SoundRoutine>(
148 }
catch (
const std::exception& e) {
152 "Exception in EventChain on_complete: {}", e.what());
157 "Unknown exception in EventChain on_complete");
#define MF_RT_ERROR(comp, ctx,...)
static const auto node_token
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="")
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.
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.
void start()
Starts executing the event chain.
std::shared_ptr< Vruta::SoundRoutine > m_routine
The underlying computational routine that implements the 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 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.
@ AUDIO_RATE
Nodes that process at the audio sample rate.
uint64_t seconds_to_samples(double seconds, uint32_t sample_rate)
Convert seconds to samples at a given sample rate.
Templated awaitable for accessing a coroutine's promise object.
Awaitable object for precise sample-accurate timing delays.