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

◆ Gate()

MAYAFLUX_API Vruta::SoundRoutine MayaFlux::Kriya::Gate ( 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
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 141 of file Tasks.cpp.

145{
146 auto& promise_ref = co_await GetAudioPromise {};
147
148 if (!logic_node) {
149 logic_node = std::make_shared<Nodes::Generator::Logic>(0.5);
150 }
151
152 if (open) {
153 logic_node->while_true([callback](const Nodes::NodeContext& /*ctx*/) {
154 callback();
155 });
156 } else {
157 logic_node->while_false([callback](const Nodes::NodeContext& /*ctx*/) {
158 callback();
159 });
160 }
161
162 while (true) {
163 if (promise_ref.should_terminate) {
164 break;
165 }
166
167 logic_node->process_sample(0.0);
168
169 co_await SampleDelay { 1 };
170 }
171}
Templated awaitable for accessing a coroutine's promise object.