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

◆ Toggle()

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

Coroutine that executes callback on any logic node state change.

Parameters
schedulerTask scheduler instance
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 166 of file Tasks.cpp.

170{
171 auto& promise_ref = co_await GetAudioPromise {};
172
173 if (!logic_node) {
174 logic_node = std::make_shared<Nodes::Generator::Logic>(0.5);
175 }
176
177 logic_node->on_change([callback](const Nodes::NodeContext& /*ctx*/) {
178 callback();
179 });
180
181 while (true) {
182 if (promise_ref.should_terminate) {
183 break;
184 }
185
186 logic_node->process_sample(0.0);
187
188 co_await SampleDelay { 1 };
189 }
190}
Templated awaitable for accessing a coroutine's promise object.