MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ process_sample()

double MayaFlux::Nodes::Generator::Logic::process_sample ( double  input = 0.)
overridevirtual

Processes a single input sample through the logic function.

Parameters
inputInput value to evaluate
Returns
1.0 for true result, 0.0 for false result

Evaluates the input according to the configured logic operation and computational model, producing a binary output (0.0 or 1.0).

Implements MayaFlux::Nodes::Node.

Definition at line 195 of file Logic.cpp.

196{
197 bool result = false;
198 m_edge_detected = false;
199
200 if (m_input_node) {
201 atomic_inc_modulator_count(m_input_node->m_modulator_count, 1);
202 uint32_t state = m_input_node->m_state.load();
203 if (state & NodeState::PROCESSED) {
204 input += m_input_node->get_last_output();
205 } else {
206 input = m_input_node->process_sample(input);
208 }
209 }
210
211 const bool pulled = m_mode == LogicMode::MULTI_INPUT && !m_input_nodes.empty();
212 if (pulled) {
214 }
215
216 bool current_bool = input > m_threshold;
217 bool previous_bool = m_last_output > 0.5;
218
219 switch (m_mode) {
221 switch (m_operator) {
223 result = current_bool;
224 break;
225
227 if (input > m_high_threshold) {
228 m_hysteresis_state = true;
229 } else if (input < m_low_threshold) {
230 m_hysteresis_state = false;
231 }
232 result = m_hysteresis_state;
233 break;
234
235 case LogicOperator::EDGE: {
236 bool previous_bool_input = m_input > m_threshold;
237 if (current_bool != previous_bool_input) {
238 switch (m_edge_type) {
239 case EdgeType::RISING:
240 m_edge_detected = current_bool && !previous_bool_input;
241 break;
243 m_edge_detected = !current_bool && previous_bool_input;
244 break;
245 case EdgeType::BOTH:
246 m_edge_detected = true;
247 break;
248 }
249 }
250 result = m_edge_detected;
251 break;
252 }
253
255 result = current_bool && previous_bool;
256 break;
257
259 result = current_bool || previous_bool;
260 break;
261
263 result = current_bool != previous_bool;
264 break;
265
267 result = !current_bool;
268 break;
269
271 result = !(current_bool && previous_bool);
272 break;
273
275 result = !(current_bool || previous_bool);
276 break;
277
279 result = m_direct_function(input);
280 break;
281
282 default:
283 result = current_bool;
284 }
285 break;
286
288 bool current_bool = input > m_threshold;
289 history_push(current_bool);
290 auto view = history_linearized_view();
291 result = m_sequential_function(view);
292 break;
293 }
294
295 case LogicMode::TEMPORAL: {
298 break;
299 }
300
302 if (!pulled) {
303 add_input(input, 0);
304 } else if (m_input_count > m_input_nodes.size()) {
306 }
308 break;
309 }
310 }
311
312 m_input = input;
313 auto current = result ? 1.0 : 0.0;
314
316 && !m_networked_node) {
318 }
319
320 if (pulled) {
322 }
323
324 if (m_input_node) {
325 atomic_dec_modulator_count(m_input_node->m_modulator_count, 1);
327 }
328
330 return m_last_output;
331}
Core::GlobalInputConfig input
Definition Config.cpp:42
glm::vec2 current
SequentialFunction m_sequential_function
Function for sequential mode.
Definition Logic.hpp:698
TemporalFunction m_temporal_function
Function for temporal mode.
Definition Logic.hpp:699
DirectFunction m_direct_function
Function for direct mode.
Definition Logic.hpp:696
std::vector< std::shared_ptr< Node > > m_input_nodes
Nodes feeding the input slots in parallel input mode.
Definition Logic.hpp:714
EdgeType m_edge_type
Type of edge to detect.
Definition Logic.hpp:707
double m_threshold
Threshold for boolean conversion.
Definition Logic.hpp:704
double m_temporal_time
Time tracking for temporal mode.
Definition Logic.hpp:710
double m_high_threshold
High threshold for hysteresis.
Definition Logic.hpp:706
double m_input
Current input value for multi-input mode.
Definition Logic.hpp:711
std::vector< double > m_input_buffer
Definition Logic.hpp:712
std::shared_ptr< Node > m_input_node
Input node for processing.
Definition Logic.hpp:713
LogicOperator m_operator
Current logic operator.
Definition Logic.hpp:695
double m_low_threshold
Low threshold for hysteresis.
Definition Logic.hpp:705
MultiInputFunction m_multi_input_function
Function for recursive/feedforward mode.
Definition Logic.hpp:697
bool m_edge_detected
Whether an edge was detected in the last processing.
Definition Logic.hpp:708
bool m_hysteresis_state
State for hysteresis operator.
Definition Logic.hpp:709
LogicMode m_mode
Current processing mode.
Definition Logic.hpp:694
std::span< bool > history_linearized_view()
Definition Logic.cpp:831
void notify_tick(double value) override
Notifies all registered callbacks about a new sample.
Definition Logic.cpp:708
size_t m_input_count
Expected number of inputs for multi-input mode.
Definition Logic.hpp:703
void add_input(double input, size_t index)
Definition Logic.cpp:412
bool m_state_saved
tracks if the node's state has been saved by a snapshot operation
Definition Node.hpp:498
bool m_networked_node
Flag indicating if the node is part of a NodeNetwork This flag is used to disable event firing when t...
Definition Node.hpp:493
uint32_t m_sample_rate
Sample rate for audio processing, used for normalization.
Definition Node.hpp:500
double m_last_output
The most recent sample value generated by this oscillator.
Definition Node.hpp:441
bool m_fire_events_during_snapshot
Internal flag controlling whether notify_tick fires during state snapshots Default: false (events don...
Definition Node.hpp:528
@ FALLING
High-to-low transition (1→0)
@ RISING
Low-to-high transition (0→1)
@ 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.
@ NOT
Logical NOT - inverts the input.
@ NOR
Logical NOR - inverted OR operation.
@ OR
Logical OR - true when any input is true.
@ 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.
@ PROCESSED
Node has been processed this cycle.
Definition NodeSpec.hpp:49
void try_reset_processed_state(std::shared_ptr< Node > node)
Attempts to reset the processed state of a node.
void atomic_inc_modulator_count(std::atomic< uint32_t > &count, int amount)
Atomically increments the modulator count by a specified amount.
void atomic_dec_modulator_count(std::atomic< uint32_t > &count, int amount)
Atomically decrements the modulator count by a specified amount.
void atomic_add_flag(std::atomic< NodeState > &state, NodeState flag)
Atomically adds a flag to a node state.

References add_input(), MayaFlux::Nodes::Generator::AND, MayaFlux::Nodes::atomic_add_flag(), MayaFlux::Nodes::atomic_dec_modulator_count(), MayaFlux::Nodes::atomic_inc_modulator_count(), MayaFlux::Nodes::Generator::BOTH, current, MayaFlux::Nodes::Generator::CUSTOM, MayaFlux::Nodes::Generator::DIRECT, MayaFlux::Nodes::Generator::EDGE, MayaFlux::Nodes::Generator::FALLING, history_linearized_view(), history_push(), MayaFlux::Nodes::Generator::HYSTERESIS, input, m_direct_function, m_edge_detected, m_edge_type, MayaFlux::Nodes::Node::m_fire_events_during_snapshot, m_high_threshold, m_hysteresis_state, m_input, m_input_buffer, m_input_count, m_input_node, m_input_nodes, MayaFlux::Nodes::Node::m_last_output, m_low_threshold, m_mode, m_multi_input_function, MayaFlux::Nodes::Node::m_networked_node, m_operator, MayaFlux::Nodes::Node::m_sample_rate, m_sequential_function, MayaFlux::Nodes::Node::m_state_saved, m_temporal_function, m_temporal_time, m_threshold, MayaFlux::Nodes::Generator::MULTI_INPUT, MayaFlux::Nodes::Generator::NAND, MayaFlux::Nodes::Generator::NOR, MayaFlux::Nodes::Generator::NOT, notify_tick(), MayaFlux::Nodes::Generator::OR, MayaFlux::Nodes::PROCESSED, pull_input_nodes(), release_input_nodes(), MayaFlux::Nodes::Generator::RISING, MayaFlux::Nodes::Generator::SEQUENTIAL, MayaFlux::Nodes::Generator::TEMPORAL, MayaFlux::Nodes::Generator::THRESHOLD, MayaFlux::Nodes::try_reset_processed_state(), and MayaFlux::Nodes::Generator::XOR.

Referenced by process_batch().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: