MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
NodeNetwork.cpp
Go to the documentation of this file.
1#include "NodeNetwork.hpp"
2
3namespace MayaFlux::Nodes {
4
6{
7 if (!m_initialized) {
9 m_initialized = true;
10 }
11}
12
13std::optional<std::vector<double>> NodeNetwork::get_audio_buffer() const
14{
17 }
18 return std::nullopt;
19}
20
21[[nodiscard]] std::unordered_map<std::string, std::string>
23{
24 return { { "topology", topology_to_string(m_topology) },
25 { "output_mode", output_mode_to_string(m_output_mode) },
26 { "node_count", std::to_string(get_node_count()) },
27 { "enabled", m_enabled ? "true" : "false" } };
28}
29
30void NodeNetwork::map_parameter(const std::string& param_name,
31 const std::shared_ptr<Node>& source,
32 MappingMode mode)
33{
34 // Default: store mapping, subclass handles in process_batch()
35 m_parameter_mappings.push_back({ param_name, mode, source, nullptr });
36}
37
38void NodeNetwork::map_parameter(const std::string& param_name,
39 const std::shared_ptr<NodeNetwork>& source_network)
40{
41 m_parameter_mappings.push_back(
42 { param_name, MappingMode::ONE_TO_ONE, nullptr, source_network });
43}
44
45void NodeNetwork::unmap_parameter(const std::string& param_name)
46{
48 std::remove_if(
50 [&](const auto& m) { return m.param_name == param_name; }),
52}
53
55{
56 return m_processing_state.load(std::memory_order_acquire);
57}
58
59void NodeNetwork::add_channel_usage(uint32_t channel_id)
60{
61 if (channel_id < 32) {
62 m_channel_mask |= (1U << channel_id);
63 }
64}
65
66void NodeNetwork::remove_channel_usage(uint32_t channel_id)
67{
68 if (channel_id < 32) {
69 m_channel_mask &= ~(1U << channel_id);
70 }
71}
72
73bool NodeNetwork::is_registered_on_channel(uint32_t channel_id) const
74{
75 if (channel_id < 32) {
76 return (m_channel_mask & (1U << channel_id)) != 0;
77 }
78 return false;
79}
80
81std::vector<uint32_t> NodeNetwork::get_registered_channels() const
82{
83 std::vector<uint32_t> channels;
84 for (uint32_t i = 0; i < 32; ++i) {
85 if (m_channel_mask & (1U << i)) {
86 channels.push_back(i);
87 }
88 }
89 return channels;
90}
91
92void NodeNetwork::mark_processing(bool processing)
93{
94 m_processing_state.store(processing, std::memory_order_release);
95}
96
98{
99 return m_processed_this_cycle.load(std::memory_order_acquire);
100}
101
102void NodeNetwork::mark_processed(bool processed)
103{
104 m_processed_this_cycle.store(processed, std::memory_order_release);
105}
106
108{
109 switch (topo) {
111 return "INDEPENDENT";
112 case Topology::CHAIN:
113 return "CHAIN";
114 case Topology::RING:
115 return "RING";
117 return "GRID_2D";
119 return "GRID_3D";
121 return "SPATIAL";
122 case Topology::CUSTOM:
123 return "CUSTOM";
124 default:
125 return "UNKNOWN";
126 }
127}
128
130{
131 switch (mode) {
132 case OutputMode::NONE:
133 return "NONE";
135 return "AUDIO_SINK";
137 return "GRAPHICS_BIND";
139 return "CUSTOM";
140 default:
141 return "UNKNOWN";
142 }
143}
144
145} // namespace MayaFlux::Nodes
virtual std::optional< std::vector< double > > get_audio_buffer() const
Get cached audio buffer from last process_batch()
std::vector< ParameterMapping > m_parameter_mappings
std::atomic< uint32_t > m_channel_mask
Bitfield of channels this network is registered on.
static std::string output_mode_to_string(OutputMode mode)
void ensure_initialized()
Ensure initialize() is called exactly once.
bool is_processed_this_cycle() const
Check if network has been processed this cycle (lock-free)
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)
bool is_processing() const
Check if network is currently processing (lock-free)
virtual void map_parameter(const std::string &param_name, const std::shared_ptr< Node > &source, MappingMode mode=MappingMode::BROADCAST)
Map external node output to network parameter.
std::vector< uint32_t > get_registered_channels() const
Get all channels this network is registered on.
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.
std::vector< double > m_last_audio_buffer
bool is_registered_on_channel(uint32_t channel_id) const
Check if network is registered on a channel.
virtual std::unordered_map< std::string, std::string > get_metadata() const
Get network metadata for debugging/visualization.
OutputMode
Defines how the network's computational results are exposed.
@ CUSTOM
User-defined output handling via callbacks.
@ GRAPHICS_BIND
State available for visualization (read-only)
@ NONE
Pure internal state, no external output.
@ AUDIO_SINK
Aggregated audio samples sent to output.
std::atomic< bool > m_processing_state
Per-channel processing state (lock-free atomic flags)
void mark_processing(bool processing)
Mark network as processing or not (lock-free)
static std::string topology_to_string(Topology topo)
void remove_channel_usage(uint32_t channel_id)
Unregister network from a specific channel.
virtual size_t get_node_count() const =0
Get the number of nodes in the network.
void add_channel_usage(uint32_t channel_id)
Register network usage on a specific channel.
void mark_processed(bool processed)
Mark network as processed this cycle (lock-free)
virtual void unmap_parameter(const std::string &param_name)
Remove parameter mapping.
std::atomic< bool > m_processed_this_cycle
virtual void initialize()
Called once before first process_batch()
Contains the node-based computational processing system components.
Definition Chronie.hpp:5