MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
NodeBuffer.hpp
Go to the documentation of this file.
1#pragma once
2
5
6namespace MayaFlux::Nodes {
7class Node;
8}
9
10namespace MayaFlux::Buffers {
11
12/**
13 * @class NodeSourceProcessor
14 * @brief Processor that bridges computational nodes and data buffers
15 *
16 * NodeSourceProcessor serves as a data flow connector between the node computation system
17 * and the buffer storage system, enabling the capture and persistence of dynamically
18 * generated values. This component is fundamental for integrating real-time, sample-by-sample
19 * computational processes with block-based data storage and transformation.
20 *
21 * Key capabilities:
22 * - Captures sequential output from computational nodes into structured data buffers
23 * - Provides configurable interpolation between existing and incoming data streams
24 * - Supports both accumulative and replacement data flow patterns
25 *
26 * This processor enables powerful computational patterns such as:
27 * - Capturing generative algorithm outputs for analysis or visualization
28 * - Creating persistent records of ephemeral computational processes
29 * - Implementing hybrid computational models that combine continuous and discrete processing
30 * - Building feedback loops between different computational domains
31 */
32class MAYAFLUX_API NodeSourceProcessor : public BufferProcessor {
33public:
34 /**
35 * @brief Creates a new processor that connects a computational node to data buffers
36 * @param node Source node that generates sequential data values
37 * @param mix Interpolation coefficient between existing and incoming data (0.0-1.0)
38 * @param clear_before_process Whether to reset the buffer before adding node output
39 *
40 * The mix parameter controls the interpolation between existing and incoming data:
41 * - 0.0: Preserve existing data (incoming values ignored)
42 * - 0.5: Equal interpolation between existing and incoming values
43 * - 1.0: Replace with incoming values (existing data overwritten)
44 */
45 NodeSourceProcessor(std::shared_ptr<Nodes::Node> node, float mix = 0.5f, bool clear_before_process = true);
46
47 /**
48 * @brief Captures node computation output into a buffer
49 * @param buffer Buffer to store the processed data
50 *
51 * This method implements a configurable data flow pattern:
52 * 1. Optionally resets the buffer if clear_before_process is true
53 * 2. Generates sequential values from the computational node
54 * 3. Applies the specified interpolation between existing and incoming data
55 */
56 void processing_function(std::shared_ptr<Buffer> buffer) override;
57
58 /**
59 * @brief Sets the interpolation coefficient between existing and incoming data
60 * @param mix Interpolation coefficient (0.0-1.0)
61 */
62 inline void set_mix(float mix) { m_mix = mix; }
63
64 /**
65 * @brief Gets the current interpolation coefficient
66 * @return Current interpolation coefficient (0.0-1.0)
67 */
68 inline float get_mix() const { return m_mix; }
69
70private:
71 /**
72 * @brief Source node that generates sequential data values
73 */
74 std::shared_ptr<Nodes::Node> m_node;
75
76 /**
77 * @brief Interpolation coefficient between existing and incoming data (0.0-1.0)
78 */
79 float m_mix;
80
81 /**
82 * @brief Whether to reset the buffer before adding node output
83 */
85
86 /**
87 * @brief Gets a batch of data from the node
88 * @param num_samples Number of samples to retrieve
89 * @return Vector of data samples
90 *
91 * This method handles the interaction with the node's processing mechanism,
92 * ensuring thread-safe access and proper state management.
93 */
94 std::vector<double> get_node_data(uint32_t num_samples);
95
96 /**
97 * @brief Updates the buffer data with node output
98 * @param buffer_data Reference to the buffer's data vector
99 *
100 * This method applies the node-generated data to the buffer according to
101 * the configured interpolation coefficient and clear_before_process setting.
102 */
103 void update_buffer(std::vector<double>& buffer_data);
104};
105
106/**
107 * @class NodeBuffer
108 * @brief Specialized buffer that automatically captures output from computational nodes
109 *
110 * NodeBuffer extends AudioBuffer to create a buffer with an intrinsic connection
111 * to a computational node. It automatically captures and persists the node's sequential
112 * output, creating a bridge between ephemeral computation and persistent data storage.
113 *
114 * This class implements a composite pattern, combining a data buffer with a NodeSourceProcessor
115 * to create a self-contained component for capturing computational outputs. This simplifies
116 * the creation of data persistence mechanisms within computational networks.
117 *
118 * Applications:
119 * - Creating persistent records of generative algorithm outputs
120 * - Implementing time-delayed computational feedback systems
121 * - Building data bridges between different computational domains
122 * - Enabling analysis and visualization of dynamic computational processes
123 */
124class MAYAFLUX_API NodeBuffer : public AudioBuffer {
125
126public:
127 /**
128 * @brief Creates a new buffer connected to a computational node
129 * @param channel_id Channel identifier for this buffer
130 * @param num_samples Buffer size in samples
131 * @param source Source node that generates sequential data values
132 * @param clear_before_process Whether to reset the buffer before adding node output
133 *
134 * Initializes a buffer that automatically captures output from the specified computational
135 * node when processed. The buffer is configured with a NodeSourceProcessor as its
136 * default processor, creating a self-contained data capture system.
137 */
138 NodeBuffer(uint32_t channel_id, uint32_t num_samples, std::shared_ptr<Nodes::Node> source, bool clear_before_process = true);
139
140 /**
141 * @brief Sets whether to reset the buffer before processing node output
142 * @param value true to reset before processing, false to interpolate with existing content
143 */
144 inline void set_clear_before_process(bool value) { m_clear_before_process = value; }
145
146 /**
147 * @brief Gets whether the buffer is reset before processing node output
148 * @return true if the buffer is reset before processing, false otherwise
149 */
150 inline bool get_clear_before_process() const { return m_clear_before_process; }
151
152 /**
153 * @brief Processes this buffer using its default processor
154 *
155 * For a NodeBuffer, this involves capturing sequential output from the source node
156 * and storing it in the buffer according to the configured interpolation coefficient
157 * and clear_before_process setting.
158 */
159 void process_default() override;
160
161protected:
162 /**
163 * @brief Creates the default processor for this buffer type
164 * @return Shared pointer to a NodeSourceProcessor
165 *
166 * NodeBuffers use a NodeSourceProcessor as their default processor,
167 * which handles capturing output from the source node.
168 */
169 std::shared_ptr<BufferProcessor> create_default_processor() override;
170
171private:
172 /**
173 * @brief Source node that generates sequential data values
174 */
175 std::shared_ptr<Nodes::Node> m_source_node;
176
177 /**
178 * @brief Whether to reset the buffer before adding node output
179 */
181};
182}
Concrete audio implementation of the Buffer interface for double-precision audio data.
Central computational transformation interface for continuous buffer processing.
void set_clear_before_process(bool value)
Sets whether to reset the buffer before processing node output.
bool get_clear_before_process() const
Gets whether the buffer is reset before processing node output.
std::shared_ptr< Nodes::Node > m_source_node
Source node that generates sequential data values.
bool m_clear_before_process
Whether to reset the buffer before adding node output.
Specialized buffer that automatically captures output from computational nodes.
void set_mix(float mix)
Sets the interpolation coefficient between existing and incoming data.
bool m_clear_before_process
Whether to reset the buffer before adding node output.
float m_mix
Interpolation coefficient between existing and incoming data (0.0-1.0)
std::shared_ptr< Nodes::Node > m_node
Source node that generates sequential data values.
float get_mix() const
Gets the current interpolation coefficient.
Processor that bridges computational nodes and data buffers.
Contains the node-based computational processing system components.
Definition Chronie.hpp:5
std::vector< double > mix(const std::vector< std::vector< double > > &streams)
Mix multiple data streams with equal weighting.
Definition Yantra.cpp:1019