MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
LiveAid.hpp
Go to the documentation of this file.
1#pragma once
2
4
5namespace MayaFlux {
6
7/**
8 * @brief JIT-compatible wrappers for MayaFlux API functions.
9 *
10 * LLVM < 21 limitation: In-place lambdas cause infinite recursion during symbol resolution.
11 * Workaround: All global MayaFlux API functions that expect std::function have template
12 * wrappers here that accept callables directly. Use these in JIT code.
13 *
14 * Example (JIT):
15 * schedule_metro(0.5, [](){ std::cout << "tick"; }, "my_metro"); // ✓ Works
16 *
17 * Once LLVM 21+ is standard, in-place lambdas will work directly without these wrappers.
18 *
19 */
20
21#ifdef LILA_WORKAROUND
22
23template <typename Callable>
24void schedule_metro(double interval_seconds, Callable&& callback, std::string name = "")
25{
26 std::function<void()> func = std::forward<Callable>(callback);
27 schedule_metro(interval_seconds, std::move(func), std::move(name));
28}
29
30template <typename... Args>
31void schedule_sequence(const std::vector<std::pair<double, std::function<void(Args...)>>>& sequence,
32 std::string name = "", Args... args)
33{
34 std::vector<std::pair<double, std::function<void()>>> seq;
35 for (const auto& [time, func] : sequence) {
36 seq.emplace_back(time, [func, args...]() { func(args...); });
37 }
38 schedule_sequence(std::move(seq), std::move(name));
39}
40
41template <typename PatternFunc, typename Callback>
42void schedule_pattern(PatternFunc&& pattern_func, Callback&& callback,
43 double interval_seconds, std::string name = "")
44{
45 auto pattern_wrapper = [pf = std::forward<PatternFunc>(pattern_func)](uint64_t idx) -> std::any {
46 return pf(idx);
47 };
48
49 auto callback_wrapper = [cb = std::forward<Callback>(callback)](std::any val) {
50 cb(val);
51 };
52
53 std::function<std::any(uint64_t)> pattern_fn = pattern_wrapper;
54 std::function<void(std::any)> callback_fn = callback_wrapper;
55
56 schedule_pattern(std::move(pattern_fn), std::move(callback_fn),
57 std::vector<double> { interval_seconds }, std::move(name));
58}
59
60template <typename FuncType>
61std::shared_ptr<Buffers::BufferProcessor> attach_quick_process(FuncType&& processor, std::shared_ptr<Buffers::AudioBuffer> buffer)
62{
63 std::function<void(std::shared_ptr<Buffers::AudioBuffer>)> func = std::forward<FuncType>(processor);
64 return attach_quick_process(std::move(func), std::move(buffer));
65}
66
67/**
68 * @brief JIT wrapper for Gate coroutine
69 * @param scheduler Task scheduler instance
70 * @param callback Function to execute while gate is open
71 * @param logic_node Logic node to control gate (creates default threshold node if null)
72 * @param open Initial gate state (true = open, false = closed)
73 * @return SoundRoutine coroutine handle
74 */
75template <typename Callable>
77 Vruta::TaskScheduler& scheduler, Callable&& callback,
78 std::shared_ptr<Nodes::Generator::Logic> logic_node, bool open = true)
79{
80 std::function<void()> func = std::forward<Callable>(callback);
81 return Gate(scheduler, std::move(func), std::move(logic_node), open);
82}
83
84/**
85 * @brief JIT wrapper for Trigger coroutine
86 * @param scheduler Task scheduler instance
87 * @param target_state State to trigger on (true/false)
88 * @param callback Function to execute on state change
89 * @param logic_node Logic node to monitor (creates default threshold node if null)
90 * @return SoundRoutine coroutine handle
91 */
92template <typename Callable>
94 Vruta::TaskScheduler& scheduler,
95 bool target_state,
96 Callable&& callback,
97 std::shared_ptr<Nodes::Generator::Logic> logic_node)
98{
99 std::function<void()> func = std::forward<Callable>(callback);
100 return Trigger(scheduler, target_state, std::move(func), std::move(logic_node));
101}
102
103/**
104 * @brief JIT wrapper for Toggle coroutine
105 * @param scheduler Task scheduler instance
106 * @param callback Function to execute on any state flip
107 * @param logic_node Logic node to monitor (creates default threshold node if null)
108 * @return SoundRoutine coroutine handle
109 */
110template <typename Callable>
112 Vruta::TaskScheduler& scheduler,
113 Callable&& callback,
114 std::shared_ptr<Nodes::Generator::Logic> logic_node)
115{
116 std::function<void()> func = std::forward<Callable>(callback);
117 return Toggle(scheduler, std::move(func), std::move(logic_node));
118}
119
120#endif // LILA_WORKAROUND
121
122}
Single include for the user facing API.
std::shared_ptr< NetworkGeometryBuffer > buffer
PickCallback callback
Definition Picker.cpp:22
std::string name
Definition VKDevice.cpp:123
A C++20 coroutine-based audio processing task with sample-accurate timing.
Definition Routine.hpp:327
Token-based multimodal task scheduling system for unified coroutine processing.
Definition Scheduler.hpp:51
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.
Definition Tasks.cpp:126
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.
Definition Tasks.cpp:185
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.
Definition Tasks.cpp:46
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.
Definition Tasks.cpp:158
void schedule_metro(double interval_seconds, std::function< void()> callback, std::string name, Vruta::ProcessingToken token)
Creates a metronome task and addes it to the default scheduler list for evaluation.
Definition Chronie.cpp:38
void schedule_sequence(std::vector< std::pair< double, std::function< void()> > > seq, std::string name, Vruta::ProcessingToken token)
Creates a sequence task that calls functions at specified times and addes it to the default scheduler...
Definition Chronie.cpp:49
std::shared_ptr< Buffers::BufferProcessor > attach_quick_process(F &&processor, std::initializer_list< unsigned int > channels={ 0 })
Attaches a processing function to one or more channels.
Definition Graph.hpp:467
void schedule_pattern(std::function< std::any(uint64_t)> pattern_func, std::function< void(std::any)> callback, std::vector< double > durations, std::string name, Vruta::ProcessingToken token)
Schedules a pattern generator whose steps are spaced by a list of durations.
Definition Chronie.cpp:74
Main namespace for the Maya Flux audio engine.
Definition Runtime.cpp:12