feat: clarify MIDI binding controls
Split each volume and mute binding into controller selection, Learn MIDI, and Unlearn MIDI actions. Preserve the current message when changing controllers and show a modal prompt while waiting for the next supported control. 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; default/no-default/backend feature checks.
This commit is contained in:
parent
bcba3e96eb
commit
2fe7824203
16
README.md
16
README.md
|
|
@ -49,13 +49,15 @@ The mixer is also the primary configuration surface. Shift+Up/Down reorders the
|
|||
selected fader or separator; 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, separate Volume and Mute Learn/Unset actions, per-fader Size (`Slim`,
|
||||
`Standard`, or `Thick`), and visibility. Slim faders occupy one terminal row;
|
||||
Standard remains the compatible default. The Config tab is a settings/status
|
||||
page: change the session theme, restore individual hidden faders, inspect
|
||||
backend and MIDI-device state, and apply or save the server-owned draft. The
|
||||
old `Shift+h` hidden-list mode and pipe-delimited object editors are no longer
|
||||
used.
|
||||
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. The editor also
|
||||
provides per-fader Size (`Slim`, `Standard`, or `Thick`) and visibility. Slim
|
||||
faders occupy one terminal row; Standard remains the compatible default. The
|
||||
Config tab is a settings/status page: change the session theme, restore
|
||||
individual hidden faders, inspect backend and MIDI-device state, and apply or
|
||||
save the server-owned draft. The old `Shift+h` hidden-list mode and
|
||||
pipe-delimited object editors are no longer used.
|
||||
|
||||
# References
|
||||
|
||||
|
|
|
|||
|
|
@ -412,8 +412,10 @@ rather than a serialized command:
|
|||
|
||||
- **Capture:** application selector field, exact/regex mode, and pattern; group
|
||||
faders instead present member faders and the currently available group mode.
|
||||
- **Volume control:** current surface/message assignment with Learn and Unset.
|
||||
- **Mute control:** current surface/message assignment with Learn and Unset.
|
||||
- **Volume control:** separate controller selection, Learn MIDI, and Unlearn
|
||||
MIDI actions.
|
||||
- **Mute control:** separate controller selection, Learn MIDI, and Unlearn MIDI
|
||||
actions.
|
||||
- **Size:** Slim, Standard, or Thick vertical presentation for this fader.
|
||||
- **Visibility:** Hide from mixer or Show in mixer without changing routing.
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use std::io::{self, Read, Write};
|
|||
use serde::{Deserialize, Serialize, de::DeserializeOwned};
|
||||
use thiserror::Error;
|
||||
|
||||
pub const PROTOCOL_VERSION: u16 = 12;
|
||||
pub const PROTOCOL_VERSION: u16 = 13;
|
||||
pub const MAX_FRAME_BYTES: usize = 64 * 1024;
|
||||
|
||||
/// Kind of mixer object addressed by a client.
|
||||
|
|
@ -280,6 +280,9 @@ pub struct ConfiguredBinding {
|
|||
pub fader: String,
|
||||
pub action: String,
|
||||
pub message: String,
|
||||
pub kind: String,
|
||||
pub channel: u16,
|
||||
pub number: u16,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
|
||||
|
|
|
|||
|
|
@ -211,6 +211,13 @@ pub(crate) fn configuration_snapshot(
|
|||
binding.channel(),
|
||||
binding.number()
|
||||
),
|
||||
kind: match binding.message_kind() {
|
||||
fader_config::MessageKind::Cc => "cc",
|
||||
fader_config::MessageKind::Note => "note",
|
||||
}
|
||||
.to_owned(),
|
||||
channel: binding.channel(),
|
||||
number: binding.number(),
|
||||
})
|
||||
.collect(),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -185,6 +185,9 @@ impl IpcMixerClient {
|
|||
fader: binding.fader,
|
||||
action: binding.action,
|
||||
message: binding.message,
|
||||
kind: binding.kind,
|
||||
channel: binding.channel,
|
||||
number: binding.number,
|
||||
})
|
||||
.collect(),
|
||||
},
|
||||
|
|
@ -380,6 +383,21 @@ fn configuration_edit(edit: TuiConfigurationEdit) -> crate::ipc::ConfigurationEd
|
|||
pattern,
|
||||
regex,
|
||||
},
|
||||
TuiConfigurationEdit::SetBinding {
|
||||
surface,
|
||||
fader,
|
||||
action,
|
||||
kind,
|
||||
channel,
|
||||
number,
|
||||
} => IpcEdit::SetBinding {
|
||||
surface,
|
||||
fader,
|
||||
action,
|
||||
kind,
|
||||
channel,
|
||||
number,
|
||||
},
|
||||
TuiConfigurationEdit::RemoveBinding { fader, action } => {
|
||||
IpcEdit::RemoveBinding { fader, action }
|
||||
}
|
||||
|
|
|
|||
16
task.md
16
task.md
|
|
@ -371,16 +371,18 @@ 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 Learn and Unset. Tests: editing one
|
||||
field preserves unrelated selectors/bindings, unset removes only the selected
|
||||
action, learn conflicts preserve the draft, and group selection translates to
|
||||
deduplicated application IDs.
|
||||
volume and mute assignments each expose controller selection, Learn MIDI, and
|
||||
Unlearn MIDI as distinct actions. 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.
|
||||
`E` on a mixer fader opens a field-oriented form. Application capture edits
|
||||
Field, Exact/Regex, and Pattern separately while preserving other selectors;
|
||||
groups show application-fader membership and the currently supported Absolute
|
||||
mode. Volume and Mute show their assignments and provide surface-scoped Learn
|
||||
and action-scoped Unset. Visibility uses the same form. Relearning atomically
|
||||
replaces only the chosen action, and validation conflicts retain the draft.
|
||||
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.
|
||||
The form also persists a per-fader Slim, Standard, or Thick size in the mixer
|
||||
layout. Existing profiles default to Standard, while Slim renders in one
|
||||
terminal row.
|
||||
|
|
|
|||
382
tui/src/lib.rs
382
tui/src/lib.rs
|
|
@ -180,6 +180,9 @@ pub struct ConfiguredBinding {
|
|||
pub fader: String,
|
||||
pub action: String,
|
||||
pub message: String,
|
||||
pub kind: String,
|
||||
pub channel: u16,
|
||||
pub number: u16,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
|
|
@ -240,6 +243,14 @@ pub enum ConfigurationEdit {
|
|||
pattern: String,
|
||||
regex: bool,
|
||||
},
|
||||
SetBinding {
|
||||
surface: String,
|
||||
fader: String,
|
||||
action: String,
|
||||
kind: String,
|
||||
channel: u16,
|
||||
number: u16,
|
||||
},
|
||||
RemoveBinding {
|
||||
fader: String,
|
||||
action: String,
|
||||
|
|
@ -762,7 +773,8 @@ pub struct LiveTui<C> {
|
|||
settings_selected: usize,
|
||||
fader_editor: Option<FaderEditor>,
|
||||
capture_editor: Option<CaptureEditor>,
|
||||
learn_picker: Option<LearnPicker>,
|
||||
controller_picker: Option<ControllerPicker>,
|
||||
controller_selections: BTreeMap<(String, String), String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
|
||||
|
|
@ -803,7 +815,7 @@ struct CaptureEditor {
|
|||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
struct LearnPicker {
|
||||
struct ControllerPicker {
|
||||
fader: String,
|
||||
action: String,
|
||||
selected: usize,
|
||||
|
|
@ -826,11 +838,23 @@ enum FaderEditorRow {
|
|||
GroupMode {
|
||||
mode: GroupVolumeMode,
|
||||
},
|
||||
Binding {
|
||||
BindingController {
|
||||
action: &'static str,
|
||||
label: &'static str,
|
||||
value: String,
|
||||
},
|
||||
BindingLearn {
|
||||
action: &'static str,
|
||||
label: &'static str,
|
||||
surface: Option<String>,
|
||||
value: String,
|
||||
},
|
||||
BindingUnlearn {
|
||||
action: &'static str,
|
||||
label: &'static str,
|
||||
configured: bool,
|
||||
surface: Option<String>,
|
||||
},
|
||||
Visibility {
|
||||
hidden: bool,
|
||||
},
|
||||
|
|
@ -902,7 +926,8 @@ impl<C: MixerClient> LiveTui<C> {
|
|||
settings_selected: 0,
|
||||
fader_editor: None,
|
||||
capture_editor: None,
|
||||
learn_picker: None,
|
||||
controller_picker: None,
|
||||
controller_selections: BTreeMap::new(),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -1009,12 +1034,18 @@ 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();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if self.capture_editor.is_some() {
|
||||
self.handle_capture_key(key_event.code);
|
||||
return;
|
||||
}
|
||||
if self.learn_picker.is_some() {
|
||||
self.handle_learn_picker_key(key_event.code);
|
||||
if self.controller_picker.is_some() {
|
||||
self.handle_controller_picker_key(key_event.code);
|
||||
return;
|
||||
}
|
||||
if self.fader_editor.is_some() {
|
||||
|
|
@ -1365,27 +1396,49 @@ impl<C: MixerClient> LiveTui<C> {
|
|||
}
|
||||
MixerObjectKind::Output => {}
|
||||
}
|
||||
for (action, label) in [
|
||||
("volume", "Volume control"),
|
||||
("toggle_mute", "Mute control"),
|
||||
] {
|
||||
let value = self
|
||||
for (action, label) in [("volume", "volume"), ("toggle_mute", "mute")] {
|
||||
let binding = self
|
||||
.snapshot
|
||||
.configuration
|
||||
.bindings
|
||||
.iter()
|
||||
.filter(|binding| binding.fader == editor.fader && binding.action == action)
|
||||
.map(|binding| format!("{} · {}", binding.surface, binding.message))
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ");
|
||||
rows.push(FaderEditorRow::Binding {
|
||||
.find(|binding| binding.fader == editor.fader && binding.action == action);
|
||||
let key = (editor.fader.clone(), action.to_owned());
|
||||
let surface = self
|
||||
.controller_selections
|
||||
.get(&key)
|
||||
.cloned()
|
||||
.or_else(|| binding.map(|binding| binding.surface.clone()));
|
||||
let controller = surface.as_deref().map_or_else(
|
||||
|| "Not selected".to_owned(),
|
||||
|surface| {
|
||||
self.snapshot
|
||||
.devices
|
||||
.iter()
|
||||
.find(|device| device.id == surface)
|
||||
.map_or_else(|| surface.to_owned(), |device| device.label.clone())
|
||||
},
|
||||
);
|
||||
let message = binding.map_or_else(
|
||||
|| "Unassigned".to_owned(),
|
||||
|binding| binding.message.clone(),
|
||||
);
|
||||
rows.push(FaderEditorRow::BindingController {
|
||||
action,
|
||||
label,
|
||||
value: if value.is_empty() {
|
||||
"Unset".to_owned()
|
||||
} else {
|
||||
value
|
||||
},
|
||||
value: controller,
|
||||
});
|
||||
rows.push(FaderEditorRow::BindingLearn {
|
||||
action,
|
||||
label,
|
||||
surface: surface.clone(),
|
||||
value: message,
|
||||
});
|
||||
rows.push(FaderEditorRow::BindingUnlearn {
|
||||
action,
|
||||
label,
|
||||
configured: binding.is_some(),
|
||||
surface,
|
||||
});
|
||||
}
|
||||
let (hidden, density) = self
|
||||
|
|
@ -1421,13 +1474,12 @@ impl<C: MixerClient> LiveTui<C> {
|
|||
KeyCode::Down | KeyCode::Char('j') => {
|
||||
editor.selected = (editor.selected + 1).min(row_count.saturating_sub(1));
|
||||
}
|
||||
KeyCode::Enter | KeyCode::Char('l') => self.activate_fader_editor_row(false),
|
||||
KeyCode::Char('u') => self.activate_fader_editor_row(true),
|
||||
KeyCode::Enter => self.activate_fader_editor_row(),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn activate_fader_editor_row(&mut self, unset: bool) {
|
||||
fn activate_fader_editor_row(&mut self) {
|
||||
let Some(editor) = &self.fader_editor else {
|
||||
return;
|
||||
};
|
||||
|
|
@ -1442,7 +1494,7 @@ impl<C: MixerClient> LiveTui<C> {
|
|||
field,
|
||||
pattern,
|
||||
regex,
|
||||
} if !unset => {
|
||||
} => {
|
||||
self.capture_editor = Some(CaptureEditor {
|
||||
application,
|
||||
selector,
|
||||
|
|
@ -1457,7 +1509,7 @@ impl<C: MixerClient> LiveTui<C> {
|
|||
application,
|
||||
included,
|
||||
..
|
||||
} if !unset => {
|
||||
} => {
|
||||
let Some(configured) = self
|
||||
.snapshot
|
||||
.configuration
|
||||
|
|
@ -1480,30 +1532,72 @@ impl<C: MixerClient> LiveTui<C> {
|
|||
members,
|
||||
});
|
||||
}
|
||||
FaderEditorRow::Binding { action, .. } if unset => {
|
||||
FaderEditorRow::BindingController { action, .. } => {
|
||||
if self.snapshot.devices.is_empty() {
|
||||
self.client_error = Some("no configured MIDI surface is available".to_owned());
|
||||
} else {
|
||||
let selected = self
|
||||
.controller_selections
|
||||
.get(&(fader.clone(), action.to_owned()))
|
||||
.or_else(|| {
|
||||
self.snapshot
|
||||
.configuration
|
||||
.bindings
|
||||
.iter()
|
||||
.find(|binding| binding.fader == fader && binding.action == action)
|
||||
.map(|binding| &binding.surface)
|
||||
})
|
||||
.and_then(|surface| {
|
||||
self.snapshot
|
||||
.devices
|
||||
.iter()
|
||||
.position(|device| device.id == *surface)
|
||||
})
|
||||
.unwrap_or(0);
|
||||
self.controller_picker = Some(ControllerPicker {
|
||||
fader,
|
||||
action: action.to_owned(),
|
||||
selected,
|
||||
});
|
||||
}
|
||||
}
|
||||
FaderEditorRow::BindingLearn {
|
||||
action, surface, ..
|
||||
} => {
|
||||
let Some(surface) = surface else {
|
||||
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),
|
||||
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::Binding { action, .. } => {
|
||||
if self.snapshot.devices.is_empty() {
|
||||
self.client_error = Some("no configured MIDI surface is available".to_owned());
|
||||
} else {
|
||||
self.learn_picker = Some(LearnPicker {
|
||||
fader,
|
||||
action: action.to_owned(),
|
||||
selected: 0,
|
||||
});
|
||||
}
|
||||
}
|
||||
FaderEditorRow::Visibility { hidden } if !unset => {
|
||||
FaderEditorRow::Visibility { hidden } => {
|
||||
self.apply_layout_edit(ConfigurationEdit::SetFaderHidden {
|
||||
id: fader,
|
||||
hidden: !hidden,
|
||||
});
|
||||
}
|
||||
FaderEditorRow::Density { density } if !unset => {
|
||||
FaderEditorRow::Density { density } => {
|
||||
self.apply_layout_edit(ConfigurationEdit::SetFaderDensity {
|
||||
id: fader,
|
||||
density: density.next(),
|
||||
|
|
@ -1555,12 +1649,12 @@ impl<C: MixerClient> LiveTui<C> {
|
|||
}
|
||||
}
|
||||
|
||||
fn handle_learn_picker_key(&mut self, code: KeyCode) {
|
||||
fn handle_controller_picker_key(&mut self, code: KeyCode) {
|
||||
if code == KeyCode::Esc {
|
||||
self.learn_picker = None;
|
||||
self.controller_picker = None;
|
||||
return;
|
||||
}
|
||||
let Some(picker) = &mut self.learn_picker else {
|
||||
let Some(picker) = &mut self.controller_picker else {
|
||||
return;
|
||||
};
|
||||
match code {
|
||||
|
|
@ -1573,16 +1667,28 @@ impl<C: MixerClient> LiveTui<C> {
|
|||
let Some(surface) = self.snapshot.devices.get(picker.selected) else {
|
||||
return;
|
||||
};
|
||||
match self.client.start_midi_learn(
|
||||
surface.id.clone(),
|
||||
picker.fader.clone(),
|
||||
picker.action.clone(),
|
||||
) {
|
||||
Ok(snapshot) => {
|
||||
self.learn_picker = None;
|
||||
self.replace_snapshot(snapshot);
|
||||
}
|
||||
Err(error) => self.client_error = Some(error.to_string()),
|
||||
let surface = surface.id.clone();
|
||||
let fader = picker.fader.clone();
|
||||
let action = picker.action.clone();
|
||||
let binding = self
|
||||
.snapshot
|
||||
.configuration
|
||||
.bindings
|
||||
.iter()
|
||||
.find(|binding| binding.fader == fader && binding.action == action)
|
||||
.cloned();
|
||||
self.controller_picker = None;
|
||||
if let Some(binding) = binding {
|
||||
self.apply_layout_edit(ConfigurationEdit::SetBinding {
|
||||
surface,
|
||||
fader,
|
||||
action,
|
||||
kind: binding.kind,
|
||||
channel: binding.channel,
|
||||
number: binding.number,
|
||||
});
|
||||
} else {
|
||||
self.controller_selections.insert((fader, action), surface);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
|
|
@ -1849,8 +1955,11 @@ impl<C: MixerClient> Widget for &LiveTui<C> {
|
|||
if self.capture_editor.is_some() {
|
||||
self.render_capture_editor(area, buf);
|
||||
}
|
||||
if self.learn_picker.is_some() {
|
||||
self.render_learn_picker(area, buf);
|
||||
if self.controller_picker.is_some() {
|
||||
self.render_controller_picker(area, buf);
|
||||
}
|
||||
if self.snapshot.configuration.learning.is_some() {
|
||||
self.render_midi_learn_waiting(area, buf);
|
||||
}
|
||||
if self.quit_confirmation {
|
||||
let width = area.width.min(46);
|
||||
|
|
@ -1968,6 +2077,13 @@ const fn selector_field_name(index: usize) -> &'static str {
|
|||
}
|
||||
}
|
||||
|
||||
fn capitalize(value: &str) -> String {
|
||||
let mut characters = value.chars();
|
||||
characters.next().map_or_else(String::new, |first| {
|
||||
first.to_uppercase().chain(characters).collect()
|
||||
})
|
||||
}
|
||||
|
||||
fn selector_field_index(field: &str) -> usize {
|
||||
match field {
|
||||
"application.name" => 0,
|
||||
|
|
@ -2017,9 +2133,23 @@ impl<C: MixerClient> LiveTui<C> {
|
|||
FaderEditorRow::GroupMode { mode } => {
|
||||
format!("{marker} Group mode {}", mode.label())
|
||||
}
|
||||
FaderEditorRow::Binding { label, value, .. } => {
|
||||
format!("{marker} {label} {value} [L learn · U unset]")
|
||||
FaderEditorRow::BindingController { label, value, .. } => format!(
|
||||
"{marker} {} controller {value} [Enter to change]",
|
||||
capitalize(label)
|
||||
),
|
||||
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" },
|
||||
|
|
@ -2096,8 +2226,8 @@ impl<C: MixerClient> LiveTui<C> {
|
|||
.render(popup, buf);
|
||||
}
|
||||
|
||||
fn render_learn_picker(&self, area: Rect, buf: &mut Buffer) {
|
||||
let Some(picker) = &self.learn_picker else {
|
||||
fn render_controller_picker(&self, area: Rect, buf: &mut Buffer) {
|
||||
let Some(picker) = &self.controller_picker else {
|
||||
return;
|
||||
};
|
||||
let theme = self.theme.palette();
|
||||
|
|
@ -2128,8 +2258,8 @@ impl<C: MixerClient> LiveTui<C> {
|
|||
Paragraph::new(Text::from(lines))
|
||||
.block(
|
||||
Block::bordered()
|
||||
.title(" Choose MIDI surface ".fg(theme.accent).bold())
|
||||
.title_bottom(" Enter learn · Esc back ".fg(theme.muted))
|
||||
.title(" Choose controller ".fg(theme.accent).bold())
|
||||
.title_bottom(" Enter select · Esc back ".fg(theme.muted))
|
||||
.border_set(border::DOUBLE)
|
||||
.border_style(Style::default().fg(theme.accent))
|
||||
.style(Style::default().bg(theme.background)),
|
||||
|
|
@ -2137,6 +2267,28 @@ impl<C: MixerClient> LiveTui<C> {
|
|||
.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));
|
||||
Clear.render(popup, buf);
|
||||
Paragraph::new(Text::from(vec![
|
||||
Line::from("Move a fader or press a button on the selected controller.")
|
||||
.alignment(Alignment::Center),
|
||||
Line::from("The next supported MIDI control will be assigned.")
|
||||
.fg(theme.muted)
|
||||
.alignment(Alignment::Center),
|
||||
]))
|
||||
.block(
|
||||
Block::bordered()
|
||||
.title(" Learn MIDI control ".fg(theme.accent).bold())
|
||||
.title_bottom(" Esc cancel ".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_configuration(&self, area: Rect, buf: &mut Buffer) {
|
||||
let theme = self.theme.palette();
|
||||
let config = &self.snapshot.configuration;
|
||||
|
|
@ -2581,12 +2733,48 @@ mod tests {
|
|||
.configuration
|
||||
.bindings
|
||||
.retain(|binding| binding.fader != *fader || binding.action != *action),
|
||||
ConfigurationEdit::SetBinding {
|
||||
surface,
|
||||
fader,
|
||||
action,
|
||||
kind,
|
||||
channel,
|
||||
number,
|
||||
} => {
|
||||
if let Some(binding) = self
|
||||
.snapshot
|
||||
.configuration
|
||||
.bindings
|
||||
.iter_mut()
|
||||
.find(|binding| binding.fader == *fader && binding.action == *action)
|
||||
{
|
||||
binding.surface.clone_from(surface);
|
||||
binding.kind.clone_from(kind);
|
||||
binding.channel = *channel;
|
||||
binding.number = *number;
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
self.snapshot.configuration.revision += 1;
|
||||
self.edits.lock().unwrap().push(edit);
|
||||
Ok(self.snapshot.clone())
|
||||
}
|
||||
|
||||
fn start_midi_learn(
|
||||
&mut self,
|
||||
surface: String,
|
||||
fader: String,
|
||||
action: String,
|
||||
) -> io::Result<MixerSnapshot> {
|
||||
self.snapshot.configuration.learning = Some(format!("{surface} -> {fader} ({action})"));
|
||||
Ok(self.snapshot.clone())
|
||||
}
|
||||
|
||||
fn cancel_midi_learn(&mut self) -> io::Result<MixerSnapshot> {
|
||||
self.snapshot.configuration.learning = None;
|
||||
Ok(self.snapshot.clone())
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -2867,14 +3055,26 @@ mod tests {
|
|||
fader: "music-fader".into(),
|
||||
action: "volume".into(),
|
||||
message: "cc ch1 #7".into(),
|
||||
kind: "cc".into(),
|
||||
channel: 1,
|
||||
number: 7,
|
||||
}];
|
||||
snapshot.devices = vec![MidiDevice {
|
||||
id: "desk".into(),
|
||||
label: "Desk controller".into(),
|
||||
status: "connected".into(),
|
||||
backend_id: Some("20:0".into()),
|
||||
error: None,
|
||||
}];
|
||||
snapshot.devices = vec![
|
||||
MidiDevice {
|
||||
id: "desk".into(),
|
||||
label: "Desk controller".into(),
|
||||
status: "connected".into(),
|
||||
backend_id: Some("20:0".into()),
|
||||
error: None,
|
||||
},
|
||||
MidiDevice {
|
||||
id: "spare".into(),
|
||||
label: "Spare controller".into(),
|
||||
status: "connected".into(),
|
||||
backend_id: Some("21:0".into()),
|
||||
error: None,
|
||||
},
|
||||
];
|
||||
let edits = Arc::new(Mutex::new(Vec::new()));
|
||||
let mut app = LiveTui::new(LayoutClient {
|
||||
snapshot,
|
||||
|
|
@ -2893,8 +3093,12 @@ mod tests {
|
|||
.collect::<String>();
|
||||
assert!(rendered.contains("Edit fader: music-fader"));
|
||||
assert!(rendered.contains("Capture 1"));
|
||||
assert!(rendered.contains("Volume control"));
|
||||
assert!(rendered.contains("Mute control"));
|
||||
assert!(rendered.contains("Volume controller"));
|
||||
assert!(rendered.contains("Learn volume MIDI"));
|
||||
assert!(rendered.contains("Unlearn volume MIDI"));
|
||||
assert!(rendered.contains("Mute controller"));
|
||||
assert!(rendered.contains("Learn mute MIDI"));
|
||||
assert!(rendered.contains("Unlearn mute MIDI"));
|
||||
assert!(rendered.contains("Size Standard"));
|
||||
assert!(rendered.contains("Visibility"));
|
||||
|
||||
|
|
@ -2912,8 +3116,7 @@ mod tests {
|
|||
app.handle_key_event(press(KeyCode::Enter));
|
||||
|
||||
app.handle_key_event(press(KeyCode::Down));
|
||||
app.handle_key_event(press(KeyCode::Char('u')));
|
||||
app.handle_key_event(press(KeyCode::Char('l')));
|
||||
app.handle_key_event(press(KeyCode::Enter));
|
||||
let mut picker = Buffer::empty(area);
|
||||
(&app).render(area, &mut picker);
|
||||
let picker_rendered = picker
|
||||
|
|
@ -2921,9 +3124,27 @@ mod tests {
|
|||
.iter()
|
||||
.map(|cell| cell.symbol())
|
||||
.collect::<String>();
|
||||
assert!(picker_rendered.contains("Choose MIDI surface"));
|
||||
assert!(picker_rendered.contains("Choose controller"));
|
||||
assert!(picker_rendered.contains("Desk controller"));
|
||||
|
||||
app.handle_key_event(press(KeyCode::Down));
|
||||
app.handle_key_event(press(KeyCode::Enter));
|
||||
app.handle_key_event(press(KeyCode::Down));
|
||||
app.handle_key_event(press(KeyCode::Enter));
|
||||
let mut waiting = Buffer::empty(area);
|
||||
(&app).render(area, &mut waiting);
|
||||
let waiting_rendered = waiting
|
||||
.content
|
||||
.iter()
|
||||
.map(|cell| cell.symbol())
|
||||
.collect::<String>();
|
||||
assert!(waiting_rendered.contains("Learn MIDI control"));
|
||||
assert!(waiting_rendered.contains("Move a fader or press a button"));
|
||||
app.handle_key_event(press(KeyCode::Esc));
|
||||
|
||||
app.handle_key_event(press(KeyCode::Down));
|
||||
app.handle_key_event(press(KeyCode::Enter));
|
||||
|
||||
let edits = edits.lock().unwrap();
|
||||
assert!(edits.iter().any(|edit| matches!(
|
||||
edit,
|
||||
|
|
@ -2935,6 +3156,11 @@ mod tests {
|
|||
..
|
||||
} if id == "music" && field == "application.id" && pattern == "Qobuz"
|
||||
)));
|
||||
assert!(edits.iter().any(|edit| matches!(
|
||||
edit,
|
||||
ConfigurationEdit::SetBinding { surface, fader, action, .. }
|
||||
if surface == "spare" && fader == "music-fader" && action == "volume"
|
||||
)));
|
||||
assert!(edits.iter().any(|edit| matches!(
|
||||
edit,
|
||||
ConfigurationEdit::RemoveBinding { fader, action }
|
||||
|
|
@ -2971,8 +3197,9 @@ mod tests {
|
|||
.unwrap();
|
||||
|
||||
app.handle_key_event(press(KeyCode::Char('e')));
|
||||
app.handle_key_event(press(KeyCode::Down));
|
||||
app.handle_key_event(press(KeyCode::Down));
|
||||
for _ in 0..6 {
|
||||
app.handle_key_event(press(KeyCode::Down));
|
||||
}
|
||||
app.handle_key_event(press(KeyCode::Enter));
|
||||
assert!(edits.lock().unwrap().iter().any(|edit| matches!(
|
||||
edit,
|
||||
|
|
@ -3131,6 +3358,9 @@ mod tests {
|
|||
fader: "media-fader".into(),
|
||||
action: "volume".into(),
|
||||
message: "cc ch1 #49".into(),
|
||||
kind: "cc".into(),
|
||||
channel: 1,
|
||||
number: 49,
|
||||
}],
|
||||
};
|
||||
client.revision = snapshot.revision;
|
||||
|
|
@ -3247,9 +3477,9 @@ mod tests {
|
|||
calls: Arc::clone(&calls),
|
||||
})
|
||||
.unwrap();
|
||||
app.handle_key_event(press(KeyCode::Char('2')));
|
||||
app.handle_key_event(press(KeyCode::Char('c')));
|
||||
assert!(app.snapshot.configuration.learning.is_none());
|
||||
app.handle_key_event(press(KeyCode::Char('2')));
|
||||
app.handle_key_event(press(KeyCode::Char('p')));
|
||||
app.handle_key_event(press(KeyCode::Char('s')));
|
||||
assert_eq!(
|
||||
|
|
|
|||
Loading…
Reference in New Issue