MayaFlux 0.1.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;
33
34/**
35 * @enum HookPosition
36 * @brief Defines the position in the processing cycle where a hook should be executed
37 *
38 * Process hooks can be registered to run either before or after the main audio processing
39 * to perform additional operations or monitoring at specific points in the signal chain.
40 */
41enum class HookPosition : uint8_t {
42 PRE_PROCESS, ///< Execute hook before any audio processing occurs
43 POST_PROCESS ///< Execute hook after all audio processing is complete
44};
45
46/**
47 * @typedef ProcessHook
48 * @brief Function type for process hooks that can be registered with the engine
49 *
50 * Process hooks are callbacks that execute at specific points in the audio processing cycle.
51 * They receive the current number of frames being processed and can be used for monitoring,
52 * debugging, or additional processing operations.
53 */
54using ProcessHook = std::function<void(unsigned int num_frames)>;
55
56/**
57 * @struct SubsystemTokens
58 * @brief Processing token configuration for subsystem operation
59 *
60 * Defines processing characteristics by specifying how buffers and nodes
61 * should be processed for each subsystem domain.
62 */
64 /** @brief Processing token for buffer operations */
66
67 /** @brief Processing token for node graph operations */
69
70 /** @brief Processing token for task scheduling operations */
72
73 /** @brief Equality comparison for efficient token matching */
74 bool operator==(const SubsystemTokens& other) const
75 {
76 return Buffer == other.Buffer && Node == other.Node && Task == other.Task;
77 }
78};
79
80/**
81 * @class BufferProcessingHandle
82 * @brief Thread-safe interface for buffer operations within a processing domain
83 *
84 * Provides scoped, thread-safe access to buffer operations with automatic token validation.
85 */
87public:
88 /** @brief Constructs handle for specific buffer manager and token */
90 std::shared_ptr<Buffers::BufferManager> manager,
92
93 // Non-copyable, moveable
98
99 /** @brief Process all channels in token domain */
100 void process(uint32_t processing_units);
101
102 /** @brief Process specific channel */
103 void process_channel(uint32_t channel, uint32_t processing_units);
104
105 /** @brief Process channel with node output data integration */
107 uint32_t channel,
108 uint32_t processing_units,
109 const std::vector<double>& node_data);
110
111 /** @brienf Process Input from backend into buffer manager */
112 void process_input(double* input_data, uint32_t num_channels, uint32_t num_frames);
113
114 /** @brief Get read-only access to channel data */
115 [[nodiscard]] std::span<const double> read_channel_data(uint32_t channel) const;
116
117 /** @brief Get write access to channel data with automatic locking */
118 std::span<double> write_channel_data(uint32_t channel);
119
120 /** @brief Configure channel layout for token domain */
121 void setup_channels(uint32_t num_channels, uint32_t buffer_size);
122
123private:
124 void ensure_valid() const;
125 void acquire_write_lock();
126
127 std::shared_ptr<Buffers::BufferManager> m_manager;
130};
131
132/**
133 * @class NodeProcessingHandle
134 * @brief Interface for node graph operations within a processing domain
135 *
136 * Provides scoped access to node operations with automatic token assignment.
137 */
139public:
140 /** @brief Constructs handle for specific node manager and token */
142 std::shared_ptr<Nodes::NodeGraphManager> manager,
144
145 /** @brief Process all nodes in token domain */
146 void process(uint32_t num_samples);
147
148 /** @brief Process nodes for specific channel and return output */
149 std::vector<double> process_channel(uint32_t channel, uint32_t num_samples);
150
151 double process_sample(uint32_t channel);
152
153 std::vector<std::vector<double>> process_audio_networks(uint32_t num_samples, uint32_t channel = 0);
154
155 /** @brief Create node with automatic token assignment */
156 template <typename NodeType, typename... Args>
157 std::shared_ptr<NodeType> create_node(Args&&... args)
158 {
159 auto node = std::make_shared<NodeType>(std::forward<Args>(args)...);
160 node->set_processing_token(m_token);
161 return node;
162 }
163
164private:
165 std::shared_ptr<Nodes::NodeGraphManager> m_manager;
167};
168
170public:
172 std::shared_ptr<MayaFlux::Vruta::TaskScheduler> task_manager,
174
175 /** @brief Register custom processing function for token domain */
177
178 /** @brief Process all tasks in token domain */
179 void process(uint64_t processing_units);
180
181 /** @brief Check if handle is valid */
182 [[nodiscard]] bool is_valid() const { return m_scheduler != nullptr; }
183
184 /** @brief Process all tasks scheduled for current buffer cycle */
186
187private:
188 std::shared_ptr<Vruta::TaskScheduler> m_scheduler;
190};
191
193public:
194 /** @brief Constructs handle for specific window manager */
195 WindowManagerHandle(std::shared_ptr<Core::WindowManager> window_manager);
196
197 /** @brief Process window events and frame hooks */
198 void process();
199
200 /** @brief Get list of windows that are open and not minimized */
201 [[nodiscard]] std::vector<std::shared_ptr<Core::Window>> get_processing_windows() const;
202
203private:
204 std::shared_ptr<Core::WindowManager> m_window_manager;
205};
206
207/**
208 * @class SubsystemProcessingHandle
209 * @brief Unified interface combining buffer and node processing for subsystems
210 *
211 * Single interface that coordinates buffer and node operations for a subsystem.
212 */
214public:
215 /** @brief Constructs unified handle with buffer and node managers */
217 std::shared_ptr<Buffers::BufferManager> buffer_manager,
218 std::shared_ptr<Nodes::NodeGraphManager> node_manager,
219 std::shared_ptr<Vruta::TaskScheduler> task_scheduler,
220 SubsystemTokens tokens);
221
223 std::shared_ptr<Buffers::BufferManager> buffer_manager,
224 std::shared_ptr<Nodes::NodeGraphManager> node_manager,
225 std::shared_ptr<Vruta::TaskScheduler> task_scheduler,
226 std::shared_ptr<Core::WindowManager> window_manager,
227 SubsystemTokens tokens);
228
229 /** @brief Buffer processing interface */
231
232 /** @brief Node processing interface */
234
236
238
239 /** @brief Get processing token configuration */
240 [[nodiscard]] inline SubsystemTokens get_tokens() const { return m_tokens; }
241
242 std::map<std::string, ProcessHook> pre_process_hooks;
243 std::map<std::string, ProcessHook> post_process_hooks;
244
245private:
247};
248
249} // namespace MayaFlux::Core
250
251namespace std {
252
253/** @brief Hash function specialization for SubsystemTokens */
254template <>
255struct hash<MayaFlux::Core::SubsystemTokens> {
256 size_t operator()(const MayaFlux::Core::SubsystemTokens& tokens) const noexcept
257 {
258 return hash<int>()(static_cast<int>(tokens.Node)) ^ hash<int>()(static_cast<int>(tokens.Buffer)) ^ hash<int>()(static_cast<int>(tokens.Task));
259 }
260};
261
262} // namespace std
static MayaFlux::Nodes::ProcessingToken token
Definition Timers.cpp:8
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 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:5
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
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