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