forge
Explore
Log in

Don't you dare go Hollow

Drop mic/speaker popovers

Browse files at this commit

397f10bc21e00ed39f3bdfe74f9e1d76bec5968bAhmet Kaan GümüşParent: 31ab094
  • style
    • drop mic/speaker popovers
    • spectrum without high tilt and floor -48 dB so quiet highs stay flat, half the strokes
    • voice and share lines split the bar equally
    • ping has a fixed slot so the bar stops moving
  • feat
    • ping history line next to the ping
Show full message
🎨 style: drop mic/speaker popovers; spectrum without high tilt and floor -48 dB so quiet highs stay flat, half the strokes; voice and share lines split the bar equally; ping has a fixed slot so the bar stops moving; ✨ feat: ping history line next to the ping
crates/client/src/gui/call_bar.rsmodified+42 -21
@@ -18,7 +18,7 @@ pub struct CallBar {
1818 pub place: SharedString,
1919 pub bands: Option<VecDeque<f32>>,
2020 pub voice: Voice,
21- pub ping: Option<f32>,
21+ pub pings: Vec<f32>,
2222 pub muted: bool,
2323 pub deafened: bool,
2424 pub camera: bool,
@@ -36,8 +36,6 @@ pub struct CallActions {
3636 pub screen: Action,
3737 pub leave: Action,
3838 pub stats: Action,
39- pub mic_more: AnyElement,
40- pub speaker_more: AnyElement,
4139 pub camera_more: AnyElement,
4240 pub screen_more: AnyElement,
4341 }
@@ -57,8 +55,14 @@ pub fn view(bar: CallBar, actions: CallActions, t: Tokens) -> Div {
5755 } else {
5856 Ink::Faint
5957 };
58+ let pings = bar
59+ .pings
60+ .iter()
61+ .map(|ping| (ping / super::voice_stats::PING_SCALE).clamp(0., 1.))
62+ .collect();
6063 let ping = bar
61- .ping
64+ .pings
65+ .last()
6266 .map_or_else(|| "–".to_string(), |ping| format!("{ping:.0} ms"));
6367 let stats = run(&actions.stats);
6468 let controls = band(space::XS)
@@ -75,7 +79,6 @@ pub fn view(bar: CallBar, actions: CallActions, t: Tokens) -> Div {
7579 t,
7680 run(&actions.mute),
7781 ))
78- .child(actions.mic_more)
7982 .child(icon_button(
8083 format!("bar_deafen_{}", bar.deafened),
8184 if bar.deafened {
@@ -88,7 +91,6 @@ pub fn view(bar: CallBar, actions: CallActions, t: Tokens) -> Div {
8891 t,
8992 run(&actions.deafen),
9093 ))
91- .child(actions.speaker_more)
9294 .when(!bar.ghost, |row| {
9395 row.child(icon_button(
9496 format!("bar_camera_{}", bar.camera),
@@ -173,16 +175,33 @@ pub fn view(bar: CallBar, actions: CallActions, t: Tokens) -> Div {
173175 )
174176 .child(
175177 div()
176- .id("bar_ping")
177- .tip("Connection stats")
178- .cursor_pointer()
179178 .flex_none()
180- .when(bar.stats, |ping| {
181- ping.border_b(px(super::style::stroke::LINE))
182- .border_color(t.paper())
183- })
184- .on_click(move |_, window, cx| stats(window, cx))
185- .child(words(ping, Text::Label, ping_ink, t)),
179+ .w(px(size::ROW))
180+ .h(px(size::ICON))
181+ .child(super::parts::spark(
182+ pings,
183+ super::voice_stats::SAMPLE_HISTORY,
184+ ping_ink.color(t),
185+ )),
186+ )
187+ .child(
188+ div()
189+ .flex_none()
190+ .w(px(size::ROW))
191+ .flex()
192+ .justify_end()
193+ .child(
194+ div()
195+ .id("bar_ping")
196+ .tip("Connection stats")
197+ .cursor_pointer()
198+ .when(bar.stats, |ping| {
199+ ping.border_b(px(super::style::stroke::LINE))
200+ .border_color(t.paper())
201+ })
202+ .on_click(move |_, window, cx| stats(window, cx))
203+ .child(words(ping, Text::Label, ping_ink, t)),
204+ ),
186205 )
187206 .child(controls),
188207 )
@@ -190,15 +209,17 @@ pub fn view(bar: CallBar, actions: CallActions, t: Tokens) -> Div {
190209
191210 pub fn share_meter(bands: Option<&VecDeque<f32>>, color: gpui_kit::Hsla, t: Tokens) -> Div {
192211 band(space::XS)
193- .flex_none()
212+ .flex_1()
213+ .min_w(px(size::CONTROL))
194214 .child(
195215 gpui_kit::component::Icon::new(IconName::ScreenShare)
196216 .size(px(size::ICON_SM))
197217 .text_color(t.faint()),
198218 )
199- .child(div().w(px(size::THUMB)).h(px(size::ICON)).child(voice_line(
200- bands,
201- Voice::Live(color),
202- t,
203- )))
219+ .child(
220+ div()
221+ .flex_1()
222+ .h(px(size::ICON))
223+ .child(voice_line(bands, Voice::Live(color), t)),
224+ )
204225 }
crates/client/src/gui/dock.rsmodified+7 -7
@@ -40,7 +40,13 @@ impl Yumush {
4040 place: super::community_name(community).to_string().into(),
4141 bands: self.chat.waves.voice(me).cloned(),
4242 voice,
43- ping: self.chat.stats.voice.back().map(|sample| sample.ping_ms),
43+ pings: self
44+ .chat
45+ .stats
46+ .voice
47+ .iter()
48+ .map(|sample| sample.ping_ms)
49+ .collect(),
4450 muted,
4551 deafened,
4652 camera: self.network.share_source(Kind::Camera).is_some(),
@@ -78,12 +84,6 @@ impl Yumush {
7884 yumush.toggle_stats(super::chat::StatsAt::Dock);
7985 cx.notify();
8086 })),
81- mic_more: self
82- .audio_button(entity, palette, super::voice_settings::Side::Input, cx)
83- .into_any_element(),
84- speaker_more: self
85- .audio_button(entity, palette, super::voice_settings::Side::Output, cx)
86- .into_any_element(),
8787 camera_more: self
8888 .share_settings_button(entity, palette, Kind::Camera, cx)
8989 .into_any_element(),
crates/client/src/gui/gallery.rsmodified+4 -6
@@ -325,10 +325,10 @@ fn call_page(state: State, t: Tokens) -> impl IntoElement {
325325 State::Empty => Voice::Quiet,
326326 _ => Voice::Live(t.hue(Hue::Amber)),
327327 },
328- ping: match state {
329- State::Empty => None,
330- State::Bad => Some(212.),
331- _ => Some(24.),
328+ pings: match state {
329+ State::Empty => Vec::new(),
330+ State::Bad => vec![40., 90., 160., 212.],
331+ _ => vec![22., 30., 24., 26., 24.],
332332 },
333333 muted: bad,
334334 deafened: false,
@@ -347,8 +347,6 @@ fn call_page(state: State, t: Tokens) -> impl IntoElement {
347347 screen: none(),
348348 leave: none(),
349349 stats: none(),
350- mic_more: super::parts::chevron_face(false, t).into_any_element(),
351- speaker_more: super::parts::chevron_face(false, t).into_any_element(),
352350 camera_more: super::parts::chevron_face(false, t).into_any_element(),
353351 screen_more: super::parts::chevron_face(false, t).into_any_element(),
354352 };
crates/client/src/gui/parts.rsmodified+2 -2
@@ -41,7 +41,7 @@ pub enum Ink {
4141 }
4242
4343 impl Ink {
44- fn color(self, t: Tokens) -> Hsla {
44+ pub fn color(self, t: Tokens) -> Hsla {
4545 match self {
4646 Ink::Paper => t.paper(),
4747 Ink::Dim => t.dim(),
@@ -368,7 +368,7 @@ pub enum Voice {
368368
369369 const STILL: f32 = 0.02;
370370 const EDGE: f32 = 16.;
371-const PEAK_SPACING: f32 = 5.;
371+const PEAK_SPACING: f32 = 10.;
372372 const MIN_PEAKS: usize = 6;
373373
374374 pub fn voice_line(bands: Option<&VecDeque<f32>>, voice: Voice, t: Tokens) -> AnyElement {
crates/client/src/gui/voice_settings.rsmodified+5 -58
@@ -1,14 +1,13 @@
11 use std::time::Duration;
22
33 use gpui_kit::{
4- Anchor, App, AppContext, Context, Div, Entity, InteractiveElement, IntoElement, KeyDownEvent,
5- KeyUpEvent, Keystroke, ModifiersChangedEvent, MouseButton, ParentElement, SharedString,
6- Stateful, Styled, Subscription, Task, Window,
4+ App, AppContext, Context, Div, Entity, IntoElement, KeyDownEvent, KeyUpEvent, Keystroke,
5+ ModifiersChangedEvent, ParentElement, SharedString, Stateful, Styled, Subscription, Task,
6+ Window,
77 assets::IconName,
88 component::{
99 Icon, IndexPath,
1010 kbd::Kbd,
11- popover::Popover,
1211 searchable_list::{SearchableListItem, SearchableVec},
1312 select::{Select, SelectEvent, SelectState},
1413 slider::{SliderEvent, SliderState},
@@ -17,7 +16,7 @@ use gpui_kit::{
1716 };
1817
1918 use super::{
20- Palette, Tooltip as _, Trigger, Yumush, clickable,
19+ Palette, Yumush, clickable,
2120 settings_page::{row, segmented},
2221 style::{radius, size, space},
2322 };
@@ -517,7 +516,7 @@ impl Yumush {
517516 }));
518517 }
519518
520- pub(super) fn load_audio_devices(&self, window: &mut Window, cx: &mut Context<Self>) {
519+ fn load_audio_devices(&self, window: &mut Window, cx: &mut Context<Self>) {
521520 cx.spawn_in(window, async move |this, cx| {
522521 let devices = cx
523522 .background_executor()
@@ -560,55 +559,3 @@ fn test_button(
560559 .font_weight(gpui_kit::FontWeight::MEDIUM)
561560 .text_color(if active { palette.text } else { palette.muted })
562561 }
563-
564-impl Yumush {
565- pub(super) fn audio_button(
566- &self,
567- entity: &Entity<Self>,
568- palette: Palette,
569- side: Side,
570- cx: &App,
571- ) -> impl IntoElement {
572- let (id, button, tip) = match side {
573- Side::Input => ("mic_settings", "mic_settings_button", "Microphone"),
574- Side::Output => ("speaker_settings", "speaker_settings_button", "Speaker"),
575- };
576- let refresh = entity.clone();
577- let content = entity.clone();
578- Popover::new(id)
579- .anchor(Anchor::BottomRight)
580- .appearance(false)
581- .trigger(Trigger::new(
582- super::parts::chevron_face(false, super::style::Tokens::of(cx))
583- .id(button)
584- .on_mouse_down(MouseButton::Left, move |_, window, cx| {
585- refresh.update(cx, |yumush, cx| yumush.load_audio_devices(window, cx));
586- })
587- .tip(tip),
588- ))
589- .content(move |_, _, cx| audio_card(content.read(cx), side, palette))
590- }
591-}
592-
593-fn audio_card(yumush: &Yumush, side: Side, palette: Palette) -> Div {
594- let voice = &yumush.settings.voice;
595- let controls = &yumush.voice;
596- let (devices, volume, value) = match side {
597- Side::Input => (&controls.inputs, &controls.input_volume, voice.input_volume),
598- Side::Output => (
599- &controls.outputs,
600- &controls.output_volume,
601- voice.output_volume,
602- ),
603- };
604- div()
605- .w(px(size::POPOVER))
606- .p(px(space::MD))
607- .flex()
608- .flex_col()
609- .gap(px(space::MD))
610- .rounded(px(radius::LG))
611- .bg(palette.field)
612- .child(Select::new(devices).appearance(false).w_full())
613- .child(volume_control(volume, value, palette))
614-}
crates/client/src/gui/voice_stats.rsmodified+1 -1
@@ -24,7 +24,7 @@ pub const SAMPLE_HISTORY: usize = 60;
2424 const LABEL_W: f32 = size::ROW * 2.;
2525 const VALUE_W: f32 = size::THUMB;
2626 const COLUMN_W: f32 = size::TALK + size::ROW * 2.;
27-const PING_SCALE: f32 = 150.;
27+pub const PING_SCALE: f32 = 150.;
2828 pub(super) const GOOD_LOSS: f32 = 2.;
2929 const FAIR_LOSS: f32 = 8.;
3030
crates/spectrum/src/lib.rsmodified+3 -14
@@ -7,9 +7,7 @@ pub const BANDS: usize = 32;
77 pub const WINDOW: usize = 2048;
88 const LOW_HZ: f32 = 60.0;
99 const HIGH_HZ: f32 = 12000.0;
10-const TILT_DB_PER_OCTAVE: f32 = 3.0;
11-const TILT_PIVOT_HZ: f32 = 1000.0;
12-const FLOOR_DB: f32 = -60.0;
10+const FLOOR_DB: f32 = -48.0;
1311 const CEIL_DB: f32 = -12.0;
1412
1513 pub struct Analyzer {
@@ -17,7 +15,6 @@ pub struct Analyzer {
1715 hann: Vec<f32>,
1816 gain: f32,
1917 edges: Vec<usize>,
20- tilts: Vec<f32>,
2118 }
2219
2320 impl Analyzer {
@@ -33,14 +30,7 @@ impl Analyzer {
3330 let previous = edges.last().map_or(0, |edge| edge + 1);
3431 edges.push(bin(hz).max(previous).min(WINDOW / 2));
3532 }
36- let tilts = (0..BANDS)
37- .map(|band| {
38- let hz = LOW_HZ * (HIGH_HZ / LOW_HZ).powf((band as f32 + 0.5) / BANDS as f32);
39- TILT_DB_PER_OCTAVE * (hz / TILT_PIVOT_HZ).log2()
40- })
41- .collect();
4233 Self {
43- tilts,
4434 fft: FftPlanner::new().plan_fft_forward(WINDOW),
4535 hann,
4636 gain,
@@ -58,13 +48,12 @@ impl Analyzer {
5848 self.fft.process(&mut buffer);
5949 self.edges
6050 .windows(2)
61- .zip(&self.tilts)
62- .map(|(edge, tilt)| {
51+ .map(|edge| {
6352 let peak = buffer[edge[0]..edge[1].max(edge[0] + 1)]
6453 .iter()
6554 .map(|value| value.norm() * self.gain)
6655 .fold(0.0, f32::max);
67- let db = 20.0 * peak.max(1e-6).log10() + tilt;
56+ let db = 20.0 * peak.max(1e-6).log10();
6857 ((db - FLOOR_DB) / (CEIL_DB - FLOOR_DB)).clamp(0.0, 1.0)
6958 })
7059 .collect()