MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Sinks.hpp
Go to the documentation of this file.
1#pragma once
2
4
7
8namespace MayaFlux::Core {
9class Window;
10}
11
13struct RenderConfig;
14}
15
16namespace MayaFlux::Buffers {
17class AudioBuffer;
18class VKBuffer;
19class BufferManager;
20class AudioWriteProcessor;
21class GeometryWriteProcessor;
22class TextureWriteProcessor;
23class RenderProcessor;
24}
25
26namespace MayaFlux::Nexus {
27
28using RenderFn = std::function<void(const InfluenceContext&)>;
29
30/**
31 * @struct AudioSink
32 * @brief Holds the plumbing for one audio output registered from a Nexus object.
33 *
34 * Created by add_audio_sink(). Owns the AudioBuffer and AudioWriteProcessor.
35 * The buffer is registered with the supplied BufferManager on construction
36 * and unregistered on destruction via remove_audio_sink().
37 *
38 * If @c fn is set, dispatch_audio_sinks() calls it with the current
39 * InfluenceContext and forwards the result to the writer. If @c fn is empty,
40 * data arrives only via push_audio_data().
41 */
42struct AudioSink {
43 std::shared_ptr<Buffers::AudioBuffer> buf;
44 std::shared_ptr<Buffers::AudioWriteProcessor> writer;
46 std::string fn_name;
47 uint32_t channel {};
48};
49
50/**
51 * @struct RenderSink
52 * @brief Holds the plumbing for one graphics output registered from a Nexus object.
53 *
54 * Created by add_render_sink(). Owns the VKBuffer, GeometryWriteProcessor,
55 * and RenderProcessor. The buffer is registered with the supplied BufferManager
56 * on construction and unregistered on destruction via remove_render_sink().
57 *
58 * Default rendering uses POINT_LIST topology with point.vert.spv /
59 * point.frag.spv. The object's spatial position is written as a single
60 * point when dispatch_render_sinks() fires and no fn is set.
61 *
62 * If @c fn is set, dispatch_render_sinks() calls it and forwards the result
63 * to the writer. If @c fn is empty, data arrives only via push_geometry().
64 */
65struct RenderSink {
66 std::shared_ptr<Buffers::VKBuffer> buf;
67 std::shared_ptr<Buffers::GeometryWriteProcessor> writer;
68 std::shared_ptr<Buffers::RenderProcessor> renderer;
70 std::string fn_name;
71 std::shared_ptr<Core::Window> window;
72};
73
74// =============================================================================
75// Audio sink free functions
76// =============================================================================
77
78/**
79 * @brief Create and register an audio sink on @p channel.
80 * @param sinks Sink vector owned by the calling Emitter or Agent.
81 * @param mgr BufferManager to register the AudioBuffer with.
82 * @param channel Output channel index.
83 * @param fn Optional producer called each dispatch with InfluenceContext.
84 * Leave empty when data is supplied via push_audio_data().
85 * @param fn_name Optional identifier for state encoding, empty if anonymous.
86 */
88 std::vector<AudioSink>& sinks,
90 uint32_t channel,
91 std::function<Kakshya::DataVariant(const InfluenceContext&)> fn = {},
92 std::string fn_name = {});
93
94/**
95 * @brief Unregister and destroy the audio sink on @p channel.
96 * @param sinks Sink vector owned by the calling Emitter or Agent.
97 * @param mgr BufferManager the AudioBuffer was registered with.
98 * @param channel Channel index passed to add_audio_sink().
99 */
101 std::vector<AudioSink>& sinks,
102 Buffers::BufferManager& mgr,
103 uint32_t channel);
104
105/**
106 * @brief Push @p samples to every audio sink in @p sinks.
107 * @param sinks Sink vector owned by the calling Emitter or Agent.
108 * @param samples Sample data forwarded to AudioWriteProcessor::set_data().
109 */
110void push_audio_data(
111 std::vector<AudioSink>& sinks,
112 std::span<const double> samples);
113
114/**
115 * @brief For each sink that has a producer fn, call it and push the result.
116 * Sinks without a fn are untouched.
117 * @param sinks Sink vector owned by the calling Emitter or Agent.
118 * @param ctx Current InfluenceContext passed to each fn.
119 */
121 std::vector<AudioSink>& sinks,
122 const InfluenceContext& ctx);
123
124// =============================================================================
125// Render sink free functions
126// =============================================================================
127
128/**
129 * @brief Create and register a render sink targeting @p window.
130 *
131 * Allocates a VKBuffer (VERTEX, POINT_LIST), attaches a GeometryWriteProcessor
132 * and a RenderProcessor with point.vert.spv / point.frag.spv defaults, and
133 * registers the buffer with @p mgr.
134 *
135 * @param sinks Sink vector owned by the calling Emitter or Agent.
136 * @param mgr BufferManager to register the VKBuffer with.
137 * @param window Target window for presentation.
138 * @param fn Optional producer called each dispatch with InfluenceContext.
139 * Leave empty when geometry is supplied via push_geometry().
140 * @param fn_name Optional identifier for state encoding, empty if anonymous.
141 * @param initial_position Optional initial position to write if no producer fn is set.
142 */
143void add_render_sink(
144 std::vector<RenderSink>& sinks,
145 Buffers::BufferManager& mgr,
146 const Portal::Graphics::RenderConfig& config,
147 RenderFn fn = {},
148 std::string fn_name = {},
149 const std::optional<glm::vec3>& initial_position = {});
150
151/**
152 * @brief Unregister and destroy the render sink targeting @p window.
153 * @param sinks Sink vector owned by the calling Emitter or Agent.
154 * @param mgr BufferManager the VKBuffer was registered with.
155 * @param window Window passed to add_render_sink().
156 */
158 std::vector<RenderSink>& sinks,
159 Buffers::BufferManager& mgr,
160 const std::shared_ptr<Core::Window>& window);
161
162/**
163 * @brief Push pre-resolved vertex bytes to every render sink.
164 * @param sinks Sink vector owned by the calling Emitter or Agent.
165 * @param data Pointer to vertex data.
166 * @param byte_count Total size in bytes.
167 * @param layout VertexLayout describing stride and attributes.
168 */
169void push_vertices(
170 std::vector<RenderSink>& sinks,
171 const void* data, size_t byte_count,
172 const Kakshya::VertexLayout& layout);
173
174/**
175 * @brief For each sink that has a producer fn, call it and push the result.
176 * If no fn is set, writes the object position as a single point.
177 * @param sinks Sink vector owned by the calling Emitter or Agent.
178 * @param ctx Current InfluenceContext passed to each fn.
179 */
181 std::vector<RenderSink>& sinks,
182 const InfluenceContext& ctx);
183
184} // namespace MayaFlux::Nexus
uint32_t channel
std::string fn_name
Token-based multimodal buffer management system for unified data stream processing.
std::variant< std::vector< double >, std::vector< float >, std::vector< uint8_t >, std::vector< uint16_t >, std::vector< uint32_t >, std::vector< std::complex< float > >, std::vector< std::complex< double > >, std::vector< glm::vec2 >, std::vector< glm::vec3 >, std::vector< glm::vec4 >, std::vector< glm::mat4 > > DataVariant
Multi-type data storage for different precision needs.
Definition NDData.hpp:76
void remove_render_sink(std::vector< RenderSink > &sinks, Buffers::BufferManager &mgr, const std::shared_ptr< Core::Window > &window)
Unregister and destroy the render sink targeting window.
Definition Sinks.cpp:194
void add_audio_sink(std::vector< AudioSink > &sinks, Buffers::BufferManager &mgr, uint32_t channel, std::function< Kakshya::DataVariant(const InfluenceContext &)> fn, std::string fn_name)
Create and register an audio sink on channel.
Definition Sinks.cpp:18
void dispatch_audio_sinks(std::vector< AudioSink > &sinks, const InfluenceContext &ctx)
For each sink that has a producer fn, call it and push the result.
Definition Sinks.cpp:71
void add_render_sink(std::vector< RenderSink > &sinks, Buffers::BufferManager &mgr, const Portal::Graphics::RenderConfig &config, RenderFn fn, std::string fn_name, const std::optional< glm::vec3 > &initial_position)
Create and register a render sink targeting window.
Definition Sinks.cpp:95
std::function< void(const InfluenceContext &)> RenderFn
Definition Sinks.hpp:28
void push_audio_data(std::vector< AudioSink > &sinks, std::span< const double > samples)
Push samples to every audio sink in sinks.
Definition Sinks.cpp:64
void remove_audio_sink(std::vector< AudioSink > &sinks, Buffers::BufferManager &mgr, uint32_t channel)
Unregister and destroy the audio sink on channel.
Definition Sinks.cpp:43
void push_vertices(std::vector< RenderSink > &sinks, const void *data, size_t byte_count, const Kakshya::VertexLayout &layout)
Push pre-resolved vertex bytes to every render sink.
Definition Sinks.cpp:215
void dispatch_render_sinks(std::vector< RenderSink > &sinks, const InfluenceContext &ctx)
For each sink that has a producer fn, call it and push the result.
Definition Sinks.cpp:225
std::function< Kakshya::DataVariant(const InfluenceContext &)> fn
Definition Sinks.hpp:45
std::shared_ptr< Buffers::AudioWriteProcessor > writer
Definition Sinks.hpp:44
std::shared_ptr< Buffers::AudioBuffer > buf
Definition Sinks.hpp:43
Holds the plumbing for one audio output registered from a Nexus object.
Definition Sinks.hpp:42
Data passed to an Emitter or Agent influence function on each commit.
std::shared_ptr< Buffers::RenderProcessor > renderer
Definition Sinks.hpp:68
std::shared_ptr< Core::Window > window
Definition Sinks.hpp:71
std::shared_ptr< Buffers::VKBuffer > buf
Definition Sinks.hpp:66
std::shared_ptr< Buffers::GeometryWriteProcessor > writer
Definition Sinks.hpp:67
Holds the plumbing for one graphics output registered from a Nexus object.
Definition Sinks.hpp:65