diff --git a/Cargo.lock b/Cargo.lock index 1cc45a3..8bc03a3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -368,7 +368,7 @@ dependencies = [ [[package]] name = "maolan-engine" -version = "0.4.23" +version = "0.4.24" dependencies = [ "alsa", "arc-swap", diff --git a/Cargo.toml b/Cargo.toml index 57aac41..881c603 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "maolan-engine" -version = "0.4.23" +version = "0.4.24" edition = "2024" description = "Audio engine for the Maolan DAW with audio/MIDI tracks, routing, export, and out-of-process CLAP/VST3/LV2 plugin support" license = "BSD-2-Clause" diff --git a/src/preferences.rs b/src/preferences.rs index f4d913f..d3fbf47 100644 --- a/src/preferences.rs +++ b/src/preferences.rs @@ -6,8 +6,8 @@ use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)] #[serde(default)] pub struct AudioDevicePreferences { - pub default_output_device_id: Option, - pub default_input_device_id: Option, + default_output_device_id: Option, + default_input_device_id: Option, } impl AudioDevicePreferences { @@ -15,7 +15,26 @@ impl AudioDevicePreferences { toml::from_str(contents) } + pub fn default_output_device_id(&self) -> Option<&str> { + self.default_output_device_id.as_deref() + } + + pub fn default_input_device_id(&self) -> Option<&str> { + self.default_input_device_id.as_deref() + } + + #[cfg(target_os = "freebsd")] + pub fn set_default_output_device_id(&mut self, id: Option) { + self.default_output_device_id = id; + } + + #[cfg(target_os = "freebsd")] + pub fn set_default_input_device_id(&mut self, id: Option) { + self.default_input_device_id = id; + } + /// Replaces these device settings in a TOML document while preserving its other values. + #[cfg(target_os = "freebsd")] pub fn update_toml_str(&self, contents: &str) -> Result { let mut value = if contents.trim().is_empty() { toml::Value::Table(toml::map::Map::new()) @@ -45,6 +64,7 @@ impl AudioDevicePreferences { .unwrap_or_default() } + #[cfg(target_os = "freebsd")] pub fn save_to_path(&self, path: &Path) -> Result<(), String> { let contents = match std::fs::read_to_string(path) { Ok(contents) => contents, @@ -59,6 +79,7 @@ impl AudioDevicePreferences { } } +#[cfg(target_os = "freebsd")] fn update_id(table: &mut toml::map::Map, key: &str, id: &Option) { if let Some(id) = id .as_deref() @@ -70,16 +91,16 @@ fn update_id(table: &mut toml::map::Map, key: &str, id: &Op } } -#[cfg(test)] +#[cfg(all(test, target_os = "freebsd"))] mod tests { use super::*; #[test] + #[cfg(target_os = "freebsd")] fn update_toml_preserves_other_preferences() { - let preferences = AudioDevicePreferences { - default_output_device_id: Some(String::from("/dev/dsp5")), - default_input_device_id: Some(String::from("/dev/dsp5")), - }; + let mut preferences = AudioDevicePreferences::default(); + preferences.set_default_output_device_id(Some(String::from("/dev/dsp5"))); + preferences.set_default_input_device_id(Some(String::from("/dev/dsp5"))); let updated = preferences .update_toml_str("theme = \"dark\"\ndefault_output_device_id = \"out2\"\n") .unwrap(); @@ -89,6 +110,7 @@ mod tests { } #[test] + #[cfg(target_os = "freebsd")] fn update_toml_removes_unset_device_ids() { let updated = AudioDevicePreferences::default() .update_toml_str(