Add volume control

This commit is contained in:
pjht 2024-01-29 15:20:18 -06:00
parent 3137312831
commit 494236d71e
Signed by: pjht
GPG Key ID: 7B5F6AFBEC7EE78E
2 changed files with 19 additions and 2 deletions

View File

@ -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)
}
}

View File

@ -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<AudioMessage>) -> 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");