118class MAYAFLUX_API
BinaryOpNode :
public Node,
public std::enable_shared_from_this<BinaryOpNode> {
154 const std::shared_ptr<Node>& lhs,
155 const std::shared_ptr<Node>& rhs,
178 double process_sample(
double input = 0.)
override;
188 std::vector<double> process_batch(
unsigned int num_samples)
override;
198 void reset_processed_state()
override;
200 void save_state()
override;
201 void restore_state()
override;
207 [[nodiscard]] std::vector<std::pair<ModulatorRole, std::shared_ptr<Node>>> get_modulators()
const override;
218 void notify_tick(
double value)
override;
229 void update_context(
double value)
override;
278 double m_last_lhs_value {};
287 double m_last_rhs_value {};
298 bool m_is_initialized {};
300 bool m_state_saved {};
301 double m_saved_last_lhs_value {};
302 double m_saved_last_rhs_value {};
317 const std::vector<std::shared_ptr<Node>>& inputs,
320 const std::shared_ptr<Node>& self);
323 const std::vector<std::shared_ptr<Node>>& inputs,
327 MAYAFLUX_API
void composite_validate(
const std::vector<std::shared_ptr<Node>>& inputs,
size_t N);
343template <
size_t N = 0>
346 using CombineFunc = std::function<double(std::span<const double>)>;
354 std::vector<std::shared_ptr<Node>>
inputs,
374 std::vector<std::shared_ptr<Node>>
inputs,
401 template <
typename DerivedNode>
402 requires std::derived_from<DerivedNode, Node>
404 std::vector<std::shared_ptr<DerivedNode>>
inputs,
410 std::move(func), manager, token)
434 for (
size_t i = 0; i <
m_inputs.size(); ++i) {
435 uint32_t state =
m_inputs[i]->m_state.load();
462 std::vector<double> output(num_samples);
463 for (
unsigned int i = 0; i < num_samples; ++i) {
474 node->reset_processed_state();
493 node->restore_state();
499 [[nodiscard]]
const std::vector<std::shared_ptr<Node>>&
inputs()
const {
return m_inputs; }
504 auto state = node->m_state.load();
515 [[nodiscard]] std::vector<std::pair<ModulatorRole, std::shared_ptr<Node>>>
518 std::vector<std::pair<ModulatorRole, std::shared_ptr<Node>>> result;
Core::GlobalInputConfig input
GPU-compatible context for binary operation callbacks.
double rhs_value
The value from the right-hand side node.
double lhs_value
The value from the left-hand side node.
Specialized context for binary operation callbacks.
std::shared_ptr< Node > m_lhs
The left-hand side node.
std::function< double(double, double)> CombineFunc
Function type for combining two node outputs.
CombineFunc m_func
The function used to combine the outputs of both nodes.
BinaryOpContext m_context
std::shared_ptr< Node > m_rhs
The right-hand side node.
BinaryOpContextGpu m_context_gpu
Combines the outputs of two nodes using a binary operation.
GPU-compatible context for composite operation callbacks.
std::vector< double > input_values
Context for N-ary composite operation callbacks.
std::vector< double > m_input_values
CompositeOpNode(std::vector< std::shared_ptr< Node > > inputs, CombineFunc func)
Creates a composite operation node (unmanaged)
CompositeOpNode(std::vector< std::shared_ptr< DerivedNode > > inputs, CombineFunc func, NodeGraphManager &manager, ProcessingToken token=ProcessingToken::AUDIO_RATE)
Creates a composite operation node with derived node types (managed)
CompositeOpContextGpu m_context_gpu
void update_context(double) override
Updates the context object with the current node state.
void restore_state() override
Restores the node's state from the last save Recursively cascades through all connected modulator nod...
std::vector< std::pair< ModulatorRole, std::shared_ptr< Node > > > get_modulators() const override
Retrieves the current modulators connected to this node.
void notify_tick(double value) override
Notifies all registered callbacks with the current context.
NodeContext & get_last_context() override
Retrieves the last created context object.
NodeGraphManager * m_manager
CompositeOpNode(std::vector< std::shared_ptr< Node > > inputs, CombineFunc func, NodeGraphManager &manager, ProcessingToken token=ProcessingToken::AUDIO_RATE)
Creates a composite operation node (managed)
const std::vector< std::shared_ptr< Node > > & inputs() const
double process_sample(double input=0.) override
Processes a single data sample.
std::vector< double > process_batch(unsigned int num_samples) override
Processes multiple samples at once.
void save_state() override
Saves the node's current state for later restoration Recursively cascades through all connected modul...
bool is_initialized() const
std::vector< double > m_saved_input_values
std::vector< std::shared_ptr< Node > > m_inputs
std::function< double(std::span< const double >)> CombineFunc
CompositeOpContext m_context
void reset_processed_state() override
Resets the processed state of the node and any attached input nodes.
size_t input_count() const
Combines the outputs of N nodes using a composite operation.
GPU-uploadable 1D array data interface.
void fire(NodeContext &ctx) const
Calls every entry whose condition, if any, holds.
double value
Current sample value.
Base context class for node callbacks.
Central manager for the computational processing node graph.
HookList m_conditional_callbacks
Hooks fired on a tick only while their condition holds.
double m_last_output
The most recent sample value generated by this oscillator.
std::atomic< NodeState > m_state
Atomic state flag tracking the node's processing status.
HookList m_callbacks
Hooks fired on every tick.
bool m_fire_events_during_snapshot
Internal flag controlling whether notify_tick fires during state snapshots Default: false (events don...
bool m_gpu_compatible
Flag indicating if the node supports GPU processing This flag is set by derived classes to indicate w...
std::span< const float > get_gpu_data_buffer() const
Provides access to the GPU data buffer.
Base interface for all computational processing nodes.
void composite_apply_semantics(const std::vector< std::shared_ptr< Node > > &inputs, NodeGraphManager &manager, ProcessingToken token)
void composite_initialize(const std::vector< std::shared_ptr< Node > > &inputs, NodeGraphManager &manager, ProcessingToken token, const std::shared_ptr< Node > &self)
void composite_validate(const std::vector< std::shared_ptr< Node > > &inputs, size_t N)
@ PROCESSED
Node has been processed this cycle.
@ ACTIVE
Engine is processing this node.
void try_reset_processed_state(std::shared_ptr< Node > node)
Attempts to reset the processed state of a node.
ProcessingToken
Enumerates the different processing domains for nodes.
@ AUDIO_RATE
Nodes that process at the audio sample rate.
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_remove_flag(std::atomic< NodeState > &state, NodeState flag)
Atomically removes a flag from a node state.
void atomic_add_flag(std::atomic< NodeState > &state, NodeState flag)
Atomically adds a flag to a node state.
Contains the node-based computational processing system components.
bool is_initialized()
Checks if the default engine has been initialized.