feat: add MIDI device details popup
Make MIDI device status rows selectable, show identity and connection diagnostics in a popup, and set or clear the profile-backed default controller from that popup. Tests: cargo fmt --all -- --check; cargo check --workspace --all-targets --all-features; cargo test --workspace --all-targets --all-features; cargo test --workspace --doc --all-features; cargo clippy --workspace --all-targets --all-features -- -D warnings; cargo build --workspace --release --all-features; cargo check --workspace; cargo check --workspace --no-default-features; cargo check -p midi --no-default-features --features midir; cargo check -p volume_lib --no-default-features --features pulse
This commit is contained in:
parent
4f3a70d1ef
commit
488cb200df
|
|
@ -87,6 +87,8 @@ default MIDI controller, restore individual faders from the hidden-fader popup,
|
|||
inspect backend and MIDI-device state, and save the server-owned draft. Save
|
||||
both activates the validated configuration and persists it; there is no
|
||||
separate Apply step.
|
||||
Each MIDI-device row is selectable; Enter opens its status and connection
|
||||
details and allows its profile-backed default-controller flag to be toggled.
|
||||
Unassigned volume and mute controls inherit that default for MIDI learn.
|
||||
Vertical mode keeps the stacked card appearance and full-width separator rows.
|
||||
Horizontal mode keeps every fader and labeled separator divider in one
|
||||
|
|
|
|||
|
|
@ -472,6 +472,9 @@ restoration, unsaved and Save state, active profile/backend status, MIDI-learn
|
|||
cancellation, and MIDI device diagnostics. Object and layout edits stay on the
|
||||
main mixer. There is no separate hidden-fader mode: hidden rows disappear from
|
||||
the mixer and are restored from this popup at their retained layout positions.
|
||||
MIDI devices are selectable settings rows. Their details popup shows stable and
|
||||
backend identity, connection status, and errors, and sets or clears the same
|
||||
profile-backed default controller used by MIDI learn.
|
||||
|
||||
Every value presented as configuration is read from the server-owned validated
|
||||
profile draft and every edit targets that same profile field. The TUI must not
|
||||
|
|
|
|||
3
task.md
3
task.md
|
|
@ -419,7 +419,8 @@ Dependencies: M8, M2, M1.
|
|||
theme, hidden restoration, Save, learning cancellation, and backend/device
|
||||
state. Hidden restoration uses one settings action that opens a popup listing
|
||||
every hidden fader rather than expanding the settings page with one row per
|
||||
fader.
|
||||
fader. MIDI-device status rows are selectable and open a details popup where
|
||||
the profile's default-controller assignment can be set or cleared.
|
||||
Keep this item open until any remaining required object-creation workflow is
|
||||
available from the mixer and its small-terminal acceptance passes.
|
||||
|
||||
|
|
|
|||
225
tui/src/lib.rs
225
tui/src/lib.rs
|
|
@ -823,6 +823,7 @@ pub struct LiveTui<C> {
|
|||
pattern_editor: Option<PatternEditor>,
|
||||
controller_picker: Option<ControllerPicker>,
|
||||
hidden_fader_picker: Option<HiddenFaderPicker>,
|
||||
midi_device_details: Option<String>,
|
||||
controller_selections: BTreeMap<(String, String), String>,
|
||||
}
|
||||
|
||||
|
|
@ -846,6 +847,7 @@ enum SettingsRow {
|
|||
HiddenFaders { count: usize },
|
||||
CancelMidiLearn,
|
||||
Save,
|
||||
MidiDevice { id: String },
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
|
|
@ -1002,6 +1004,7 @@ impl<C: MixerClient> LiveTui<C> {
|
|||
pattern_editor: None,
|
||||
controller_picker: None,
|
||||
hidden_fader_picker: None,
|
||||
midi_device_details: None,
|
||||
controller_selections: BTreeMap::new(),
|
||||
}
|
||||
}
|
||||
|
|
@ -1138,6 +1141,10 @@ impl<C: MixerClient> LiveTui<C> {
|
|||
self.handle_hidden_fader_picker_key(key_event.code);
|
||||
return;
|
||||
}
|
||||
if self.midi_device_details.is_some() {
|
||||
self.handle_midi_device_details_key(key_event.code);
|
||||
return;
|
||||
}
|
||||
if self.fader_editor.is_some() {
|
||||
self.handle_fader_editor_key(key_event.code);
|
||||
return;
|
||||
|
|
@ -1350,6 +1357,14 @@ impl<C: MixerClient> LiveTui<C> {
|
|||
rows.push(SettingsRow::CancelMidiLearn);
|
||||
}
|
||||
rows.push(SettingsRow::Save);
|
||||
rows.extend(
|
||||
self.snapshot
|
||||
.devices
|
||||
.iter()
|
||||
.map(|device| SettingsRow::MidiDevice {
|
||||
id: device.id.clone(),
|
||||
}),
|
||||
);
|
||||
rows
|
||||
}
|
||||
|
||||
|
|
@ -1421,6 +1436,9 @@ impl<C: MixerClient> LiveTui<C> {
|
|||
}
|
||||
SettingsRow::CancelMidiLearn if forward => self.cancel_midi_learn(),
|
||||
SettingsRow::Save if forward => self.save_configuration(),
|
||||
SettingsRow::MidiDevice { id } if forward => {
|
||||
self.midi_device_details = Some(id);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
|
@ -1489,6 +1507,35 @@ impl<C: MixerClient> LiveTui<C> {
|
|||
}
|
||||
}
|
||||
|
||||
fn handle_midi_device_details_key(&mut self, code: KeyCode) {
|
||||
let Some(id) = self.midi_device_details.clone() else {
|
||||
return;
|
||||
};
|
||||
if !self.snapshot.devices.iter().any(|device| device.id == id) {
|
||||
if code == KeyCode::Esc {
|
||||
self.midi_device_details = None;
|
||||
}
|
||||
return;
|
||||
}
|
||||
let is_default = self.snapshot.configuration.default_controller.as_deref() == Some(&id);
|
||||
let make_default = match code {
|
||||
KeyCode::Esc => {
|
||||
self.midi_device_details = None;
|
||||
return;
|
||||
}
|
||||
KeyCode::Left => false,
|
||||
KeyCode::Right => true,
|
||||
KeyCode::Enter => !is_default,
|
||||
_ => return,
|
||||
};
|
||||
if make_default == is_default {
|
||||
return;
|
||||
}
|
||||
self.apply_layout_edit(ConfigurationEdit::SetDefaultController {
|
||||
surface: make_default.then_some(id),
|
||||
});
|
||||
}
|
||||
|
||||
fn cancel_midi_learn(&mut self) {
|
||||
match self.client.cancel_midi_learn() {
|
||||
Ok(snapshot) => self.replace_snapshot(snapshot),
|
||||
|
|
@ -2225,6 +2272,9 @@ impl<C: MixerClient> Widget for &LiveTui<C> {
|
|||
if self.hidden_fader_picker.is_some() {
|
||||
self.render_hidden_fader_picker(area, buf);
|
||||
}
|
||||
if self.midi_device_details.is_some() {
|
||||
self.render_midi_device_details(area, buf);
|
||||
}
|
||||
if self.snapshot.configuration.learning.is_some() {
|
||||
self.render_midi_learn_waiting(area, buf);
|
||||
}
|
||||
|
|
@ -2678,6 +2728,43 @@ impl<C: MixerClient> LiveTui<C> {
|
|||
.render(popup, buf);
|
||||
}
|
||||
|
||||
fn render_midi_device_details(&self, area: Rect, buf: &mut Buffer) {
|
||||
let Some(id) = &self.midi_device_details else {
|
||||
return;
|
||||
};
|
||||
let theme = self.theme.palette();
|
||||
let Some(device) = self.snapshot.devices.iter().find(|device| &device.id == id) else {
|
||||
return;
|
||||
};
|
||||
let is_default = self.snapshot.configuration.default_controller.as_deref() == Some(id);
|
||||
let backend = device.backend_id.as_deref().unwrap_or("Unavailable");
|
||||
let error = device.error.as_deref().unwrap_or("None");
|
||||
let popup = centered_rect(area, 68, 11);
|
||||
Clear.render(popup, buf);
|
||||
Paragraph::new(Text::from(vec![
|
||||
Line::from(device.label.as_str()).bold(),
|
||||
Line::from(format!("Device ID {}", device.id)),
|
||||
Line::from(format!("Status {}", device.status)),
|
||||
Line::from(format!("Backend port {backend}")),
|
||||
Line::from(format!("Error {error}")),
|
||||
Line::from(""),
|
||||
Line::from(vec![
|
||||
"▶ Default controller ".fg(theme.foreground),
|
||||
is_default.to_string().fg(theme.accent).bold(),
|
||||
" [←→/Enter]".fg(theme.muted),
|
||||
]),
|
||||
]))
|
||||
.block(
|
||||
Block::bordered()
|
||||
.title(" MIDI device details ".fg(theme.accent).bold())
|
||||
.title_bottom(" ← false · → true · Enter toggle · Esc close ".fg(theme.muted))
|
||||
.border_set(border::DOUBLE)
|
||||
.border_style(Style::default().fg(theme.accent))
|
||||
.style(Style::default().bg(theme.background)),
|
||||
)
|
||||
.render(popup, buf);
|
||||
}
|
||||
|
||||
fn render_midi_learn_waiting(&self, area: Rect, buf: &mut Buffer) {
|
||||
let theme = self.theme.palette();
|
||||
let popup = centered_rect(area, 68, 7.min(area.height));
|
||||
|
|
@ -2739,7 +2826,12 @@ impl<C: MixerClient> LiveTui<C> {
|
|||
}
|
||||
lines.push(Line::from(""));
|
||||
lines.push(Line::from("Settings").fg(theme.accent).bold());
|
||||
for (index, row) in self.settings_rows().iter().enumerate() {
|
||||
let settings_rows = self.settings_rows();
|
||||
let mut selected_line = None;
|
||||
for (index, row) in settings_rows.iter().enumerate() {
|
||||
if matches!(row, SettingsRow::MidiDevice { .. }) {
|
||||
continue;
|
||||
}
|
||||
let marker = if index == self.settings_selected {
|
||||
"▶"
|
||||
} else {
|
||||
|
|
@ -2776,7 +2868,11 @@ impl<C: MixerClient> LiveTui<C> {
|
|||
"already saved"
|
||||
}
|
||||
),
|
||||
SettingsRow::MidiDevice { .. } => continue,
|
||||
};
|
||||
if index == self.settings_selected {
|
||||
selected_line = Some(lines.len());
|
||||
}
|
||||
lines.push(Line::from(format!("{marker} {value}")).style(
|
||||
if index == self.settings_selected {
|
||||
Style::default().fg(theme.accent).bold()
|
||||
|
|
@ -2790,24 +2886,41 @@ impl<C: MixerClient> LiveTui<C> {
|
|||
if self.snapshot.devices.is_empty() {
|
||||
lines.push(Line::from(" No configured MIDI devices").fg(theme.muted));
|
||||
} else {
|
||||
lines.extend(self.snapshot.devices.iter().map(|device| {
|
||||
let backend = device
|
||||
.backend_id
|
||||
.as_deref()
|
||||
.map_or_else(String::new, |id| format!(" · {id}"));
|
||||
let error = device
|
||||
.error
|
||||
.as_deref()
|
||||
.map_or_else(String::new, |message| format!(" · {message}"));
|
||||
Line::from(format!(
|
||||
" {} — {}{}{}",
|
||||
device.label, device.status, backend, error
|
||||
))
|
||||
}));
|
||||
for (index, row) in settings_rows.iter().enumerate() {
|
||||
let SettingsRow::MidiDevice { id } = row else {
|
||||
continue;
|
||||
};
|
||||
let Some(device) = self.snapshot.devices.iter().find(|device| &device.id == id)
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
let selected = index == self.settings_selected;
|
||||
if selected {
|
||||
selected_line = Some(lines.len());
|
||||
}
|
||||
lines.push(
|
||||
Line::from(format!(
|
||||
"{} {} — {} [Enter]",
|
||||
if selected { "▶" } else { " " },
|
||||
device.label,
|
||||
device.status
|
||||
))
|
||||
.style(if selected {
|
||||
Style::default().fg(theme.accent).bold()
|
||||
} else {
|
||||
Style::default().fg(theme.foreground)
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
let scroll = selected_line
|
||||
.unwrap_or_default()
|
||||
.saturating_add(1)
|
||||
.saturating_sub(usize::from(area.height));
|
||||
Paragraph::new(Text::from(lines))
|
||||
.style(Style::default().fg(theme.foreground))
|
||||
.wrap(Wrap { trim: false })
|
||||
.scroll((u16::try_from(scroll).unwrap_or(u16::MAX), 0))
|
||||
.render(area, buf);
|
||||
}
|
||||
|
||||
|
|
@ -4397,10 +4510,90 @@ mod tests {
|
|||
assert!(rendered.contains("Show hidden faders none"));
|
||||
assert!(!rendered.contains("Apply draft"));
|
||||
assert!(rendered.contains("Save changes"));
|
||||
assert!(rendered.contains("Desk controller — connected · 20:0"));
|
||||
assert!(rendered.contains("Desk controller — connected [Enter]"));
|
||||
assert!(!rendered.contains("Applications"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn midi_device_details_popup_assigns_the_default_controller() {
|
||||
let edits = Arc::new(Mutex::new(Vec::new()));
|
||||
let mut snapshot = DemoClient::default().view();
|
||||
snapshot.configuration.default_controller = Some("desk-left".into());
|
||||
snapshot.devices = vec![
|
||||
MidiDevice {
|
||||
id: "desk-left".into(),
|
||||
label: "Left controller".into(),
|
||||
status: "connected".into(),
|
||||
backend_id: Some("20:0".into()),
|
||||
error: None,
|
||||
},
|
||||
MidiDevice {
|
||||
id: "desk-right".into(),
|
||||
label: "Right controller".into(),
|
||||
status: "missing".into(),
|
||||
backend_id: None,
|
||||
error: Some("connect the controller".into()),
|
||||
},
|
||||
];
|
||||
let mut app = LiveTui::new(LayoutClient {
|
||||
snapshot,
|
||||
edits: Arc::clone(&edits),
|
||||
})
|
||||
.unwrap();
|
||||
app.handle_key_event(press(KeyCode::Tab));
|
||||
for _ in 0..5 {
|
||||
app.handle_key_event(press(KeyCode::Down));
|
||||
}
|
||||
app.handle_key_event(press(KeyCode::Enter));
|
||||
|
||||
let area = Rect::new(0, 0, 100, 24);
|
||||
let mut buffer = Buffer::empty(area);
|
||||
(&app).render(area, &mut buffer);
|
||||
let rendered = buffer
|
||||
.content
|
||||
.iter()
|
||||
.map(|cell| cell.symbol())
|
||||
.collect::<String>();
|
||||
assert!(rendered.contains("MIDI device details"));
|
||||
assert!(rendered.contains("Left controller"));
|
||||
assert!(rendered.contains("Device ID desk-left"));
|
||||
assert!(rendered.contains("Backend port 20:0"));
|
||||
assert!(rendered.contains("Default controller true"));
|
||||
|
||||
app.handle_key_event(press(KeyCode::Enter));
|
||||
assert_eq!(app.snapshot.configuration.default_controller, None);
|
||||
app.handle_key_event(press(KeyCode::Esc));
|
||||
app.handle_key_event(press(KeyCode::Down));
|
||||
app.handle_key_event(press(KeyCode::Enter));
|
||||
let mut second_buffer = Buffer::empty(area);
|
||||
(&app).render(area, &mut second_buffer);
|
||||
let second_rendered = second_buffer
|
||||
.content
|
||||
.iter()
|
||||
.map(|cell| cell.symbol())
|
||||
.collect::<String>();
|
||||
assert!(second_rendered.contains("Right controller"));
|
||||
assert!(second_rendered.contains("Status missing"));
|
||||
assert!(second_rendered.contains("Error connect the controller"));
|
||||
assert!(second_rendered.contains("Default controller false"));
|
||||
app.handle_key_event(press(KeyCode::Right));
|
||||
assert_eq!(
|
||||
app.snapshot.configuration.default_controller.as_deref(),
|
||||
Some("desk-right")
|
||||
);
|
||||
|
||||
let edits = edits.lock().unwrap();
|
||||
assert!(edits.iter().any(|edit| matches!(
|
||||
edit,
|
||||
ConfigurationEdit::SetDefaultController { surface: None }
|
||||
)));
|
||||
assert!(edits.iter().any(|edit| matches!(
|
||||
edit,
|
||||
ConfigurationEdit::SetDefaultController { surface: Some(id) }
|
||||
if id == "desk-right"
|
||||
)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn configuration_tab_changes_theme_without_raw_object_editors() {
|
||||
let edits = Arc::new(Mutex::new(Vec::new()));
|
||||
|
|
|
|||
Loading…
Reference in New Issue