14 if (promise.should_terminate) {
24 for (
const auto& [time, callback] :
sequence) {
35 promise_ref.set_state(
"current_value", start_value);
36 promise_ref.set_state(
"end_value", end_value);
37 promise_ref.set_state(
"restart",
false);
39 const unsigned int sample_rate = scheduler.
get_rate();
40 if (step_duration < 1) {
44 uint64_t total_samples = duration_seconds * sample_rate;
45 float per_sample_step = (end_value - start_value) / total_samples;
46 float sample_step = per_sample_step * step_duration;
48 promise_ref.set_state(
"step", sample_step);
51 float* current_value = promise_ref.get_state<
float>(
"current_value");
52 float* last_value = promise_ref.get_state<
float>(
"end_value");
53 float* step = promise_ref.get_state<
float>(
"step");
55 if (!current_value || !last_value || !step) {
56 std::cerr <<
"Error: line task state not properly initialized" << std::endl;
60 *current_value = start_value;
62 uint64_t samples_elapsed = 0;
66 while (samples_elapsed < total_samples) {
67 *current_value += *step;
69 if ((*step > 0 && *current_value >= *last_value) || (*step < 0 && *current_value <= *last_value)) {
70 *current_value = *last_value;
73 samples_elapsed += step_duration;
80 bool* restart_requested = promise_ref.get_state<
bool>(
"restart");
81 if (restart_requested && *restart_requested) {
82 *restart_requested =
false;
86 promise_ref.auto_resume =
false;
87 co_await std::suspend_always {};
97 std::any value = pattern_func(step++);
105 std::function<
void()> callback,
106 std::shared_ptr<Nodes::Generator::Logic> logic_node,
112 logic_node = std::make_shared<Nodes::Generator::Logic>(0.5);
126 if (promise_ref.should_terminate) {
130 logic_node->process_sample(0.0);
139 std::function<
void()> callback,
140 std::shared_ptr<Nodes::Generator::Logic> logic_node)
145 logic_node = std::make_shared<Nodes::Generator::Logic>(0.5);
154 if (promise_ref.should_terminate) {
158 logic_node->process_sample(0.0);
166 std::function<
void()> callback,
167 std::shared_ptr<Nodes::Generator::Logic> logic_node)
172 logic_node = std::make_shared<Nodes::Generator::Logic>(0.5);
180 if (promise_ref.should_terminate) {
184 logic_node->process_sample(0.0);
Base context class for node callbacks.
A C++20 coroutine-based audio processing task with sample-accurate timing.
uint64_t seconds_to_samples(double seconds) const
Converts a time in seconds to a number of samples.
unsigned int get_rate(ProcessingToken token=ProcessingToken::SAMPLE_ACCURATE) const
Get processing rate for a domain.
Token-based multimodal task scheduling system for unified coroutine processing.
Vruta::SoundRoutine sequence(Vruta::TaskScheduler &scheduler, std::vector< std::pair< double, std::function< void()> > > sequence)
Creates a temporal sequence that executes callbacks at specified time offsets.
Vruta::SoundRoutine Trigger(Vruta::TaskScheduler &scheduler, bool target_state, std::function< void()> callback, std::shared_ptr< Nodes::Generator::Logic > logic_node)
Coroutine that executes callback when logic node changes to specific state.
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.
Vruta::SoundRoutine Toggle(Vruta::TaskScheduler &scheduler, std::function< void()> callback, std::shared_ptr< Nodes::Generator::Logic > logic_node)
Coroutine that executes callback on any logic node state change.
Vruta::SoundRoutine line(Vruta::TaskScheduler &scheduler, float start_value, float end_value, float duration_seconds, uint32_t step_duration, bool restartable)
Creates a continuous interpolation generator between two values over time.
Vruta::SoundRoutine Gate(Vruta::TaskScheduler &scheduler, std::function< void()> callback, std::shared_ptr< Nodes::Generator::Logic > logic_node, bool open)
Coroutine that executes callback continuously while logic node outputs true.
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.
Templated awaitable for accessing a coroutine's promise object.
Awaitable object for precise sample-accurate timing delays.