diff --git a/src/audio.rs b/src/audio.rs index 26c3a0a..1106471 100644 --- a/src/audio.rs +++ b/src/audio.rs @@ -12,6 +12,7 @@ pub enum AudioMessage { PlaySwitchClick, FanOn, FanOff, + SetVolume(f32), } impl AudioMessage { @@ -215,6 +216,7 @@ impl AudioThread { }; } }, + AudioMessage::SetVolume(vol) => self.sl.set_global_volume(*vol / 100.0) } } diff --git a/src/main.rs b/src/main.rs index cd2cd28..e109175 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,7 +9,7 @@ use std::sync::mpsc::Sender; use audio::{AudioMessage, AudioThread}; use cpu::{MemCycle, Status, I8080}; use eframe::{ - egui::{self, menu, Button}, + egui::{self, menu, Button, Slider}, NativeOptions, }; use egui_modal::Modal; @@ -32,7 +32,19 @@ fn main() -> Result<(), eframe::Error> { #[derive(Debug, Copy, Clone, Serialize, Deserialize)] struct Options { + #[serde(default = "Options::default_fan_enabled")] fan_enabled: bool, + #[serde(default = "Options::default_volume")] + volume: f32, +} + +impl Options { + fn default_fan_enabled() -> bool { + true + } + fn default_volume() -> f32 { + 100.0 + } } struct AltairEmulator { @@ -49,10 +61,11 @@ 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 } + Options { fan_enabled: true, volume: 1.0 } } else { eframe::get_value(cc.storage.unwrap(), "options").unwrap() }; + audio_tx.send(AudioMessage::SetVolume(options.volume)).unwrap(); let mut mem = [0; 65536]; let cpu = I8080::new(); rand::thread_rng().fill_bytes(&mut mem); @@ -287,6 +300,7 @@ 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 (old_fan_enabled != self.options.fan_enabled) && self.fp_state.power() { if self.options.fan_enabled { @@ -331,6 +345,7 @@ impl OptionWindow { match self.category { OptionsCategory::General => { ui.checkbox(&mut self.options.fan_enabled, "Fan enabled"); + ui.add(Slider::new(&mut self.options.volume, 0.0..=100.0).text("Volume")); } OptionsCategory::Cards => { ui.heading("TODO");