155 [[nodiscard]]
virtual std::optional<std::vector<double>> get_audio_buffer()
const;
166 [[nodiscard]]
virtual std::optional<std::span<const double>>
219 [[nodiscard]]
virtual std::unordered_map<std::string, std::string>
220 get_metadata()
const;
270 virtual void map_parameter(
const std::string& param_name,
271 const std::shared_ptr<Node>& source,
282 map_parameter(
const std::string& param_name,
283 const std::shared_ptr<NodeNetwork>& source_network);
287 virtual void unmap_parameter(
const std::string& param_name);
311 void add_channel_usage(uint32_t channel_id);
317 void remove_channel_usage(uint32_t channel_id);
324 [[nodiscard]]
bool is_registered_on_channel(uint32_t channel_id)
const;
330 [[nodiscard]] std::vector<uint32_t> get_registered_channels()
const;
346 [[nodiscard]]
bool is_processed_this_cycle()
const;
351 void mark_processing(
bool processing);
356 void mark_processed(
bool processed);
362 [[nodiscard]]
bool is_processing()
const;
368 void request_reset_from_channel(uint32_t channel_id);
403 return m_routing_state.phase & (RoutingState::ACTIVE | RoutingState::COMPLETED);
418 bool m_enabled =
true;
419 bool m_initialized =
false;
420 uint32_t m_sample_rate { 48000 };
421 uint32_t m_block_size { 512 };
426 void ensure_initialized();
438 static std::unordered_map<size_t, std::vector<size_t>>
448 static std::unordered_map<size_t, std::vector<size_t>>
456 static std::unordered_map<size_t, std::vector<size_t>>
464 static std::unordered_map<size_t, std::vector<size_t>>
472 void apply_output_scale();
490 std::atomic<uint32_t> m_channel_mask { 0 };
491 std::atomic<uint32_t> m_pending_reset_mask { 0 };
494 std::atomic<bool> m_processing_state {
false };
495 std::atomic<bool> m_processed_this_cycle {
false };
499 double m_output_scale { 1.0 };
506 static std::string topology_to_string(
Topology topo);
508 static std::string output_mode_to_string(
OutputMode mode);
Domain-agnostic interpretive lens for network processing.
double get_output_scale() const
Get the current output scale factor.
virtual void reset()
Reset network to initial state.
std::vector< ParameterMapping > m_parameter_mappings
uint32_t get_sample_rate() const
Topology get_topology() const
Get the current topology.
virtual ~NodeNetwork()=default
OutputMode get_output_mode() const
Get the current output routing mode.
static std::unordered_map< size_t, std::vector< size_t > > build_grid_3d_neighbors(size_t width, size_t height, size_t depth)
Build neighbor map for GRID_3D topology.
virtual void set_topology(Topology topology)
Set the network's topology.
virtual void initialize()
Called once before first process_batch()
bool is_enabled() const
Check if network is enabled.
void set_output_scale(double scale)
Set the scalar multiplier applied to the network's output buffer after processing.
void set_block_size(uint32_t block_size)
virtual std::optional< double > get_node_output(size_t index) const
Get output of specific internal node (for ONE_TO_ONE mapping)
virtual void process_batch(unsigned int num_samples)=0
Process the network for the given number of samples.
void set_sample_rate(uint32_t sample_rate)
const RoutingState & get_routing_state() const
Retrieves the current routing state of the network.
static std::unordered_map< size_t, std::vector< size_t > > build_ring_neighbors(size_t count)
Build neighbor map for RING topology.
bool needs_channel_routing() const
Checks if the network is currently in a routing transition phase.
void set_channel_mask(uint32_t mask)
Set channel mask directly.
static std::unordered_map< size_t, std::vector< size_t > > build_chain_neighbors(size_t count)
Build neighbor map for CHAIN topology.
uint32_t get_channel_mask() const
Get channel mask (bitfield of registered channels)
static std::unordered_map< size_t, std::vector< size_t > > build_grid_2d_neighbors(size_t width, size_t height)
Build neighbor map for GRID_2D topology.
virtual std::optional< std::span< const double > > get_node_audio_buffer(size_t) const
Get output of specific internal node as audio buffer (for ONE_TO_ONE mapping)
RoutingState & get_routing_state()
Retrieves the current routing state of the network (non-const)
uint32_t get_block_size() const
virtual const NetworkOperator * get_operator() const
std::vector< double > m_last_audio_buffer
virtual size_t get_node_count() const =0
Get the number of nodes in the network.
virtual NetworkOperator * get_operator()
void set_enabled(bool enabled)
Enable/disable the network.
virtual bool has_operator() const
void set_output_mode(OutputMode mode)
Set the network's output routing mode.
RoutingState m_routing_state
Abstract base class for structured collections of nodes with defined relationships.
Topology
Defines the structural relationships between nodes in the network.
@ CHAIN
Linear sequence: node[i] → node[i+1].
@ GRID_2D
2D lattice with 4-connectivity
@ INDEPENDENT
No connections, nodes process independently.
@ CUSTOM
User-defined arbitrary topology.
@ GRID_3D
3D lattice with 6-connectivity
@ SPATIAL
Dynamic proximity-based (nodes within radius interact)
@ RING
Circular: last node connects to first.
MappingMode
Defines how nodes map to external entities (e.g., audio channels, graphics objects)
@ ONE_TO_ONE
Node array/network → network nodes (must match count)
@ BROADCAST
One node → all network nodes.
OutputMode
Defines how the network's computational results are exposed.
@ GRAPHICS_BIND
State available for visualization (read-only)
@ AUDIO_COMPUTE
processed each cycle but not sent to output
@ NONE
Pure internal state, no external output.
@ AUDIO_SINK
Aggregated audio samples sent to output.
std::shared_ptr< Node > broadcast_source
std::shared_ptr< NodeNetwork > network_source
Represents the state of routing transitions for a node.