veloren/voxygen/src/settings/audio.rs

74 lines
2.1 KiB
Rust
Raw Normal View History

2021-04-13 13:24:47 +00:00
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum AudioOutput {
/// Veloren's audio system wont work on some systems,
/// so you can use this to disable it, and allow the
/// game to function
// If this option is disabled, functions in the rodio
// library MUST NOT be called.
Off,
#[serde(other)]
Automatic,
}
impl AudioOutput {
pub fn is_enabled(&self) -> bool { !matches!(self, Self::Off) }
}
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
pub struct AudioVolume {
pub volume: f32,
pub muted: bool,
}
impl AudioVolume {
pub fn new(volume: f32, muted: bool) -> Self { Self { volume, muted } }
pub fn get_checked(&self) -> f32 {
match self.muted {
true => 0.0,
false => self.volume,
}
}
}
2021-04-13 13:24:47 +00:00
/// `AudioSettings` controls the volume of different audio subsystems and which
/// device is used.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(default)]
pub struct AudioSettings {
pub master_volume: AudioVolume,
#[serde(rename = "inactive_master_volume")]
pub inactive_master_volume_perc: AudioVolume,
pub music_volume: AudioVolume,
pub sfx_volume: AudioVolume,
pub ambience_volume: AudioVolume,
2022-01-03 22:40:31 +00:00
pub num_sfx_channels: usize,
pub num_ui_channels: usize,
pub music_spacing: f32,
2023-04-26 14:20:56 +00:00
pub subtitles: bool,
2023-07-30 08:10:36 +00:00
pub combat_music_enabled: bool,
2021-04-13 13:24:47 +00:00
/// Audio Device that Voxygen will use to play audio.
pub output: AudioOutput,
}
impl Default for AudioSettings {
fn default() -> Self {
Self {
2023-05-14 21:12:49 +00:00
master_volume: AudioVolume::new(0.8, false),
inactive_master_volume_perc: AudioVolume::new(0.5, false),
2023-05-14 21:12:49 +00:00
music_volume: AudioVolume::new(0.3, false),
sfx_volume: AudioVolume::new(0.6, false),
ambience_volume: AudioVolume::new(0.6, false),
2022-01-03 22:40:31 +00:00
num_sfx_channels: 60,
num_ui_channels: 10,
music_spacing: 1.0,
2023-04-26 14:20:56 +00:00
subtitles: false,
2021-04-13 13:24:47 +00:00
output: AudioOutput::Automatic,
2023-07-30 08:10:36 +00:00
combat_music_enabled: true,
2021-04-13 13:24:47 +00:00
}
}
}