MayaFlux 0.2.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
BufferProcessingControl.hpp
Go to the documentation of this file.
1#pragma once
2
5
6namespace MayaFlux::Nodes {
7class Node;
8}
9
10namespace MayaFlux::Buffers {
11
12class BufferProcessor;
13class BufferProcessingChain;
14class TokenUnitManager;
15class BufferAccessControl;
16
17/**
18 * @class BufferProcessingControl
19 * @brief Processor attachment, removal, and processing chain management
20 *
21 * Manages all operations related to adding/removing processors to buffers
22 * and processing chains. Handles processor routing for different tokens,
23 * processor lifecycle (quick processes), and node-to-buffer connections.
24 *
25 * Design Principles:
26 * - Token-aware: Routes processors to appropriate token chains
27 * - Domain-agnostic: Works with any token's processing chains
28 * - Single responsibility: Only handles processor management, not access/input
29 * - Delegates to TokenUnitManager and BufferAccessControl for underlying operations
30 *
31 * This class centralizes all processor-related logic that was scattered
32 * throughout the original BufferManager.
33 */
34class MAYAFLUX_API BufferProcessingControl {
35public:
36 /**
37 * @brief Creates a new processing control handler
38 * @param unit_manager Reference to the TokenUnitManager
39 * @param access_control Reference to the BufferAccessControl
40 */
41 BufferProcessingControl(TokenUnitManager& unit_manager, BufferAccessControl& access_control);
42
44
45 // =========================================================================
46 // Processor Management (Token-Dispatching)
47 // =========================================================================
48
49 /**
50 * @brief Adds a processor to a buffer (dispatches based on buffer/token)
51 * @param processor Processor to add
52 * @param buffer Target buffer
53 * @param token Processing domain (optional, used for routing)
54 */
55 void add_processor(
56 const std::shared_ptr<BufferProcessor>& processor,
57 const std::shared_ptr<Buffer>& buffer,
58 ProcessingToken token = ProcessingToken::AUDIO_BACKEND);
59
60 /**
61 * @brief Adds a processor to a token (dispatches based on token)
62 * @param processor Processor to add
63 * @param token Processing domain
64 * @param channel Channel index (optional, used for audio tokens)
65 */
66 void add_processor(
67 const std::shared_ptr<BufferProcessor>& processor,
69 uint32_t channel);
70
71 /**
72 * @brief Adds a processor to all channels in a token (dispatches based on token)
73 * @param processor Processor to add
74 * @param token Processing domain
75 */
76 void add_processor(
77 const std::shared_ptr<BufferProcessor>& processor,
79
80 /**
81 * @brief Removes a processor from a buffer (dispatches based on buffer/token)
82 * @param processor Processor to remove
83 * @param buffer Target buffer
84 * @param token Processing domain (optional, used for routing)
85 */
86 void remove_processor(
87 const std::shared_ptr<BufferProcessor>& processor,
88 const std::shared_ptr<Buffer>& buffer,
89 ProcessingToken token = ProcessingToken::AUDIO_BACKEND);
90
91 /**
92 * @brief Removes a processor from a token (dispatches based on token)
93 * @param processor Processor to remove
94 * @param token Processing domain
95 * @param channel Channel index (optional, used for audio tokens)
96 */
97 void remove_processor_from_token(
98 const std::shared_ptr<BufferProcessor>& processor,
100 uint32_t channel = 0);
101
102 /**
103 * @brief Sets a final processor for a token (dispatches based on token)
104 * @param processor Final processor to apply
105 * @param token Processing domain
106 */
107 void set_final_processor(
108 const std::shared_ptr<BufferProcessor>& processor,
110
111 // =========================================================================
112 // Processor Management - Audio
113 // =========================================================================
114
115 /**
116 * @brief Adds a processor to a specific audio buffer
117 * @param processor Processor to add
118 * @param buffer Target audio buffer
119 *
120 * Routes the processor to the appropriate processing chain based on the buffer's channel ID.
121 */
122 void add_audio_processor(
123 const std::shared_ptr<BufferProcessor>& processor,
124 const std::shared_ptr<AudioBuffer>& buffer);
125
126 /**
127 * @brief Adds a processor to a specific audio token and channel
128 * @param processor Processor to add
129 * @param token Processing domain
130 * @param channel Channel index
131 */
132 void add_audio_processor_to_channel(
133 const std::shared_ptr<BufferProcessor>& processor,
135 uint32_t channel);
136
137 /**
138 * @brief Adds a processor to all channels in an audio token
139 * @param processor Processor to add
140 * @param token Processing domain
141 */
142 void add_audio_processor_to_token(
143 const std::shared_ptr<BufferProcessor>& processor,
145
146 /**
147 * @brief Removes a processor from a specific audio buffer
148 * @param processor Processor to remove
149 * @param buffer Target audio buffer
150 */
151 void remove_audio_processor(
152 const std::shared_ptr<BufferProcessor>& processor,
153 const std::shared_ptr<AudioBuffer>& buffer);
154
155 /**
156 * @brief Removes a processor from a specific audio token and channel
157 * @param processor Processor to remove
158 * @param token Processing domain
159 * @param channel Channel index
160 */
161 void remove_audio_processor_from_channel(
162 const std::shared_ptr<BufferProcessor>& processor,
164 uint32_t channel);
165
166 /**
167 * @brief Removes a processor from all channels in an audio token
168 * @param processor Processor to remove
169 * @param token Processing domain
170 */
171 void remove_audio_processor_from_token(
172 const std::shared_ptr<BufferProcessor>& processor,
174
175 /**
176 * @brief Sets a final processor for an audio token (applied to all channels)
177 * @param processor Final processor to apply
178 * @param token Processing domain
179 *
180 * Final processors are applied as the last step in the processing chain.
181 */
182 void set_audio_final_processor(
183 const std::shared_ptr<BufferProcessor>& processor,
185
186 // =========================================================================
187 // Quick Processing - Audio
188 // =========================================================================
189
190 /**
191 * @brief Creates and attaches a quick processing function to buffer
192 * @param processor Processing function
193 * @param buffer Target buffer
194 * @return Shared pointer to the created processor
195 *
196 * Quick processes are simple lambda-based processors for one-off transformations.
197 */
198 std::shared_ptr<BufferProcessor> attach_quick_process(
199 AudioProcessingFunction processor,
200 const std::shared_ptr<Buffer>& buffer, ProcessingToken token = ProcessingToken::AUDIO_BACKEND);
201
202 std::shared_ptr<BufferProcessor> attach_quick_process(
204 const std::shared_ptr<Buffer>& buffer, ProcessingToken token = ProcessingToken::GRAPHICS_BACKEND);
205
206 /**
207 * @brief Creates and attaches a quick processing function to an audio token/channel
208 * @param processor Processing function
209 * @param token Processing domain
210 * @param channel Channel index
211 * @return Shared pointer to the created processor
212 */
213 std::shared_ptr<BufferProcessor> attach_quick_process(
214 AudioProcessingFunction processor,
216 uint32_t channel);
217
218 /**
219 * @brief Creates and attaches a quick processing function to all channels in a token
220 * @param processor Processing function
221 * @param token Processing domain
222 * @return Shared pointer to the created processor
223 */
224 std::shared_ptr<BufferProcessor> attach_quick_process(
225 AudioProcessingFunction processor,
227
228 std::shared_ptr<BufferProcessor> attach_quick_process(
231
232 // =========================================================================
233 // Node Connection - Audio
234 // =========================================================================
235
236 /**
237 * @brief Connects a node to a specific audio token and channel
238 * @param node Node to connect
239 * @param token Processing domain
240 * @param channel Channel index
241 * @param mix Mix level (default: 0.5)
242 * @param clear_before Whether to clear buffer before adding node output (default: false)
243 *
244 * Creates a NodeSourceProcessor that feeds node output into the channel.
245 */
246 void connect_node_to_audio_channel(
247 const std::shared_ptr<Nodes::Node>& node,
249 uint32_t channel,
250 float mix = 0.5F,
251 bool clear_before = false);
252
253 /**
254 * @brief Connects a node directly to a specific audio buffer
255 * @param node Node to connect
256 * @param buffer Target audio buffer
257 * @param mix Mix level (default: 0.5)
258 * @param clear_before Whether to clear buffer before adding node output (default: true)
259 */
260 void connect_node_to_audio_buffer(
261 const std::shared_ptr<Nodes::Node>& node,
262 const std::shared_ptr<AudioBuffer>& buffer,
263 float mix = 0.5F,
264 bool clear_before = true);
265
266 // =========================================================================
267 // Processor Management - Graphics
268 // =========================================================================
269
270 /**
271 * @brief Adds a processor to the graphics processing chain
272 * @param processor Processor to add
273 * @param token Processing domain
274 */
275 void add_graphics_processor(
276 const std::shared_ptr<BufferProcessor>& processor,
278
279 /**
280 * @brief Adds a processor to a specific graphics buffer
281 * @param processor Processor to add
282 * @param buffer Target graphics buffer
283 * @param token Processing domain
284 */
285 void add_graphics_processor(
286 const std::shared_ptr<BufferProcessor>& processor,
287 const std::shared_ptr<class Buffer>& buffer,
289
290 /**
291 * @brief Sets a final processor for the graphics processing chain
292 * @param processor Final processor to apply
293 * @param token Processing domain
294 */
295 void set_graphics_final_processor(
296 const std::shared_ptr<BufferProcessor>& processor,
298
299 /**
300 * @brief Removes a processor from the graphics processing chain
301 * @param processor Processor to remove
302 * @param token Processing domain
303 */
304 void remove_graphics_processor(
305 const std::shared_ptr<BufferProcessor>& processor,
307
308private:
309 /// Reference to the token/unit manager
311
312 /// Reference to the buffer access control
314};
315
316} // namespace MayaFlux::Buffers
static MayaFlux::Nodes::ProcessingToken token
Definition Timers.cpp:8
Token-aware buffer and unit access patterns.
TokenUnitManager & m_unit_manager
Reference to the token/unit manager.
BufferAccessControl & m_access_control
Reference to the buffer access control.
Processor attachment, removal, and processing chain management.
Token-scoped unit storage and lifecycle management.
std::function< void(const std::shared_ptr< AudioBuffer > &)> AudioProcessingFunction
Audio processing function - receives correctly-typed AudioBuffer.
ProcessingToken
Bitfield enum defining processing characteristics and backend requirements for buffer operations.
std::function< void(const std::shared_ptr< VKBuffer > &)> GraphicsProcessingFunction
Graphics processing function - receives correctly-typed VKBuffer.
Contains the node-based computational processing system components.
Definition Chronie.hpp:5
void add_processor(const std::shared_ptr< Buffers::BufferProcessor > &processor, const std::shared_ptr< Buffers::Buffer > &buffer, Buffers::ProcessingToken token)
Adds a processor to a specific buffer.
Definition Graph.cpp:116
std::shared_ptr< Buffers::BufferProcessor > attach_quick_process(Buffers::AudioProcessingFunction processor, unsigned int channel_id)
Attaches a processing function to a specific channel.
Definition Graph.cpp:170