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

◆ Gate()

MAYAFLUX_API Vruta::SoundRoutine MayaFlux::Kriya::Gate ( Vruta::TaskScheduler scheduler,
std::function< void()>  callback,
std::shared_ptr< Nodes::Generator::Logic logic_node,
bool  open = true 
)

Coroutine that executes callback continuously while logic node outputs true.

Parameters
schedulerTask scheduler instance
callbackFunction to execute while condition is true
logic_nodeLogic node to monitor (creates default threshold node if null)
openWhether to subscribe to gate open (true) or close (false)
Returns
SoundRoutine coroutine handle

Definition at line 103 of file Tasks.cpp.

108{
109 auto& promise_ref = co_await GetAudioPromise {};
110
111 if (!logic_node) {
112 logic_node = std::make_shared<Nodes::Generator::Logic>(0.5);
113 }
114
115 if (open) {
116 logic_node->while_true([callback](const Nodes::NodeContext& ctx) {
117 callback();
118 });
119 } else {
120 logic_node->while_false([callback](const Nodes::NodeContext& ctx) {
121 callback();
122 });
123 }
124
125 while (true) {
126 if (promise_ref.should_terminate) {
127 break;
128 }
129
130 logic_node->process_sample(0.0);
131
132 co_await SampleDelay { 1 };
133 }
134}
Templated awaitable for accessing a coroutine's promise object.
Definition Awaiters.hpp:188