aboutsummaryrefslogtreecommitdiffstats
path: root/mumd
diff options
context:
space:
mode:
authorEskil Queseth <eskilq@kth.se>2020-11-16 02:23:28 +0100
committerEskil Queseth <eskilq@kth.se>2020-11-16 02:23:28 +0100
commit3b0d0f7aee5b6d8dc4ab59c1c16315c2c80347b3 (patch)
treec0d87b13c6264afeff9b93badcb16b4aa1a8ebed /mumd
parentc6cb3fc95bb00e66b66e0638cae8a036073bdeb4 (diff)
downloadmum-3b0d0f7aee5b6d8dc4ab59c1c16315c2c80347b3.tar.gz
cargo fmt
Diffstat (limited to 'mumd')
-rw-r--r--mumd/src/audio.rs49
-rw-r--r--mumd/src/audio/output.rs4
-rw-r--r--mumd/src/state.rs71
3 files changed, 92 insertions, 32 deletions
diff --git a/mumd/src/audio.rs b/mumd/src/audio.rs
index 7f6dd51..a51c2f2 100644
--- a/mumd/src/audio.rs
+++ b/mumd/src/audio.rs
@@ -1,26 +1,41 @@
pub mod input;
pub mod output;
+use crate::audio::output::SaturatingAdd;
use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
use cpal::{SampleFormat, SampleRate, Stream, StreamConfig};
use log::*;
use mumble_protocol::voice::VoicePacketPayload;
use opus::Channels;
+use samplerate::ConverterType;
use std::collections::hash_map::Entry;
use std::collections::{HashMap, VecDeque};
use std::sync::{Arc, Mutex};
use tokio::sync::{mpsc, watch};
-use samplerate::ConverterType;
-use crate::audio::output::SaturatingAdd;
//TODO? move to mumlib
pub const EVENT_SOUNDS: &[(&str, NotificationEvents)] = &[
("resources/connect.wav", NotificationEvents::ServerConnect),
- ("resources/disconnect.wav", NotificationEvents::ServerDisconnect),
- ("resources/channel_join.wav", NotificationEvents::UserConnected),
- ("resources/channel_leave.wav", NotificationEvents::UserDisconnected),
- ("resources/channel_join.wav", NotificationEvents::UserJoinedChannel),
- ("resources/channel_leave.wav", NotificationEvents::UserLeftChannel),
+ (
+ "resources/disconnect.wav",
+ NotificationEvents::ServerDisconnect,
+ ),
+ (
+ "resources/channel_join.wav",
+ NotificationEvents::UserConnected,
+ ),
+ (
+ "resources/channel_leave.wav",
+ NotificationEvents::UserDisconnected,
+ ),
+ (
+ "resources/channel_join.wav",
+ NotificationEvents::UserJoinedChannel,
+ ),
+ (
+ "resources/channel_leave.wav",
+ NotificationEvents::UserLeftChannel,
+ ),
("resources/mute.wav", NotificationEvents::Mute),
("resources/unmute.wav", NotificationEvents::Unmute),
("resources/deafen.wav", NotificationEvents::Deafen),
@@ -200,21 +215,29 @@ impl Audio {
output_stream.play().unwrap();
- let sounds = EVENT_SOUNDS.iter()
+ let sounds = EVENT_SOUNDS
+ .iter()
.map(|(path, event)| {
- let reader = hound::WavReader::open(path).unwrap();
+ let reader = hound::WavReader::open(path).unwrap();
let spec = reader.spec();
let samples = match spec.sample_format {
- hound::SampleFormat::Float => reader.into_samples::<f32>().map(|e| e.unwrap()).collect::<Vec<_>>(),
- hound::SampleFormat::Int => reader.into_samples::<i16>().map(|e| cpal::Sample::to_f32(&e.unwrap())).collect::<Vec<_>>(),
+ hound::SampleFormat::Float => reader
+ .into_samples::<f32>()
+ .map(|e| e.unwrap())
+ .collect::<Vec<_>>(),
+ hound::SampleFormat::Int => reader
+ .into_samples::<i16>()
+ .map(|e| cpal::Sample::to_f32(&e.unwrap()))
+ .collect::<Vec<_>>(),
};
let samples = samplerate::convert(
spec.sample_rate,
SAMPLE_RATE,
spec.channels as usize,
ConverterType::SincBestQuality,
- &samples)
- .unwrap();
+ &samples,
+ )
+ .unwrap();
(*event, samples)
})
.collect();
diff --git a/mumd/src/audio/output.rs b/mumd/src/audio/output.rs
index 2b58d5b..5e0cb8d 100644
--- a/mumd/src/audio/output.rs
+++ b/mumd/src/audio/output.rs
@@ -102,7 +102,9 @@ pub fn curry_callback<T: Sample + AddAssign + SaturatingAdd + std::fmt::Display>
}
for sample in data.iter_mut() {
- *sample = sample.saturating_add(Sample::from(&(effects_sound.pop_front().unwrap_or(0.0) * volume)));
+ *sample = sample.saturating_add(Sample::from(
+ &(effects_sound.pop_front().unwrap_or(0.0) * volume),
+ ));
}
}
}
diff --git a/mumd/src/state.rs b/mumd/src/state.rs
index 6bb78c5..d3c793e 100644
--- a/mumd/src/state.rs
+++ b/mumd/src/state.rs
@@ -256,9 +256,17 @@ impl State {
if let Some((mute, deafen)) = action {
if server.deafened() != deafen {
- self.audio.play_effect(if deafen { NotificationEvents::Deafen } else { NotificationEvents::Undeafen });
+ self.audio.play_effect(if deafen {
+ NotificationEvents::Deafen
+ } else {
+ NotificationEvents::Undeafen
+ });
} else if server.muted() != mute {
- self.audio.play_effect(if mute { NotificationEvents::Mute } else { NotificationEvents::Unmute });
+ self.audio.play_effect(if mute {
+ NotificationEvents::Mute
+ } else {
+ NotificationEvents::Unmute
+ });
}
let mut msg = msgs::UserState::new();
if server.muted() != mute {
@@ -300,9 +308,17 @@ impl State {
if let Some((mute, deafen)) = action {
if server.deafened() != deafen {
- self.audio.play_effect(if deafen { NotificationEvents::Deafen } else { NotificationEvents::Undeafen });
+ self.audio.play_effect(if deafen {
+ NotificationEvents::Deafen
+ } else {
+ NotificationEvents::Undeafen
+ });
} else if server.muted() != mute {
- self.audio.play_effect(if mute { NotificationEvents::Mute } else { NotificationEvents::Unmute });
+ self.audio.play_effect(if mute {
+ NotificationEvents::Mute
+ } else {
+ NotificationEvents::Unmute
+ });
}
let mut msg = msgs::UserState::new();
if server.muted() != mute {
@@ -430,7 +446,9 @@ impl State {
if *self.phase_receiver().borrow() == StatePhase::Connected {
let channel_id = msg.get_channel_id();
- if channel_id == self.get_users_channel(self.server().unwrap().session_id().unwrap()) {
+ if channel_id
+ == self.get_users_channel(self.server().unwrap().session_id().unwrap())
+ {
if let Some(channel) = self.server().unwrap().channels().get(&channel_id) {
notify::send(format!(
"{} connected and joined {}",
@@ -455,7 +473,8 @@ impl State {
let from_channel = self.get_users_channel(session);
- let user = self.server_mut()
+ let user = self
+ .server_mut()
.unwrap()
.users_mut()
.get_mut(&session)
@@ -475,16 +494,13 @@ impl State {
let diff = UserDiff::from(msg);
user.apply_user_diff(&diff);
- let user = self.server()
- .unwrap()
- .users()
- .get(&session)
- .unwrap();
+ let user = self.server().unwrap().users().get(&session).unwrap();
if Some(session) != self.server().unwrap().session_id() {
//send notification if the user moved to or from any channel
if let Some(to_channel) = diff.channel_id {
- let this_channel = self.get_users_channel(self.server().unwrap().session_id().unwrap());
+ let this_channel =
+ self.get_users_channel(self.server().unwrap().session_id().unwrap());
if from_channel == this_channel || to_channel == this_channel {
if let Some(channel) = self.server().unwrap().channels().get(&to_channel) {
notify::send(format!(
@@ -495,20 +511,32 @@ impl State {
} else {
warn!("{} moved to invalid channel {}", user.name(), to_channel);
}
- self.audio.play_effect(if from_channel == this_channel { NotificationEvents::UserJoinedChannel } else { NotificationEvents::UserLeftChannel });
+ self.audio.play_effect(if from_channel == this_channel {
+ NotificationEvents::UserJoinedChannel
+ } else {
+ NotificationEvents::UserLeftChannel
+ });
}
}
//send notification if a user muted/unmuted
let notify_desc = match (mute, deaf) {
- (Some(true), Some(true)) => Some(format!("{} muted and deafend themselves", &user.name())),
- (Some(false), Some(false)) => Some(format!("{} unmuted and undeafend themselves", &user.name())),
+ (Some(true), Some(true)) => {
+ Some(format!("{} muted and deafend themselves", &user.name()))
+ }
+ (Some(false), Some(false)) => {
+ Some(format!("{} unmuted and undeafend themselves", &user.name()))
+ }
(None, Some(true)) => Some(format!("{} deafend themselves", &user.name())),
(None, Some(false)) => Some(format!("{} undeafend themselves", &user.name())),
(Some(true), None) => Some(format!("{} muted themselves", &user.name())),
(Some(false), None) => Some(format!("{} unmuted themselves", &user.name())),
- (Some(true), Some(false)) => Some(format!("{} muted and undeafened themselves", &user.name())),
- (Some(false), Some(true)) => Some(format!("{} unmuted and deafened themselves", &user.name())),
+ (Some(true), Some(false)) => {
+ Some(format!("{} muted and undeafened themselves", &user.name()))
+ }
+ (Some(false), Some(true)) => {
+ Some(format!("{} unmuted and deafened themselves", &user.name()))
+ }
(None, None) => None,
};
if let Some(notify_desc) = notify_desc {
@@ -580,6 +608,13 @@ impl State {
self.server.as_ref().map(|e| e.username()).flatten()
}
fn get_users_channel(&self, user_id: u32) -> u32 {
- self.server().unwrap().users().iter().find(|e| *e.0 == user_id).unwrap().1.channel()
+ self.server()
+ .unwrap()
+ .users()
+ .iter()
+ .find(|e| *e.0 == user_id)
+ .unwrap()
+ .1
+ .channel()
}
}