use serde::{Deserialize, Serialize}; const APP_NAME: &str = "cagire"; #[derive(Debug, Default, Serialize, Deserialize)] pub struct Settings { pub audio: AudioSettings, pub display: DisplaySettings, pub link: LinkSettings, } #[derive(Debug, Serialize, Deserialize)] pub struct AudioSettings { pub output_device: Option, pub input_device: Option, pub channels: u16, pub buffer_size: u32, } #[derive(Debug, Serialize, Deserialize)] pub struct DisplaySettings { pub fps: u32, pub runtime_highlight: bool, pub show_scope: bool, pub show_spectrum: bool, } #[derive(Debug, Serialize, Deserialize)] pub struct LinkSettings { pub enabled: bool, pub tempo: f64, pub quantum: f64, } impl Default for AudioSettings { fn default() -> Self { Self { output_device: None, input_device: None, channels: 2, buffer_size: 512, } } } impl Default for DisplaySettings { fn default() -> Self { Self { fps: 60, runtime_highlight: false, show_scope: true, show_spectrum: true, } } } impl Default for LinkSettings { fn default() -> Self { Self { enabled: true, tempo: 120.0, quantum: 4.0, } } } impl Settings { pub fn load() -> Self { confy::load(APP_NAME, None).unwrap_or_default() } pub fn save(&self) { let _ = confy::store(APP_NAME, None, self); } }