MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ Trigger()

MAYAFLUX_API Vruta::SoundRoutine MayaFlux::Kriya::Trigger ( Vruta::TaskScheduler scheduler,
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.

Parameters
schedulerTask scheduler instance
logic_nodeLogic node to monitor (creates default threshold node if null)
target_stateState to trigger on (true/false)
callbackFunction to execute on state change
Returns
SoundRoutine coroutine handle

Definition at line 136 of file Tasks.cpp.

141{
142 auto& promise_ref = co_await GetAudioPromise {};
143
144 if (!logic_node) {
145 logic_node = std::make_shared<Nodes::Generator::Logic>(0.5);
146 }
147
148 logic_node->on_change_to([callback](const Nodes::NodeContext& ctx) {
149 callback();
150 },
151 target_state);
152
153 while (true) {
154 if (promise_ref.should_terminate) {
155 break;
156 }
157
158 logic_node->process_sample(0.0);
159
160 co_await SampleDelay { 1 };
161 }
162}
Templated awaitable for accessing a coroutine's promise object.
Definition Awaiters.hpp:188