MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
LiveAid.hpp
Go to the documentation of this file.
1#pragma once
2#define MAYASIMPLE
3
5
6namespace MayaFlux {
7
8/**
9 * @brief JIT-compatible wrappers for MayaFlux API functions.
10 *
11 * LLVM < 21 limitation: In-place lambdas cause infinite recursion during symbol resolution.
12 * Workaround: All global MayaFlux API functions that expect std::function have template
13 * wrappers here that accept callables directly. Use these in JIT code.
14 *
15 * Example (JIT):
16 * schedule_metro(0.5, [](){ std::cout << "tick"; }, "my_metro"); // ✓ Works
17 *
18 * Once LLVM 21+ is standard, in-place lambdas will work directly without these wrappers.
19 *
20 * @note This header is automatically included in the PCH for JIT contexts (MAYASIMPLE mode).
21 */
22
23#ifdef LILA_WORKAROUND
24
25template <typename Callable>
26void schedule_metro(double interval_seconds, Callable&& callback, std::string name = "")
27{
28 std::function<void()> func = std::forward<Callable>(callback);
29 schedule_metro(interval_seconds, std::move(func), std::move(name));
30}
31
32template <typename... Args>
33void schedule_sequence(const std::vector<std::pair<double, std::function<void(Args...)>>>& sequence,
34 std::string name = "", Args... args)
35{
36 std::vector<std::pair<double, std::function<void()>>> seq;
37 for (const auto& [time, func] : sequence) {
38 seq.emplace_back(time, [func, args...]() { func(args...); });
39 }
40 schedule_sequence(std::move(seq), std::move(name));
41}
42
43template <typename PatternFunc, typename Callback>
44void schedule_pattern(PatternFunc&& pattern_func, Callback&& callback,
45 double interval_seconds, std::string name = "")
46{
47 auto pattern_wrapper = [pf = std::forward<PatternFunc>(pattern_func)](uint64_t idx) -> std::any {
48 return pf(idx);
49 };
50
51 auto callback_wrapper = [cb = std::forward<Callback>(callback)](std::any val) {
52 cb(val);
53 };
54
55 std::function<std::any(uint64_t)> pattern_fn = pattern_wrapper;
56 std::function<void(std::any)> callback_fn = callback_wrapper;
57
58 schedule_pattern(std::move(pattern_fn), std::move(callback_fn),
59 interval_seconds, std::move(name));
60}
61
62template <typename FuncType>
63std::shared_ptr<Buffers::BufferProcessor> attach_quick_process(FuncType&& processor, std::shared_ptr<Buffers::AudioBuffer> buffer)
64{
65 std::function<void(std::shared_ptr<Buffers::AudioBuffer>)> func = std::forward<FuncType>(processor);
66 return attach_quick_process(std::move(func), std::move(buffer));
67}
68
69/**
70 * @brief JIT wrapper for Gate coroutine
71 * @param scheduler Task scheduler instance
72 * @param callback Function to execute while gate is open
73 * @param logic_node Logic node to control gate (creates default threshold node if null)
74 * @param open Initial gate state (true = open, false = closed)
75 * @return SoundRoutine coroutine handle
76 */
77template <typename Callable>
79 Vruta::TaskScheduler& scheduler, Callable&& callback,
80 std::shared_ptr<Nodes::Generator::Logic> logic_node, bool open = true)
81{
82 std::function<void()> func = std::forward<Callable>(callback);
83 return Gate(scheduler, std::move(func), std::move(logic_node), open);
84}
85
86/**
87 * @brief JIT wrapper for Trigger coroutine
88 * @param scheduler Task scheduler instance
89 * @param target_state State to trigger on (true/false)
90 * @param callback Function to execute on state change
91 * @param logic_node Logic node to monitor (creates default threshold node if null)
92 * @return SoundRoutine coroutine handle
93 */
94template <typename Callable>
96 Vruta::TaskScheduler& scheduler,
97 bool target_state,
98 Callable&& callback,
99 std::shared_ptr<Nodes::Generator::Logic> logic_node)
100{
101 std::function<void()> func = std::forward<Callable>(callback);
102 return Trigger(scheduler, target_state, std::move(func), std::move(logic_node));
103}
104
105/**
106 * @brief JIT wrapper for Toggle coroutine
107 * @param scheduler Task scheduler instance
108 * @param callback Function to execute on any state flip
109 * @param logic_node Logic node to monitor (creates default threshold node if null)
110 * @return SoundRoutine coroutine handle
111 */
112template <typename Callable>
114 Vruta::TaskScheduler& scheduler,
115 Callable&& callback,
116 std::shared_ptr<Nodes::Generator::Logic> logic_node)
117{
118 std::function<void()> func = std::forward<Callable>(callback);
119 return Toggle(scheduler, std::move(func), std::move(logic_node));
120}
121
122#endif // LILA_WORKAROUND
123
124}
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 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
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
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
std::shared_ptr< Buffers::BufferProcessor > attach_quick_process(Buffers::BufferProcessingFunction processor, const std::shared_ptr< Buffers::AudioBuffer > &buffer)
Attaches a processing function to a specific buffer.
Definition Graph.cpp:140
Main namespace for the Maya Flux audio engine.
Definition LiveAid.hpp:6