From a286e4258e37f5547e202b4f15f9e768810dd7f7 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Thu, 15 Oct 2026 04:00:04 +0200 Subject: [PATCH] feat(M8.2): show actionable MIDI device status Preserve server-published device mappings in the buffered TUI snapshot and summarize connected IDs, missing/ambiguous recovery actions, connection progress, and transport errors without expanding the mixer layout. Tests: cargo fmt --all -- --check; cargo test -p tui; cargo test -p fader_master --all-targets --all-features; cargo clippy --workspace --all-targets --all-features -- -D warnings. --- architecture.md | 5 ++ fader_master/src/tui_client.rs | 11 +++++ task.md | 5 ++ tui/src/lib.rs | 90 ++++++++++++++++++++++++++++++++-- 4 files changed, 108 insertions(+), 3 deletions(-) diff --git a/architecture.md b/architecture.md index e8ea6ed..949a06b 100644 --- a/architecture.md +++ b/architecture.md @@ -335,6 +335,11 @@ volume bindings. They expose `unavailable`, `waiting`, `tracking`, or `mixed`; controls are instantiated from the profile before discovery so the first live observation can arm them without waiting for an initial MIDI packet. +The same client snapshot retains configured MIDI-device placeholders and their +backend IDs/errors. The compact mixer status line distinguishes connected, +connecting, missing, ambiguous, and failed devices, adding a connect/select +action where the user can resolve the state. + Terminal colors come from semantic theme palettes rather than renderer-local literals. The built-ins are Default, Dracula, Nord, Gruvbox Dark, Catppuccin Mocha, and Solarized Dark. `tui --theme NAME` selects the initial palette and diff --git a/fader_master/src/tui_client.rs b/fader_master/src/tui_client.rs index 4bdd4cb..b3b1a95 100644 --- a/fader_master/src/tui_client.rs +++ b/fader_master/src/tui_client.rs @@ -78,6 +78,17 @@ impl IpcMixerClient { error: object.error, }) .collect(), + devices: snapshot + .devices + .into_iter() + .map(|device| tui::MidiDevice { + id: device.id, + label: device.label, + status: device.status, + backend_id: device.backend_id, + error: device.error, + }) + .collect(), }), ResponseResult::Error { message, .. } => { let kind = if message.contains("stale revision") { diff --git a/task.md b/task.md index 1ddf834..3e1f0d2 100644 --- a/task.md +++ b/task.md @@ -275,6 +275,11 @@ Dependencies: M7, M4 for real use. should add a denser row mode and/or horizontal fader layout for smaller terminals. - [ ] **M8.2 Devices/status:** show adapter selection/probe errors, device mappings, ambiguity and persistence problems. Tests: disconnected/unsupported states have useful actions; manual backend selection validates rather than silently applying incompatible mappings. + The live TUI now preserves server-published MIDI placeholders and shows + connected backend IDs, connection progress, missing-device guidance, + ambiguity selection guidance, and transport errors in its compact status + line. Keep this item open until editor-managed assignment persistence can + report save/conflict failures from M9.3. - [ ] **M8.3 Terminal lifecycle:** restoration on normal/error exit, nonblocking refresh, logging away from display. Tests: injected IO/client failure releases terminal guard; polling/refresh does not block server operation. Blocking IPC now runs on a joined worker and a delayed request cannot block redraw access; keep this item open for explicit terminal-restoration failure diff --git a/tui/src/lib.rs b/tui/src/lib.rs index 4ca1562..ef65572 100644 --- a/tui/src/lib.rs +++ b/tui/src/lib.rs @@ -65,6 +65,15 @@ pub struct MixerItem { pub error: Option, } +#[derive(Clone, Debug, Eq, PartialEq)] +pub struct MidiDevice { + pub id: String, + pub label: String, + pub status: String, + pub backend_id: Option, + pub error: Option, +} + #[derive(Clone, Debug, PartialEq)] pub struct MixerSnapshot { pub revision: u64, @@ -73,6 +82,7 @@ pub struct MixerSnapshot { /// Client/transport failure while the last confirmed items remain visible. pub error: Option, pub items: Vec, + pub devices: Vec, } /// Client boundary kept independent of sockets for deterministic TUI tests. @@ -126,6 +136,7 @@ impl BufferedMixerClient { status: "waiting for server".to_owned(), error: None, items: Vec::new(), + devices: Vec::new(), }; let shared = Arc::new(( Mutex::new(BufferedState { @@ -586,11 +597,22 @@ impl Widget for &LiveTui { ) .render(header, buf); + let status_error = self.client_error.is_some() + || self + .snapshot + .devices + .iter() + .any(|device| device.error.is_some() || device.status == "error"); + let status = self.client_error.clone().unwrap_or_else(|| { + device_summary(&self.snapshot.devices) + .unwrap_or_else(|| "confirmed server state".to_owned()) + }); let mixer = Block::bordered() .title(" Live mixer objects ".fg(theme.accent).bold()) - .title_bottom(match self.client_error.as_deref() { - Some(error) => error.fg(theme.error), - None => "confirmed server state".fg(theme.muted), + .title_bottom(if status_error { + status.fg(theme.error) + } else { + status.fg(theme.muted) }) .border_style(Style::default().fg(theme.muted)) .border_set(border::THICK); @@ -622,6 +644,32 @@ impl Widget for &LiveTui { } } +fn device_summary(devices: &[MidiDevice]) -> Option { + (!devices.is_empty()).then(|| { + devices + .iter() + .map(|device| { + let detail = if let Some(error) = &device.error { + format!("error — {error}") + } else { + match device.status.as_str() { + "missing" => "missing — connect device".to_owned(), + "ambiguous" => "ambiguous — select port".to_owned(), + "connected" => device.backend_id.as_ref().map_or_else( + || "connected".to_owned(), + |backend| format!("connected ({backend})"), + ), + "connecting" => "connecting…".to_owned(), + status => status.to_owned(), + } + }; + format!("{}: {detail}", device.label) + }) + .collect::>() + .join(" | ") + }) +} + impl LiveTui { fn render_streams(&self, area: Rect, buf: &mut Buffer) { let theme = self.theme.palette(); @@ -749,6 +797,7 @@ impl DemoClient { writable: true, error: None, }], + devices: Vec::new(), } } } @@ -848,6 +897,13 @@ mod tests { fn live_mixer_renders_status_and_stream_at_typical_size() { let mut app = LiveTui::new(DemoClient::default()).unwrap(); app.snapshot.items[0].pickup = Some(PickupStatus::Waiting); + app.snapshot.devices.push(MidiDevice { + id: "apc-mini".into(), + label: "APC MINI".into(), + status: "missing".into(), + backend_id: None, + error: None, + }); let area = Rect::new(0, 0, 100, 20); let mut buffer = Buffer::empty(area); (&app).render(area, &mut buffer); @@ -861,9 +917,37 @@ mod tests { assert!(rendered.contains("Desktop audio")); assert!(rendered.contains("65%")); assert!(rendered.contains("pickup: waiting")); + assert!(rendered.contains("APC MINI: missing — connect device")); assert!(rendered.contains("Q/Esc")); } + #[test] + fn device_status_summaries_include_recovery_actions_and_errors() { + let ambiguous = MidiDevice { + id: "left".into(), + label: "Left deck".into(), + status: "ambiguous".into(), + backend_id: None, + error: None, + }; + assert_eq!( + device_summary(&[ambiguous]).as_deref(), + Some("Left deck: ambiguous — select port") + ); + + let failed = MidiDevice { + id: "right".into(), + label: "Right deck".into(), + status: "error".into(), + backend_id: Some("36:0".into()), + error: Some("permission denied".into()), + }; + assert_eq!( + device_summary(&[failed]).as_deref(), + Some("Right deck: error — permission denied") + ); + } + #[test] fn mixed_and_offline_objects_render_without_panicking_at_small_sizes() { let mut app = LiveTui::new(DemoClient::default()).unwrap();