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

◆ pattern()

MAYAFLUX_API std::shared_ptr< Vruta::Routine > MayaFlux::Kriya::pattern ( std::function< std::any(uint64_t)>  pattern_func,
std::function< void(std::any)>  callback,
double  interval_seconds,
Vruta::ProcessingToken  token = Vruta::ProcessingToken::SAMPLE_ACCURATE 
)

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

Parameters
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 Routine shared_ptr of type determined by the processing token of the scheduler (SoundRoutine, GraphicsRoutine, etc.)

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(
// 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(generator);
std::shared_ptr< Vruta::Routine > pattern(std::function< std::any(uint64_t)> pattern_func, std::function< void(std::any)> callback, double interval_seconds, Vruta::ProcessingToken token)
Creates a generative algorithm that produces values based on a pattern function.
Definition Tasks.cpp:116

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

Definition at line 116 of file Tasks.cpp.

117{
118 if (token == Vruta::ProcessingToken::FRAME_ACCURATE) {
119 auto coro = [](std::function<std::any(uint64_t)> fn, std::function<void(std::any)> cb, double interval) -> Vruta::GraphicsRoutine {
120 uint64_t units = Vruta::seconds_to_frames(interval);
121 uint64_t step = 0;
122 while (true) {
123 cb(fn(step++));
124 co_await FrameDelay { .frames_to_wait = units };
125 }
126 };
127 return std::make_shared<Vruta::GraphicsRoutine>(coro(std::move(pattern_func), std::move(callback), interval_seconds));
128 }
129
130 auto coro = [](std::function<std::any(uint64_t)> fn, std::function<void(std::any)> cb, double interval) -> Vruta::SoundRoutine {
131 uint64_t units = Vruta::seconds_to_samples(interval);
132 uint64_t step = 0;
133 while (true) {
134 cb(fn(step++));
135 co_await SampleDelay { units };
136 }
137 };
138 return std::make_shared<Vruta::SoundRoutine>(coro(std::move(pattern_func), std::move(callback), interval_seconds));
139}
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(), and MayaFlux::Vruta::seconds_to_samples().

Referenced by MayaFlux::schedule_pattern().

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