Add volume control
This commit is contained in:
parent
3137312831
commit
494236d71e
@ -12,6 +12,7 @@ pub enum AudioMessage {
|
|||||||
PlaySwitchClick,
|
PlaySwitchClick,
|
||||||
FanOn,
|
FanOn,
|
||||||
FanOff,
|
FanOff,
|
||||||
|
SetVolume(f32),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AudioMessage {
|
impl AudioMessage {
|
||||||
@ -215,6 +216,7 @@ impl AudioThread {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
AudioMessage::SetVolume(vol) => self.sl.set_global_volume(*vol / 100.0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
19
src/main.rs
19
src/main.rs
@ -9,7 +9,7 @@ use std::sync::mpsc::Sender;
|
|||||||
use audio::{AudioMessage, AudioThread};
|
use audio::{AudioMessage, AudioThread};
|
||||||
use cpu::{MemCycle, Status, I8080};
|
use cpu::{MemCycle, Status, I8080};
|
||||||
use eframe::{
|
use eframe::{
|
||||||
egui::{self, menu, Button},
|
egui::{self, menu, Button, Slider},
|
||||||
NativeOptions,
|
NativeOptions,
|
||||||
};
|
};
|
||||||
use egui_modal::Modal;
|
use egui_modal::Modal;
|
||||||
@ -32,7 +32,19 @@ fn main() -> Result<(), eframe::Error> {
|
|||||||
|
|
||||||
#[derive(Debug, Copy, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Copy, Clone, Serialize, Deserialize)]
|
||||||
struct Options {
|
struct Options {
|
||||||
|
#[serde(default = "Options::default_fan_enabled")]
|
||||||
fan_enabled: bool,
|
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 {
|
struct AltairEmulator {
|
||||||
@ -49,10 +61,11 @@ struct AltairEmulator {
|
|||||||
impl AltairEmulator {
|
impl AltairEmulator {
|
||||||
fn new(cc: &eframe::CreationContext<'_>, audio_tx: Sender<AudioMessage>) -> Self {
|
fn new(cc: &eframe::CreationContext<'_>, audio_tx: Sender<AudioMessage>) -> Self {
|
||||||
let options = if cc.storage.unwrap().get_string("options").is_none() {
|
let options = if cc.storage.unwrap().get_string("options").is_none() {
|
||||||
Options { fan_enabled: true }
|
Options { fan_enabled: true, volume: 1.0 }
|
||||||
} else {
|
} else {
|
||||||
eframe::get_value(cc.storage.unwrap(), "options").unwrap()
|
eframe::get_value(cc.storage.unwrap(), "options").unwrap()
|
||||||
};
|
};
|
||||||
|
audio_tx.send(AudioMessage::SetVolume(options.volume)).unwrap();
|
||||||
let mut mem = [0; 65536];
|
let mut mem = [0; 65536];
|
||||||
let cpu = I8080::new();
|
let cpu = I8080::new();
|
||||||
rand::thread_rng().fill_bytes(&mut mem);
|
rand::thread_rng().fill_bytes(&mut mem);
|
||||||
@ -287,6 +300,7 @@ impl eframe::App for AltairEmulator {
|
|||||||
if option_window.draw(ctx, &mut self.options) {
|
if option_window.draw(ctx, &mut self.options) {
|
||||||
self.option_window = None;
|
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 (old_fan_enabled != self.options.fan_enabled) && self.fp_state.power() {
|
||||||
if self.options.fan_enabled {
|
if self.options.fan_enabled {
|
||||||
@ -331,6 +345,7 @@ impl OptionWindow {
|
|||||||
match self.category {
|
match self.category {
|
||||||
OptionsCategory::General => {
|
OptionsCategory::General => {
|
||||||
ui.checkbox(&mut self.options.fan_enabled, "Fan enabled");
|
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 => {
|
OptionsCategory::Cards => {
|
||||||
ui.heading("TODO");
|
ui.heading("TODO");
|
||||||
|
Loading…
Reference in New Issue
Block a user