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

◆ pattern() [1/4]

template<std::incrementable Index = uint64_t, typename Generator , typename Callback , typename Condition >
requires PatternGenerator<Generator, Index> && PatternCallback<Callback, typename PatternTraits<Generator, Index>::value_type> && PatternCondition<Condition, Index>
std::shared_ptr< Vruta::Routine > MayaFlux::Kriya::pattern ( Generator  generator,
Callback  callback,
Condition  ready,
Vruta::ProcessingToken  token = Vruta::ProcessingToken::SAMPLE_ACCURATE 
)

Creates a pattern whose next step runs when a condition holds.

Template Parameters
IndexStep index type, default uint64_t
Parameters
generatorCallable from the step index to any value
callbackCallable that takes the generated value
readyCondition for the step index, checked each time the routine resumes
tokenSelects the routine type that runs the pattern
Returns
The routine, or nullptr for an empty function or an unsupported token

The routine suspends and checks ready(index) again until it holds, then runs callback(generator(index)) and advances the index. The value type is whatever the generator returns, so no cast is involved. The condition can be anything that returns a bool: a Logic node's output, a flag, another routine's state. A condition that stays true runs one step per check.

Tokens:

  • SAMPLE_ACCURATE: SoundRoutine
  • FRAME_ACCURATE: GraphicsRoutine
  • MULTI_RATE: CrossRoutine
  • CONDITIONAL: FreeRoutine on the condition thread

A function that throws is logged and ends the pattern.

auto routine = Kriya::pattern(
[](uint64_t step) { return glm::vec2(step, step * 2); },
[](glm::vec2 point) { use(point); },
[gate](uint64_t) { return gate->get_last_output() > 0.5; });
scheduler->add_task(routine);
std::shared_ptr< Vruta::Routine > pattern(std::function< std::any(uint64_t)> pattern_func, std::function< void(std::any)> callback, std::function< bool(uint64_t)> ready, Vruta::ProcessingToken token)
The std::any, uint64_t form of the condition driven pattern.
Definition Pattern.cpp:5