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

◆ line()

MAYAFLUX_API Vruta::SoundRoutine MayaFlux::Kriya::line ( Vruta::TaskScheduler scheduler,
float  start_value,
float  end_value,
float  duration_seconds,
uint32_t  step_duration = 5,
bool  restartable = false 
)

Creates a continuous interpolation generator between two values over time.

Parameters
schedulerThe task scheduler that will manage this generator
start_valueInitial value of the interpolation
end_valueFinal value of the interpolation
duration_secondsTotal duration of the interpolation in seconds
step_durationNumber of samples between value updates (default: 5)
restartableWhether the interpolation can be restarted after completion (default: false)
Returns
A SoundRoutine that implements the interpolation behavior

The line task generates a linear interpolation between two numerical values over a specified duration. This creates continuous, gradual transitions that can be applied to any parameter in a computational system - from audio parameters to visual properties, physical simulation values, or data transformation coefficients.

The current value of the interpolation is stored in the task's state under the key "current_value" and can be accessed by external code using get_state<float>.

Example usage:

// Create a 2-second interpolation from 0.0 to 1.0
auto transition = Kriya::line(*scheduler, 0.0f, 1.0f, 2.0f);
auto task_ptr = std::make_shared<SoundRoutine>(std::move(transition));
scheduler->add_task(task_ptr);
// In the processing loop:
float* value = task_ptr->get_state<float>("current_value");
if (value) {
// Apply to any parameter in any domain
apply_parameter(*value);
}
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.
Definition Tasks.cpp:31

If restartable is true, the interpolation task will remain active after reaching the end value and can be restarted by calling restart() on the SoundRoutine.

Definition at line 31 of file Tasks.cpp.

32{
33 auto& promise_ref = co_await GetAudioPromise {};
34
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);
38
39 const unsigned int sample_rate = scheduler.get_rate();
40 if (step_duration < 1) {
41 step_duration = 1;
42 }
43
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;
47
48 promise_ref.set_state("step", sample_step);
49
50 for (;;) {
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");
54
55 if (!current_value || !last_value || !step) {
56 std::cerr << "Error: line task state not properly initialized" << std::endl;
57 co_return;
58 }
59
60 *current_value = start_value;
61
62 uint64_t samples_elapsed = 0;
63
64 co_await SampleDelay { 1 };
65
66 while (samples_elapsed < total_samples) {
67 *current_value += *step;
68
69 if ((*step > 0 && *current_value >= *last_value) || (*step < 0 && *current_value <= *last_value)) {
70 *current_value = *last_value;
71 }
72
73 samples_elapsed += step_duration;
74 co_await SampleDelay { step_duration };
75 }
76
77 if (!restartable)
78 break;
79
80 bool* restart_requested = promise_ref.get_state<bool>("restart");
81 if (restart_requested && *restart_requested) {
82 *restart_requested = false;
83 continue;
84 }
85
86 promise_ref.auto_resume = false;
87 co_await std::suspend_always {};
88 }
89}
unsigned int get_rate(ProcessingToken token=ProcessingToken::SAMPLE_ACCURATE) const
Get processing rate for a domain.
Templated awaitable for accessing a coroutine's promise object.
Definition Awaiters.hpp:188

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

Referenced by MayaFlux::create_line().

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