|
MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
|
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:Public Types | |
| using | CoefDirectFunction = std::function< bool(double, std::span< double >)> |
| Function type for stateless evaluation with access to the coefficient array. | |
| using | CoefMultiInputFunction = std::function< bool(const std::vector< double > &, std::span< double >)> |
| Function type for parallel input evaluation with access to the coefficient array. | |
| using | CoefSequentialFunction = std::function< bool(std::span< bool >, std::span< double >)> |
| Function type for state-based evaluation with access to the coefficient array. | |
| using | CoefTemporalFunction = std::function< bool(double, double, std::span< double >)> |
| Function type for time-dependent evaluation with access to the coefficient array. | |
| 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 | |
| void | add_input_node (const std::shared_ptr< Node > &node) |
| Appends a node whose output feeds the next input slot. | |
| std::shared_ptr< Logic > | clone () const |
| An independent node with the same behaviour and fresh state. | |
| const std::vector< double > & | get_coefficients () const |
| The coefficient array as it stands now, including state written by a function. | |
| 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. | |
| NodeContext & | get_last_context () override |
| Retrieves the last created context object. | |
| LogicMode | get_mode () const |
| Gets the current computational model. | |
| std::vector< std::pair< ModulatorRole, std::shared_ptr< Node > > > | get_modulators () const override |
| Retrieves the current modulators connected to this node. | |
| LogicOperator | get_operator () const |
| Gets the current boolean operator. | |
| double | get_threshold () const |
| Gets the decision boundary for binary quantization. | |
| Logic (CoefDirectFunction function, std::vector< double > coefficients) | |
| Constructs a Logic node with a stateless function and a coefficient array. | |
| Logic (CoefMultiInputFunction function, size_t input_count, std::vector< double > coefficients={}) | |
| Constructs a Logic node for parallel inputs with a coefficient array. | |
| Logic (CoefSequentialFunction function, size_t history_size, std::vector< double > coefficients={}) | |
| Constructs a Logic node with a state-based function and a coefficient array. | |
| Logic (CoefTemporalFunction function, std::vector< double > coefficients) | |
| Constructs a Logic node with a time-dependent function and a coefficient array. | |
| 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. | |
| HookId | on_change (const TypedHook< LogicContext > &callback) |
| Registers a callback for any state change (true↔false) | |
| HookId | on_change_to (bool target_state, const TypedHook< LogicContext > &callback) |
| Registers a callback for when output changes to a specific state. | |
| HookId | on_tick (const TypedHook< LogicContext > &callback) |
| Registers a callback for every generated sample. | |
| HookId | on_tick_if (const NodeCondition &condition, const TypedHook< LogicContext > &callback) |
| Registers a conditional callback for generated samples. | |
| 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. | |
| bool | remove_conditional_hook (const NodeCondition &callback) override |
| Removes a previously registered conditional callback. | |
| bool | remove_hook (const TypedHook< LogicContext > &callback) |
| 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_coefficients (const std::vector< double > &coefficients) |
| Replaces the coefficient array. | |
| void | set_direct_function (CoefDirectFunction function) |
| Sets a stateless function that receives the coefficient array. | |
| 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_input_nodes (std::vector< std::shared_ptr< Node > > nodes) |
| Replaces all input nodes. | |
| void | set_multi_input_function (CoefMultiInputFunction function, size_t input_count) |
| Sets a parallel input function that receives the coefficient array. | |
| 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 (CoefSequentialFunction function, size_t history_size) |
| Sets a state-based function that receives the coefficient array. | |
| void | set_sequential_function (SequentialFunction function, size_t history_size) |
| Sets a custom state-based evaluation function. | |
| void | set_temporal_function (CoefTemporalFunction function) |
| Sets a time-dependent function that receives the coefficient array. | |
| 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. | |
| HookId | while_false (const TypedHook< LogicContext > &callback) |
| Registers a callback that executes continuously while output is false. | |
| HookId | while_true (const TypedHook< LogicContext > &callback) |
| Registers a callback that executes continuously while output is true. | |
| virtual | ~Logic ()=default |
Public Member Functions inherited from MayaFlux::Nodes::Generator::Generator | |
| virtual double | get_amplitude () const |
| Gets the current base amplitude. | |
| virtual float | get_frequency () const |
| Gets the current frequency. | |
| HookId | on_tick (const TypedHook< GeneratorContext > &callback) |
| Registers a typed callback receiving GeneratorContext directly. | |
| HookId | on_tick_if (const NodeCondition &condition, const TypedHook< GeneratorContext > &callback) |
| Registers a conditional typed callback receiving GeneratorContext directly. | |
| virtual void | set_amplitude (double amplitude) |
| Sets the generator's amplitude. | |
| virtual void | set_frequency (float frequency) |
| Sets the generator's frequency. | |
| 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. | |
| void | enable_mock_process (bool mock_process) |
| Old name of exclude_output_from_graph(). | |
| virtual void | exclude_output_from_graph (bool excluded=true) |
| Exclude this node's output from the graph it is registered in. | |
| 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. | |
| std::vector< ModulatorTree > | get_modulator_tree () const |
| Returns the full modulator tree rooted at this node. | |
| RoutingState & | get_routing_state () |
| Retrieves the current routing state of the network (non-const) | |
| const RoutingState & | get_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. | |
| virtual bool | is_output_excluded_from_graph () const |
| True if the node's output is excluded from the graph. | |
| 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 HookId | on_tick (const NodeHook &callback) |
| Registers a callback to be called on each tick. | |
| virtual HookId | 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. | |
| virtual void | remove_all_hooks () |
| Removes all registered callbacks. | |
| 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_hook (const NodeHook &callback) |
| Removes a previously registered 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) |
| void | set_in_network (bool networked) |
| Marks the node as being part of a NodeNetwork. | |
| void | set_sample_rate (uint32_t sample_rate) |
| bool | should_mock_process () const |
| Old name of is_output_excluded_from_graph(). | |
| bool | try_claim_snapshot_context (uint64_t context_id) |
| Attempt to claim snapshot context for this processing cycle. | |
| virtual bool | unhook (HookId id) |
| Removes the one registration with this id, whichever hook list holds it. | |
| 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 | |
| HookId | add_callback (const TypedHook< LogicContext > &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) |
| MultiInputFunction | default_multi_input_function () |
| std::span< double > | external_context_view (double input) |
| std::span< bool > | history_linearized_view () |
| void | history_push (bool val) |
| void | pull_input_nodes () |
| void | release_input_nodes () |
Private Attributes | |
| HookList | m_all_callbacks { *this } |
| Event-specific callbacks, tagged with their LogicEventType. | |
| bool | m_coef_bound {} |
| True while the active mode runs a coefficient function. | |
| CoefDirectFunction | m_coef_direct_function |
| The function behind m_direct_function while bound. | |
| CoefMultiInputFunction | m_coef_multi_function |
| The function behind m_multi_input_function while bound. | |
| CoefSequentialFunction | m_coef_sequential_function |
| The function behind m_sequential_function while bound. | |
| CoefTemporalFunction | m_coef_temporal_function |
| The function behind m_temporal_function while bound. | |
| std::vector< double > | m_coefficients |
| Coefficient array handed to coefficient-aware functions. | |
| LogicContext | m_context |
| LogicContextGpu | m_context_gpu |
| bool | m_default_multi_input {} |
| True while the parallel function is the built in all-above-threshold one. | |
| 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< Node > | m_input_node |
| Input node for processing. | |
| std::vector< std::shared_ptr< Node > > | m_input_nodes |
| Nodes feeding the input slots in parallel input mode. | |
| 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. | |
| std::vector< double > | m_saved_coefficients |
| Saved coefficient array, used when a coefficient function is bound. | |
| 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< NodeState > | m_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 | |
| HookList | m_callbacks { *this } |
| Hooks fired on every tick. | |
| HookList | m_conditional_callbacks { *this } |
| Hooks fired on a tick only while their condition holds. | |
| 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) | |
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:
Applications include: