14Counter::Counter(
const std::shared_ptr<Node>& reset_trigger, uint32_t modulo, int32_t step)
17 , m_reset_trigger(reset_trigger)
47 const auto& key =
callback.target_type();
61 double trigger_val = 0.0;
77 auto prev =
static_cast<int32_t
>(
m_count);
78 int32_t next = (prev +
m_step);
79 int32_t wrapped = ((next %
static_cast<int32_t
>(
m_modulo)) +
static_cast<int32_t
>(
m_modulo)) %
static_cast<int32_t
>(
m_modulo);
80 m_wrapped = (wrapped < prev && m_step > 0) || (wrapped > prev &&
m_step < 0);
81 m_count =
static_cast<uint32_t
>(wrapped);
108 std::vector<double>
out(num_samples);
109 for (
unsigned int i = 0; i < num_samples; ++i) {
127 if (
m_count ==
static_cast<uint32_t
>(entry.params[0])) {
164std::vector<std::pair<ModulatorRole, std::shared_ptr<Node>>>
std::vector< float > * out
HookId on_count(uint32_t target, const TypedHook< GeneratorContext > &callback)
Registers a callback fired when the counter reaches a specific raw value.
bool remove_hook(const NodeHook &callback) override
Removes a previously registered callback.
void save_state() override
Saves the node's current state for later restoration Recursively cascades through all connected modul...
HookId on_wrap(const TypedHook< GeneratorContext > &callback)
Registers a callback fired when the counter wraps to zero.
void reset()
Resets counter to zero immediately.
std::vector< double > process_batch(unsigned int num_samples) override
Processes multiple samples at once.
void set_reset_trigger(const std::shared_ptr< Node > &trigger)
Connects a reset trigger node.
HookList m_wrap_callbacks
void restore_state() override
Restores the node's state from the last save Recursively cascades through all connected modulator nod...
void update_context(double value) override
Updates the context object for callbacks.
void set_step(int32_t step)
Sets the step increment.
HookList m_count_callbacks
double m_last_trigger_value
void notify_tick(double value) override
Notifies all registered callbacks with the current context.
double m_saved_last_output
Counter(uint32_t modulo=16, int32_t step=1)
Construct with modulo and step.
std::shared_ptr< Node > m_reset_trigger
std::vector< std::pair< ModulatorRole, std::shared_ptr< Node > > > get_modulators() const override
Retrieves the current modulators connected to this node.
HookId on_increment(const TypedHook< GeneratorContext > &callback)
Registers a callback fired on every increment.
double m_saved_last_trigger_value
void set_modulo(uint32_t modulo)
Sets the wrap boundary.
void clear_reset_trigger()
Disconnects the reset trigger node.
double process_sample(double input=0.0) override
Processes a single data sample.
HookList m_increment_callbacks
Specialized context for generator node callbacks.
GeneratorContext m_context
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.
HookId add(NodeHook hook, const std::type_info &key, uint8_t tag=0, std::array< double, 2 > params={})
Appends a hook with no duplicate check and returns its id.
Snapshot snapshot() const
The current entries, held stable for the lifetime of the returned object.
bool remove_by_key(const std::type_info &key)
Removes every entry registered with this callable type.
void fire(NodeContext &ctx) const
Calls every entry whose condition, if any, holds.
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...
TypedHook<> NodeHook
Alias for TypedHook<NodeContext>.
@ 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.