diff --git a/fader_master/src/editor.rs b/fader_master/src/editor.rs index 7a20bca..5cc68fd 100644 --- a/fader_master/src/editor.rs +++ b/fader_master/src/editor.rs @@ -161,6 +161,21 @@ impl ConfigurationEditor { channel, number, )?, + ConfigurationEdit::MoveLayoutEntry { id, position } => { + self.document.move_layout_entry(&id, position)? + } + ConfigurationEdit::SetFaderHidden { id, hidden } => { + self.document.set_fader_hidden(&id, hidden)? + } + ConfigurationEdit::AddSeparator { + id, + label, + position, + } => self.document.add_separator(&id, &label, position)?, + ConfigurationEdit::SetSeparatorLabel { id, label } => { + self.document.set_separator_label(&id, &label)? + } + ConfigurationEdit::RemoveSeparator { id } => self.document.remove_separator(&id)?, } self.revision = self.revision.saturating_add(1); self.dirty = true; @@ -276,6 +291,38 @@ mod tests { assert_eq!(editor.profile().unwrap().faders().len(), 2); } + #[test] + fn layout_edits_are_revisioned_without_changing_fader_routing() { + let root = tempdir().unwrap(); + let path = root.path().join("desktop.toml"); + fs::write(&path, PROFILE).unwrap(); + let document = ProfileDocument::parse(PROFILE).unwrap(); + let mut editor = ConfigurationEditor::new(document, path); + + editor + .apply( + 0, + ConfigurationEdit::AddSeparator { + id: "media-heading".into(), + label: "Media".into(), + position: 0, + }, + ) + .unwrap(); + let profile = editor + .apply( + 1, + ConfigurationEdit::SetFaderHidden { + id: "media-fader".into(), + hidden: true, + }, + ) + .unwrap(); + assert_eq!(profile.faders().len(), 1); + assert_eq!(profile.mixer_layout().len(), 2); + assert_eq!(editor.revision(), 2); + } + #[test] fn save_is_atomic_and_refuses_external_changes() { let root = tempdir().unwrap(); diff --git a/fader_master/src/ipc.rs b/fader_master/src/ipc.rs index 98ba9e1..df356e4 100644 --- a/fader_master/src/ipc.rs +++ b/fader_master/src/ipc.rs @@ -130,6 +130,26 @@ pub enum ConfigurationEdit { channel: u16, number: u16, }, + MoveLayoutEntry { + id: String, + position: usize, + }, + SetFaderHidden { + id: String, + hidden: bool, + }, + AddSeparator { + id: String, + label: String, + position: usize, + }, + SetSeparatorLabel { + id: String, + label: String, + }, + RemoveSeparator { + id: String, + }, } #[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] @@ -168,9 +188,17 @@ pub struct ConfigurationSnapshot { pub applications: Vec, pub groups: Vec, pub faders: Vec, + pub mixer_layout: Vec, pub bindings: Vec, } +#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] +#[serde(tag = "kind", rename_all = "snake_case")] +pub enum MixerLayoutEntry { + Fader { fader: String, hidden: bool }, + Separator { id: String, label: String }, +} + #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] pub struct ConfiguredApplication { pub id: String, diff --git a/fader_master/src/live.rs b/fader_master/src/live.rs index 856e49d..f2b9a78 100644 --- a/fader_master/src/live.rs +++ b/fader_master/src/live.rs @@ -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, - MidiDevice, MixerObject, MixerObjectKey, MixerObjectKind, MixerSnapshot, PROTOCOL_VERSION, - PickupStatus, RequestCommand, ResponseResult, ServerResponse, + MidiDevice, MixerLayoutEntry as IpcLayoutEntry, MixerObject, MixerObjectKey, MixerObjectKind, + MixerSnapshot, PROTOCOL_VERSION, PickupStatus, RequestCommand, ResponseResult, ServerResponse, }; #[derive(Clone, Debug)] @@ -148,6 +148,22 @@ pub(crate) fn configuration_snapshot( pickup: fader.pickup(), }) .collect(), + mixer_layout: profile + .mixer_layout() + .iter() + .map(|entry| match entry { + fader_config::MixerLayoutEntry::Fader { fader, hidden } => IpcLayoutEntry::Fader { + fader: fader.clone(), + hidden: *hidden, + }, + fader_config::MixerLayoutEntry::Separator { id, label } => { + IpcLayoutEntry::Separator { + id: id.clone(), + label: label.clone(), + } + } + }) + .collect(), bindings: profile .bindings() .iter() diff --git a/fader_master/src/tui_client.rs b/fader_master/src/tui_client.rs index 035cb64..11db71b 100644 --- a/fader_master/src/tui_client.rs +++ b/fader_master/src/tui_client.rs @@ -133,6 +133,19 @@ impl IpcMixerClient { pickup: fader.pickup, }) .collect(), + mixer_layout: snapshot + .configuration + .mixer_layout + .into_iter() + .map(|entry| match entry { + crate::ipc::MixerLayoutEntry::Fader { fader, hidden } => { + tui::MixerLayoutEntry::Fader { fader, hidden } + } + crate::ipc::MixerLayoutEntry::Separator { id, label } => { + tui::MixerLayoutEntry::Separator { id, label } + } + }) + .collect(), bindings: snapshot .configuration .bindings @@ -297,6 +310,25 @@ fn configuration_edit(edit: TuiConfigurationEdit) -> crate::ipc::ConfigurationEd "fader" => IpcEdit::RemoveFader { id }, _ => IpcEdit::RemoveApplication { id }, }, + TuiConfigurationEdit::MoveLayoutEntry { id, position } => { + IpcEdit::MoveLayoutEntry { id, position } + } + TuiConfigurationEdit::SetFaderHidden { id, hidden } => { + IpcEdit::SetFaderHidden { id, hidden } + } + TuiConfigurationEdit::AddSeparator { + id, + label, + position, + } => IpcEdit::AddSeparator { + id, + label, + position, + }, + TuiConfigurationEdit::SetSeparatorLabel { id, label } => { + IpcEdit::SetSeparatorLabel { id, label } + } + TuiConfigurationEdit::RemoveSeparator { id } => IpcEdit::RemoveSeparator { id }, } } diff --git a/tui/src/lib.rs b/tui/src/lib.rs index 3e6d762..5f688d8 100644 --- a/tui/src/lib.rs +++ b/tui/src/lib.rs @@ -86,9 +86,16 @@ pub struct ConfigurationSnapshot { pub applications: Vec, pub groups: Vec, pub faders: Vec, + pub mixer_layout: Vec, pub bindings: Vec, } +#[derive(Clone, Debug, Eq, PartialEq)] +pub enum MixerLayoutEntry { + Fader { fader: String, hidden: bool }, + Separator { id: String, label: String }, +} + #[derive(Clone, Debug, Eq, PartialEq)] pub struct ConfiguredApplication { pub id: String, @@ -144,6 +151,26 @@ pub enum ConfigurationEdit { kind: String, id: String, }, + MoveLayoutEntry { + id: String, + position: usize, + }, + SetFaderHidden { + id: String, + hidden: bool, + }, + AddSeparator { + id: String, + label: String, + position: usize, + }, + SetSeparatorLabel { + id: String, + label: String, + }, + RemoveSeparator { + id: String, + }, } #[derive(Clone, Debug, PartialEq)] @@ -1666,6 +1693,10 @@ mod tests { }, pickup: true, }], + mixer_layout: vec![MixerLayoutEntry::Fader { + fader: "media-fader".into(), + hidden: false, + }], bindings: vec![ConfiguredBinding { surface: "desk-left".into(), fader: "media-fader".into(),