MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
MayaFlux::Nodes::Generator::Counter Class Reference

Integer step accumulator with modulo wrap and optional trigger reset. More...

#include <Counter.hpp>

+ Inheritance diagram for MayaFlux::Nodes::Generator::Counter:
+ Collaboration diagram for MayaFlux::Nodes::Generator::Counter:

Public Member Functions

void clear_reset_trigger ()
 Disconnects the reset trigger node.
 
 Counter (const std::shared_ptr< Node > &reset_trigger, uint32_t modulo=16, int32_t step=1)
 Construct with reset trigger node.
 
 Counter (uint32_t modulo=16, int32_t step=1)
 Construct with modulo and step.
 
uint32_t get_count () const
 Returns current raw counter value.
 
float get_frequency () const
 
uint32_t get_modulo () const
 Returns current modulo.
 
int32_t get_step () const
 Returns current step.
 
void on_count (uint32_t target, const TypedHook< GeneratorContext > &callback)
 Registers a callback fired when the counter reaches a specific raw value.
 
void on_increment (const TypedHook< GeneratorContext > &callback)
 Registers a callback fired on every increment.
 
void on_wrap (const TypedHook< GeneratorContext > &callback)
 Registers a callback fired when the counter wraps to zero.
 
void printCurrent () override
 Prints the current state and parameters of the generator.
 
void printGraph () override
 Prints a visual representation of the generated pattern.
 
std::vector< double > process_batch (unsigned int num_samples) override
 Processes multiple samples at once.
 
double process_sample (double input=0.0) override
 Processes a single data sample.
 
void remove_all_hooks () override
 Removes all registered callbacks.
 
bool remove_hook (const NodeHook &callback) override
 Removes a previously registered callback.
 
void reset ()
 Resets counter to zero immediately.
 
void restore_state () override
 Restores the node's state from the last save Recursively cascades through all connected modulator nodes Protected - only NodeSourceProcessor and NodeBuffer can call.
 
void save_state () override
 Saves the node's current state for later restoration Recursively cascades through all connected modulator nodes Protected - only NodeSourceProcessor and NodeBuffer can call.
 
void set_frequency (float) override
 Sets the generator's frequency.
 
void set_modulo (uint32_t modulo)
 Sets the wrap boundary.
 
void set_reset_trigger (const std::shared_ptr< Node > &trigger)
 Connects a reset trigger node.
 
void set_step (int32_t step)
 Sets the step increment.
 
 ~Counter () override=default
 
- Public Member Functions inherited from MayaFlux::Nodes::Generator::Generator
virtual void enable_mock_process (bool mock_process)
 Allows RootNode to process the Generator without using the processed sample.
 
virtual double get_amplitude () const
 Gets the current base amplitude.
 
NodeContextget_last_context () override
 Gets the last created context object.
 
virtual void set_amplitude (double amplitude)
 Sets the generator's amplitude.
 
virtual bool should_mock_process () const
 Checks if the generator should mock process.
 
virtual ~Generator ()=default
 Virtual destructor for proper cleanup.
 
- Public Member Functions inherited from MayaFlux::Nodes::Node
void add_buffer_reference ()
 Increments the buffer reference count This method is called when a new buffer starts using this node to ensure proper lifecycle management.
 
uint64_t get_active_snapshot_context () const
 Get the active snapshot context ID.
 
const std::atomic< uint32_t > & get_channel_mask () const
 Retrieves the current bitmask of active channels using this node.
 
uint32_t get_frame_rate () const
 
std::span< const float > get_gpu_data_buffer () const
 Provides access to the GPU data buffer.
 
virtual double get_last_output ()
 Retrieves the most recent output value produced by the node.
 
RoutingStateget_routing_state ()
 Retrieves the current routing state of the network (non-const)
 
const RoutingStateget_routing_state () const
 Retrieves the current routing state of the network.
 
uint32_t get_sample_rate () const
 
bool has_active_snapshot () const
 Check if node is currently being snapshotted by any context.
 
bool has_capability (NodeCapability cap) const
 Query a single capability.
 
bool is_buffer_processed () const
 Checks if the buffer has been processed.
 
bool is_gpu_compatible () const
 Checks if the node supports GPU processing.
 
bool is_in_network () const
 Sets whether the node is part of a NodeNetwork.
 
bool is_in_snapshot_context (uint64_t context_id) const
 Check if currently in a snapshot context.
 
bool is_used_by_channel (uint32_t channel_id) const
 Checks if the node is currently used by a specific channel.
 
bool mark_buffer_processed ()
 Marks the node as having been processed by a buffer.
 
bool needs_channel_routing () const
 Checks if the network is currently in a routing transition phase.
 
virtual uint8_t node_capabilities () const
 Declare which data shapes this node's context can produce.
 
virtual void on_tick (const NodeHook &callback)
 Registers a callback to be called on each tick.
 
virtual void on_tick_if (const NodeCondition &condition, const NodeHook &callback)
 Registers a conditional callback.
 
void register_channel_usage (uint32_t channel_id)
 Mark the specificed channel as a processor/user.
 
void release_snapshot_context (uint64_t context_id)
 Release snapshot context.
 
void remove_buffer_reference ()
 Decrements the buffer reference count This method is called when a buffer stops using this node to ensure proper lifecycle management.
 
virtual bool remove_conditional_hook (const NodeCondition &callback)
 Removes a previously registered conditional callback.
 
void request_buffer_reset ()
 Requests a reset of the buffer state.
 
void request_reset_from_channel (uint32_t channel_id)
 Requests a reset of the processed state from a specific channel.
 
virtual void reset_processed_state ()
 Resets the processed state of the node and any attached input nodes.
 
void set_frame_rate (uint32_t frame_rate)
 
virtual void set_gpu_compatible (bool compatible)
 Sets whether the node is compatible with GPU processing.
 
void set_in_network (bool networked)
 Marks the node as being part of a NodeNetwork.
 
void set_sample_rate (uint32_t sample_rate)
 
bool try_claim_snapshot_context (uint64_t context_id)
 Attempt to claim snapshot context for this processing cycle.
 
void unregister_channel_usage (uint32_t channel_id)
 Removes the specified channel from the usage tracking.
 
virtual ~Node ()=default
 Virtual destructor for proper cleanup of derived classes.
 

Protected Member Functions

NodeContextget_last_context () override
 Retrieves the last created context object.
 
void notify_tick (double value) override
 Notifies all registered callbacks with the current context.
 
void update_context (double value) override
 Updates the context object for callbacks.
 
- Protected Member Functions inherited from MayaFlux::Nodes::Node
virtual void reset_processed_state_internal ()
 Resets the processed state of the node directly.
 

Private Attributes

GeneratorContext m_context { 0.0, 0.F, 1.0, 0.0 }
 
uint32_t m_count { 0 }
 
std::vector< std::pair< uint32_t, TypedHook< GeneratorContext > > > m_count_callbacks
 
std::vector< TypedHook< GeneratorContext > > m_increment_callbacks
 
double m_last_trigger_value { 0.0 }
 
uint32_t m_modulo { 16 }
 
std::shared_ptr< Nodem_reset_trigger
 
uint32_t m_saved_count { 0 }
 
double m_saved_last_output { 0.0 }
 
double m_saved_last_trigger_value { 0.0 }
 
int32_t m_step { 1 }
 
std::vector< TypedHook< GeneratorContext > > m_wrap_callbacks
 
bool m_wrapped { false }
 

Additional Inherited Members

- Public Attributes inherited from MayaFlux::Nodes::Node
bool m_fire_events_during_snapshot = false
 Internal flag controlling whether notify_tick fires during state snapshots Default: false (events don't fire during isolated buffer processing) Can be exposed in future if needed via concrete implementation in parent.
 
std::atomic< uint32_t > m_modulator_count { 0 }
 Counter tracking how many other nodes are using this node as a modulator.
 
std::atomic< NodeStatem_state { NodeState::INACTIVE }
 Atomic state flag tracking the node's processing status.
 
- Protected Attributes inherited from MayaFlux::Nodes::Generator::Generator
double m_amplitude { 1.0 }
 Base amplitude of the generator.
 
GeneratorContext m_context { 0., m_frequency, m_amplitude, m_phase }
 
GeneratorContextGpu m_context_gpu { 0., m_frequency, m_amplitude, m_phase, get_gpu_data_buffer() }
 
float m_frequency { 440.0F }
 Base frequency of the generator.
 
double m_phase {}
 Current phase of the generator.
 
- Protected Attributes inherited from MayaFlux::Nodes::Node
std::vector< NodeHookm_callbacks
 Collection of standard callback functions.
 
std::vector< std::pair< NodeHook, NodeCondition > > m_conditional_callbacks
 Collection of conditional callback functions with their predicates.
 
uint32_t m_frame_rate { 60 }
 Frame rate for time-based processing, used for normalization.
 
bool m_gpu_compatible {}
 Flag indicating if the node supports GPU processing This flag is set by derived classes to indicate whether the node can be processed on the GPU.
 
std::vector< float > m_gpu_data_buffer
 GPU data buffer for context objects.
 
double m_last_output { 0 }
 The most recent sample value generated by this oscillator.
 
bool m_networked_node {}
 Flag indicating if the node is part of a NodeNetwork This flag is used to disable event firing when the node is managed within a NodeNetwork, preventing redundant or conflicting event notifications.
 
uint8_t m_node_capability { NodeCapability::SCALAR }
 Bitmask of capabilities declared by this node.
 
uint32_t m_sample_rate { 48000 }
 Sample rate for audio processing, used for normalization.
 
bool m_state_saved {}
 tracks if the node's state has been saved by a snapshot operation
 
uint32_t m_timing_rate { m_sample_rate }
 Current timing rate for the node, used for timing calculations (can be sample rate or frame rate)
 

Detailed Description

Integer step accumulator with modulo wrap and optional trigger reset.

Advances an internal integer counter by a fixed step on every process_sample() call, wrapping at a configurable modulo boundary. Output is the counter value normalized to [0, 1] by default, making it directly composable with any downstream node expecting a unit-range signal.

When modulo is zero the counter accumulates without bound and the raw integer value is emitted as a double, suitable for use as a direct index.

An optional reset trigger node resets the counter to zero on a rising edge (transition from zero to nonzero). The trigger is edge-sensitive: a sustained nonzero value does not repeatedly reset.

Tick rate is determined entirely by the processing token the node is routed into (AUDIO_RATE or VISUAL_RATE), consistent with all other generators.

Definition at line 26 of file Counter.hpp.


The documentation for this class was generated from the following files: