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

◆ write() [4/16]

void MayaFlux::Portal::Forma::Bridge::write ( const ElementRef &  ref,
std::function< void(std::span< const float >)>  sink 
)

Route element bulk value to a caller-supplied sink each frame.

When the element's MappedState<T> has a bulk_reader (T is vector<float>, vector<double> or a glm vector), the full value is forwarded as a span. For scalar T the sink receives a single-element span of the scalar value.

Intended for consumers that operate on coefficient arrays or other N-element state: FIR/IIR coefficient vectors, Random node bounds, any function accepting a contiguous float range.

Parameters
refOwning Layer and element id.
sinkCallable invoked each frame with the current value span.

Definition at line 310 of file Bridge.cpp.

311{
312 auto* rec = find_record(ref);
313 if (!rec) {
315 "Bridge::write: unknown element id {}", ref.second);
316 return;
317 }
318
319 auto name = make_task_name(ref.second, "bulk_sink");
320 rec->outbound_tasks.push_back(name);
321
322 auto bulk = rec->bulk_reader;
323 auto reader = rec->reader;
324
325 if (bulk) {
326 auto routine = [](Vruta::TaskScheduler&,
327 std::function<std::vector<float>()> b,
328 std::function<void(std::span<const float>)> s)
329 -> Vruta::GraphicsRoutine {
330 auto& p = co_await Kriya::GetGraphicsPromise {};
331 while (!p.should_terminate) {
332 const auto v = b();
333 s(v);
334 co_await Kriya::FrameDelay { .frames_to_wait = 1 };
335 }
336 };
338 std::make_shared<Vruta::GraphicsRoutine>(
339 routine(m_scheduler, std::move(bulk), std::move(sink))),
340 name, false);
341 } else {
342 auto routine = [](Vruta::TaskScheduler&,
343 std::function<float()> r,
344 std::function<void(std::span<const float>)> s)
345 -> Vruta::GraphicsRoutine {
346 auto& p = co_await Kriya::GetGraphicsPromise {};
347 float val {};
348 while (!p.should_terminate) {
349 val = r();
350 s(std::span<const float> { &val, 1 });
351 co_await Kriya::FrameDelay { .frames_to_wait = 1 };
352 }
353 };
355 std::make_shared<Vruta::GraphicsRoutine>(
356 routine(m_scheduler, std::move(reader), std::move(sink))),
357 name, false);
358 }
359}
#define MF_ERROR(comp, ctx,...)
size_t b
std::string name
Definition VKDevice.cpp:123
Vruta::TaskScheduler & m_scheduler
Definition Bridge.hpp:693
std::string make_task_name(uint32_t id, const char *suffix) const
Definition Bridge.cpp:416
ElementRecord * find_record(const ElementRef &ref)
Definition Bridge.cpp:406
void add_task(const std::shared_ptr< Routine > &routine, const std::string &name="", bool initialize=false)
Add a routine to the scheduler based on its processing token.
Definition Scheduler.cpp:94
@ Init
Engine/subsystem initialization.
@ Portal
High-level user-facing API layer.
GetPromiseBase< Vruta::graphics_promise > GetGraphicsPromise
Graphics domain promise accessor.

References MayaFlux::Vruta::TaskScheduler::add_task(), b, find_record(), MayaFlux::Kriya::FrameDelay::frames_to_wait, MayaFlux::Journal::Init, m_scheduler, make_task_name(), MF_ERROR, name, and MayaFlux::Journal::Portal.

+ Here is the call graph for this function: