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

◆ Toggle()

MAYAFLUX_API Vruta::SoundRoutine MayaFlux::Kriya::Toggle ( std::function< void()>  callback,
std::shared_ptr< Nodes::Generator::Logic logic_node 
)

Coroutine that executes callback on any logic node state change.

Parameters
logic_nodeLogic node to monitor (creates default threshold node if null)
callbackFunction to execute on any state flip
Returns
SoundRoutine coroutine handle

Definition at line 200 of file Tasks.cpp.

203{
204 auto& promise_ref = co_await GetAudioPromise {};
205
206 if (!logic_node) {
207 logic_node = std::make_shared<Nodes::Generator::Logic>(0.5);
208 }
209
210 logic_node->on_change([callback](const Nodes::NodeContext& /*ctx*/) {
211 callback();
212 });
213
214 while (true) {
215 if (promise_ref.should_terminate) {
216 break;
217 }
218
219 logic_node->process_sample(0.0);
220
221 co_await SampleDelay { 1 };
222 }
223}
Templated awaitable for accessing a coroutine's promise object.