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