MayaFlux 0.2.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(const 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 [[nodiscard]] inline float get_mix() const { return m_mix; }
69
70 void on_attach(const std::shared_ptr<Buffer>& buffer) override;
71
72 void on_detach(const std::shared_ptr<Buffer>& buffer) override;
73
74private:
75 /**
76 * @brief Source node that generates sequential data values
77 */
78 std::shared_ptr<Nodes::Node> m_node;
79
80 /**
81 * @brief Interpolation coefficient between existing and incoming data (0.0-1.0)
82 */
83 float m_mix;
84
85 /**
86 * @brief Whether to reset the buffer before adding node output
87 */
89
90 /**
91 * @brief Gets a batch of data from the node
92 * @param num_samples Number of samples to retrieve
93 * @return Vector of data samples
94 *
95 * This method handles the interaction with the node's processing mechanism,
96 * ensuring thread-safe access and proper state management.
97 */
98 std::vector<double> get_node_data(uint32_t num_samples);
99};
100
101/**
102 * @class NodeBuffer
103 * @brief Specialized buffer that automatically captures output from computational nodes
104 *
105 * NodeBuffer extends AudioBuffer to create a buffer with an intrinsic connection
106 * to a computational node. It automatically captures and persists the node's sequential
107 * output, creating a bridge between ephemeral computation and persistent data storage.
108 *
109 * This class implements a composite pattern, combining a data buffer with a NodeSourceProcessor
110 * to create a self-contained component for capturing computational outputs. This simplifies
111 * the creation of data persistence mechanisms within computational networks.
112 *
113 * Applications:
114 * - Creating persistent records of generative algorithm outputs
115 * - Implementing time-delayed computational feedback systems
116 * - Building data bridges between different computational domains
117 * - Enabling analysis and visualization of dynamic computational processes
118 */
119class MAYAFLUX_API NodeBuffer : public AudioBuffer {
120
121public:
122 /**
123 * @brief Creates a new buffer connected to a computational node
124 * @param channel_id Channel identifier for this buffer
125 * @param num_samples Buffer size in samples
126 * @param source Source node that generates sequential data values
127 * @param clear_before_process Whether to reset the buffer before adding node output
128 *
129 * Initializes a buffer that automatically captures output from the specified computational
130 * node when processed. The buffer is configured with a NodeSourceProcessor as its
131 * default processor, creating a self-contained data capture system.
132 */
133 NodeBuffer(uint32_t channel_id, uint32_t num_samples, std::shared_ptr<Nodes::Node> source, bool clear_before_process = true);
134
135 void setup_processors(ProcessingToken token) override;
136
137 /**
138 * @brief Sets whether to reset the buffer before processing node output
139 * @param value true to reset before processing, false to interpolate with existing content
140 */
141 inline void set_clear_before_process(bool value) { m_clear_before_process = value; }
142
143 /**
144 * @brief Gets whether the buffer is reset before processing node output
145 * @return true if the buffer is reset before processing, false otherwise
146 */
147 inline bool get_clear_before_process() const { return m_clear_before_process; }
148
149 /**
150 * @brief Processes this buffer using its default processor
151 *
152 * For a NodeBuffer, this involves capturing sequential output from the source node
153 * and storing it in the buffer according to the configured interpolation coefficient
154 * and clear_before_process setting.
155 */
156 void process_default() override;
157
158protected:
159 /**
160 * @brief Creates the default processor for this buffer type
161 * @return Shared pointer to a NodeSourceProcessor
162 *
163 * NodeBuffers use a NodeSourceProcessor as their default processor,
164 * which handles capturing output from the source node.
165 */
166 std::shared_ptr<BufferProcessor> create_default_processor() override;
167
168private:
169 /**
170 * @brief Source node that generates sequential data values
171 */
172 std::shared_ptr<Nodes::Node> m_source_node;
173
174 /**
175 * @brief Whether to reset the buffer before adding node output
176 */
178};
179
180}
static MayaFlux::Nodes::ProcessingToken token
Definition Timers.cpp:8
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.
ProcessingToken
Bitfield enum defining processing characteristics and backend requirements for buffer operations.
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