MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Graph.hpp
Go to the documentation of this file.
1#pragma once
2
5
6namespace MayaFlux {
7
8namespace Nodes {
9 class Node;
10 class NodeGraphManager;
11 class RootNode;
12 namespace Network {
13 class NodeNetwork;
14 }
15}
16
17namespace Buffers {
18 class Buffer;
19 class AudioBuffer;
20 class VKBuffer;
21 class RootAudioBuffer;
22 class BufferManager;
23 class BufferProcessor;
24 class BufferProcessingChain;
25}
26
27namespace internal {
28 std::shared_ptr<Buffers::BufferProcessor> attach_quick_process_audio(Buffers::AudioProcessingFunction processor, const std::shared_ptr<Buffers::AudioBuffer>& buffer);
29 std::shared_ptr<Buffers::BufferProcessor> attach_quick_process_graphics(Buffers::GraphicsProcessingFunction processor, const std::shared_ptr<Buffers::VKBuffer>& buffer);
30}
31
32//-------------------------------------------------------------------------
33// Node Graph Management
34//-------------------------------------------------------------------------
35
36/**
37 * @brief Gets the node graph manager from the default engine
38 * @return Shared pointer to the centrally managed NodeGraphManager
39 *
40 * Returns the node graph manager that's managed by the default engine instance.
41 * All node operations using the convenience functions will use this manager.
42 */
43MAYAFLUX_API std::shared_ptr<Nodes::NodeGraphManager> get_node_graph_manager();
44
45/**
46 * @brief Adds a node to the root node of a specific channel
47 * @param node Node to add
48 * @param channel Channel index
49 *
50 * Adds the node as a child of the root node for the specified channel.
51 * Uses the default engine's node graph manager.
52 */
53MAYAFLUX_API void register_audio_node(const std::shared_ptr<Nodes::Node>& node, uint32_t channel = 0);
54
55/**
56 * @brief Adds a node to the root node of specified channels
57 * @param node Node to add
58 * @param channels Vector of channel indices
59 *
60 * Adds the node as a child of the root node for the specified channels.
61 * Uses the default engine's node graph manager.
62 */
63MAYAFLUX_API void register_audio_node(const std::shared_ptr<Nodes::Node>& node, const std::vector<uint32_t>& channels);
64
65MAYAFLUX_API void register_node(
66 const std::shared_ptr<Nodes::Node>& node,
67 const Nodes::ProcessingToken& token,
68 uint32_t channel = 0);
69
70/**
71 * @breif Moves the node from its current channel(s) to the specified channel(s) with an optional fade time
72 * @param node Node to route
73 * @param channels Vector of channel indices to route the node to
74 * @param seconds_to_fade Time in seconds to fade the routing (optional, default is 1 second)
75 * @param token Processing domain to route within (default is AUDIO_RATE)
76 *
77 * This method adds the specified node to the root nodes of the target channels
78 * within the given processing domain. If seconds_to_fade is greater than 0, the routing
79 * will be smoothly faded in over that time period.
80 */
81MAYAFLUX_API void route_node(
82 const std::shared_ptr<Nodes::Node>& node,
83 const std::vector<uint32_t>& channels,
84 double seconds_to_fade = 1.F,
86
87/**
88 * @breif Moves the node from its current channel(s) to the specified channel(s) with an optional fade time
89 * @param node Node to route
90 * @param channels Vector of channel indices to route the node to
91 * @param num_samples Number of samples to fade the routing over (optional, default is 48000 samples for 1 second at 48kHz)
92 * @param token Processing domain to route within (default is AUDIO_RATE)
93 *
94 * This method adds the specified node to the root nodes of the target channels
95 * within the given processing domain. If num_samples is greater than 0, the routing
96 * will be smoothly faded in over that many samples.
97 */
98MAYAFLUX_API void route_node(
99 const std::shared_ptr<Nodes::Node>& node,
100 const std::vector<uint32_t>& channels,
101 uint32_t num_samples,
103
104/**
105 * @brief Removes a node from the root node of a specific channel
106 * @param node Node to remove
107 * @param channel Channel index
108 *
109 * Removes the node from being a child of the root node for the specified channel.
110 * Uses the default engine's node graph manager.
111 */
112MAYAFLUX_API void unregister_audio_node(const std::shared_ptr<Nodes::Node>& node, uint32_t channel = 0);
113
114/**
115 * @brief Removes a node from the root node of specified channels
116 * @param node Node to remove
117 * @param channels Vector of channel indices
118 *
119 * Removes the node from being a child of the root node for the specified channels.
120 * Uses the default engine's node graph manager.
121 */
122MAYAFLUX_API void unregister_node(
123 const std::shared_ptr<Nodes::Node>& node,
124 const Nodes::ProcessingToken& token,
125 uint32_t channel = 0);
126
127/**
128 * @brief Removes a node from the root node from list of channels
129 * @param node Node to remove
130 * @param channels Channel indices
131 *
132 * Removes the node from being a child of the root node for the list of channels
133 * Uses the default engine's node graph manager.
134 */
135MAYAFLUX_API void unregister_audio_node(const std::shared_ptr<Nodes::Node>& node, const std::vector<uint32_t>& channels);
136
137/**
138 * @brief Gets the root node for a specific channel
139 * @param channel Channel index
140 * @return The root node for the specified channel
141 *
142 * The root node is the top-level node in the processing hierarchy for a channel.
143 * Uses the default engine's node graph manager.
144 */
145MAYAFLUX_API Nodes::RootNode& get_audio_channel_root(uint32_t channel = 0);
146
147template <typename NodeType, typename... Args>
148 requires std::derived_from<NodeType, Nodes::Node>
149auto create_node(Args&&... args) -> std::shared_ptr<NodeType>
150{
151 auto node = std::make_shared<NodeType>(std::forward<Args>(args)...);
153 return node;
154}
155
156//-------------------------------------------------------------------------
157// Node Network Management
158//-------------------------------------------------------------------------
159
160/**
161 * @brief Registers a node network with the default engine's node graph manager
162 * @param network NodeNetwork to register
163 *
164 * Adds the node network to the default engine's node graph manager.
165 * The network can then be used to manage nodes and their connections.
166 */
167MAYAFLUX_API void register_node_network(const std::shared_ptr<Nodes::Network::NodeNetwork>& network, const Nodes::ProcessingToken& token = Nodes::ProcessingToken::AUDIO_RATE);
168
169/**
170 * @brief Unregisters a node network from the default engine's node graph manager
171 * @param network NodeNetwork to unregister
172 *
173 * Removes the node network from the default engine's node graph manager.
174 * The network will no longer be available for managing nodes and their connections.
175 */
176MAYAFLUX_API void unregister_node_network(const std::shared_ptr<Nodes::Network::NodeNetwork>& network, const Nodes::ProcessingToken& token = Nodes::ProcessingToken::AUDIO_RATE);
177
178/**
179 * @breif Moves the network from its current channel(s) to the specified channel(s) with an optional fade time
180 * @param network NodeNetwork to route
181 * @param channels Vector of channel indices to route the network to
182 * @param seconds_to_fade Time in seconds to fade the routing (optional, default is 1 second)
183 * @param token Processing domain to route within (default is AUDIO_RATE)
184 *
185 * This method adds the specified network to the target channels
186 * within the given processing domain. If seconds_to_fade is greater than 0, the routing
187 * will be smoothly faded in over that time period.
188 */
189MAYAFLUX_API void route_network(
190 const std::shared_ptr<Nodes::Network::NodeNetwork>& network,
191 const std::vector<uint32_t>& channels,
192 double seconds_to_fade = 1.F,
194
195/**
196 * @breif Moves the node from its current channel(s) to the specified channel(s) with an optional fade time
197 * @param network NodeNetwork to route
198 * @param channels Vector of channel indices to route the node to
199 * @param num_samples Number of samples to fade the routing over (optional, default is 48000 samples for 1 second at 48kHz)
200 * @param token Processing domain to route within (default is AUDIO_RATE)
201 *
202 * This method adds the specified network to the target channels
203 * within the given processing domain. If num_samples is greater than 0, the routing
204 * will be smoothly faded in over that many samples.
205 */
206MAYAFLUX_API void route_network(
207 const std::shared_ptr<Nodes::Network::NodeNetwork>& network,
208 const std::vector<uint32_t>& channels,
209 uint32_t num_samples,
211
212/**
213 * @brief Creates a new node network
214 * @return Shared pointer to the created NodeNetwork
215 *
216 * This function creates a new node network that can be used to manage
217 * complex node graphs with multiple channels and processing domains.
218 */
219
220template <typename NodeNetworkType, typename... Args>
221 requires std::derived_from<NodeNetworkType, Nodes::Network::NodeNetwork>
222auto create_node_network(Args&&... args) -> std::shared_ptr<NodeNetworkType>
223{
224 auto network = std::make_shared<NodeNetworkType>(std::forward<Args>(args)...);
225 register_node_network(network);
226 return network;
227}
228
229//-------------------------------------------------------------------------
230// Buffer Management
231//-------------------------------------------------------------------------
232
233/**
234 * @brief Gets the buffer manager from the default engine
235 * @return Shared pointer to the centrally managed BufferManager
236 *
237 * Returns the buffer manager that's managed by the default engine instance.
238 * All buffer operations using the convenience functions will use this manager.
239 */
240MAYAFLUX_API std::shared_ptr<Buffers::BufferManager> get_buffer_manager();
241
242/**
243 * @brief Adds a processor to a specific buffer
244 * @param processor Processor to add
245 * @param buffer Buffer to add the processor to
246 *
247 * Adds the processor to the specified buffer's processing chain.
248 * Uses the default engine's buffer manager.
249 */
250MAYAFLUX_API void add_processor(const std::shared_ptr<Buffers::BufferProcessor>& processor, const std::shared_ptr<Buffers::Buffer>& buffer, Buffers::ProcessingToken token = Buffers::ProcessingToken::AUDIO_BACKEND);
251
252/**
253 * @brief Adds a processor to all buffers in a specific channel
254 * @param processor Processor to add
255 * @param token Processing domain
256 * @param channel Channel index
257 *
258 * Adds the processor to all buffers associated with the specified channel
259 * in the given processing domain.
260 * Uses the default engine's buffer manager.
261 */
262MAYAFLUX_API void add_processor(const std::shared_ptr<Buffers::BufferProcessor>& processor, Buffers::ProcessingToken token, uint32_t channel);
263
264/**
265 * @brief Adds a processor to all buffers in a processing domain
266 * @param processor Processor to add
267 * @param token Processing domain
268 *
269 * Adds the processor to all buffers associated with the given processing domain.
270 * Uses the default engine's buffer manager.
271 */
272MAYAFLUX_API void add_processor(const std::shared_ptr<Buffers::BufferProcessor>& processor, Buffers::ProcessingToken token = Buffers::ProcessingToken::AUDIO_BACKEND);
273
274/**
275 * @brief Removes a processor from a specific buffer
276 * @param processor Processor to remove
277 * @param buffer Buffer to remove the processor from
278 *
279 * Removes the processor from the specified buffer's processing chain.
280 * Uses the default engine's buffer manager.
281 */
282void remove_processor(const std::shared_ptr<Buffers::BufferProcessor>& processor, const std::shared_ptr<Buffers::Buffer>& buffer);
283
284/**
285 * @brief Removes a processor from all buffers in a specific channel
286 * @param processor Processor to remove
287 * @param token Processing domain
288 * @param channel Channel index
289 *
290 * Removes the processor from all buffers associated with the specified channel
291 * in the given processing domain.
292 * Uses the default engine's buffer manager.
293 */
294void remove_processor(const std::shared_ptr<Buffers::BufferProcessor>& processor, uint32_t channel, Buffers::ProcessingToken token = Buffers::ProcessingToken::AUDIO_BACKEND);
295
296/**
297 * @brief Removes a processor from all buffers in a processing domain
298 * @param processor Processor to remove
299 * @param token Processing domain
300 *
301 * Removes the processor from all buffers associated with the given processing domain.
302 * Uses the default engine's buffer manager.
303 */
304void remove_processor(const std::shared_ptr<Buffers::BufferProcessor>& processor, Buffers::ProcessingToken token = Buffers::ProcessingToken::AUDIO_BACKEND);
305
306/**
307 * @brief Registers an AudioBuffer with the default engine's buffer manager
308 * @param buffer AudioBuffer to register
309 * @param channel Channel index to associate with the buffer (default: 0)
310 *
311 * Adds the buffer to the default engine's buffer management system, enabling
312 * it to participate in the audio processing pipeline. The buffer will be
313 * processed during each audio cycle according to its configuration.
314 * Multiple buffers can be registered to the same channel for layered processing.
315 */
316MAYAFLUX_API void register_audio_buffer(const std::shared_ptr<Buffers::AudioBuffer>& buffer, uint32_t channel = 0);
317
318/**
319 * @brief Unregisters an AudioBuffer from the default engine's buffer manager
320 * @param buffer AudioBuffer to unregister
321 * @param channel Channel index the buffer was associated with (default: 0)
322 *
323 * Removes the buffer from the default engine's buffer management system.
324 * The buffer will no longer participate in audio processing cycles.
325 * This is essential for clean shutdown and preventing processing of
326 * destroyed or invalid buffers.
327 */
328MAYAFLUX_API void unregister_audio_buffer(const std::shared_ptr<Buffers::AudioBuffer>& buffer, uint32_t channel = 0);
329
330/**
331 * @brief creates a new buffer of the specified type and registers it
332 * @tparam BufferType Type of buffer to create (must be derived from AudioBuffer)
333 * @tparam Args Constructor argument types
334 * @param channel Channel index to create the buffer for
335 * @param buffer_size Size of the buffer in processing units
336 */
337template <typename BufferType, typename... Args>
338 requires std::derived_from<BufferType, Buffers::AudioBuffer>
339auto create_buffer(uint32_t channel, uint32_t buffer_size, Args&&... args) -> std::shared_ptr<BufferType>
340{
341 auto buffer = std::make_shared<BufferType>(channel, buffer_size, std::forward<Args>(args)...);
343 return buffer;
344}
345
346/**
347 * @brief Registers a VKBuffer with the default engine's buffer manager
348 * @param buffer VKBuffer to register
349 *
350 * Adds the buffer to the default engine's buffer management system, enabling
351 * it to participate in the graphics processing pipeline.
352 */
353MAYAFLUX_API void register_graphics_buffer(const std::shared_ptr<Buffers::VKBuffer>& buffer, Buffers::ProcessingToken token = Buffers::ProcessingToken::GRAPHICS_BACKEND);
354
355/**
356 * @brief Unregisters a VKBuffer from the default engine's buffer manager
357 * @param buffer VKBuffer to unregister
358 *
359 * Removes the buffer from the default engine's buffer management system.
360 * The buffer will no longer participate in graphics processing cycles.
361 */
362MAYAFLUX_API void unregister_graphics_buffer(const std::shared_ptr<Buffers::VKBuffer>& buffer);
363
364/**
365 * @brief creates a new graphics buffer of the specified type and registers it
366 * @tparam BufferType Type of buffer to create (must be derived from VKBuffer)
367 * @tparam Args Constructor argument types
368 * @param args Constructor arguments for the buffer
369 * @return Shared pointer to the created buffer
370 */
371template <typename BufferType, typename... Args>
372 requires std::derived_from<BufferType, Buffers::VKBuffer>
373auto create_buffer(Args&&... args) -> std::shared_ptr<BufferType>
374{
375 auto buffer = std::make_shared<BufferType>(std::forward<Args>(args)...);
377 return buffer;
378}
379
380/**
381 * @brief Creates a new processor and adds it to a buffer
382 * @tparam ProcessorType Type of processor to create (must be derived from BufferProcessor)
383 * @tparam Args Constructor argument types
384 * @param buffer Buffer to add the processor to
385 * @param args Constructor arguments for the processor
386 * @return Shared pointer to the created processor
387 *
388 * This function creates a new processor of the specified type, initializes it with the provided arguments,
389 * and adds it to the specified buffer's processing chain.
390 */
391template <typename ProcessorType, typename... Args>
392 requires std::derived_from<ProcessorType, Buffers::BufferProcessor>
393auto create_processor(const std::shared_ptr<Buffers::AudioBuffer> buffer, Args&&... args) -> std::shared_ptr<ProcessorType>
394{
395 auto processor = std::make_shared<ProcessorType>(std::forward<Args>(args)...);
396 add_processor(processor, buffer);
397 return processor;
398}
399
400template <typename ProcessorType, typename... Args>
401 requires std::derived_from<ProcessorType, Buffers::BufferProcessor>
402auto create_processor(const std::shared_ptr<Buffers::VKBuffer> buffer, Args&&... args) -> std::shared_ptr<ProcessorType>
403{
404 auto processor = std::make_shared<ProcessorType>(std::forward<Args>(args)...);
406 return processor;
407}
408
409/**
410 * @brief Creates a new processing chain for the default engine
411 * @return Shared pointer to the created BufferProcessingChain
412 *
413 * This function creates a new processing chain that can be used to manage
414 * audio processing for buffers. The chain can be customized with various
415 * processors and is managed by the default engine's buffer manager.
416 */
417MAYAFLUX_API std::shared_ptr<Buffers::BufferProcessingChain> create_processing_chain();
418
419/**
420 * @brief Gets the audio buffer for a specific channel
421 * @param channel Channel index
422 * @return Reference to the channel's AudioBuffer
423 *
424 * Returns the buffer from the default engine's buffer manager.
425 */
426MAYAFLUX_API Buffers::RootAudioBuffer& get_root_audio_buffer(uint32_t channel);
427
428/**
429 * @brief Connects a node to a specific output channel
430 * @param node Node to connect
431 * @param channel_index Channel index to connect to
432 * @param mix Mix level (0.0 to 1.0) for blending node output with existing channel content
433 * @param clear_before Whether to clear the channel buffer before adding node output
434 *
435 * Uses the default engine's buffer manager and node graph manager.
436 */
437MAYAFLUX_API void connect_node_to_channel(const std::shared_ptr<Nodes::Node>& node, uint32_t channel_index = 0, float mix = 0.5F, bool clear_before = false);
438
439/**
440 * @brief Connects a node to a specific buffer
441 * @param node Node to connect
442 * @param buffer Buffer to connect to
443 * @param mix Mix level (0.0 to 1.0) for blending node output with existing buffer content
444 * @param clear_before Whether to clear the buffer before adding node output
445 *
446 * Uses the default engine's node graph manager.
447 */
448MAYAFLUX_API void connect_node_to_buffer(const std::shared_ptr<Nodes::Node>& node, const std::shared_ptr<Buffers::AudioBuffer>& buffer, float mix = 0.5F, bool clear_before = true);
449
450//-------------------------------------------------------------------------
451// Audio Processing
452//-------------------------------------------------------------------------
453
454/**
455 * @brief Attaches a processing function to a specific channel
456 * @param processor Function to process the buffer
457 * @param channel_id Channel index to process
458 *
459 * The processor will be called during the default engine's audio processing cycle
460 * and will operate on the specified output channel buffer.
461 */
462MAYAFLUX_API std::shared_ptr<Buffers::BufferProcessor> attach_quick_process(Buffers::AudioProcessingFunction processor, unsigned int channel_id = 0);
463
464// Template overloads for auto lambdas
465template <typename F>
466std::shared_ptr<Buffers::BufferProcessor> attach_quick_process(
467 F&& processor,
468 const std::shared_ptr<Buffers::AudioBuffer>& buffer)
469{
471 Buffers::AudioProcessingFunction { std::forward<F>(processor) },
472 buffer);
473}
474
475template <typename F>
476std::shared_ptr<Buffers::BufferProcessor> attach_quick_process(
477 F&& processor,
478 const std::shared_ptr<Buffers::VKBuffer>& buffer)
479{
481 Buffers::GraphicsProcessingFunction { std::forward<F>(processor) },
482 buffer);
483}
484
485/**
486 * @brief Reads audio data from the default input source into a buffer
487 * @param buffer Buffer to read audio data into
488 * @param channel Channel index to read from (default: 0)
489 *
490 * Reads audio data from the default input source (e.g., microphone)
491 * and fills the provided AudioBuffer with the captured audio samples.
492 * This function is typically used to capture live audio input for processing.
493 */
494MAYAFLUX_API void read_from_audio_input(const std::shared_ptr<Buffers::AudioBuffer>& buffer, uint32_t channel = 0);
495
496/**
497 * @brief Stops reading audio data from the default input source
498 * @param buffer Buffer to stop reading audio data from
499 * @param channel Channel index to stop reading from (default: 0)
500 */
501MAYAFLUX_API void detach_from_audio_input(const std::shared_ptr<Buffers::AudioBuffer>& buffer, uint32_t channel = 0);
502
503/**
504 * @brief Creates a new AudioBuffer for input listening
505 * @param channel Channel index to create the buffer for (default: 0)
506 * @param add_to_output Whether to add this buffer to the output channel (default: false)
507 * @return Shared pointer to the created AudioBuffer
508 *
509 * This function creates a new AudioBuffer that can be used to listen to audio input.
510 * If `add_to_output` is true, the buffer will be automatically added to the output channel
511 * for processing.
512 */
513MAYAFLUX_API std::shared_ptr<Buffers::AudioBuffer> create_input_listener_buffer(uint32_t channel = 0, bool add_to_output = false);
514
515/**
516 * @brief Clones a buffer to multiple channels
517 * @param buffer Buffer to clone
518 * @param channels Vector of channel indices to clone to
519 *
520 * Creates independent copies of the buffer for each specified channel.
521 * Each clone maintains the same data, processors, and processing chain,
522 * but operates independently on its assigned channel.
523 * Uses the default engine's buffer manager.
524 */
525MAYAFLUX_API std::vector<std::shared_ptr<Buffers::AudioBuffer>> clone_buffer_to_channels(const std::shared_ptr<Buffers::AudioBuffer>& buffer,
526 const std::vector<uint32_t>& channels);
527
528MAYAFLUX_API std::vector<std::shared_ptr<Buffers::AudioBuffer>> clone_buffer_to_channels(
529 const std::shared_ptr<Buffers::AudioBuffer>& buffer,
530 const std::vector<uint32_t>& channels,
531 const Buffers::ProcessingToken& token);
532/**
533 * @brief Supplies a buffer to a single channel with mixing
534 * @param buffer Source buffer to supply
535 * @param channel Target channel index
536 * @param mix Mix level (default: 1.0)
537 *
538 * Convenience wrapper for single-channel buffer supply operations.
539 */
540MAYAFLUX_API void supply_buffer_to_channel(const std::shared_ptr<Buffers::AudioBuffer>& buffer,
541 uint32_t channel,
542 double mix = 1.0);
543
544/**
545 * @brief Supplies a buffer to multiple channels with mixing
546 * @param buffer Source buffer to supply
547 * @param channels Vector of channel indices to supply to
548 * @param mix Mix level for each channel (default: 1.0)
549 *
550 * Efficiently routes a single buffer's output to multiple channels using
551 * the MixProcessor system. This is ideal for sending the same signal to
552 * multiple outputs without duplicating processing.
553 */
554MAYAFLUX_API void supply_buffer_to_channels(const std::shared_ptr<Buffers::AudioBuffer>& buffer,
555 const std::vector<uint32_t>& channels,
556 double mix = 1.0);
557
558/**
559 * @brief Removes a supplied buffer from multiple channels
560 * @param buffer Buffer to remove from supply chains
561 * @param channels channel index to remove from
562 *
563 * Efficiently removes a buffer from channel mix processor.
564 */
565MAYAFLUX_API void remove_supplied_buffer_from_channel(const std::shared_ptr<Buffers::AudioBuffer>& buffer,
566 const uint32_t channel);
567
568/**
569 * @brief Removes a supplied buffer from multiple channels
570 * @param buffer Buffer to remove from supply chains
571 * @param channels Vector of channel indices to remove from
572 *
573 * Efficiently removes a buffer from multiple channel mix processors.
574 */
575MAYAFLUX_API void remove_supplied_buffer_from_channels(const std::shared_ptr<Buffers::AudioBuffer>& buffer,
576 const std::vector<uint32_t>& channels);
577
578/**
579 * @brief Routes a buffer from its current channel to a target channel with fade
580 * @param buffer Buffer to route
581 * @param target_channel Destination channel
582 * @param seconds_to_fade Crossfade duration in seconds
583 * @param token Processing domain
584 */
585MAYAFLUX_API void route_buffer(
586 const std::shared_ptr<Buffers::AudioBuffer>& buffer,
587 uint32_t target_channel,
588 double seconds_to_fade = 1.0,
590
591/**
592 * @brief Routes a buffer from its current channel to a target channel with fade
593 * @param buffer Buffer to route
594 * @param target_channel Destination channel
595 * @param num_blocks Crossfade duration in processing blocks
596 * @param token Processing domain
597 *
598 * NOTE: num_blocks is in processing blocks, not samples. The actual time duration will depend on the block size and sample rate.
599 */
600MAYAFLUX_API void route_buffer(
601 const std::shared_ptr<Buffers::AudioBuffer>& buffer,
602 uint32_t target_channel,
603 uint32_t num_blocks,
605
606/**
607 * @brief Connects two nodes in series (pipeline operator)
608 * @param lhs Source node (may already be a ChainNode)
609 * @param rhs Target node (may already be a ChainNode)
610 * @return A ChainNode containing the flattened sequence
611 *
612 * If lhs is already a ChainNode, rhs is appended to its sequence
613 * rather than creating a nested chain.
614 *
615 * Uses the default engine's NodeGraphManager for registration.
616 * For manual construction without registration, create ChainNode directly
617 * with no manager argument.
618 *
619 * ```cpp
620 * auto chain = generator >> transformer >> output;
621 * ```
622 */
623MAYAFLUX_API std::shared_ptr<Nodes::Node> operator>>(const std::shared_ptr<Nodes::Node>& lhs, const std::shared_ptr<Nodes::Node>& rhs);
624
625/**
626 * @brief Combines two nodes in parallel (addition)
627 * @param lhs First node
628 * @param rhs Second node
629 * @return A BinaryOpNode that sums both outputs
630 *
631 * Creates a new node that processes both input nodes and sums their outputs.
632 * This allows for mixing multiple data sources or transformations:
633 *
634 * ```cpp
635 * auto combined = primary_source + secondary_source;
636 * ```
637 *
638 * The resulting node takes an input, passes it to both source nodes,
639 * and returns the sum of their outputs.
640 */
641MAYAFLUX_API std::shared_ptr<Nodes::Node> operator+(const std::shared_ptr<Nodes::Node>& lhs, const std::shared_ptr<Nodes::Node>& rhs);
642
643/**
644 * @brief Combines two nodes in parallel (multiplication)
645 * @param lhs First node
646 * @param rhs Second node
647 * @return A BinaryOpNode that multiplies both outputs
648 *
649 * Creates a new node that processes both input nodes and multiplies their outputs.
650 * This is useful for amplitude modulation, scaling operations, and other
651 * multiplicative transformations:
652 *
653 * ```cpp
654 * auto modulated = carrier * modulator;
655 * ```
656 *
657 * The resulting node takes an input, passes it to both source nodes,
658 * and returns the product of their outputs.
659 */
660MAYAFLUX_API std::shared_ptr<Nodes::Node> operator*(const std::shared_ptr<Nodes::Node>& lhs, const std::shared_ptr<Nodes::Node>& rhs);
661
662}
uint32_t channel
Abstract base class for structured collections of nodes with defined relationships.
std::function< void(const std::shared_ptr< AudioBuffer > &)> AudioProcessingFunction
Audio processing function - receives correctly-typed AudioBuffer.
ProcessingToken
Bitfield enum defining processing characteristics and backend requirements for buffer operations.
@ AUDIO_BACKEND
Standard audio processing backend configuration.
@ GRAPHICS_BACKEND
Standard graphics processing backend configuration.
std::function< void(const std::shared_ptr< VKBuffer > &)> GraphicsProcessingFunction
Graphics processing function - receives correctly-typed VKBuffer.
@ Nodes
DSP Generator and Filter Nodes, graph pipeline, node management.
ProcessingToken
Enumerates the different processing domains for nodes.
@ AUDIO_RATE
Nodes that process at the audio sample rate.
std::shared_ptr< Buffers::BufferProcessor > attach_quick_process_audio(Buffers::AudioProcessingFunction processor, const std::shared_ptr< Buffers::AudioBuffer > &buffer)
Definition Graph.cpp:20
std::shared_ptr< Buffers::BufferProcessor > attach_quick_process_graphics(Buffers::GraphicsProcessingFunction processor, const std::shared_ptr< Buffers::VKBuffer > &buffer)
Definition Graph.cpp:25
void connect_node_to_buffer(const std::shared_ptr< Nodes::Node > &node, const std::shared_ptr< Buffers::AudioBuffer > &buffer, float mix, bool clear_before)
Connects a node to a specific buffer.
Definition Graph.cpp:184
std::shared_ptr< Nodes::Node > operator*(const std::shared_ptr< Nodes::Node > &lhs, const std::shared_ptr< Nodes::Node > &rhs)
Combines two nodes in parallel (multiplication)
Definition Graph.cpp:386
std::shared_ptr< Buffers::AudioBuffer > create_input_listener_buffer(uint32_t channel, bool add_to_output)
Creates a new AudioBuffer for input listening.
Definition Graph.cpp:260
void register_node(const std::shared_ptr< Nodes::Node > &node, const Nodes::ProcessingToken &token, uint32_t channel)
Definition Graph.cpp:124
std::shared_ptr< Buffers::BufferProcessingChain > create_processing_chain()
Creates a new processing chain for the default engine.
Definition Graph.cpp:168
void unregister_node(const std::shared_ptr< Nodes::Node > &node, const Nodes::ProcessingToken &token, uint32_t channel)
Removes a node from the root node of specified channels.
Definition Graph.cpp:85
auto create_processor(const std::shared_ptr< Buffers::AudioBuffer > buffer, Args &&... args) -> std::shared_ptr< ProcessorType >
Creates a new processor and adds it to a buffer.
Definition Graph.hpp:393
void remove_processor(const std::shared_ptr< Buffers::BufferProcessor > &processor, const std::shared_ptr< Buffers::Buffer > &buffer)
Removes a processor from a specific buffer.
Definition Graph.cpp:153
void unregister_graphics_buffer(const std::shared_ptr< Buffers::VKBuffer > &buffer)
Unregisters a VKBuffer from the default engine's buffer manager.
Definition Graph.cpp:245
void add_processor(const std::shared_ptr< Buffers::BufferProcessor > &processor, const std::shared_ptr< Buffers::Buffer > &buffer, Buffers::ProcessingToken token)
Adds a processor to a specific buffer.
Definition Graph.cpp:138
void route_network(const std::shared_ptr< Nodes::Network::NodeNetwork > &network, const std::vector< uint32_t > &channels, uint32_t num_samples, const Nodes::ProcessingToken &token)
@breif Moves the node from its current channel(s) to the specified channel(s) with an optional fade t...
Definition Graph.cpp:203
std::shared_ptr< Nodes::NodeGraphManager > get_node_graph_manager()
Gets the node graph manager from the default engine.
Definition Graph.cpp:35
std::shared_ptr< Buffers::BufferProcessor > attach_quick_process(Buffers::AudioProcessingFunction processor, unsigned int channel_id)
Attaches a processing function to a specific channel.
Definition Graph.cpp:225
std::shared_ptr< Nodes::Node > operator>>(const std::shared_ptr< Nodes::Node > &lhs, const std::shared_ptr< Nodes::Node > &rhs)
Connects two nodes in series (pipeline operator)
Definition Graph.cpp:343
Buffers::RootAudioBuffer & get_root_audio_buffer(uint32_t channel)
Gets the audio buffer for a specific channel.
Definition Graph.cpp:173
auto create_node_network(Args &&... args) -> std::shared_ptr< NodeNetworkType >
Creates a new node network.
Definition Graph.hpp:222
void route_node(const std::shared_ptr< Nodes::Node > &node, const std::vector< uint32_t > &channels, uint32_t num_samples, const Nodes::ProcessingToken &token)
@breif Moves the node from its current channel(s) to the specified channel(s) with an optional fade t...
Definition Graph.cpp:101
void register_node_network(const std::shared_ptr< Nodes::Network::NodeNetwork > &network, const Nodes::ProcessingToken &token)
Registers a node network with the default engine's node graph manager.
Definition Graph.cpp:193
std::shared_ptr< Nodes::Node > operator+(const std::shared_ptr< Nodes::Node > &lhs, const std::shared_ptr< Nodes::Node > &rhs)
Combines two nodes in parallel (addition)
Definition Graph.cpp:377
void remove_supplied_buffer_from_channels(const std::shared_ptr< Buffers::AudioBuffer > &buffer, const std::vector< uint32_t > &channels)
Removes a supplied buffer from multiple channels.
Definition Graph.cpp:316
std::vector< std::shared_ptr< Buffers::AudioBuffer > > clone_buffer_to_channels(const std::shared_ptr< Buffers::AudioBuffer > &buffer, const std::vector< uint32_t > &channels)
Clones a buffer to multiple channels.
Definition Graph.cpp:272
void unregister_audio_buffer(const std::shared_ptr< Buffers::AudioBuffer > &buffer, uint32_t channel)
Unregisters an AudioBuffer from the default engine's buffer manager.
Definition Graph.cpp:235
void supply_buffer_to_channels(const std::shared_ptr< Buffers::AudioBuffer > &buffer, const std::vector< uint32_t > &channels, double mix)
Supplies a buffer to multiple channels with mixing.
Definition Graph.cpp:297
void supply_buffer_to_channel(const std::shared_ptr< Buffers::AudioBuffer > &buffer, uint32_t channel, double mix)
Supplies a buffer to a single channel with mixing.
Definition Graph.cpp:283
void route_buffer(const std::shared_ptr< Buffers::AudioBuffer > &buffer, uint32_t target_channel, double seconds_to_fade, const Buffers::ProcessingToken &token)
Routes a buffer from its current channel to a target channel with fade.
Definition Graph.cpp:324
void register_audio_buffer(const std::shared_ptr< Buffers::AudioBuffer > &buffer, uint32_t channel)
Registers an AudioBuffer with the default engine's buffer manager.
Definition Graph.cpp:230
void detach_from_audio_input(const std::shared_ptr< Buffers::AudioBuffer > &buffer, uint32_t channel)
Stops reading audio data from the default input source.
Definition Graph.cpp:255
void register_audio_node(const std::shared_ptr< Nodes::Node > &node, uint32_t channel)
Adds a node to the root node of a specific channel.
Definition Graph.cpp:40
void unregister_node_network(const std::shared_ptr< Nodes::Network::NodeNetwork > &network, const Nodes::ProcessingToken &token)
Unregisters a node network from the default engine's node graph manager.
Definition Graph.cpp:198
void unregister_audio_node(const std::shared_ptr< Nodes::Node > &node, uint32_t channel)
Removes a node from the root node of a specific channel.
Definition Graph.cpp:62
auto create_node(Args &&... args) -> std::shared_ptr< NodeType >
Definition Graph.hpp:149
std::shared_ptr< Buffers::BufferManager > get_buffer_manager()
Gets the buffer manager from the default engine.
Definition Graph.cpp:133
void register_graphics_buffer(const std::shared_ptr< Buffers::VKBuffer > &buffer, Buffers::ProcessingToken token)
Registers a VKBuffer with the default engine's buffer manager.
Definition Graph.cpp:240
auto create_buffer(uint32_t channel, uint32_t buffer_size, Args &&... args) -> std::shared_ptr< BufferType >
creates a new buffer of the specified type and registers it
Definition Graph.hpp:339
Nodes::RootNode & get_audio_channel_root(uint32_t channel)
Gets the root node for a specific channel.
Definition Graph.cpp:119
std::vector< double > mix(const std::vector< std::vector< double > > &streams)
Mix multiple data streams with equal weighting.
Definition Yantra.cpp:945
void read_from_audio_input(const std::shared_ptr< Buffers::AudioBuffer > &buffer, uint32_t channel)
Reads audio data from the default input source into a buffer.
Definition Graph.cpp:250
void connect_node_to_channel(const std::shared_ptr< Nodes::Node > &node, uint32_t channel_index, float mix, bool clear_before)
Connects a node to a specific output channel.
Definition Graph.cpp:178
void remove_supplied_buffer_from_channel(const std::shared_ptr< Buffers::AudioBuffer > &buffer, const uint32_t channel)
Removes a supplied buffer from multiple channels.
Definition Graph.cpp:306
Main namespace for the Maya Flux audio engine.
Definition Runtime.cpp:12