forge
Explore
Log in

Don't you dare go Hollow

HSV wheel, real glow, fixed-length window

Browse files at this commit

20ec2e759d33aa97cf19c37fbc22857f520c31edAhmet Kaan GümüşParent: 7ebfc44
  • feat
    • HSV wheel, real glow, fixed-length window
Show full message
✨ feat(audio): HSV wheel, real glow, fixed-length window

Colour is a standard HSV wheel (0° red at top, radius = sat). Glow
now expands the stroke. The 2s view no longer shrinks at file edges,
which was stretching a bump as it entered.
crates/app/src/player/library.rsmodified+4 -2
@@ -236,8 +236,10 @@ impl Player {
236236 .unwrap_or(0)
237237 }
238238
239- pub(crate) fn set_viz_hue(&mut self, hue: u8, cx: &mut Context<Self>) {
240- self.set_viz_paint_with(cx, |p| engine::decode::with_viz_paint_hue(p, hue));
239+ pub(crate) fn set_viz_hs(&mut self, hue: u8, sat: u8, cx: &mut Context<Self>) {
240+ self.set_viz_paint_with(cx, |p| {
241+ engine::decode::with_viz_paint_sat(engine::decode::with_viz_paint_hue(p, hue), sat)
242+ });
241243 }
242244
243245 pub(crate) fn set_viz_sat(&mut self, sat: u8, cx: &mut Context<Self>) {
crates/app/src/ui/dock_stance.rsmodified+92 -36
@@ -15,7 +15,7 @@ use crate::ui::hitmap;
1515 use crate::ui::stance::{Surface, is_focus_cycle_key, is_focus_exit_key, next_surface};
1616 use crate::ui::type_scale::{self, Typeset, head, label, mono};
1717 use crate::*;
18-use gpui::FontWeight;
18+use gpui::{FontWeight, PathBuilder, point};
1919
2020 /// Where the dock tab pick lives: one word beside the theme and the
2121 /// keybindings (`ui::theme::config_path`/`save`/`load` is the exact pattern
@@ -1306,8 +1306,95 @@ fn viz_step(
13061306 .child(glyph)
13071307 }
13081308
1309+fn viz_color_wheel(paint: u32, cx: &mut Context<Player>) -> impl IntoElement {
1310+ let hit = std::rc::Rc::new(std::cell::Cell::new(Bounds::default()));
1311+ let hit_click = hit.clone();
1312+ div()
1313+ .id("dock-viz-hs")
1314+ .w(px(112.))
1315+ .h(px(112.))
1316+ .relative()
1317+ .cursor_pointer()
1318+ .children(hitmap::control("dock-viz-hs", "Colour wheel", true))
1319+ .child(bounds_probe(hit))
1320+ .child(
1321+ canvas(
1322+ |_, _, _| (),
1323+ move |bounds, _, window, _| {
1324+ let o = bounds.origin;
1325+ let (w, h) = (f32::from(bounds.size.width), f32::from(bounds.size.height));
1326+ let cx = f32::from(o.x) + w / 2.;
1327+ let cy = f32::from(o.y) + h / 2.;
1328+ let radius = w.min(h) / 2. - 1.;
1329+ let wedges = 48;
1330+ for i in 0..wedges {
1331+ let a0 = (i as f32 / wedges as f32) * std::f32::consts::TAU;
1332+ let a1 = ((i + 1) as f32 / wedges as f32) * std::f32::consts::TAU;
1333+ // 0 at top, clockwise: screen y down, so angle 0 is -Y.
1334+ let hue = i as f32 / wedges as f32 * 360.;
1335+ let (r, g, b) = engine::decode::viz_hsv_rgb(hue, 1., 0.84);
1336+ let color = (u32::from(r) << 16) | (u32::from(g) << 8) | u32::from(b);
1337+ let p0 = point(px(cx), px(cy));
1338+ let p1 = point(
1339+ px(cx + radius * a0.sin()),
1340+ px(cy - radius * a0.cos()),
1341+ );
1342+ let p2 = point(
1343+ px(cx + radius * a1.sin()),
1344+ px(cy - radius * a1.cos()),
1345+ );
1346+ let mut path = PathBuilder::fill();
1347+ path.add_polygon(&[p0, p1, p2], false);
1348+ if let Ok(path) = path.build() {
1349+ window.paint_path(path, rgb(color));
1350+ }
1351+ }
1352+ // Selection mark.
1353+ let hue = f32::from(engine::decode::viz_hue_ui(paint)) / 256. * std::f32::consts::TAU;
1354+ let sat = f32::from(engine::decode::viz_sat_ui(paint)) / 255.;
1355+ let mx = cx + radius * sat * hue.sin();
1356+ let my = cy - radius * sat * hue.cos();
1357+ let mut mark = PathBuilder::stroke(px(2.));
1358+ let r = 4.;
1359+ mark.add_polygon(
1360+ &[
1361+ point(px(mx - r), px(my)),
1362+ point(px(mx), px(my - r)),
1363+ point(px(mx + r), px(my)),
1364+ point(px(mx), px(my + r)),
1365+ ],
1366+ true,
1367+ );
1368+ if let Ok(path) = mark.build() {
1369+ window.paint_path(path, rgb(INK1()));
1370+ }
1371+ },
1372+ )
1373+ .size_full(),
1374+ )
1375+ .on_mouse_down(
1376+ MouseButton::Left,
1377+ cx.listener(move |this, event: &MouseDownEvent, _, cx| {
1378+ let b = hit_click.get();
1379+ let w = f32::from(b.size.width).max(1.);
1380+ let h = f32::from(b.size.height).max(1.);
1381+ let dx = f32::from(event.position.x - b.origin.x) - w / 2.;
1382+ let dy = h / 2. - f32::from(event.position.y - b.origin.y);
1383+ let radius = w.min(h) / 2.;
1384+ let r = (dx * dx + dy * dy).sqrt() / radius;
1385+ if r > 1.08 {
1386+ return;
1387+ }
1388+ let sat = (r.clamp(0., 1.) * 255.).round() as u8;
1389+ let ang = dx.atan2(dy).to_degrees();
1390+ let hue_deg = (ang + 360.) % 360.;
1391+ let hue = (hue_deg / 360. * 256.).round() as u16 as u8;
1392+ this.set_viz_hs(hue, sat.max(1), cx);
1393+ }),
1394+ )
1395+}
1396+
13091397 fn viz_paint_knobs(paint: u32, cx: &mut Context<Player>) -> impl IntoElement {
1310- let hue = engine::decode::viz_hue_ui(paint);
13111398 let sat = engine::decode::viz_sat_ui(paint);
13121399 let strands = engine::decode::viz_strands_of(paint);
13131400 let glow = engine::decode::viz_glow_of(paint);
@@ -1319,11 +1406,10 @@ fn viz_paint_knobs(paint: u32, cx: &mut Context<Player>) -> impl IntoElement {
13191406 .px(px(8.))
13201407 .child(
13211408 div()
1322- .id("dock-viz-hue")
1409+ .id("dock-viz-wheel")
13231410 .flex()
1324- .items_center()
1411+ .flex_col()
13251412 .gap(px(4.))
1326- .h(px(CONTROL_H))
13271413 .child(
13281414 div()
13291415 .font(style.font.clone())
@@ -1331,37 +1417,7 @@ fn viz_paint_knobs(paint: u32, cx: &mut Context<Player>) -> impl IntoElement {
13311417 .text_color(rgb(INK2()))
13321418 .child("Colour"),
13331419 )
1334- .child(viz_step("dock-viz-hue-minus", "−", cx, |this, cx| {
1335- this.set_viz_hue(engine::decode::viz_hue_ui(this.viz_paint()).wrapping_sub(4), cx);
1336- }))
1337- .child(
1338- div()
1339- .id("dock-viz-hue-bar")
1340- .flex_1()
1341- .flex()
1342- .h(px(14.))
1343- .children((0u8..64).map(|i| {
1344- let h = i.saturating_mul(4);
1345- let (r, g, b) = engine::decode::viz_ink_from_paint(
1346- engine::decode::with_viz_paint_hue(paint, h),
1347- );
1348- let color = (u32::from(r) << 16) | (u32::from(g) << 8) | u32::from(b);
1349- div()
1350- .id(("dock-viz-hue", u64::from(i)))
1351- .flex_1()
1352- .h_full()
1353- .bg(rgb(color))
1354- .when(hue.abs_diff(h) < 3, |d| d.border_1().border_color(rgb(INK1())))
1355- .cursor_pointer()
1356- .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| {
1357- this.set_viz_hue(h, cx);
1358- }))
1359- .into_any_element()
1360- })),
1361- )
1362- .child(viz_step("dock-viz-hue-plus", "+", cx, |this, cx| {
1363- this.set_viz_hue(engine::decode::viz_hue_ui(this.viz_paint()).wrapping_add(4), cx);
1364- })),
1420+ .child(viz_color_wheel(paint, cx)),
13651421 )
13661422 .child(
13671423 div()
crates/engine/src/decode.rsmodified+58 -63
@@ -1505,6 +1505,10 @@ pub fn viz_sat_ui(paint: u32) -> u8 {
15051505 }
15061506 }
15071507
1508+pub fn viz_hsv_rgb(h: f32, s: f32, v: f32) -> (u8, u8, u8) {
1509+ hsv_to_rgb(h, s, v)
1510+}
1511+
15081512 fn hsv_to_rgb(h: f32, s: f32, v: f32) -> (u8, u8, u8) {
15091513 let h = ((h % 360.0) + 360.0) % 360.0;
15101514 let c = v * s;
@@ -1595,28 +1599,6 @@ fn viz_span(
15951599 }
15961600 }
15971601
1598-fn viz_smooth(lo: &mut [f32], hi: &mut [f32]) {
1599- let n = lo.len();
1600- if n < 5 {
1601- return;
1602- }
1603- let (src_lo, src_hi) = (lo.to_vec(), hi.to_vec());
1604- for i in 2..n - 2 {
1605- lo[i] = (src_lo[i - 2]
1606- + src_lo[i - 1] * 2.0
1607- + src_lo[i] * 3.0
1608- + src_lo[i + 1] * 2.0
1609- + src_lo[i + 2])
1610- / 9.0;
1611- hi[i] = (src_hi[i - 2]
1612- + src_hi[i - 1] * 2.0
1613- + src_hi[i] * 3.0
1614- + src_hi[i + 1] * 2.0
1615- + src_hi[i + 2])
1616- / 9.0;
1617- }
1618-}
1619-
16201602 fn viz_line(
16211603 y: &mut [u8],
16221604 u: &mut [u8],
@@ -1700,36 +1682,43 @@ pub(crate) fn visualizer_i420(
17001682 } else {
17011683 VIZ_WINDOW_SECS
17021684 };
1703- let first = (((t_secs - window / 2.0).max(0.0) * per_sec).floor() as usize)
1704- .min(peaks.len() - 1);
1705- let last = ((((t_secs + window / 2.0).min(duration) * per_sec).ceil() as usize)
1706- .clamp(first + 1, peaks.len()))
1707- .min(peaks.len());
1708- let span = (last - first) as f64;
1709- let pair = |i: usize| peaks[i.min(peaks.len() - 1)];
1710- let signed = |i: usize| {
1711- let (a, b) = pair(i);
1712- if b.abs() >= a.abs() {
1713- b
1714- } else {
1715- a
1685+ // Fixed window length, silence outside the file: shrinking the span
1686+ // to the samples that exist stretched a bump as it entered (2s) and
1687+ // Fast (0.2s) rarely hit the edge. Column x always maps to
1688+ // t - window/2 + x/w * window.
1689+ let origin = t_secs - window / 2.0;
1690+ let pair_at = |t: f64| -> (f32, f32) {
1691+ if !t.is_finite() || t < 0.0 || t > duration {
1692+ return (0.0, 0.0);
17161693 }
1694+ let pos = (t * per_sec).clamp(0.0, (peaks.len() - 1) as f64);
1695+ let i = pos.floor() as usize;
1696+ let f = (pos - i as f64) as f32;
1697+ let (lo0, hi0) = peaks[i];
1698+ let (lo1, hi1) = peaks[(i + 1).min(peaks.len() - 1)];
1699+ (
1700+ (lo0 + (lo1 - lo0) * f).clamp(-1.0, 0.0),
1701+ (hi0 + (hi1 - hi0) * f).clamp(0.0, 1.0),
1702+ )
1703+ };
1704+ let signed_at = |t: f64| {
1705+ let (a, b) = pair_at(t);
1706+ if b.abs() >= a.abs() { b } else { a }
17171707 };
17181708 for col in 0..w {
1719- let a = first + (col as f64 * span / w as f64).floor() as usize;
1720- let b = (first + (((col + 1) as f64 * span / w as f64).ceil() as usize)).min(peaks.len());
1721- let b = b.max(a + 1);
1709+ let t0 = origin + col as f64 / w as f64 * window;
1710+ let t1 = origin + (col + 1) as f64 / w as f64 * window;
17221711 let (mut mn, mut mx) = (0.0f32, 0.0f32);
1723- for &(l, h) in &peaks[a.min(peaks.len() - 1)..b.min(peaks.len()).max(a.min(peaks.len() - 1) + 1)] {
1712+ let samples = 4;
1713+ for k in 0..samples {
1714+ let t = t0 + (t1 - t0) * (k as f64 + 0.5) / samples as f64;
1715+ let (l, h) = pair_at(t);
17241716 mn = mn.min(l);
17251717 mx = mx.max(h);
17261718 }
1727- lo[col] = mn.clamp(-1.0, 0.0);
1728- hi[col] = mx.clamp(0.0, 1.0);
1729- let pos = first as f64 + (col as f64 + 0.5) * span / w as f64;
1730- let i = pos.floor() as usize;
1731- let f = (pos - i as f64) as f32;
1732- sig[col] = signed(i) + (signed(i.saturating_add(1)) - signed(i)) * f;
1719+ lo[col] = mn;
1720+ hi[col] = mx;
1721+ sig[col] = signed_at(origin + (col as f64 + 0.5) / w as f64 * window);
17331722 }
17341723 // Whole-file peak, not the window's: a 2s window that gains or loses
17351724 // a loud hit used to rescale every column, so the same bump changed
@@ -1745,8 +1734,6 @@ pub(crate) fn visualizer_i420(
17451734 sig[i] /= peak;
17461735 }
17471736 }
1748- viz_smooth(&mut lo, &mut hi);
1749- viz_smooth(&mut lo, &mut hi);
17501737 }
17511738
17521739 match viz_style(flags) {
@@ -1761,18 +1748,22 @@ pub(crate) fn visualizer_i420(
17611748 let scale = 0.28 + 0.72 * frac;
17621749 let wave = (x_phase + travel + s as f64 * 0.05).sin() as f32;
17631750 let row = (center + half * env * scale * wave).round() as i32;
1751+ let glow = i32::from(viz_glow_of(paint)).max(1);
17641752 viz_stamp(
17651753 &mut y, &mut u, &mut v, w, h, cw, ch, col as i32, row, 1.0, bg_y, ink_y,
17661754 ink_u, ink_v,
17671755 );
1768- viz_stamp(
1769- &mut y, &mut u, &mut v, w, h, cw, ch, col as i32, row - 1, 0.35, bg_y,
1770- ink_y, ink_u, ink_v,
1771- );
1772- viz_stamp(
1773- &mut y, &mut u, &mut v, w, h, cw, ch, col as i32, row + 1, 0.35, bg_y,
1774- ink_y, ink_u, ink_v,
1775- );
1756+ for dy in 1..=glow {
1757+ let fall = 0.5 / dy as f32;
1758+ viz_stamp(
1759+ &mut y, &mut u, &mut v, w, h, cw, ch, col as i32, row - dy, fall, bg_y,
1760+ ink_y, ink_u, ink_v,
1761+ );
1762+ viz_stamp(
1763+ &mut y, &mut u, &mut v, w, h, cw, ch, col as i32, row + dy, fall, bg_y,
1764+ ink_y, ink_u, ink_v,
1765+ );
1766+ }
17761767 }
17771768 }
17781769 }
@@ -1828,6 +1819,7 @@ pub(crate) fn visualizer_i420(
18281819 _ => {
18291820 // Timeline envelope: one filled body, tops then bottoms, after
18301821 // the fold+smooth above. Default look.
1822+ let glow = i32::from(viz_glow_of(paint)).max(1);
18311823 for col in 0..w {
18321824 let top = (center - hi[col] * half).round() as i32;
18331825 let bot = (center - lo[col] * half).round() as i32;
@@ -1835,14 +1827,17 @@ pub(crate) fn visualizer_i420(
18351827 &mut y, &mut u, &mut v, w, h, cw, ch, col as i32, top, bot, bg_y, ink_y, ink_u,
18361828 ink_v,
18371829 );
1838- viz_stamp(
1839- &mut y, &mut u, &mut v, w, h, cw, ch, col as i32, top - 1, 0.4, bg_y, ink_y,
1840- ink_u, ink_v,
1841- );
1842- viz_stamp(
1843- &mut y, &mut u, &mut v, w, h, cw, ch, col as i32, bot + 1, 0.4, bg_y, ink_y,
1844- ink_u, ink_v,
1845- );
1830+ for dy in 1..=glow {
1831+ let fall = 0.55 / dy as f32;
1832+ viz_stamp(
1833+ &mut y, &mut u, &mut v, w, h, cw, ch, col as i32, top - dy, fall, bg_y,
1834+ ink_y, ink_u, ink_v,
1835+ );
1836+ viz_stamp(
1837+ &mut y, &mut u, &mut v, w, h, cw, ch, col as i32, bot + dy, fall, bg_y,
1838+ ink_y, ink_u, ink_v,
1839+ );
1840+ }
18461841 }
18471842 }
18481843 }