From a966917c76867980708986ae3e9307e8a0e4b5ad Mon Sep 17 00:00:00 2001 From: NetterSilver <133535268+Silvertree2010@users.noreply.github.com> Date: Thu, 22 Oct 2026 20:13:14 +0200 Subject: [PATCH] Fix automation_id overflow and bad ids for high send/plugin slots Found while testing crates/ui-egui/src/edit_window.rs:2474-2477 Co-Authored-By: Claude Haiku 5.5 Co-Authored-By: Claude Sonnet 5.5 --- crates/ui-egui/src/edit_window.rs | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/crates/ui-egui/src/edit_window.rs b/crates/ui-egui/src/edit_window.rs index 7e24a4c7..714e9fa5 100644 --- a/crates/ui-egui/src/edit_window.rs +++ b/crates/ui-egui/src/edit_window.rs @@ -2471,13 +2471,18 @@ fn automation_id(p: &AutoParam) -> String { AutoParam::Pan(0) => "pan".into(), AutoParam::Pan(_) => "pan2".into(), AutoParam::Mute => "mute".into(), - AutoParam::SendLevel(i) => format!("send_{}_level", (b'a' + i) as char), - AutoParam::SendPan(i) => format!("send_{}_pan", (b'a' + i) as char), - AutoParam::SendMute(i) => format!("send_{}_mute", (b'a' + i) as char), - AutoParam::Plugin { slot, param } => format!("plugin:{}:{param}", (b'a' + slot) as char), + AutoParam::SendLevel(i) => format!("send_{}_level", slot_id(*i)), + AutoParam::SendPan(i) => format!("send_{}_pan", slot_id(*i)), + AutoParam::SendMute(i) => format!("send_{}_mute", slot_id(*i)), + AutoParam::Plugin { slot, param } => format!("plugin:{}:{param}", slot_id(*slot)), } } +/// A slot as `AutoParam::parse` reads it: a letter for 0..=25, the number beyond that. +fn slot_id(i: u8) -> String { + if i < 26 { char::from(b'a' + i).to_string() } else { i.to_string() } +} + /// Grid snapping while dragging; holding Cmd/Ctrl swaps Grid and Slip. fn drag_snap(s: &Session, at: Samples, flip: bool) -> Samples { if s.edit.edit_mode.is_grid() != flip { s.edit.grid.snap(at, s.sample_rate, &s.tempo, s.frame_rate) } else { at } @@ -2781,6 +2786,17 @@ mod tests { use super::*; use egui_kittest::Harness; + #[test] + fn automation_id_round_trips_for_high_slots() { + for slot in [0u8, 25, 26, 155, 156, 255] { + for p in + [AutoParam::SendLevel(slot), AutoParam::SendPan(slot), AutoParam::SendMute(slot), AutoParam::Plugin { slot, param: "trim".into() }] + { + assert_eq!(AutoParam::parse(&automation_id(&p)), Some(p)); + } + } + } + #[test] fn follow_jumps_to_offscreen_playhead_while_playing() { // Steady view, follow mode, playhead left the screen: jump to it.