76 const std::deque<bool>& history,
78 bool edge_detected =
false,
80 const std::vector<double>& inputs = {})
83 , m_operator(operator_type)
85 , m_threshold(threshold)
86 , m_edge_detected(edge_detected)
87 , m_edge_type(edge_type)
96 const std::deque<bool>&
get_history()
const {
return m_history; }
100 const std::vector<double>&
get_inputs()
const {
return m_inputs; }
104 bool as_bool()
const {
return get_value() > 0.5; }
129 const std::deque<bool>& history,
133 const std::vector<double>& inputs,
134 std::span<const float> gpu_data)
135 :
LogicContext(value, mode, operator_type, history, threshold, edge_detected, edge_type, inputs)
191 explicit Logic(
double threshold = 0.5);
258 double process_sample(
double input = 0.)
override;
269 std::vector<double> process_batch(
unsigned int num_samples)
override;
279 double process_multi_input(
const std::vector<double>& inputs);
299 void set_threshold(
double threshold,
bool create_default_direct_function =
false);
311 void set_hysteresis(
double low_threshold,
double high_threshold,
bool create_default_direct_function =
false);
322 void set_edge_detection(
EdgeType type,
double threshold = 0.5);
332 void set_operator(
LogicOperator op,
bool create_default_direct_function =
false);
385 void set_initial_conditions(
const std::vector<bool>& initial_values);
393 inline void set_input_node(
const std::shared_ptr<Node>& input_node) { m_input_node = input_node; }
457 void on_tick(
const NodeHook& callback)
override;
470 void while_true(
const NodeHook& callback);
476 void while_false(
const NodeHook& callback);
483 void on_change_to(
const NodeHook& callback,
bool target_state);
489 void on_change(
const NodeHook& callback);
496 bool remove_hook(
const NodeHook& callback)
override;
503 bool remove_conditional_hook(
const NodeCondition& callback)
override;
515 m_all_callbacks.clear();
528 , condition(
std::move(cond))
533 void save_state()
override;
534 void restore_state()
override;
546 std::unique_ptr<NodeContext> create_context(
double value)
override;
556 void notify_tick(
double value)
override;
580 void add_input(
double input,
size_t index);
590 m_all_callbacks.emplace_back(callback, type, condition);
604 bool m_saved_hysteresis_state {};
605 bool m_saved_edge_detected {};
606 double m_saved_temporal_time {};
607 double m_saved_last_output {};
608 bool m_state_saved {};
Base class for all signal and pattern generators in Maya Flux.
LogicContextGpu(double value, LogicMode mode, LogicOperator operator_type, const std::deque< bool > &history, double threshold, bool edge_detected, EdgeType edge_type, const std::vector< double > &inputs, std::span< const float > gpu_data)
GPU-accelerated context for logic node callbacks.
std::deque< bool > m_history
History of boolean states.
const std::deque< bool > & get_history() const
bool is_edge_detected() const
LogicMode m_mode
Current computational model.
LogicOperator m_operator
Current boolean operator.
std::vector< double > m_inputs
Current input values (for multi-input mode)
LogicContext(double value, LogicMode mode, LogicOperator operator_type, const std::deque< bool > &history, double threshold, bool edge_detected=false, EdgeType edge_type=EdgeType::BOTH, const std::vector< double > &inputs={})
Constructs a LogicContext with complete state information.
double get_threshold() const
LogicMode get_mode() const
double m_input
Current input value for multi-input mode.
const std::vector< double > & get_inputs() const
EdgeType m_edge_type
Type of transition being monitored.
bool m_edge_detected
Whether a state transition was detected.
const double & get_value() const
LogicOperator get_operator() const
EdgeType get_edge_type() const
double m_threshold
Decision boundary for binary quantization.
SequentialFunction m_sequential_function
Function for sequential mode.
TemporalFunction m_temporal_function
Function for temporal mode.
DirectFunction m_direct_function
Function for direct mode.
bool was_edge_detected() const
Checks if a state transition was detected.
size_t m_history_size
Maximum size of the history buffer.
EdgeType m_edge_type
Type of edge to detect.
void set_input_node(const std::shared_ptr< Node > &input_node)
Sets the input node to generate logic values from.
double m_threshold
Threshold for boolean conversion.
std::deque< bool > m_history
Buffer of input values for feedforward mode.
std::function< bool(double)> DirectFunction
Function type for stateless boolean evaluation.
double m_temporal_time
Time tracking for temporal mode.
double m_high_threshold
High threshold for hysteresis.
std::function< bool(const std::deque< bool > &)> SequentialFunction
Function type for state-based evaluation.
std::vector< double > m_input_buffer
std::shared_ptr< Node > m_input_node
Input node for processing.
LogicMode get_mode() const
Gets the current computational model.
LogicOperator m_operator
Current logic operator.
void printGraph() override
Prints a visual representation of the logic function.
std::function< bool(const std::vector< double > &)> MultiInputFunction
Function type for parallel input evaluation.
const std::deque< bool > & get_history() const
Gets the current state history.
void add_callback(const NodeHook &callback, LogicEventType type, const std::optional< NodeCondition > &condition=std::nullopt)
Adds a callback to the list of all callbacks.
double m_low_threshold
Low threshold for hysteresis.
MultiInputFunction m_multi_input_function
Function for recursive/feedforward mode.
std::deque< bool > m_saved_history
bool m_edge_detected
Whether an edge was detected in the last processing.
std::vector< LogicCallback > m_all_callbacks
Collection of all callback functions.
void printCurrent() override
Prints the current state and parameters.
bool m_hysteresis_state
State for hysteresis operator.
void remove_all_hooks() override
Removes all registered callbacks.
double get_threshold() const
Gets the decision boundary for binary quantization.
EdgeType get_edge_type() const
Gets the type of transitions being monitored.
size_t get_input_count() const
Gets the number of parallel inputs expected.
LogicOperator get_operator() const
Gets the current boolean operator.
LogicMode m_mode
Current processing mode.
std::function< bool(double, double)> TemporalFunction
Function type for time-dependent evaluation.
size_t get_history_size() const
Gets the state history buffer capacity.
size_t m_input_count
Expected number of inputs for multi-input mode.
Digital signal processor implementing boolean logic operations.
GPU-uploadable 1D array data interface.
Base context class for node callbacks.
EdgeType
Digital transition patterns to detect.
@ FALLING
High-to-low transition (1→0)
@ BOTH
Any state transition.
@ RISING
Low-to-high transition (0→1)
LogicMode
Defines the computational model for digital signal evaluation.
@ SEQUENTIAL
State-based evaluation using history of inputs (sequential logic)
@ DIRECT
Stateless evaluation of current input only (combinational logic)
@ TEMPORAL
Time-dependent evaluation with timing constraints.
@ MULTI_INPUT
Parallel evaluation of multiple input signals.
LogicEventType
Events that can trigger callbacks.
LogicOperator
Digital operators for boolean computation.
@ NOT
Logical NOT - inverts the input.
@ NOR
Logical NOR - inverted OR operation.
@ OR
Logical OR - true when any input is true.
@ IMPLIES
Logical implication - false only when A is true and B is false.
@ NAND
Logical NAND - inverted AND operation.
@ THRESHOLD
Binary quantization - true when input exceeds threshold.
@ AND
Logical AND - true only when all inputs are true.
@ EDGE
Transition detector - identifies state changes.
@ HYSTERESIS
Threshold with memory - prevents rapid oscillation at boundary.
@ CUSTOM
User-defined boolean function.
@ XOR
Logical XOR - true when odd number of inputs are true.
std::function< void(NodeContext &)> NodeHook
Callback function type for node processing events.
std::function< bool(NodeContext &)> NodeCondition
Predicate function type for conditional callbacks.
LogicCallback(const NodeHook &cb, LogicEventType type, std::optional< NodeCondition > cond=std::nullopt)
std::optional< NodeCondition > condition
LogicEventType event_type