From 7cfd3ad1cdaed43139588b853c35dc48805df2b4 Mon Sep 17 00:00:00 2001 From: Louis Pearson Date: Mon, 20 May 2019 07:46:11 -0600 Subject: [PATCH 01/12] Add field_grazing.ogg Former-commit-id: 36a5bf4a9af2d89e9acd8dd7404c0b4eb1836f5b --- assets/voxygen/audio/soundtrack/field_grazing.ogg | 3 +++ voxygen/src/audio/mod.rs | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 assets/voxygen/audio/soundtrack/field_grazing.ogg diff --git a/assets/voxygen/audio/soundtrack/field_grazing.ogg b/assets/voxygen/audio/soundtrack/field_grazing.ogg new file mode 100644 index 0000000000..b3b1115318 --- /dev/null +++ b/assets/voxygen/audio/soundtrack/field_grazing.ogg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:31abe12210d7eaea3fbdd9e52102f63711b8227c31985dac9cf2da319e24fed0 +size 8645063 diff --git a/voxygen/src/audio/mod.rs b/voxygen/src/audio/mod.rs index e6c85494ee..5ce1a2c772 100644 --- a/voxygen/src/audio/mod.rs +++ b/voxygen/src/audio/mod.rs @@ -62,7 +62,7 @@ impl AudioFrontend { pub fn maintain(&mut self) { let music = [ "voxygen/audio/soundtrack/Ethereal_Bonds.ogg", - "voxygen/audio/soundtrack/Field_Grazing.mp3", + "voxygen/audio/soundtrack/field_grazing.ogg", "voxygen/audio/soundtrack/fiesta_del_pueblo.ogg", "voxygen/audio/soundtrack/library_theme_with_harpsichord.ogg", "voxygen/audio/soundtrack/Mineral_Deposits.ogg", From 50fc7549b9ddd0ae5a675c6de20c00fa5db5131d Mon Sep 17 00:00:00 2001 From: Louis Pearson Date: Mon, 20 May 2019 08:53:12 -0600 Subject: [PATCH 02/12] Add baby steps for audio device choice support Former-commit-id: 8c1d623b2a28997e7705ba2775b382b38e9a34ed --- voxygen/src/hud/mod.rs | 10 +++++ voxygen/src/hud/settings_window.rs | 69 +++++++++++++++++++++++++++++- 2 files changed, 78 insertions(+), 1 deletion(-) diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index 388d5a5525..82dd3b0f9d 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -92,6 +92,7 @@ pub enum Event { SendMessage(String), AdjustViewDistance(u32), AdjustVolume(f32), + ChangeAudioDevice(String), Logout, Quit, } @@ -212,10 +213,13 @@ pub struct Hud { // TODO: move to settings current_vd: u32, current_volume: f32, + audio_devices: Vec, + current_audio_device: String, } impl Hud { pub fn new(window: &mut Window, settings: Settings) -> Self { + let settings = global_state.settings; let mut ui = Ui::new(window).unwrap(); // TODO: Adjust/remove this, right now it is used to demonstrate window scaling functionality. ui.scaling_mode(ScaleMode::RelativeToWindow([1920.0, 1080.0].into())); @@ -385,6 +389,8 @@ impl Hud { &self.fonts, self.current_vd, self.current_volume, + self.audio_devices, + self.current_audio_device, ) .set(self.ids.settings_window, ui_widgets) { @@ -403,6 +409,10 @@ impl Hud { self.current_volume = volume; events.push(Event::AdjustVolume(volume)); } + settings_window::Event::ChangeAudioDevice(name) => { + self.current_audio_device = name; + events.push(Event::ChangeAudioDevice(name)); + } } } } diff --git a/voxygen/src/hud/settings_window.rs b/voxygen/src/hud/settings_window.rs index 0f290cea71..b6b478f2ba 100644 --- a/voxygen/src/hud/settings_window.rs +++ b/voxygen/src/hud/settings_window.rs @@ -10,7 +10,7 @@ use crate::{ }; use conrod_core::{ color, - widget::{self, Button, Image, Rectangle, Scrollbar, Text}, + widget::{self, Button, Image, List, Rectangle, Scrollbar, Text}, widget_ids, Colorable, Labelable, Positionable, Sizeable, Widget, WidgetCommon, }; widget_ids! { @@ -45,6 +45,8 @@ widget_ids! { vd_slider_text, audio_volume_slider, audio_volume_text, + audio_device_list, + audio_device_text, } } @@ -65,6 +67,8 @@ pub struct SettingsWindow<'a> { current_vd: u32, current_volume: f32, + audio_devices: Vec, + current_audio_device: String, #[conrod(common_builder)] common: widget::CommonBuilder, @@ -77,6 +81,8 @@ impl<'a> SettingsWindow<'a> { fonts: &'a Fonts, current_vd: u32, current_volume: f32, + audio_devices: Vec, + current_audio_device: String, ) -> Self { Self { show, @@ -84,6 +90,8 @@ impl<'a> SettingsWindow<'a> { fonts, current_vd, current_volume, + audio_devices, + current_audio_device, common: widget::CommonBuilder::default(), } } @@ -102,6 +110,7 @@ pub enum Event { Close, AdjustViewDistance(u32), AdjustVolume(f32), + ChangeAudioDevice(String), } impl<'a> Widget for SettingsWindow<'a> { @@ -535,6 +544,7 @@ impl<'a> Widget for SettingsWindow<'a> { } // Contents if let SettingsTab::Sound = state.settings_tab { + // Volume Slider ---------------------------------------------------- Text::new("Volume") .top_left_with_margins_on(state.ids.settings_content, 10.0, 10.0) .font_size(14) @@ -558,6 +568,63 @@ impl<'a> Widget for SettingsWindow<'a> { { events.push(Event::AdjustVolume(new_val)); } + + // Audio Device Selector -------------------------------------------- + Text::new("Volume") + .down_from(state.ids.audio_volume_slider, 10.0) + .font_size(14) + .font_id(self.fonts.opensans) + .color(TEXT_COLOR) + .set(state.ids.audio_device_text, ui); + + // TODO: Draw scroll bar or remove it. + let (mut items, scrollbar) = List::flow_down(self.audio_devices.len()) + .down_from(state.ids.audio_device_text, 10.0) + .w_h(400.0, 300.0) + .scrollbar_next_to() + .scrollbar_thickness(18.0) + .scrollbar_color(TEXT_COLOR) + .set(state.ids.audio_device_list, ui); + + while let Some(item) = items.next(ui) { + let mut text = "".to_string(); + if &self.audio_devices[item.i] == &self.current_audio_device { + text.push_str("* ") + } else { + text.push_str(" ") + } + text.push_str(&self.audio_devices[item.i]); + + // TODO: Use buttons to allow changing audio devices + item.set( + Text::new(&text) + .down_from(state.ids.audio_device_text, 10.0) + .font_size(14) + .font_id(self.fonts.opensans) + .color(TEXT_COLOR), + ui, + ); + + /* + if item + .set( + Button::image(self.imgs.button) + .w_h(100.0, 53.0) + .mid_bottom_with_margin_on(self.ids.servers_frame, 5.0) + .hover_image(self.imgs.button_hover) + .press_image(self.imgs.button_press) + .label_y(Relative::Scalar(2.0)) + .label(&text) + .label_font_size(20) + .label_color(TEXT_COLOR), + ui, + ) + .was_clicked() + { + events.push(Event::ChangeAudioDevice(self.audio_devices[item.i])); + } + */ + } } events From 8dc35b8609060a9921d4c3aa7d03480e6349f438 Mon Sep 17 00:00:00 2001 From: Louis Pearson Date: Mon, 20 May 2019 10:54:54 -0600 Subject: [PATCH 03/12] Add audio to settings Former-commit-id: 6e18b95bb3460a3b6d971b89c767045dcdbe7344 --- voxygen/src/audio/mod.rs | 31 ++++++++++++++++++++++--------- voxygen/src/main.rs | 18 +++++++++++++++--- voxygen/src/settings.rs | 24 ++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 12 deletions(-) diff --git a/voxygen/src/audio/mod.rs b/voxygen/src/audio/mod.rs index 5ce1a2c772..e04154adfe 100644 --- a/voxygen/src/audio/mod.rs +++ b/voxygen/src/audio/mod.rs @@ -23,15 +23,6 @@ impl AudioFrontend { pub fn new() -> Self { let mut device = rodio::default_output_device().unwrap(); - for d in rodio::devices() { - if d.name().contains("jack") { - continue; - } - - device = d; - break; - } - let mut sink = rodio::SpatialSink::new(&device, [0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [-1.0, 0.0, 0.0]); @@ -80,4 +71,26 @@ impl AudioFrontend { pub fn set_volume(&mut self, volume: f32) { self.stream.set_volume(volume.min(1.0).max(0.0)) } + + /// Returns a vec of the audio devices available. + /// Does not return rodio Device struct in case our audio backend changes. + // TODO: Decide if this should be an associated function + pub fn get_devices(&self) -> Vec { + rodio::output_devices().map(|x| x.name()).collect() + } + + /// Returns the name of the current audio device. + /// Does not return rodio Device struct in case our audio backend changes. + pub fn get_device(&self) -> String { + self.device.name() + } + + /// Sets the current audio device from a string. + /// Does not use the rodio Device struct in case that detail changes. + /// If the string is an invalid audio device, then no change is made. + pub fn set_device(&mut self, name: String) { + if let Some(dev) = rodio::output_devices().find(|x| x.name() == name) { + self.device = dev; + } + } } diff --git a/voxygen/src/main.rs b/voxygen/src/main.rs index 643674e135..bc5471dc5e 100644 --- a/voxygen/src/main.rs +++ b/voxygen/src/main.rs @@ -165,9 +165,21 @@ fn main() { audio: AudioFrontend::new(), }; - // TODO: Remove this when the volume setting can be saved - // Lower the volume to 50% - global_state.audio.set_volume(0.5); + // Load volume from audio file + global_state.audio.set_volume(settings.audio.music_volume); + + global_state.settings.audio.audio_devices = global_state.audio.get_devices(); + + // Load last used audio device, or set the current audio device as the last + // used if there is no last used + if global_state.settings.audio.audio_device != "" { + global_state + .audio + .set_device(global_state.settings.audio.audio_device); + } else { + global_state.settings.audio.audio_device = global_state.audio.get_device(); + global_state.settings.save_to_file(); + } // Set up the initial play state. let mut states: Vec> = vec![Box::new(MainMenuState::new(&mut global_state))]; diff --git a/voxygen/src/settings.rs b/voxygen/src/settings.rs index 22950cb6d2..1f1728505f 100644 --- a/voxygen/src/settings.rs +++ b/voxygen/src/settings.rs @@ -12,6 +12,7 @@ pub struct Settings { pub controls: ControlSettings, pub networking: NetworkingSettings, pub log: Log, + pub audio: AudioSettings, } /// `ControlSettings` contains keybindings. @@ -52,6 +53,23 @@ pub struct Log { pub file: PathBuf, } +/// AudioSettings controls the volume of different audio subsystems and which +/// which device is used. +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct AudioSettings { + pub music_volume: f32, + pub sfx_volume: f32, + + /// Audio Device that Voxygen wil use to play audio. + pub audio_device: String, + + /// Audio devices that are available. Listed here so that it can be accessed + /// from the settings editor in the HUD, but skipped over because it is a + /// runtime specific detail that should not be persisted. + #[serde(skip)] + pub audio_devices: Vec, +} + impl Default for Settings { fn default() -> Self { Settings { @@ -86,6 +104,12 @@ impl Default for Settings { log: Log { file: "voxygen.log".into(), }, + audio: AudioSettings { + music_volume: 0.5, + sfx_volume: 0.5, + audio_device: "".to_string(), + audio_devices: vec![], + }, } } } From ee6ec2d2998c3f9c765a827719136bb675ea560d Mon Sep 17 00:00:00 2001 From: Louis Pearson Date: Mon, 20 May 2019 11:40:35 -0600 Subject: [PATCH 04/12] Continue implementing audio device selection Former-commit-id: 6b92cbdb2e93653f43c0ed4d04e1b8fc35cfe8cf --- voxygen/src/hud/mod.rs | 26 +++++-------------------- voxygen/src/hud/settings_window.rs | 31 +++++++++--------------------- voxygen/src/main.rs | 6 ++++-- voxygen/src/session.rs | 3 +++ voxygen/src/settings.rs | 7 +++++++ 5 files changed, 28 insertions(+), 45 deletions(-) diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index 82dd3b0f9d..a8d4a18c62 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -210,16 +210,10 @@ pub struct Hud { to_focus: Option>, settings: Settings, force_ungrab: bool, - // TODO: move to settings - current_vd: u32, - current_volume: f32, - audio_devices: Vec, - current_audio_device: String, } impl Hud { pub fn new(window: &mut Window, settings: Settings) -> Self { - let settings = global_state.settings; let mut ui = Ui::new(window).unwrap(); // TODO: Adjust/remove this, right now it is used to demonstrate window scaling functionality. ui.scaling_mode(ScaleMode::RelativeToWindow([1920.0, 1080.0].into())); @@ -252,8 +246,6 @@ impl Hud { to_focus: None, settings, force_ungrab: false, - current_vd: 5, - current_volume: 0.5, } } @@ -383,16 +375,8 @@ impl Hud { // Settings if let Windows::Settings = self.show.open_windows { - for event in SettingsWindow::new( - &self.show, - &self.imgs, - &self.fonts, - self.current_vd, - self.current_volume, - self.audio_devices, - self.current_audio_device, - ) - .set(self.ids.settings_window, ui_widgets) + for event in SettingsWindow::new(&self.show, &self.imgs, &self.fonts, &self.settings) + .set(self.ids.settings_window, ui_widgets) { match event { settings_window::Event::ToggleHelp => self.show.toggle_help(), @@ -402,15 +386,15 @@ impl Hud { settings_window::Event::ToggleDebug => self.show.debug = !self.show.debug, settings_window::Event::Close => self.show.open_windows = Windows::None, settings_window::Event::AdjustViewDistance(view_distance) => { - self.current_vd = view_distance; + self.settings.graphics.view_distance = view_distance; events.push(Event::AdjustViewDistance(view_distance)); } settings_window::Event::AdjustVolume(volume) => { - self.current_volume = volume; + self.settings.audio.music_volume = volume; events.push(Event::AdjustVolume(volume)); } settings_window::Event::ChangeAudioDevice(name) => { - self.current_audio_device = name; + self.settings.audio.audio_device = name.clone(); events.push(Event::ChangeAudioDevice(name)); } } diff --git a/voxygen/src/hud/settings_window.rs b/voxygen/src/hud/settings_window.rs index b6b478f2ba..a1769fdf59 100644 --- a/voxygen/src/hud/settings_window.rs +++ b/voxygen/src/hud/settings_window.rs @@ -7,6 +7,7 @@ use crate::{ ImageSlider, ScaleMode, ToggleButton, Ui, }, window::Window, + Settings, }; use conrod_core::{ color, @@ -65,33 +66,19 @@ pub struct SettingsWindow<'a> { imgs: &'a Imgs, fonts: &'a Fonts, - current_vd: u32, - current_volume: f32, - audio_devices: Vec, - current_audio_device: String, + settings: &'a Settings, #[conrod(common_builder)] common: widget::CommonBuilder, } impl<'a> SettingsWindow<'a> { - pub fn new( - show: &'a Show, - imgs: &'a Imgs, - fonts: &'a Fonts, - current_vd: u32, - current_volume: f32, - audio_devices: Vec, - current_audio_device: String, - ) -> Self { + pub fn new(show: &'a Show, imgs: &'a Imgs, fonts: &'a Fonts, settings: &'a Settings) -> Self { Self { show, imgs, fonts, - current_vd, - current_volume, - audio_devices, - current_audio_device, + settings, common: widget::CommonBuilder::default(), } } @@ -499,7 +486,7 @@ impl<'a> Widget for SettingsWindow<'a> { .set(state.ids.vd_slider_text, ui); if let Some(new_val) = ImageSlider::discrete( - self.current_vd, + self.settings.graphics.view_distance, 1, 25, self.imgs.slider_indicator, @@ -553,7 +540,7 @@ impl<'a> Widget for SettingsWindow<'a> { .set(state.ids.audio_volume_text, ui); if let Some(new_val) = ImageSlider::continuous( - self.current_volume, + self.settings.audio.music_volume, 0.0, 1.0, self.imgs.slider_indicator, @@ -578,7 +565,7 @@ impl<'a> Widget for SettingsWindow<'a> { .set(state.ids.audio_device_text, ui); // TODO: Draw scroll bar or remove it. - let (mut items, scrollbar) = List::flow_down(self.audio_devices.len()) + let (mut items, scrollbar) = List::flow_down(self.settings.audio.audio_devices.len()) .down_from(state.ids.audio_device_text, 10.0) .w_h(400.0, 300.0) .scrollbar_next_to() @@ -588,12 +575,12 @@ impl<'a> Widget for SettingsWindow<'a> { while let Some(item) = items.next(ui) { let mut text = "".to_string(); - if &self.audio_devices[item.i] == &self.current_audio_device { + if &self.settings.audio.audio_devices[item.i] == &self.settings.audio.audio_device { text.push_str("* ") } else { text.push_str(" ") } - text.push_str(&self.audio_devices[item.i]); + text.push_str(&self.settings.audio.audio_devices[item.i]); // TODO: Use buttons to allow changing audio devices item.set( diff --git a/voxygen/src/main.rs b/voxygen/src/main.rs index bc5471dc5e..0ad98ce515 100644 --- a/voxygen/src/main.rs +++ b/voxygen/src/main.rs @@ -166,7 +166,9 @@ fn main() { }; // Load volume from audio file - global_state.audio.set_volume(settings.audio.music_volume); + global_state + .audio + .set_volume(global_state.settings.audio.music_volume); global_state.settings.audio.audio_devices = global_state.audio.get_devices(); @@ -175,7 +177,7 @@ fn main() { if global_state.settings.audio.audio_device != "" { global_state .audio - .set_device(global_state.settings.audio.audio_device); + .set_device(global_state.settings.audio.audio_device.clone()); } else { global_state.settings.audio.audio_device = global_state.audio.get_device(); global_state.settings.save_to_file(); diff --git a/voxygen/src/session.rs b/voxygen/src/session.rs index de75d9bb4d..36a13decce 100644 --- a/voxygen/src/session.rs +++ b/voxygen/src/session.rs @@ -196,6 +196,9 @@ impl PlayState for SessionState { HudEvent::AdjustVolume(volume) => { global_state.audio.set_volume(volume); } + HudEvent::ChangeAudioDevice(name) => { + global_state.audio.set_device(name); + } } } diff --git a/voxygen/src/settings.rs b/voxygen/src/settings.rs index 1f1728505f..0791ec7cbb 100644 --- a/voxygen/src/settings.rs +++ b/voxygen/src/settings.rs @@ -12,6 +12,7 @@ pub struct Settings { pub controls: ControlSettings, pub networking: NetworkingSettings, pub log: Log, + pub graphics: GraphicsSettings, pub audio: AudioSettings, } @@ -53,6 +54,11 @@ pub struct Log { pub file: PathBuf, } +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct GraphicsSettings { + pub view_distance: u32, +} + /// AudioSettings controls the volume of different audio subsystems and which /// which device is used. #[derive(Clone, Debug, Serialize, Deserialize)] @@ -104,6 +110,7 @@ impl Default for Settings { log: Log { file: "voxygen.log".into(), }, + graphics: GraphicsSettings { view_distance: 5 }, audio: AudioSettings { music_volume: 0.5, sfx_volume: 0.5, From 0437f88601ebca10930e3d050c58872abfa3c951 Mon Sep 17 00:00:00 2001 From: Louis Pearson Date: Mon, 20 May 2019 12:25:44 -0600 Subject: [PATCH 05/12] Prevent audio crashes by blocking jack by default Former-commit-id: 61243a38667f64d1c8f106b1191ae876fc652c63 --- voxygen/src/audio/mod.rs | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/voxygen/src/audio/mod.rs b/voxygen/src/audio/mod.rs index e04154adfe..48820619b0 100644 --- a/voxygen/src/audio/mod.rs +++ b/voxygen/src/audio/mod.rs @@ -5,6 +5,7 @@ use std::{ collections::HashMap, fs::File, io::BufReader, + iter::{Filter, Iterator}, path::PathBuf, sync::mpsc::{channel, Receiver, Sender, TryRecvError}, thread, @@ -21,7 +22,7 @@ pub struct AudioFrontend { impl AudioFrontend { pub fn new() -> Self { - let mut device = rodio::default_output_device().unwrap(); + let mut device = AudioFrontend::get_devices_raw()[0].clone(); let mut sink = rodio::SpatialSink::new(&device, [0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [-1.0, 0.0, 0.0]); @@ -37,17 +38,10 @@ impl AudioFrontend { let bufreader = assets::load_from_path(path).unwrap(); let src = Decoder::new(bufreader).unwrap(); - let mut sink = rodio::SpatialSink::new( - &self.device, - [0.0, 0.0, 0.0], - [1.0, 0.0, 0.0], - [-1.0, 0.0, 0.0], - ); - - sink.append(src); - - // self.streams.insert(path.to_string(), sink); - self.stream = sink; + // TODO: stop previous audio from playing. Sink has this ability, but + // SpatialSink does not for some reason. This means that we will + // probably want to use sinks for music, and SpatialSink for sfx. + self.stream.append(src); } pub fn maintain(&mut self) { @@ -72,6 +66,13 @@ impl AudioFrontend { self.stream.set_volume(volume.min(1.0).max(0.0)) } + /// Internal method for working with rodio. Filters out the jack audio server. + fn get_devices_raw() -> Vec { + rodio::output_devices() + .filter(|x| !x.name().contains("jack")) + .collect() + } + /// Returns a vec of the audio devices available. /// Does not return rodio Device struct in case our audio backend changes. // TODO: Decide if this should be an associated function From c8928587dd87cafb9616f679df0f6b95b35b11bc Mon Sep 17 00:00:00 2001 From: Louis Pearson Date: Mon, 20 May 2019 14:05:42 -0600 Subject: [PATCH 06/12] Allow user to change audio device in the settings menu Former-commit-id: 645b91182509da70075bb57f8ea6f9cd638c0d8e --- voxygen/src/audio/mod.rs | 6 +++ voxygen/src/hud/settings_window.rs | 63 ++++++++---------------------- 2 files changed, 22 insertions(+), 47 deletions(-) diff --git a/voxygen/src/audio/mod.rs b/voxygen/src/audio/mod.rs index 48820619b0..989be91004 100644 --- a/voxygen/src/audio/mod.rs +++ b/voxygen/src/audio/mod.rs @@ -92,6 +92,12 @@ impl AudioFrontend { pub fn set_device(&mut self, name: String) { if let Some(dev) = rodio::output_devices().find(|x| x.name() == name) { self.device = dev; + self.stream = rodio::SpatialSink::new( + &self.device, + [0.0, 0.0, 0.0], + [1.0, 0.0, 0.0], + [-1.0, 0.0, 0.0], + ); } } } diff --git a/voxygen/src/hud/settings_window.rs b/voxygen/src/hud/settings_window.rs index a1769fdf59..62b0fbb29e 100644 --- a/voxygen/src/hud/settings_window.rs +++ b/voxygen/src/hud/settings_window.rs @@ -11,7 +11,7 @@ use crate::{ }; use conrod_core::{ color, - widget::{self, Button, Image, List, Rectangle, Scrollbar, Text}, + widget::{self, Button, DropDownList, Image, List, Rectangle, Scrollbar, Text}, widget_ids, Colorable, Labelable, Positionable, Sizeable, Widget, WidgetCommon, }; widget_ids! { @@ -564,53 +564,22 @@ impl<'a> Widget for SettingsWindow<'a> { .color(TEXT_COLOR) .set(state.ids.audio_device_text, ui); - // TODO: Draw scroll bar or remove it. - let (mut items, scrollbar) = List::flow_down(self.settings.audio.audio_devices.len()) + // Get which device is currently selected + let selected = self + .settings + .audio + .audio_devices + .iter() + .position(|x| x.contains(&self.settings.audio.audio_device)); + + if let Some(clicked) = DropDownList::new(&self.settings.audio.audio_devices, selected) + .w_h(400.0, 22.0) .down_from(state.ids.audio_device_text, 10.0) - .w_h(400.0, 300.0) - .scrollbar_next_to() - .scrollbar_thickness(18.0) - .scrollbar_color(TEXT_COLOR) - .set(state.ids.audio_device_list, ui); - - while let Some(item) = items.next(ui) { - let mut text = "".to_string(); - if &self.settings.audio.audio_devices[item.i] == &self.settings.audio.audio_device { - text.push_str("* ") - } else { - text.push_str(" ") - } - text.push_str(&self.settings.audio.audio_devices[item.i]); - - // TODO: Use buttons to allow changing audio devices - item.set( - Text::new(&text) - .down_from(state.ids.audio_device_text, 10.0) - .font_size(14) - .font_id(self.fonts.opensans) - .color(TEXT_COLOR), - ui, - ); - - /* - if item - .set( - Button::image(self.imgs.button) - .w_h(100.0, 53.0) - .mid_bottom_with_margin_on(self.ids.servers_frame, 5.0) - .hover_image(self.imgs.button_hover) - .press_image(self.imgs.button_press) - .label_y(Relative::Scalar(2.0)) - .label(&text) - .label_font_size(20) - .label_color(TEXT_COLOR), - ui, - ) - .was_clicked() - { - events.push(Event::ChangeAudioDevice(self.audio_devices[item.i])); - } - */ + .label_font_id(self.fonts.opensans) + .set(state.ids.audio_device_list, ui) + { + let new_val = self.settings.audio.audio_devices[clicked].clone(); + events.push(Event::ChangeAudioDevice(new_val)); } } From f52954971da763d583da5cf2ac108eba793d8e63 Mon Sep 17 00:00:00 2001 From: Louis Pearson Date: Mon, 20 May 2019 14:18:01 -0600 Subject: [PATCH 07/12] Save view distance, volume, and audio device to settings when changed Former-commit-id: ac7db47520c6524b3f2d7a788907daabb73ad237 --- voxygen/src/session.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/voxygen/src/session.rs b/voxygen/src/session.rs index 36a13decce..beb1f9c40d 100644 --- a/voxygen/src/session.rs +++ b/voxygen/src/session.rs @@ -191,13 +191,22 @@ impl PlayState for SessionState { return PlayStateResult::Shutdown; } HudEvent::AdjustViewDistance(view_distance) => { - self.client.borrow_mut().set_view_distance(view_distance) + self.client.borrow_mut().set_view_distance(view_distance); + + global_state.settings.graphics.view_distance = view_distance; + global_state.settings.save_to_file(); } HudEvent::AdjustVolume(volume) => { global_state.audio.set_volume(volume); + + global_state.settings.audio.music_volume = volume; + global_state.settings.save_to_file(); } HudEvent::ChangeAudioDevice(name) => { - global_state.audio.set_device(name); + global_state.audio.set_device(name.clone()); + + global_state.settings.audio.audio_device = name; + global_state.settings.save_to_file(); } } } From 9f1c70792ff4d8e5137e175c691e5c1b699c8089 Mon Sep 17 00:00:00 2001 From: Louis Pearson Date: Mon, 20 May 2019 19:21:31 -0600 Subject: [PATCH 08/12] Move to using only global_state for settings menu Former-commit-id: bb86c851f51c02af1a25d57f2be95d1947b330ad --- voxygen/src/audio/mod.rs | 27 ++++++++++++++---------- voxygen/src/hud/mod.rs | 23 +++++++-------------- voxygen/src/hud/settings_window.rs | 33 ++++++++++++++++++------------ voxygen/src/main.rs | 32 ++++++++--------------------- voxygen/src/session.rs | 9 +++----- 5 files changed, 55 insertions(+), 69 deletions(-) diff --git a/voxygen/src/audio/mod.rs b/voxygen/src/audio/mod.rs index 989be91004..fe62005b69 100644 --- a/voxygen/src/audio/mod.rs +++ b/voxygen/src/audio/mod.rs @@ -1,3 +1,4 @@ +use crate::settings::AudioSettings; use common::assets; use rand::prelude::*; use rodio::{Decoder, Device, Source, SpatialSink}; @@ -21,11 +22,15 @@ pub struct AudioFrontend { } impl AudioFrontend { - pub fn new() -> Self { - let mut device = AudioFrontend::get_devices_raw()[0].clone(); + pub fn new(settings: &AudioSettings) -> Self { + let mut device = rodio::output_devices() + .find(|x| x.name() == settings.audio_device) + .or_else(rodio::default_output_device) + .expect("No Audio devices found"); let mut sink = rodio::SpatialSink::new(&device, [0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [-1.0, 0.0, 0.0]); + sink.set_volume(settings.music_volume); AudioFrontend { device, @@ -66,20 +71,20 @@ impl AudioFrontend { self.stream.set_volume(volume.min(1.0).max(0.0)) } - /// Internal method for working with rodio. Filters out the jack audio server. - fn get_devices_raw() -> Vec { - rodio::output_devices() - .filter(|x| !x.name().contains("jack")) - .collect() - } - /// Returns a vec of the audio devices available. /// Does not return rodio Device struct in case our audio backend changes. - // TODO: Decide if this should be an associated function - pub fn get_devices(&self) -> Vec { + pub fn get_devices() -> Vec { rodio::output_devices().map(|x| x.name()).collect() } + /// Returns the default audio device. + /// Does not return rodio Device struct in case our audio backend changes. + pub fn get_default_device() -> String { + rodio::default_output_device() + .expect("No audio output devices detected.") + .name() + } + /// Returns the name of the current audio device. /// Does not return rodio Device struct in case our audio backend changes. pub fn get_device(&self) -> String { diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index a8d4a18c62..70a9c216f8 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -208,12 +208,11 @@ pub struct Hud { inventory_space: u32, show: Show, to_focus: Option>, - settings: Settings, force_ungrab: bool, } impl Hud { - pub fn new(window: &mut Window, settings: Settings) -> Self { + pub fn new(window: &mut Window) -> Self { let mut ui = Ui::new(window).unwrap(); // TODO: Adjust/remove this, right now it is used to demonstrate window scaling functionality. ui.scaling_mode(ScaleMode::RelativeToWindow([1920.0, 1080.0].into())); @@ -244,12 +243,11 @@ impl Hud { want_grab: true, }, to_focus: None, - settings, force_ungrab: false, } } - fn update_layout(&mut self, tps: f64) -> Vec { + fn update_layout(&mut self, tps: f64, global_state: &GlobalState) -> Vec { let mut events = Vec::new(); let ref mut ui_widgets = self.ui.set_widgets(); let version = env!("CARGO_PKG_VERSION"); @@ -298,7 +296,7 @@ impl Hud { .top_left_with_margins_on(ui_widgets.window, 3.0, 3.0) .w_h(300.0, 190.0) .set(self.ids.help_bg, ui_widgets); - Text::new(get_help_text(&self.settings.controls).as_str()) + Text::new(get_help_text(&global_state.settings.controls).as_str()) .color(TEXT_COLOR) .top_left_with_margins_on(self.ids.help_bg, 20.0, 20.0) .font_id(self.fonts.opensans) @@ -375,7 +373,7 @@ impl Hud { // Settings if let Windows::Settings = self.show.open_windows { - for event in SettingsWindow::new(&self.show, &self.imgs, &self.fonts, &self.settings) + for event in SettingsWindow::new(&self.show, &self.imgs, &self.fonts, &global_state) .set(self.ids.settings_window, ui_widgets) { match event { @@ -386,15 +384,12 @@ impl Hud { settings_window::Event::ToggleDebug => self.show.debug = !self.show.debug, settings_window::Event::Close => self.show.open_windows = Windows::None, settings_window::Event::AdjustViewDistance(view_distance) => { - self.settings.graphics.view_distance = view_distance; events.push(Event::AdjustViewDistance(view_distance)); } settings_window::Event::AdjustVolume(volume) => { - self.settings.audio.music_volume = volume; events.push(Event::AdjustVolume(volume)); } settings_window::Event::ChangeAudioDevice(name) => { - self.settings.audio.audio_device = name.clone(); events.push(Event::ChangeAudioDevice(name)); } } @@ -477,10 +472,6 @@ impl Hud { pub fn handle_event(&mut self, event: WinEvent, global_state: &mut GlobalState) -> bool { let cursor_grabbed = global_state.window.is_cursor_grabbed(); let handled = match event { - WinEvent::SettingsChanged => { - self.settings = global_state.settings.clone(); - false - } WinEvent::Ui(event) => { if (self.typing() && event.is_keyboard() && self.show.ui) || !(cursor_grabbed && event.is_keyboard_or_mouse()) @@ -575,12 +566,12 @@ impl Hud { handled } - pub fn maintain(&mut self, renderer: &mut Renderer, tps: f64) -> Vec { + pub fn maintain(&mut self, global_state: &mut GlobalState, tps: f64) -> Vec { if let Some(maybe_id) = self.to_focus.take() { self.ui.focus_widget(maybe_id); } - let events = self.update_layout(tps); - self.ui.maintain(renderer); + let events = self.update_layout(tps, &global_state); + self.ui.maintain(&mut global_state.window.renderer_mut()); events } diff --git a/voxygen/src/hud/settings_window.rs b/voxygen/src/hud/settings_window.rs index 62b0fbb29e..d2f18a915b 100644 --- a/voxygen/src/hud/settings_window.rs +++ b/voxygen/src/hud/settings_window.rs @@ -7,7 +7,7 @@ use crate::{ ImageSlider, ScaleMode, ToggleButton, Ui, }, window::Window, - Settings, + GlobalState, }; use conrod_core::{ color, @@ -66,19 +66,24 @@ pub struct SettingsWindow<'a> { imgs: &'a Imgs, fonts: &'a Fonts, - settings: &'a Settings, + global_state: &'a GlobalState, #[conrod(common_builder)] common: widget::CommonBuilder, } impl<'a> SettingsWindow<'a> { - pub fn new(show: &'a Show, imgs: &'a Imgs, fonts: &'a Fonts, settings: &'a Settings) -> Self { + pub fn new( + show: &'a Show, + imgs: &'a Imgs, + fonts: &'a Fonts, + global_state: &'a GlobalState, + ) -> Self { Self { show, imgs, fonts, - settings, + global_state, common: widget::CommonBuilder::default(), } } @@ -486,7 +491,7 @@ impl<'a> Widget for SettingsWindow<'a> { .set(state.ids.vd_slider_text, ui); if let Some(new_val) = ImageSlider::discrete( - self.settings.graphics.view_distance, + self.global_state.settings.graphics.view_distance, 1, 25, self.imgs.slider_indicator, @@ -540,7 +545,7 @@ impl<'a> Widget for SettingsWindow<'a> { .set(state.ids.audio_volume_text, ui); if let Some(new_val) = ImageSlider::continuous( - self.settings.audio.music_volume, + self.global_state.settings.audio.music_volume, 0.0, 1.0, self.imgs.slider_indicator, @@ -566,19 +571,21 @@ impl<'a> Widget for SettingsWindow<'a> { // Get which device is currently selected let selected = self + .global_state .settings .audio .audio_devices .iter() - .position(|x| x.contains(&self.settings.audio.audio_device)); + .position(|x| x.contains(&self.global_state.settings.audio.audio_device)); - if let Some(clicked) = DropDownList::new(&self.settings.audio.audio_devices, selected) - .w_h(400.0, 22.0) - .down_from(state.ids.audio_device_text, 10.0) - .label_font_id(self.fonts.opensans) - .set(state.ids.audio_device_list, ui) + if let Some(clicked) = + DropDownList::new(&self.global_state.settings.audio.audio_devices, selected) + .w_h(400.0, 22.0) + .down_from(state.ids.audio_device_text, 10.0) + .label_font_id(self.fonts.opensans) + .set(state.ids.audio_device_list, ui) { - let new_val = self.settings.audio.audio_devices[clicked].clone(); + let new_val = self.global_state.settings.audio.audio_devices[clicked].clone(); events.push(Event::ChangeAudioDevice(new_val)); } } diff --git a/voxygen/src/main.rs b/voxygen/src/main.rs index 0ad98ce515..838a2b0c5a 100644 --- a/voxygen/src/main.rs +++ b/voxygen/src/main.rs @@ -79,7 +79,7 @@ pub trait PlayState { fn main() { // Set up the global state. - let settings = Settings::load(); + let mut settings = Settings::load(); let window = Window::new(&settings).expect("Failed to create window!"); // Initialize logging. @@ -159,30 +159,16 @@ fn main() { default_hook(panic_info); })); - let mut global_state = GlobalState { - settings, - window, - audio: AudioFrontend::new(), - }; - - // Load volume from audio file - global_state - .audio - .set_volume(global_state.settings.audio.music_volume); - - global_state.settings.audio.audio_devices = global_state.audio.get_devices(); - - // Load last used audio device, or set the current audio device as the last - // used if there is no last used - if global_state.settings.audio.audio_device != "" { - global_state - .audio - .set_device(global_state.settings.audio.audio_device.clone()); - } else { - global_state.settings.audio.audio_device = global_state.audio.get_device(); - global_state.settings.save_to_file(); + if settings.audio.audio_device == "" { + settings.audio.audio_device = AudioFrontend::get_default_device(); } + let mut global_state = GlobalState { + audio: AudioFrontend::new(&settings.audio), + window, + settings, + }; + // Set up the initial play state. let mut states: Vec> = vec![Box::new(MainMenuState::new(&mut global_state))]; states diff --git a/voxygen/src/session.rs b/voxygen/src/session.rs index beb1f9c40d..3cfc945528 100644 --- a/voxygen/src/session.rs +++ b/voxygen/src/session.rs @@ -32,7 +32,7 @@ impl SessionState { scene, client, key_state: KeyState::new(), - hud: Hud::new(window, settings), + hud: Hud::new(window), input_events: Vec::new(), } } @@ -173,14 +173,11 @@ impl PlayState for SessionState { // Maintain the scene. self.scene.maintain( global_state.window.renderer_mut(), - &mut self.client.borrow_mut(), + &self.client.borrow_mut(), ); // Maintain the UI. - for event in self - .hud - .maintain(global_state.window.renderer_mut(), clock.get_tps()) - { + for event in self.hud.maintain(&mut global_state, clock.get_tps()) { match event { HudEvent::SendMessage(msg) => { // TODO: Handle result From 4dfebb779ec3100da09f405ed615c32bf65df13e Mon Sep 17 00:00:00 2001 From: Louis Pearson Date: Mon, 20 May 2019 22:51:29 -0600 Subject: [PATCH 09/12] Use global_state for accessing settings in hud This has led to a performance regression. For some reason when the menu opens FPS drops to about 20. Former-commit-id: 84cdbec5ef40cf6189e544eba6b87981bb9514fe --- voxygen/src/hud/settings_window.rs | 25 ++++++++++--------------- voxygen/src/session.rs | 2 +- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/voxygen/src/hud/settings_window.rs b/voxygen/src/hud/settings_window.rs index d2f18a915b..70d23d5918 100644 --- a/voxygen/src/hud/settings_window.rs +++ b/voxygen/src/hud/settings_window.rs @@ -7,7 +7,7 @@ use crate::{ ImageSlider, ScaleMode, ToggleButton, Ui, }, window::Window, - GlobalState, + AudioFrontend, GlobalState, }; use conrod_core::{ color, @@ -562,6 +562,8 @@ impl<'a> Widget for SettingsWindow<'a> { } // Audio Device Selector -------------------------------------------- + let device = self.global_state.audio.get_device(); + let device_list = AudioFrontend::get_devices(); Text::new("Volume") .down_from(state.ids.audio_volume_slider, 10.0) .font_size(14) @@ -570,22 +572,15 @@ impl<'a> Widget for SettingsWindow<'a> { .set(state.ids.audio_device_text, ui); // Get which device is currently selected - let selected = self - .global_state - .settings - .audio - .audio_devices - .iter() - .position(|x| x.contains(&self.global_state.settings.audio.audio_device)); + let selected = device_list.iter().position(|x| x.contains(&device)); - if let Some(clicked) = - DropDownList::new(&self.global_state.settings.audio.audio_devices, selected) - .w_h(400.0, 22.0) - .down_from(state.ids.audio_device_text, 10.0) - .label_font_id(self.fonts.opensans) - .set(state.ids.audio_device_list, ui) + if let Some(clicked) = DropDownList::new(&device_list, selected) + .w_h(400.0, 22.0) + .down_from(state.ids.audio_device_text, 10.0) + .label_font_id(self.fonts.opensans) + .set(state.ids.audio_device_list, ui) { - let new_val = self.global_state.settings.audio.audio_devices[clicked].clone(); + let new_val = device_list[clicked].clone(); events.push(Event::ChangeAudioDevice(new_val)); } } diff --git a/voxygen/src/session.rs b/voxygen/src/session.rs index 3cfc945528..91450623d7 100644 --- a/voxygen/src/session.rs +++ b/voxygen/src/session.rs @@ -177,7 +177,7 @@ impl PlayState for SessionState { ); // Maintain the UI. - for event in self.hud.maintain(&mut global_state, clock.get_tps()) { + for event in self.hud.maintain(global_state, clock.get_tps()) { match event { HudEvent::SendMessage(msg) => { // TODO: Handle result From eeceef12ef4847be1ae6e19361417f4e446bf2f4 Mon Sep 17 00:00:00 2001 From: Louis Pearson Date: Mon, 20 May 2019 23:07:57 -0600 Subject: [PATCH 10/12] Prevent framerate drop when accessing settings menu Former-commit-id: f51d1b700cd328b8156c7df97d6524277cc0718b --- voxygen/src/audio/mod.rs | 17 +++++++++++++++-- voxygen/src/hud/settings_window.rs | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/voxygen/src/audio/mod.rs b/voxygen/src/audio/mod.rs index fe62005b69..463afc16b4 100644 --- a/voxygen/src/audio/mod.rs +++ b/voxygen/src/audio/mod.rs @@ -17,6 +17,8 @@ use vek::*; pub struct AudioFrontend { device: Device, + // Performance optimisation, iterating through available audio devices takes time + devices: Vec, // streams: HashMap, //always use SpatialSink even if no possition is used for now stream: SpatialSink, } @@ -36,6 +38,7 @@ impl AudioFrontend { device, // streams: HashMap::::new(), stream: sink, + devices: AudioFrontend::get_devices_raw(), } } @@ -73,8 +76,18 @@ impl AudioFrontend { /// Returns a vec of the audio devices available. /// Does not return rodio Device struct in case our audio backend changes. - pub fn get_devices() -> Vec { - rodio::output_devices().map(|x| x.name()).collect() + pub fn get_devices(&self) -> Vec { + self.devices.iter().map(|x| x.name()).collect() + } + + /// Returns vec of devices + fn get_devices_raw() -> Vec { + rodio::output_devices().collect() + } + + /// Caches vec of devices for later reference + fn collect_devices(&mut self) { + self.devices = AudioFrontend::get_devices_raw() } /// Returns the default audio device. diff --git a/voxygen/src/hud/settings_window.rs b/voxygen/src/hud/settings_window.rs index 70d23d5918..5426067a74 100644 --- a/voxygen/src/hud/settings_window.rs +++ b/voxygen/src/hud/settings_window.rs @@ -563,7 +563,7 @@ impl<'a> Widget for SettingsWindow<'a> { // Audio Device Selector -------------------------------------------- let device = self.global_state.audio.get_device(); - let device_list = AudioFrontend::get_devices(); + let device_list = self.global_state.audio.get_devices(); Text::new("Volume") .down_from(state.ids.audio_volume_slider, 10.0) .font_size(14) From affa5c081e8b1be8830b3dc080d21e5aa36b1f25 Mon Sep 17 00:00:00 2001 From: Louis Pearson Date: Wed, 22 May 2019 03:00:16 -0600 Subject: [PATCH 11/12] Temporarily remove Ruination Former-commit-id: a63df9eaf187f7786b9a2a0e50194c3a7866edbe --- voxygen/src/audio/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/voxygen/src/audio/mod.rs b/voxygen/src/audio/mod.rs index 463afc16b4..d41cd65b25 100644 --- a/voxygen/src/audio/mod.rs +++ b/voxygen/src/audio/mod.rs @@ -59,7 +59,7 @@ impl AudioFrontend { "voxygen/audio/soundtrack/fiesta_del_pueblo.ogg", "voxygen/audio/soundtrack/library_theme_with_harpsichord.ogg", "voxygen/audio/soundtrack/Mineral_Deposits.ogg", - "voxygen/audio/soundtrack/Ruination.ogg", + //"voxygen/audio/soundtrack/Ruination.ogg", "voxygen/audio/soundtrack/sacred_temple.ogg", "voxygen/audio/soundtrack/Snowtop.ogg", "voxygen/audio/soundtrack/veloren_title_tune-3.ogg", From e78ae4fefc46fd525d6739404bf6411ddc130bc9 Mon Sep 17 00:00:00 2001 From: Louis Pearson Date: Wed, 22 May 2019 05:29:38 -0600 Subject: [PATCH 12/12] Remove hacks, clean up crufty code Former-commit-id: 7c10103235e8d9e2967baa1f8e33d68995bdf4d5 --- voxygen/src/audio/mod.rs | 23 +++++++++++++---------- voxygen/src/hud/settings_window.rs | 4 ++-- voxygen/src/main.rs | 4 ++-- voxygen/src/session.rs | 2 +- voxygen/src/settings.rs | 15 ++++----------- 5 files changed, 22 insertions(+), 26 deletions(-) diff --git a/voxygen/src/audio/mod.rs b/voxygen/src/audio/mod.rs index d41cd65b25..8af09d54dd 100644 --- a/voxygen/src/audio/mod.rs +++ b/voxygen/src/audio/mod.rs @@ -25,10 +25,13 @@ pub struct AudioFrontend { impl AudioFrontend { pub fn new(settings: &AudioSettings) -> Self { - let mut device = rodio::output_devices() - .find(|x| x.name() == settings.audio_device) - .or_else(rodio::default_output_device) - .expect("No Audio devices found"); + let mut device = match &settings.audio_device { + Some(dev) => rodio::output_devices() + .find(|x| &x.name() == dev) + .or_else(rodio::default_output_device) + .expect("No Audio devices found"), + None => rodio::default_output_device().expect("No audio devices found"), + }; let mut sink = rodio::SpatialSink::new(&device, [0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [-1.0, 0.0, 0.0]); @@ -38,7 +41,7 @@ impl AudioFrontend { device, // streams: HashMap::::new(), stream: sink, - devices: AudioFrontend::get_devices_raw(), + devices: AudioFrontend::list_devices_raw(), } } @@ -76,18 +79,18 @@ impl AudioFrontend { /// Returns a vec of the audio devices available. /// Does not return rodio Device struct in case our audio backend changes. - pub fn get_devices(&self) -> Vec { + pub fn list_device_names(&self) -> Vec { self.devices.iter().map(|x| x.name()).collect() } /// Returns vec of devices - fn get_devices_raw() -> Vec { + fn list_devices_raw() -> Vec { rodio::output_devices().collect() } /// Caches vec of devices for later reference - fn collect_devices(&mut self) { - self.devices = AudioFrontend::get_devices_raw() + fn maintain_devices(&mut self) { + self.devices = AudioFrontend::list_devices_raw() } /// Returns the default audio device. @@ -100,7 +103,7 @@ impl AudioFrontend { /// Returns the name of the current audio device. /// Does not return rodio Device struct in case our audio backend changes. - pub fn get_device(&self) -> String { + pub fn get_device_name(&self) -> String { self.device.name() } diff --git a/voxygen/src/hud/settings_window.rs b/voxygen/src/hud/settings_window.rs index 5426067a74..323aef618e 100644 --- a/voxygen/src/hud/settings_window.rs +++ b/voxygen/src/hud/settings_window.rs @@ -562,8 +562,8 @@ impl<'a> Widget for SettingsWindow<'a> { } // Audio Device Selector -------------------------------------------- - let device = self.global_state.audio.get_device(); - let device_list = self.global_state.audio.get_devices(); + let device = self.global_state.audio.get_device_name(); + let device_list = self.global_state.audio.list_device_names(); Text::new("Volume") .down_from(state.ids.audio_volume_slider, 10.0) .font_size(14) diff --git a/voxygen/src/main.rs b/voxygen/src/main.rs index 838a2b0c5a..f48ea71175 100644 --- a/voxygen/src/main.rs +++ b/voxygen/src/main.rs @@ -159,8 +159,8 @@ fn main() { default_hook(panic_info); })); - if settings.audio.audio_device == "" { - settings.audio.audio_device = AudioFrontend::get_default_device(); + if settings.audio.audio_device == None { + settings.audio.audio_device = Some(AudioFrontend::get_default_device()); } let mut global_state = GlobalState { diff --git a/voxygen/src/session.rs b/voxygen/src/session.rs index 91450623d7..1fa492c173 100644 --- a/voxygen/src/session.rs +++ b/voxygen/src/session.rs @@ -202,7 +202,7 @@ impl PlayState for SessionState { HudEvent::ChangeAudioDevice(name) => { global_state.audio.set_device(name.clone()); - global_state.settings.audio.audio_device = name; + global_state.settings.audio.audio_device = Some(name); global_state.settings.save_to_file(); } } diff --git a/voxygen/src/settings.rs b/voxygen/src/settings.rs index 0791ec7cbb..8986f08cac 100644 --- a/voxygen/src/settings.rs +++ b/voxygen/src/settings.rs @@ -60,20 +60,14 @@ pub struct GraphicsSettings { } /// AudioSettings controls the volume of different audio subsystems and which -/// which device is used. +/// device is used. #[derive(Clone, Debug, Serialize, Deserialize)] pub struct AudioSettings { pub music_volume: f32, pub sfx_volume: f32, - /// Audio Device that Voxygen wil use to play audio. - pub audio_device: String, - - /// Audio devices that are available. Listed here so that it can be accessed - /// from the settings editor in the HUD, but skipped over because it is a - /// runtime specific detail that should not be persisted. - #[serde(skip)] - pub audio_devices: Vec, + /// Audio Device that Voxygen will use to play audio. + pub audio_device: Option, } impl Default for Settings { @@ -114,8 +108,7 @@ impl Default for Settings { audio: AudioSettings { music_volume: 0.5, sfx_volume: 0.5, - audio_device: "".to_string(), - audio_devices: vec![], + audio_device: None, }, } }