MayaFlux 0.4.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 105 of file Tasks.cpp.

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