feat: remove MIDI devices from Config
Add confirmed MIDI surface removal in the Config tab, clear its bindings and default-controller reference atomically, and keep added or removed devices consistent in the draft view until Save. Tests: cargo fmt --all -- --check; cargo check --workspace --all-targets --all-features; cargo clippy --workspace --all-targets --all-features -- -D warnings; cargo test -p tui; cargo test -p fader-config --test editor; targeted fader_master editor/live tests; cargo test --workspace --doc --all-features; cargo build --workspace --release --all-features. Full workspace tests are blocked by the pre-existing edited examples/profiles/arch-pipewire.toml fixture mismatch.
This commit is contained in:
parent
a967cc30ea
commit
1863f82f15
|
|
@ -77,6 +77,8 @@ and starts an embedded one otherwise. Running without `--config` creates
|
|||
a `default` profile with a Master-output fader. A sole detected MIDI input is
|
||||
adopted as the default controller; otherwise choose a detected input in Config,
|
||||
add it, and Save. Edit the Master fader with `E` to learn volume and mute controls.
|
||||
Configured controllers can be removed with `D` in Config; confirmation also
|
||||
removes their bindings, and Save activates the change.
|
||||
|
||||
### Build from source (alternative)
|
||||
|
||||
|
|
|
|||
|
|
@ -580,7 +580,9 @@ 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.
|
||||
profile-backed default controller used by MIDI learn. Removing a device is a
|
||||
confirmed draft edit that atomically removes its surface, bindings, and any
|
||||
default-controller reference; the running MIDI topology changes on Save.
|
||||
|
||||
Config also exposes a confirmed emergency reset for the active profile. The
|
||||
server, never the TUI process, preserves the current on-disk bytes beside the
|
||||
|
|
|
|||
|
|
@ -210,6 +210,25 @@ pickup_tolerance = 0.02
|
|||
})
|
||||
}
|
||||
|
||||
/// Removes a MIDI surface and all configuration that references it.
|
||||
pub fn remove_surface(&mut self, id: &str) -> Result<(), ConfigError> {
|
||||
self.transaction(|document| {
|
||||
remove_table_entry(document, "surfaces", id)?;
|
||||
if let Some(bindings) = document
|
||||
.get_mut("bindings")
|
||||
.and_then(Item::as_array_of_tables_mut)
|
||||
{
|
||||
bindings.retain(|table| table.get("surface").and_then(Item::as_str) != Some(id));
|
||||
}
|
||||
if let Some(ui) = document.get_mut("ui").and_then(Item::as_table_mut)
|
||||
&& ui.get("default_controller").and_then(Item::as_str) == Some(id)
|
||||
{
|
||||
ui.remove("default_controller");
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
|
||||
/// Changes one application's display label without rebuilding its table.
|
||||
pub fn set_application_label(
|
||||
&mut self,
|
||||
|
|
|
|||
|
|
@ -5,6 +5,18 @@ use fader_config::{
|
|||
|
||||
const PROFILE: &str = include_str!("../../examples/profiles/desktop.toml");
|
||||
|
||||
#[test]
|
||||
fn removing_a_surface_clears_its_bindings_and_default_controller_atomically() {
|
||||
let mut draft = ProfileDocument::parse(PROFILE).unwrap();
|
||||
|
||||
draft.remove_surface("desk-left").unwrap();
|
||||
|
||||
let profile = draft.preview().unwrap();
|
||||
assert!(profile.surfaces().is_empty());
|
||||
assert!(profile.bindings().is_empty());
|
||||
assert_eq!(profile.default_controller(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mixer_objects_are_created_and_removed_as_atomic_valid_units() {
|
||||
let mut draft = ProfileDocument::empty("default").unwrap();
|
||||
|
|
|
|||
|
|
@ -249,8 +249,10 @@ actions inherit `[ui].default_controller` for learning.
|
|||
Learn opens a modal waiting for a movement or button press; Escape cancels it.
|
||||
Changing controller, learning, and unlearning are separate actions. In Config,
|
||||
open a MIDI device to see its connection details and set its default-controller
|
||||
flag. Hidden faders remain bound and continue contributing to groups; restore
|
||||
them from Config → Show hidden faders.
|
||||
flag. Press `D` on the device row or in its details popup to remove it after
|
||||
confirmation. Removal also clears that device's bindings and default-controller
|
||||
selection; Save activates the draft. Hidden faders remain bound and continue
|
||||
contributing to groups; restore them from Config → Show hidden faders.
|
||||
|
||||
`feedback` is optional and requires the binding's surface to define
|
||||
`output_port`. After that output attaches, the server sends `on` when the
|
||||
|
|
|
|||
|
|
@ -121,6 +121,7 @@ impl ConfigurationEditor {
|
|||
self.document.set_default_controller(Some(&id))?;
|
||||
}
|
||||
}
|
||||
ConfigurationEdit::RemoveSurface { id } => self.document.remove_surface(&id)?,
|
||||
ConfigurationEdit::AddApplication {
|
||||
id,
|
||||
label,
|
||||
|
|
@ -491,6 +492,17 @@ mod tests {
|
|||
assert_eq!(profile.surfaces()[0].id(), "apc-mini");
|
||||
assert_eq!(profile.default_controller(), Some("apc-mini"));
|
||||
assert!(editor.dirty());
|
||||
|
||||
let profile = editor
|
||||
.apply(
|
||||
1,
|
||||
ConfigurationEdit::RemoveSurface {
|
||||
id: "apc-mini".into(),
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
assert!(profile.surfaces().is_empty());
|
||||
assert_eq!(profile.default_controller(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use std::io::{self, Read, Write};
|
|||
use serde::{Deserialize, Serialize, de::DeserializeOwned};
|
||||
use thiserror::Error;
|
||||
|
||||
pub const PROTOCOL_VERSION: u16 = 21;
|
||||
pub const PROTOCOL_VERSION: u16 = 22;
|
||||
pub const MAX_FRAME_BYTES: usize = 64 * 1024;
|
||||
|
||||
/// Kind of mixer object addressed by a client.
|
||||
|
|
@ -106,6 +106,9 @@ pub enum ConfigurationEdit {
|
|||
usb_path: Option<String>,
|
||||
manual_backend_id: Option<String>,
|
||||
},
|
||||
RemoveSurface {
|
||||
id: String,
|
||||
},
|
||||
AddApplication {
|
||||
id: String,
|
||||
label: String,
|
||||
|
|
@ -262,6 +265,8 @@ pub struct ConfigurationSnapshot {
|
|||
pub status_display: StatusDisplayMode,
|
||||
pub default_controller: Option<String>,
|
||||
pub theme: String,
|
||||
#[serde(default)]
|
||||
pub surfaces: Vec<ConfiguredSurface>,
|
||||
pub applications: Vec<ConfiguredApplication>,
|
||||
pub groups: Vec<ConfiguredGroup>,
|
||||
pub faders: Vec<ConfiguredFader>,
|
||||
|
|
@ -269,6 +274,12 @@ pub struct ConfigurationSnapshot {
|
|||
pub bindings: Vec<ConfiguredBinding>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
|
||||
pub struct ConfiguredSurface {
|
||||
pub id: String,
|
||||
pub label: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum MixerOrientation {
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ use volume_lib::WorkerEvent;
|
|||
use crate::ipc::{
|
||||
ClientRequest, ConfigurationSnapshot, ConfiguredApplication as IpcApplication,
|
||||
ConfiguredBinding as IpcBinding, ConfiguredFader as IpcFader, ConfiguredGroup as IpcGroup,
|
||||
ConfiguredSelector as IpcSelector, GroupVolumeMode, MidiDevice,
|
||||
MixerLayoutEntry as IpcLayoutEntry, MixerObject, MixerObjectKey, MixerObjectKind,
|
||||
ConfiguredSelector as IpcSelector, ConfiguredSurface as IpcSurface, GroupVolumeMode,
|
||||
MidiDevice, MixerLayoutEntry as IpcLayoutEntry, MixerObject, MixerObjectKey, MixerObjectKind,
|
||||
MixerSnapshot, PROTOCOL_VERSION, PickupStatus, RequestCommand, ResponseResult, ServerResponse,
|
||||
};
|
||||
|
||||
|
|
@ -139,6 +139,14 @@ pub(crate) fn configuration_snapshot(
|
|||
fader_config::UiTheme::SolarizedDark => "solarized-dark",
|
||||
}
|
||||
.to_owned(),
|
||||
surfaces: profile
|
||||
.surfaces()
|
||||
.iter()
|
||||
.map(|surface| IpcSurface {
|
||||
id: surface.id().to_owned(),
|
||||
label: surface.label().to_owned(),
|
||||
})
|
||||
.collect(),
|
||||
applications: profile
|
||||
.applications()
|
||||
.iter()
|
||||
|
|
@ -1091,6 +1099,8 @@ mod reconfigure_tests {
|
|||
crate::ipc::GroupVolumeMode::Absolute
|
||||
);
|
||||
assert_eq!(snapshot.faders[0].pickup_tolerance, 0.02);
|
||||
assert_eq!(snapshot.surfaces[0].id, "desk-left");
|
||||
assert_eq!(snapshot.surfaces[0].label, "Left controller");
|
||||
assert_eq!(
|
||||
snapshot.status_display,
|
||||
crate::ipc::StatusDisplayMode::Detailed
|
||||
|
|
|
|||
|
|
@ -134,6 +134,15 @@ impl IpcMixerClient {
|
|||
),
|
||||
)
|
||||
})?,
|
||||
surfaces: snapshot
|
||||
.configuration
|
||||
.surfaces
|
||||
.into_iter()
|
||||
.map(|surface| tui::ConfiguredSurface {
|
||||
id: surface.id,
|
||||
label: surface.label,
|
||||
})
|
||||
.collect(),
|
||||
applications: snapshot
|
||||
.configuration
|
||||
.applications
|
||||
|
|
@ -397,6 +406,7 @@ fn configuration_edit(edit: TuiConfigurationEdit) -> crate::ipc::ConfigurationEd
|
|||
usb_path,
|
||||
manual_backend_id,
|
||||
},
|
||||
TuiConfigurationEdit::RemoveSurface { id } => IpcEdit::RemoveSurface { id },
|
||||
TuiConfigurationEdit::Application {
|
||||
existing,
|
||||
id,
|
||||
|
|
|
|||
4
task.md
4
task.md
|
|
@ -468,6 +468,10 @@ Dependencies: M8, M2, M1.
|
|||
Master-output default. The server backs up the prior bytes as `.reset.bak`,
|
||||
atomically persists the replacement, and activates it without audio writes;
|
||||
editor, IPC/server, and confirmation/cancellation paths are regression-tested.
|
||||
Configured MIDI devices can also be removed with `D` from their row or details
|
||||
popup. Confirmation describes the binding cleanup, and the draft atomically
|
||||
removes the surface, its bindings, and any default-controller reference before
|
||||
Save reconfigures the running MIDI topology.
|
||||
Mixer `A` now chooses a new application fader, empty absolute group, or
|
||||
separator. Compound application/group creation adds the target, fader, and
|
||||
visible layout entry atomically before opening its guided editor. New targets
|
||||
|
|
|
|||
|
|
@ -9,9 +9,10 @@ use ratatui::{
|
|||
style::{Color, Modifier},
|
||||
};
|
||||
use tui::{
|
||||
ConfigurationSnapshot, ConfiguredApplication, ConfiguredFader, ConfiguredGroup, FaderDensity,
|
||||
GroupVolumeMode, LiveTui, MidiDevice, MixerClient, MixerItem, MixerLayoutEntry, MixerObjectId,
|
||||
MixerObjectKind, MixerOrientation, MixerSnapshot, PickupStatus, ThemeName,
|
||||
ConfigurationSnapshot, ConfiguredApplication, ConfiguredFader, ConfiguredGroup,
|
||||
ConfiguredSurface, FaderDensity, GroupVolumeMode, LiveTui, MidiDevice, MixerClient, MixerItem,
|
||||
MixerLayoutEntry, MixerObjectId, MixerObjectKind, MixerOrientation, MixerSnapshot,
|
||||
PickupStatus, ThemeName,
|
||||
};
|
||||
|
||||
const CELL_WIDTH: u16 = 9;
|
||||
|
|
@ -148,6 +149,10 @@ fn snapshot(mixer_orientation: MixerOrientation) -> MixerSnapshot {
|
|||
status_display: tui::StatusDisplayMode::Symbol,
|
||||
default_controller: Some("apc-mini".to_owned()),
|
||||
theme: ThemeName::CatppuccinMocha,
|
||||
surfaces: vec![ConfiguredSurface {
|
||||
id: "apc-mini".to_owned(),
|
||||
label: "APC MINI".to_owned(),
|
||||
}],
|
||||
applications: vec![
|
||||
ConfiguredApplication {
|
||||
id: "music".to_owned(),
|
||||
|
|
|
|||
245
tui/src/lib.rs
245
tui/src/lib.rs
|
|
@ -33,6 +33,7 @@ const CLIENT_PENDING_REFRESH: Duration = Duration::from_millis(20);
|
|||
const CLIENT_SHUTDOWN_GRACE: Duration = Duration::from_millis(25);
|
||||
const MAX_BUFFERED_MUTE_EDGES: usize = 128;
|
||||
const DRAFT_ITEM_DETAIL: &str = "draft · save to activate";
|
||||
const DRAFT_DEVICE_STATUS: &str = "draft · save to activate";
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
|
||||
pub enum MixerObjectKind {
|
||||
|
|
@ -103,6 +104,7 @@ pub struct ConfigurationSnapshot {
|
|||
pub status_display: StatusDisplayMode,
|
||||
pub default_controller: Option<String>,
|
||||
pub theme: ThemeName,
|
||||
pub surfaces: Vec<ConfiguredSurface>,
|
||||
pub applications: Vec<ConfiguredApplication>,
|
||||
pub groups: Vec<ConfiguredGroup>,
|
||||
pub faders: Vec<ConfiguredFader>,
|
||||
|
|
@ -110,6 +112,12 @@ pub struct ConfigurationSnapshot {
|
|||
pub bindings: Vec<ConfiguredBinding>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub struct ConfiguredSurface {
|
||||
pub id: String,
|
||||
pub label: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
|
||||
pub enum MixerOrientation {
|
||||
#[default]
|
||||
|
|
@ -372,6 +380,9 @@ pub enum ConfigurationEdit {
|
|||
usb_path: Option<String>,
|
||||
manual_backend_id: Option<String>,
|
||||
},
|
||||
RemoveSurface {
|
||||
id: String,
|
||||
},
|
||||
Application {
|
||||
existing: bool,
|
||||
id: String,
|
||||
|
|
@ -967,6 +978,28 @@ fn publish_confirmed(state: &mut BufferedState, confirmed: &MixerSnapshot) {
|
|||
|
||||
fn apply_optimistic_configuration_edit(snapshot: &mut MixerSnapshot, edit: &ConfigurationEdit) {
|
||||
match edit {
|
||||
ConfigurationEdit::AddSurface { id, label, .. } => {
|
||||
snapshot.configuration.surfaces.push(ConfiguredSurface {
|
||||
id: id.clone(),
|
||||
label: label.clone(),
|
||||
});
|
||||
snapshot.configuration.dirty = true;
|
||||
}
|
||||
ConfigurationEdit::RemoveSurface { id } => {
|
||||
snapshot
|
||||
.configuration
|
||||
.surfaces
|
||||
.retain(|surface| surface.id != *id);
|
||||
snapshot.devices.retain(|device| device.id != *id);
|
||||
snapshot
|
||||
.configuration
|
||||
.bindings
|
||||
.retain(|binding| binding.surface != *id);
|
||||
if snapshot.configuration.default_controller.as_deref() == Some(id) {
|
||||
snapshot.configuration.default_controller = None;
|
||||
}
|
||||
snapshot.configuration.dirty = true;
|
||||
}
|
||||
ConfigurationEdit::MoveLayoutEntry { id, position } => {
|
||||
let Some(index) = snapshot
|
||||
.configuration
|
||||
|
|
@ -1184,6 +1217,7 @@ pub struct LiveTui<C> {
|
|||
add_picker: Option<AddPicker>,
|
||||
new_item_editor: Option<NewItemEditor>,
|
||||
delete_confirmation: Option<DeleteConfirmation>,
|
||||
device_delete_confirmation: Option<DeviceDeleteConfirmation>,
|
||||
show_help: bool,
|
||||
client_error: Option<String>,
|
||||
tab: Tab,
|
||||
|
|
@ -1321,6 +1355,12 @@ struct DeleteConfirmation {
|
|||
separator: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
struct DeviceDeleteConfirmation {
|
||||
id: String,
|
||||
label: String,
|
||||
}
|
||||
|
||||
enum FaderEditorRow {
|
||||
Capture {
|
||||
application: String,
|
||||
|
|
@ -1550,6 +1590,32 @@ fn add_draft_mixer_items(snapshot: &mut MixerSnapshot) {
|
|||
}
|
||||
}
|
||||
|
||||
fn reconcile_configured_midi_devices(snapshot: &mut MixerSnapshot) {
|
||||
snapshot.devices.retain(|device| {
|
||||
snapshot
|
||||
.configuration
|
||||
.surfaces
|
||||
.iter()
|
||||
.any(|surface| surface.id == device.id)
|
||||
});
|
||||
for surface in &snapshot.configuration.surfaces {
|
||||
if snapshot
|
||||
.devices
|
||||
.iter()
|
||||
.any(|device| device.id == surface.id)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
snapshot.devices.push(MidiDevice {
|
||||
id: surface.id.clone(),
|
||||
label: surface.label.clone(),
|
||||
status: DRAFT_DEVICE_STATUS.to_owned(),
|
||||
backend_id: None,
|
||||
error: None,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
impl<C: MixerClient> LiveTui<C> {
|
||||
pub fn new(mut client: C) -> io::Result<Self> {
|
||||
let snapshot = client.snapshot()?;
|
||||
|
|
@ -1569,6 +1635,7 @@ impl<C: MixerClient> LiveTui<C> {
|
|||
theme_override: bool,
|
||||
) -> Self {
|
||||
add_draft_mixer_items(&mut snapshot);
|
||||
reconcile_configured_midi_devices(&mut snapshot);
|
||||
Self {
|
||||
client,
|
||||
snapshot,
|
||||
|
|
@ -1581,6 +1648,7 @@ impl<C: MixerClient> LiveTui<C> {
|
|||
add_picker: None,
|
||||
new_item_editor: None,
|
||||
delete_confirmation: None,
|
||||
device_delete_confirmation: None,
|
||||
show_help: false,
|
||||
client_error: None,
|
||||
tab: Tab::Mixer,
|
||||
|
|
@ -1635,6 +1703,7 @@ impl<C: MixerClient> LiveTui<C> {
|
|||
self.theme = snapshot.configuration.theme;
|
||||
}
|
||||
add_draft_mixer_items(&mut snapshot);
|
||||
reconcile_configured_midi_devices(&mut snapshot);
|
||||
self.snapshot = snapshot;
|
||||
self.selected = selected_id
|
||||
.and_then(|id| self.mixer_rows().iter().position(|row| row.id() == id))
|
||||
|
|
@ -1709,6 +1778,10 @@ impl<C: MixerClient> LiveTui<C> {
|
|||
}
|
||||
|
||||
fn handle_key_event(&mut self, key_event: KeyEvent) {
|
||||
if self.device_delete_confirmation.is_some() {
|
||||
self.handle_device_delete_confirmation_key(key_event.code);
|
||||
return;
|
||||
}
|
||||
if self.delete_confirmation.is_some() {
|
||||
self.handle_delete_confirmation_key(key_event.code);
|
||||
return;
|
||||
|
|
@ -2235,10 +2308,27 @@ impl<C: MixerClient> LiveTui<C> {
|
|||
self.cancel_midi_learn()
|
||||
}
|
||||
KeyCode::Char('s') => self.save_configuration(),
|
||||
KeyCode::Char('d' | 'D') => self.start_delete_selected_device(),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn start_delete_selected_device(&mut self) {
|
||||
let Some(SettingsRow::MidiDevice { id }) =
|
||||
self.settings_rows().into_iter().nth(self.settings_selected)
|
||||
else {
|
||||
return;
|
||||
};
|
||||
let Some(device) = self.snapshot.devices.iter().find(|device| device.id == id) else {
|
||||
return;
|
||||
};
|
||||
self.device_delete_confirmation = Some(DeviceDeleteConfirmation {
|
||||
id,
|
||||
label: device.label.clone(),
|
||||
});
|
||||
self.client_error = None;
|
||||
}
|
||||
|
||||
fn activate_settings_row(&mut self, forward: bool) {
|
||||
let Some(row) = self.settings_rows().into_iter().nth(self.settings_selected) else {
|
||||
return;
|
||||
|
|
@ -2479,6 +2569,17 @@ impl<C: MixerClient> LiveTui<C> {
|
|||
KeyCode::Left => false,
|
||||
KeyCode::Right => true,
|
||||
KeyCode::Enter => !is_default,
|
||||
KeyCode::Char('d' | 'D') => {
|
||||
let label = self
|
||||
.snapshot
|
||||
.devices
|
||||
.iter()
|
||||
.find(|device| device.id == id)
|
||||
.map_or_else(|| id.clone(), |device| device.label.clone());
|
||||
self.device_delete_confirmation = Some(DeviceDeleteConfirmation { id, label });
|
||||
self.client_error = None;
|
||||
return;
|
||||
}
|
||||
_ => return,
|
||||
};
|
||||
if make_default == is_default {
|
||||
|
|
@ -2489,6 +2590,24 @@ impl<C: MixerClient> LiveTui<C> {
|
|||
});
|
||||
}
|
||||
|
||||
fn handle_device_delete_confirmation_key(&mut self, code: KeyCode) {
|
||||
match code {
|
||||
KeyCode::Char('y' | 'Y') => {
|
||||
let Some(confirmation) = self.device_delete_confirmation.take() else {
|
||||
return;
|
||||
};
|
||||
self.midi_device_details = None;
|
||||
self.apply_layout_edit(ConfigurationEdit::RemoveSurface {
|
||||
id: confirmation.id,
|
||||
});
|
||||
}
|
||||
KeyCode::Char('n' | 'N') | KeyCode::Esc => {
|
||||
self.device_delete_confirmation = None;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn cancel_midi_learn(&mut self) {
|
||||
match self.client.cancel_midi_learn() {
|
||||
Ok(snapshot) => self.replace_snapshot(snapshot),
|
||||
|
|
@ -3315,6 +3434,26 @@ impl<C: MixerClient> Widget for &LiveTui<C> {
|
|||
if self.midi_device_details.is_some() {
|
||||
self.render_midi_device_details(area, buf);
|
||||
}
|
||||
if let Some(confirmation) = &self.device_delete_confirmation {
|
||||
let popup = centered_rect(area, 62, 8);
|
||||
Clear.render(popup, buf);
|
||||
Paragraph::new(Text::from(vec![
|
||||
Line::from("Remove MIDI device?").bold(),
|
||||
Line::from(format!("“{}”", confirmation.label)).fg(theme.secondary),
|
||||
Line::from("Its MIDI bindings will also be removed."),
|
||||
Line::from("Changes take effect after Save.").fg(theme.muted),
|
||||
Line::from("Y remove N / Esc cancel"),
|
||||
]))
|
||||
.alignment(Alignment::Center)
|
||||
.block(
|
||||
Block::bordered()
|
||||
.title(" Confirm device removal ".fg(theme.error).bold())
|
||||
.border_set(border::DOUBLE)
|
||||
.border_style(Style::default().fg(theme.error))
|
||||
.style(Style::default().bg(theme.background)),
|
||||
)
|
||||
.render(popup, buf);
|
||||
}
|
||||
if self.snapshot.configuration.learning.is_some() {
|
||||
self.render_midi_learn_waiting(area, buf);
|
||||
}
|
||||
|
|
@ -4162,7 +4301,7 @@ impl<C: MixerClient> LiveTui<C> {
|
|||
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);
|
||||
let popup = centered_rect(area, 68, 12);
|
||||
Clear.render(popup, buf);
|
||||
Paragraph::new(Text::from(vec![
|
||||
Line::from(device.label.as_str()).bold(),
|
||||
|
|
@ -4176,11 +4315,12 @@ impl<C: MixerClient> LiveTui<C> {
|
|||
is_default.to_string().fg(theme.accent).bold(),
|
||||
" [←→/Enter]".fg(theme.muted),
|
||||
]),
|
||||
Line::from("▶ Remove device [D]").fg(theme.error),
|
||||
]))
|
||||
.block(
|
||||
Block::bordered()
|
||||
.title(" MIDI device details ".fg(theme.accent).bold())
|
||||
.title_bottom(" ← false · → true · Enter toggle · Esc close ".fg(theme.muted))
|
||||
.title_bottom(" ←→/Enter default · D remove · Esc close ".fg(theme.muted))
|
||||
.border_set(border::DOUBLE)
|
||||
.border_style(Style::default().fg(theme.accent))
|
||||
.style(Style::default().bg(theme.background)),
|
||||
|
|
@ -4932,7 +5072,9 @@ mod tests {
|
|||
match &edit {
|
||||
ConfigurationEdit::AddApplicationFader { .. }
|
||||
| ConfigurationEdit::AddGroupFader { .. }
|
||||
| ConfigurationEdit::RemoveMixerFader { .. } => {
|
||||
| ConfigurationEdit::RemoveMixerFader { .. }
|
||||
| ConfigurationEdit::AddSurface { .. }
|
||||
| ConfigurationEdit::RemoveSurface { .. } => {
|
||||
apply_optimistic_configuration_edit(&mut self.snapshot, &edit);
|
||||
}
|
||||
ConfigurationEdit::MoveLayoutEntry { id, position } => {
|
||||
|
|
@ -6106,6 +6248,16 @@ mod tests {
|
|||
number: 7,
|
||||
}];
|
||||
snapshot.configuration.default_controller = Some("spare".into());
|
||||
snapshot.configuration.surfaces = vec![
|
||||
ConfiguredSurface {
|
||||
id: "desk".into(),
|
||||
label: "Desk controller".into(),
|
||||
},
|
||||
ConfiguredSurface {
|
||||
id: "spare".into(),
|
||||
label: "Spare controller".into(),
|
||||
},
|
||||
];
|
||||
snapshot.devices = vec![
|
||||
MidiDevice {
|
||||
id: "desk".into(),
|
||||
|
|
@ -6258,6 +6410,10 @@ mod tests {
|
|||
density: FaderDensity::Standard,
|
||||
}];
|
||||
snapshot.configuration.default_controller = Some("desk".into());
|
||||
snapshot.configuration.surfaces = vec![ConfiguredSurface {
|
||||
id: "desk".into(),
|
||||
label: "Desk controller".into(),
|
||||
}];
|
||||
snapshot.devices = vec![MidiDevice {
|
||||
id: "desk".into(),
|
||||
label: "Desk controller".into(),
|
||||
|
|
@ -6660,6 +6816,10 @@ mod tests {
|
|||
status_display: StatusDisplayMode::Detailed,
|
||||
default_controller: Some("desk-left".into()),
|
||||
theme: ThemeName::Dracula,
|
||||
surfaces: vec![ConfiguredSurface {
|
||||
id: "desk-left".into(),
|
||||
label: "Desk Left".into(),
|
||||
}],
|
||||
applications: vec![ConfiguredApplication {
|
||||
id: "browser".into(),
|
||||
label: "Browser".into(),
|
||||
|
|
@ -6770,6 +6930,16 @@ mod tests {
|
|||
let edits = Arc::new(Mutex::new(Vec::new()));
|
||||
let mut snapshot = DemoClient::default().view();
|
||||
snapshot.configuration.default_controller = Some("desk-left".into());
|
||||
snapshot.configuration.surfaces = vec![
|
||||
ConfiguredSurface {
|
||||
id: "desk-left".into(),
|
||||
label: "Left controller".into(),
|
||||
},
|
||||
ConfiguredSurface {
|
||||
id: "desk-right".into(),
|
||||
label: "Right controller".into(),
|
||||
},
|
||||
];
|
||||
snapshot.devices = vec![
|
||||
MidiDevice {
|
||||
id: "desk-left".into(),
|
||||
|
|
@ -6812,6 +6982,7 @@ mod tests {
|
|||
assert!(rendered.contains("Device ID desk-left"));
|
||||
assert!(rendered.contains("Backend port 20:0"));
|
||||
assert!(rendered.contains("Default controller true"));
|
||||
assert!(rendered.contains("Remove device [D]"));
|
||||
|
||||
app.handle_key_event(press(KeyCode::Enter));
|
||||
assert_eq!(app.snapshot.configuration.default_controller, None);
|
||||
|
|
@ -6884,6 +7055,9 @@ mod tests {
|
|||
assert!(rendered.contains("Add as controller"));
|
||||
|
||||
app.handle_key_event(press(KeyCode::Enter));
|
||||
assert!(app.snapshot.devices.iter().any(|device| {
|
||||
device.id == "apc-mini-apc-mini-midi-1" && device.status == DRAFT_DEVICE_STATUS
|
||||
}));
|
||||
assert!(matches!(
|
||||
edits.lock().unwrap().as_slice(),
|
||||
[ConfigurationEdit::AddSurface {
|
||||
|
|
@ -6897,6 +7071,67 @@ mod tests {
|
|||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn configured_midi_device_can_be_removed_with_confirmation() {
|
||||
let edits = Arc::new(Mutex::new(Vec::new()));
|
||||
let mut snapshot = DemoClient::default().view();
|
||||
snapshot.configuration.default_controller = Some("desk".into());
|
||||
snapshot.configuration.surfaces = vec![ConfiguredSurface {
|
||||
id: "desk".into(),
|
||||
label: "Desk controller".into(),
|
||||
}];
|
||||
snapshot.configuration.bindings = vec![ConfiguredBinding {
|
||||
surface: "desk".into(),
|
||||
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,
|
||||
}];
|
||||
let mut app = LiveTui::new(LayoutClient {
|
||||
snapshot,
|
||||
edits: Arc::clone(&edits),
|
||||
})
|
||||
.unwrap();
|
||||
app.handle_key_event(press(KeyCode::Char('2')));
|
||||
app.settings_selected = app
|
||||
.settings_rows()
|
||||
.iter()
|
||||
.position(|row| matches!(row, SettingsRow::MidiDevice { id } if id == "desk"))
|
||||
.unwrap();
|
||||
app.handle_key_event(press(KeyCode::Char('D')));
|
||||
|
||||
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("Confirm device removal"));
|
||||
assert!(rendered.contains("Its MIDI bindings will also be removed."));
|
||||
|
||||
app.handle_key_event(press(KeyCode::Char('y')));
|
||||
|
||||
assert!(app.snapshot.configuration.surfaces.is_empty());
|
||||
assert!(app.snapshot.devices.is_empty());
|
||||
assert!(app.snapshot.configuration.bindings.is_empty());
|
||||
assert_eq!(app.snapshot.configuration.default_controller, None);
|
||||
assert!(matches!(
|
||||
edits.lock().unwrap().last(),
|
||||
Some(ConfigurationEdit::RemoveSurface { id }) if id == "desk"
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn legacy_empty_profile_can_add_a_master_fader_from_settings() {
|
||||
let edits = Arc::new(Mutex::new(Vec::new()));
|
||||
|
|
@ -6931,6 +7166,10 @@ mod tests {
|
|||
fn configuration_tab_changes_theme_without_raw_object_editors() {
|
||||
let edits = Arc::new(Mutex::new(Vec::new()));
|
||||
let mut snapshot = DemoClient::default().view();
|
||||
snapshot.configuration.surfaces.push(ConfiguredSurface {
|
||||
id: "desk".into(),
|
||||
label: "Desk controller".into(),
|
||||
});
|
||||
snapshot.devices.push(MidiDevice {
|
||||
id: "desk".into(),
|
||||
label: "Desk controller".into(),
|
||||
|
|
|
|||
Loading…
Reference in New Issue