70 if (
typeid(T).name() == type_id) {
71 return static_cast<T*
>(
this);
79 if (
typeid(T).name() == type_id) {
80 return static_cast<const T*
>(
this);
96 , type_id(
std::move(type))
172 virtual void on_tick(
const NodeHook& callback);
209 virtual bool remove_hook(
const NodeHook& callback);
223 virtual bool remove_conditional_hook(
const NodeCondition& callback);
235 virtual void remove_all_hooks();
245 virtual void reset_processed_state();
271 void register_channel_usage(uint32_t channel_id);
277 void unregister_channel_usage(uint32_t channel_id);
283 [[nodiscard]]
bool is_used_by_channel(uint32_t channel_id)
const;
294 void request_reset_from_channel(uint32_t channel_id);
305 [[nodiscard]]
const inline std::atomic<uint32_t>&
get_channel_mask()
const {
return m_active_channels_mask; }
334 m_gpu_compatible = compatible;
336 m_timing_rate = m_frame_rate;
338 m_timing_rate = m_sample_rate;
355 [[nodiscard]] std::span<const float> get_gpu_data_buffer()
const;
387 virtual void reset_processed_state_internal();
397 double m_last_output { 0 };
406 bool m_gpu_compatible {};
444 bool m_networked_node {};
449 bool m_state_saved {};
451 uint32_t m_sample_rate { 48000 };
453 uint32_t m_frame_rate { 60 };
455 uint32_t m_timing_rate { m_sample_rate };
457 uint8_t m_node_capability { NodeCapability::SCALAR };
479 bool m_fire_events_during_snapshot =
false;
494 std::atomic<NodeState> m_state { NodeState::INACTIVE };
508 std::atomic<uint32_t> m_modulator_count { 0 };
519 bool try_claim_snapshot_context(uint64_t context_id);
529 [[nodiscard]]
bool is_in_snapshot_context(uint64_t context_id)
const;
538 void release_snapshot_context(uint64_t context_id);
544 [[nodiscard]]
bool has_active_snapshot()
const;
552 return m_snapshot_context_id.load(std::memory_order_acquire);
560 void add_buffer_reference();
567 void remove_buffer_reference();
577 bool mark_buffer_processed();
586 void request_buffer_reset();
594 return m_buffer_processed.load(std::memory_order_acquire);
605 [[nodiscard]]
inline bool is_in_network()
const {
return m_networked_node; }
645 return m_routing_state.phase & (RoutingState::ACTIVE | RoutingState::COMPLETED);
667 return (m_node_capability & cap) != 0U;
674 std::atomic<uint32_t> m_active_channels_mask { 0 };
683 std::atomic<uint32_t> m_pending_reset_mask { 0 };
694 std::atomic<uint64_t> m_snapshot_context_id { 0 };
702 std::atomic<uint32_t> m_buffer_count { 0 };
709 std::atomic<bool> m_buffer_processed {
false };
718 std::atomic<uint32_t> m_buffer_reset_count { 0 };
std::string type_id
Type identifier for runtime type checking.
virtual ~NodeContext()=default
NodeContext(double value, std::string type)
Protected constructor for NodeContext.
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.
void set_frame_rate(uint32_t frame_rate)
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>.
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.
Represents the state of routing transitions for a node.