MayaFlux 1.0.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 (ElementRef ref)
 Return a Binding handle for the element registered under ref.
 
void bind (const ElementRef &ref, std::function< float()> source)
 Drive element value from an arbitrary per-frame callable.
 
void bind (const ElementRef &ref, std::shared_ptr< Nodes::Node > node, std::function< float(double)> project={})
 Drive element value from a Node's output each frame.
 
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={})
 
 Bridge (Bridge &&)=delete
 
 Bridge (const Bridge &)=delete
 
 Bridge (Vruta::TaskScheduler &scheduler, Buffers::BufferManager &buffer_manager)
 
Bridge & operator= (Bridge &&)=delete
 
Bridge & operator= (const Bridge &)=delete
 
template<typename T >
void register_element (const ElementRef &ref, std::shared_ptr< MappedState< T > > state, 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 and reader.
 
template<typename T >
void register_element (Layer &layer, Mapped< T > mapped, std::function< float(T)> project={})
 Register a Mapped element and scope its presentation sync to a Layer.
 
void spawn_sync (Layer &layer, uint32_t id, std::function< void()> sync_fn)
 Spawn a presentation sync task scoped to a Layer.
 
void stop_sync (Layer &layer)
 Stop Bridge tasks owned by a Layer.
 
void unbind (const ElementRef &ref)
 Cancel all inbound and outbound bindings for an element.
 
template<typename T >
void unbind (std::shared_ptr< MappedState< T > > state)
 
void write (const ElementRef &ref, 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 (const ElementRef &ref, const std::shared_ptr< Buffers::VKBuffer > &target_buffer, const std::string &shader_path, uint32_t offset, Kakshya::GpuDataFormat format)
 Route element value to a push constant slot described by a GpuDataFormat.
 
void write (const ElementRef &ref, 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 (const ElementRef &ref, std::function< void(std::span< const float >)> sink)
 Route element bulk value to a caller-supplied sink each frame.
 
void write (const ElementRef &ref, std::shared_ptr< Buffers::AudioWriteProcessor > target)
 Route element value to an AudioWriteProcessor each frame.
 
void write (const ElementRef &ref, std::shared_ptr< Buffers::DataWriteProcessor > target)
 Route element value to a DataWriteProcessor each frame.
 
void write (const ElementRef &ref, std::shared_ptr< Nodes::Constant > node)
 Route element value into a Constant node via set_constant().
 
void write (Layer &layer, const std::vector< std::shared_ptr< MappedState< float > > > &states, std::function< void(std::span< const float >)> sink)
 Route an ordered set of scalar states as one float range each frame.
 
template<typename T , typename Processor , typename Assemble >
void write (Layer &layer, const std::vector< std::shared_ptr< MappedState< T > > > &states, Assemble assemble, std::shared_ptr< Processor > target)
 Assemble a typed state range into DataVariant for a write processor.
 
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, Kakshya::GpuDataFormat format)
 
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)
 
 ~Bridge ()
 

Private Member Functions

void cancel_inbound (ElementRecord &rec)
 
void cancel_outbound (ElementRecord &rec)
 
ElementRecord * find_record (const ElementRef &ref)
 
std::string make_layer_task_name (const char *suffix) const
 
std::string make_task_name (uint32_t id, const char *suffix) const
 
void spawn_inbound (const ElementRef &ref, std::function< float()> source)
 
void write_aggregate (Layer &layer, std::vector< std::function< float()> > readers, std::function< void(std::span< const float >)> sink)
 
void write_assembled_data (Layer &layer, std::function< Kakshya::DataVariant()> assemble, std::function< void(Kakshya::DataVariant)> write)
 

Static Private Member Functions

template<typename T >
static ElementRef ref_of (const std::shared_ptr< MappedState< T > > &state)
 

Private Attributes

Buffers::BufferManager & m_buffer_manager
 
std::map< std::weak_ptr< Layer >, std::vector< std::string >, std::owner_less<> > m_layer_tasks
 
uint32_t m_next_id { 0 }
 
std::map< std::weak_ptr< Layer >, std::unordered_map< uint32_t, ElementRecord >, std::owner_less<> > m_records
 
Vruta::TaskScheduler & m_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(ref, Node) — reads Node::get_last_output() via GraphicsRoutine
  • bind(ref, lambda) — calls std::function<float()> via GraphicsRoutine

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

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

Element ids are unique only within their Layer, so every element is addressed by an ElementRef. All overloads also accept shared_ptr<MappedState<T>> in place of the ElementRef; the state carries both halves once registered.

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){});
std::weak_ptr< Core::Window > window
Definition Picker.cpp:23
void write(std::shared_ptr< MappedState< T > > state, std::function< void(std::span< const float >)> sink)
Definition Bridge.hpp:138
void bind(const ElementRef &ref, std::shared_ptr< Nodes::Node > node, std::function< float(double)> project={})
Drive element value from a Node's output each frame.
Definition Bridge.cpp:45
Two-way binding orchestrator for Forma elements.
Definition Bridge.hpp:74
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:80
Bridge & bridge()
Return the application-level Bridge instance.
Definition Forma.cpp:71

Definition at line 74 of file Bridge.hpp.


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