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

◆ Trigger()

MAYAFLUX_API Vruta::SoundRoutine MayaFlux::Kriya::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.

Parameters
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 173 of file Tasks.cpp.

177{
178 auto& promise_ref = co_await GetAudioPromise {};
179
180 if (!logic_node) {
181 logic_node = std::make_shared<Nodes::Generator::Logic>(0.5);
182 }
183
184 logic_node->on_change_to(target_state,
185 [callback](const Nodes::NodeContext& /*ctx*/) {
186 callback();
187 });
188
189 while (true) {
190 if (promise_ref.should_terminate) {
191 break;
192 }
193
194 logic_node->process_sample(0.0);
195
196 co_await SampleDelay { 1 };
197 }
198}
Templated awaitable for accessing a coroutine's promise object.