MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Chronie.hpp
Go to the documentation of this file.
1#pragma once
2
3namespace MayaFlux {
4
5namespace Nodes {
6 class Node;
7}
8
9namespace Vruta {
10 class TaskScheduler;
11 class EventManager;
12 class SoundRoutine;
13}
14
15namespace Kriya {
16 class ActionToken;
17 class BufferPipeline;
18}
19
20/**
21 * @brief Gets the task scheduler from the default engine
22 * @return Shared pointer to the centrally managed TaskScheduler
23 *
24 * Returns the scheduler that's managed by the default engine instance.
25 * All scheduled tasks using the convenience functions will use this scheduler.
26 */
27MAYAFLUX_API std::shared_ptr<Vruta::TaskScheduler> get_scheduler();
28
29/**
30 * @brief Gets the event manager from the default engine
31 * @return Shared pointer to the centrally managed EventManager
32 *
33 * Returns the event manager that's managed by the default engine instance.
34 * Used for handling windowing and input events.
35 */
36MAYAFLUX_API std::shared_ptr<Vruta::EventManager> get_event_manager();
37
38/**
39 * @brief Creates a simple task that calls a function at a specified interval
40 * @param interval_seconds Time between calls in seconds
41 * @param callback Function to call on each tick
42 * This is conceptually similar to Metronomes in PureData and MaxMSP
43 */
44MAYAFLUX_API Vruta::SoundRoutine create_metro(double interval_seconds, std::function<void()> callback);
45
46/**
47 * @brief Creates a metronome task and addes it to the default scheduler list for evaluation
48 * @param interval_seconds Time between calls in seconds
49 * @param callback Function to call on each tick
50 * @param name Name of the metronome task (optional but recommended).
51 If not provided, a default name will be generated.
52 *
53 * Uses the task scheduler from the default engine.
54 */
55MAYAFLUX_API void schedule_metro(double interval_seconds, std::function<void()> callback, std::string name = "");
56
57/**
58 * @brief Creates a sequence task that calls functions at specified times
59 * @param sequence Vector of (time, function) pairs
60 * @param name Name of the metronome task (optional but recommended).
61 If not provided, a default name will be generated.
62 * @return SoundRoutine object representing the scheduled task
63 *
64 * Uses the task scheduler from the default engine.
65 */
66MAYAFLUX_API Vruta::SoundRoutine create_sequence(std::vector<std::pair<double, std::function<void()>>> sequence);
67
68/**
69 * @brief Creates a sequence task that calls functions at specified times
70 * and addes it to the default scheduler list for evaluation
71 * @param sequence Vector of (time, function) pairs
72 * @param name Name of the metronome task (optional but recommended).
73 If not provided, a default name will be generated.
74 *
75 * Uses the task scheduler from the default engine.
76 */
77MAYAFLUX_API void schedule_sequence(std::vector<std::pair<double, std::function<void()>>> sequence, std::string name = "");
78
79/**
80 * @brief Creates a line generator that interpolates between values over time
81 * @param start_value Starting value
82 * @param end_value Ending value
83 * @param duration_seconds Total duration in seconds
84 * @param step_duration Time between steps in seconds
85 * @param loop Whether to loop back to start after reaching end
86 * @return SoundRoutine object representing the line generator
87 *
88 * Uses the task scheduler from the default engine.
89 */
90MAYAFLUX_API Vruta::SoundRoutine create_line(float start_value, float end_value, float duration_seconds, uint32_t step_duration, bool loop);
91
92/**
93 * @brief Schedules a pattern generator that produces values based on a pattern function
94 * @param pattern_func Function that generates pattern values based on step index
95 * @param callback Function to call with each pattern value
96 * @param interval_seconds Time between pattern steps
97 * @return SoundRoutine object representing the scheduled task
98 *
99 * Uses the task scheduler from the default engine.
100 */
101MAYAFLUX_API Vruta::SoundRoutine create_pattern(std::function<std::any(uint64_t)> pattern_func, std::function<void(std::any)> callback, double interval_seconds);
102
103/**
104 * @brief Schedules a pattern generator that produces values based on a pattern function
105 * and addes it to the default scheduler list for evaluation
106 * @param pattern_func Function that generates pattern values based on step index
107 * @param callback Function to call with each pattern value
108 * @param interval_seconds Time between pattern steps
109 * @param name Name of the metronome task (optional but recommended).
110 If not provided, a default name will be generated.
111 *
112 * Uses the task scheduler from the default engine.
113 */
114MAYAFLUX_API void schedule_pattern(std::function<std::any(uint64_t)> pattern_func, std::function<void(std::any)> callback, double interval_seconds, std::string name = "");
115
116/**
117 * @brief Gets a pointer to a task's current value
118 * @param name Name of the task
119 * @return Pointer to the float value, or nullptr if not found
120 *
121 * Convenience wrapper for Engine::get_line_value() on the default engine.
122 */
123MAYAFLUX_API float* get_line_value(const std::string& name);
124
125/**
126 * @brief Schedules a new sound routine task
127 * @param name Unique name for the task
128 * @param task The sound routine to schedule
129 * @param initialize Whether to initialize the task immediately
130 *
131 * Convenience wrapper for Engine::schedule_task() on the default engine.
132 */
133MAYAFLUX_API void schedule_task(const std::string& name, Vruta::SoundRoutine&& task, bool initialize = false);
134
135/**
136 * @brief Cancels a scheduled task
137 * @param name Name of the task to cancel
138 * @return true if task was found and canceled, false otherwise
139 *
140 * Convenience wrapper for Engine::cancel_task() on the default engine.
141 */
142MAYAFLUX_API bool cancel_task(const std::string& name);
143
144/**
145 * @brief Restarts a scheduled task
146 * @param name Name of the task to restart
147 * @return true if task was found and restarted, false otherwise
148 *
149 * Convenience wrapper for Engine::restart_task() on the default engine.
150 */
151MAYAFLUX_API bool restart_task(const std::string& name);
152
153/**
154 * @brief Updates parameters of a scheduled task
155 * @tparam Args Parameter types
156 * @param name Name of the task to update
157 * @param args New parameter values
158 * @return true if task was found and updated, false otherwise
159 *
160 * Convenience wrapper for Engine::update_task_params() on the default engine.
161 */
162template <typename... Args>
163MAYAFLUX_API bool update_task_params(const std::string& name, Args... args);
164
165/**
166 * @brief Creates an action to play a node
167 * @param node Node to play
168 * @return ActionToken representing the action
169 *
170 * Adds the node to the default engine's processing chain.
171 */
172MAYAFLUX_API Kriya::ActionToken Play(std::shared_ptr<Nodes::Node> node);
173
174/**
175 * @brief Creates a wait action
176 * @param seconds Time to wait in seconds
177 * @return ActionToken representing the wait
178 *
179 * Uses the task scheduler from the default engine.
180 */
181MAYAFLUX_API Kriya::ActionToken Wait(double seconds);
182
183/**
184 * @brief Creates a custom action
185 * @param func Function to execute
186 * @return ActionToken representing the action
187 *
188 * Uses the task scheduler from the default engine.
189 */
190MAYAFLUX_API Kriya::ActionToken Action(std::function<void()> func);
191
192/**
193 * @brief Creates a new buffer pipeline instance
194 * @return Shared pointer to the created BufferPipeline
195 *
196 * Uses the task scheduler from the default engine.
197 */
198MAYAFLUX_API std::shared_ptr<Kriya::BufferPipeline> create_buffer_pipeline();
199
200}
A token representing an action in a computational sequence.
Definition Chain.hpp:140
Coroutine-based execution engine for composable, multi-strategy buffer processing.
Base interface for all computational processing nodes.
Definition Node.hpp:109
A C++20 coroutine-based audio processing task with sample-accurate timing.
Definition Routine.hpp:309
Token-based multimodal task scheduling system for unified coroutine processing.
Definition Scheduler.hpp:51
void initialize()
Definition main.cpp:11
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
bool cancel_task(const std::string &name)
Cancels a scheduled task.
Definition Chronie.cpp:102
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