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
6
7namespace MayaFlux::Core {
8class Window;
9}
10
12struct RenderConfig;
13}
14
15namespace MayaFlux::Buffers {
16class AudioBuffer;
17class VKBuffer;
18class BufferManager;
19class AudioWriteProcessor;
20class DataWriteProcessor;
21class RenderProcessor;
22}
23
24namespace MayaFlux::Nexus {
25
26using RenderFn = std::function<void(const InfluenceContext&)>;
27
28/**
29 * @struct AudioSink
30 * @brief Holds the plumbing for one audio output registered from a Nexus object.
31 *
32 * Created by add_audio_sink(). Owns the AudioBuffer and AudioWriteProcessor.
33 * The buffer is registered with the supplied BufferManager on construction
34 * and unregistered on destruction via remove_audio_sink().
35 *
36 * If @c fn is set, dispatch_audio_sinks() calls it with the current
37 * InfluenceContext and forwards the result to the writer. If @c fn is empty,
38 * data arrives only via push_audio_data().
39 */
40struct AudioSink {
41 std::shared_ptr<Buffers::AudioBuffer> buf;
42 std::shared_ptr<Buffers::AudioWriteProcessor> writer;
44 std::string fn_name;
45 uint32_t channel {};
46};
47
48/**
49 * @struct RenderSink
50 * @brief Holds the plumbing for one graphics output registered from a Nexus object.
51 *
52 * Created by add_render_sink(). Owns the VKBuffer, DataWriteProcessor,
53 * and RenderProcessor. The buffer is registered with the supplied BufferManager
54 * on construction and unregistered on destruction via remove_render_sink().
55 *
56 * Default rendering uses POINT_LIST topology with point.vert.spv /
57 * point.frag.spv. The object's spatial position is written as a single
58 * point when dispatch_render_sinks() fires and no fn is set.
59 *
60 * If @c fn is set, dispatch_render_sinks() calls it and forwards the result
61 * to the writer. If @c fn is empty, data arrives only via push_geometry().
62 */
63struct RenderSink {
64 std::shared_ptr<Buffers::VKBuffer> buf;
65 std::shared_ptr<Buffers::DataWriteProcessor> writer;
66 std::shared_ptr<Buffers::RenderProcessor> renderer;
68 std::string fn_name;
69 std::shared_ptr<Core::Window> window;
70};
71
72// =============================================================================
73// Audio sink free functions
74// =============================================================================
75
76/**
77 * @brief Create and register an audio sink on @p channel.
78 * @param sinks Sink vector owned by the calling Emitter or Agent.
79 * @param mgr BufferManager to register the AudioBuffer with.
80 * @param channel Output channel index.
81 * @param fn Optional producer called each dispatch with InfluenceContext.
82 * Leave empty when data is supplied via push_audio_data().
83 * @param fn_name Optional identifier for state encoding, empty if anonymous.
84 */
85MAYAFLUX_API void add_audio_sink(
86 std::vector<AudioSink>& sinks,
88 uint32_t channel,
89 std::function<Kakshya::DataVariant(const InfluenceContext&)> fn = {},
90 std::string fn_name = {});
91
92/**
93 * @brief Unregister and destroy the audio sink on @p channel.
94 * @param sinks Sink vector owned by the calling Emitter or Agent.
95 * @param mgr BufferManager the AudioBuffer was registered with.
96 * @param channel Channel index passed to add_audio_sink().
97 */
98MAYAFLUX_API void remove_audio_sink(
99 std::vector<AudioSink>& sinks,
100 Buffers::BufferManager& mgr,
101 uint32_t channel);
102
103/**
104 * @brief Push @p samples to every audio sink in @p sinks.
105 * @param sinks Sink vector owned by the calling Emitter or Agent.
106 * @param samples Sample data forwarded to AudioWriteProcessor::set_data().
107 */
108MAYAFLUX_API void push_audio_data(
109 std::vector<AudioSink>& sinks,
110 std::span<const double> samples);
111
112/**
113 * @brief For each sink that has a producer fn, call it and push the result.
114 * Sinks without a fn are untouched.
115 * @param sinks Sink vector owned by the calling Emitter or Agent.
116 * @param ctx Current InfluenceContext passed to each fn.
117 */
118MAYAFLUX_API void dispatch_audio_sinks(
119 std::vector<AudioSink>& sinks,
120 const InfluenceContext& ctx);
121
122// =============================================================================
123// Render sink free functions
124// =============================================================================
125
126/**
127 * @brief Create and register a render sink targeting @p window.
128 *
129 * Allocates a VKBuffer (VERTEX, POINT_LIST), attaches a DataWriteProcessor
130 * and a RenderProcessor with point.vert.spv / point.frag.spv defaults, and
131 * registers the buffer with @p mgr.
132 *
133 * @param sinks Sink vector owned by the calling Emitter or Agent.
134 * @param mgr BufferManager to register the VKBuffer with.
135 * @param window Target window for presentation.
136 * @param fn Optional producer called each dispatch with InfluenceContext.
137 * Leave empty when geometry is supplied via push_geometry().
138 * @param fn_name Optional identifier for state encoding, empty if anonymous.
139 * @param initial_position Optional initial position to write if no producer fn is set.
140 */
141MAYAFLUX_API void add_render_sink(
142 std::vector<RenderSink>& sinks,
143 Buffers::BufferManager& mgr,
144 const Portal::Graphics::RenderConfig& config,
145 RenderFn fn = {},
146 std::string fn_name = {},
147 const std::optional<glm::vec3>& initial_position = {});
148
149/**
150 * @brief Unregister and destroy the render sink targeting @p window.
151 * @param sinks Sink vector owned by the calling Emitter or Agent.
152 * @param mgr BufferManager the VKBuffer was registered with.
153 * @param window Window passed to add_render_sink().
154 */
155MAYAFLUX_API void remove_render_sink(
156 std::vector<RenderSink>& sinks,
157 Buffers::BufferManager& mgr,
158 const std::shared_ptr<Core::Window>& window);
159
160/**
161 * @brief For each sink that has a producer fn, call it and push the result.
162 * If no fn is set, writes the object position as a single point.
163 * @param sinks Sink vector owned by the calling Emitter or Agent.
164 * @param ctx Current InfluenceContext passed to each fn.
165 */
166MAYAFLUX_API void dispatch_render_sinks(
167 std::vector<RenderSink>& sinks,
168 const InfluenceContext& ctx);
169
170} // namespace MayaFlux::Nexus
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
std::function< void(const InfluenceContext &)> RenderFn
Definition Sinks.hpp:26
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:186
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:207
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 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_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 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
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
std::function< Kakshya::DataVariant(const InfluenceContext &)> fn
Definition Sinks.hpp:43
std::shared_ptr< Buffers::AudioWriteProcessor > writer
Definition Sinks.hpp:42
std::shared_ptr< Buffers::AudioBuffer > buf
Definition Sinks.hpp:41
Holds the plumbing for one audio output registered from a Nexus object.
Definition Sinks.hpp:40
Data passed to an Emitter or Agent influence function on each commit.
std::shared_ptr< Buffers::RenderProcessor > renderer
Definition Sinks.hpp:66
std::shared_ptr< Buffers::DataWriteProcessor > writer
Definition Sinks.hpp:65
std::shared_ptr< Core::Window > window
Definition Sinks.hpp:69
std::shared_ptr< Buffers::VKBuffer > buf
Definition Sinks.hpp:64
Holds the plumbing for one graphics output registered from a Nexus object.
Definition Sinks.hpp:63