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

◆ metro()

MAYAFLUX_API Vruta::SoundRoutine MayaFlux::Kriya::metro ( Vruta::TaskScheduler scheduler,
double  interval_seconds,
std::function< void()>  callback 
)

Creates a periodic event generator that executes a callback at regular intervals.

Parameters
schedulerThe task scheduler that will manage this event generator
interval_secondsTime between callback executions in seconds
callbackFunction to execute on each interval
Returns
A SoundRoutine that implements the periodic behavior

The metro task provides a fundamental temporal mechanism for creating time-based structures in computational systems. It executes the provided callback function at precise, regular intervals with sample-accurate timing, enabling the creation of rhythmic patterns, event sequences, and temporal frameworks that can synchronize across different domains.

Unlike system timers which can drift due to processing load, this implementation maintains precise timing by synchronizing with the sample-rate clock, making it suitable for both audio and cross-domain applications where timing accuracy is critical.

Example usage:

// Create a periodic event generator (2Hz)
auto periodic_task = Kriya::metro(*scheduler, 0.5, []() {
trigger_event(); // Could affect audio, visuals, data, etc.
});
scheduler->add_task(std::make_shared<SoundRoutine>(std::move(periodic_task)));
Vruta::SoundRoutine metro(Vruta::TaskScheduler &scheduler, double interval_seconds, std::function< void()> callback)
Creates a periodic event generator that executes a callback at regular intervals.
Definition Tasks.cpp:8

The metro task continues indefinitely until explicitly cancelled, creating a persistent temporal structure within the computational system.

Definition at line 8 of file Tasks.cpp.

9{
10 uint64_t interval_samples = scheduler.seconds_to_samples(interval_seconds);
11 auto& promise = co_await Kriya::GetAudioPromise {};
12
13 while (true) {
14 if (promise.should_terminate) {
15 break;
16 }
17 callback();
18 co_await SampleDelay(interval_samples);
19 }
20}
uint64_t seconds_to_samples(double seconds) const
Converts a time in seconds to a number of samples.
Templated awaitable for accessing a coroutine's promise object.
Definition Awaiters.hpp:188

References MayaFlux::Vruta::TaskScheduler::seconds_to_samples().

Referenced by MayaFlux::create_metro().

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