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