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

Digital signal processor implementing boolean logic operations. More...

#include <Logic.hpp>

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

Classes

struct  LogicCallback
 

Public Types

using DirectFunction = std::function< bool(double)>
 Function type for stateless boolean evaluation.
 
using MultiInputFunction = std::function< bool(const std::vector< double > &)>
 Function type for parallel input evaluation.
 
using SequentialFunction = std::function< bool(std::span< bool >)>
 Function type for state-based evaluation.
 
using TemporalFunction = std::function< bool(double, double)>
 Function type for time-dependent evaluation.
 

Public Member Functions

EdgeType get_edge_type () const
 Gets the type of transitions being monitored.
 
std::span< bool > get_history ()
 Gets the current state history.
 
size_t get_history_size () const
 Gets the state history buffer capacity.
 
size_t get_input_count () const
 Gets the number of parallel inputs expected.
 
NodeContextget_last_context () override
 Retrieves the last created context object.
 
LogicMode get_mode () const
 Gets the current computational model.
 
LogicOperator get_operator () const
 Gets the current boolean operator.
 
double get_threshold () const
 Gets the decision boundary for binary quantization.
 
 Logic (DirectFunction function)
 Constructs a Logic node with a custom combinational function.
 
 Logic (double threshold=0.5)
 Constructs a Logic node with threshold quantization.
 
 Logic (LogicOperator op, double threshold=0.5)
 Constructs a Logic node with a specific boolean operator.
 
 Logic (MultiInputFunction function, size_t input_count)
 Constructs a Logic node for parallel input evaluation.
 
 Logic (SequentialFunction function, size_t history_size)
 Constructs a Logic node for state-based evaluation.
 
 Logic (TemporalFunction function)
 Constructs a Logic node for time-dependent evaluation.
 
void on_change (const NodeHook &callback)
 Registers a callback for any state change (true↔false)
 
void on_change_to (bool target_state, const NodeHook &callback)
 Registers a callback for when output changes to a specific state.
 
void on_tick (const NodeHook &callback) override
 Registers a callback for every generated sample.
 
void on_tick_if (const NodeCondition &condition, const NodeHook &callback) override
 Registers a conditional callback for generated samples.
 
void printCurrent () override
 Prints the current state and parameters.
 
void printGraph () override
 Prints a visual representation of the logic function.
 
std::vector< double > process_batch (unsigned int num_samples) override
 Processes multiple samples in batch mode.
 
double process_multi_input (const std::vector< double > &inputs)
 Processes multiple parallel inputs.
 
double process_sample (double input=0.) override
 Processes a single input sample through the logic function.
 
void remove_all_hooks () override
 Removes all registered callbacks.
 
bool remove_conditional_hook (const NodeCondition &callback) override
 Removes a previously registered conditional callback.
 
bool remove_hook (const NodeHook &callback) override
 Removes a previously registered callback.
 
void remove_hooks_of_type (LogicEventType type)
 
void reset ()
 Resets internal state to initial conditions.
 
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_direct_function (DirectFunction function)
 Sets a custom combinational logic function.
 
void set_edge_detection (EdgeType type, double threshold=0.5)
 Configures digital transition detection.
 
void set_gpu_compatible (bool compatible) override
 Sets whether the node is compatible with GPU processing.
 
void set_hysteresis (double low_threshold, double high_threshold, bool create_default_direct_function=false)
 Configures noise-resistant binary quantization with memory.
 
void set_initial_conditions (const std::vector< bool > &initial_values)
 Preloads the state history buffer.
 
void set_input_node (const std::shared_ptr< Node > &input_node)
 Sets the input node to generate logic values from.
 
void set_multi_input_function (MultiInputFunction function, size_t input_count)
 Sets a custom parallel input evaluation function.
 
void set_operator (LogicOperator op, bool create_default_direct_function=false)
 Sets the boolean operation to perform.
 
void set_sequential_function (SequentialFunction function, size_t history_size)
 Sets a custom state-based evaluation function.
 
void set_temporal_function (TemporalFunction function)
 Sets a custom time-dependent evaluation function.
 
void set_threshold (double threshold, bool create_default_direct_function=false)
 Sets the decision boundary for binary quantization.
 
bool was_edge_detected () const
 Checks if a state transition was detected.
 
void while_false (const NodeHook &callback)
 Registers a callback that executes continuously while output is false.
 
void while_true (const NodeHook &callback)
 Registers a callback that executes continuously while output is true.
 
virtual ~Logic ()=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.
 
virtual void set_amplitude (double amplitude)
 Sets the generator's amplitude.
 
virtual void set_frequency (float frequency)
 Sets the generator's frequency.
 
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.
 
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.
 
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)
 
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

void notify_tick (double value) override
 Notifies all registered callbacks about a new sample.
 
void update_context (double value) override
 Updates the context with the latest sample value.
 
- Protected Member Functions inherited from MayaFlux::Nodes::Node
virtual void reset_processed_state_internal ()
 Resets the processed state of the node directly.
 

Private Member Functions

void add_callback (const NodeHook &callback, LogicEventType type, const std::optional< NodeCondition > &condition=std::nullopt)
 Adds a callback to the list of all callbacks.
 
void add_input (double input, size_t index)
 
std::span< double > external_context_view (double input)
 
std::span< bool > history_linearized_view ()
 
void history_push (bool val)
 

Private Attributes

std::vector< LogicCallbackm_all_callbacks
 Collection of all callback functions.
 
LogicContext m_context
 
LogicContextGpu m_context_gpu
 
DirectFunction m_direct_function
 Function for direct mode.
 
bool m_edge_detected {}
 Whether an edge was detected in the last processing.
 
EdgeType m_edge_type
 Type of edge to detect.
 
double m_high_threshold
 High threshold for hysteresis.
 
size_t m_history_count {}
 Number of valid entries in the history buffer.
 
size_t m_history_head {}
 Head index for the history ring buffer.
 
std::vector< uint8_t > m_history_linear
 Linear view of history for easy access.
 
std::vector< uint8_t > m_history_ring
 Ring buffer for history storage.
 
size_t m_history_size
 Maximum size of the history buffer.
 
bool m_hysteresis_state {}
 State for hysteresis operator.
 
double m_input {}
 Current input value for multi-input mode.
 
std::vector< double > m_input_buffer
 
size_t m_input_count
 Expected number of inputs for multi-input mode.
 
std::shared_ptr< Nodem_input_node
 Input node for processing.
 
double m_low_threshold
 Low threshold for hysteresis.
 
LogicMode m_mode
 Current processing mode.
 
MultiInputFunction m_multi_input_function
 Function for recursive/feedforward mode.
 
LogicOperator m_operator
 Current logic operator.
 
bool m_saved_edge_detected {}
 
size_t m_saved_history_count {}
 
size_t m_saved_history_head {}
 
std::vector< uint8_t > m_saved_history_ring
 
bool m_saved_hysteresis_state {}
 
double m_saved_last_output {}
 
double m_saved_temporal_time {}
 
SequentialFunction m_sequential_function
 Function for sequential mode.
 
TemporalFunction m_temporal_function
 Function for temporal mode.
 
double m_temporal_time {}
 Time tracking for temporal mode.
 
double m_threshold
 Threshold for boolean conversion.
 

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

Digital signal processor implementing boolean logic operations.

The Logic node transforms continuous signals into discrete binary outputs using configurable boolean operations. It supports multiple computational models:

  • Combinational logic: Stateless evaluation based solely on current inputs
  • Sequential logic: State-based evaluation using history of previous inputs
  • Temporal logic: Time-dependent evaluation with timing constraints
  • Multi-input logic: Parallel evaluation of multiple input signals

Applications include:

  • Binary signal generation
  • Event detection and triggering
  • State machine implementation
  • Digital pattern recognition
  • Signal quantization and discretization
  • Conditional processing chains

Definition at line 168 of file Logic.hpp.


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