MayaFlux 0.1.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 164 of file Tasks.cpp.

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