MayaFlux 0.3.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
MayaFlux::Kriya::EventChain Class Reference

A sequential chain of timed events with precise temporal control. More...

#include <Chain.hpp>

+ Collaboration diagram for MayaFlux::Kriya::EventChain:

Classes

struct  TimedEvent
 Structure representing a timed event in the chain. More...
 

Public Member Functions

 EventChain (Vruta::TaskScheduler &scheduler, std::string name="")
 Constructs an EventChain with an explicit scheduler.
 
EventChainthen (std::function< void()> action, double delay_seconds=0.F)
 Adds an event to the chain with a specified delay.
 
EventChainrepeat (size_t count)
 Repeat the last event N times.
 
EventChaintimes (size_t count)
 Repeat entire chain N times.
 
EventChainwait (double delay_seconds)
 Add a wait/delay without an action.
 
EventChainevery (double interval_seconds, std::function< void()> action)
 Convenience method for repeating an action at regular intervals.
 
void start ()
 Starts executing the event chain.
 
void cancel ()
 Cancels the event chain if it's currently executing.
 
bool is_active () const
 Checks if the event chain is currently active.
 
EventChainon_complete (std::function< void()> callback)
 Sets a callback to execute when the chain stops executing.
 
const std::string & name () const
 Gets the name of the event chain.
 
size_t event_count () const
 Gets the number of events in the chain.
 
size_t repeat_count () const
 Gets the repeat count for the entire chain.
 

Private Member Functions

void fire_on_complete ()
 Internal method to safely fire the on_complete callback.
 

Private Attributes

std::vector< TimedEventm_events
 Collection of events in this chain.
 
Vruta::TaskSchedulerm_Scheduler
 Reference to the scheduler that manages timing.
 
std::shared_ptr< Vruta::SoundRoutinem_routine
 The underlying computational routine that implements the chain.
 
std::function< void()> m_on_complete
 Optional callback to execute when the chain completes.
 
std::string m_name
 Optional name for the event chain.
 
bool m_on_complete_fired {}
 Flag to ensure on_complete is only fired once.
 
size_t m_repeat_count { 1 }
 Number of times to repeat the entire chain.
 
uint64_t m_default_rate { 48000 }
 

Detailed Description

A sequential chain of timed events with precise temporal control.

The EventChain class provides a way to schedule a sequence of events to occur at specific time intervals. It's designed for creating temporal sequences of actions with sample-accurate timing, which is essential for deterministic computational flows.

This approach is inspired by reactive programming and temporal logic systems where precise sequencing of operations is critical. It allows for creating complex temporal behaviors with a simple, declarative API.

Example usage:

// Create an event chain
EventChain chain(*scheduler);
// Add events with specific delays
chain.then([]() { process_initial_state(); }) // Immediate
.then([]() { transform_data(); }, 0.5) // After 0.5 seconds
.then([]() { apply_filter(); }, 0.25) // After another 0.25 seconds
.then([]() { finalize_output(); }, 0.25); // After another 0.25 seconds
// Start the chain
chain.start();
EventChain & then(std::function< void()> action, double delay_seconds=0.F)
Adds an event to the chain with a specified delay.
Definition Chain.cpp:20
void start()
Starts executing the event chain.
Definition Chain.cpp:56
A sequential chain of timed events with precise temporal control.
Definition Chain.hpp:41

The EventChain is particularly useful for creating precisely timed computational sequences, state transitions, or any series of time-based events that need to occur in a specific order with deterministic timing.

Definition at line 41 of file Chain.hpp.


The documentation for this class was generated from the following files: