fix: project editor values from profiles

Publish configured group modes and pickup tolerances through IPC so the TUI renders server-owned draft values. Preserve unrelated group modes and fader tolerances during edits, and document the projection invariant. Protocol version is now 11.\n\nTests: cargo fmt --all -- --check\nTests: cargo check --workspace --all-targets --all-features\nTests: cargo test --workspace --all-targets --all-features\nTests: cargo test --workspace --doc --all-features\nTests: cargo clippy --workspace --all-targets --all-features -- -D warnings\nTests: cargo build --workspace --release --all-features\nTests: cargo check --workspace --all-targets --no-default-features\nTests: cargo test --workspace --all-targets --no-default-features\nTests: cargo check -p midi --all-targets --no-default-features --features midir\nTests: cargo check -p volume_lib --all-targets --no-default-features --features pulse
This commit is contained in:
Dandaedre 2026-10-15 18:02:22 +02:00
parent 1da6da5da2
commit 93506e0a67
Signed by: Dandaedre
GPG Key ID: 440C6592E8A26D99
7 changed files with 156 additions and 37 deletions

View File

@ -421,6 +421,12 @@ 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.
Every value presented as configuration is read from the server-owned validated
profile draft and every edit targets that same profile field. The TUI must not
invent parallel configuration defaults or overwrite unrelated fields; local
state is limited to clearly transient navigation and presentation choices such
as selection, open dialogs, the hidden-items view, and the session theme.
Draft changes do not affect live routing or audio. Apply and Save remain
distinct server-owned revisioned operations, validation errors preserve the
draft, MIDI learn reserves the selected action and suppresses its normal action,

View File

@ -180,7 +180,7 @@ impl ProfileDocument {
})
}
/// Replaces a group's label and absolute member set.
/// Replaces a group's label and member set without changing its mode.
pub fn set_group(
&mut self,
id: &str,
@ -191,7 +191,6 @@ impl ProfileDocument {
let table = find_table_mut(document, "groups", id)?;
table["label"] = value(label);
table["members"] = value(string_array(members));
table["volume_mode"] = value("absolute");
Ok(())
})
}

View File

@ -111,6 +111,23 @@ fn existing_applications_groups_and_faders_can_be_edited_and_deleted() {
assert!(draft.source().contains("media-fader"));
}
#[test]
fn editing_group_members_preserves_the_configured_volume_mode_field() {
let source = PROFILE.replace(
"volume_mode = \"absolute\"",
"volume_mode = \"absolute\" # user-owned group mode",
);
let mut draft = ProfileDocument::parse(&source).unwrap();
draft.set_group("media", "Players", &["browser"]).unwrap();
assert!(
draft
.source()
.contains("volume_mode = \"absolute\" # user-owned group mode")
);
}
#[test]
fn draft_adds_bindings_and_rejects_duplicate_physical_controls() {
let mut draft = ProfileDocument::parse(PROFILE).unwrap();

View File

@ -3,7 +3,7 @@ use std::io::{self, Read, Write};
use serde::{Deserialize, Serialize, de::DeserializeOwned};
use thiserror::Error;
pub const PROTOCOL_VERSION: u16 = 10;
pub const PROTOCOL_VERSION: u16 = 11;
pub const MAX_FRAME_BYTES: usize = 64 * 1024;
/// Kind of mixer object addressed by a client.
@ -195,7 +195,7 @@ pub struct MixerSnapshot {
pub configuration: ConfigurationSnapshot,
}
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
pub struct ConfigurationSnapshot {
pub revision: u64,
pub dirty: bool,
@ -232,18 +232,27 @@ pub struct ConfiguredSelector {
pub regex: bool,
}
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum GroupVolumeMode {
Absolute,
Relative,
}
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct ConfiguredGroup {
pub id: String,
pub label: String,
pub members: Vec<String>,
pub volume_mode: GroupVolumeMode,
}
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct ConfiguredFader {
pub id: String,
pub target: MixerObjectKey,
pub pickup: bool,
pub pickup_tolerance: f64,
}
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]

View File

@ -13,9 +13,9 @@ use volume_lib::WorkerEvent;
use crate::ipc::{
ClientRequest, ConfigurationSnapshot, ConfiguredApplication as IpcApplication,
ConfiguredBinding as IpcBinding, ConfiguredFader as IpcFader, ConfiguredGroup as IpcGroup,
ConfiguredSelector as IpcSelector, MidiDevice, MixerLayoutEntry as IpcLayoutEntry, MixerObject,
MixerObjectKey, MixerObjectKind, MixerSnapshot, PROTOCOL_VERSION, PickupStatus, RequestCommand,
ResponseResult, ServerResponse,
ConfiguredSelector as IpcSelector, GroupVolumeMode, MidiDevice,
MixerLayoutEntry as IpcLayoutEntry, MixerObject, MixerObjectKey, MixerObjectKind,
MixerSnapshot, PROTOCOL_VERSION, PickupStatus, RequestCommand, ResponseResult, ServerResponse,
};
#[derive(Clone, Debug)]
@ -143,6 +143,10 @@ pub(crate) fn configuration_snapshot(
id: group.id().to_owned(),
label: group.label().to_owned(),
members: group.members().to_vec(),
volume_mode: match group.volume_mode() {
fader_core::VolumeMode::Absolute => GroupVolumeMode::Absolute,
fader_core::VolumeMode::Relative => GroupVolumeMode::Relative,
},
})
.collect(),
faders: profile
@ -159,6 +163,7 @@ pub(crate) fn configuration_snapshot(
id: fader.target_id().to_owned(),
},
pickup: fader.pickup(),
pickup_tolerance: fader.pickup_tolerance(),
})
.collect(),
mixer_layout: profile
@ -998,6 +1003,19 @@ impl LiveMixerState {
mod reconfigure_tests {
use super::*;
#[test]
fn configuration_snapshot_exposes_profile_backed_editor_values() {
let profile = Profile::parse(include_str!("../../examples/profiles/desktop.toml")).unwrap();
let snapshot = configuration_snapshot(&profile, 0, false, 0);
assert_eq!(
snapshot.groups[0].volume_mode,
crate::ipc::GroupVolumeMode::Absolute
);
assert_eq!(snapshot.faders[0].pickup_tolerance, 0.02);
}
fn desired() -> Vec<DesiredWrite> {
let state = fader_config::PersistedState::parse(
r#"

View File

@ -123,6 +123,14 @@ impl IpcMixerClient {
id: group.id,
label: group.label,
members: group.members,
volume_mode: match group.volume_mode {
crate::ipc::GroupVolumeMode::Absolute => {
tui::GroupVolumeMode::Absolute
}
crate::ipc::GroupVolumeMode::Relative => {
tui::GroupVolumeMode::Relative
}
},
})
.collect(),
faders: snapshot
@ -140,6 +148,7 @@ impl IpcMixerClient {
id: fader.target.id,
},
pickup: fader.pickup,
pickup_tolerance: fader.pickup_tolerance,
})
.collect(),
mixer_layout: snapshot

View File

@ -74,7 +74,7 @@ pub struct MidiDevice {
pub error: Option<String>,
}
#[derive(Clone, Debug, Default, Eq, PartialEq)]
#[derive(Clone, Debug, Default, PartialEq)]
pub struct ConfigurationSnapshot {
pub revision: u64,
pub dirty: bool,
@ -110,18 +110,35 @@ pub struct ConfiguredSelector {
pub regex: bool,
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum GroupVolumeMode {
Absolute,
Relative,
}
impl GroupVolumeMode {
const fn label(self) -> &'static str {
match self {
Self::Absolute => "Absolute",
Self::Relative => "Relative",
}
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ConfiguredGroup {
pub id: String,
pub label: String,
pub members: Vec<String>,
pub volume_mode: GroupVolumeMode,
}
#[derive(Clone, Debug, Eq, PartialEq)]
#[derive(Clone, Debug, PartialEq)]
pub struct ConfiguredFader {
pub id: String,
pub target: MixerObjectId,
pub pickup: bool,
pub pickup_tolerance: f64,
}
#[derive(Clone, Debug, Eq, PartialEq)]
@ -772,7 +789,9 @@ enum FaderEditorRow {
label: String,
included: bool,
},
GroupMode,
GroupMode {
mode: GroupVolumeMode,
},
Binding {
action: &'static str,
label: &'static str,
@ -1202,25 +1221,28 @@ impl<C: MixerClient> LiveTui<C> {
.map(str::to_owned)
.collect(),
}),
EditorOperation::Fader if fields.len() == 4 => Ok(ConfigurationEdit::Fader {
existing: self
EditorOperation::Fader if fields.len() == 4 => {
let configured = self
.snapshot
.configuration
.faders
.iter()
.any(|item| item.id == fields[0]),
id: fields[0].to_owned(),
target: MixerObjectId {
kind: parse_kind(fields[1])?,
id: fields[2].to_owned(),
},
pickup: match fields[3] {
"yes" | "true" => true,
"no" | "false" => false,
_ => return Err("pickup must be yes/no or true/false".to_owned()),
},
pickup_tolerance: 0.02,
}),
.find(|item| item.id == fields[0]);
Ok(ConfigurationEdit::Fader {
existing: configured.is_some(),
id: fields[0].to_owned(),
target: MixerObjectId {
kind: parse_kind(fields[1])?,
id: fields[2].to_owned(),
},
pickup: match fields[3] {
"yes" | "true" => true,
"no" | "false" => false,
_ => return Err("pickup must be yes/no or true/false".to_owned()),
},
pickup_tolerance: configured.map_or(0.02, |fader| fader.pickup_tolerance),
})
}
EditorOperation::Remove
if fields.len() == 2 && matches!(fields[0], "application" | "group" | "fader") =>
{
@ -1311,7 +1333,9 @@ impl<C: MixerClient> LiveTui<C> {
included: group.members.contains(&application_fader.target.id),
});
}
rows.push(FaderEditorRow::GroupMode);
rows.push(FaderEditorRow::GroupMode {
mode: group.volume_mode,
});
}
}
MixerObjectKind::Output => {}
@ -1986,8 +2010,8 @@ impl<C: MixerClient> LiveTui<C> {
"{marker} [{}] Group member {label}",
if *included { "x" } else { " " }
),
FaderEditorRow::GroupMode => {
format!("{marker} Group mode Absolute (current supported mode)")
FaderEditorRow::GroupMode { mode } => {
format!("{marker} Group mode {}", mode.label())
}
FaderEditorRow::Binding { label, value, .. } => {
format!("{marker} {label} {value} [L learn · U unset]")
@ -2164,10 +2188,11 @@ impl<C: MixerClient> LiveTui<C> {
lines.push(Line::from("Groups").fg(theme.accent).bold());
lines.extend(config.groups.iter().map(|group| {
Line::from(format!(
" {} — {} [{}]",
" {} — {} [{}] · {} mode",
group.id,
group.label,
group.members.join(", ")
group.members.join(", "),
group.volume_mode.label()
))
}));
lines.push(
@ -2182,11 +2207,12 @@ impl<C: MixerClient> LiveTui<C> {
MixerObjectKind::Output => "output",
};
lines.push(Line::from(format!(
" {} -> {}:{}{}",
" {} -> {}:{}{} · pickup tolerance {:.3}",
fader.id,
target_kind,
fader.target.id,
if fader.pickup { " (pickup)" } else { "" }
if fader.pickup { " (pickup)" } else { "" },
fader.pickup_tolerance
)));
lines.extend(
config
@ -2686,11 +2712,13 @@ mod tests {
id: "music-fader".into(),
target: snapshot.items[0].id.clone(),
pickup: true,
pickup_tolerance: 0.02,
},
ConfiguredFader {
id: "browser-fader".into(),
target: snapshot.items[1].id.clone(),
pickup: true,
pickup_tolerance: 0.02,
},
];
snapshot.configuration.mixer_layout = vec![
@ -2786,6 +2814,7 @@ mod tests {
id: "music-fader".into(),
target: snapshot.items[0].id.clone(),
pickup: true,
pickup_tolerance: 0.02,
}];
snapshot.configuration.mixer_layout = vec![MixerLayoutEntry::Fader {
fader: "music-fader".into(),
@ -2894,12 +2923,14 @@ mod tests {
id: "media".into(),
label: "Media".into(),
members: vec!["music".into()],
volume_mode: GroupVolumeMode::Relative,
}];
snapshot.configuration.faders = vec![
ConfiguredFader {
id: "media-fader".into(),
target: snapshot.items[0].id.clone(),
pickup: true,
pickup_tolerance: 0.02,
},
ConfiguredFader {
id: "music-fader".into(),
@ -2908,6 +2939,7 @@ mod tests {
id: "music".into(),
},
pickup: true,
pickup_tolerance: 0.02,
},
ConfiguredFader {
id: "browser-fader".into(),
@ -2916,6 +2948,7 @@ mod tests {
id: "browser".into(),
},
pickup: true,
pickup_tolerance: 0.02,
},
];
snapshot.configuration.mixer_layout = vec![MixerLayoutEntry::Fader {
@ -2940,7 +2973,7 @@ mod tests {
.collect::<String>();
assert!(rendered.contains("[x] Group member Music"));
assert!(rendered.contains("[ ] Group member Browser"));
assert!(rendered.contains("Group mode Absolute"));
assert!(rendered.contains("Group mode Relative"));
app.handle_key_event(press(KeyCode::Enter));
assert!(edits.lock().unwrap().iter().any(|edit| matches!(
@ -2975,6 +3008,7 @@ mod tests {
id: "media".into(),
label: "Media".into(),
members: vec!["browser".into()],
volume_mode: GroupVolumeMode::Absolute,
}],
faders: vec![ConfiguredFader {
id: "media-fader".into(),
@ -2983,6 +3017,7 @@ mod tests {
id: "media".into(),
},
pickup: true,
pickup_tolerance: 0.075,
}],
mixer_layout: vec![MixerLayoutEntry::Fader {
fader: "media-fader".into(),
@ -3011,8 +3046,9 @@ mod tests {
assert!(rendered.contains("Profile: desktop"));
assert!(rendered.contains("unsaved draft"));
assert!(rendered.contains("media — Media [browser]"));
assert!(rendered.contains("media — Media [browser] · Absolute mode"));
assert!(rendered.contains("media-fader -> group:media (pickup)"));
assert!(rendered.contains("pickup tolerance 0.075"));
assert!(rendered.contains("desk-left · volume · cc ch1 #49"));
}
@ -3050,7 +3086,7 @@ mod tests {
edit: ConfigurationEdit,
expected_revision: u64,
) -> io::Result<MixerSnapshot> {
assert_eq!(expected_revision, 0);
assert_eq!(expected_revision, self.snapshot.configuration.revision);
self.edits.lock().unwrap().push(edit);
self.snapshot.configuration.revision += 1;
self.snapshot.configuration.dirty = true;
@ -3059,8 +3095,18 @@ mod tests {
}
let edits = Arc::new(Mutex::new(Vec::new()));
let mut snapshot = DemoClient::default().view();
snapshot.configuration.faders = vec![ConfiguredFader {
id: "media-fader".into(),
target: MixerObjectId {
kind: MixerObjectKind::Group,
id: "media".into(),
},
pickup: true,
pickup_tolerance: 0.075,
}];
let mut app = LiveTui::new(EditingClient {
snapshot: DemoClient::default().view(),
snapshot,
edits: Arc::clone(&edits),
})
.unwrap();
@ -3088,6 +3134,21 @@ mod tests {
app.handle_key_event(press(KeyCode::Esc));
assert_eq!(edits.lock().unwrap().len(), 1);
assert!(app.editor.is_none());
app.handle_key_event(press(KeyCode::Char('f')));
for character in "media-fader|group|media|yes".chars() {
app.handle_key_event(press(KeyCode::Char(character)));
}
app.handle_key_event(press(KeyCode::Enter));
assert!(edits.lock().unwrap().iter().any(|edit| matches!(
edit,
ConfigurationEdit::Fader {
existing: true,
id,
pickup_tolerance,
..
} if id == "media-fader" && (*pickup_tolerance - 0.075).abs() < f64::EPSILON
)));
}
#[test]