MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
MayaFlux::Portal::Forma::Bridge Class Reference

Two-way binding orchestrator for Forma elements. More...

#include <Bridge.hpp>

+ Collaboration diagram for MayaFlux::Portal::Forma::Bridge:

Classes

class  Binding
 Non-owning handle for all bind/write/unbind operations on one element. More...
 
struct  ElementRecord
 

Public Member Functions

template<typename T >
Binding at (const std::shared_ptr< MappedState< T > > &state)
 Return a Binding handle resolved from a MappedState.
 
Binding at (uint32_t id)
 Return a Binding handle for the element registered under id.
 
template<typename T >
void bind (std::shared_ptr< MappedState< T > > state, std::function< float()> source)
 
template<typename T >
void bind (std::shared_ptr< MappedState< T > > state, std::shared_ptr< Nodes::Node > node, std::function< float(double)> project={})
 
void bind (uint32_t id, std::function< float()> source)
 Drive element value from an arbitrary per-frame callable.
 
void bind (uint32_t id, std::shared_ptr< Nodes::Node > node, std::function< float(double)> project={})
 Drive element value from a Node's output each frame.
 
 Bridge (Bridge &&)=delete
 
 Bridge (const Bridge &)=delete
 
 Bridge (Vruta::TaskScheduler &scheduler, Buffers::BufferManager &buffer_manager)
 
Bridgeoperator= (Bridge &&)=delete
 
Bridgeoperator= (const Bridge &)=delete
 
template<typename T >
void register_element (Mapped< T > mapped, std::function< float(T)> project={})
 Register a fully constructed Mapped<T> and own its sync loop.
 
template<typename T >
void register_element (std::shared_ptr< MappedState< T > > state, uint32_t id, std::shared_ptr< Buffers::FormaBuffer > buffer, std::function< float(T)> project={})
 Register a MappedState<T> so that MappedState overloads and outbound bindings can resolve to the correct element id and reader.
 
void spawn_sync (uint32_t id, std::function< void()> sync_fn)
 Spawn a per-frame GraphicsRoutine that calls sync_fn each tick.
 
template<typename T >
void unbind (std::shared_ptr< MappedState< T > > state)
 
void unbind (uint32_t id)
 Cancel all inbound and outbound bindings for an element.
 
template<typename T >
void write (std::shared_ptr< MappedState< T > > state, std::function< void(std::span< const float >)> sink)
 
template<typename T >
void write (std::shared_ptr< MappedState< T > > state, std::shared_ptr< Buffers::AudioWriteProcessor > target)
 
template<typename T >
void write (std::shared_ptr< MappedState< T > > state, std::shared_ptr< Buffers::DataWriteProcessor > target)
 
template<typename T >
void write (std::shared_ptr< MappedState< T > > state, std::shared_ptr< Buffers::VKBuffer > target_buffer, const std::string &shader_path, const std::string &descriptor_name, uint32_t binding_index, uint32_t set, Portal::Graphics::DescriptorRole role=Portal::Graphics::DescriptorRole::UNIFORM)
 
template<typename T >
void write (std::shared_ptr< MappedState< T > > state, std::shared_ptr< Buffers::VKBuffer > target_buffer, const std::string &shader_path, uint32_t offset, size_t size=sizeof(float))
 
template<typename T >
void write (std::shared_ptr< MappedState< T > > state, std::shared_ptr< Nodes::Constant > node)
 
void write (uint32_t id, const std::shared_ptr< Buffers::VKBuffer > &target_buffer, const std::string &shader_path, const std::string &descriptor_name, uint32_t binding_index, uint32_t set, Portal::Graphics::DescriptorRole role=Portal::Graphics::DescriptorRole::UNIFORM)
 Route element value to a descriptor binding on target_buffer.
 
void write (uint32_t id, const std::shared_ptr< Buffers::VKBuffer > &target_buffer, const std::string &shader_path, uint32_t offset, size_t size=sizeof(float))
 Route element value to a push constant slot on a ShaderProcessor.
 
void write (uint32_t id, std::function< void(std::span< const float >)> sink)
 Route element bulk value to a caller-supplied sink each frame.
 
void write (uint32_t id, std::shared_ptr< Buffers::AudioWriteProcessor > target)
 Route element value to an AudioWriteProcessor each frame.
 
void write (uint32_t id, std::shared_ptr< Buffers::DataWriteProcessor > target)
 Route element value to a DataWriteProcessor each frame.
 
void write (uint32_t id, std::shared_ptr< Nodes::Constant > node)
 Route element value into a Constant node via set_constant().
 
 ~Bridge ()
 

Private Member Functions

void cancel_inbound (ElementRecord &rec)
 
void cancel_outbound (ElementRecord &rec)
 
std::string make_task_name (uint32_t id, const char *suffix) const
 
void spawn_inbound (uint32_t id, std::function< float()> source)
 

Private Attributes

Buffers::BufferManagerm_buffer_manager
 
uint32_t m_next_id { 0 }
 
std::unordered_map< uint32_t, ElementRecordm_records
 
Vruta::TaskSchedulerm_scheduler
 

Detailed Description

Two-way binding orchestrator for Forma elements.

One Bridge instance serves the full application. It owns all inbound GraphicsRoutine tasks and all outbound FormaBindingsProcessor instances. Layer and Context are created via the Forma free functions and passed in — Bridge does not own or create them.

Inbound (what drives an element's MappedState each frame):

  • bind(id, Node) — reads Node::get_last_output() via GraphicsRoutine
  • bind(id, lambda) — calls std::function<float()> via GraphicsRoutine

Outbound (where the element's value goes each frame):

  • write(id, ShaderProcessor, offset) — push constant staging
  • write(id, descriptor_name, ...) — descriptor binding
  • write(id, AudioWriteProcessor) — audio buffer
  • write(id, DataWriteProcessor) — vertex buffer
  • write(id, Constant) — node graph value carrier

All overloads also accept shared_ptr<MappedState<T>> in place of the element id. These resolve to the state->id. duplicated logic.

Usage:

auto [layer, ctx] = Forma::create_layer(window, "hud", event_manager);
auto el = Forma::create_element<float>(*layer, window, bm, geom, 0.5f);
Bridge bridge(scheduler, buffer_manager);
bridge.bind(el.state, envelope);
bridge.write(el.state, compute_proc, offsetof(PC, cutoff));
ctx->on_press(el.element.id, IO::MouseButtons::LEFT,
[](uint32_t, glm::vec2){});
void write(std::shared_ptr< MappedState< T > > state, std::function< void(std::span< const float >)> sink)
Definition Bridge.hpp:129
void bind(uint32_t id, std::shared_ptr< Nodes::Node > node, std::function< float(double)> project={})
Drive element value from a Node's output each frame.
Definition Bridge.cpp:38
Two-way binding orchestrator for Forma elements.
Definition Bridge.hpp:65
std::pair< std::shared_ptr< Layer >, std::shared_ptr< Context > > create_layer(const std::shared_ptr< Core::Window > &window, std::string name)
Construct a Layer and a Context wired to window.
Definition Forma.cpp:202
Bridge & bridge()
Return the application-level Bridge instance.
Definition Forma.cpp:295

Definition at line 65 of file Bridge.hpp.


The documentation for this class was generated from the following files: