MayaFlux 0.4.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;
18class IClock;
19
20using token_processing_func_t = std::function<void(const std::vector<std::shared_ptr<Routine>>&, uint64_t)>;
21}
22
23/**
24 * @file ProcessingArchitecture.hpp
25 * @brief Unified processing architecture for multimodal subsystem coordination
26 *
27 * Token-based system where each processing domain (audio, video, custom) can have
28 * its own processing characteristics while maintaining unified interfaces.
29 */
30namespace MayaFlux::Core {
31
32class Window;
33class WindowManager;
34class InputManager;
35
36struct InputValue;
37struct OSCConfigInfo;
38
39/**
40 * @enum HookPosition
41 * @brief Defines the position in the processing cycle where a hook should be executed
42 *
43 * Process hooks can be registered to run either before or after the main audio processing
44 * to perform additional operations or monitoring at specific points in the signal chain.
45 */
46enum class HookPosition : uint8_t {
47 PRE_PROCESS, ///< Execute hook before any audio processing occurs
48 POST_PROCESS ///< Execute hook after all audio processing is complete
49};
50
51/**
52 * @typedef ProcessHook
53 * @brief Function type for process hooks that can be registered with the engine
54 *
55 * Process hooks are callbacks that execute at specific points in the audio processing cycle.
56 * They receive the current number of frames being processed and can be used for monitoring,
57 * debugging, or additional processing operations.
58 */
59using ProcessHook = std::function<void(unsigned int num_frames)>;
60
61/**
62 * @struct SubsystemTokens
63 * @brief Processing token configuration for subsystem operation
64 *
65 * Defines processing characteristics by specifying how buffers and nodes
66 * should be processed for each subsystem domain.
67 */
69 /** @brief Processing token for buffer operations */
71
72 /** @brief Processing token for node graph operations */
74
75 /** @brief Processing token for task scheduling operations */
77
78 /** @brief Equality comparison for efficient token matching */
79 bool operator==(const SubsystemTokens& other) const
80 {
81 return Buffer == other.Buffer && Node == other.Node && Task == other.Task;
82 }
83};
84
85/**
86 * @class BufferProcessingHandle
87 * @brief Thread-safe interface for buffer operations within a processing domain
88 *
89 * Provides scoped, thread-safe access to buffer operations with automatic token validation.
90 */
92public:
93 /** @brief Constructs handle for specific buffer manager and token */
95 std::shared_ptr<Buffers::BufferManager> manager,
97
98 // Non-copyable, moveable
103
104 /** @brief Process all channels in token domain */
105 void process(uint32_t processing_units);
106
107 /** @brief Process specific channel */
108 void process_channel(uint32_t channel, uint32_t processing_units);
109
110 /** @brief Process channel with node output data integration */
112 uint32_t channel,
113 uint32_t processing_units,
114 const std::vector<double>& node_data);
115
116 /** @brienf Process Input from backend into buffer manager */
117 void process_input(double* input_data, uint32_t num_channels, uint32_t num_frames);
118
119 /** @brief Get read-only access to channel data */
120 [[nodiscard]] std::span<const double> read_channel_data(uint32_t channel) const;
121
122 /** @brief Get write access to channel data with automatic locking */
123 std::span<double> write_channel_data(uint32_t channel);
124
125 /** @brief Configure channel layout for token domain */
126 void setup_channels(uint32_t num_channels, uint32_t buffer_size);
127
128 /* @brief Supply buffer to a channel with optional mixing */
130
131 /* @brief Route a buffer to a different channel with fade transition */
133
134private:
135 void ensure_valid() const;
136 void acquire_write_lock();
137
138 std::shared_ptr<Buffers::BufferManager> m_manager;
141};
142
143/**
144 * @class NodeProcessingHandle
145 * @brief Interface for node graph operations within a processing domain
146 *
147 * Provides scoped access to node operations with automatic token assignment.
148 */
150public:
151 /** @brief Constructs handle for specific node manager and token */
153 std::shared_ptr<Nodes::NodeGraphManager> manager,
155
156 /** @brief Process all nodes in token domain */
157 void process(uint32_t num_samples);
158
159 /** @brief Process nodes for specific channel and return output */
160 std::vector<double> process_channel(uint32_t channel, uint32_t num_samples);
161
162 double process_sample(uint32_t channel);
163
165
167
168 std::vector<std::vector<double>> process_audio_networks(uint32_t num_samples, uint32_t channel = 0);
169
170 /** @brief Create node with automatic token assignment */
171 template <typename NodeType, typename... Args>
172 std::shared_ptr<NodeType> create_node(Args&&... args)
173 {
174 auto node = std::make_shared<NodeType>(std::forward<Args>(args)...);
175 node->set_processing_token(m_token);
176 return node;
177 }
178
179private:
180 std::shared_ptr<Nodes::NodeGraphManager> m_manager;
182};
183
185public:
187 std::shared_ptr<MayaFlux::Vruta::TaskScheduler> task_manager,
189
190 /** @brief Register custom processing function for token domain */
192
193 /** @brief Register an externally-owned clock for a token domain. */
194 void register_clock(Vruta::ProcessingToken token, std::shared_ptr<Vruta::IClock> clock);
195
196 /** @brief Process all tasks in token domain */
197 void process(uint64_t processing_units);
198
199 /** @brief Check if handle is valid */
200 [[nodiscard]] bool is_valid() const { return m_scheduler != nullptr; }
201
202 /** @brief Process all tasks scheduled for current buffer cycle */
204
205private:
206 std::shared_ptr<Vruta::TaskScheduler> m_scheduler;
208};
209
211public:
212 /** @brief Constructs handle for specific window manager */
213 WindowManagerHandle(std::shared_ptr<Core::WindowManager> window_manager);
214
215 /** @brief Process window events and frame hooks */
216 void process();
217
218 /** @brief Get list of windows that are open and not minimized */
219 [[nodiscard]] std::vector<std::shared_ptr<Core::Window>> get_processing_windows() const;
220
221private:
222 std::shared_ptr<Core::WindowManager> m_window_manager;
223};
224
226public:
227 /** @brief Constructs handle for specific InputManager */
228 InputManagerHandle(std::shared_ptr<InputManager> input_manager);
229
230 /** @brief start InputManager */
231 void start();
232
233 /** @brief stop InputManager */
234 void stop();
235
236 /** @brief unregister all nodes from InputManager */
237 void unregister();
238
239 /** @brief enqueue input value to InputManager */
240 void enqueue_input(const InputValue& value);
241
242 /** @brief enqueue batch of input values to InputManager */
243 void setup_osc_bridge(const OSCConfigInfo& config);
244
245private:
246 std::shared_ptr<InputManager> m_input_manager;
247};
248
249/**
250 * @class SubsystemProcessingHandle
251 * @brief Unified interface combining buffer and node processing for subsystems
252 *
253 * Single interface that coordinates buffer and node operations for a subsystem.
254 */
256public:
258 std::shared_ptr<Buffers::BufferManager> buffer_manager,
259 std::shared_ptr<Nodes::NodeGraphManager> node_manager,
260 std::shared_ptr<Vruta::TaskScheduler> task_scheduler,
261 std::shared_ptr<WindowManager> window_manager,
262 std::shared_ptr<InputManager> input_manager,
263 SubsystemTokens tokens);
264
265 /** @brief Buffer processing interface */
267
268 /** @brief Node processing interface */
270
272
274
276
277 /** @brief Get processing token configuration */
278 [[nodiscard]] inline SubsystemTokens get_tokens() const { return m_tokens; }
279
280 std::map<std::string, ProcessHook> pre_process_hooks;
281 std::map<std::string, ProcessHook> post_process_hooks;
282
283private:
285};
286
287} // namespace MayaFlux::Core
288
289namespace std {
290
291/** @brief Hash function specialization for SubsystemTokens */
292template <>
293struct hash<MayaFlux::Core::SubsystemTokens> {
294 size_t operator()(const MayaFlux::Core::SubsystemTokens& tokens) const noexcept
295 {
296 return hash<int>()(static_cast<int>(tokens.Node)) ^ hash<int>()(static_cast<int>(tokens.Buffer)) ^ hash<int>()(static_cast<int>(tokens.Task));
297 }
298};
299
300} // 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
void setup_osc_bridge(const OSCConfigInfo &config)
enqueue batch of input values 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.
void register_clock(Vruta::ProcessingToken token, std::shared_ptr< Vruta::IClock > clock)
Register an externally-owned clock for a token domain.
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:14
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 Runtime.cpp:12
Generic input value container.
OSC backend configuration.
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