feat(M8.1): expose validated mixer profile views
Rust CI fader_master failed CI.
MadGobblins/fader_master/pipeline/head There was a failure building this commit Details

Tests: cargo test --locked -p fader-config --test schema
Lint: cargo clippy --locked -p fader-config --all-targets -- -D warnings
This commit is contained in:
Dandaedre 2026-10-15 01:10:24 +02:00
parent 86b6c0ee41
commit d21a57f4d5
Signed by: Dandaedre
GPG Key ID: 440C6592E8A26D99
2 changed files with 100 additions and 2 deletions

View File

@ -1,8 +1,8 @@
use std::collections::{BTreeMap, BTreeSet};
use fader_core::{
ApplicationId, ApplicationSelector, FaderId, GroupId, MetadataField, MidiChannel, MidiData,
ProfileId, SurfaceId,
ApplicationId, ApplicationMatcher, ApplicationSelector, FaderId, GroupId, MetadataField,
MidiChannel, MidiData, ProfileId, SurfaceId,
};
use serde::{Deserialize, Serialize};
@ -290,6 +290,83 @@ impl Audio {
}
}
impl Application {
/// Stable application identifier from the validated profile.
#[must_use]
pub fn id(&self) -> &str {
&self.id
}
/// User-facing application label.
#[must_use]
pub fn label(&self) -> &str {
&self.label
}
/// Compiles this validated application's selectors for live stream matching.
pub fn matcher(&self) -> Result<ApplicationMatcher, ConfigError> {
let id = parse_id::<ApplicationId>(&self.id, "application.id")?;
let selectors = self
.selectors
.iter()
.map(Selector::compile)
.collect::<Result<Vec<_>, _>>()?;
ApplicationMatcher::new(id, selectors)
.map_err(|error| ConfigError::validation("application.selectors", error.to_string()))
}
}
impl Selector {
fn compile(&self) -> Result<ApplicationSelector, ConfigError> {
let field = match self.field {
SelectorField::ApplicationName => MetadataField::ApplicationName,
SelectorField::ApplicationId => MetadataField::ApplicationId,
SelectorField::ProcessBinary => MetadataField::ProcessBinary,
SelectorField::MediaName => MetadataField::MediaName,
};
match (&self.exact, &self.regex) {
(Some(pattern), None) => ApplicationSelector::exact(field, pattern),
(None, Some(pattern)) => ApplicationSelector::regex(field, pattern),
_ => {
return Err(ConfigError::validation(
"application.selector",
"exactly one of exact or regex is required",
));
}
}
.map_err(|error| ConfigError::validation("application.selector", error.to_string()))
}
}
impl Group {
/// Stable group identifier from the validated profile.
#[must_use]
pub fn id(&self) -> &str {
&self.id
}
/// User-facing group label.
#[must_use]
pub fn label(&self) -> &str {
&self.label
}
/// Stable application IDs included in this group.
#[must_use]
pub fn members(&self) -> &[String] {
&self.members
}
/// Group gain semantics used when planning writes.
#[must_use]
pub const fn volume_mode(&self) -> fader_core::VolumeMode {
match self.volume_mode {
VolumeMode::Absolute => fader_core::VolumeMode::Absolute,
VolumeMode::Relative => fader_core::VolumeMode::Relative,
}
}
}
fn validate_version(version: u16) -> Result<(), ConfigError> {
if version == SCHEMA_VERSION {
Ok(())

View File

@ -1,4 +1,5 @@
use fader_config::{DeviceProfile, PersistedState, Profile, StartupPolicy};
use fader_core::{StreamMetadata, VolumeMode};
const EXAMPLE: &str = include_str!("../../examples/profiles/desktop.toml");
const ARCHITECTURE: &str = include_str!("../../architecture.md");
@ -26,6 +27,26 @@ fn architecture_profile_parses_and_round_trips_semantically() {
assert_eq!(profile, reparsed);
}
#[test]
fn validated_profile_exposes_compiled_runtime_application_and_group_views() {
let profile = Profile::parse(EXAMPLE).expect("example profile must validate");
let music = &profile.applications()[0];
assert_eq!(music.id(), "music");
assert_eq!(music.label(), "Music");
assert!(
music
.matcher()
.expect("validated selector compiles")
.matches(&StreamMetadata::new().with_application_name("Music Player"))
);
let media = &profile.groups()[0];
assert_eq!(media.id(), "media");
assert_eq!(media.label(), "Media");
assert_eq!(media.members(), ["music", "browser"]);
assert_eq!(media.volume_mode(), VolumeMode::Absolute);
}
#[test]
fn rejects_unknown_fields_versions_and_bad_ids_with_context() {
let unknown = EXAMPLE.replace("schema_version = 1", "schema_version = 1\nsurprise = true");