MayaFlux 0.1.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(const std::deque< bool > &)>
 Function type for state-based evaluation.
 
using TemporalFunction = std::function< bool(double, double)>
 Function type for time-dependent evaluation.
 

Public Member Functions

 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 (DirectFunction function)
 Constructs a Logic node with a custom combinational function.
 
 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.
 
virtual ~Logic ()=default
 
double process_sample (double input=0.) override
 Processes a single input sample through 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.
 
void reset ()
 Resets internal state to initial conditions.
 
void set_threshold (double threshold, bool create_default_direct_function=false)
 Sets the decision boundary for binary quantization.
 
void set_hysteresis (double low_threshold, double high_threshold, bool create_default_direct_function=false)
 Configures noise-resistant binary quantization with memory.
 
void set_edge_detection (EdgeType type, double threshold=0.5)
 Configures digital transition detection.
 
void set_operator (LogicOperator op, bool create_default_direct_function=false)
 Sets the boolean operation to perform.
 
void set_direct_function (DirectFunction function)
 Sets a custom combinational logic function.
 
void set_multi_input_function (MultiInputFunction function, size_t input_count)
 Sets a custom parallel input evaluation function.
 
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_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.
 
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.
 
size_t get_history_size () const
 Gets the state history buffer capacity.
 
const std::deque< bool > & get_history () const
 Gets the current state history.
 
size_t get_input_count () const
 Gets the number of parallel inputs expected.
 
bool was_edge_detected () const
 Checks if a state transition was detected.
 
EdgeType get_edge_type () const
 Gets the type of transitions being monitored.
 
void printGraph () override
 Prints a visual representation of the logic function.
 
void printCurrent () override
 Prints the current state and parameters.
 
void on_tick (const NodeHook &callback) override
 Registers a callback for every generated sample.
 
void on_tick_if (const NodeHook &callback, const NodeCondition &condition) override
 Registers a conditional callback for generated samples.
 
void while_true (const NodeHook &callback)
 Registers a callback that executes continuously while output is true.
 
void while_false (const NodeHook &callback)
 Registers a callback that executes continuously while output is false.
 
void on_change_to (const NodeHook &callback, bool target_state)
 Registers a callback for when output changes to a specific state.
 
void on_change (const NodeHook &callback)
 Registers a callback for any state change (true↔false)
 
bool remove_hook (const NodeHook &callback) override
 Removes a previously registered callback.
 
bool remove_conditional_hook (const NodeCondition &callback) override
 Removes a previously registered conditional callback.
 
void remove_all_hooks () override
 Removes all registered callbacks.
 
void remove_hooks_of_type (LogicEventType type)
 
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 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.
 
- Public Member Functions inherited from MayaFlux::Nodes::Generator::Generator
virtual ~Generator ()=default
 Virtual destructor for proper cleanup.
 
virtual void set_amplitude (double amplitude)
 Sets the generator's amplitude.
 
virtual double get_amplitude () const
 Gets the current base amplitude.
 
virtual void enable_mock_process (bool mock_process)
 Allows RootNode to process the Generator without using the processed sample.
 
virtual bool should_mock_process () const
 Checks if the generator should mock process.
 
virtual void set_frequency (float frequency)
 Sets the generator's frequency.
 
- Public Member Functions inherited from MayaFlux::Nodes::Node
virtual ~Node ()=default
 Virtual destructor for proper cleanup of derived classes.
 
virtual void reset_processed_state ()
 Resets the processed state of the node and any attached input nodes.
 
virtual double get_last_output ()
 Retrieves the most recent output value produced by the node.
 
void register_channel_usage (uint32_t channel_id)
 Mark the specificed channel as a processor/user.
 
void unregister_channel_usage (uint32_t channel_id)
 Removes the specified channel from the usage tracking.
 
bool is_used_by_channel (uint32_t channel_id) const
 Checks if the node is currently used by a specific channel.
 
void request_reset_from_channel (uint32_t channel_id)
 Requests a reset of the processed state from a specific channel.
 
const std::atomic< uint32_t > & get_channel_mask () const
 Retrieves the current bitmask of active channels using this node.
 
NodeContextget_last_context ()
 Retrieves the last created context object.
 
void set_gpu_compatible (bool compatible)
 Sets whether the node is compatible with GPU processing.
 
bool is_gpu_compatible () const
 Checks if the node supports GPU processing.
 
std::span< const float > get_gpu_data_buffer () const
 Provides access to the GPU data buffer.
 

Protected Member Functions

std::unique_ptr< NodeContextcreate_context (double value) override
 Creates a context object for callbacks.
 
void notify_tick (double value) override
 Notifies all registered callbacks about a new sample.
 
- 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_input (double input, size_t index)
 
void add_callback (const NodeHook &callback, LogicEventType type, const std::optional< NodeCondition > &condition=std::nullopt)
 Adds a callback to the list of all callbacks.
 

Private Attributes

LogicMode m_mode
 Current processing mode.
 
LogicOperator m_operator
 Current logic operator.
 
DirectFunction m_direct_function
 Function for direct mode.
 
MultiInputFunction m_multi_input_function
 Function for recursive/feedforward mode.
 
SequentialFunction m_sequential_function
 Function for sequential mode.
 
TemporalFunction m_temporal_function
 Function for temporal mode.
 
std::deque< bool > m_history
 Buffer of input values for feedforward mode.
 
size_t m_history_size
 Maximum size of the history buffer.
 
size_t m_input_count
 Expected number of inputs for multi-input mode.
 
double m_threshold
 Threshold for boolean conversion.
 
double m_low_threshold
 Low threshold for hysteresis.
 
double m_high_threshold
 High threshold for hysteresis.
 
EdgeType m_edge_type
 Type of edge to detect.
 
bool m_edge_detected
 Whether an edge was detected in the last processing.
 
bool m_hysteresis_state
 State for hysteresis operator.
 
double m_temporal_time
 Time tracking for temporal mode.
 
std::vector< double > m_input_buffer
 
double m_input {}
 Current input value for multi-input mode.
 
std::shared_ptr< Nodem_input_node
 Input node for processing.
 
std::vector< LogicCallbackm_all_callbacks
 Collection of all callback functions.
 
std::deque< bool > m_saved_history
 
bool m_saved_hysteresis_state {}
 
bool m_saved_edge_detected {}
 
double m_saved_temporal_time {}
 
double m_saved_last_output {}
 
bool m_state_saved {}
 

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< Utils::NodeStatem_state { Utils::NodeState::INACTIVE }
 Atomic state flag tracking the node's processing status.
 
std::atomic< uint32_t > m_modulator_count { 0 }
 Counter tracking how many other nodes are using this node as a modulator.
 
- Protected Attributes inherited from MayaFlux::Nodes::Generator::Generator
double m_amplitude { 1.0 }
 Base amplitude of the generator.
 
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
double m_last_output { 0 }
 The most recent sample value generated by this oscillator.
 
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::unique_ptr< NodeContextm_last_context
 The last context object created for callbacks.
 
std::vector< float > m_gpu_data_buffer
 GPU data buffer for context objects.
 
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.
 

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 162 of file Logic.hpp.


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