Group nodes
This commit is contained in:
@@ -98,6 +98,9 @@ pub struct AudioGraph {
|
||||
|
||||
/// Cached topological sort order (invalidated on graph mutation)
|
||||
topo_cache: Option<Vec<NodeIndex>>,
|
||||
|
||||
/// Frontend-only group definitions (stored opaquely for persistence)
|
||||
frontend_groups: Vec<crate::audio::node_graph::preset::SerializedGroup>,
|
||||
}
|
||||
|
||||
impl AudioGraph {
|
||||
@@ -117,6 +120,7 @@ impl AudioGraph {
|
||||
node_positions: std::collections::HashMap::new(),
|
||||
playback_time: 0.0,
|
||||
topo_cache: None,
|
||||
frontend_groups: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -645,6 +649,10 @@ impl AudioGraph {
|
||||
self.graph.node_weight(idx).map(|n| &*n.node)
|
||||
}
|
||||
|
||||
pub fn get_node_mut(&mut self, idx: NodeIndex) -> Option<&mut (dyn AudioNode + 'static)> {
|
||||
self.graph.node_weight_mut(idx).map(|n| &mut *n.node)
|
||||
}
|
||||
|
||||
/// Get oscilloscope data from a specific node
|
||||
pub fn get_oscilloscope_data(&self, idx: NodeIndex, sample_count: usize) -> Option<Vec<f32>> {
|
||||
self.get_node(idx).and_then(|node| node.get_oscilloscope_data(sample_count))
|
||||
@@ -729,9 +737,17 @@ impl AudioGraph {
|
||||
}
|
||||
}
|
||||
|
||||
// Clone frontend groups
|
||||
new_graph.frontend_groups = self.frontend_groups.clone();
|
||||
|
||||
new_graph
|
||||
}
|
||||
|
||||
/// Set frontend-only group definitions (stored opaquely for persistence)
|
||||
pub fn set_frontend_groups(&mut self, groups: Vec<crate::audio::node_graph::preset::SerializedGroup>) {
|
||||
self.frontend_groups = groups;
|
||||
}
|
||||
|
||||
/// Serialize the graph to a preset
|
||||
pub fn to_preset(&self, name: impl Into<String>) -> crate::audio::node_graph::preset::GraphPreset {
|
||||
use crate::audio::node_graph::preset::{GraphPreset, SerializedConnection, SerializedNode};
|
||||
@@ -897,6 +913,9 @@ impl AudioGraph {
|
||||
// Output node
|
||||
preset.output_node = self.output_node.map(|idx| idx.index() as u32);
|
||||
|
||||
// Frontend groups (stored opaquely)
|
||||
preset.groups = self.frontend_groups.clone();
|
||||
|
||||
preset
|
||||
}
|
||||
|
||||
@@ -1118,6 +1137,9 @@ impl AudioGraph {
|
||||
}
|
||||
}
|
||||
|
||||
// Restore frontend groups (stored opaquely)
|
||||
graph.frontend_groups = preset.groups.clone();
|
||||
|
||||
Ok(graph)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,5 +6,5 @@ pub mod preset;
|
||||
|
||||
pub use graph::{Connection, GraphNode, AudioGraph};
|
||||
pub use node_trait::{AudioNode, cv_input_or_default};
|
||||
pub use preset::{GraphPreset, PresetMetadata, SerializedConnection, SerializedNode};
|
||||
pub use preset::{GraphPreset, PresetMetadata, SerializedConnection, SerializedNode, SerializedGroup, SerializedBoundaryConnection};
|
||||
pub use types::{ConnectionError, NodeCategory, NodePort, Parameter, ParameterUnit, SignalType};
|
||||
|
||||
@@ -67,6 +67,10 @@ pub struct GraphPreset {
|
||||
|
||||
/// Which node index is the audio output (None if not set)
|
||||
pub output_node: Option<u32>,
|
||||
|
||||
/// Frontend-only group definitions (backend stores opaquely, does not interpret)
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
pub groups: Vec<SerializedGroup>,
|
||||
}
|
||||
|
||||
/// Metadata about the preset
|
||||
@@ -121,6 +125,32 @@ pub struct SerializedNode {
|
||||
pub sample_data: Option<SampleData>,
|
||||
}
|
||||
|
||||
/// Serialized group definition (frontend-only visual grouping, stored opaquely by backend)
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct SerializedGroup {
|
||||
pub id: u32,
|
||||
pub name: String,
|
||||
pub member_nodes: Vec<u32>,
|
||||
pub position: (f32, f32),
|
||||
pub boundary_inputs: Vec<SerializedBoundaryConnection>,
|
||||
pub boundary_outputs: Vec<SerializedBoundaryConnection>,
|
||||
/// Parent group ID for nested groups (None = top-level group)
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub parent_group_id: Option<u32>,
|
||||
}
|
||||
|
||||
/// Serialized boundary connection for group definitions
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct SerializedBoundaryConnection {
|
||||
pub external_node: u32,
|
||||
pub external_port: usize,
|
||||
pub internal_node: u32,
|
||||
pub internal_port: usize,
|
||||
pub port_name: String,
|
||||
/// Signal type as string ("Audio", "Midi", "CV")
|
||||
pub data_type: String,
|
||||
}
|
||||
|
||||
/// Serialized connection between nodes
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct SerializedConnection {
|
||||
@@ -152,6 +182,7 @@ impl GraphPreset {
|
||||
connections: Vec::new(),
|
||||
midi_targets: Vec::new(),
|
||||
output_node: None,
|
||||
groups: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user