diff options
| -rw-r--r-- | Cargo.lock | 35 | ||||
| -rw-r--r-- | mumd/Cargo.toml | 2 | ||||
| -rw-r--r-- | mumd/src/audio.rs | 40 |
3 files changed, 48 insertions, 29 deletions
@@ -857,6 +857,15 @@ dependencies = [ ] [[package]] +name = "heck" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cbf45460356b7deeb5e3415b5563308c0a9b057c85e12b06ad551f98d0a6ac" +dependencies = [ + "unicode-segmentation", +] + +[[package]] name = "hermit-abi" version = "0.1.17" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1212,6 +1221,8 @@ dependencies = [ "openssl", "opus", "serde", + "strum", + "strum_macros", "tokio", "tokio-native-tls", "tokio-util", @@ -2005,6 +2016,24 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c" [[package]] +name = "strum" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7318c509b5ba57f18533982607f24070a55d353e90d4cae30c467cdb2ad5ac5c" + +[[package]] +name = "strum_macros" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee8bc6b87a5112aeeab1f4a9f7ab634fe6cbefc4850006df31267f4cfb9e3149" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] name = "syn" version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2224,6 +2253,12 @@ dependencies = [ ] [[package]] +name = "unicode-segmentation" +version = "1.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796" + +[[package]] name = "unicode-width" version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" diff --git a/mumd/Cargo.toml b/mumd/Cargo.toml index 8c6958c..9af1f73 100644 --- a/mumd/Cargo.toml +++ b/mumd/Cargo.toml @@ -33,6 +33,8 @@ native-tls = "0.2" openssl = { version = "0.10" } opus = "0.2" serde = { version = "1.0", features = ["derive"] } +strum = "0.20" +strum_macros = "0.20" tokio = { version = "1.0", features = ["macros", "rt", "rt-multi-thread", "sync", "net", "time"] } tokio-native-tls = "0.3" tokio-util = { version = "0.6", features = ["codec", "net"] } diff --git a/mumd/src/audio.rs b/mumd/src/audio.rs index 61e2179..08a4b48 100644 --- a/mumd/src/audio.rs +++ b/mumd/src/audio.rs @@ -14,25 +14,13 @@ use opus::Channels; use std::{collections::hash_map::Entry, fs::File, io::Read}; use std::collections::{HashMap, VecDeque}; use std::sync::{Arc, Mutex}; +use strum::IntoEnumIterator; +use strum_macros::EnumIter; use tokio::sync::{mpsc, watch}; -//TODO? move to mumlib -pub const DEFAULT_SOUND_FILES: &[(NotificationEvents, &str)] = &[ - (NotificationEvents::ServerConnect, "fallback_sfx.wav"), - (NotificationEvents::ServerDisconnect, "fallback_sfx.wav"), - (NotificationEvents::UserConnected, "fallback_sfx.wav"), - (NotificationEvents::UserDisconnected, "fallback_sfx.wav"), - (NotificationEvents::UserJoinedChannel, "fallback_sfx.wav"), - (NotificationEvents::UserLeftChannel, "fallback_sfx.wav"), - (NotificationEvents::Mute, "fallback_sfx.wav"), - (NotificationEvents::Unmute, "fallback_sfx.wav"), - (NotificationEvents::Deafen, "fallback_sfx.wav"), - (NotificationEvents::Undeafen, "fallback_sfx.wav"), -]; - const SAMPLE_RATE: u32 = 48000; -#[derive(Debug, Eq, PartialEq, Clone, Copy, Hash)] +#[derive(Debug, Eq, PartialEq, Clone, Copy, Hash, EnumIter)] pub enum NotificationEvents { ServerConnect, ServerDisconnect, @@ -243,19 +231,13 @@ impl Audio { }) .collect(); - self.sounds = DEFAULT_SOUND_FILES - .iter() - .map(|(event, file)| { - let file = if let Some(file) = overrides.get(event) { - *file - } else { - *file - }; - let bytes = if let Some(bytes_vec) = get_resource(file) { - &*bytes_vec.leak() // needs immutability - } else { - include_bytes!("fallback_sfx.wav") - }; + self.sounds = NotificationEvents::iter() + .map(|event| { + let bytes = overrides.get(&event) + .map(|file| get_resource(file)) + .flatten() + .map(|byte_vec| &*byte_vec.leak()) + .unwrap_or(include_bytes!("fallback_sfx.wav")); let reader = hound::WavReader::new(bytes).unwrap(); let spec = reader.spec(); let samples = match spec.sample_format { @@ -287,7 +269,7 @@ impl Audio { } ) .collect::<Vec<f32>>(); - (*event, samples) + (event, samples) }) .collect(); |
