76 std::span<bool> history,
78 bool edge_detected =
false,
80 const std::vector<double>& inputs = {})
83 , m_operator(operator_type)
86 , m_edge_detected(edge_detected)
87 , m_edge_type(edge_type)
96 [[nodiscard]] std::span<bool>
get_history()
const {
return m_history; }
100 [[nodiscard]]
const std::vector<double>&
get_inputs()
const {
return m_inputs; }
110 static const std::vector<double> none;
111 return m_coefficients ? *m_coefficients : none;
113 [[nodiscard]]
const double&
get_value()
const {
return m_input; }
116 [[nodiscard]]
bool as_bool()
const {
return get_value() > 0.5; }
127 const std::vector<double>* m_coefficients {};
144 std::span<bool> history,
148 const std::vector<double>& inputs,
149 std::span<const float> gpu_data)
316 Logic(CoefTemporalFunction function, std::vector<double> coefficients);
324 Logic(CoefMultiInputFunction function,
size_t input_count, std::vector<double> coefficients = {});
339 [[nodiscard]] std::shared_ptr<Logic> clone()
const;
348 void set_coefficients(
const std::vector<double>& coefficients);
353 [[nodiscard]]
const std::vector<double>&
get_coefficients()
const {
return m_coefficients; }
363 double process_sample(
double input = 0.)
override;
374 std::vector<double> process_batch(
unsigned int num_samples)
override;
384 double process_multi_input(
const std::vector<double>& inputs);
404 void set_threshold(
double threshold,
bool create_default_direct_function =
false);
416 void set_hysteresis(
double low_threshold,
double high_threshold,
bool create_default_direct_function =
false);
437 void set_operator(
LogicOperator op,
bool create_default_direct_function =
false);
447 void set_direct_function(DirectFunction function);
458 void set_multi_input_function(MultiInputFunction function,
size_t input_count);
465 void set_multi_input_function(CoefMultiInputFunction function,
size_t input_count);
478 void add_input_node(
const std::shared_ptr<Node>& node);
484 void set_input_nodes(std::vector<std::shared_ptr<Node>> nodes);
496 void set_sequential_function(SequentialFunction function,
size_t history_size);
506 void set_temporal_function(TemporalFunction function);
512 void set_direct_function(CoefDirectFunction function);
519 void set_sequential_function(CoefSequentialFunction function,
size_t history_size);
525 void set_temporal_function(CoefTemporalFunction function);
535 void set_initial_conditions(
const std::vector<bool>& initial_values);
543 inline void set_input_node(
const std::shared_ptr<Node>& input_node) { m_input_node = input_node; }
573 std::span<bool> get_history();
647 void save_state()
override;
648 void restore_state()
override;
662 Node::set_gpu_compatible(compatible);
664 m_node_capability |= NodeCapability::VECTOR;
674 [[nodiscard]] std::vector<std::pair<ModulatorRole, std::shared_ptr<Node>>> get_modulators()
const override;
681 void update_context(
double value)
override;
691 void notify_tick(
double value)
override;
700 size_t m_history_head {};
701 size_t m_history_count {};
708 bool m_edge_detected {};
709 bool m_hysteresis_state {};
710 double m_temporal_time {};
723 bool m_coef_bound {};
724 bool m_default_multi_input {};
729 void pull_input_nodes();
730 void release_input_nodes();
732 MultiInputFunction default_multi_input_function();
742 if (
type == LogicEventType::TICK) {
745 if (
type == LogicEventType::CONDITIONAL && condition) {
751 void history_push(
bool val);
753 std::span<bool> history_linearized_view();
765 size_t m_saved_history_head {};
766 size_t m_saved_history_count {};
768 bool m_saved_hysteresis_state {};
769 bool m_saved_edge_detected {};
770 double m_saved_temporal_time {};
771 double m_saved_last_output {};
Core::GlobalInputConfig input
vk::PhysicalDeviceType type
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
const std::vector< double > & get_coefficients() const
The node's coefficient array as it stands at this tick.
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.
const std::vector< double > & get_coefficients() const
The coefficient array as it stands now, including state written by a function.
TemporalFunction m_temporal_function
Function for temporal mode.
std::vector< uint8_t > m_saved_history_ring
DirectFunction m_direct_function
Function for direct mode.
CoefSequentialFunction m_coef_sequential_function
The function behind m_sequential_function while bound.
CoefDirectFunction m_coef_direct_function
The function behind m_direct_function while bound.
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.
std::vector< std::shared_ptr< Node > > m_input_nodes
Nodes feeding the input slots in parallel input mode.
size_t m_history_size
Maximum size of the history buffer.
EdgeType m_edge_type
Type of edge to detect.
std::function< bool(std::span< bool >, std::span< double >)> CoefSequentialFunction
Function type for state-based evaluation with access to the coefficient array.
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, std::span< double >)> CoefDirectFunction
Function type for stateless evaluation with access to the coefficient array.
std::function< bool(double)> DirectFunction
Function type for stateless boolean evaluation.
double m_high_threshold
High threshold for hysteresis.
CoefTemporalFunction m_coef_temporal_function
The function behind m_temporal_function while bound.
std::vector< double > m_input_buffer
std::vector< double > m_coefficients
Coefficient array handed to coefficient-aware functions.
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.
std::function< bool(const std::vector< double > &, std::span< double >)> CoefMultiInputFunction
Function type for parallel input evaluation with access to the coefficient array.
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< uint8_t > m_history_ring
Ring buffer for history storage.
std::function< bool(double, double, std::span< double >)> CoefTemporalFunction
Function type for time-dependent evaluation with access to the coefficient array.
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.
CoefMultiInputFunction m_coef_multi_function
The function behind m_multi_input_function while bound.
LogicMode m_mode
Current processing mode.
std::function< bool(double, double)> TemporalFunction
Function type for time-dependent evaluation.
std::vector< double > m_saved_coefficients
Saved coefficient array, used when a coefficient function is bound.
size_t get_history_size() const
Gets the state history buffer capacity.
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.
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.
Stores, fires and clears the hooks of one node channel.
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.
uint64_t HookId
Identifies one registration inside a HookList.
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.
NodeHook adapt_hook(const TypedHook< ContextT > &hook)
Wraps a context-typed hook into a NodeHook.