diff --git a/architecture.md b/architecture.md index ed8568c..4ab401a 100644 --- a/architecture.md +++ b/architecture.md @@ -187,6 +187,8 @@ Global and per-fader/per-media-entry switches gate MIDI output. Global off sends no messages (even clearing messages), so existing lights may remain lit until feedback is re-enabled and resynchronized. These additions remain planned until their individual M13 acceptance criteria pass. +Global and per-fader gates now use `feedback_enabled` (default true) at root and +fader-table scope, applied on configuration Save, including explicit mappings. The protocol boundary follows the [MPRIS Player interface](https://specifications.freedesktop.org/mpris/latest/Player_Interface.html). diff --git a/config/src/document.rs b/config/src/document.rs index a005ce0..b571007 100644 --- a/config/src/document.rs +++ b/config/src/document.rs @@ -300,6 +300,22 @@ pickup_tolerance = 0.02 }) } + /// Sets the global or per-fader MIDI feedback gate transactionally. + pub fn set_feedback_enabled( + &mut self, + fader: Option<&str>, + enabled: bool, + ) -> Result<(), ConfigError> { + self.transaction(|document| { + if let Some(id) = fader { + find_table_mut(document, "faders", id)?["feedback_enabled"] = value(enabled); + } else { + document["feedback_enabled"] = value(enabled); + } + Ok(()) + }) + } + /// Changes selector composition without replacing selectors or their comments. pub fn set_application_selector_mode( &mut self, diff --git a/config/src/profile.rs b/config/src/profile.rs index e1b8d3e..6c082c6 100644 --- a/config/src/profile.rs +++ b/config/src/profile.rs @@ -12,6 +12,9 @@ use serde::{Deserialize, Serialize}; use crate::{ConfigError, SCHEMA_VERSION}; const DEFAULT_POLL_INTERVAL_MS: u64 = 10; +const fn enabled() -> bool { + true +} const MIN_POLL_INTERVAL_MS: u64 = 1; const MAX_POLL_INTERVAL_MS: u64 = 100; @@ -264,6 +267,8 @@ struct Target { #[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] #[serde(deny_unknown_fields)] pub struct Fader { + #[serde(default = "enabled")] + feedback_enabled: bool, id: String, target: Target, pickup: bool, @@ -385,6 +390,8 @@ pub struct Binding { #[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] #[serde(deny_unknown_fields)] struct RawProfile { + #[serde(default = "enabled")] + feedback_enabled: bool, schema_version: u16, id: String, startup: StartupPolicy, @@ -417,6 +424,10 @@ pub struct Profile { } impl Profile { + /// Master gate for every MIDI output message generated as feedback. + pub const fn feedback_enabled(&self) -> bool { + self.raw.feedback_enabled + } /// Parses strict TOML and validates all cross-document invariants. pub fn parse(input: &str) -> Result { let raw: RawProfile = toml::from_str(input)?; @@ -514,6 +525,15 @@ impl Profile { /// off=0, whenever the surface has an output. Other protocols are explicit. /// This does not rewrite the document or override an explicit mapping. pub fn effective_feedback(&self, binding: &Binding) -> Option { + if !self.feedback_enabled() + || !self + .faders() + .iter() + .find(|f| f.id() == binding.fader())? + .feedback_enabled() + { + return None; + } if let Some(feedback) = binding.feedback() { return Some(feedback.clone()); } @@ -735,6 +755,9 @@ impl Surface { } impl Fader { + pub const fn feedback_enabled(&self) -> bool { + self.feedback_enabled + } pub fn id(&self) -> &str { &self.id } diff --git a/config/tests/schema.rs b/config/tests/schema.rs index 4963d12..e2d6907 100644 --- a/config/tests/schema.rs +++ b/config/tests/schema.rs @@ -6,6 +6,24 @@ const EXAMPLE: &str = include_str!("../../examples/profiles/desktop.toml"); const ARCH_PIPEWIRE: &str = include_str!("../../examples/profiles/arch-pipewire.toml"); const ARCHITECTURE: &str = include_str!("../../architecture.md"); +#[test] +fn feedback_switches_override_explicit_and_default_output() { + for source in [ + format!("feedback_enabled = false\n{EXAMPLE}"), + EXAMPLE.replace("pickup = true", "pickup = true\nfeedback_enabled = false"), + ] { + let profile = Profile::parse(&source).unwrap(); + assert!( + profile + .bindings() + .iter() + .all(|binding| profile.effective_feedback(binding).is_none()) + ); + } + let profile = Profile::parse(EXAMPLE).unwrap(); + assert!(profile.effective_feedback(&profile.bindings()[1]).is_some()); +} + #[test] fn enriched_process_fields_match_only_available_values() { let metadata = StreamMetadata::new().with_process_metadata( diff --git a/docs/configuration.md b/docs/configuration.md index f367a7f..f92bd4e 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -110,6 +110,12 @@ before activating the profile unless a supported schema migration can upgrade it ### Application capture +MIDI feedback defaults to enabled. Set root-level `feedback_enabled = false` +to disable all feedback, or put the same setting in a `[[faders]]` table to +disable only that fader. Config and Edit fader expose these switches. Save the +configuration to apply them. Disabled feedback sends nothing, even light-off +messages; lights may retain their previous state until re-enabled and refreshed. + Selectors are ORed. Each selector chooses exactly one supported metadata field and exactly one matching mode: diff --git a/fader_master/src/editor.rs b/fader_master/src/editor.rs index 1be2b7d..02d8193 100644 --- a/fader_master/src/editor.rs +++ b/fader_master/src/editor.rs @@ -162,6 +162,9 @@ impl ConfigurationEditor { self.document .set_application(&id, &label, &[selector(&field, pattern, regex)?])? } + ConfigurationEdit::SetFeedbackEnabled { fader, enabled } => self + .document + .set_feedback_enabled(fader.as_deref(), enabled)?, ConfigurationEdit::SetApplicationSelectorMode { id, match_all } => { self.document.set_application_selector_mode( &id, diff --git a/fader_master/src/ipc.rs b/fader_master/src/ipc.rs index 82d89d1..57111d4 100644 --- a/fader_master/src/ipc.rs +++ b/fader_master/src/ipc.rs @@ -77,6 +77,10 @@ pub enum RequestCommand { #[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] #[serde(tag = "operation", rename_all = "snake_case")] pub enum ConfigurationEdit { + SetFeedbackEnabled { + fader: Option, + enabled: bool, + }, AddApplicationFader { application_id: String, label: String, @@ -260,6 +264,10 @@ pub struct MixerSnapshot { #[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)] pub struct ConfigurationSnapshot { + #[serde(default)] + pub feedback_disabled: bool, + #[serde(default)] + pub disabled_feedback_faders: Vec, #[serde(default)] pub stream_metadata: Vec, pub revision: u64, diff --git a/fader_master/src/live.rs b/fader_master/src/live.rs index e77ac70..d5a1a91 100644 --- a/fader_master/src/live.rs +++ b/fader_master/src/live.rs @@ -110,6 +110,13 @@ pub(crate) fn configuration_snapshot( applied_revision: u64, ) -> ConfigurationSnapshot { ConfigurationSnapshot { + feedback_disabled: !profile.feedback_enabled(), + disabled_feedback_faders: profile + .faders() + .iter() + .filter(|f| !f.feedback_enabled()) + .map(|f| f.id().to_owned()) + .collect(), revision, dirty, applied_revision, diff --git a/fader_master/src/midi_runtime.rs b/fader_master/src/midi_runtime.rs index 38cbf71..320050d 100644 --- a/fader_master/src/midi_runtime.rs +++ b/fader_master/src/midi_runtime.rs @@ -847,6 +847,28 @@ mod tests { } } + #[test] + fn disabled_feedback_sends_nothing_and_reenable_resynchronizes() { + let source = include_str!("../../examples/profiles/desktop.toml"); + let mut doc = fader_config::ProfileDocument::parse(source).unwrap(); + for fader in [None, Some("media-fader")] { + doc.set_feedback_enabled(fader, false).unwrap(); + assert!( + FeedbackEngine::new(&doc.preview().unwrap()) + .unwrap() + .bindings + .is_empty() + ); + doc.set_feedback_enabled(fader, true).unwrap(); + let engine = FeedbackEngine::new(&doc.preview().unwrap()).unwrap(); + assert_eq!(engine.bindings.len(), 1); + assert!(engine.sent.is_empty()); + } + let reloaded = Profile::parse(&doc.source()).unwrap(); + assert!(reloaded.feedback_enabled()); + assert!(reloaded.faders()[0].feedback_enabled()); + } + #[test] fn confirmed_mute_feedback_is_surface_scoped_deduplicated_and_resynced() { let profile = Profile::parse(include_str!("../../examples/profiles/desktop.toml")).unwrap(); diff --git a/fader_master/src/tui_client.rs b/fader_master/src/tui_client.rs index 0ef9ac8..40c785e 100644 --- a/fader_master/src/tui_client.rs +++ b/fader_master/src/tui_client.rs @@ -102,6 +102,8 @@ impl IpcMixerClient { }) .collect(), configuration: tui::ConfigurationSnapshot { + feedback_disabled: snapshot.configuration.feedback_disabled, + disabled_feedback_faders: snapshot.configuration.disabled_feedback_faders, revision: snapshot.configuration.revision, dirty: snapshot.configuration.dirty, applied_revision: snapshot.configuration.applied_revision, @@ -550,6 +552,9 @@ fn configuration_edit(edit: TuiConfigurationEdit) -> crate::ipc::ConfigurationEd tui::SeparatorDecoration::Box => crate::ipc::SeparatorDecoration::Box, }, }, + TuiConfigurationEdit::SetFeedbackEnabled { fader, enabled } => { + IpcEdit::SetFeedbackEnabled { fader, enabled } + } TuiConfigurationEdit::SetApplicationSelectorMode { id, match_all } => { IpcEdit::SetApplicationSelectorMode { id, match_all } } diff --git a/task.md b/task.md index ced5d54..dcb63cc 100644 --- a/task.md +++ b/task.md @@ -619,6 +619,8 @@ Approved implementation slices for M13.3 (each independently tested/committed): - [ ] **M13.3a Feedback switches:** persisted global MIDI-feedback gate and per-fader/per-media-entry gates; global off overrides local settings and sends no output, including clearing messages; re-enable resynchronizes observed state. + Global and per-fader gates are implemented in configuration/runtime and TUI; + per-media-entry gate follows with the media schema. - [ ] **M13.3b MPRIS adapter:** session-bus discovery independent of audio streams, bounded calls, capability reporting, owner-change handling and reconnects. Verify dependency license, native prerequisites and Rust 1.88 compatibility. diff --git a/tui/examples/doc_screenshots.rs b/tui/examples/doc_screenshots.rs index d68eac6..e654433 100644 --- a/tui/examples/doc_screenshots.rs +++ b/tui/examples/doc_screenshots.rs @@ -145,6 +145,8 @@ fn snapshot(mixer_orientation: MixerOrientation) -> MixerSnapshot { error: None, profile_id: "desktop".to_owned(), profile_path: Some("/home/alex/.config/fader_master/profiles/desktop.toml".to_owned()), + feedback_disabled: false, + disabled_feedback_faders: Vec::new(), stream_metadata: Vec::new(), available_profiles: vec!["desktop".to_owned()], mixer_orientation, diff --git a/tui/src/lib.rs b/tui/src/lib.rs index 6607977..32b5cb0 100644 --- a/tui/src/lib.rs +++ b/tui/src/lib.rs @@ -92,6 +92,8 @@ pub struct DiscoveredMidiPort { #[derive(Clone, Debug, Default, PartialEq)] pub struct ConfigurationSnapshot { + pub feedback_disabled: bool, + pub disabled_feedback_faders: Vec, pub stream_metadata: Vec, pub revision: u64, pub dirty: bool, @@ -354,6 +356,10 @@ pub struct ConfiguredBinding { #[derive(Clone, Debug, PartialEq)] pub enum ConfigurationEdit { + SetFeedbackEnabled { + fader: Option, + enabled: bool, + }, AddApplicationFader { application_id: String, label: String, @@ -989,6 +995,23 @@ fn publish_confirmed(state: &mut BufferedState, confirmed: &MixerSnapshot) { fn apply_optimistic_configuration_edit(snapshot: &mut MixerSnapshot, edit: &ConfigurationEdit) { match edit { + ConfigurationEdit::SetFeedbackEnabled { fader, enabled } => { + if let Some(fader) = fader { + snapshot + .configuration + .disabled_feedback_faders + .retain(|id| id != fader); + if !enabled { + snapshot + .configuration + .disabled_feedback_faders + .push(fader.clone()); + } + } else { + snapshot.configuration.feedback_disabled = !enabled; + } + snapshot.configuration.dirty = true; + } ConfigurationEdit::SetApplicationSelectorMode { id, match_all } => { if let Some(application) = snapshot .configuration @@ -1305,6 +1328,7 @@ struct EditorInput { } enum SettingsRow { + Feedback, StreamMetadata(String), Theme, MixerOrientation, @@ -1425,6 +1449,9 @@ struct DeviceDeleteConfirmation { } enum FaderEditorRow { + Feedback { + enabled: bool, + }, SelectorMode { application: String, match_all: bool, @@ -2357,6 +2384,7 @@ impl LiveTui { } rows.push(SettingsRow::Save); rows.push(SettingsRow::Reset); + rows.push(SettingsRow::Feedback); rows.extend( self.snapshot .devices @@ -2423,6 +2451,12 @@ impl LiveTui { return; }; match row { + SettingsRow::Feedback => { + self.apply_layout_edit(ConfigurationEdit::SetFeedbackEnabled { + fader: None, + enabled: self.snapshot.configuration.feedback_disabled, + }) + } SettingsRow::Theme => { let theme = if forward { self.theme.next() @@ -2861,6 +2895,13 @@ impl LiveTui { .unwrap_or((false, FaderDensity::Standard)); rows.push(FaderEditorRow::Density { density }); rows.push(FaderEditorRow::Visibility { hidden }); + rows.push(FaderEditorRow::Feedback { + enabled: !self + .snapshot + .configuration + .disabled_feedback_faders + .contains(&editor.fader), + }); if let Some(application) = self.snapshot .configuration @@ -2950,6 +2991,12 @@ impl LiveTui { return; }; match row { + FaderEditorRow::Feedback { enabled } => { + self.apply_layout_edit(ConfigurationEdit::SetFeedbackEnabled { + fader: Some(fader), + enabled: !enabled, + }) + } FaderEditorRow::SelectorMode { application, match_all, @@ -4136,6 +4183,10 @@ impl LiveTui { .map(|(index, row)| { let marker = if index == editor.selected { "▶" } else { " " }; let text = match row { + FaderEditorRow::Feedback { enabled } => format!( + "{marker} MIDI feedback {} [Enter]", + if *enabled { "On" } else { "Off" } + ), FaderEditorRow::SelectorMode { match_all, .. } => format!( "{marker} Match captures {} [Enter to toggle]", if *match_all { "All (AND)" } else { "Any (OR)" } @@ -4727,6 +4778,14 @@ impl LiveTui { " " }; let value = match row { + SettingsRow::Feedback => format!( + "MIDI feedback {} [Enter]", + if config.feedback_disabled { + "Off" + } else { + "On" + } + ), SettingsRow::StreamMetadata(value) => value.clone(), SettingsRow::Theme => format!("Theme {} [←→]", self.theme.label()), SettingsRow::MixerOrientation => { @@ -5438,7 +5497,7 @@ mod tests { .retain(|entry| { !matches!(entry, MixerLayoutEntry::Separator { id: separator, .. } if separator == id) }), - ConfigurationEdit::SetApplicationSelectorMode { .. } => { + ConfigurationEdit::SetFeedbackEnabled { .. } | ConfigurationEdit::SetApplicationSelectorMode { .. } => { apply_optimistic_configuration_edit(&mut self.snapshot, &edit); } ConfigurationEdit::SetApplicationSelector { @@ -6765,6 +6824,39 @@ mod tests { ))); } + #[test] + fn feedback_settings_toggle_without_changing_bindings() { + let edits = Arc::new(Mutex::new(Vec::new())); + let mut app = LiveTui::new(LayoutClient { + snapshot: DemoClient::default().view(), + edits: Arc::clone(&edits), + }) + .unwrap(); + app.tab = Tab::Configuration; + app.settings_selected = app + .settings_rows() + .iter() + .position(|row| matches!(row, SettingsRow::Feedback)) + .unwrap(); + app.handle_key_event(press(KeyCode::Enter)); + assert!(app.snapshot.configuration.feedback_disabled); + app.handle_key_event(press(KeyCode::Enter)); + assert!(!app.snapshot.configuration.feedback_disabled); + assert!(matches!( + edits.lock().unwrap().as_slice(), + [ + ConfigurationEdit::SetFeedbackEnabled { + fader: None, + enabled: false + }, + ConfigurationEdit::SetFeedbackEnabled { + fader: None, + enabled: true + } + ] + )); + } + #[test] fn capture_save_and_exit_validates_without_reopening_pattern() { let edits = Arc::new(Mutex::new(Vec::new())); @@ -7300,6 +7392,8 @@ mod tests { error: None, profile_id: "desktop".into(), profile_path: Some("/home/test/.config/fader_master/profiles/desktop.toml".into()), + feedback_disabled: false, + disabled_feedback_faders: Vec::new(), stream_metadata: Vec::new(), available_profiles: vec!["desktop".into(), "streaming".into()], mixer_orientation: MixerOrientation::Vertical, @@ -7362,7 +7456,7 @@ mod tests { }); app.handle_key_event(press(KeyCode::Tab)); - let area = Rect::new(0, 0, 100, 24); + let area = Rect::new(0, 0, 100, 28); let mut buffer = Buffer::empty(area); (&app).render(area, &mut buffer); let rendered = buffer