From cfa3c0da05f94a97e1c927daa94ab4ff4ea7a713 Mon Sep 17 00:00:00 2001 From: pjht Date: Tue, 30 Jan 2024 12:31:16 -0600 Subject: [PATCH] Add mute option --- src/main.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index e109175..b0762da 100644 --- a/src/main.rs +++ b/src/main.rs @@ -32,6 +32,8 @@ fn main() -> Result<(), eframe::Error> { #[derive(Debug, Copy, Clone, Serialize, Deserialize)] struct Options { + #[serde(default = "Options::default_mute")] + mute: bool, #[serde(default = "Options::default_fan_enabled")] fan_enabled: bool, #[serde(default = "Options::default_volume")] @@ -39,6 +41,9 @@ struct Options { } impl Options { + fn default_mute() -> bool { + false + } fn default_fan_enabled() -> bool { true } @@ -61,11 +66,15 @@ struct AltairEmulator { impl AltairEmulator { fn new(cc: &eframe::CreationContext<'_>, audio_tx: Sender) -> Self { let options = if cc.storage.unwrap().get_string("options").is_none() { - Options { fan_enabled: true, volume: 1.0 } + Options { mute: false, fan_enabled: true, volume: 1.0 } } else { eframe::get_value(cc.storage.unwrap(), "options").unwrap() }; - audio_tx.send(AudioMessage::SetVolume(options.volume)).unwrap(); + if options.mute { + audio_tx.send(AudioMessage::SetVolume(0.0)).unwrap(); + } else { + audio_tx.send(AudioMessage::SetVolume(options.volume)).unwrap(); + } let mut mem = [0; 65536]; let cpu = I8080::new(); rand::thread_rng().fill_bytes(&mut mem); @@ -300,7 +309,11 @@ impl eframe::App for AltairEmulator { if option_window.draw(ctx, &mut self.options) { self.option_window = None; } - self.audio_tx.send(AudioMessage::SetVolume(self.options.volume)).unwrap(); + if self.options.mute { + self.audio_tx.send(AudioMessage::SetVolume(0.0)).unwrap(); + } else { + self.audio_tx.send(AudioMessage::SetVolume(self.options.volume)).unwrap(); + } } if (old_fan_enabled != self.options.fan_enabled) && self.fp_state.power() { if self.options.fan_enabled { @@ -344,6 +357,7 @@ impl OptionWindow { }); match self.category { OptionsCategory::General => { + ui.checkbox(&mut self.options.mute, "Mute"); ui.checkbox(&mut self.options.fan_enabled, "Fan enabled"); ui.add(Slider::new(&mut self.options.volume, 0.0..=100.0).text("Volume")); }