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

◆ sequence()

MAYAFLUX_API Vruta::SoundRoutine MayaFlux::Kriya::sequence ( Vruta::TaskScheduler scheduler,
std::vector< std::pair< double, std::function< void()> > >  sequence 
)

Creates a temporal sequence that executes callbacks at specified time offsets.

Parameters
schedulerThe task scheduler that will manage this sequence
sequenceVector of (time_offset, callback) pairs to execute in order
Returns
A SoundRoutine that implements the sequence behavior

The sequence task enables the creation of precisely timed event chains with specific temporal relationships. Each event consists of a time offset (in seconds) and a callback function to execute at that precise moment.

This mechanism is valuable for creating structured temporal progressions, algorithmic sequences, or any series of time-based events that require specific timing relationships. The sequence can coordinate events across multiple domains (audio, visual, data) with sample-accurate precision.

Example usage:

// Create a temporal sequence of events
auto event_sequence = Kriya::sequence(*scheduler, {
{0.0, []() { trigger_event_a(); }}, // Immediate
{0.5, []() { trigger_event_b(); }}, // 0.5 seconds later
{1.0, []() { trigger_event_c(); }}, // 1.0 seconds later
{1.5, []() { trigger_event_d(); }} // 1.5 seconds later
});
scheduler->add_task(std::make_shared<SoundRoutine>(std::move(event_sequence)));
Vruta::SoundRoutine sequence(Vruta::TaskScheduler &scheduler, std::vector< std::pair< double, std::function< void()> > > sequence)
Creates a temporal sequence that executes callbacks at specified time offsets.
Definition Tasks.cpp:22

The sequence task completes after executing all events in the defined timeline.

Definition at line 22 of file Tasks.cpp.

23{
24 for (const auto& [time, callback] : sequence) {
25 uint64_t delay_samples = scheduler.seconds_to_samples(time);
26 co_await SampleDelay(delay_samples);
27 callback();
28 }
29}
uint64_t seconds_to_samples(double seconds) const
Converts a time in seconds to a number of samples.
Awaitable object for precise sample-accurate timing delays.
Definition Awaiters.hpp:35

References MayaFlux::Vruta::TaskScheduler::seconds_to_samples(), and sequence().

Referenced by MayaFlux::create_sequence(), and sequence().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: