MayaFlux 0.3.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Logic.hpp
Go to the documentation of this file.
1#pragma once
2
4
6
7/**
8 * @enum LogicMode
9 * @brief Defines the computational model for digital signal evaluation
10 */
11enum class LogicMode : uint8_t {
12 DIRECT, ///< Stateless evaluation of current input only (combinational logic)
13 SEQUENTIAL, ///< State-based evaluation using history of inputs (sequential logic)
14 TEMPORAL, ///< Time-dependent evaluation with timing constraints
15 MULTI_INPUT ///< Parallel evaluation of multiple input signals
16};
17
18/**
19 * @enum LogicOperator
20 * @brief Digital operators for boolean computation
21 */
22enum class LogicOperator : uint8_t {
23 AND, ///< Logical AND - true only when all inputs are true
24 OR, ///< Logical OR - true when any input is true
25 XOR, ///< Logical XOR - true when odd number of inputs are true
26 NOT, ///< Logical NOT - inverts the input
27 NAND, ///< Logical NAND - inverted AND operation
28 NOR, ///< Logical NOR - inverted OR operation
29 IMPLIES, ///< Logical implication - false only when A is true and B is false
30 THRESHOLD, ///< Binary quantization - true when input exceeds threshold
31 HYSTERESIS, ///< Threshold with memory - prevents rapid oscillation at boundary
32 EDGE, ///< Transition detector - identifies state changes
33 CUSTOM ///< User-defined boolean function
34};
35
36/**
37 * @enum EdgeType
38 * @brief Digital transition patterns to detect
39 */
40enum class EdgeType : uint8_t {
41 RISING, ///< Low-to-high transition (0→1)
42 FALLING, ///< High-to-low transition (1→0)
43 BOTH ///< Any state transition
44};
45
46/**
47 * @enum LogicEventType
48 * @brief Events that can trigger callbacks
49 */
50enum class LogicEventType : uint8_t {
51 TICK, // Every sample
52 CHANGE, // Any state change
53 TRUE, // Change to true
54 FALSE, // Change to false
55 WHILE_TRUE, // Every tick while true
56 WHILE_FALSE, // Every tick while false
57 CONDITIONAL // Custom condition
58};
59
60class MAYAFLUX_API LogicContext : public NodeContext {
61public:
62 /**
63 * @brief Constructs a LogicContext with complete state information
64 * @param value Current output value (0.0 for false, 1.0 for true)
65 * @param mode Current computational model
66 * @param operator_type Current boolean operator
67 * @param history Buffer of previous boolean states
68 * @param threshold Decision boundary for binary quantization
69 * @param edge_detected Whether a state transition was detected
70 * @param edge_type Type of transition being monitored
71 * @param inputs Current input values for multi-input evaluation
72 */
73 LogicContext(double value,
74 LogicMode mode,
75 LogicOperator operator_type,
76 std::span<bool> history,
77 double threshold,
78 bool edge_detected = false,
79 EdgeType edge_type = EdgeType::BOTH,
80 const std::vector<double>& inputs = {})
81 : NodeContext(value, typeid(LogicContext).name())
82 , m_mode(mode)
83 , m_operator(operator_type)
84 , m_history(history)
85 , m_threshold(threshold)
86 , m_edge_detected(edge_detected)
87 , m_edge_type(edge_type)
88 , m_inputs(inputs)
89 , m_input(value)
90 {
91 }
92
93 // Getters for context properties
94 LogicMode get_mode() const { return m_mode; }
95 LogicOperator get_operator() const { return m_operator; }
96 std::span<bool> get_history() const { return m_history; }
97 double get_threshold() const { return m_threshold; }
98 bool is_edge_detected() const { return m_edge_detected; }
99 EdgeType get_edge_type() const { return m_edge_type; }
100 const std::vector<double>& get_inputs() const { return m_inputs; }
101 const double& get_value() const { return m_input; }
102
103 // Boolean conversion of the current value
104 bool as_bool() const { return get_value() > 0.5; }
105
106private:
107 LogicMode m_mode; ///< Current computational model
108 LogicOperator m_operator; ///< Current boolean operator
109 std::span<bool> m_history; ///< History of boolean states
110 double m_threshold; ///< Decision boundary for binary quantization
111 bool m_edge_detected; ///< Whether a state transition was detected
112 EdgeType m_edge_type; ///< Type of transition being monitored
113 const std::vector<double>& m_inputs; ///< Current input values (for multi-input mode)
114 double m_input; ///< Current input value for multi-input mode
115
116 friend class Logic;
117};
118
119/**
120 * @class LogicContextGpu
121 * @brief GPU-accelerated context for logic node callbacks
122 */
123class MAYAFLUX_API LogicContextGpu
124 : public LogicContext,
125 public GpuVectorData {
126public:
128 double value,
129 LogicMode mode,
130 LogicOperator operator_type,
131 std::span<bool> history,
132 double threshold,
133 bool edge_detected,
134 EdgeType edge_type,
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)
138 , GpuVectorData(gpu_data)
139 {
140 type_id = typeid(LogicContextGpu).name();
141 }
142
143 friend class Logic;
144
145 std::vector<float> gpu_float_buffer;
146};
147
148/**
149 * @class Logic
150 * @brief Digital signal processor implementing boolean logic operations
151 *
152 * The Logic node transforms continuous signals into discrete binary outputs
153 * using configurable boolean operations. It supports multiple computational models:
154 *
155 * - Combinational logic: Stateless evaluation based solely on current inputs
156 * - Sequential logic: State-based evaluation using history of previous inputs
157 * - Temporal logic: Time-dependent evaluation with timing constraints
158 * - Multi-input logic: Parallel evaluation of multiple input signals
159 *
160 * Applications include:
161 * - Binary signal generation
162 * - Event detection and triggering
163 * - State machine implementation
164 * - Digital pattern recognition
165 * - Signal quantization and discretization
166 * - Conditional processing chains
167 */
168class MAYAFLUX_API Logic : public Generator {
169public:
170 /**
171 * @brief Function type for stateless boolean evaluation
172 */
173 using DirectFunction = std::function<bool(double)>;
174
175 /**
176 * @brief Function type for parallel input evaluation
177 */
178 using MultiInputFunction = std::function<bool(const std::vector<double>&)>;
179
180 /**
181 * @brief Function type for state-based evaluation
182 */
183 using SequentialFunction = std::function<bool(std::span<bool>)>;
184
185 /**
186 * @brief Function type for time-dependent evaluation
187 */
188 using TemporalFunction = std::function<bool(double, double)>; // input, time
189
190 /**
191 * @brief Constructs a Logic node with threshold quantization
192 * @param threshold Decision boundary for binary quantization
193 *
194 * Creates a basic binary quantizer that outputs 1.0 when input exceeds
195 * the threshold and 0.0 otherwise.
196 */
197 explicit Logic(double threshold = 0.5);
198
199 /**
200 * @brief Constructs a Logic node with a specific boolean operator
201 * @param op Boolean operator to apply
202 * @param threshold Decision boundary for binary quantization
203 *
204 * Creates a Logic node configured with one of the standard boolean
205 * operations (AND, OR, XOR, etc.) using the specified threshold
206 * for binary quantization of inputs.
207 */
208 Logic(LogicOperator op, double threshold = 0.5);
209
210 /**
211 * @brief Constructs a Logic node with a custom combinational function
212 * @param function Custom function implementing stateless boolean logic
213 *
214 * Creates a Logic node that applies a user-defined function to each input
215 * sample, enabling custom combinational logic operations beyond the
216 * standard operators.
217 */
218 explicit Logic(DirectFunction function);
219
220 /**
221 * @brief Constructs a Logic node for parallel input evaluation
222 * @param function Function implementing multi-input boolean logic
223 * @param input_count Number of parallel inputs to process
224 *
225 * Creates a Logic node that evaluates multiple inputs simultaneously,
226 * enabling implementation of complex decision functions like voting
227 * systems, majority logic, or custom multi-input boolean operations.
228 */
229 Logic(MultiInputFunction function, size_t input_count);
230
231 /**
232 * @brief Constructs a Logic node for state-based evaluation
233 * @param function Function implementing sequential boolean logic
234 * @param history_size Size of the state history buffer
235 *
236 * Creates a Logic node that maintains a history of previous states
237 * and evaluates new inputs in the context of this history. This enables
238 * implementation of sequential logic circuits, pattern detectors,
239 * and finite state machines.
240 */
241 Logic(SequentialFunction function, size_t history_size);
242
243 /**
244 * @brief Constructs a Logic node for time-dependent evaluation
245 * @param function Function implementing temporal boolean logic
246 *
247 * Creates a Logic node that evaluates inputs based on both their value
248 * and the time at which they occur. This enables implementation of
249 * timing-sensitive operations like pulse width detection, timeout
250 * monitoring, and rate-of-change analysis.
251 */
252 explicit Logic(TemporalFunction function);
253
254 virtual ~Logic() = default;
255
256 /**
257 * @brief Processes a single input sample through the logic function
258 * @param input Input value to evaluate
259 * @return 1.0 for true result, 0.0 for false result
260 *
261 * Evaluates the input according to the configured logic operation
262 * and computational model, producing a binary output (0.0 or 1.0).
263 */
264 double process_sample(double input = 0.) override;
265
266 /**
267 * @brief Processes multiple samples in batch mode
268 * @param num_samples Number of samples to generate
269 * @return Vector of binary outputs (1.0 for true, 0.0 for false)
270 *
271 * Generates a sequence of binary values by repeatedly applying
272 * the configured logic operation. In stateful modes, each output
273 * depends on previous results.
274 */
275 std::vector<double> process_batch(unsigned int num_samples) override;
276
277 /**
278 * @brief Processes multiple parallel inputs
279 * @param inputs Vector of input values to evaluate together
280 * @return 1.0 for true result, 0.0 for false result
281 *
282 * Evaluates multiple inputs simultaneously according to the configured
283 * multi-input logic function, producing a single binary output.
284 */
285 double process_multi_input(const std::vector<double>& inputs);
286
287 /**
288 * @brief Resets internal state to initial conditions
289 *
290 * Clears history buffers, resets state variables, and returns
291 * the node to its initial configuration. Essential for restarting
292 * sequential processing or clearing accumulated state.
293 */
294 void reset();
295
296 /**
297 * @brief Sets the decision boundary for binary quantization
298 * @param threshold Value above which input is considered true
299 * @param create_default_direct_function Whether to create a default direct function if none is set
300 *
301 * Configures the threshold used to convert continuous input values
302 * to binary states (true/false). Critical for accurate digital
303 * interpretation of analog-like signals.
304 */
305 void set_threshold(double threshold, bool create_default_direct_function = false);
306
307 /**
308 * @brief Configures noise-resistant binary quantization with memory
309 * @param low_threshold Value below which input becomes false
310 * @param high_threshold Value above which input becomes true
311 * @param create_default_direct_function Whether to create a default direct function if none is set
312 *
313 * Implements a Schmitt trigger with separate thresholds for rising and falling
314 * transitions, preventing rapid oscillation when input hovers near the threshold.
315 * Essential for stable binary quantization of noisy signals.
316 */
317 void set_hysteresis(double low_threshold, double high_threshold, bool create_default_direct_function = false);
318
319 /**
320 * @brief Configures digital transition detection
321 * @param type Type of transition to detect (rising, falling, or both)
322 * @param threshold Decision boundary for state changes
323 *
324 * Sets up the node to detect specific types of state transitions
325 * (edges) in the input signal. Useful for event detection, trigger
326 * generation, and synchronization with external events.
327 */
328 void set_edge_detection(EdgeType type, double threshold = 0.5);
329
330 /**
331 * @brief Sets the boolean operation to perform
332 * @param op Boolean operator to apply
333 * @param create_default_direct_function Whether to create a default direct function if none is set
334 *
335 * Configures the node to use one of the standard boolean operations
336 * (AND, OR, XOR, etc.) for evaluating inputs.
337 */
338 void set_operator(LogicOperator op, bool create_default_direct_function = false);
339
340 /**
341 * @brief Sets a custom combinational logic function
342 * @param function Custom function implementing stateless boolean logic
343 *
344 * Configures the node to use a user-defined function for stateless
345 * evaluation of inputs, enabling custom combinational logic beyond
346 * the standard operators.
347 */
348 void set_direct_function(DirectFunction function);
349
350 /**
351 * @brief Sets a custom parallel input evaluation function
352 * @param function Function implementing multi-input boolean logic
353 * @param input_count Number of parallel inputs to process
354 *
355 * Configures the node to evaluate multiple inputs simultaneously
356 * using a user-defined function, enabling implementation of complex
357 * decision functions like voting systems or custom multi-input operations.
358 */
359 void set_multi_input_function(MultiInputFunction function, size_t input_count);
360
361 /**
362 * @brief Sets a custom state-based evaluation function
363 * @param function Function implementing sequential boolean logic
364 * @param history_size Size of the state history buffer
365 *
366 * Configures the node to maintain a history of previous states and
367 * evaluate new inputs in this context using a user-defined function.
368 * Enables implementation of sequential logic, pattern detectors, and
369 * finite state machines.
370 */
371 void set_sequential_function(SequentialFunction function, size_t history_size);
372
373 /**
374 * @brief Sets a custom time-dependent evaluation function
375 * @param function Function implementing temporal boolean logic
376 *
377 * Configures the node to evaluate inputs based on both their value
378 * and timing using a user-defined function. Enables implementation of
379 * timing-sensitive operations like pulse width detection and rate analysis.
380 */
381 void set_temporal_function(TemporalFunction function);
382
383 /**
384 * @brief Preloads the state history buffer
385 * @param initial_values Vector of initial boolean states
386 *
387 * Initializes the history buffer with specified values, allowing
388 * sequential logic to begin operation with a predefined state sequence.
389 * Useful for testing specific patterns or starting from known states.
390 */
391 void set_initial_conditions(const std::vector<bool>& initial_values);
392
393 /**
394 * @brief Sets the input node to generate logic values from
395 * @param input_node Node providing the input values
396 *
397 * Configures the node to receive input from another node
398 */
399 inline void set_input_node(const std::shared_ptr<Node>& input_node) { m_input_node = input_node; }
400
401 /**
402 * @brief Gets the current computational model
403 * @return Current logic mode
404 */
405 LogicMode get_mode() const { return m_mode; }
406
407 /**
408 * @brief Gets the current boolean operator
409 * @return Current logic operator
410 */
411 LogicOperator get_operator() const { return m_operator; }
412
413 /**
414 * @brief Gets the decision boundary for binary quantization
415 * @return Current threshold value
416 */
417 double get_threshold() const { return m_threshold; }
418
419 /**
420 * @brief Gets the state history buffer capacity
421 * @return Current history buffer size
422 */
423 size_t get_history_size() const { return m_history_size; }
424
425 /**
426 * @brief Gets the current state history
427 * @return Reference to the history buffer
428 */
429 std::span<bool> get_history();
430
431 /**
432 * @brief Gets the number of parallel inputs expected
433 * @return Number of expected inputs
434 */
435 size_t get_input_count() const { return m_input_count; }
436
437 /**
438 * @brief Checks if a state transition was detected
439 * @return True if a transition matching the configured edge type was detected
440 */
441 bool was_edge_detected() const { return m_edge_detected; }
442
443 /**
444 * @brief Gets the type of transitions being monitored
445 * @return Current edge detection type
446 */
447 EdgeType get_edge_type() const { return m_edge_type; }
448
449 /**
450 * @brief Prints a visual representation of the logic function
451 */
452 inline void printGraph() override { }
453
454 /**
455 * @brief Prints the current state and parameters
456 */
457 inline void printCurrent() override { }
458
459 /**
460 * @brief Registers a callback for every generated sample
461 * @param callback Function to call when a new sample is generated
462 */
463 void on_tick(const NodeHook& callback) override;
464
465 /**
466 * @brief Registers a conditional callback for generated samples
467 * @param callback Function to call when condition is met
468 * @param condition Predicate that determines when callback is triggered
469 */
470 void on_tick_if(const NodeCondition& condition, const NodeHook& callback) override;
471
472 /**
473 * @brief Registers a callback that executes continuously while output is true
474 * @param callback Function to call on each tick when output is true (1.0)
475 */
476 void while_true(const NodeHook& callback);
477
478 /**
479 * @brief Registers a callback that executes continuously while output is false
480 * @param callback Function to call on each tick when output is false (0.0)
481 */
482 void while_false(const NodeHook& callback);
483
484 /**
485 * @brief Registers a callback for when output changes to a specific state
486 * @param target_state The state to detect (true for 1.0, false for 0.0)
487 * @param callback Function to call when state changes to target_state
488 */
489 void on_change_to(bool target_state, const NodeHook& callback);
490
491 /**
492 * @brief Registers a callback for any state change (true↔false)
493 * @param callback Function to call when output changes state
494 */
495 void on_change(const NodeHook& callback);
496
497 /**
498 * @brief Removes a previously registered callback
499 * @param callback The callback function to remove
500 * @return True if the callback was found and removed, false otherwise
501 */
502 bool remove_hook(const NodeHook& callback) override;
503
504 /**
505 * @brief Removes a previously registered conditional callback
506 * @param callback The condition function to remove
507 * @return True if the callback was found and removed, false otherwise
508 */
509 bool remove_conditional_hook(const NodeCondition& callback) override;
510
511 /**
512 * @brief Removes all registered callbacks
513 *
514 * Clears all standard and conditional callbacks, effectively
515 * disconnecting all external components from this oscillator's
516 * notification system. Useful when reconfiguring the processing
517 * graph or shutting down components.
518 */
519 inline void remove_all_hooks() override
520 {
521 m_all_callbacks.clear();
522 }
523
524 void remove_hooks_of_type(LogicEventType type);
525
529 std::optional<NodeCondition> condition; // Only used for CONDITIONAL type
530
531 LogicCallback(const NodeHook& cb, LogicEventType type, std::optional<NodeCondition> cond = std::nullopt)
532 : callback(cb)
533 , event_type(type)
534 , condition(std::move(cond))
535 {
536 }
537 };
538
539 void save_state() override;
540 void restore_state() override;
541
542 /**
543 * @brief Retrieves the last created context object
544 * @return Reference to the last LogicContext object
545 *
546 * This method provides access to the most recent LogicContext object
547 * created by the logic node. This context contains information about
548 * the node's state at the time of the last output generation.
549 */
550 NodeContext& get_last_context() override;
551
552 void set_gpu_compatible(bool compatible) override
553 {
554 m_gpu_compatible = compatible;
555 if (compatible) {
556 m_node_capability |= NodeCapability::VECTOR;
557 } else {
558 m_node_capability &= ~NodeCapability::VECTOR;
559 }
560 }
561
562protected:
563 /**
564 * @brief Updates the context with the latest sample value
565 * @param value The current generated sample
566 */
567 void update_context(double value) override;
568
569 /**
570 * @brief Notifies all registered callbacks about a new sample
571 * @param value The newly generated sample
572 *
573 * This method is called internally whenever a new sample is generated,
574 * creating the appropriate context and invoking all registered callbacks
575 * that should receive notification about this sample.
576 */
577 void notify_tick(double value) override;
578
579private:
580 LogicMode m_mode; ///< Current processing mode
581 LogicOperator m_operator; ///< Current logic operator
582 DirectFunction m_direct_function; ///< Function for direct mode
583 MultiInputFunction m_multi_input_function; ///< Function for recursive/feedforward mode
584 SequentialFunction m_sequential_function; ///< Function for sequential mode
585 TemporalFunction m_temporal_function; ///< Function for temporal mode
586 size_t m_history_head {}; ///< Head index for the history ring buffer
587 size_t m_history_count {}; ///< Number of valid entries in the history buffer
588 size_t m_history_size; ///< Maximum size of the history buffer
589 size_t m_input_count; ///< Expected number of inputs for multi-input mode
590 double m_threshold; ///< Threshold for boolean conversion
591 double m_low_threshold; ///< Low threshold for hysteresis
592 double m_high_threshold; ///< High threshold for hysteresis
593 EdgeType m_edge_type; ///< Type of edge to detect
594 bool m_edge_detected {}; ///< Whether an edge was detected in the last processing
595 bool m_hysteresis_state {}; ///< State for hysteresis operator
596 double m_temporal_time {}; ///< Time tracking for temporal mode
597 double m_input {}; ///< Current input value for multi-input mode
598 std::vector<double> m_input_buffer; // Buffer for multi-input mode
599 std::shared_ptr<Node> m_input_node; ///< Input node for processing
600 std::vector<uint8_t> m_history_ring; ///< Ring buffer for history storage
601 std::vector<uint8_t> m_history_linear; ///< Linear view of history for easy access
602
603 // Helper method for multi-input mode
604 void add_input(double input, size_t index);
605
606 /**
607 * @brief Adds a callback to the list of all callbacks
608 * @param callback The callback function to add
609 * @param type The type of event to trigger the callback
610 * @param condition Optional condition for conditional callbacks
611 */
612 void add_callback(const NodeHook& callback, LogicEventType type, const std::optional<NodeCondition>& condition = std::nullopt)
613 {
614 m_all_callbacks.emplace_back(callback, type, condition);
615 }
616
617 void history_push(bool val);
618
619 std::span<bool> history_linearized_view();
620
621 std::span<double> external_context_view(double input);
622
623 /**
624 * @brief Collection of all callback functions
625 *
626 * Stores the registered callback functions that will be notified
627 * whenever the oscillator produces a new sample. These callbacks
628 * enable external components to monitor and react to the oscillator's
629 * output without interrupting the generation process.
630 */
631 std::vector<LogicCallback> m_all_callbacks;
632
633 std::vector<uint8_t> m_saved_history_ring;
634 size_t m_saved_history_head {};
635 size_t m_saved_history_count {};
636
637 bool m_saved_hysteresis_state {};
638 bool m_saved_edge_detected {};
639 double m_saved_temporal_time {};
640 double m_saved_last_output {};
643};
644
645} // namespace MayaFlux::Nodes::Generator
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)
Definition Logic.hpp:127
GPU-accelerated context for logic node callbacks.
Definition Logic.hpp:125
std::span< bool > get_history() const
Definition Logic.hpp:96
std::span< bool > m_history
History of boolean states.
Definition Logic.hpp:109
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.
Definition Logic.hpp:73
LogicMode m_mode
Current computational model.
Definition Logic.hpp:107
LogicOperator m_operator
Current boolean operator.
Definition Logic.hpp:108
const std::vector< double > & m_inputs
Current input values (for multi-input mode)
Definition Logic.hpp:113
double m_input
Current input value for multi-input mode.
Definition Logic.hpp:114
const std::vector< double > & get_inputs() const
Definition Logic.hpp:100
EdgeType m_edge_type
Type of transition being monitored.
Definition Logic.hpp:112
bool m_edge_detected
Whether a state transition was detected.
Definition Logic.hpp:111
const double & get_value() const
Definition Logic.hpp:101
LogicOperator get_operator() const
Definition Logic.hpp:95
double m_threshold
Decision boundary for binary quantization.
Definition Logic.hpp:110
SequentialFunction m_sequential_function
Function for sequential mode.
Definition Logic.hpp:584
TemporalFunction m_temporal_function
Function for temporal mode.
Definition Logic.hpp:585
std::vector< uint8_t > m_saved_history_ring
Definition Logic.hpp:633
DirectFunction m_direct_function
Function for direct mode.
Definition Logic.hpp:582
bool was_edge_detected() const
Checks if a state transition was detected.
Definition Logic.hpp:441
std::vector< uint8_t > m_history_linear
Linear view of history for easy access.
Definition Logic.hpp:601
size_t m_history_size
Maximum size of the history buffer.
Definition Logic.hpp:588
EdgeType m_edge_type
Type of edge to detect.
Definition Logic.hpp:593
void set_input_node(const std::shared_ptr< Node > &input_node)
Sets the input node to generate logic values from.
Definition Logic.hpp:399
double m_threshold
Threshold for boolean conversion.
Definition Logic.hpp:590
std::function< bool(double)> DirectFunction
Function type for stateless boolean evaluation.
Definition Logic.hpp:173
double m_high_threshold
High threshold for hysteresis.
Definition Logic.hpp:592
std::vector< double > m_input_buffer
Definition Logic.hpp:598
std::shared_ptr< Node > m_input_node
Input node for processing.
Definition Logic.hpp:599
LogicMode get_mode() const
Gets the current computational model.
Definition Logic.hpp:405
std::span< double > external_context_view(double input)
LogicOperator m_operator
Current logic operator.
Definition Logic.hpp:581
void printGraph() override
Prints a visual representation of the logic function.
Definition Logic.hpp:452
std::function< bool(const std::vector< double > &)> MultiInputFunction
Function type for parallel input evaluation.
Definition Logic.hpp:178
void add_callback(const NodeHook &callback, LogicEventType type, const std::optional< NodeCondition > &condition=std::nullopt)
Adds a callback to the list of all callbacks.
Definition Logic.hpp:612
double m_low_threshold
Low threshold for hysteresis.
Definition Logic.hpp:591
MultiInputFunction m_multi_input_function
Function for recursive/feedforward mode.
Definition Logic.hpp:583
std::function< bool(std::span< bool >)> SequentialFunction
Function type for state-based evaluation.
Definition Logic.hpp:183
std::vector< LogicCallback > m_all_callbacks
Collection of all callback functions.
Definition Logic.hpp:631
void printCurrent() override
Prints the current state and parameters.
Definition Logic.hpp:457
std::vector< uint8_t > m_history_ring
Ring buffer for history storage.
Definition Logic.hpp:600
void remove_all_hooks() override
Removes all registered callbacks.
Definition Logic.hpp:519
double get_threshold() const
Gets the decision boundary for binary quantization.
Definition Logic.hpp:417
EdgeType get_edge_type() const
Gets the type of transitions being monitored.
Definition Logic.hpp:447
size_t get_input_count() const
Gets the number of parallel inputs expected.
Definition Logic.hpp:435
void set_gpu_compatible(bool compatible) override
Sets whether the node is compatible with GPU processing.
Definition Logic.hpp:552
LogicOperator get_operator() const
Gets the current boolean operator.
Definition Logic.hpp:411
LogicMode m_mode
Current processing mode.
Definition Logic.hpp:580
std::function< bool(double, double)> TemporalFunction
Function type for time-dependent evaluation.
Definition Logic.hpp:188
size_t get_history_size() const
Gets the state history buffer capacity.
Definition Logic.hpp:423
size_t m_input_count
Expected number of inputs for multi-input mode.
Definition Logic.hpp:589
Digital signal processor implementing boolean logic operations.
Definition Logic.hpp:168
GPU-uploadable 1D array data interface.
Base context class for node callbacks.
Definition Node.hpp:30
EdgeType
Digital transition patterns to detect.
Definition Logic.hpp:40
@ FALLING
High-to-low transition (1→0)
@ RISING
Low-to-high transition (0→1)
LogicMode
Defines the computational model for digital signal evaluation.
Definition Logic.hpp:11
@ 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.
Definition Logic.hpp:50
LogicOperator
Digital operators for boolean computation.
Definition Logic.hpp:22
@ 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.
Definition NodeUtils.hpp:25
NodeCapability
Bitmask flags declaring what data shapes a node's context can produce.
Definition NodeSpec.hpp:104
std::function< bool(NodeContext &)> NodeCondition
Predicate function type for conditional callbacks.
Definition NodeUtils.hpp:43
LogicCallback(const NodeHook &cb, LogicEventType type, std::optional< NodeCondition > cond=std::nullopt)
Definition Logic.hpp:531
std::optional< NodeCondition > condition
Definition Logic.hpp:529