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)
196 explicit Logic(
double threshold = 0.5);
263 double process_sample(
double input = 0.)
override;
274 std::vector<double> process_batch(
unsigned int num_samples)
override;
284 double process_multi_input(
const std::vector<double>& inputs);
304 void set_threshold(
double threshold,
bool create_default_direct_function =
false);
316 void set_hysteresis(
double low_threshold,
double high_threshold,
bool create_default_direct_function =
false);
327 void set_edge_detection(
EdgeType type,
double threshold = 0.5);
337 void set_operator(
LogicOperator op,
bool create_default_direct_function =
false);
390 void set_initial_conditions(
const std::vector<bool>& initial_values);
398 inline void set_input_node(
const std::shared_ptr<Node>& input_node) { m_input_node = input_node; }
428 std::span<bool> get_history();
498 bool remove_conditional_hook(
const NodeCondition& callback)
override;
510 m_all_callbacks.clear();
527 : callback(
std::move(cb))
529 , condition(
std::move(cond))
540 , condition(std::move(cond))
545 void save_state()
override;
546 void restore_state()
override;
560 Node::set_gpu_compatible(compatible);
562 m_node_capability |= NodeCapability::VECTOR;
572 [[nodiscard]] std::vector<std::pair<ModulatorRole, std::shared_ptr<Node>>> get_modulators()
const override;
579 void update_context(
double value)
override;
589 void notify_tick(
double value)
override;
598 size_t m_history_head {};
599 size_t m_history_count {};
606 bool m_edge_detected {};
607 bool m_hysteresis_state {};
608 double m_temporal_time {};
616 void add_input(
double input,
size_t index);
626 m_all_callbacks.emplace_back(callback, type, condition);
629 void history_push(
bool val);
631 std::span<bool> history_linearized_view();
646 size_t m_saved_history_head {};
647 size_t m_saved_history_count {};
649 bool m_saved_hysteresis_state {};
650 bool m_saved_edge_detected {};
651 double m_saved_temporal_time {};
652 double m_saved_last_output {};
Core::GlobalInputConfig input
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)
std::vector< float > gpu_float_buffer
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.
std::function< bool(const std::vector< double > &)> MultiInputFunction
Function type for parallel input evaluation.
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.
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.
void set_gpu_compatible(bool compatible) override
Sets whether the node is compatible with GPU processing.
LogicOperator get_operator() const
Gets the current boolean operator.
void add_callback(const TypedHook< LogicContext > &callback, LogicEventType type, const std::optional< NodeCondition > &condition=std::nullopt)
Adds a callback to the list of all callbacks.
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.
TypedHook<> NodeHook
Alias for TypedHook<NodeContext>.
NodeCapability
Bitmask flags declaring what data shapes a node's context can produce.
std::function< void(ContextT &)> TypedHook
Callback function type for node processing events, parameterised on context type.
std::function< bool(NodeContext &)> NodeCondition
Predicate function type for conditional callbacks.
LogicCallback(const LogicCallback &)=default
LogicCallback(NodeHook cb, LogicEventType type, std::optional< NodeCondition > cond=std::nullopt)
LogicCallback & operator=(LogicCallback &&)=default
LogicCallback & operator=(const LogicCallback &)=default
std::optional< NodeCondition > condition
TypedHook< LogicContext > typed_callback
LogicCallback(const TypedHook< LogicContext > &cb, LogicEventType type, std::optional< NodeCondition > cond=std::nullopt)
LogicCallback(LogicCallback &&)=default
LogicEventType event_type