76 std::span<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)
100 const std::vector<double>&
get_inputs()
const {
return m_inputs; }
104 bool as_bool()
const {
return get_value() > 0.5; }
131 std::span<bool> history,
135 const std::vector<double>& inputs,
136 std::span<const float> gpu_data)
137 :
LogicContext(value, mode, operator_type, history, threshold, edge_detected, edge_type, inputs)
193 explicit Logic(
double threshold = 0.5);
260 double process_sample(
double input = 0.)
override;
271 std::vector<double> process_batch(
unsigned int num_samples)
override;
281 double process_multi_input(
const std::vector<double>& inputs);
301 void set_threshold(
double threshold,
bool create_default_direct_function =
false);
313 void set_hysteresis(
double low_threshold,
double high_threshold,
bool create_default_direct_function =
false);
324 void set_edge_detection(
EdgeType type,
double threshold = 0.5);
334 void set_operator(
LogicOperator op,
bool create_default_direct_function =
false);
387 void set_initial_conditions(
const std::vector<bool>& initial_values);
395 inline void set_input_node(
const std::shared_ptr<Node>& input_node) { m_input_node = input_node; }
425 std::span<bool> get_history();
459 void on_tick(
const NodeHook& callback)
override;
472 void while_true(
const NodeHook& callback);
478 void while_false(
const NodeHook& callback);
485 void on_change_to(
bool target_state,
const NodeHook& callback);
491 void on_change(
const NodeHook& callback);
498 bool remove_hook(
const NodeHook& callback)
override;
505 bool remove_conditional_hook(
const NodeCondition& callback)
override;
517 m_all_callbacks.clear();
530 , condition(
std::move(cond))
535 void save_state()
override;
536 void restore_state()
override;
553 void update_context(
double value)
override;
563 void notify_tick(
double value)
override;
572 size_t m_history_head {};
573 size_t m_history_count {};
580 bool m_edge_detected {};
581 bool m_hysteresis_state {};
582 double m_temporal_time {};
590 void add_input(
double input,
size_t index);
600 m_all_callbacks.emplace_back(callback, type, condition);
603 void history_push(
bool val);
605 std::span<bool> history_linearized_view();
620 size_t m_saved_history_head {};
621 size_t m_saved_history_count {};
623 bool m_saved_hysteresis_state {};
624 bool m_saved_edge_detected {};
625 double m_saved_temporal_time {};
626 double m_saved_last_output {};
Base class for all signal and pattern generators in Maya Flux.
LogicContextGpu(double value, LogicMode mode, LogicOperator operator_type, std::span< 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::span< bool > get_history() const
std::span< bool > m_history
History of boolean states.
bool is_edge_detected() const
LogicContext(double value, LogicMode mode, LogicOperator operator_type, std::span< 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.
LogicMode m_mode
Current computational model.
LogicOperator m_operator
Current boolean operator.
const std::vector< double > & m_inputs
Current input values (for multi-input mode)
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.
std::vector< uint8_t > m_saved_history_ring
DirectFunction m_direct_function
Function for direct mode.
bool was_edge_detected() const
Checks if a state transition was detected.
std::vector< uint8_t > m_history_linear
Linear view of history for easy access.
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::function< bool(double)> DirectFunction
Function type for stateless boolean evaluation.
double m_high_threshold
High threshold for hysteresis.
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.
std::span< double > external_context_view(double input)
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.
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::function< bool(std::span< bool >)> SequentialFunction
Function type for state-based evaluation.
std::vector< LogicCallback > m_all_callbacks
Collection of all callback functions.
void printCurrent() override
Prints the current state and parameters.
std::vector< uint8_t > m_history_ring
Ring buffer for history storage.
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.
LogicContextGpu m_context_gpu
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