Add automation inputs for audio graphs
This commit is contained in:
@@ -301,6 +301,12 @@ pub struct GraphState {
|
||||
pub available_nam_models: Vec<NamModelInfo>,
|
||||
/// Search text for the NAM model picker popup
|
||||
pub nam_search_text: String,
|
||||
/// Edit buffers for AutomationInput display names, keyed by frontend NodeId
|
||||
pub automation_name_edits: HashMap<NodeId, String>,
|
||||
/// Pending automation name changes (node_id, backend_node_id, new_name)
|
||||
pub pending_automation_name_changes: Vec<(NodeId, u32, String)>,
|
||||
/// AutomationInput nodes whose display name still needs to be queried from backend
|
||||
pub pending_automation_name_queries: Vec<(NodeId, u32)>,
|
||||
}
|
||||
|
||||
impl Default for GraphState {
|
||||
@@ -327,6 +333,9 @@ impl Default for GraphState {
|
||||
pending_amp_sim_load: None,
|
||||
available_nam_models: Vec::new(),
|
||||
nam_search_text: String::new(),
|
||||
automation_name_edits: HashMap::new(),
|
||||
pending_automation_name_changes: Vec::new(),
|
||||
pending_automation_name_queries: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1511,6 +1520,21 @@ impl NodeDataTrait for NodeData {
|
||||
if close_popup {
|
||||
egui::Popup::close_id(ui.ctx(), popup_id);
|
||||
}
|
||||
} else if self.template == NodeTemplate::AutomationInput {
|
||||
let backend_node_id = user_state.node_backend_ids.get(&node_id).copied().unwrap_or(0);
|
||||
let edit_buf = user_state.automation_name_edits
|
||||
.entry(node_id)
|
||||
.or_insert_with(String::new);
|
||||
let resp = ui.add(
|
||||
egui::TextEdit::singleline(edit_buf)
|
||||
.hint_text("Lane name...")
|
||||
.desired_width(f32::INFINITY),
|
||||
);
|
||||
if resp.lost_focus() {
|
||||
user_state.pending_automation_name_changes.push(
|
||||
(node_id, backend_node_id, edit_buf.clone()),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
ui.label("");
|
||||
}
|
||||
|
||||
@@ -681,6 +681,9 @@ impl NodeGraphPane {
|
||||
if let Err(e) = shared.action_executor.execute_with_backend(action, &mut backend_context) {
|
||||
eprintln!("Failed to execute node graph action: {}", e);
|
||||
} else {
|
||||
// Notify other panes (e.g. timeline automation cache) that graph topology changed
|
||||
*shared.graph_topology_generation += 1;
|
||||
|
||||
// If this was a node addition, query backend to get the new node's ID
|
||||
if let Some((frontend_id, node_type, position)) = self.pending_node_addition.take() {
|
||||
if let Some(track_id) = self.track_id {
|
||||
@@ -1432,6 +1435,7 @@ impl NodeGraphPane {
|
||||
|
||||
// Create nodes in frontend
|
||||
self.pending_script_resolutions.clear();
|
||||
self.user_state.pending_automation_name_queries.clear();
|
||||
for node in &graph_state.nodes {
|
||||
let node_template = match NodeTemplate::from_backend_name(&node.node_type) {
|
||||
Some(t) => t,
|
||||
@@ -1456,6 +1460,13 @@ impl NodeGraphPane {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// For AutomationInput nodes: queue a name query to populate the edit buffer
|
||||
if node.node_type == "AutomationInput" {
|
||||
if let Some(fid) = frontend_id {
|
||||
self.user_state.pending_automation_name_queries.push((fid, node.id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create connections in frontend
|
||||
@@ -2780,6 +2791,36 @@ impl crate::panes::PaneRenderer for NodeGraphPane {
|
||||
}
|
||||
}
|
||||
|
||||
// Populate automation name edit buffers (deferred after load)
|
||||
if !self.user_state.pending_automation_name_queries.is_empty() {
|
||||
let queries: Vec<_> = self.user_state.pending_automation_name_queries.drain(..).collect();
|
||||
if let Some(backend_track_id) = self.track_id.and_then(|tid| shared.layer_to_track_map.get(&tid).copied()) {
|
||||
if let Some(controller_arc) = &shared.audio_controller {
|
||||
let mut controller = controller_arc.lock().unwrap();
|
||||
for (node_id, backend_node_id) in queries {
|
||||
if let Ok(name) = controller.query_automation_name(backend_track_id, backend_node_id) {
|
||||
self.user_state.automation_name_edits.insert(node_id, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle pending automation name changes
|
||||
if !self.user_state.pending_automation_name_changes.is_empty() {
|
||||
let changes: Vec<_> = self.user_state.pending_automation_name_changes.drain(..).collect();
|
||||
if let Some(backend_track_id) = self.track_id.and_then(|tid| shared.layer_to_track_map.get(&tid).copied()) {
|
||||
if let Some(controller_arc) = &shared.audio_controller {
|
||||
let mut controller = controller_arc.lock().unwrap();
|
||||
for (_node_id, backend_node_id, name) in changes {
|
||||
controller.automation_set_name(backend_track_id, backend_node_id, name);
|
||||
}
|
||||
// Invalidate timeline automation cache so renamed lanes appear immediately
|
||||
*shared.graph_topology_generation += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle param changes from draw block (canvas knob drag etc.)
|
||||
if !self.user_state.pending_draw_param_changes.is_empty() {
|
||||
let changes: Vec<_> = self.user_state.pending_draw_param_changes.drain(..).collect();
|
||||
|
||||
Reference in New Issue
Block a user