diff --git a/README.md b/README.md index 3e653ce..669c335 100644 --- a/README.md +++ b/README.md @@ -83,8 +83,9 @@ restoration steps. The mixer is also the primary configuration surface. A adds a separator, E edits a selected fader or separator, D removes a selected separator, and `h` hides a fader. Fader editing provides capture Field/Exact-or-Regex/Pattern -controls, group membership and mode, and separate controller, Learn MIDI, and -Unlearn MIDI actions for both volume and mute. Learning opens a waiting popup +controls, a checked multi-select popup for group membership, group mode, and +separate controller, Learn MIDI, and Unlearn MIDI actions for both volume and +mute. Learning opens a waiting popup and captures the next supported fader movement or button press from the selected controller. Capture patterns open in a cursor-aware popup, so individual characters can be inserted or removed without replacing the whole value. The diff --git a/architecture.md b/architecture.md index 9e8ef42..8b52a7b 100644 --- a/architecture.md +++ b/architecture.md @@ -463,8 +463,9 @@ line. Editing a fader presents domain fields rather than a serialized command: - **Capture:** application selector field, exact/regex mode, and pattern. Pattern values open in a cursor-aware modal with insertion, Backspace, Delete, - Home/End, accept, and cancel controls; group faders instead present member - faders and the currently available group mode. + Home/End, accept, and cancel controls; group faders instead present a member + summary that opens a multi-select popup, plus the currently available group + mode. - **Volume control:** separate controller selection, Learn MIDI, and Unlearn MIDI actions. - **Mute control:** separate controller selection, Learn MIDI, and Unlearn MIDI @@ -472,12 +473,12 @@ line. Editing a fader presents domain fields rather than a serialized command: - **Size:** Slim, Standard, or Thick vertical presentation for this fader. - **Visibility:** Hide from mixer or Show in mixer without changing routing. -Groups select application-targeting faders in the UI; the server stores their -deduplicated application IDs because group membership is an audio-domain -relationship, not a dependency on a particular physical control. The editor -shows this translation and prevents group or output faders from being chosen as -members. Absolute remains the only selectable group mode until the reserved -relative-mode runtime work is complete. +Groups select application-targeting faders in a checked multi-select popup; the +server stores their deduplicated application IDs because group membership is an +audio-domain relationship, not a dependency on a particular physical control. +The popup shows this translation and prevents group or output faders from being +chosen as members. Absolute remains the only selectable group mode until the +reserved relative-mode runtime work is complete. The secondary Config tab is not an alternative object editor. It presents profile theme selection, a popup listing all hidden faders for individual diff --git a/task.md b/task.md index fc79904..32d89f0 100644 --- a/task.md +++ b/task.md @@ -398,8 +398,9 @@ Dependencies: M8, M2, M1. Field, Exact/Regex, and Pattern separately while preserving other selectors; Pattern opens a cursor-aware modal for local insertion and deletion rather than requiring the full value to be erased; - groups show application-fader membership and the currently supported Absolute - mode. Volume and Mute show separate controller, Learn MIDI, and Unlearn MIDI + groups edit application-fader membership in a checked multi-select popup and + show the currently supported Absolute mode. Volume and Mute show separate + controller, Learn MIDI, and Unlearn MIDI actions. Learning opens a modal prompt for a fader movement or button press; relearning atomically replaces only the chosen action, and validation conflicts retain the draft. Visibility uses the same form. diff --git a/tui/src/lib.rs b/tui/src/lib.rs index fca4165..5a66c38 100644 --- a/tui/src/lib.rs +++ b/tui/src/lib.rs @@ -823,6 +823,7 @@ pub struct LiveTui { capture_editor: Option, pattern_editor: Option, controller_picker: Option, + group_member_picker: Option, hidden_fader_picker: Option, midi_device_details: Option, controller_selections: BTreeMap<(String, String), String>, @@ -880,6 +881,20 @@ struct ControllerPicker { selected: usize, } +#[derive(Clone, Debug, Eq, PartialEq)] +struct GroupMemberPicker { + group: String, + selected: usize, +} + +#[derive(Clone, Debug, Eq, PartialEq)] +struct GroupMemberChoice { + application: String, + fader: String, + label: String, + included: bool, +} + #[derive(Clone, Debug, Eq, PartialEq)] struct HiddenFaderPicker { selected: usize, @@ -893,11 +908,10 @@ enum FaderEditorRow { pattern: String, regex: bool, }, - GroupMember { + GroupMembers { group: String, - application: String, - label: String, - included: bool, + included: usize, + available: usize, }, GroupMode { mode: GroupVolumeMode, @@ -1005,6 +1019,7 @@ impl LiveTui { capture_editor: None, pattern_editor: None, controller_picker: None, + group_member_picker: None, hidden_fader_picker: None, midi_device_details: None, controller_selections: BTreeMap::new(), @@ -1145,6 +1160,10 @@ impl LiveTui { self.handle_controller_picker_key(key_event.code); return; } + if self.group_member_picker.is_some() { + self.handle_group_member_picker_key(key_event.code); + return; + } if self.hidden_fader_picker.is_some() { self.handle_hidden_fader_picker_key(key_event.code); return; @@ -1611,30 +1630,12 @@ impl LiveTui { .iter() .find(|group| group.id == fader.target.id) { - let mut seen = std::collections::BTreeSet::new(); - for application_fader in &self.snapshot.configuration.faders { - if application_fader.target.kind != MixerObjectKind::Application - || !seen.insert(application_fader.target.id.as_str()) - { - continue; - } - let label = self - .snapshot - .configuration - .applications - .iter() - .find(|application| application.id == application_fader.target.id) - .map_or_else( - || application_fader.target.id.clone(), - |application| application.label.clone(), - ); - rows.push(FaderEditorRow::GroupMember { - group: group.id.clone(), - application: application_fader.target.id.clone(), - label, - included: group.members.contains(&application_fader.target.id), - }); - } + let choices = self.group_member_choices(&group.id); + rows.push(FaderEditorRow::GroupMembers { + group: group.id.clone(), + included: choices.iter().filter(|choice| choice.included).count(), + available: choices.len(), + }); rows.push(FaderEditorRow::GroupMode { mode: group.volume_mode, }); @@ -1713,6 +1714,46 @@ impl LiveTui { rows } + fn group_member_choices(&self, group: &str) -> Vec { + let members = self + .snapshot + .configuration + .groups + .iter() + .find(|candidate| candidate.id == group) + .map(|configured| configured.members.as_slice()) + .unwrap_or_default(); + let mut seen = std::collections::BTreeSet::new(); + self.snapshot + .configuration + .faders + .iter() + .filter_map(|fader| { + if fader.target.kind != MixerObjectKind::Application + || !seen.insert(fader.target.id.as_str()) + { + return None; + } + let label = self + .snapshot + .configuration + .applications + .iter() + .find(|application| application.id == fader.target.id) + .map_or_else( + || fader.target.id.clone(), + |application| application.label.clone(), + ); + Some(GroupMemberChoice { + application: fader.target.id.clone(), + fader: fader.id.clone(), + label, + included: members.contains(&fader.target.id), + }) + }) + .collect() + } + fn handle_fader_editor_key(&mut self, code: KeyCode) { if code == KeyCode::Esc { self.fader_editor = None; @@ -1757,33 +1798,8 @@ impl LiveTui { selected: 0, }); } - FaderEditorRow::GroupMember { - group, - application, - included, - .. - } => { - let Some(configured) = self - .snapshot - .configuration - .groups - .iter() - .find(|candidate| candidate.id == group) - else { - return; - }; - let mut members = configured.members.clone(); - if included { - members.retain(|member| member != &application); - } else { - members.push(application); - } - self.apply_layout_edit(ConfigurationEdit::Group { - existing: true, - id: configured.id.clone(), - label: configured.label.clone(), - members, - }); + FaderEditorRow::GroupMembers { group, .. } => { + self.group_member_picker = Some(GroupMemberPicker { group, selected: 0 }); } FaderEditorRow::BindingController { action, .. } => { if self.snapshot.devices.is_empty() { @@ -1860,6 +1876,60 @@ impl LiveTui { } } + fn handle_group_member_picker_key(&mut self, code: KeyCode) { + if code == KeyCode::Esc { + self.group_member_picker = None; + return; + } + let Some(picker) = &self.group_member_picker else { + return; + }; + let group = picker.group.clone(); + let choices = self.group_member_choices(&group); + let Some(picker) = &mut self.group_member_picker else { + return; + }; + match code { + KeyCode::Up | KeyCode::Char('k') => { + picker.selected = picker.selected.saturating_sub(1); + } + KeyCode::Down | KeyCode::Char('j') => { + picker.selected = (picker.selected + 1).min(choices.len().saturating_sub(1)); + } + KeyCode::Enter | KeyCode::Char(' ') => { + let Some(choice) = choices.get(picker.selected) else { + return; + }; + self.toggle_group_member(&group, choice); + } + _ => {} + } + } + + fn toggle_group_member(&mut self, group: &str, choice: &GroupMemberChoice) { + let Some(configured) = self + .snapshot + .configuration + .groups + .iter() + .find(|candidate| candidate.id == group) + else { + return; + }; + let mut members = configured.members.clone(); + if choice.included { + members.retain(|member| member != &choice.application); + } else { + members.push(choice.application.clone()); + } + self.apply_layout_edit(ConfigurationEdit::Group { + existing: true, + id: configured.id.clone(), + label: configured.label.clone(), + members, + }); + } + fn handle_capture_key(&mut self, code: KeyCode) { if code == KeyCode::Esc { self.capture_editor = None; @@ -2285,6 +2355,9 @@ impl Widget for &LiveTui { if self.controller_picker.is_some() { self.render_controller_picker(area, buf); } + if self.group_member_picker.is_some() { + self.render_group_member_picker(area, buf); + } if self.hidden_fader_picker.is_some() { self.render_hidden_fader_picker(area, buf); } @@ -2517,11 +2590,12 @@ impl LiveTui { if *regex { "regex" } else { "exact" }, pattern ), - FaderEditorRow::GroupMember { - label, included, .. + FaderEditorRow::GroupMembers { + included, + available, + .. } => format!( - "{marker} [{}] Group member {label}", - if *included { "x" } else { " " } + "{marker} Members {included} of {available} selected [Enter to edit]" ), FaderEditorRow::GroupMode { mode } => { format!("{marker} Group mode {}", mode.label()) @@ -2577,6 +2651,58 @@ impl LiveTui { .render(popup, buf); } + fn render_group_member_picker(&self, area: Rect, buf: &mut Buffer) { + let Some(picker) = &self.group_member_picker else { + return; + }; + let theme = self.theme.palette(); + let choices = self.group_member_choices(&picker.group); + let height = u16::try_from(choices.len().saturating_add(4)) + .unwrap_or(u16::MAX) + .min(area.height); + let popup = centered_rect(area, 70, height.max(5)); + let visible_rows = usize::from(popup.height.saturating_sub(2)).max(1); + let first_visible = picker + .selected + .saturating_add(1) + .saturating_sub(visible_rows); + let lines = if choices.is_empty() { + vec![Line::from("No application faders are available.").fg(theme.muted)] + } else { + choices + .iter() + .enumerate() + .skip(first_visible) + .take(visible_rows) + .map(|(index, choice)| { + Line::from(format!( + "{} [{}] {} · {}", + if index == picker.selected { "▶" } else { " " }, + if choice.included { "x" } else { " " }, + choice.label, + choice.fader + )) + .style(if index == picker.selected { + Style::default().fg(theme.accent).bold() + } else { + Style::default().fg(theme.foreground) + }) + }) + .collect::>() + }; + Clear.render(popup, buf); + Paragraph::new(Text::from(lines)) + .block( + Block::bordered() + .title(" Group members ".fg(theme.accent).bold()) + .title_bottom(" ↑↓ select · Enter/Space toggle · Esc back ".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_capture_editor(&self, area: Rect, buf: &mut Buffer) { let Some(editor) = &self.capture_editor else { return; @@ -3567,6 +3693,17 @@ mod tests { selector.regex = *regex; } } + ConfigurationEdit::Group { id, members, .. } => { + if let Some(group) = self + .snapshot + .configuration + .groups + .iter_mut() + .find(|group| group.id == *id) + { + group.members.clone_from(members); + } + } ConfigurationEdit::RemoveBinding { fader, action } => self .snapshot .configuration @@ -4434,7 +4571,7 @@ mod tests { } #[test] - fn group_fader_form_selects_application_faders_and_shows_mode() { + fn group_fader_form_edits_application_faders_in_a_popup_and_shows_mode() { let mut snapshot = DemoClient::default().view(); snapshot.items[0].id = MixerObjectId { kind: MixerObjectKind::Group, @@ -4506,16 +4643,49 @@ mod tests { .iter() .map(|cell| cell.symbol()) .collect::(); - assert!(rendered.contains("[x] Group member Music")); - assert!(rendered.contains("[ ] Group member Browser")); + assert!(rendered.contains("Members 1 of 2 selected")); + assert!(!rendered.contains("Group member Music")); + assert!(!rendered.contains("Group member Browser")); assert!(rendered.contains("Group mode Relative")); + app.handle_key_event(press(KeyCode::Enter)); + let mut popup_buffer = Buffer::empty(area); + (&app).render(area, &mut popup_buffer); + let popup = popup_buffer + .content + .iter() + .map(|cell| cell.symbol()) + .collect::(); + assert!(popup.contains("Group members")); + assert!(popup.contains("[x] Music · music-fader")); + assert!(popup.contains("[ ] Browser · browser-fader")); + app.handle_key_event(press(KeyCode::Enter)); assert!(edits.lock().unwrap().iter().any(|edit| matches!( edit, ConfigurationEdit::Group { id, members, .. } if id == "media" && members.is_empty() ))); + + let mut toggled_buffer = Buffer::empty(area); + (&app).render(area, &mut toggled_buffer); + let toggled = toggled_buffer + .content + .iter() + .map(|cell| cell.symbol()) + .collect::(); + assert!(toggled.contains("[ ] Music · music-fader")); + app.handle_key_event(press(KeyCode::Down)); + app.handle_key_event(press(KeyCode::Char(' '))); + assert!(edits.lock().unwrap().iter().any(|edit| matches!( + edit, + ConfigurationEdit::Group { id, members, .. } + if id == "media" && members == &["browser"] + ))); + + app.handle_key_event(press(KeyCode::Esc)); + assert!(app.group_member_picker.is_none()); + assert!(app.fader_editor.is_some()); } #[test]