MayaFlux 0.3.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
ProcessingArchitecture.hpp
Go to the documentation of this file.
1#pragma once
2
4
5namespace MayaFlux::Nodes {
6class NodeGraphManager;
7}
8
9namespace MayaFlux::Buffers {
10class BufferManager;
11class Buffer;
12class VKBuffer;
13}
14
15namespace MayaFlux::Vruta {
16class TaskScheduler;
17class Routine;
18
19using token_processing_func_t = std::function<void(const std::vector<std::shared_ptr<Routine>>&, uint64_t)>;
20}
21
22/**
23 * @file ProcessingArchitecture.hpp
24 * @brief Unified processing architecture for multimodal subsystem coordination
25 *
26 * Token-based system where each processing domain (audio, video, custom) can have
27 * its own processing characteristics while maintaining unified interfaces.
28 */
29namespace MayaFlux::Core {
30
31class Window;
32class WindowManager;
33class InputManager;
34
35struct InputValue;
36
37/**
38 * @enum HookPosition
39 * @brief Defines the position in the processing cycle where a hook should be executed
40 *
41 * Process hooks can be registered to run either before or after the main audio processing
42 * to perform additional operations or monitoring at specific points in the signal chain.
43 */
44enum class HookPosition : uint8_t {
45 PRE_PROCESS, ///< Execute hook before any audio processing occurs
46 POST_PROCESS ///< Execute hook after all audio processing is complete
47};
48
49/**
50 * @typedef ProcessHook
51 * @brief Function type for process hooks that can be registered with the engine
52 *
53 * Process hooks are callbacks that execute at specific points in the audio processing cycle.
54 * They receive the current number of frames being processed and can be used for monitoring,
55 * debugging, or additional processing operations.
56 */
57using ProcessHook = std::function<void(unsigned int num_frames)>;
58
59/**
60 * @struct SubsystemTokens
61 * @brief Processing token configuration for subsystem operation
62 *
63 * Defines processing characteristics by specifying how buffers and nodes
64 * should be processed for each subsystem domain.
65 */
67 /** @brief Processing token for buffer operations */
69
70 /** @brief Processing token for node graph operations */
72
73 /** @brief Processing token for task scheduling operations */
75
76 /** @brief Equality comparison for efficient token matching */
77 bool operator==(const SubsystemTokens& other) const
78 {
79 return Buffer == other.Buffer && Node == other.Node && Task == other.Task;
80 }
81};
82
83/**
84 * @class BufferProcessingHandle
85 * @brief Thread-safe interface for buffer operations within a processing domain
86 *
87 * Provides scoped, thread-safe access to buffer operations with automatic token validation.
88 */
90public:
91 /** @brief Constructs handle for specific buffer manager and token */
93 std::shared_ptr<Buffers::BufferManager> manager,
95
96 // Non-copyable, moveable
101
102 /** @brief Process all channels in token domain */
103 void process(uint32_t processing_units);
104
105 /** @brief Process specific channel */
106 void process_channel(uint32_t channel, uint32_t processing_units);
107
108 /** @brief Process channel with node output data integration */
110 uint32_t channel,
111 uint32_t processing_units,
112 const std::vector<double>& node_data);
113
114 /** @brienf Process Input from backend into buffer manager */
115 void process_input(double* input_data, uint32_t num_channels, uint32_t num_frames);
116
117 /** @brief Get read-only access to channel data */
118 [[nodiscard]] std::span<const double> read_channel_data(uint32_t channel) const;
119
120 /** @brief Get write access to channel data with automatic locking */
121 std::span<double> write_channel_data(uint32_t channel);
122
123 /** @brief Configure channel layout for token domain */
124 void setup_channels(uint32_t num_channels, uint32_t buffer_size);
125
126 /* @brief Supply buffer to a channel with optional mixing */
128
129 /* @brief Route a buffer to a different channel with fade transition */
131
132private:
133 void ensure_valid() const;
134 void acquire_write_lock();
135
136 std::shared_ptr<Buffers::BufferManager> m_manager;
139};
140
141/**
142 * @class NodeProcessingHandle
143 * @brief Interface for node graph operations within a processing domain
144 *
145 * Provides scoped access to node operations with automatic token assignment.
146 */
148public:
149 /** @brief Constructs handle for specific node manager and token */
151 std::shared_ptr<Nodes::NodeGraphManager> manager,
153
154 /** @brief Process all nodes in token domain */
155 void process(uint32_t num_samples);
156
157 /** @brief Process nodes for specific channel and return output */
158 std::vector<double> process_channel(uint32_t channel, uint32_t num_samples);
159
160 double process_sample(uint32_t channel);
161
163
165
166 std::vector<std::vector<double>> process_audio_networks(uint32_t num_samples, uint32_t channel = 0);
167
168 /** @brief Create node with automatic token assignment */
169 template <typename NodeType, typename... Args>
170 std::shared_ptr<NodeType> create_node(Args&&... args)
171 {
172 auto node = std::make_shared<NodeType>(std::forward<Args>(args)...);
173 node->set_processing_token(m_token);
174 return node;
175 }
176
177private:
178 std::shared_ptr<Nodes::NodeGraphManager> m_manager;
180};
181
183public:
185 std::shared_ptr<MayaFlux::Vruta::TaskScheduler> task_manager,
187
188 /** @brief Register custom processing function for token domain */
190
191 /** @brief Process all tasks in token domain */
192 void process(uint64_t processing_units);
193
194 /** @brief Check if handle is valid */
195 [[nodiscard]] bool is_valid() const { return m_scheduler != nullptr; }
196
197 /** @brief Process all tasks scheduled for current buffer cycle */
199
200private:
201 std::shared_ptr<Vruta::TaskScheduler> m_scheduler;
203};
204
206public:
207 /** @brief Constructs handle for specific window manager */
208 WindowManagerHandle(std::shared_ptr<Core::WindowManager> window_manager);
209
210 /** @brief Process window events and frame hooks */
211 void process();
212
213 /** @brief Get list of windows that are open and not minimized */
214 [[nodiscard]] std::vector<std::shared_ptr<Core::Window>> get_processing_windows() const;
215
216private:
217 std::shared_ptr<Core::WindowManager> m_window_manager;
218};
219
221public:
222 /** @brief Constructs handle for specific InputManager */
223 InputManagerHandle(std::shared_ptr<InputManager> input_manager);
224
225 /** @brief start InputManager */
226 void start();
227
228 /** @brief stop InputManager */
229 void stop();
230
231 /** @brief unregister all nodes from InputManager */
232 void unregister();
233
234 /** @brief enqueue input value to InputManager */
235 void enqueue_input(const InputValue& value);
236
237private:
238 std::shared_ptr<InputManager> m_input_manager;
239};
240
241/**
242 * @class SubsystemProcessingHandle
243 * @brief Unified interface combining buffer and node processing for subsystems
244 *
245 * Single interface that coordinates buffer and node operations for a subsystem.
246 */
248public:
250 std::shared_ptr<Buffers::BufferManager> buffer_manager,
251 std::shared_ptr<Nodes::NodeGraphManager> node_manager,
252 std::shared_ptr<Vruta::TaskScheduler> task_scheduler,
253 std::shared_ptr<WindowManager> window_manager,
254 std::shared_ptr<InputManager> input_manager,
255 SubsystemTokens tokens);
256
257 /** @brief Buffer processing interface */
259
260 /** @brief Node processing interface */
262
264
266
268
269 /** @brief Get processing token configuration */
270 [[nodiscard]] inline SubsystemTokens get_tokens() const { return m_tokens; }
271
272 std::map<std::string, ProcessHook> pre_process_hooks;
273 std::map<std::string, ProcessHook> post_process_hooks;
274
275private:
277};
278
279} // namespace MayaFlux::Core
280
281namespace std {
282
283/** @brief Hash function specialization for SubsystemTokens */
284template <>
285struct hash<MayaFlux::Core::SubsystemTokens> {
286 size_t operator()(const MayaFlux::Core::SubsystemTokens& tokens) const noexcept
287 {
288 return hash<int>()(static_cast<int>(tokens.Node)) ^ hash<int>()(static_cast<int>(tokens.Buffer)) ^ hash<int>()(static_cast<int>(tokens.Task));
289 }
290};
291
292} // namespace std
std::span< double > write_channel_data(uint32_t channel)
Get write access to channel data with automatic locking.
std::span< const double > read_channel_data(uint32_t channel) const
Get read-only access to channel data.
void process_channel(uint32_t channel, uint32_t processing_units)
Process specific channel.
BufferProcessingHandle & operator=(const BufferProcessingHandle &)=delete
void process(uint32_t processing_units)
Process all channels in token domain.
void setup_channels(uint32_t num_channels, uint32_t buffer_size)
Configure channel layout for token domain.
BufferProcessingHandle(BufferProcessingHandle &&)=default
void process_channel_with_node_data(uint32_t channel, uint32_t processing_units, const std::vector< double > &node_data)
Process channel with node output data integration.
std::shared_ptr< Buffers::BufferManager > m_manager
BufferProcessingHandle & operator=(BufferProcessingHandle &&)=default
void process_input(double *input_data, uint32_t num_channels, uint32_t num_frames)
@brienf Process Input from backend into buffer manager
BufferProcessingHandle(const BufferProcessingHandle &)=delete
Thread-safe interface for buffer operations within a processing domain.
void unregister()
unregister all nodes from InputManager
void enqueue_input(const InputValue &value)
enqueue input value to InputManager
std::shared_ptr< InputManager > m_input_manager
void process(uint32_t num_samples)
Process all nodes in token domain.
std::vector< double > process_channel(uint32_t channel, uint32_t num_samples)
Process nodes for specific channel and return output.
std::shared_ptr< NodeType > create_node(Args &&... args)
Create node with automatic token assignment.
std::vector< std::vector< double > > process_audio_networks(uint32_t num_samples, uint32_t channel=0)
std::shared_ptr< Nodes::NodeGraphManager > m_manager
Interface for node graph operations within a processing domain.
std::map< std::string, ProcessHook > post_process_hooks
SubsystemTokens get_tokens() const
Get processing token configuration.
NodeProcessingHandle nodes
Node processing interface.
std::map< std::string, ProcessHook > pre_process_hooks
BufferProcessingHandle buffers
Buffer processing interface.
Unified interface combining buffer and node processing for subsystems.
void register_token_processor(Vruta::token_processing_func_t processor)
Register custom processing function for token domain.
void process_buffer_cycle()
Process all tasks scheduled for current buffer cycle.
bool is_valid() const
Check if handle is valid.
std::shared_ptr< Vruta::TaskScheduler > m_scheduler
void process(uint64_t processing_units)
Process all tasks in token domain.
void process()
Process window events and frame hooks.
std::shared_ptr< Core::WindowManager > m_window_manager
std::vector< std::shared_ptr< Core::Window > > get_processing_windows() const
Get list of windows that are open and not minimized.
ProcessingToken
Bitfield enum defining processing characteristics and backend requirements for buffer operations.
std::function< void(unsigned int num_frames)> ProcessHook
Function type for process hooks that can be registered with the engine.
HookPosition
Defines the position in the processing cycle where a hook should be executed.
@ POST_PROCESS
Execute hook after all audio processing is complete.
@ PRE_PROCESS
Execute hook before any audio processing occurs.
ProcessingToken
Enumerates the different processing domains for nodes.
Contains the node-based computational processing system components.
Definition Chronie.hpp:11
std::function< void(const std::vector< std::shared_ptr< Routine > > &, uint64_t)> token_processing_func_t
Function type for processing tasks in a specific token domain.
Main namespace for the Maya Flux audio engine.
Definition LiveAid.hpp:6
Generic input value container.
MayaFlux::Vruta::ProcessingToken Task
Processing token for task scheduling operations.
MayaFlux::Buffers::ProcessingToken Buffer
Processing token for buffer operations.
MayaFlux::Nodes::ProcessingToken Node
Processing token for node graph operations.
bool operator==(const SubsystemTokens &other) const
Equality comparison for efficient token matching.
Processing token configuration for subsystem operation.
size_t operator()(const MayaFlux::Core::SubsystemTokens &tokens) const noexcept