MayaFlux 1.0.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 */
91class MAYAFLUX_API BufferProcessingHandle {
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 */
111 void process_channel_with_node_data(
112 uint32_t channel,
113 uint32_t processing_units,
114 const std::vector<double>& node_data);
115
116 /**
117 * @brief Detach graphics presentation for a window in this token domain.
118 * @param window Window whose render processors should be detached
119 */
120 void destroy_window(const std::shared_ptr<Core::Window>& window);
121
122 /** @brienf Process Input from backend into buffer manager */
123 void process_input(double* input_data, uint32_t num_channels, uint32_t num_frames);
124
125 /** @brief Get read-only access to channel data */
126 [[nodiscard]] std::span<const double> read_channel_data(uint32_t channel) const;
127
128 /** @brief Get write access to channel data with automatic locking */
129 std::span<double> write_channel_data(uint32_t channel);
130
131 /** @brief Configure channel layout for token domain */
132 void setup_channels(uint32_t num_channels, uint32_t buffer_size);
133
134 /* @brief Supply buffer to a channel with optional mixing */
135 void update_routing_states();
136
137 /* @brief Route a buffer to a different channel with fade transition */
138 void cleanup_completed_routing();
139
140private:
141 void ensure_valid() const;
142 void acquire_write_lock();
143
144 std::shared_ptr<Buffers::BufferManager> m_manager;
147};
148
149/**
150 * @class NodeProcessingHandle
151 * @brief Interface for node graph operations within a processing domain
152 *
153 * Provides scoped access to node operations with automatic token assignment.
154 */
156public:
157 /** @brief Constructs handle for specific node manager and token */
159 std::shared_ptr<Nodes::NodeGraphManager> manager,
161
162 /** @brief Process all nodes in token domain */
163 void process(uint32_t num_samples);
164
165 /** @brief Process nodes for specific channel and return output */
166 std::vector<double> process_channel(uint32_t channel, uint32_t num_samples);
167
168 double process_sample(uint32_t channel);
169
171
173
174 std::vector<std::vector<double>> process_audio_networks(uint32_t num_samples, uint32_t channel = 0);
175
176 /** @brief Create node with automatic token assignment */
177 template <typename NodeType, typename... Args>
178 std::shared_ptr<NodeType> create_node(Args&&... args)
179 {
180 auto node = std::make_shared<NodeType>(std::forward<Args>(args)...);
181 node->set_processing_token(m_token);
182 return node;
183 }
184
185private:
186 std::shared_ptr<Nodes::NodeGraphManager> m_manager;
188};
189
191public:
193 std::shared_ptr<MayaFlux::Vruta::TaskScheduler> task_manager,
195
196 /** @brief Register custom processing function for token domain */
198
199 /** @brief Register an externally-owned clock for a token domain. */
200 void register_clock(Vruta::ProcessingToken token, std::shared_ptr<Vruta::IClock> clock);
201
202 /** @brief Process all tasks in token domain */
203 void process(uint64_t processing_units);
204
205 /** @brief Check if handle is valid */
206 [[nodiscard]] bool is_valid() const { return m_scheduler != nullptr; }
207
208 /** @brief Process all tasks scheduled for current buffer cycle */
210
211private:
212 std::shared_ptr<Vruta::TaskScheduler> m_scheduler;
214};
215
217public:
218 /** @brief Constructs handle for specific window manager */
219 WindowManagerHandle(std::shared_ptr<Core::WindowManager> window_manager);
220
221 /** @brief Process window events and frame hooks */
222 void process();
223
224 /** @brief Get list of windows that are open and not minimized */
225 [[nodiscard]] std::vector<std::shared_ptr<Core::Window>> get_processing_windows() const;
226
227private:
228 std::shared_ptr<Core::WindowManager> m_window_manager;
229};
230
232public:
233 /** @brief Constructs handle for specific InputManager */
234 InputManagerHandle(std::shared_ptr<InputManager> input_manager);
235
236 /** @brief start InputManager */
237 void start();
238
239 /** @brief stop InputManager */
240 void stop();
241
242 /** @brief unregister all nodes from InputManager */
243 void unregister();
244
245 /** @brief enqueue input value to InputManager */
246 void enqueue_input(const InputValue& value);
247
248 /** @brief enqueue batch of input values to InputManager */
249 void setup_osc_bridge(const OSCConfigInfo& config);
250
251private:
252 std::shared_ptr<InputManager> m_input_manager;
253};
254
255/**
256 * @class SubsystemProcessingHandle
257 * @brief Unified interface combining buffer and node processing for subsystems
258 *
259 * Single interface that coordinates buffer and node operations for a subsystem.
260 */
261class MAYAFLUX_API SubsystemProcessingHandle {
262public:
264 std::shared_ptr<Buffers::BufferManager> buffer_manager,
265 std::shared_ptr<Nodes::NodeGraphManager> node_manager,
266 std::shared_ptr<Vruta::TaskScheduler> task_scheduler,
267 std::shared_ptr<WindowManager> window_manager,
268 std::shared_ptr<InputManager> input_manager,
269 SubsystemTokens tokens);
270
271 /** @brief Buffer processing interface */
273
274 /** @brief Node processing interface */
276
278
280
282
283 /** @brief Get processing token configuration */
284 [[nodiscard]] inline SubsystemTokens get_tokens() const { return m_tokens; }
285
286 std::map<std::string, ProcessHook> pre_process_hooks;
287 std::map<std::string, ProcessHook> post_process_hooks;
288
289private:
291};
292
293} // namespace MayaFlux::Core
294
295namespace std {
296
297/** @brief Hash function specialization for SubsystemTokens */
298template <>
299struct hash<MayaFlux::Core::SubsystemTokens> {
300 size_t operator()(const MayaFlux::Core::SubsystemTokens& tokens) const noexcept
301 {
302 return hash<int>()(static_cast<int>(tokens.Node)) ^ hash<int>()(static_cast<int>(tokens.Buffer)) ^ hash<int>()(static_cast<int>(tokens.Task));
303 }
304};
305
306} // namespace std
std::weak_ptr< Core::Window > window
Definition Picker.cpp:23
glm::vec3 value
BufferProcessingHandle & operator=(const BufferProcessingHandle &)=delete
BufferProcessingHandle(BufferProcessingHandle &&)=default
std::shared_ptr< Buffers::BufferManager > m_manager
BufferProcessingHandle & operator=(BufferProcessingHandle &&)=default
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