MayaFlux 0.4.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

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

Private Member Functions

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

Private Attributes

uint64_t m_default_rate { 48000 }
 
std::vector< TimedEventm_events
 Collection of events in this chain.
 
std::string m_name
 Optional name for the event chain.
 
std::function< void()> m_on_complete
 Optional callback to execute when the chain completes.
 
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.
 
std::shared_ptr< Vruta::SoundRoutinem_routine
 The underlying computational routine that implements the chain.
 
Vruta::TaskSchedulerm_Scheduler
 Reference to the scheduler that manages timing.
 

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
A sequential chain of timed events with precise temporal control.
Definition Chain.hpp:41
Tendency< A, C > chain(const Tendency< A, B > &first, const Tendency< B, C > &second)
Sequential composition: evaluate first, feed result into second.
Definition Tendency.hpp:82

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: