MayaFlux 0.1.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 const std::deque<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 const std::deque<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::deque<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 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
117/**
118 * @class LogicContextGpu
119 * @brief GPU-accelerated context for logic node callbacks
120 */
121class MAYAFLUX_API LogicContextGpu
122 : public LogicContext,
123 public GpuVectorData {
124public:
126 double value,
127 LogicMode mode,
128 LogicOperator operator_type,
129 const std::deque<bool>& history,
130 double threshold,
131 bool edge_detected,
132 EdgeType edge_type,
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)
136 , GpuVectorData(gpu_data)
137 {
138 type_id = typeid(LogicContextGpu).name();
139 }
140};
141
142/**
143 * @class Logic
144 * @brief Digital signal processor implementing boolean logic operations
145 *
146 * The Logic node transforms continuous signals into discrete binary outputs
147 * using configurable boolean operations. It supports multiple computational models:
148 *
149 * - Combinational logic: Stateless evaluation based solely on current inputs
150 * - Sequential logic: State-based evaluation using history of previous inputs
151 * - Temporal logic: Time-dependent evaluation with timing constraints
152 * - Multi-input logic: Parallel evaluation of multiple input signals
153 *
154 * Applications include:
155 * - Binary signal generation
156 * - Event detection and triggering
157 * - State machine implementation
158 * - Digital pattern recognition
159 * - Signal quantization and discretization
160 * - Conditional processing chains
161 */
162class MAYAFLUX_API Logic : public Generator {
163public:
164 /**
165 * @brief Function type for stateless boolean evaluation
166 */
167 using DirectFunction = std::function<bool(double)>;
168
169 /**
170 * @brief Function type for parallel input evaluation
171 */
172 using MultiInputFunction = std::function<bool(const std::vector<double>&)>;
173
174 /**
175 * @brief Function type for state-based evaluation
176 */
177 using SequentialFunction = std::function<bool(const std::deque<bool>&)>;
178
179 /**
180 * @brief Function type for time-dependent evaluation
181 */
182 using TemporalFunction = std::function<bool(double, double)>; // input, time
183
184 /**
185 * @brief Constructs a Logic node with threshold quantization
186 * @param threshold Decision boundary for binary quantization
187 *
188 * Creates a basic binary quantizer that outputs 1.0 when input exceeds
189 * the threshold and 0.0 otherwise.
190 */
191 explicit Logic(double threshold = 0.5);
192
193 /**
194 * @brief Constructs a Logic node with a specific boolean operator
195 * @param op Boolean operator to apply
196 * @param threshold Decision boundary for binary quantization
197 *
198 * Creates a Logic node configured with one of the standard boolean
199 * operations (AND, OR, XOR, etc.) using the specified threshold
200 * for binary quantization of inputs.
201 */
202 Logic(LogicOperator op, double threshold = 0.5);
203
204 /**
205 * @brief Constructs a Logic node with a custom combinational function
206 * @param function Custom function implementing stateless boolean logic
207 *
208 * Creates a Logic node that applies a user-defined function to each input
209 * sample, enabling custom combinational logic operations beyond the
210 * standard operators.
211 */
212 explicit Logic(DirectFunction function);
213
214 /**
215 * @brief Constructs a Logic node for parallel input evaluation
216 * @param function Function implementing multi-input boolean logic
217 * @param input_count Number of parallel inputs to process
218 *
219 * Creates a Logic node that evaluates multiple inputs simultaneously,
220 * enabling implementation of complex decision functions like voting
221 * systems, majority logic, or custom multi-input boolean operations.
222 */
223 Logic(MultiInputFunction function, size_t input_count);
224
225 /**
226 * @brief Constructs a Logic node for state-based evaluation
227 * @param function Function implementing sequential boolean logic
228 * @param history_size Size of the state history buffer
229 *
230 * Creates a Logic node that maintains a history of previous states
231 * and evaluates new inputs in the context of this history. This enables
232 * implementation of sequential logic circuits, pattern detectors,
233 * and finite state machines.
234 */
235 Logic(SequentialFunction function, size_t history_size);
236
237 /**
238 * @brief Constructs a Logic node for time-dependent evaluation
239 * @param function Function implementing temporal boolean logic
240 *
241 * Creates a Logic node that evaluates inputs based on both their value
242 * and the time at which they occur. This enables implementation of
243 * timing-sensitive operations like pulse width detection, timeout
244 * monitoring, and rate-of-change analysis.
245 */
246 explicit Logic(TemporalFunction function);
247
248 virtual ~Logic() = default;
249
250 /**
251 * @brief Processes a single input sample through the logic function
252 * @param input Input value to evaluate
253 * @return 1.0 for true result, 0.0 for false result
254 *
255 * Evaluates the input according to the configured logic operation
256 * and computational model, producing a binary output (0.0 or 1.0).
257 */
258 double process_sample(double input = 0.) override;
259
260 /**
261 * @brief Processes multiple samples in batch mode
262 * @param num_samples Number of samples to generate
263 * @return Vector of binary outputs (1.0 for true, 0.0 for false)
264 *
265 * Generates a sequence of binary values by repeatedly applying
266 * the configured logic operation. In stateful modes, each output
267 * depends on previous results.
268 */
269 std::vector<double> process_batch(unsigned int num_samples) override;
270
271 /**
272 * @brief Processes multiple parallel inputs
273 * @param inputs Vector of input values to evaluate together
274 * @return 1.0 for true result, 0.0 for false result
275 *
276 * Evaluates multiple inputs simultaneously according to the configured
277 * multi-input logic function, producing a single binary output.
278 */
279 double process_multi_input(const std::vector<double>& inputs);
280
281 /**
282 * @brief Resets internal state to initial conditions
283 *
284 * Clears history buffers, resets state variables, and returns
285 * the node to its initial configuration. Essential for restarting
286 * sequential processing or clearing accumulated state.
287 */
288 void reset();
289
290 /**
291 * @brief Sets the decision boundary for binary quantization
292 * @param threshold Value above which input is considered true
293 * @param create_default_direct_function Whether to create a default direct function if none is set
294 *
295 * Configures the threshold used to convert continuous input values
296 * to binary states (true/false). Critical for accurate digital
297 * interpretation of analog-like signals.
298 */
299 void set_threshold(double threshold, bool create_default_direct_function = false);
300
301 /**
302 * @brief Configures noise-resistant binary quantization with memory
303 * @param low_threshold Value below which input becomes false
304 * @param high_threshold Value above which input becomes true
305 * @param create_default_direct_function Whether to create a default direct function if none is set
306 *
307 * Implements a Schmitt trigger with separate thresholds for rising and falling
308 * transitions, preventing rapid oscillation when input hovers near the threshold.
309 * Essential for stable binary quantization of noisy signals.
310 */
311 void set_hysteresis(double low_threshold, double high_threshold, bool create_default_direct_function = false);
312
313 /**
314 * @brief Configures digital transition detection
315 * @param type Type of transition to detect (rising, falling, or both)
316 * @param threshold Decision boundary for state changes
317 *
318 * Sets up the node to detect specific types of state transitions
319 * (edges) in the input signal. Useful for event detection, trigger
320 * generation, and synchronization with external events.
321 */
322 void set_edge_detection(EdgeType type, double threshold = 0.5);
323
324 /**
325 * @brief Sets the boolean operation to perform
326 * @param op Boolean operator to apply
327 * @param create_default_direct_function Whether to create a default direct function if none is set
328 *
329 * Configures the node to use one of the standard boolean operations
330 * (AND, OR, XOR, etc.) for evaluating inputs.
331 */
332 void set_operator(LogicOperator op, bool create_default_direct_function = false);
333
334 /**
335 * @brief Sets a custom combinational logic function
336 * @param function Custom function implementing stateless boolean logic
337 *
338 * Configures the node to use a user-defined function for stateless
339 * evaluation of inputs, enabling custom combinational logic beyond
340 * the standard operators.
341 */
342 void set_direct_function(DirectFunction function);
343
344 /**
345 * @brief Sets a custom parallel input evaluation function
346 * @param function Function implementing multi-input boolean logic
347 * @param input_count Number of parallel inputs to process
348 *
349 * Configures the node to evaluate multiple inputs simultaneously
350 * using a user-defined function, enabling implementation of complex
351 * decision functions like voting systems or custom multi-input operations.
352 */
353 void set_multi_input_function(MultiInputFunction function, size_t input_count);
354
355 /**
356 * @brief Sets a custom state-based evaluation function
357 * @param function Function implementing sequential boolean logic
358 * @param history_size Size of the state history buffer
359 *
360 * Configures the node to maintain a history of previous states and
361 * evaluate new inputs in this context using a user-defined function.
362 * Enables implementation of sequential logic, pattern detectors, and
363 * finite state machines.
364 */
365 void set_sequential_function(SequentialFunction function, size_t history_size);
366
367 /**
368 * @brief Sets a custom time-dependent evaluation function
369 * @param function Function implementing temporal boolean logic
370 *
371 * Configures the node to evaluate inputs based on both their value
372 * and timing using a user-defined function. Enables implementation of
373 * timing-sensitive operations like pulse width detection and rate analysis.
374 */
375 void set_temporal_function(TemporalFunction function);
376
377 /**
378 * @brief Preloads the state history buffer
379 * @param initial_values Vector of initial boolean states
380 *
381 * Initializes the history buffer with specified values, allowing
382 * sequential logic to begin operation with a predefined state sequence.
383 * Useful for testing specific patterns or starting from known states.
384 */
385 void set_initial_conditions(const std::vector<bool>& initial_values);
386
387 /**
388 * @brief Sets the input node to generate logic values from
389 * @param input_node Node providing the input values
390 *
391 * Configures the node to receive input from another node
392 */
393 inline void set_input_node(const std::shared_ptr<Node>& input_node) { m_input_node = input_node; }
394
395 /**
396 * @brief Gets the current computational model
397 * @return Current logic mode
398 */
399 LogicMode get_mode() const { return m_mode; }
400
401 /**
402 * @brief Gets the current boolean operator
403 * @return Current logic operator
404 */
405 LogicOperator get_operator() const { return m_operator; }
406
407 /**
408 * @brief Gets the decision boundary for binary quantization
409 * @return Current threshold value
410 */
411 double get_threshold() const { return m_threshold; }
412
413 /**
414 * @brief Gets the state history buffer capacity
415 * @return Current history buffer size
416 */
417 size_t get_history_size() const { return m_history_size; }
418
419 /**
420 * @brief Gets the current state history
421 * @return Reference to the history buffer
422 */
423 const std::deque<bool>& get_history() const { return m_history; }
424
425 /**
426 * @brief Gets the number of parallel inputs expected
427 * @return Number of expected inputs
428 */
429 size_t get_input_count() const { return m_input_count; }
430
431 /**
432 * @brief Checks if a state transition was detected
433 * @return True if a transition matching the configured edge type was detected
434 */
435 bool was_edge_detected() const { return m_edge_detected; }
436
437 /**
438 * @brief Gets the type of transitions being monitored
439 * @return Current edge detection type
440 */
441 EdgeType get_edge_type() const { return m_edge_type; }
442
443 /**
444 * @brief Prints a visual representation of the logic function
445 */
446 inline void printGraph() override { }
447
448 /**
449 * @brief Prints the current state and parameters
450 */
451 inline void printCurrent() override { }
452
453 /**
454 * @brief Registers a callback for every generated sample
455 * @param callback Function to call when a new sample is generated
456 */
457 void on_tick(const NodeHook& callback) override;
458
459 /**
460 * @brief Registers a conditional callback for generated samples
461 * @param callback Function to call when condition is met
462 * @param condition Predicate that determines when callback is triggered
463 */
464 void on_tick_if(const NodeHook& callback, const NodeCondition& condition) override;
465
466 /**
467 * @brief Registers a callback that executes continuously while output is true
468 * @param callback Function to call on each tick when output is true (1.0)
469 */
470 void while_true(const NodeHook& callback);
471
472 /**
473 * @brief Registers a callback that executes continuously while output is false
474 * @param callback Function to call on each tick when output is false (0.0)
475 */
476 void while_false(const NodeHook& callback);
477
478 /**
479 * @brief Registers a callback for when output changes to a specific state
480 * @param callback Function to call when state changes to target_state
481 * @param target_state The state to detect (true for 1.0, false for 0.0)
482 */
483 void on_change_to(const NodeHook& callback, bool target_state);
484
485 /**
486 * @brief Registers a callback for any state change (true↔false)
487 * @param callback Function to call when output changes state
488 */
489 void on_change(const NodeHook& callback);
490
491 /**
492 * @brief Removes a previously registered callback
493 * @param callback The callback function to remove
494 * @return True if the callback was found and removed, false otherwise
495 */
496 bool remove_hook(const NodeHook& callback) override;
497
498 /**
499 * @brief Removes a previously registered conditional callback
500 * @param callback The condition function to remove
501 * @return True if the callback was found and removed, false otherwise
502 */
503 bool remove_conditional_hook(const NodeCondition& callback) override;
504
505 /**
506 * @brief Removes all registered callbacks
507 *
508 * Clears all standard and conditional callbacks, effectively
509 * disconnecting all external components from this oscillator's
510 * notification system. Useful when reconfiguring the processing
511 * graph or shutting down components.
512 */
513 inline void remove_all_hooks() override
514 {
515 m_all_callbacks.clear();
516 }
517
518 void remove_hooks_of_type(LogicEventType type);
519
523 std::optional<NodeCondition> condition; // Only used for CONDITIONAL type
524
525 LogicCallback(const NodeHook& cb, LogicEventType type, std::optional<NodeCondition> cond = std::nullopt)
526 : callback(cb)
527 , event_type(type)
528 , condition(std::move(cond))
529 {
530 }
531 };
532
533 void save_state() override;
534 void restore_state() override;
535
536protected:
537 /**
538 * @brief Creates a context object for callbacks
539 * @param value The current generated sample
540 * @return A unique pointer to a GeneratorContext object
541 *
542 * This method creates a specialized context object containing
543 * the current sample value and all oscillator parameters, providing
544 * callbacks with rich information about the oscillator's state.
545 */
546 std::unique_ptr<NodeContext> create_context(double value) override;
547
548 /**
549 * @brief Notifies all registered callbacks about a new sample
550 * @param value The newly generated sample
551 *
552 * This method is called internally whenever a new sample is generated,
553 * creating the appropriate context and invoking all registered callbacks
554 * that should receive notification about this sample.
555 */
556 void notify_tick(double value) override;
557
558private:
559 LogicMode m_mode; ///< Current processing mode
560 LogicOperator m_operator; ///< Current logic operator
561 DirectFunction m_direct_function; ///< Function for direct mode
562 MultiInputFunction m_multi_input_function; ///< Function for recursive/feedforward mode
563 SequentialFunction m_sequential_function; ///< Function for sequential mode
564 TemporalFunction m_temporal_function; ///< Function for temporal mode
565 std::deque<bool> m_history; ///< Buffer of input values for feedforward mode
566 size_t m_history_size; ///< Maximum size of the history buffer
567 size_t m_input_count; ///< Expected number of inputs for multi-input mode
568 double m_threshold; ///< Threshold for boolean conversion
569 double m_low_threshold; ///< Low threshold for hysteresis
570 double m_high_threshold; ///< High threshold for hysteresis
571 EdgeType m_edge_type; ///< Type of edge to detect
572 bool m_edge_detected; ///< Whether an edge was detected in the last processing
573 bool m_hysteresis_state; ///< State for hysteresis operator
574 double m_temporal_time; ///< Time tracking for temporal mode
575 std::vector<double> m_input_buffer; // Buffer for multi-input mode
576 double m_input {}; ///< Current input value for multi-input mode
577 std::shared_ptr<Node> m_input_node; ///< Input node for processing
578
579 // Helper method for multi-input mode
580 void add_input(double input, size_t index);
581
582 /**
583 * @brief Adds a callback to the list of all callbacks
584 * @param callback The callback function to add
585 * @param type The type of event to trigger the callback
586 * @param condition Optional condition for conditional callbacks
587 */
588 void add_callback(const NodeHook& callback, LogicEventType type, const std::optional<NodeCondition>& condition = std::nullopt)
589 {
590 m_all_callbacks.emplace_back(callback, type, condition);
591 }
592
593 /**
594 * @brief Collection of all callback functions
595 *
596 * Stores the registered callback functions that will be notified
597 * whenever the oscillator produces a new sample. These callbacks
598 * enable external components to monitor and react to the oscillator's
599 * output without interrupting the generation process.
600 */
601 std::vector<LogicCallback> m_all_callbacks;
602
603 std::deque<bool> m_saved_history;
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 {};
609};
610
611} // namespace MayaFlux::Nodes::Generator
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)
Definition Logic.hpp:125
GPU-accelerated context for logic node callbacks.
Definition Logic.hpp:123
std::deque< bool > m_history
History of boolean states.
Definition Logic.hpp:109
const std::deque< bool > & get_history() const
Definition Logic.hpp:96
LogicMode m_mode
Current computational model.
Definition Logic.hpp:107
LogicOperator m_operator
Current boolean operator.
Definition Logic.hpp:108
std::vector< double > m_inputs
Current input values (for multi-input mode)
Definition Logic.hpp:113
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.
Definition Logic.hpp:73
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:563
TemporalFunction m_temporal_function
Function for temporal mode.
Definition Logic.hpp:564
DirectFunction m_direct_function
Function for direct mode.
Definition Logic.hpp:561
bool was_edge_detected() const
Checks if a state transition was detected.
Definition Logic.hpp:435
size_t m_history_size
Maximum size of the history buffer.
Definition Logic.hpp:566
EdgeType m_edge_type
Type of edge to detect.
Definition Logic.hpp:571
void set_input_node(const std::shared_ptr< Node > &input_node)
Sets the input node to generate logic values from.
Definition Logic.hpp:393
double m_threshold
Threshold for boolean conversion.
Definition Logic.hpp:568
std::deque< bool > m_history
Buffer of input values for feedforward mode.
Definition Logic.hpp:565
std::function< bool(double)> DirectFunction
Function type for stateless boolean evaluation.
Definition Logic.hpp:167
double m_temporal_time
Time tracking for temporal mode.
Definition Logic.hpp:574
double m_high_threshold
High threshold for hysteresis.
Definition Logic.hpp:570
std::function< bool(const std::deque< bool > &)> SequentialFunction
Function type for state-based evaluation.
Definition Logic.hpp:177
std::vector< double > m_input_buffer
Definition Logic.hpp:575
std::shared_ptr< Node > m_input_node
Input node for processing.
Definition Logic.hpp:577
LogicMode get_mode() const
Gets the current computational model.
Definition Logic.hpp:399
LogicOperator m_operator
Current logic operator.
Definition Logic.hpp:560
void printGraph() override
Prints a visual representation of the logic function.
Definition Logic.hpp:446
std::function< bool(const std::vector< double > &)> MultiInputFunction
Function type for parallel input evaluation.
Definition Logic.hpp:172
const std::deque< bool > & get_history() const
Gets the current state history.
Definition Logic.hpp:423
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:588
double m_low_threshold
Low threshold for hysteresis.
Definition Logic.hpp:569
MultiInputFunction m_multi_input_function
Function for recursive/feedforward mode.
Definition Logic.hpp:562
std::deque< bool > m_saved_history
Definition Logic.hpp:603
bool m_edge_detected
Whether an edge was detected in the last processing.
Definition Logic.hpp:572
std::vector< LogicCallback > m_all_callbacks
Collection of all callback functions.
Definition Logic.hpp:601
void printCurrent() override
Prints the current state and parameters.
Definition Logic.hpp:451
bool m_hysteresis_state
State for hysteresis operator.
Definition Logic.hpp:573
void remove_all_hooks() override
Removes all registered callbacks.
Definition Logic.hpp:513
double get_threshold() const
Gets the decision boundary for binary quantization.
Definition Logic.hpp:411
EdgeType get_edge_type() const
Gets the type of transitions being monitored.
Definition Logic.hpp:441
size_t get_input_count() const
Gets the number of parallel inputs expected.
Definition Logic.hpp:429
LogicOperator get_operator() const
Gets the current boolean operator.
Definition Logic.hpp:405
LogicMode m_mode
Current processing mode.
Definition Logic.hpp:559
std::function< bool(double, double)> TemporalFunction
Function type for time-dependent evaluation.
Definition Logic.hpp:182
size_t get_history_size() const
Gets the state history buffer capacity.
Definition Logic.hpp:417
size_t m_input_count
Expected number of inputs for multi-input mode.
Definition Logic.hpp:567
Digital signal processor implementing boolean logic operations.
Definition Logic.hpp:162
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
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:525
std::optional< NodeCondition > condition
Definition Logic.hpp:523