Own voice meter always shows the mic (dimmed while gated/muted-off), speaking state still follows transmission
Browse files at this commit24aef4b3223f010e4f22b434d0200bd62565feccParent: 19bdbbf- feat
- own voice meter always shows the mic (dimmed while gated/muted-off), speaking state still follows transmission
- stats rates read kbps/Mbps
9 changed files +53 -22
- crates/client/src/gui/chat.rs +3 -3
- crates/client/src/gui/dock.rs +5 -1
- crates/client/src/gui/sidebar.rs +14 -6
- crates/client/src/gui/voice_stats.rs +2 -2
- crates/client/src/gui/wave.rs +18 -7
- crates/client/src/net/media.rs +1 -0
- crates/client/src/net/mod.rs +1 -0
- crates/client/src/voice/engine.rs +5 -3
- crates/client/src/voice/mod.rs +4 -0
crates/client/src/gui/chat.rsmodified+3 -3
| @@ -2375,12 +2375,12 @@ impl Yumush { | ||
| 2375 | 2375 | } |
| 2376 | 2376 | |
| 2377 | 2377 | fn update_waves(&mut self, levels: Levels, cx: &mut Context<Self>) { |
| 2378 | - let silent = self | |
| 2378 | + let deafened = self | |
| 2379 | 2379 | .chat |
| 2380 | 2380 | .voice_flags() |
| 2381 | - .is_some_and(|(muted, deafened)| muted || deafened); | |
| 2381 | + .is_some_and(|(_, deafened)| deafened); | |
| 2382 | 2382 | let me = self.user.as_ref().map(|user| user.id); |
| 2383 | - if self.chat.waves.update(levels, me, silent) { | |
| 2383 | + if self.chat.waves.update(levels, me, deafened) { | |
| 2384 | 2384 | cx.notify(); |
| 2385 | 2385 | } |
| 2386 | 2386 | } |
crates/client/src/gui/dock.rsmodified+5 -1
| @@ -186,7 +186,11 @@ impl Yumush { | ||
| 186 | 186 | .flex_1() |
| 187 | 187 | .flex() |
| 188 | 188 | .justify_center() |
| 189 | - .child(wave::wave_slot(self.chat.waves.voice(me), 14., tone)); | |
| 189 | + .child(wave::wave_slot( | |
| 190 | + self.chat.waves.voice(me), | |
| 191 | + 14., | |
| 192 | + self.chat.waves.tone(me, Some(me), tone), | |
| 193 | + )); | |
| 190 | 194 | let group = hoverable_with( |
| 191 | 195 | "dock_mic", |
| 192 | 196 | div() |
crates/client/src/gui/sidebar.rsmodified+14 -6
| @@ -142,7 +142,10 @@ impl Yumush { | ||
| 142 | 142 | |
| 143 | 143 | fn voice_chip(&self, community_id: Id, palette: Palette) -> AnyElement { |
| 144 | 144 | let ids = self.chat.voice_ids(community_id); |
| 145 | - let wave = ids.iter().find_map(|id| self.chat.waves.voice(*id)); | |
| 145 | + let wave = ids | |
| 146 | + .iter() | |
| 147 | + .filter(|id| self.chat.waves.speaking.contains(id)) | |
| 148 | + .find_map(|id| self.chat.waves.voice(*id)); | |
| 146 | 149 | div() |
| 147 | 150 | .id(format!("voice_chip_{community_id}")) |
| 148 | 151 | .tip("In call") |
| @@ -197,11 +200,16 @@ impl Yumush { | ||
| 197 | 200 | palette: Palette, |
| 198 | 201 | ) -> impl IntoElement { |
| 199 | 202 | let user_id = user.id; |
| 200 | - let speaking = self.chat.waves.speaking.contains(&user_id); | |
| 201 | - let wave = speaking.then(|| self.chat.waves.voice(user_id)).flatten(); | |
| 202 | - let muted = (self.is_me(user_id) | |
| 203 | - && self.chat.voice_flags().is_some_and(|(muted, _)| muted)) | |
| 203 | + let me = self.is_me(user_id); | |
| 204 | + let muted = (me && self.chat.voice_flags().is_some_and(|(muted, _)| muted)) | |
| 204 | 205 | || self.chat.server_muted.contains(&user_id); |
| 206 | + let speaking = self.chat.waves.speaking.contains(&user_id); | |
| 207 | + let shown = speaking || (me && !muted); | |
| 208 | + let wave = shown.then(|| self.chat.waves.voice(user_id)).flatten(); | |
| 209 | + let wave_tone = | |
| 210 | + self.chat | |
| 211 | + .waves | |
| 212 | + .tone(user_id, self.user.as_ref().map(|user| user.id), palette.ok); | |
| 205 | 213 | let camera = self |
| 206 | 214 | .chat |
| 207 | 215 | .share_of(community_id, user_id, Kind::Camera) |
| @@ -229,7 +237,7 @@ impl Yumush { | ||
| 229 | 237 | .when(speaking, |name| name.font_weight(FontWeight::SEMIBOLD)) |
| 230 | 238 | .child(user.username.clone()), |
| 231 | 239 | ) |
| 232 | - .children(wave.map(|history| mini_wave(history, 12., palette.ok))) | |
| 240 | + .children(wave.map(|history| mini_wave(history, 12., wave_tone))) | |
| 233 | 241 | .children((muted && wave.is_none()).then(|| { |
| 234 | 242 | Icon::new(IconName::MicOff) |
| 235 | 243 | .w(px(12.)) |
crates/client/src/gui/voice_stats.rsmodified+2 -2
| @@ -554,8 +554,8 @@ fn largest(values: impl Iterator<Item = u32>) -> f32 { | ||
| 554 | 554 | |
| 555 | 555 | pub fn rate(kbps: u32) -> String { |
| 556 | 556 | match kbps { |
| 557 | - 0..1000 => format!("{kbps} kb"), | |
| 558 | - _ => format!("{:.1} Mb", kbps as f32 / 1000.), | |
| 557 | + 0..1000 => format!("{kbps} kbps"), | |
| 558 | + _ => format!("{:.1} Mbps", kbps as f32 / 1000.), | |
| 559 | 559 | } |
| 560 | 560 | } |
| 561 | 561 |
crates/client/src/gui/wave.rsmodified+18 -7
| @@ -81,6 +81,7 @@ fn soften(bands: &[f32]) -> Vec<f32> { | ||
| 81 | 81 | #[derive(Default)] |
| 82 | 82 | pub struct Waves { |
| 83 | 83 | pub speaking: HashSet<Id>, |
| 84 | + pub own_live: bool, | |
| 84 | 85 | voice: HashMap<Id, Wave>, |
| 85 | 86 | share: HashMap<Id, Wave>, |
| 86 | 87 | } |
| @@ -100,19 +101,21 @@ fn advance(waves: &mut HashMap<Id, Wave>, levels: Vec<(Id, Vec<f32>)>) -> bool { | ||
| 100 | 101 | } |
| 101 | 102 | |
| 102 | 103 | impl Waves { |
| 103 | - pub fn update(&mut self, levels: Levels, me: Option<Id>, silent: bool) -> bool { | |
| 104 | + pub fn update(&mut self, levels: Levels, me: Option<Id>, deafened: bool) -> bool { | |
| 104 | 105 | let mut voice = levels.voice; |
| 106 | + let mut speaking: HashSet<Id> = voice.iter().map(|(id, _)| *id).collect(); | |
| 107 | + let own_live = levels.own_sending && !deafened; | |
| 105 | 108 | if let Some(me) = me |
| 106 | - && !levels.own.is_empty() | |
| 109 | + && !deafened | |
| 107 | 110 | { |
| 108 | 111 | voice.push((me, levels.own)); |
| 112 | + if own_live { | |
| 113 | + speaking.insert(me); | |
| 114 | + } | |
| 109 | 115 | } |
| 110 | - if silent { | |
| 111 | - voice.retain(|(id, _)| Some(*id) != me); | |
| 112 | - } | |
| 113 | - let speaking: HashSet<Id> = voice.iter().map(|(id, _)| *id).collect(); | |
| 114 | - let mut changed = speaking != self.speaking; | |
| 116 | + let mut changed = speaking != self.speaking || own_live != self.own_live; | |
| 115 | 117 | self.speaking = speaking; |
| 118 | + self.own_live = own_live; | |
| 116 | 119 | let had = !self.voice.is_empty() || !self.share.is_empty(); |
| 117 | 120 | changed |= advance(&mut self.voice, voice); |
| 118 | 121 | |
| @@ -126,6 +129,14 @@ impl Waves { | ||
| 126 | 129 | *self = Self::default(); |
| 127 | 130 | } |
| 128 | 131 | |
| 132 | + pub fn tone(&self, id: Id, me: Option<Id>, color: Hsla) -> Hsla { | |
| 133 | + if Some(id) == me && !self.own_live { | |
| 134 | + color.opacity(0.35) | |
| 135 | + } else { | |
| 136 | + color | |
| 137 | + } | |
| 138 | + } | |
| 139 | + | |
| 129 | 140 | pub fn voice(&self, id: Id) -> Option<&VecDeque<f32>> { |
| 130 | 141 | self.voice.get(&id).map(|wave| &wave.bars) |
| 131 | 142 | } |
crates/client/src/net/media.rsmodified+1 -0
| @@ -613,6 +613,7 @@ impl NetworkHandle { | ||
| 613 | 613 | .as_ref() |
| 614 | 614 | .map(Voice::own_level) |
| 615 | 615 | .unwrap_or_default(), |
| 616 | + own_sending: inner.voice.as_ref().is_some_and(Voice::own_sending), | |
| 616 | 617 | watching: inner |
| 617 | 618 | .watching |
| 618 | 619 | .iter() |
crates/client/src/net/mod.rsmodified+1 -0
| @@ -43,6 +43,7 @@ struct Shared { | ||
| 43 | 43 | pub struct Levels { |
| 44 | 44 | pub voice: Vec<(Id, Vec<f32>)>, |
| 45 | 45 | pub own: Vec<f32>, |
| 46 | + pub own_sending: bool, | |
| 46 | 47 | pub watching: Vec<(Id, Vec<f32>)>, |
| 47 | 48 | pub sharing: Option<Vec<f32>>, |
| 48 | 49 | } |
crates/client/src/voice/engine.rsmodified+5 -3
| @@ -240,6 +240,7 @@ impl Engine { | ||
| 240 | 240 | |
| 241 | 241 | let mut packets = Vec::new(); |
| 242 | 242 | for frame in frames.as_chunks::<VOICE_FRAME_SAMPLES>().0 { |
| 243 | + self.sent.record(frame, 1); | |
| 243 | 244 | let loud = rms(frame); |
| 244 | 245 | self.level_db = db(loud); |
| 245 | 246 | if loud >= self.gate { |
| @@ -257,9 +258,6 @@ impl Engine { | ||
| 257 | 258 | continue; |
| 258 | 259 | } |
| 259 | 260 | |
| 260 | - if speaking { | |
| 261 | - self.sent.record(frame, 1); | |
| 262 | - } | |
| 263 | 261 | let mut samples = *frame; |
| 264 | 262 | if speaking && !was_sending { |
| 265 | 263 | for (index, sample) in samples[..FADE_SAMPLES].iter_mut().enumerate() { |
| @@ -450,6 +448,10 @@ impl Engine { | ||
| 450 | 448 | self.sent.take() |
| 451 | 449 | } |
| 452 | 450 | |
| 451 | + pub fn sending(&self) -> bool { | |
| 452 | + self.sending | |
| 453 | + } | |
| 454 | + | |
| 453 | 455 | pub fn level_db(&self) -> f32 { |
| 454 | 456 | self.level_db |
| 455 | 457 | } |
crates/client/src/voice/mod.rsmodified+4 -0
| @@ -304,6 +304,10 @@ impl Voice { | ||
| 304 | 304 | self.with_engine(Vec::new(), Engine::own_level) |
| 305 | 305 | } |
| 306 | 306 | |
| 307 | + pub fn own_sending(&self) -> bool { | |
| 308 | + self.with_engine(false, |engine| engine.sending()) | |
| 309 | + } | |
| 310 | + | |
| 307 | 311 | pub fn level_db(&self) -> f32 { |
| 308 | 312 | self.with_engine(SILENT_DB, |engine| engine.level_db()) |
| 309 | 313 | } |