36 std::shared_ptr<Node>
node;
85 return dynamic_cast<T*
>(
this);
91 return dynamic_cast<const T*
>(
this);
180 virtual void on_tick(
const NodeHook& callback);
217 virtual bool remove_hook(
const NodeHook& callback);
231 virtual bool remove_conditional_hook(
const NodeCondition& callback);
243 virtual void remove_all_hooks();
253 virtual void reset_processed_state();
279 void register_channel_usage(uint32_t channel_id);
285 void unregister_channel_usage(uint32_t channel_id);
291 [[nodiscard]]
bool is_used_by_channel(uint32_t channel_id)
const;
302 void request_reset_from_channel(uint32_t channel_id);
313 [[nodiscard]]
const inline std::atomic<uint32_t>&
get_channel_mask()
const {
return m_active_channels_mask; }
342 m_gpu_compatible = compatible;
344 m_timing_rate = m_frame_rate;
346 m_timing_rate = m_sample_rate;
363 [[nodiscard]] std::span<const float> get_gpu_data_buffer()
const;
395 virtual void reset_processed_state_internal();
405 double m_last_output { 0 };
414 bool m_gpu_compatible {};
452 bool m_networked_node {};
457 bool m_state_saved {};
459 uint32_t m_sample_rate { 48000 };
461 uint32_t m_frame_rate { 60 };
463 uint32_t m_timing_rate { m_sample_rate };
465 uint8_t m_node_capability { NodeCapability::SCALAR };
487 bool m_fire_events_during_snapshot =
false;
502 std::atomic<NodeState> m_state { NodeState::INACTIVE };
516 std::atomic<uint32_t> m_modulator_count { 0 };
527 bool try_claim_snapshot_context(uint64_t context_id);
537 [[nodiscard]]
bool is_in_snapshot_context(uint64_t context_id)
const;
546 void release_snapshot_context(uint64_t context_id);
552 [[nodiscard]]
bool has_active_snapshot()
const;
560 return m_snapshot_context_id.load(std::memory_order_acquire);
568 void add_buffer_reference();
575 void remove_buffer_reference();
585 bool mark_buffer_processed();
594 void request_buffer_reset();
602 return m_buffer_processed.load(std::memory_order_acquire);
613 [[nodiscard]]
inline bool is_in_network()
const {
return m_networked_node; }
653 return m_routing_state.phase & (RoutingState::ACTIVE | RoutingState::COMPLETED);
675 return (m_node_capability & cap) != 0U;
685 [[nodiscard]]
virtual std::vector<std::pair<ModulatorRole, std::shared_ptr<Node>>>
697 std::vector<ModulatorTree> result;
698 for (
auto& [role, node] : get_modulators()) {
702 entry.
modulators = node->get_modulator_tree();
703 result.push_back(std::move(entry));
712 std::atomic<uint32_t> m_active_channels_mask { 0 };
721 std::atomic<uint32_t> m_pending_reset_mask { 0 };
732 std::atomic<uint64_t> m_snapshot_context_id { 0 };
740 std::atomic<uint32_t> m_buffer_count { 0 };
747 std::atomic<bool> m_buffer_processed {
false };
756 std::atomic<uint32_t> m_buffer_reset_count { 0 };
Core::GlobalInputConfig input
NodeContext(double value)
Protected constructor for NodeContext.
virtual ~NodeContext()=default
double value
Current sample value.
T * as()
Safely cast to a derived context type.
Base context class for node callbacks.
virtual double process_sample(double input=0.)=0
Processes a single data sample.
virtual double get_last_output()
Retrieves the most recent output value produced by the node.
virtual std::vector< double > process_batch(unsigned int num_samples)=0
Processes multiple samples at once.
bool is_buffer_processed() const
Checks if the buffer has been processed.
virtual void save_state()=0
Saves the node's current state for later restoration Recursively cascades through all connected modul...
bool is_in_network() const
Sets whether the node is part of a NodeNetwork.
uint32_t get_frame_rate() const
std::vector< NodeHook > m_callbacks
Collection of standard callback functions.
void set_in_network(bool networked)
Marks the node as being part of a NodeNetwork.
virtual void restore_state()=0
Restores the node's state from the last save Recursively cascades through all connected modulator nod...
uint64_t get_active_snapshot_context() const
Get the active snapshot context ID.
const std::atomic< uint32_t > & get_channel_mask() const
Retrieves the current bitmask of active channels using this node.
bool needs_channel_routing() const
Checks if the network is currently in a routing transition phase.
virtual NodeContext & get_last_context()=0
Retrieves the last created context object.
virtual void notify_tick(double value)=0
Notifies all registered callbacks with the current context.
virtual void update_context(double value)=0
Updates the context object with the current node state.
virtual void set_gpu_compatible(bool compatible)
Sets whether the node is compatible with GPU processing.
void set_sample_rate(uint32_t sample_rate)
bool is_gpu_compatible() const
Checks if the node supports GPU processing.
std::vector< std::pair< NodeHook, NodeCondition > > m_conditional_callbacks
Collection of conditional callback functions with their predicates.
virtual ~Node()=default
Virtual destructor for proper cleanup of derived classes.
uint32_t get_sample_rate() const
RoutingState & get_routing_state()
Retrieves the current routing state of the network (non-const)
bool has_capability(NodeCapability cap) const
Query a single capability.
std::vector< ModulatorTree > get_modulator_tree() const
Returns the full modulator tree rooted at this node.
void set_frame_rate(uint32_t frame_rate)
virtual std::vector< std::pair< ModulatorRole, std::shared_ptr< Node > > > get_modulators() const
Returns direct modulator nodes and their roles.
std::vector< float > m_gpu_data_buffer
GPU data buffer for context objects.
RoutingState m_routing_state
Internal state tracking for routing transitions.
virtual uint8_t node_capabilities() const
Declare which data shapes this node's context can produce.
const RoutingState & get_routing_state() const
Retrieves the current routing state of the network.
Base interface for all computational processing nodes.
TypedHook<> NodeHook
Alias for TypedHook<NodeContext>.
ModulatorRole
Describes the role a modulator node plays relative to its owner.
NodeCapability
Bitmask flags declaring what data shapes a node's context can produce.
std::function< bool(NodeContext &)> NodeCondition
Predicate function type for conditional callbacks.
Contains the node-based computational processing system components.
std::vector< ModulatorTree > modulators
std::shared_ptr< Node > node
Recursive tree node describing a modulator and all of its own modulators.
Represents the state of routing transitions for a node.