MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Generator.hpp
Go to the documentation of this file.
1#pragma once
2
4
6
7/**
8 * @class GeneratorContext
9 * @brief Specialized context for generator node callbacks
10 *
11 * GeneratorContext extends the base NodeContext to provide detailed information
12 * about a generator's current state to callbacks. It includes fundamental
13 * oscillator parameters such as frequency, amplitude, and phase that define
14 * the generator's behavior at the moment a sample is produced.
15 *
16 * This rich context enables callbacks to perform sophisticated analysis and
17 * monitoring of generator behavior, such as:
18 * - Tracking parameter changes over time
19 * - Implementing frequency-dependent processing
20 * - Creating visualizations of generator state
21 * - Synchronizing multiple generators based on phase relationships
22 * - Implementing adaptive processing based on generator characteristics
23 */
24class MAYAFLUX_API GeneratorContext : public NodeContext {
25public:
26 /**
27 * @brief Constructs a GeneratorContext with the current generator state
28 * @param value Current output sample value
29 * @param frequency Current oscillation frequency in Hz
30 * @param amplitude Current scaling factor for output values
31 * @param phase Current phase position in radians
32 *
33 * Creates a context object that provides a complete snapshot of the
34 * generator's current state, including its most recent output value
35 * and all parameters that define its oscillation behavior.
36 */
37 GeneratorContext(double value, double frequency, float amplitude, double phase)
38 : NodeContext(value, typeid(GeneratorContext).name())
39 , frequency(frequency)
40 , amplitude(amplitude)
41 , phase(phase)
42 {
43 }
44
45 /**
46 * @brief Current frequency of the generator
47 *
48 * Represents the oscillation rate in Hertz (cycles per second).
49 * This parameter determines the pitch or periodicity of the
50 * generated signal.
51 */
52 double frequency;
53
54 /**
55 * @brief Current amplitude of the generator
56 */
57 float amplitude;
58
59 /**
60 * @brief Current phase of the generator
61 */
62 double phase;
63};
64
65class MAYAFLUX_API GeneratorContextGpu : public GeneratorContext, public GpuVectorData {
66public:
68 double value,
69 double frequency,
70 float amplitude,
71 double phase,
72 std::span<const float> gpu_data)
73 : GeneratorContext(value, frequency, amplitude, phase)
74 , GpuVectorData(gpu_data)
75 {
76 type_id = typeid(GeneratorContextGpu).name();
77 }
78};
79
80/**
81 * @class Generator
82 * @brief Base class for all signal and pattern generators in Maya Flux
83 *
84 * Generators are specialized nodes that create numerical sequences from mathematical principles,
85 * rather than processing existing signals. They form the foundation of the
86 * computational graph by providing the initial patterns that other nodes
87 * can then transform, filter, or combine.
88 *
89 * Unlike transformation nodes that modify input signals, generators typically:
90 * - Create sequences based on mathematical formulas or algorithms
91 * - Maintain internal state to track progression, phase, or other parameters
92 * - Can operate autonomously without any input (though they may accept modulation inputs)
93 * - Serve as the origin points in computational processing networks
94 *
95 * Common types of generators include:
96 * - Oscillators (sine, square, sawtooth, triangle waves)
97 * - Stochastic generators (various probability distributions)
98 * - Sample-based generators (playing back recorded sequences)
99 * - Envelope generators (creating amplitude contours)
100 *
101 * Generators integrate with the node graph system, allowing them to be:
102 * - Connected to other nodes using operators like '>>' (chain)
103 * - Combined with other nodes using operators like '+' (mix)
104 * - Registered with a RootNode for processing
105 * - Used as modulation sources for other generators or transformations
106 *
107 * The Generator class extends the base Node interface with additional
108 * methods for visualization and analysis of the generated patterns.
109 */
110class MAYAFLUX_API Generator : public Node {
111public:
112 /**
113 * @brief Virtual destructor for proper cleanup
114 */
115 virtual ~Generator() = default;
116
117 /**
118 * @brief Sets the generator's amplitude
119 * @param amplitude New amplitude value
120 *
121 * This method updates the generator's amplitude setting,
122 * which controls the overall scaling of the generated values.
123 */
124 inline virtual void set_amplitude(double amplitude) { m_amplitude = amplitude; }
125
126 /**
127 * @brief Gets the current base amplitude
128 * @return Current amplitude
129 */
130 inline virtual double get_amplitude() const { return m_amplitude; }
131
132 /**
133 * @brief Allows RootNode to process the Generator without using the processed sample
134 * @param bMock_process True to mock process, false to process normally
135 *
136 * NOTE: This has no effect on the behaviour of process_sample (or process_batch).
137 * This is ONLY used by the RootNode when processing the node graph.
138 * If the output of the Generator needs to be ignored elsewhere, simply discard the return value.
139 *
140 * Calling process manually can be cumbersome. Using a coroutine just to call process
141 * is overkill. This method allows the RootNode to process the Generator without
142 * using the processed sample, which is useful for mocking processing.
143 */
144 virtual void enable_mock_process(bool mock_process);
145
146 /**
147 * @brief Checks if the generator should mock process
148 * @return True if the generator should mock process, false otherwise
149 */
150 virtual bool should_mock_process() const;
151
152 /**
153 * @brief Prints a visual representation of the generated pattern
154 *
155 * This method should output a visual representation of the
156 * generator's output over time, useful for analysis and
157 * understanding the pattern characteristics.
158 */
159 virtual void printGraph() = 0;
160
161 /**
162 * @brief Prints the current state and parameters of the generator
163 *
164 * This method should output the current configuration and state
165 * of the generator, including parameters like frequency, amplitude,
166 * phase, or any other generator-specific settings.
167 */
168 virtual void printCurrent() = 0;
169
170 /**
171 * @brief Creates a context object for callbacks
172 * @param value The current generated sample
173 * @return A unique pointer to a GeneratorContext object
174 *
175 * This method creates a specialized context object containing
176 * the current sample value and all oscillator parameters, providing
177 * callbacks with rich information about the oscillator's state.
178 */
179 virtual std::unique_ptr<NodeContext> create_context(double value) override;
180
181 /**
182 * @brief Sets the generator's frequency
183 * @param frequency New frequency value in Hz
184 *
185 * This method updates the generator's frequency setting,
186 * which controls the rate of oscillation or pattern repetition.
187 */
188 virtual void set_frequency(float frequency) { m_frequency = frequency; }
189
190protected:
191 /**
192 * @brief Base amplitude of the generator
193 */
194 double m_amplitude { 1.0 };
195
196 /**
197 * @brief Base frequency of the generator
198 */
199 float m_frequency { 440.0F };
200
201 /**
202 * @brief Current phase of the generator
203 */
204 double m_phase {};
205};
206
207}
GeneratorContextGpu(double value, double frequency, float amplitude, double phase, std::span< const float > gpu_data)
Definition Generator.hpp:67
double phase
Current phase of the generator.
Definition Generator.hpp:62
double frequency
Current frequency of the generator.
Definition Generator.hpp:52
float amplitude
Current amplitude of the generator.
Definition Generator.hpp:57
GeneratorContext(double value, double frequency, float amplitude, double phase)
Constructs a GeneratorContext with the current generator state.
Definition Generator.hpp:37
Specialized context for generator node callbacks.
Definition Generator.hpp:24
virtual ~Generator()=default
Virtual destructor for proper cleanup.
virtual void printCurrent()=0
Prints the current state and parameters of the generator.
virtual void printGraph()=0
Prints a visual representation of the generated pattern.
virtual double get_amplitude() const
Gets the current base amplitude.
virtual void set_amplitude(double amplitude)
Sets the generator's amplitude.
virtual void set_frequency(float frequency)
Sets the generator's frequency.
Base class for all signal and pattern generators in Maya Flux.
GPU-uploadable 1D array data interface.
Base context class for node callbacks.
Definition Node.hpp:30
Base interface for all computational processing nodes.
Definition Node.hpp:109