MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Chronie.cpp
Go to the documentation of this file.
1#include "Chronie.hpp"
2
3#include "Core.hpp"
4
9
11
12namespace MayaFlux {
13
14std::shared_ptr<Vruta::TaskScheduler> get_scheduler()
15{
16 return get_context().get_scheduler();
17}
18
19std::shared_ptr<Vruta::EventManager> get_event_manager()
20{
22}
23
24template <typename... Args>
25bool update_task_params(const std::string& name, Args... args)
26{
27 return get_scheduler()->update_task_params(name, args...);
28}
29
30Vruta::SoundRoutine create_metro(double interval_seconds, std::function<void()> callback)
31{
32 return Kriya::metro(*get_scheduler(), interval_seconds, std::move(callback));
33}
34
35void schedule_metro(double interval_seconds, std::function<void()> callback, std::string name)
36{
37 auto scheduler = get_scheduler();
38 if (name.empty()) {
39 name = "metro_" + std::to_string(scheduler->get_next_task_id());
40 }
41 auto metronome = std::make_shared<Vruta::SoundRoutine>(create_metro(interval_seconds, std::move(callback)));
42
43 get_scheduler()->add_task(std::move(metronome), name, false);
44}
45
46Vruta::SoundRoutine create_sequence(std::vector<std::pair<double, std::function<void()>>> seq)
47{
48 return Kriya::sequence(*get_scheduler(), std::move(seq));
49}
50
51void schedule_sequence(std::vector<std::pair<double, std::function<void()>>> seq, std::string name)
52{
53 auto scheduler = get_scheduler();
54 if (name.empty()) {
55 name = "seq_" + std::to_string(scheduler->get_next_task_id());
56 }
57 auto tseq = std::make_shared<Vruta::SoundRoutine>(create_sequence(std::move(seq)));
58 get_scheduler()->add_task(std::move(tseq), name, false);
59}
60
61Vruta::SoundRoutine create_line(float start_value, float end_value, float duration_seconds, uint32_t step_duration, bool loop)
62{
63 return Kriya::line(*get_scheduler(), start_value, end_value, duration_seconds, step_duration, loop);
64}
65
66Vruta::SoundRoutine create_pattern(std::function<std::any(uint64_t)> pattern_func, std::function<void(std::any)> callback, double interval_seconds)
67{
68 return Kriya::pattern(*get_scheduler(), std::move(pattern_func), std::move(callback), interval_seconds);
69}
70
71void schedule_pattern(std::function<std::any(uint64_t)> pattern_func, std::function<void(std::any)> callback, double interval_seconds, std::string name)
72{
73 auto scheduler = get_scheduler();
74 if (name.empty()) {
75 name = "pattern_" + std::to_string(scheduler->get_next_task_id());
76 }
77 auto pattern = std::make_shared<Vruta::SoundRoutine>(create_pattern(std::move(pattern_func), std::move(callback), interval_seconds));
78 get_scheduler()->add_task(std::move(pattern), name, false);
79}
80
81float* get_line_value(const std::string& name)
82{
83 if (auto task = get_scheduler()->get_task(name)) {
84 auto cur_val = task->get_state<float>("current_value");
85 if (cur_val) {
86 return cur_val;
87 }
88
89 MF_ERROR(Journal::Component::API, Journal::Context::CoroutineScheduling, "line value not returned from task. Verify that tasks has not returned");
90 return nullptr;
91 }
92 MF_ERROR(Journal::Component::API, Journal::Context::CoroutineScheduling, "Task: {} not found. Verify task validity or if its been scheduled", name);
93 return nullptr;
94}
95
96void schedule_task(const std::string& name, Vruta::SoundRoutine&& task, bool initialize)
97{
98 auto task_ptr = std::make_shared<Vruta::SoundRoutine>(task);
99 get_scheduler()->add_task(std::move(task_ptr), name, initialize);
100}
101
102bool cancel_task(const std::string& name)
103{
104 return get_scheduler()->cancel_task(name);
105}
106
107bool restart_task(const std::string& name)
108{
109 return get_scheduler()->restart_task(name);
110}
111
112Kriya::ActionToken Play(std::shared_ptr<Nodes::Node> node)
113{
114 return { std::move(node) };
115}
116
118{
119 return { seconds };
120}
121
122Kriya::ActionToken Action(std::function<void()> func)
123{
124 return { std::move(func) };
125}
126
127std::shared_ptr<Kriya::BufferPipeline> create_buffer_pipeline()
128{
130}
131
132}
#define MF_ERROR(comp, ctx,...)
Core engine lifecycle and configuration API.
std::shared_ptr< Vruta::EventManager > get_event_manager()
Gets the event manager.
Definition Engine.hpp:265
std::shared_ptr< Vruta::TaskScheduler > get_scheduler()
Gets the task scheduler.
Definition Engine.hpp:238
A token representing an action in a computational sequence.
Definition Chain.hpp:140
static std::shared_ptr< BufferPipeline > create(Vruta::TaskScheduler &scheduler, std::shared_ptr< Buffers::BufferManager > buffer_manager=nullptr)
A C++20 coroutine-based audio processing task with sample-accurate timing.
Definition Routine.hpp:309
void initialize()
Definition main.cpp:11
@ CoroutineScheduling
Coroutine scheduling and temporal coordination (Vruta::TaskScheduler)
@ API
MayaFlux/API Wrapper and convenience functions.
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.
Definition Tasks.cpp:22
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.
Definition Tasks.cpp:91
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
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.
Definition Tasks.cpp:8
bool update_task_params(const std::string &name, Args... args)
Updates parameters of a scheduled task.
Definition Chronie.cpp:25
void schedule_metro(double interval_seconds, std::function< void()> callback, std::string name)
Creates a metronome task and addes it to the default scheduler list for evaluation.
Definition Chronie.cpp:35
std::shared_ptr< Vruta::EventManager > get_event_manager()
Gets the event manager from the default engine.
Definition Chronie.cpp:19
bool restart_task(const std::string &name)
Restarts a scheduled task.
Definition Chronie.cpp:107
Vruta::SoundRoutine create_pattern(std::function< std::any(uint64_t)> pattern_func, std::function< void(std::any)> callback, double interval_seconds)
Schedules a pattern generator that produces values based on a pattern function.
Definition Chronie.cpp:66
void schedule_sequence(std::vector< std::pair< double, std::function< void()> > > seq, std::string name)
Creates a sequence task that calls functions at specified times and addes it to the default scheduler...
Definition Chronie.cpp:51
Vruta::SoundRoutine create_line(float start_value, float end_value, float duration_seconds, uint32_t step_duration, bool loop)
Creates a line generator that interpolates between values over time.
Definition Chronie.cpp:61
Kriya::ActionToken Play(std::shared_ptr< Nodes::Node > node)
Creates an action to play a node.
Definition Chronie.cpp:112
void schedule_task(const std::string &name, Vruta::SoundRoutine &&task, bool initialize)
Schedules a new sound routine task.
Definition Chronie.cpp:96
void schedule_pattern(std::function< std::any(uint64_t)> pattern_func, std::function< void(std::any)> callback, double interval_seconds, std::string name)
Schedules a pattern generator that produces values based on a pattern function and addes it to the de...
Definition Chronie.cpp:71
float * get_line_value(const std::string &name)
Gets a pointer to a task's current value.
Definition Chronie.cpp:81
Kriya::ActionToken Action(std::function< void()> func)
Creates a custom action.
Definition Chronie.cpp:122
Vruta::SoundRoutine create_metro(double interval_seconds, std::function< void()> callback)
Creates a simple task that calls a function at a specified interval.
Definition Chronie.cpp:30
std::shared_ptr< Kriya::BufferPipeline > create_buffer_pipeline()
Creates a new buffer pipeline instance.
Definition Chronie.cpp:127
std::shared_ptr< Buffers::BufferManager > get_buffer_manager()
Gets the buffer manager from the default engine.
Definition Graph.cpp:81
bool cancel_task(const std::string &name)
Cancels a scheduled task.
Definition Chronie.cpp:102
Core::Engine & get_context()
Gets the default engine instance.
Definition Core.cpp:56
Vruta::SoundRoutine create_sequence(std::vector< std::pair< double, std::function< void()> > > seq)
Creates a sequence task that calls functions at specified times.
Definition Chronie.cpp:46
Kriya::ActionToken Wait(double seconds)
Creates a wait action.
Definition Chronie.cpp:117
std::shared_ptr< Vruta::TaskScheduler > get_scheduler()
Gets the task scheduler from the default engine.
Definition Chronie.cpp:14
Main namespace for the Maya Flux audio engine.
Definition LiveAid.hpp:6