19 "metro interval {}s is shorter than one frame, clamping to 1 frame", interval);
21 units = std::max<uint64_t>(1, units);
23 while (!p.should_terminate) {
28 return std::make_shared<Vruta::GraphicsRoutine>(coro(interval_seconds, std::move(
callback)));
34 "metro interval {}s is shorter than one sample, clamping to 1 sample", interval);
36 units = std::max<uint64_t>(1, units);
38 while (!p.should_terminate) {
43 return std::make_shared<Vruta::SoundRoutine>(coro(interval_seconds, std::move(
callback)));
50 for (
const auto& [time, cb] : seq) {
55 return std::make_shared<Vruta::GraphicsRoutine>(coro(std::move(
sequence)));
57 auto coro = [](std::vector<std::pair<double, std::function<void()>>> seq) ->
Vruta::SoundRoutine {
58 for (
const auto& [time, cb] : seq) {
63 return std::make_shared<Vruta::SoundRoutine>(coro(std::move(
sequence)));
66Vruta::SoundRoutine line(
float start_value,
float end_value,
float duration_seconds, uint32_t step_duration,
bool restartable)
70 promise_ref.set_state(
"current_value", start_value);
71 promise_ref.set_state(
"end_value", end_value);
72 promise_ref.set_state(
"restart",
false);
75 if (step_duration < 1) {
79 uint64_t total_samples =
static_cast<uint64_t
>(
static_cast<double>(duration_seconds) * sample_rate);
80 float per_sample_step = (end_value - start_value) / (
float)total_samples;
81 float sample_step = per_sample_step * (float)step_duration;
83 promise_ref.set_state(
"step", sample_step);
86 auto current_value = promise_ref.get_state<
float>(
"current_value");
87 auto last_value = promise_ref.get_state<
float>(
"end_value");
88 auto step = promise_ref.get_state<
float>(
"step");
90 if (!current_value || !last_value || !step) {
95 *current_value = start_value;
97 uint64_t samples_elapsed = 0;
101 while (samples_elapsed < total_samples) {
102 *current_value += *step;
104 if ((*step > 0 && *current_value >= *last_value) || (*step < 0 && *current_value <= *last_value)) {
105 *current_value = *last_value;
108 samples_elapsed += step_duration;
115 auto restart_requested = promise_ref.get_state<
bool>(
"restart");
116 if (restart_requested && *restart_requested) {
117 *restart_requested =
false;
121 promise_ref.auto_resume =
false;
122 co_await std::suspend_always {};
128 std::shared_ptr<Nodes::Generator::Logic> logic_node,
134 logic_node = std::make_shared<Nodes::Generator::Logic>(0.5);
148 if (promise_ref.should_terminate) {
152 logic_node->process_sample(0.0);
161 std::shared_ptr<Nodes::Generator::Logic> logic_node)
166 logic_node = std::make_shared<Nodes::Generator::Logic>(0.5);
169 logic_node->on_change_to(target_state,
175 if (promise_ref.should_terminate) {
179 logic_node->process_sample(0.0);
187 std::shared_ptr<Nodes::Generator::Logic> logic_node)
192 logic_node = std::make_shared<Nodes::Generator::Logic>(0.5);
200 if (promise_ref.should_terminate) {
204 logic_node->process_sample(0.0);
#define MF_ERROR(comp, ctx,...)
#define MF_RT_WARN(comp, ctx,...)
Base context class for node callbacks.
A C++20 coroutine-based graphics processing task with frame-accurate timing.
A C++20 coroutine-based audio processing task with sample-accurate timing.
@ CoroutineScheduling
Coroutine scheduling and temporal coordination (Vruta::TaskScheduler)
@ Kriya
Automatable tasks and fluent scheduling api for Nodes and Buffers.
Vruta::SoundRoutine Gate(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 Toggle(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(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.
std::shared_ptr< Vruta::Routine > sequence(std::vector< std::pair< double, std::function< void()> > > sequence, Vruta::ProcessingToken token)
Creates a temporal sequence that executes callbacks at specified time offsets.
Vruta::SoundRoutine Trigger(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.
std::shared_ptr< Vruta::Routine > metro(double interval_seconds, std::function< void()> callback, Vruta::ProcessingToken token)
Creates a periodic event generator that executes a callback at regular intervals.
uint64_t seconds_to_samples(double seconds, uint32_t sample_rate=s_registered_sample_rate)
Convert seconds to samples at a given sample rate.
@ FRAME_ACCURATE
Coroutine is frame-accurate.
MAYAFLUX_API uint32_t s_registered_sample_rate
uint64_t seconds_to_frames(double seconds, uint32_t frame_rate=s_registered_frame_rate)
Convert seconds to frames at a given frame rate.
graphics-domain awaiter for frame-accurate timing delays
Templated awaitable for accessing a coroutine's promise object.
Awaitable object for precise sample-accurate timing delays.