Group nodes
This commit is contained in:
@@ -1426,6 +1426,34 @@ impl Engine {
|
||||
}
|
||||
}
|
||||
|
||||
Command::GraphSetGroups(track_id, groups) => {
|
||||
let graph = match self.project.get_track_mut(track_id) {
|
||||
Some(TrackNode::Midi(track)) => Some(&mut track.instrument_graph),
|
||||
Some(TrackNode::Audio(track)) => Some(&mut track.effects_graph),
|
||||
_ => None,
|
||||
};
|
||||
if let Some(graph) = graph {
|
||||
graph.set_frontend_groups(groups);
|
||||
}
|
||||
}
|
||||
|
||||
Command::GraphSetGroupsInTemplate(track_id, voice_allocator_id, groups) => {
|
||||
use crate::audio::node_graph::nodes::VoiceAllocatorNode;
|
||||
let graph = match self.project.get_track_mut(track_id) {
|
||||
Some(TrackNode::Midi(track)) => Some(&mut track.instrument_graph),
|
||||
Some(TrackNode::Audio(track)) => Some(&mut track.effects_graph),
|
||||
_ => None,
|
||||
};
|
||||
if let Some(graph) = graph {
|
||||
let node_idx = NodeIndex::new(voice_allocator_id as usize);
|
||||
if let Some(graph_node) = graph.get_node_mut(node_idx) {
|
||||
if let Some(va_node) = graph_node.as_any_mut().downcast_mut::<VoiceAllocatorNode>() {
|
||||
va_node.template_graph_mut().set_frontend_groups(groups);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Command::GraphSavePreset(track_id, preset_path, preset_name, description, tags) => {
|
||||
let graph = match self.project.get_track(track_id) {
|
||||
Some(TrackNode::Midi(track)) => Some(&track.instrument_graph),
|
||||
@@ -3029,6 +3057,16 @@ impl EngineController {
|
||||
let _ = self.command_tx.push(Command::GraphSetOutputNode(track_id, node_id));
|
||||
}
|
||||
|
||||
/// Set frontend-only group definitions on a track's graph
|
||||
pub fn graph_set_groups(&mut self, track_id: TrackId, groups: Vec<crate::audio::node_graph::preset::SerializedGroup>) {
|
||||
let _ = self.command_tx.push(Command::GraphSetGroups(track_id, groups));
|
||||
}
|
||||
|
||||
/// Set frontend-only group definitions on a VA template graph
|
||||
pub fn graph_set_groups_in_template(&mut self, track_id: TrackId, voice_allocator_id: u32, groups: Vec<crate::audio::node_graph::preset::SerializedGroup>) {
|
||||
let _ = self.command_tx.push(Command::GraphSetGroupsInTemplate(track_id, voice_allocator_id, groups));
|
||||
}
|
||||
|
||||
/// Save the current graph as a preset
|
||||
pub fn graph_save_preset(&mut self, track_id: TrackId, preset_path: String, preset_name: String, description: String, tags: Vec<String>) {
|
||||
let _ = self.command_tx.push(Command::GraphSavePreset(track_id, preset_path, preset_name, description, tags));
|
||||
|
||||
@@ -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