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

◆ sequence()

MAYAFLUX_API std::shared_ptr< Vruta::Routine > MayaFlux::Kriya::sequence ( std::vector< std::pair< double, std::function< void()> > >  sequence,
Vruta::ProcessingToken  token = Vruta::ProcessingToken::SAMPLE_ACCURATE 
)

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
tokenProcessing token to determine which scheduler rate to use (default: SAMPLE_ACCURATE)
Returns
A Routine shared_ptr of type determined by the processing token of the scheduler (SoundRoutine, GraphicsRoutine, etc.)

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({
{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(event_sequence);
std::shared_ptr< Vruta::Routine > sequence(std::vector< std::pair< double, std::function< void()> > > sequence, Vruta::ProcessingToken token)
Creates a temporal sequence that executes callbacks at specified time offsets.
Definition Tasks.cpp:36

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

Definition at line 36 of file Tasks.cpp.

37{
38 if (token == Vruta::ProcessingToken::FRAME_ACCURATE) {
39 auto coro = [](std::vector<std::pair<double, std::function<void()>>> seq) -> Vruta::GraphicsRoutine {
40 for (const auto& [time, cb] : seq) {
41 co_await FrameDelay { .frames_to_wait = Vruta::seconds_to_frames(time) };
42 cb();
43 }
44 };
45 return std::make_shared<Vruta::GraphicsRoutine>(coro(std::move(sequence)));
46 }
47 auto coro = [](std::vector<std::pair<double, std::function<void()>>> seq) -> Vruta::SoundRoutine {
48 for (const auto& [time, cb] : seq) {
49 co_await SampleDelay { Vruta::seconds_to_samples(time) };
50 cb();
51 }
52 };
53 return std::make_shared<Vruta::SoundRoutine>(coro(std::move(sequence)));
54}
A C++20 coroutine-based graphics processing task with frame-accurate timing.
Definition Routine.hpp:496
graphics-domain awaiter for frame-accurate timing delays

References MayaFlux::Vruta::FRAME_ACCURATE, MayaFlux::Kriya::FrameDelay::frames_to_wait, MayaFlux::Vruta::seconds_to_frames(), MayaFlux::Vruta::seconds_to_samples(), and sequence().

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

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