feat: expose M13.1 selector composition in fader editor

Add revisioned Any/OR and All/AND editing, optimistic display and persistence across a fresh editor instance. Preserve legacy IPC defaults.

Verification passed: cargo test -p tui --quiet; cargo test -p fader_master selector_mode --quiet; cargo fmt --all -- --check; cargo check --workspace --all-targets --all-features; cargo test --workspace --all-targets --all-features --quiet; cargo test --workspace --doc --all-features; cargo clippy --workspace --all-targets --all-features -- -D warnings; cargo build --workspace --release --all-features; default and no-default-features workspace builds; volume_lib pulse and midi midir builds. Hardware fixtures remain opt-in. Regression first failed on missing Match captures row.
This commit is contained in:
Dandaedre 2026-10-18 22:21:39 +02:00
parent 002570a848
commit 64f08e9db0
Signed by: Dandaedre
GPG Key ID: 440C6592E8A26D99
9 changed files with 153 additions and 4 deletions

View File

@ -135,7 +135,8 @@ All outer crates depend inward on domain contracts; core depends on none of them
The agreed stretch-goal order is AND selectors and richer process metadata,
then targeted MPRIS media controls (M13 in `task.md`). Selector composition is
implemented in the domain/configuration layer; process metadata and media
implemented in the domain/configuration layer and the fader editor's Match
captures toggle (Any/OR or All/AND); process metadata and media
controls remain future work, not additions to the current profile schema.
The existing `media.name` regex `(?i) - YouTube$` is sufficient for YouTube

View File

@ -129,6 +129,10 @@ and case-sensitive. Regexes use Rust's bounded `regex` syntax.
Applications may set `selector_mode = "all"` to require every selector to
match (AND). The default `"any"` preserves OR matching for existing profiles.
The fader editor's **Match captures** row toggles **Any (OR)** / **All (AND)**
for the application; save the configuration to activate the change. Individual
Capture rows continue to edit their respective selectors without replacing the
rest of the list.
Missing fields fail their selector; empty selector lists and unknown modes are
rejected. For example, requiring a particular application ID and media title:

View File

@ -162,6 +162,16 @@ impl ConfigurationEditor {
self.document
.set_application(&id, &label, &[selector(&field, pattern, regex)?])?
}
ConfigurationEdit::SetApplicationSelectorMode { id, match_all } => {
self.document.set_application_selector_mode(
&id,
if match_all {
fader_config::SelectorMode::All
} else {
fader_config::SelectorMode::Any
},
)?;
}
ConfigurationEdit::SetApplicationSelector {
id,
index,
@ -709,6 +719,44 @@ mod tests {
));
}
#[test]
fn selector_mode_is_saved_reloaded_and_published_to_clients() {
let root = tempdir().unwrap();
let path = root.path().join("desktop.toml");
fs::write(&path, PROFILE).unwrap();
let mut editor =
ConfigurationEditor::new(ProfileDocument::parse(PROFILE).unwrap(), path.clone());
editor
.apply(
0,
ConfigurationEdit::SetApplicationSelectorMode {
id: "music".into(),
match_all: true,
},
)
.unwrap();
editor.save(1).unwrap();
let document = ProfileDocument::parse(&fs::read_to_string(&path).unwrap()).unwrap();
let profile = document.preview().unwrap();
let snapshot = crate::live::configuration_snapshot(&profile, 0, false, 0);
assert!(snapshot.applications[0].match_all);
assert!(!snapshot.applications[1].match_all);
let mut restarted = ConfigurationEditor::new(document, path);
let profile = restarted
.apply(
0,
ConfigurationEdit::SetApplicationSelectorMode {
id: "music".into(),
match_all: false,
},
)
.unwrap();
assert_eq!(
profile.applications()[0].selector_mode(),
fader_config::SelectorMode::Any
);
}
#[test]
fn layout_edits_are_revisioned_without_changing_fader_routing() {
let root = tempdir().unwrap();

View File

@ -127,6 +127,10 @@ pub enum ConfigurationEdit {
pattern: String,
regex: bool,
},
SetApplicationSelectorMode {
id: String,
match_all: bool,
},
SetApplicationSelector {
id: String,
index: usize,
@ -356,6 +360,8 @@ pub enum FaderDensity {
pub struct ConfiguredApplication {
pub id: String,
pub label: String,
#[serde(default)]
pub match_all: bool,
pub selectors: Vec<ConfiguredSelector>,
}

View File

@ -154,6 +154,7 @@ pub(crate) fn configuration_snapshot(
.map(|application| IpcApplication {
id: application.id().to_owned(),
label: application.label().to_owned(),
match_all: application.selector_mode() == fader_config::SelectorMode::All,
selectors: application
.selectors()
.iter()

View File

@ -151,6 +151,7 @@ impl IpcMixerClient {
.map(|application| tui::ConfiguredApplication {
id: application.id,
label: application.label,
match_all: application.match_all,
selectors: application
.selectors
.into_iter()
@ -548,6 +549,9 @@ fn configuration_edit(edit: TuiConfigurationEdit) -> crate::ipc::ConfigurationEd
tui::SeparatorDecoration::Box => crate::ipc::SeparatorDecoration::Box,
},
},
TuiConfigurationEdit::SetApplicationSelectorMode { id, match_all } => {
IpcEdit::SetApplicationSelectorMode { id, match_all }
}
TuiConfigurationEdit::SetApplicationSelector {
id,
index,

View File

@ -581,14 +581,17 @@ supported configuration or mark the remaining release qualifications complete.
The existing `media.name` selector `(?i) - YouTube$` already satisfies the
YouTube capture use case; no browser-name condition is needed.
- [ ] **M13.1 AND selectors:** add explicit conjunction while preserving existing
- [x] **M13.1 AND selectors:** add explicit conjunction while preserving existing
OR-list behavior. Dependencies: M1.2, M9.5. Acceptance: configuration and TUI
express the composition clearly; exact/regex and missing-field behavior are
deterministic; existing profiles retain their matches; invalid composition
is rejected before activation; save/reload preserves the expression.
Domain/configuration slice: `selector_mode = "any"` (default OR) or `"all"`
(AND), preserving missing-field and bounded pattern validation. TUI integration
and full milestone verification remain pending.
(AND), preserving missing-field and bounded pattern validation. The fader
editor exposes Match captures Any/All, with revisioned IPC edits and a
save/reload/restart regression. Workspace formatting, check, tests, doc tests,
clippy and release build pass, as do default/no-default and individual backend
builds. Existing profile semantics remain unchanged.
- [ ] **M13.2 Richer process metadata:** enrich stream metadata with available
process paths and Steam launch identity, then expose validated matcher fields
and useful diagnostics. Dependencies: M1.2, M4. Acceptance: bounded adapter

View File

@ -158,16 +158,19 @@ fn snapshot(mixer_orientation: MixerOrientation) -> MixerSnapshot {
ConfiguredApplication {
id: "music".to_owned(),
label: "Music".to_owned(),
match_all: false,
selectors: Vec::new(),
},
ConfiguredApplication {
id: "browser".to_owned(),
label: "Browser".to_owned(),
match_all: false,
selectors: Vec::new(),
},
ConfiguredApplication {
id: "voice".to_owned(),
label: "Voice chat".to_owned(),
match_all: false,
selectors: Vec::new(),
},
],

View File

@ -298,6 +298,7 @@ impl FaderDensity {
pub struct ConfiguredApplication {
pub id: String,
pub label: String,
pub match_all: bool,
pub selectors: Vec<ConfiguredSelector>,
}
@ -454,6 +455,10 @@ pub enum ConfigurationEdit {
RemoveSeparator {
id: String,
},
SetApplicationSelectorMode {
id: String,
match_all: bool,
},
SetApplicationSelector {
id: String,
index: usize,
@ -983,6 +988,17 @@ fn publish_confirmed(state: &mut BufferedState, confirmed: &MixerSnapshot) {
fn apply_optimistic_configuration_edit(snapshot: &mut MixerSnapshot, edit: &ConfigurationEdit) {
match edit {
ConfigurationEdit::SetApplicationSelectorMode { id, match_all } => {
if let Some(application) = snapshot
.configuration
.applications
.iter_mut()
.find(|app| app.id == *id)
{
application.match_all = *match_all;
snapshot.configuration.dirty = true;
}
}
ConfigurationEdit::AddSurface { id, label, .. } => {
snapshot.configuration.surfaces.push(ConfiguredSurface {
id: id.clone(),
@ -1065,6 +1081,7 @@ fn apply_optimistic_configuration_edit(snapshot: &mut MixerSnapshot, edit: &Conf
.push(ConfiguredApplication {
id: application_id.clone(),
label: label.clone(),
match_all: false,
selectors: vec![ConfiguredSelector {
field: field.clone(),
pattern: pattern.clone(),
@ -1406,6 +1423,10 @@ struct DeviceDeleteConfirmation {
}
enum FaderEditorRow {
SelectorMode {
application: String,
match_all: bool,
},
Name {
target: MixerObjectId,
label: String,
@ -2830,6 +2851,21 @@ impl<C: MixerClient> LiveTui<C> {
.unwrap_or((false, FaderDensity::Standard));
rows.push(FaderEditorRow::Density { density });
rows.push(FaderEditorRow::Visibility { hidden });
if let Some(application) =
self.snapshot
.configuration
.applications
.iter()
.find(|application| {
fader.target.kind == MixerObjectKind::Application
&& application.id == fader.target.id
})
{
rows.push(FaderEditorRow::SelectorMode {
application: application.id.clone(),
match_all: application.match_all,
});
}
if self.snapshot.configuration.dirty {
rows.push(FaderEditorRow::Save);
}
@ -2904,6 +2940,15 @@ impl<C: MixerClient> LiveTui<C> {
return;
};
match row {
FaderEditorRow::SelectorMode {
application,
match_all,
} => {
self.apply_layout_edit(ConfigurationEdit::SetApplicationSelectorMode {
id: application,
match_all: !match_all,
});
}
FaderEditorRow::Name { target, label } => {
self.rename_editor = Some(RenameEditor {
target,
@ -4069,6 +4114,10 @@ impl<C: MixerClient> LiveTui<C> {
.map(|(index, row)| {
let marker = if index == editor.selected { "▶" } else { " " };
let text = match row {
FaderEditorRow::SelectorMode { match_all, .. } => format!(
"{marker} Match captures {} [Enter to toggle]",
if *match_all { "All (AND)" } else { "Any (OR)" }
),
FaderEditorRow::Name { label, .. } => {
format!("{marker} Name {label} [Enter to rename]")
}
@ -5366,6 +5415,9 @@ mod tests {
.retain(|entry| {
!matches!(entry, MixerLayoutEntry::Separator { id: separator, .. } if separator == id)
}),
ConfigurationEdit::SetApplicationSelectorMode { .. } => {
apply_optimistic_configuration_edit(&mut self.snapshot, &edit);
}
ConfigurationEdit::SetApplicationSelector {
id,
index,
@ -5838,6 +5890,7 @@ mod tests {
snapshot.configuration.applications = vec![ConfiguredApplication {
id: "desktop".into(),
label: "Desktop audio".into(),
match_all: false,
selectors: vec![ConfiguredSelector {
field: "application.name".into(),
pattern: "Desktop audio".into(),
@ -6464,6 +6517,7 @@ mod tests {
snapshot.configuration.applications = vec![ConfiguredApplication {
id: "music".into(),
label: "Music".into(),
match_all: false,
selectors: vec![ConfiguredSelector {
field: "application.name".into(),
pattern: "Old Player".into(),
@ -6536,6 +6590,7 @@ mod tests {
assert!(rendered.contains("Edit fader: music-fader"));
assert!(rendered.contains("Name Music"));
assert!(rendered.contains("Capture 1"));
assert!(rendered.contains("Match captures Any (OR)"));
assert!(rendered.contains("Volume controller"));
assert!(rendered.contains("Learn volume MIDI"));
assert!(!rendered.contains("Unlearn volume MIDI"));
@ -6640,6 +6695,25 @@ mod tests {
app.handle_key_event(press(KeyCode::Char('u')));
assert!(app.snapshot.configuration.learning.is_none());
let mode_row = app
.fader_editor_rows()
.iter()
.position(|row| matches!(row, FaderEditorRow::SelectorMode { .. }))
.unwrap();
app.fader_editor.as_mut().unwrap().selected = mode_row;
app.handle_key_event(press(KeyCode::Enter));
assert!(app.snapshot.configuration.applications[0].match_all);
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("Match captures All (AND)"));
app.handle_key_event(press(KeyCode::Enter));
assert!(!app.snapshot.configuration.applications[0].match_all);
let edits = edits.lock().unwrap();
assert!(edits.iter().any(|edit| matches!(
edit,
@ -6779,6 +6853,7 @@ mod tests {
snapshot.configuration.applications = vec![ConfiguredApplication {
id: "music".into(),
label: "Music".into(),
match_all: false,
selectors: Vec::new(),
}];
snapshot.configuration.faders = vec![ConfiguredFader {
@ -6871,6 +6946,7 @@ mod tests {
snapshot.configuration.applications = vec![ConfiguredApplication {
id: "music".into(),
label: "Music".into(),
match_all: false,
selectors: Vec::new(),
}];
snapshot.configuration.faders = vec![ConfiguredFader {
@ -7078,11 +7154,13 @@ mod tests {
ConfiguredApplication {
id: "music".into(),
label: "Music".into(),
match_all: false,
selectors: Vec::new(),
},
ConfiguredApplication {
id: "browser".into(),
label: "Browser".into(),
match_all: false,
selectors: Vec::new(),
},
];
@ -7211,6 +7289,7 @@ mod tests {
applications: vec![ConfiguredApplication {
id: "browser".into(),
label: "Browser".into(),
match_all: false,
selectors: vec![ConfiguredSelector {
field: "application.process.binary".into(),
pattern: "firefox".into(),