7 , m_frequency_modulator(nullptr)
8 , m_amplitude_modulator(nullptr)
9 , m_phase_wrapped(false)
10 , m_threshold_crossed(false)
19 , m_frequency_modulator(frequency_modulator)
20 , m_amplitude_modulator(nullptr)
21 , m_phase_wrapped(false)
22 , m_threshold_crossed(false)
31 , m_frequency_modulator(nullptr)
32 , m_amplitude_modulator(amplitude_modulator)
33 , m_phase_wrapped(false)
34 , m_threshold_crossed(false)
41Phasor::Phasor(
const std::shared_ptr<Node>& frequency_modulator,
const std::shared_ptr<Node>& amplitude_modulator,
44 , m_frequency_modulator(frequency_modulator)
45 , m_amplitude_modulator(amplitude_modulator)
46 , m_phase_wrapped(false)
47 , m_threshold_crossed(false)
143 std::vector<double> output(num_samples, 0.0);
145 for (
unsigned int i = 0; i < num_samples; ++i) {
203 const double threshold = entry.params[0];
245std::vector<std::pair<ModulatorRole, std::shared_ptr<Node>>>
248 std::vector<std::pair<ModulatorRole, std::shared_ptr<Node>>> result;
Core::GlobalInputConfig input
float m_frequency
Base frequency of the generator.
NodeContext & get_last_context() override
Gets the last created context object.
double m_amplitude
Base amplitude of the generator.
virtual void update_context(double value) override
Updates the context object for callbacks.
double m_phase
Current phase of the generator.
HookId on_phase_wrap(const TypedHook< GeneratorContext > &callback)
Registers a callback for every phase wrap.
std::shared_ptr< Node > m_frequency_modulator
Node that modulates the frequency.
void set_amplitude_modulator(const std::shared_ptr< Node > &modulator)
Sets a node to modulate the generator's amplitude.
HookId on_threshold(const TypedHook< GeneratorContext > &callback, double threshold, bool rising=true)
Registers a callback for every time the phasor crosses a threshold.
bool m_threshold_crossed
Flag indicating whether the threshold has been crossed in the current sample.
void restore_state() override
Restores the node's state from the last save Recursively cascades through all connected modulator nod...
bool m_phase_wrapped
Flag indicating whether the phase has wrapped in the current sample.
double m_saved_last_output
void set_frequency(float frequency) override
Sets the generator's frequency.
bool remove_hook(const TypedHook< GeneratorContext > &callback)
Removes a previously registered callback.
std::vector< std::pair< ModulatorRole, std::shared_ptr< Node > > > get_modulators() const override
Retrieves the current modulators connected to this node.
HookList m_threshold_callbacks
Collection of threshold-specific callback functions with their thresholds.
std::shared_ptr< Node > m_amplitude_modulator
Node that modulates the amplitude.
std::vector< double > process_batch(unsigned int num_samples) override
Processes multiple samples at once.
void update_phase_increment(double frequency)
Updates the phase increment based on a new frequency.
double m_phase_inc
Phase increment per sample.
void notify_tick(double value) override
Notifies all registered callbacks about a new sample.
void reset(float frequency=1, float amplitude=1.0, float offset=0, double phase=0.0)
Resets the generator's phase and parameters.
HookList m_phase_wrap_callbacks
Collection of phase wrap-specific callback functions.
void set_frequency_modulator(const std::shared_ptr< Node > &modulator)
Sets a node to modulate the generator's frequency.
void save_state() override
Saves the node's current state for later restoration Recursively cascades through all connected modul...
Phasor(float frequency=1, double amplitude=1, float offset=0)
Basic constructor with fixed parameters.
double process_sample(double input=0.) override
Processes a single input sample and generates a phasor sample.
bool remove_threshold_callback(const TypedHook< GeneratorContext > &callback)
Removes a previously registered phase wrap callback.
void clear_modulators()
Removes all modulation connections.
float m_offset
DC offset added to the output.
Snapshot snapshot() const
The current entries, held stable for the lifetime of the returned object.
void fire(NodeContext &ctx) const
Calls every entry whose condition, if any, holds.
bool remove_first_by_key(const std::type_info &key)
Removes the first entry registered with this callable type.
HookId add_unique(NodeHook hook, const std::type_info &key, uint8_t tag=0, std::array< double, 2 > params={})
Appends unless an entry with the same key and params exists, in which case that entry's id is returne...
HookList m_conditional_callbacks
Hooks fired on a tick only while their condition holds.
bool m_state_saved
tracks if the node's state has been saved by a snapshot operation
bool m_networked_node
Flag indicating if the node is part of a NodeNetwork This flag is used to disable event firing when t...
double m_last_output
The most recent sample value generated by this oscillator.
HookList m_callbacks
Hooks fired on every tick.
bool m_fire_events_during_snapshot
Internal flag controlling whether notify_tick fires during state snapshots Default: false (events don...
uint32_t m_timing_rate
Current timing rate for the node, used for timing calculations (can be sample rate or frame rate)
@ PROCESSED
Node has been processed this cycle.
void try_reset_processed_state(std::shared_ptr< Node > node)
Attempts to reset the processed state of a node.
void atomic_inc_modulator_count(std::atomic< uint32_t > &count, int amount)
Atomically increments the modulator count by a specified amount.
uint64_t HookId
Identifies one registration inside a HookList.
void atomic_dec_modulator_count(std::atomic< uint32_t > &count, int amount)
Atomically decrements the modulator count by a specified amount.
std::function< void(ContextT &)> TypedHook
Callback function type for node processing events, parameterised on context type.
NodeHook adapt_hook(const TypedHook< ContextT > &hook)
Wraps a context-typed hook into a NodeHook.
void atomic_add_flag(std::atomic< NodeState > &state, NodeState flag)
Atomically adds a flag to a node state.