Track › Instrument: choose the selected track's instrument from the menu bar (#374)

The submenu under Track › New... opens the same picker as the Mix window's
instrument slot for the first selected instrument track, and is greyed out
with a hint when none is selected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Justin JohnandClaude Opus 5.5 committed 2026-10-13 17:44:34 +05:30
1 parent c0cb993408
commit 606ddac169
1 file changed
+32
+32
View File
@@ -243,6 +243,9 @@ pub fn menu_bar(app: &mut SoundApp, ui: &mut egui::Ui) {
if c.path == "File > Open" {
crate::recent::menu(app, ui);
}
if c.path == "Track > New..." {
instrument_menu(app, ui);
}
}
if root.label == "AudioSuite" {
ui.separator();
@@ -276,6 +279,23 @@ pub fn menu_bar(app: &mut SoundApp, ui: &mut egui::Ui) {
);
}
/// Track › Instrument: the instrument picker for the selected instrument track (#374).
fn instrument_menu(app: &mut SoundApp, ui: &mut egui::Ui) {
match instrument_track(app.engine.session()) {
Some(id) => {
ui.menu_button("Instrument", |ui| crate::mix_window::instrument_menu(app, ui, id));
}
None => {
ui.add_enabled(false, egui::Button::new("Instrument")).on_disabled_hover_text("Select an instrument track");
}
}
}
/// The first selected instrument track, in track order.
fn instrument_track(s: &soundcraft_model::Session) -> Option<soundcraft_model::TrackId> {
s.tracks.iter().find(|t| t.kind == soundcraft_model::TrackKind::Instrument && s.edit.selected_tracks.contains(&t.id)).map(|t| t.id)
}
fn menu_node(app: &mut SoundApp, ui: &mut egui::Ui, n: &MenuNode, extra: &[(&str, &str)]) {
if !n.children.is_empty() {
ui.menu_button(&n.label, |ui| {
@@ -720,4 +740,16 @@ mod tests {
assert!(!app.engine.is_dirty());
let _ = std::fs::remove_dir_all(&dir);
}
#[test]
fn track_instrument_menu_targets_the_selected_instrument_track() {
let mut e = soundcraft_engine::Engine::default();
let audio = e.execute("track.new", &json!({"kind": "audio"})).unwrap()["tracks"][0].as_u64().unwrap();
assert_eq!(instrument_track(e.session()), None);
let inst = e.execute("track.new", &json!({"kind": "instrument"})).unwrap()["tracks"][0].as_u64().unwrap();
e.execute("edit.select", &json!({"tracks": [audio]})).unwrap();
assert_eq!(instrument_track(e.session()), None, "an audio track has no instrument");
e.execute("edit.select", &json!({"tracks": [audio, inst]})).unwrap();
assert_eq!(instrument_track(e.session()).map(|t| t.0), Some(inst));
}
}