MayaFlux 0.4.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 138 of file Tasks.cpp.

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