31class MAYAFLUX_API
Phasor :
public Generator,
public std::enable_shared_from_this<Phasor> {
41 Phasor(
float frequency = 1,
double amplitude = 1,
float offset = 0);
53 Phasor(
const std::shared_ptr<Node>& frequency_modulator,
float frequency = 1,
double amplitude = 1,
float offset = 0);
65 Phasor(
float frequency,
const std::shared_ptr<Node>& amplitude_modulator,
double amplitude = 1,
float offset = 0);
78 Phasor(
const std::shared_ptr<Node>& frequency_modulator,
const std::shared_ptr<Node>& amplitude_modulator,
79 float frequency = 1,
double amplitude = 1,
float offset = 0);
94 double process_sample(
double input = 0.)
override;
104 std::vector<double> process_batch(
unsigned int num_samples)
override;
128 void set_frequency(
float frequency)
override;
145 inline void set_params(
float frequency,
double amplitude,
float offset)
147 m_amplitude = amplitude;
149 set_frequency(frequency);
159 void set_frequency_modulator(
const std::shared_ptr<Node>& modulator);
168 void set_amplitude_modulator(
const std::shared_ptr<Node>& modulator);
176 void clear_modulators();
188 void reset(
float frequency = 1,
float amplitude = 1.0,
float offset = 0,
double phase = 0.0);
201 while (m_phase >= 1.0)
203 while (m_phase < 0.0)
222 void on_phase_wrap(
const NodeHook& callback);
235 void on_threshold(
const NodeHook& callback,
double threshold,
bool rising =
true);
245 bool remove_hook(
const NodeHook& callback)
override;
258 m_conditional_callbacks.clear();
259 m_phase_wrap_callbacks.clear();
260 m_threshold_callbacks.clear();
263 void save_state()
override;
264 void restore_state()
override;
275 void notify_tick(
double value)
override;
285 bool remove_threshold_callback(
const NodeHook& callback);
294 double m_phase_inc {};
318 void update_phase_increment(
double frequency);
340 double m_saved_phase {};
341 float m_saved_frequency {};
342 float m_saved_offset {};
343 double m_saved_phase_inc {};
344 double m_saved_last_output {};
346 bool m_state_saved {};
Base class for all signal and pattern generators in Maya Flux.
std::shared_ptr< Node > m_frequency_modulator
Node that modulates the frequency.
float get_frequency() const
Gets the current base frequency.
bool m_threshold_crossed
Flag indicating whether the threshold has been crossed in the current sample.
bool m_phase_wrapped
Flag indicating whether the phase has wrapped in the current sample.
void set_phase(double phase)
Sets the current phase of the phasor.
std::shared_ptr< Node > m_amplitude_modulator
Node that modulates the amplitude.
std::vector< NodeHook > m_phase_wrap_callbacks
Collection of phase wrap-specific callback functions.
double get_phase() const
Gets the current phase of the phasor.
void remove_all_hooks() override
Removes all registered callbacks.
std::vector< std::pair< NodeHook, double > > m_threshold_callbacks
Collection of threshold-specific callback functions with their thresholds.
void set_params(float frequency, double amplitude, float offset)
Sets all basic parameters at once.
void printCurrent() override
Prints the current parameters of the phasor generator.
void printGraph() override
Prints a visual representation of the phasor waveform.
~Phasor() override=default
Virtual destructor.
float m_offset
DC offset added to the output.
Phase ramp generator node.
std::function< void(NodeContext &)> NodeHook
Callback function type for node processing events.