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

◆ pattern()

MAYAFLUX_API Vruta::SoundRoutine MayaFlux::Kriya::pattern ( Vruta::TaskScheduler scheduler,
std::function< std::any(uint64_t)>  pattern_func,
std::function< void(std::any)>  callback,
double  interval_seconds 
)

Creates a generative algorithm that produces values based on a pattern function.

Parameters
schedulerThe task scheduler that will manage this generator
pattern_funcFunction that generates values based on a step index
callbackFunction to execute with each generated value
interval_secondsTime between pattern steps in seconds
Returns
A SoundRoutine that implements the generative behavior

The pattern task provides a powerful framework for algorithmic generation of values according to any computational pattern or rule system. At regular intervals, it calls the pattern_func with the current step index, then passes the returned value to the callback function.

This mechanism enables the creation of generative algorithms, procedural sequences, emergent behaviors, and rule-based systems that can influence any aspect of a computational environment - from audio parameters to visual elements, data transformations, or cross-domain mappings.

Example usage:

// Create a generative algorithm based on a mathematical sequence
std::vector<int> fibonacci = {0, 1, 1, 2, 3, 5, 8, 13, 21};
auto generator = Kriya::pattern(*scheduler,
// Pattern function - apply algorithmic rules
[&fibonacci](uint64_t step) -> std::any {
return fibonacci[step % fibonacci.size()];
},
// Callback - apply the generated value
[](std::any value) {
int result = std::any_cast<int>(value);
// Can be applied to any domain - audio, visual, data, etc.
apply_generated_value(result);
},
0.125 // Generate 8 values per second
);
scheduler->add_task(std::make_shared<SoundRoutine>(std::move(generator)));
Vruta::SoundRoutine pattern(Vruta::TaskScheduler &scheduler, std::function< std::any(uint64_t)> pattern_func, std::function< void(std::any)> callback, double interval_seconds)
Creates a generative algorithm that produces values based on a pattern function.
Definition Tasks.cpp:91

The pattern task continues indefinitely until explicitly cancelled, creating an ongoing generative process within the computational system.

Definition at line 91 of file Tasks.cpp.

92{
93 uint64_t interval_samples = scheduler.seconds_to_samples(interval_seconds);
94 uint64_t step = 0;
95
96 while (true) {
97 std::any value = pattern_func(step++);
98 callback(value);
99 co_await SampleDelay(interval_samples);
100 }
101}
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().

Referenced by MayaFlux::create_pattern().

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