feat: fold MIDI unbind into the learn prompt
M9.5: Remove separate Unlearn rows. U in a locally opened Learn MIDI prompt cancels capture and removes only that fader action; Esc cancels unchanged. Retain the controller for relearning and document the compact workflow. Tests: updated guided-editor regression fails before implementation; new volume/mute scope, cancel and relearn regression passes. cargo fmt --all -- --check, cargo check --workspace --all-targets --all-features, cargo test --workspace --all-targets --all-features --quiet (48 TUI tests, two opt-in hardware tests ignored), cargo test --workspace --doc --all-features, cargo clippy --workspace --all-targets --all-features -- -D warnings, and cargo build --workspace --release --all-features all pass.
This commit is contained in:
parent
dc27b764fc
commit
2b725ca82f
|
|
@ -604,10 +604,11 @@ presents domain fields rather than a serialized command:
|
|||
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
|
||||
actions.
|
||||
- **Volume control:** controller selection and Learn MIDI. The learn prompt
|
||||
offers `U` to unbind the current volume assignment and `Esc` to cancel.
|
||||
- **Mute control:** controller selection and Learn MIDI, with the same prompt
|
||||
shortcuts scoped to the mute assignment. Unbinding cancels capture first,
|
||||
preserves the other action, and retains the selected controller for relearning.
|
||||
- **Size:** Slim, Bordered slim, Standard, or Thick vertical presentation for
|
||||
this fader.
|
||||
- **Visibility:** Hide from mixer or Show in mixer without changing routing.
|
||||
|
|
|
|||
|
|
@ -289,6 +289,11 @@ lights an LED as if it succeeded. Reconnect sends the current state again;
|
|||
unchanged states are deduplicated. Both note and CC feedback use 1-based
|
||||
channels and values from 0–127.
|
||||
|
||||
In the fader editor, open **Learn volume MIDI** or **Learn mute MIDI** to change
|
||||
that assignment. Press `U` in the learn prompt to unbind it, or `Esc` to cancel
|
||||
without changing it. Unbinding leaves the other action intact and keeps the
|
||||
controller selected for relearning. Save the draft to persist and activate it.
|
||||
|
||||
LED values are device-specific: a note velocity can mean a color or animation,
|
||||
so 127 is not a universal “on” value. The APC MINI example uses its configured
|
||||
green value. Relearning a mute binding moves its feedback assignment to the new
|
||||
|
|
|
|||
9
task.md
9
task.md
|
|
@ -442,8 +442,8 @@ Dependencies: M8, M2, M1.
|
|||
- [x] **M9.5 Guided fader editor:** replace pipe-delimited table commands with a
|
||||
selected-fader form. Application faders edit capture field/mode/pattern;
|
||||
groups select eligible application faders and show the absolute group mode;
|
||||
volume and mute assignments each expose controller selection, Learn MIDI, and
|
||||
Unlearn MIDI as distinct actions. Tests: editing one field preserves unrelated
|
||||
volume and mute assignments each expose controller selection and Learn MIDI;
|
||||
`U` in the learn prompt unbinds that action. Tests: editing one field preserves unrelated
|
||||
selectors/bindings, unlearn removes only the selected action, learn conflicts
|
||||
preserve the draft, and group selection translates to deduplicated
|
||||
application IDs.
|
||||
|
|
@ -453,8 +453,9 @@ Dependencies: M8, M2, M1.
|
|||
than requiring the full value to be erased;
|
||||
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;
|
||||
controller and Learn MIDI actions. Learning opens a modal prompt for a fader
|
||||
movement or button press, with `U` to unbind and `Esc` to cancel unchanged.
|
||||
Unbinding cancels capture and keeps the controller available for relearning;
|
||||
relearning atomically replaces only the chosen action, and validation
|
||||
conflicts retain the draft. Visibility uses the same form.
|
||||
The form also persists a per-fader Slim, Bordered slim, Standard, or Thick
|
||||
|
|
|
|||
160
tui/src/lib.rs
160
tui/src/lib.rs
|
|
@ -1267,6 +1267,7 @@ pub struct LiveTui<C> {
|
|||
profile_picker: Option<ProfilePicker>,
|
||||
midi_device_details: Option<String>,
|
||||
controller_selections: BTreeMap<(String, String), String>,
|
||||
midi_learn_target: Option<(String, String)>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
|
||||
|
|
@ -1434,12 +1435,6 @@ enum FaderEditorRow {
|
|||
surface: Option<String>,
|
||||
value: String,
|
||||
},
|
||||
BindingUnlearn {
|
||||
action: &'static str,
|
||||
label: &'static str,
|
||||
configured: bool,
|
||||
surface: Option<String>,
|
||||
},
|
||||
Visibility {
|
||||
hidden: bool,
|
||||
},
|
||||
|
|
@ -1713,6 +1708,7 @@ impl<C: MixerClient> LiveTui<C> {
|
|||
profile_picker: None,
|
||||
midi_device_details: None,
|
||||
controller_selections: BTreeMap::new(),
|
||||
midi_learn_target: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1743,6 +1739,11 @@ impl<C: MixerClient> LiveTui<C> {
|
|||
}
|
||||
|
||||
fn replace_snapshot(&mut self, mut snapshot: MixerSnapshot) {
|
||||
if self.snapshot.configuration.learning.is_some()
|
||||
&& snapshot.configuration.learning.is_none()
|
||||
{
|
||||
self.midi_learn_target = None;
|
||||
}
|
||||
let selected_id = self.selected_layout_id();
|
||||
self.client_error.clone_from(&snapshot.error);
|
||||
if self.theme_override {
|
||||
|
|
@ -1876,8 +1877,10 @@ impl<C: MixerClient> LiveTui<C> {
|
|||
return;
|
||||
}
|
||||
if self.snapshot.configuration.learning.is_some() {
|
||||
if matches!(key_event.code, KeyCode::Esc | KeyCode::Char('c')) {
|
||||
self.cancel_midi_learn();
|
||||
match key_event.code {
|
||||
KeyCode::Esc | KeyCode::Char('c') => self.cancel_midi_learn(),
|
||||
KeyCode::Char('u' | 'U') => self.unbind_learning_target(),
|
||||
_ => {}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
@ -2669,6 +2672,22 @@ impl<C: MixerClient> LiveTui<C> {
|
|||
}
|
||||
}
|
||||
|
||||
fn unbind_learning_target(&mut self) {
|
||||
let Some((fader, action)) = self.midi_learn_target.clone() else {
|
||||
return;
|
||||
};
|
||||
// Cancel capture before removing its assignment. The buffered client
|
||||
// preserves these operations in the configuration FIFO.
|
||||
match self.client.cancel_midi_learn() {
|
||||
Ok(snapshot) => {
|
||||
self.replace_snapshot(snapshot);
|
||||
self.midi_learn_target = None;
|
||||
self.apply_layout_edit(ConfigurationEdit::RemoveBinding { fader, action });
|
||||
}
|
||||
Err(error) => self.client_error = Some(error.to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
fn change_theme(&mut self, theme: ThemeName) {
|
||||
self.theme = theme;
|
||||
self.theme_override = true;
|
||||
|
|
@ -2790,14 +2809,8 @@ impl<C: MixerClient> LiveTui<C> {
|
|||
rows.push(FaderEditorRow::BindingLearn {
|
||||
action,
|
||||
label,
|
||||
surface: surface.clone(),
|
||||
value: message,
|
||||
});
|
||||
rows.push(FaderEditorRow::BindingUnlearn {
|
||||
action,
|
||||
label,
|
||||
configured: binding.is_some(),
|
||||
surface,
|
||||
value: message,
|
||||
});
|
||||
}
|
||||
let (hidden, density) = self
|
||||
|
|
@ -2952,29 +2965,20 @@ impl<C: MixerClient> LiveTui<C> {
|
|||
self.client_error = Some("choose a controller before learning MIDI".to_owned());
|
||||
return;
|
||||
};
|
||||
match self
|
||||
.client
|
||||
.start_midi_learn(surface, fader, action.to_owned())
|
||||
{
|
||||
Ok(snapshot) => self.replace_snapshot(snapshot),
|
||||
match self.client.start_midi_learn(
|
||||
surface.clone(),
|
||||
fader.clone(),
|
||||
action.to_owned(),
|
||||
) {
|
||||
Ok(snapshot) => {
|
||||
self.replace_snapshot(snapshot);
|
||||
self.controller_selections
|
||||
.insert((fader.clone(), action.to_owned()), surface);
|
||||
self.midi_learn_target = Some((fader, action.to_owned()));
|
||||
}
|
||||
Err(error) => self.client_error = Some(error.to_string()),
|
||||
}
|
||||
}
|
||||
FaderEditorRow::BindingUnlearn {
|
||||
action,
|
||||
configured: true,
|
||||
surface,
|
||||
..
|
||||
} => {
|
||||
if let Some(surface) = surface {
|
||||
self.controller_selections
|
||||
.insert((fader.clone(), action.to_owned()), surface);
|
||||
}
|
||||
self.apply_layout_edit(ConfigurationEdit::RemoveBinding {
|
||||
fader,
|
||||
action: action.to_owned(),
|
||||
});
|
||||
}
|
||||
FaderEditorRow::Visibility { hidden } => {
|
||||
self.apply_layout_edit(ConfigurationEdit::SetFaderHidden {
|
||||
id: fader,
|
||||
|
|
@ -4070,16 +4074,6 @@ impl<C: MixerClient> LiveTui<C> {
|
|||
FaderEditorRow::BindingLearn { label, value, .. } => {
|
||||
format!("{marker} Learn {label} MIDI {value} [Enter]")
|
||||
}
|
||||
FaderEditorRow::BindingUnlearn {
|
||||
label, configured, ..
|
||||
} => format!(
|
||||
"{marker} Unlearn {label} MIDI {}",
|
||||
if *configured {
|
||||
"[Enter]"
|
||||
} else {
|
||||
"not assigned"
|
||||
}
|
||||
),
|
||||
FaderEditorRow::Visibility { hidden } => format!(
|
||||
"{marker} Visibility {} [Enter to {}]",
|
||||
if *hidden { "Hidden" } else { "Shown" },
|
||||
|
|
@ -4517,7 +4511,11 @@ impl<C: MixerClient> LiveTui<C> {
|
|||
.block(
|
||||
Block::bordered()
|
||||
.title(" Learn MIDI control ".fg(theme.accent).bold())
|
||||
.title_bottom(" Esc cancel ".fg(theme.muted))
|
||||
.title_bottom(if self.midi_learn_target.is_some() {
|
||||
" U unbind · Esc cancel ".fg(theme.muted)
|
||||
} else {
|
||||
" Esc cancel ".fg(theme.muted)
|
||||
})
|
||||
.border_set(border::DOUBLE)
|
||||
.border_style(Style::default().fg(theme.accent))
|
||||
.style(Style::default().bg(theme.background)),
|
||||
|
|
@ -6509,11 +6507,11 @@ mod tests {
|
|||
assert!(rendered.contains("Capture 1"));
|
||||
assert!(rendered.contains("Volume controller"));
|
||||
assert!(rendered.contains("Learn volume MIDI"));
|
||||
assert!(rendered.contains("Unlearn volume MIDI"));
|
||||
assert!(!rendered.contains("Unlearn volume MIDI"));
|
||||
assert!(rendered.contains("Mute controller"));
|
||||
assert!(rendered.contains("Mute controller Default · Spare controller"));
|
||||
assert!(rendered.contains("Learn mute MIDI"));
|
||||
assert!(rendered.contains("Unlearn mute MIDI"));
|
||||
assert!(!rendered.contains("Unlearn mute MIDI"));
|
||||
assert!(rendered.contains("Size Standard"));
|
||||
assert!(rendered.contains("Visibility"));
|
||||
|
||||
|
|
@ -6597,10 +6595,19 @@ mod tests {
|
|||
.collect::<String>();
|
||||
assert!(waiting_rendered.contains("Learn MIDI control"));
|
||||
assert!(waiting_rendered.contains("Move a fader or press a button"));
|
||||
assert!(waiting_rendered.contains("U unbind"));
|
||||
app.handle_key_event(press(KeyCode::Esc));
|
||||
|
||||
app.handle_key_event(press(KeyCode::Down));
|
||||
assert!(
|
||||
!edits
|
||||
.lock()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.any(|edit| matches!(edit, ConfigurationEdit::RemoveBinding { .. }))
|
||||
);
|
||||
app.handle_key_event(press(KeyCode::Enter));
|
||||
app.handle_key_event(press(KeyCode::Char('u')));
|
||||
assert!(app.snapshot.configuration.learning.is_none());
|
||||
|
||||
let edits = edits.lock().unwrap();
|
||||
assert!(edits.iter().any(|edit| matches!(
|
||||
|
|
@ -6630,6 +6637,61 @@ mod tests {
|
|||
)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn learn_popup_unbinds_only_its_action_and_keeps_controller_for_relearning() {
|
||||
let mut snapshot = DemoClient::default().view();
|
||||
snapshot.configuration.mixer_layout = vec![MixerLayoutEntry::Fader {
|
||||
fader: "test-fader".into(),
|
||||
hidden: false,
|
||||
density: FaderDensity::Standard,
|
||||
}];
|
||||
snapshot.configuration.faders = vec![ConfiguredFader {
|
||||
id: "test-fader".into(),
|
||||
target: snapshot.items[0].id.clone(),
|
||||
pickup: true,
|
||||
pickup_tolerance: 0.02,
|
||||
}];
|
||||
snapshot.configuration.bindings = ["volume", "toggle_mute"]
|
||||
.into_iter()
|
||||
.map(|action| ConfiguredBinding {
|
||||
surface: "desk".into(),
|
||||
fader: "test-fader".into(),
|
||||
action: action.into(),
|
||||
message: "cc ch1 #7".into(),
|
||||
kind: "cc".into(),
|
||||
channel: 1,
|
||||
number: 7,
|
||||
})
|
||||
.collect();
|
||||
let edits = Arc::new(Mutex::new(Vec::new()));
|
||||
let mut app = LiveTui::new(LayoutClient { snapshot, edits }).unwrap();
|
||||
app.handle_key_event(press(KeyCode::Char('e')));
|
||||
for action in ["toggle_mute", "volume"] {
|
||||
let selected = app.fader_editor_rows().iter().position(|row| matches!(row, FaderEditorRow::BindingLearn { action: row_action, .. } if *row_action == action)).unwrap();
|
||||
app.fader_editor.as_mut().unwrap().selected = selected;
|
||||
let before = app.snapshot.configuration.bindings.clone();
|
||||
app.handle_key_event(press(KeyCode::Enter));
|
||||
app.handle_key_event(press(KeyCode::Esc));
|
||||
assert_eq!(app.snapshot.configuration.bindings, before);
|
||||
app.handle_key_event(press(KeyCode::Enter));
|
||||
app.handle_key_event(press(KeyCode::Char('U')));
|
||||
assert!(app.snapshot.configuration.learning.is_none());
|
||||
assert_eq!(
|
||||
app.snapshot.configuration.bindings,
|
||||
before
|
||||
.into_iter()
|
||||
.filter(|binding| binding.action != action)
|
||||
.collect::<Vec<_>>()
|
||||
);
|
||||
app.handle_key_event(press(KeyCode::Enter));
|
||||
assert_eq!(
|
||||
app.snapshot.configuration.learning,
|
||||
Some(format!("desk -> test-fader ({action})"))
|
||||
);
|
||||
app.handle_key_event(press(KeyCode::Esc));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unassigned_midi_actions_learn_from_the_configured_default_controller() {
|
||||
let mut snapshot = DemoClient::default().view();
|
||||
|
|
|
|||
Loading…
Reference in New Issue