MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
BufferAccessControl.hpp
Go to the documentation of this file.
1#pragma once
2
5
6namespace MayaFlux::Buffers {
7
8class AudioBuffer;
9class Buffer;
10class VKBuffer;
11class RootAudioBuffer;
12class RootGraphicsBuffer;
13class BufferProcessingChain;
14class TokenUnitManager;
15
16/**
17 * @class BufferAccessControl
18 * @brief Token-aware buffer and unit access patterns
19 *
20 * Manages all operations related to accessing and querying buffer data, units,
21 * and processing chains. Works directly with a TokenUnitManager that it holds
22 * as a member, providing a cohesive interface for buffer access operations.
23 *
24 * Design Principles:
25 * - Member variable: Holds reference to TokenUnitManager
26 * - Token-aware: Works with any token's audio or graphics units
27 * - Domain-agnostic: Doesn't distinguish between audio/graphics at logic level
28 * - Single responsibility: Only handles access/query/resize, not processing
29 *
30 * This class is a facade over the unit manager's storage, providing convenient
31 * methods for the common buffer access patterns BufferManager needs.
32 */
33class MAYAFLUX_API BufferAccessControl {
34public:
35 /**
36 * @brief Creates a new access control handler
37 * @param unit_manager Reference to the TokenUnitManager
38 */
39 explicit BufferAccessControl(TokenUnitManager& unit_manager);
40
42
43 // =========================================================================
44 // Audio Buffer Data Access
45 // =========================================================================
46
47 /**
48 * @brief Gets mutable reference to audio buffer data for a channel
49 * @param token Processing domain
50 * @param channel Channel index
51 * @return Reference to the audio buffer's data vector
52 */
53 std::vector<double>& get_audio_buffer_data(ProcessingToken token, uint32_t channel);
54
55 /**
56 * @brief Gets const reference to audio buffer data for a channel
57 * @param token Processing domain
58 * @param channel Channel index
59 * @return Const reference to the audio buffer's data vector
60 */
61 [[nodiscard]] const std::vector<double>& get_audio_buffer_data(ProcessingToken token, uint32_t channel) const;
62
63 // =========================================================================
64 // Audio Channel and Sizing Operations
65 // =========================================================================
66
67 /**
68 * @brief Gets the number of channels for an audio token
69 * @param token Processing domain
70 * @return Number of channels, or 0 if token not found
71 */
72 [[nodiscard]] uint32_t get_num_audio_out_channels(ProcessingToken token) const;
73
74 /**
75 * @brief Gets the buffer size for an audio token
76 * @param token Processing domain
77 * @return Buffer size in samples, or 512 if token not found
78 */
79 [[nodiscard]] uint32_t get_audio_buffer_size(ProcessingToken token) const;
80
81 /**
82 * @brief Resizes all audio buffers for a token to the specified size
83 * @param token Processing domain
84 * @param buffer_size New buffer size in samples
85 */
86 void resize_audio_buffers(ProcessingToken token, uint32_t buffer_size);
87
88 /**
89 * @brief Ensures minimum number of audio channels exist for a token
90 * @param token Processing domain
91 * @param channel_count Minimum number of channels to ensure
92 */
93 void ensure_audio_channels(ProcessingToken token, uint32_t channel_count);
94
95 // =========================================================================
96 // Root Buffer Access (Audio)
97 // =========================================================================
98
99 /**
100 * @brief Gets the root audio buffer for a specific token and channel
101 * @param token Processing domain
102 * @param channel Channel index
103 * @return Shared pointer to the root audio buffer
104 */
105 std::shared_ptr<RootAudioBuffer> get_root_audio_buffer(ProcessingToken token, uint32_t channel);
106
107 /**
108 * @brief Gets the root audio buffer for a specific token and channel (const)
109 * @param token Processing domain
110 * @param channel Channel index
111 * @return Shared pointer to the root audio buffer
112 */
113 [[nodiscard]] std::shared_ptr<const RootAudioBuffer> get_root_audio_buffer(ProcessingToken token, uint32_t channel) const;
114
115 // =========================================================================
116 // Root Buffer Access (Graphics)
117 // =========================================================================
118
119 /**
120 * @brief Gets the root graphics buffer for a specific token
121 * @param token Processing domain
122 * @return Shared pointer to the root graphics buffer
123 */
124 std::shared_ptr<RootGraphicsBuffer> get_root_graphics_buffer(ProcessingToken token);
125
126 /**
127 * @brief Gets the root graphics buffer for a specific token (const)
128 * @param token Processing domain
129 * @return Shared pointer to the root graphics buffer
130 */
131 [[nodiscard]] std::shared_ptr<const RootGraphicsBuffer> get_root_graphics_buffer(ProcessingToken token) const;
132
133 // =========================================================================
134 // Audio Buffer Hierarchy Management
135 // =========================================================================
136
137 /**
138 * @brief Adds a buffer to a token (dispatches based on token type)
139 * @param buffer Buffer to add (AudioBuffer or VKBuffer)
140 * @param token Processing domain
141 * @param channel Channel index (used only for audio tokens)
142 */
143 void add_buffer(
144 const std::shared_ptr<Buffer>& buffer,
146 uint32_t channel = 0);
147
148 /**
149 * @brief Adds an audio buffer to a token and channel
150 * @param buffer Audio buffer to add
151 * @param token Processing domain
152 * @param channel Channel index
153 */
154 void add_audio_buffer(
155 const std::shared_ptr<AudioBuffer>& buffer,
157 uint32_t channel);
158
159 /**
160 * @brief Removes a buffer from a token (dispatches based on token type)
161 * @param buffer Buffer to remove
162 * @param token Processing domain
163 * @param channel Channel index (used only for audio tokens)
164 */
165 void remove_buffer(
166 const std::shared_ptr<Buffer>& buffer,
168 uint32_t channel = 0);
169
170 /**
171 * @brief Removes an audio buffer from a token and channel
172 * @param buffer Audio buffer to remove
173 * @param token Processing domain
174 * @param channel Channel index
175 */
176 void remove_audio_buffer(
177 const std::shared_ptr<AudioBuffer>& buffer,
179 uint32_t channel);
180
181 /**
182 * @brief Gets all audio buffers for a token and channel
183 * @param token Processing domain
184 * @param channel Channel index
185 * @return Const reference to vector of audio buffers
186 */
187 [[nodiscard]] const std::vector<std::shared_ptr<AudioBuffer>>& get_audio_buffers(
189 uint32_t channel) const;
190
191 // =========================================================================
192 // Graphics Buffer Hierarchy Management
193 // =========================================================================
194
195 /**
196 * @brief Adds a graphics buffer to a token
197 * @param buffer Graphics buffer to add (must be VKBuffer-derived)
198 * @param token Processing domain
199 */
200 void add_graphics_buffer(const std::shared_ptr<Buffer>& buffer, ProcessingToken token);
201
202 /**
203 * @brief Removes a graphics buffer from a token
204 * @param buffer Graphics buffer to remove
205 * @param token Processing domain
206 */
207 void remove_graphics_buffer(const std::shared_ptr<Buffer>& buffer, ProcessingToken token);
208
209 /**
210 * @brief Gets all graphics buffers for a token
211 * @param token Processing domain
212 * @return Const reference to vector of graphics buffers
213 */
214 [[nodiscard]] const std::vector<std::shared_ptr<VKBuffer>>& get_graphics_buffers(ProcessingToken token) const;
215
216 /**
217 * @brief Gets graphics buffers filtered by usage type
218 * @param usage VKBuffer::Usage type to filter by
219 * @param token Processing domain
220 * @return Vector of buffers matching the specified usage
221 */
222 [[nodiscard]] std::vector<std::shared_ptr<VKBuffer>> get_graphics_buffers_by_usage(
223 VKBuffer::Usage usage,
224 ProcessingToken token) const;
225
226 // =========================================================================
227 // Processing Chain Access
228 // =========================================================================
229
230 /**
231 * @brief Gets the processing chain for an audio token and channel
232 * @param token Processing domain
233 * @param channel Channel index
234 * @return Shared pointer to the processing chain
235 */
236 std::shared_ptr<BufferProcessingChain> get_audio_processing_chain(ProcessingToken token, uint32_t channel);
237
238 /**
239 * @brief Gets the processing chain for a graphics token
240 * @param token Processing domain
241 * @return Shared pointer to the processing chain
242 */
243 std::shared_ptr<BufferProcessingChain> get_graphics_processing_chain(ProcessingToken token);
244
245 /**
246 * @brief Initializes the buffer service for Vulkan operations
247 */
248 void initialize_buffer_service();
249
250 /**
251 * @brief Terminates all active Audio and VK buffers
252 */
253 void terminate_active_buffers();
254
255private:
256 /// Reference to the token/unit manager for storage operations
258
259 /// Vulkan buffer processing context
260 Registry::Service::BufferService* m_buffer_service = nullptr;
261};
262
263} // namespace MayaFlux::Buffers
static MayaFlux::Nodes::ProcessingToken token
Definition Timers.cpp:8
TokenUnitManager & m_unit_manager
Reference to the token/unit manager for storage operations.
Token-aware buffer and unit access patterns.
Token-scoped unit storage and lifecycle management.
ProcessingToken
Bitfield enum defining processing characteristics and backend requirements for buffer operations.
Buffers::RootAudioBuffer & get_root_audio_buffer(uint32_t channel)
Gets the audio buffer for a specific channel.
Definition Graph.cpp:106
Backend buffer management service interface.