From 2ad667f166869454797e9b6f01c4d2113c601b64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 15 Sep 2026 04:00:59 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(audio):=20ring=20uses=20the?= =?UTF-8?q?=20picked=20colour;=20glow=200=20is=200;=20HSV=20disk?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit One strand was always the opposite hue (`0 < 1/2`). Glow on Ring never stamped. Glow 1 then − wrote the unset sentinel and showed 2. Wheel is a sat×hue disk; Sat row is gone (radius is sat). --- crates/app/src/player/library.rs | 4 -- crates/app/src/ui/dock_stance.rs | 72 +++++++++-------------------- crates/engine/src/decode.rs | 77 +++++++++++++++++++------------- 3 files changed, 68 insertions(+), 85 deletions(-) diff --git a/crates/app/src/player/library.rs b/crates/app/src/player/library.rs index a326c91..5acf26f 100644 --- a/crates/app/src/player/library.rs +++ b/crates/app/src/player/library.rs @@ -242,10 +242,6 @@ impl Player { }); } - pub(crate) fn set_viz_sat(&mut self, sat: u8, cx: &mut Context) { - self.set_viz_paint_with(cx, |p| engine::decode::with_viz_paint_sat(p, sat)); - } - pub(crate) fn set_viz_strands(&mut self, n: u8, cx: &mut Context) { self.set_viz_paint_with(cx, |p| engine::decode::with_viz_paint_strands(p, n)); } diff --git a/crates/app/src/ui/dock_stance.rs b/crates/app/src/ui/dock_stance.rs index eb1ce3d..4eca6fb 100644 --- a/crates/app/src/ui/dock_stance.rs +++ b/crates/app/src/ui/dock_stance.rs @@ -1326,27 +1326,27 @@ fn viz_color_wheel(paint: u32, cx: &mut Context) -> impl IntoElement { let cx = f32::from(o.x) + w / 2.; let cy = f32::from(o.y) + h / 2.; let radius = w.min(h) / 2. - 1.; - let wedges = 48; - for i in 0..wedges { - let a0 = (i as f32 / wedges as f32) * std::f32::consts::TAU; - let a1 = ((i + 1) as f32 / wedges as f32) * std::f32::consts::TAU; - // 0 at top, clockwise: screen y down, so angle 0 is -Y. - let hue = i as f32 / wedges as f32 * 360.; - let (r, g, b) = engine::decode::viz_hsv_rgb(hue, 1., 0.84); - let color = (u32::from(r) << 16) | (u32::from(g) << 8) | u32::from(b); - let p0 = point(px(cx), px(cy)); - let p1 = point( - px(cx + radius * a0.sin()), - px(cy - radius * a0.cos()), - ); - let p2 = point( - px(cx + radius * a1.sin()), - px(cy - radius * a1.cos()), - ); - let mut path = PathBuilder::fill(); - path.add_polygon(&[p0, p1, p2], false); - if let Ok(path) = path.build() { - window.paint_path(path, rgb(color)); + let wedges = 72; + let rings = 10; + for ring in 0..rings { + let s0 = ring as f32 / rings as f32; + let s1 = (ring + 1) as f32 / rings as f32; + let sat = (s0 + s1) / 2.; + for i in 0..wedges { + let a0 = (i as f32 / wedges as f32) * std::f32::consts::TAU; + let a1 = ((i + 1) as f32 / wedges as f32) * std::f32::consts::TAU; + let hue = i as f32 / wedges as f32 * 360.; + let (r, g, b) = engine::decode::viz_hsv_rgb(hue, sat, 0.84); + let color = (u32::from(r) << 16) | (u32::from(g) << 8) | u32::from(b); + let p00 = point(px(cx + radius * s0 * a0.sin()), px(cy - radius * s0 * a0.cos())); + let p01 = point(px(cx + radius * s0 * a1.sin()), px(cy - radius * s0 * a1.cos())); + let p11 = point(px(cx + radius * s1 * a1.sin()), px(cy - radius * s1 * a1.cos())); + let p10 = point(px(cx + radius * s1 * a0.sin()), px(cy - radius * s1 * a0.cos())); + let mut path = PathBuilder::fill(); + path.add_polygon(&[p00, p01, p11, p10], false); + if let Ok(path) = path.build() { + window.paint_path(path, rgb(color)); + } } } // Selection mark. @@ -1389,13 +1389,12 @@ fn viz_color_wheel(paint: u32, cx: &mut Context) -> impl IntoElement { let ang = dx.atan2(dy).to_degrees(); let hue_deg = (ang + 360.) % 360.; let hue = (hue_deg / 360. * 256.).round() as u16 as u8; - this.set_viz_hs(hue, sat.max(1), cx); + this.set_viz_hs(hue, sat, cx); }), ) } fn viz_paint_knobs(paint: u32, cx: &mut Context) -> impl IntoElement { - let sat = engine::decode::viz_sat_ui(paint); let strands = engine::decode::viz_strands_of(paint); let glow = engine::decode::viz_glow_of(paint); let style = label(type_scale::LABEL_ROW_PX, FontWeight::MEDIUM); @@ -1419,33 +1418,6 @@ fn viz_paint_knobs(paint: u32, cx: &mut Context) -> impl IntoElement { ) .child(viz_color_wheel(paint, cx)), ) - .child( - div() - .flex() - .items_center() - .gap(px(4.)) - .h(px(CONTROL_H)) - .child( - div() - .font(style.font.clone()) - .text_size(style.size) - .text_color(rgb(INK2())) - .child("Sat"), - ) - .child(viz_step("dock-viz-sat-minus", "−", cx, |this, cx| { - this.set_viz_sat(engine::decode::viz_sat_ui(this.viz_paint()).saturating_sub(16), cx); - })) - .child( - div() - .font(style.font.clone()) - .text_size(style.size) - .text_color(rgb(INK1())) - .child(format!("{sat}")), - ) - .child(viz_step("dock-viz-sat-plus", "+", cx, |this, cx| { - this.set_viz_sat(engine::decode::viz_sat_ui(this.viz_paint()).saturating_add(16).min(255), cx); - })), - ) .child( div() .flex() diff --git a/crates/engine/src/decode.rs b/crates/engine/src/decode.rs index a4aff5b..710b820 100644 --- a/crates/engine/src/decode.rs +++ b/crates/engine/src/decode.rs @@ -1446,48 +1446,46 @@ pub fn viz_ink_rgb(hue: u8) -> (u8, u8, u8) { hsv_to_rgb(212.0 + f32::from(hue & 15) * 22.5, 0.63, 0.84) } -pub fn viz_ink_from_paint(paint: u32) -> (u8, u8, u8) { +/// Azure + sat 160 + 8 strands + glow 2. What `viz_paint == 0` means. +pub const VIZ_PAINT_AZURE: u32 = 150 | (160 << 8) | (8 << 16) | (2 << 24); + +pub fn viz_materialize(paint: u32) -> u32 { if paint == 0 { - return hsv_to_rgb(212.0, 0.63, 0.84); + VIZ_PAINT_AZURE + } else { + paint } - let hue = (paint & 0xFF) as f32 * 360.0 / 256.0; - let sat_b = ((paint >> 8) & 0xFF) as u8; - let sat = if sat_b == 0 { 0.63 } else { f32::from(sat_b) / 255.0 }; +} + +pub fn viz_ink_from_paint(paint: u32) -> (u8, u8, u8) { + let p = viz_materialize(paint); + let hue = (p & 0xFF) as f32 * 360.0 / 256.0; + let sat = f32::from(((p >> 8) & 0xFF) as u8) / 255.0; hsv_to_rgb(hue, sat, 0.84) } pub fn viz_strands_of(paint: u32) -> u8 { - match ((paint >> 16) & 0xFF) as u8 { - 0 => 8, - n => n.clamp(1, 32), - } + (((viz_materialize(paint) >> 16) & 0xFF) as u8).clamp(1, 32) } pub fn viz_glow_of(paint: u32) -> u8 { - match ((paint >> 24) & 0xFF) as u8 { - 0 => 2, - n => n.min(16), - } + ((viz_materialize(paint) >> 24) & 0xFF) as u8 } pub fn with_viz_paint_hue(paint: u32, hue: u8) -> u32 { - let sat = match (paint >> 8) & 0xFF { - 0 => 255, - s => s, - }; - (paint & !0xFF) | u32::from(hue) | (sat << 8) + (viz_materialize(paint) & !0xFF) | u32::from(hue) } pub fn with_viz_paint_sat(paint: u32, sat: u8) -> u32 { - (paint & !(0xFF << 8)) | (u32::from(sat.max(1)) << 8) + (viz_materialize(paint) & !(0xFF << 8)) | (u32::from(sat) << 8) } pub fn with_viz_paint_strands(paint: u32, n: u8) -> u32 { - (paint & !(0xFF << 16)) | (u32::from(n.clamp(1, 32)) << 16) + (viz_materialize(paint) & !(0xFF << 16)) | (u32::from(n.clamp(1, 32)) << 16) } pub fn with_viz_paint_glow(paint: u32, n: u8) -> u32 { - (paint & !(0xFF << 24)) | (u32::from(n.min(16)) << 24) + (viz_materialize(paint) & !(0xFF << 24)) | (u32::from(n.min(16)) << 24) } pub fn viz_hue_ui(paint: u32) -> u8 { @@ -1615,16 +1613,29 @@ fn viz_line( ink_y: u8, ink_u: u8, ink_v: u8, + glow: u8, ) { let dx = (x1 - x0).abs(); let dy = -(y1 - y0).abs(); let sx = if x0 < x1 { 1 } else { -1 }; let sy = if y0 < y1 { 1 } else { -1 }; let mut err = dx + dy; + let g = i32::from(glow); loop { - viz_stamp(y, u, v, w, h, cw, ch, x0, y0, 1.0, bg_y, ink_y, ink_u, ink_v); - viz_stamp(y, u, v, w, h, cw, ch, x0, y0 - 1, 0.45, bg_y, ink_y, ink_u, ink_v); - viz_stamp(y, u, v, w, h, cw, ch, x0, y0 + 1, 0.45, bg_y, ink_y, ink_u, ink_v); + for oy in -g..=g { + for ox in -g..=g { + if ox * ox + oy * oy > g * g { + continue; + } + let fall = if ox == 0 && oy == 0 { + 1.0 + } else { + let d2 = (ox * ox + oy * oy) as f32; + (-0.45 * d2 / (g * g).max(1) as f32).exp() + }; + viz_stamp(y, u, v, w, h, cw, ch, x0 + ox, y0 + oy, fall, bg_y, ink_y, ink_u, ink_v); + } + } if x0 == x1 && y0 == y1 { break; } @@ -1748,7 +1759,7 @@ pub(crate) fn visualizer_i420( let scale = 0.28 + 0.72 * frac; let wave = (x_phase + travel + s as f64 * 0.05).sin() as f32; let row = (center + half * env * scale * wave).round() as i32; - let glow = i32::from(viz_glow_of(paint)).max(1); + let glow = i32::from(viz_glow_of(paint)); viz_stamp( &mut y, &mut u, &mut v, w, h, cw, ch, col as i32, row, 1.0, bg_y, ink_y, ink_u, ink_v, @@ -1774,11 +1785,14 @@ pub(crate) fn visualizer_i420( let amp = (w.min(h) as f32) * 0.18; let tau = std::f32::consts::TAU; let steps = w.max(h) * 4; - for strand in 0..viz_strands_of(paint) { - let (ir, ig, ib) = viz_ink_from_paint(if strand < viz_strands_of(paint) / 2 { - paint - } else { + let strands = viz_strands_of(paint); + let glow = viz_glow_of(paint); + for strand in 0..strands { + let dual = strands >= 2 && strand >= strands / 2; + let (ir, ig, ib) = viz_ink_from_paint(if dual { with_viz_paint_hue(paint, viz_hue_ui(paint).wrapping_add(128)) + } else { + paint }); let (iy, iu, iv) = rgb_yuv(ir as i32, ig as i32, ib as i32); let scale = 0.65 + 0.35 * f32::from(strand % 4) / 3.0; @@ -1796,6 +1810,7 @@ pub(crate) fn visualizer_i420( if let Some((px, py)) = prev { viz_line( &mut y, &mut u, &mut v, w, h, cw, ch, px, py, x, row, bg_y, iy, iu, iv, + glow, ); } prev = Some((x, row)); @@ -1810,7 +1825,7 @@ pub(crate) fn visualizer_i420( if let Some((px, py)) = prev { viz_line( &mut y, &mut u, &mut v, w, h, cw, ch, px, py, x, y_pt, bg_y, ink_y, ink_u, - ink_v, + ink_v, viz_glow_of(paint), ); } prev = Some((x, y_pt)); @@ -1819,7 +1834,7 @@ pub(crate) fn visualizer_i420( _ => { // Timeline envelope: one filled body, tops then bottoms, after // the fold+smooth above. Default look. - let glow = i32::from(viz_glow_of(paint)).max(1); + let glow = i32::from(viz_glow_of(paint)); for col in 0..w { let top = (center - hi[col] * half).round() as i32; let bot = (center - lo[col] * half).round() as i32;