forge
Explore
Log in

Don't you dare go Hollow

Own voice meter always shows the mic (dimmed while gated/muted-off), speaking state still follows transmission

Browse files at this commit

24aef4b3223f010e4f22b434d0200bd62565feccAhmet Kaan GümüşParent: 19bdbbf
  • feat
    • own voice meter always shows the mic (dimmed while gated/muted-off), speaking state still follows transmission
    • stats rates read kbps/Mbps
Show full message
✨ feat: own voice meter always shows the mic (dimmed while gated/muted-off), speaking state still follows transmission; stats rates read kbps/Mbps
crates/client/src/gui/chat.rsmodified+3 -3
@@ -2375,12 +2375,12 @@ impl Yumush {
2375 }2375 }
2376 2376
2377 fn update_waves(&mut self, levels: Levels, cx: &mut Context<Self>) {2377 fn update_waves(&mut self, levels: Levels, cx: &mut Context<Self>) {
2378- let silent = self2378+ let deafened = self
2379 .chat2379 .chat
2380 .voice_flags()2380 .voice_flags()
2381- .is_some_and(|(muted, deafened)| muted || deafened);2381+ .is_some_and(|(_, deafened)| deafened);
2382 let me = self.user.as_ref().map(|user| user.id);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 cx.notify();2384 cx.notify();
2385 }2385 }
2386 }2386 }
crates/client/src/gui/dock.rsmodified+5 -1
@@ -186,7 +186,11 @@ impl Yumush {
186 .flex_1()186 .flex_1()
187 .flex()187 .flex()
188 .justify_center()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 let group = hoverable_with(194 let group = hoverable_with(
191 "dock_mic",195 "dock_mic",
192 div()196 div()
crates/client/src/gui/sidebar.rsmodified+14 -6
@@ -142,7 +142,10 @@ impl Yumush {
142 142
143 fn voice_chip(&self, community_id: Id, palette: Palette) -> AnyElement {143 fn voice_chip(&self, community_id: Id, palette: Palette) -> AnyElement {
144 let ids = self.chat.voice_ids(community_id);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 div()149 div()
147 .id(format!("voice_chip_{community_id}"))150 .id(format!("voice_chip_{community_id}"))
148 .tip("In call")151 .tip("In call")
@@ -197,11 +200,16 @@ impl Yumush {
197 palette: Palette,200 palette: Palette,
198 ) -> impl IntoElement {201 ) -> impl IntoElement {
199 let user_id = user.id;202 let user_id = user.id;
200- let speaking = self.chat.waves.speaking.contains(&user_id);203+ let me = self.is_me(user_id);
201- let wave = speaking.then(|| self.chat.waves.voice(user_id)).flatten();204+ let muted = (me && self.chat.voice_flags().is_some_and(|(muted, _)| muted))
202- let muted = (self.is_me(user_id)
203- && self.chat.voice_flags().is_some_and(|(muted, _)| muted))
204 || self.chat.server_muted.contains(&user_id);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 let camera = self213 let camera = self
206 .chat214 .chat
207 .share_of(community_id, user_id, Kind::Camera)215 .share_of(community_id, user_id, Kind::Camera)
@@ -229,7 +237,7 @@ impl Yumush {
229 .when(speaking, |name| name.font_weight(FontWeight::SEMIBOLD))237 .when(speaking, |name| name.font_weight(FontWeight::SEMIBOLD))
230 .child(user.username.clone()),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 .children((muted && wave.is_none()).then(|| {241 .children((muted && wave.is_none()).then(|| {
234 Icon::new(IconName::MicOff)242 Icon::new(IconName::MicOff)
235 .w(px(12.))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 pub fn rate(kbps: u32) -> String {555 pub fn rate(kbps: u32) -> String {
556 match kbps {556 match kbps {
557- 0..1000 => format!("{kbps} kb"),557+ 0..1000 => format!("{kbps} kbps"),
558- _ => format!("{:.1} Mb", kbps as f32 / 1000.),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 #[derive(Default)]81 #[derive(Default)]
82 pub struct Waves {82 pub struct Waves {
83 pub speaking: HashSet<Id>,83 pub speaking: HashSet<Id>,
84+ pub own_live: bool,
84 voice: HashMap<Id, Wave>,85 voice: HashMap<Id, Wave>,
85 share: HashMap<Id, Wave>,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 impl Waves {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 let mut voice = levels.voice;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 if let Some(me) = me108 if let Some(me) = me
106- && !levels.own.is_empty()109+ && !deafened
107 {110 {
108 voice.push((me, levels.own));111 voice.push((me, levels.own));
112+ if own_live {
113+ speaking.insert(me);
114+ }
109 }115 }
110- if silent {116+ let mut changed = speaking != self.speaking || own_live != self.own_live;
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;
115 self.speaking = speaking;117 self.speaking = speaking;
118+ self.own_live = own_live;
116 let had = !self.voice.is_empty() || !self.share.is_empty();119 let had = !self.voice.is_empty() || !self.share.is_empty();
117 changed |= advance(&mut self.voice, voice);120 changed |= advance(&mut self.voice, voice);
118 121
@@ -126,6 +129,14 @@ impl Waves {
126 *self = Self::default();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 pub fn voice(&self, id: Id) -> Option<&VecDeque<f32>> {140 pub fn voice(&self, id: Id) -> Option<&VecDeque<f32>> {
130 self.voice.get(&id).map(|wave| &wave.bars)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 .as_ref()613 .as_ref()
614 .map(Voice::own_level)614 .map(Voice::own_level)
615 .unwrap_or_default(),615 .unwrap_or_default(),
616+ own_sending: inner.voice.as_ref().is_some_and(Voice::own_sending),
616 watching: inner617 watching: inner
617 .watching618 .watching
618 .iter()619 .iter()
crates/client/src/net/mod.rsmodified+1 -0
@@ -43,6 +43,7 @@ struct Shared {
43 pub struct Levels {43 pub struct Levels {
44 pub voice: Vec<(Id, Vec<f32>)>,44 pub voice: Vec<(Id, Vec<f32>)>,
45 pub own: Vec<f32>,45 pub own: Vec<f32>,
46+ pub own_sending: bool,
46 pub watching: Vec<(Id, Vec<f32>)>,47 pub watching: Vec<(Id, Vec<f32>)>,
47 pub sharing: Option<Vec<f32>>,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 let mut packets = Vec::new();241 let mut packets = Vec::new();
242 for frame in frames.as_chunks::<VOICE_FRAME_SAMPLES>().0 {242 for frame in frames.as_chunks::<VOICE_FRAME_SAMPLES>().0 {
243+ self.sent.record(frame, 1);
243 let loud = rms(frame);244 let loud = rms(frame);
244 self.level_db = db(loud);245 self.level_db = db(loud);
245 if loud >= self.gate {246 if loud >= self.gate {
@@ -257,9 +258,6 @@ impl Engine {
257 continue;258 continue;
258 }259 }
259 260
260- if speaking {
261- self.sent.record(frame, 1);
262- }
263 let mut samples = *frame;261 let mut samples = *frame;
264 if speaking && !was_sending {262 if speaking && !was_sending {
265 for (index, sample) in samples[..FADE_SAMPLES].iter_mut().enumerate() {263 for (index, sample) in samples[..FADE_SAMPLES].iter_mut().enumerate() {
@@ -450,6 +448,10 @@ impl Engine {
450 self.sent.take()448 self.sent.take()
451 }449 }
452 450
451+ pub fn sending(&self) -> bool {
452+ self.sending
453+ }
454+
453 pub fn level_db(&self) -> f32 {455 pub fn level_db(&self) -> f32 {
454 self.level_db456 self.level_db
455 }457 }
crates/client/src/voice/mod.rsmodified+4 -0
@@ -304,6 +304,10 @@ impl Voice {
304 self.with_engine(Vec::new(), Engine::own_level)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 pub fn level_db(&self) -> f32 {311 pub fn level_db(&self) -> f32 {
308 self.with_engine(SILENT_DB, |engine| engine.level_db())312 self.with_engine(SILENT_DB, |engine| engine.level_db())
309 }313 }