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

◆ write() [9/12]

void MayaFlux::Portal::Forma::Bridge::write ( uint32_t  id,
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> or vector<double>), the full vector 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
idElement id.
sinkCallable invoked each frame with the current value span.

Definition at line 277 of file Bridge.cpp.

278{
279 auto it = m_records.find(id);
280 if (it == m_records.end()) {
282 "Bridge::write: unknown element id {}", id);
283 return;
284 }
285
286 auto name = make_task_name(id, "bulk_sink");
287 it->second.outbound_tasks.push_back(name);
288
289 auto bulk = it->second.bulk_reader;
290 auto reader = it->second.reader;
291
292 if (bulk) {
293 auto routine = [](Vruta::TaskScheduler&,
294 std::function<std::vector<float>()> b,
295 std::function<void(std::span<const float>)> s)
296 -> Vruta::GraphicsRoutine {
297 auto& p = co_await Kriya::GetGraphicsPromise {};
298 while (!p.should_terminate) {
299 const auto v = b();
300 s(v);
301 co_await Kriya::FrameDelay { .frames_to_wait = 1 };
302 }
303 };
305 std::make_shared<Vruta::GraphicsRoutine>(
306 routine(m_scheduler, std::move(bulk), std::move(sink))),
307 name, false);
308 } else {
309 auto routine = [](Vruta::TaskScheduler&,
310 std::function<float()> r,
311 std::function<void(std::span<const float>)> s)
312 -> Vruta::GraphicsRoutine {
313 auto& p = co_await Kriya::GetGraphicsPromise {};
314 float val {};
315 while (!p.should_terminate) {
316 val = r();
317 s(std::span<const float> { &val, 1 });
318 co_await Kriya::FrameDelay { .frames_to_wait = 1 };
319 }
320 };
322 std::make_shared<Vruta::GraphicsRoutine>(
323 routine(m_scheduler, std::move(reader), std::move(sink))),
324 name, false);
325 }
326}
#define MF_ERROR(comp, ctx,...)
size_t b
Vruta::TaskScheduler & m_scheduler
Definition Bridge.hpp:522
std::string make_task_name(uint32_t id, const char *suffix) const
Definition Bridge.cpp:346
std::unordered_map< uint32_t, ElementRecord > m_records
Definition Bridge.hpp:527
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:23
@ 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, MayaFlux::Kriya::FrameDelay::frames_to_wait, MayaFlux::Journal::Init, m_records, m_scheduler, make_task_name(), MF_ERROR, and MayaFlux::Journal::Portal.

+ Here is the call graph for this function: