forge
Explore
Log in

Don't you dare go Hollow

Ring uses the picked colour

Browse files at this commit

2ad667f166869454797e9b6f01c4d2113c601b64Ahmet Kaan GümüşParent: 20ec2e7
  • fix
    • ring uses the picked colour
    • glow 0 is 0
    • HSV disk
Show full message
🐛 fix(audio): ring uses the picked colour; glow 0 is 0; HSV disk

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.rsmodified+0 -4
@@ -242,10 +242,6 @@ impl Player {
242 });242 });
243 }243 }
244 244
245- pub(crate) fn set_viz_sat(&mut self, sat: u8, cx: &mut Context<Self>) {
246- self.set_viz_paint_with(cx, |p| engine::decode::with_viz_paint_sat(p, sat));
247- }
248-
249 pub(crate) fn set_viz_strands(&mut self, n: u8, cx: &mut Context<Self>) {245 pub(crate) fn set_viz_strands(&mut self, n: u8, cx: &mut Context<Self>) {
250 self.set_viz_paint_with(cx, |p| engine::decode::with_viz_paint_strands(p, n));246 self.set_viz_paint_with(cx, |p| engine::decode::with_viz_paint_strands(p, n));
251 }247 }
crates/app/src/ui/dock_stance.rsmodified+22 -50
@@ -1326,27 +1326,27 @@ fn viz_color_wheel(paint: u32, cx: &mut Context<Player>) -> impl IntoElement {
1326 let cx = f32::from(o.x) + w / 2.;1326 let cx = f32::from(o.x) + w / 2.;
1327 let cy = f32::from(o.y) + h / 2.;1327 let cy = f32::from(o.y) + h / 2.;
1328 let radius = w.min(h) / 2. - 1.;1328 let radius = w.min(h) / 2. - 1.;
1329- let wedges = 48;1329+ let wedges = 72;
1330- for i in 0..wedges {1330+ let rings = 10;
1331- let a0 = (i as f32 / wedges as f32) * std::f32::consts::TAU;1331+ for ring in 0..rings {
1332- let a1 = ((i + 1) as f32 / wedges as f32) * std::f32::consts::TAU;1332+ let s0 = ring as f32 / rings as f32;
1333- // 0 at top, clockwise: screen y down, so angle 0 is -Y.1333+ let s1 = (ring + 1) as f32 / rings as f32;
1334- let hue = i as f32 / wedges as f32 * 360.;1334+ let sat = (s0 + s1) / 2.;
1335- let (r, g, b) = engine::decode::viz_hsv_rgb(hue, 1., 0.84);1335+ for i in 0..wedges {
1336- let color = (u32::from(r) << 16) | (u32::from(g) << 8) | u32::from(b);1336+ let a0 = (i as f32 / wedges as f32) * std::f32::consts::TAU;
1337- let p0 = point(px(cx), px(cy));1337+ let a1 = ((i + 1) as f32 / wedges as f32) * std::f32::consts::TAU;
1338- let p1 = point(1338+ let hue = i as f32 / wedges as f32 * 360.;
1339- px(cx + radius * a0.sin()),1339+ let (r, g, b) = engine::decode::viz_hsv_rgb(hue, sat, 0.84);
1340- px(cy - radius * a0.cos()),1340+ let color = (u32::from(r) << 16) | (u32::from(g) << 8) | u32::from(b);
1341- );1341+ let p00 = point(px(cx + radius * s0 * a0.sin()), px(cy - radius * s0 * a0.cos()));
1342- let p2 = point(1342+ let p01 = point(px(cx + radius * s0 * a1.sin()), px(cy - radius * s0 * a1.cos()));
1343- px(cx + radius * a1.sin()),1343+ let p11 = point(px(cx + radius * s1 * a1.sin()), px(cy - radius * s1 * a1.cos()));
1344- px(cy - radius * a1.cos()),1344+ let p10 = point(px(cx + radius * s1 * a0.sin()), px(cy - radius * s1 * a0.cos()));
1345- );1345+ let mut path = PathBuilder::fill();
1346- let mut path = PathBuilder::fill();1346+ path.add_polygon(&[p00, p01, p11, p10], false);
1347- path.add_polygon(&[p0, p1, p2], false);1347+ if let Ok(path) = path.build() {
1348- if let Ok(path) = path.build() {1348+ window.paint_path(path, rgb(color));
1349- window.paint_path(path, rgb(color));1349+ }
1350 }1350 }
1351 }1351 }
1352 // Selection mark.1352 // Selection mark.
@@ -1389,13 +1389,12 @@ fn viz_color_wheel(paint: u32, cx: &mut Context<Player>) -> impl IntoElement {
1389 let ang = dx.atan2(dy).to_degrees();1389 let ang = dx.atan2(dy).to_degrees();
1390 let hue_deg = (ang + 360.) % 360.;1390 let hue_deg = (ang + 360.) % 360.;
1391 let hue = (hue_deg / 360. * 256.).round() as u16 as u8;1391 let hue = (hue_deg / 360. * 256.).round() as u16 as u8;
1392- this.set_viz_hs(hue, sat.max(1), cx);1392+ this.set_viz_hs(hue, sat, cx);
1393 }),1393 }),
1394 )1394 )
1395 }1395 }
1396 1396
1397 fn viz_paint_knobs(paint: u32, cx: &mut Context<Player>) -> impl IntoElement {1397 fn viz_paint_knobs(paint: u32, cx: &mut Context<Player>) -> impl IntoElement {
1398- let sat = engine::decode::viz_sat_ui(paint);
1399 let strands = engine::decode::viz_strands_of(paint);1398 let strands = engine::decode::viz_strands_of(paint);
1400 let glow = engine::decode::viz_glow_of(paint);1399 let glow = engine::decode::viz_glow_of(paint);
1401 let style = label(type_scale::LABEL_ROW_PX, FontWeight::MEDIUM);1400 let style = label(type_scale::LABEL_ROW_PX, FontWeight::MEDIUM);
@@ -1419,33 +1418,6 @@ fn viz_paint_knobs(paint: u32, cx: &mut Context<Player>) -> impl IntoElement {
1419 )1418 )
1420 .child(viz_color_wheel(paint, cx)),1419 .child(viz_color_wheel(paint, cx)),
1421 )1420 )
1422- .child(
1423- div()
1424- .flex()
1425- .items_center()
1426- .gap(px(4.))
1427- .h(px(CONTROL_H))
1428- .child(
1429- div()
1430- .font(style.font.clone())
1431- .text_size(style.size)
1432- .text_color(rgb(INK2()))
1433- .child("Sat"),
1434- )
1435- .child(viz_step("dock-viz-sat-minus", "−", cx, |this, cx| {
1436- this.set_viz_sat(engine::decode::viz_sat_ui(this.viz_paint()).saturating_sub(16), cx);
1437- }))
1438- .child(
1439- div()
1440- .font(style.font.clone())
1441- .text_size(style.size)
1442- .text_color(rgb(INK1()))
1443- .child(format!("{sat}")),
1444- )
1445- .child(viz_step("dock-viz-sat-plus", "+", cx, |this, cx| {
1446- this.set_viz_sat(engine::decode::viz_sat_ui(this.viz_paint()).saturating_add(16).min(255), cx);
1447- })),
1448- )
1449 .child(1421 .child(
1450 div()1422 div()
1451 .flex()1423 .flex()
crates/engine/src/decode.rsmodified+46 -31
@@ -1446,48 +1446,46 @@ pub fn viz_ink_rgb(hue: u8) -> (u8, u8, u8) {
1446 hsv_to_rgb(212.0 + f32::from(hue & 15) * 22.5, 0.63, 0.84)1446 hsv_to_rgb(212.0 + f32::from(hue & 15) * 22.5, 0.63, 0.84)
1447 }1447 }
1448 1448
1449-pub fn viz_ink_from_paint(paint: u32) -> (u8, u8, u8) {1449+/// Azure + sat 160 + 8 strands + glow 2. What `viz_paint == 0` means.
1450+pub const VIZ_PAINT_AZURE: u32 = 150 | (160 << 8) | (8 << 16) | (2 << 24);
1451+
1452+pub fn viz_materialize(paint: u32) -> u32 {
1450 if paint == 0 {1453 if paint == 0 {
1451- return hsv_to_rgb(212.0, 0.63, 0.84);1454+ VIZ_PAINT_AZURE
1455+ } else {
1456+ paint
1452 }1457 }
1453- let hue = (paint & 0xFF) as f32 * 360.0 / 256.0;1458+}
1454- let sat_b = ((paint >> 8) & 0xFF) as u8;1459+
1455- let sat = if sat_b == 0 { 0.63 } else { f32::from(sat_b) / 255.0 };1460+pub fn viz_ink_from_paint(paint: u32) -> (u8, u8, u8) {
1461+ let p = viz_materialize(paint);
1462+ let hue = (p & 0xFF) as f32 * 360.0 / 256.0;
1463+ let sat = f32::from(((p >> 8) & 0xFF) as u8) / 255.0;
1456 hsv_to_rgb(hue, sat, 0.84)1464 hsv_to_rgb(hue, sat, 0.84)
1457 }1465 }
1458 1466
1459 pub fn viz_strands_of(paint: u32) -> u8 {1467 pub fn viz_strands_of(paint: u32) -> u8 {
1460- match ((paint >> 16) & 0xFF) as u8 {1468+ (((viz_materialize(paint) >> 16) & 0xFF) as u8).clamp(1, 32)
1461- 0 => 8,
1462- n => n.clamp(1, 32),
1463- }
1464 }1469 }
1465 1470
1466 pub fn viz_glow_of(paint: u32) -> u8 {1471 pub fn viz_glow_of(paint: u32) -> u8 {
1467- match ((paint >> 24) & 0xFF) as u8 {1472+ ((viz_materialize(paint) >> 24) & 0xFF) as u8
1468- 0 => 2,
1469- n => n.min(16),
1470- }
1471 }1473 }
1472 1474
1473 pub fn with_viz_paint_hue(paint: u32, hue: u8) -> u32 {1475 pub fn with_viz_paint_hue(paint: u32, hue: u8) -> u32 {
1474- let sat = match (paint >> 8) & 0xFF {1476+ (viz_materialize(paint) & !0xFF) | u32::from(hue)
1475- 0 => 255,
1476- s => s,
1477- };
1478- (paint & !0xFF) | u32::from(hue) | (sat << 8)
1479 }1477 }
1480 1478
1481 pub fn with_viz_paint_sat(paint: u32, sat: u8) -> u32 {1479 pub fn with_viz_paint_sat(paint: u32, sat: u8) -> u32 {
1482- (paint & !(0xFF << 8)) | (u32::from(sat.max(1)) << 8)1480+ (viz_materialize(paint) & !(0xFF << 8)) | (u32::from(sat) << 8)
1483 }1481 }
1484 1482
1485 pub fn with_viz_paint_strands(paint: u32, n: u8) -> u32 {1483 pub fn with_viz_paint_strands(paint: u32, n: u8) -> u32 {
1486- (paint & !(0xFF << 16)) | (u32::from(n.clamp(1, 32)) << 16)1484+ (viz_materialize(paint) & !(0xFF << 16)) | (u32::from(n.clamp(1, 32)) << 16)
1487 }1485 }
1488 1486
1489 pub fn with_viz_paint_glow(paint: u32, n: u8) -> u32 {1487 pub fn with_viz_paint_glow(paint: u32, n: u8) -> u32 {
1490- (paint & !(0xFF << 24)) | (u32::from(n.min(16)) << 24)1488+ (viz_materialize(paint) & !(0xFF << 24)) | (u32::from(n.min(16)) << 24)
1491 }1489 }
1492 1490
1493 pub fn viz_hue_ui(paint: u32) -> u8 {1491 pub fn viz_hue_ui(paint: u32) -> u8 {
@@ -1615,16 +1613,29 @@ fn viz_line(
1615 ink_y: u8,1613 ink_y: u8,
1616 ink_u: u8,1614 ink_u: u8,
1617 ink_v: u8,1615 ink_v: u8,
1616+ glow: u8,
1618 ) {1617 ) {
1619 let dx = (x1 - x0).abs();1618 let dx = (x1 - x0).abs();
1620 let dy = -(y1 - y0).abs();1619 let dy = -(y1 - y0).abs();
1621 let sx = if x0 < x1 { 1 } else { -1 };1620 let sx = if x0 < x1 { 1 } else { -1 };
1622 let sy = if y0 < y1 { 1 } else { -1 };1621 let sy = if y0 < y1 { 1 } else { -1 };
1623 let mut err = dx + dy;1622 let mut err = dx + dy;
1623+ let g = i32::from(glow);
1624 loop {1624 loop {
1625- viz_stamp(y, u, v, w, h, cw, ch, x0, y0, 1.0, bg_y, ink_y, ink_u, ink_v);1625+ for oy in -g..=g {
1626- viz_stamp(y, u, v, w, h, cw, ch, x0, y0 - 1, 0.45, bg_y, ink_y, ink_u, ink_v);1626+ for ox in -g..=g {
1627- viz_stamp(y, u, v, w, h, cw, ch, x0, y0 + 1, 0.45, bg_y, ink_y, ink_u, ink_v);1627+ if ox * ox + oy * oy > g * g {
1628+ continue;
1629+ }
1630+ let fall = if ox == 0 && oy == 0 {
1631+ 1.0
1632+ } else {
1633+ let d2 = (ox * ox + oy * oy) as f32;
1634+ (-0.45 * d2 / (g * g).max(1) as f32).exp()
1635+ };
1636+ viz_stamp(y, u, v, w, h, cw, ch, x0 + ox, y0 + oy, fall, bg_y, ink_y, ink_u, ink_v);
1637+ }
1638+ }
1628 if x0 == x1 && y0 == y1 {1639 if x0 == x1 && y0 == y1 {
1629 break;1640 break;
1630 }1641 }
@@ -1748,7 +1759,7 @@ pub(crate) fn visualizer_i420(
1748 let scale = 0.28 + 0.72 * frac;1759 let scale = 0.28 + 0.72 * frac;
1749 let wave = (x_phase + travel + s as f64 * 0.05).sin() as f32;1760 let wave = (x_phase + travel + s as f64 * 0.05).sin() as f32;
1750 let row = (center + half * env * scale * wave).round() as i32;1761 let row = (center + half * env * scale * wave).round() as i32;
1751- let glow = i32::from(viz_glow_of(paint)).max(1);1762+ let glow = i32::from(viz_glow_of(paint));
1752 viz_stamp(1763 viz_stamp(
1753 &mut y, &mut u, &mut v, w, h, cw, ch, col as i32, row, 1.0, bg_y, ink_y,1764 &mut y, &mut u, &mut v, w, h, cw, ch, col as i32, row, 1.0, bg_y, ink_y,
1754 ink_u, ink_v,1765 ink_u, ink_v,
@@ -1774,11 +1785,14 @@ pub(crate) fn visualizer_i420(
1774 let amp = (w.min(h) as f32) * 0.18;1785 let amp = (w.min(h) as f32) * 0.18;
1775 let tau = std::f32::consts::TAU;1786 let tau = std::f32::consts::TAU;
1776 let steps = w.max(h) * 4;1787 let steps = w.max(h) * 4;
1777- for strand in 0..viz_strands_of(paint) {1788+ let strands = viz_strands_of(paint);
1778- let (ir, ig, ib) = viz_ink_from_paint(if strand < viz_strands_of(paint) / 2 {1789+ let glow = viz_glow_of(paint);
1779- paint1790+ for strand in 0..strands {
1780- } else {1791+ let dual = strands >= 2 && strand >= strands / 2;
1792+ let (ir, ig, ib) = viz_ink_from_paint(if dual {
1781 with_viz_paint_hue(paint, viz_hue_ui(paint).wrapping_add(128))1793 with_viz_paint_hue(paint, viz_hue_ui(paint).wrapping_add(128))
1794+ } else {
1795+ paint
1782 });1796 });
1783 let (iy, iu, iv) = rgb_yuv(ir as i32, ig as i32, ib as i32);1797 let (iy, iu, iv) = rgb_yuv(ir as i32, ig as i32, ib as i32);
1784 let scale = 0.65 + 0.35 * f32::from(strand % 4) / 3.0;1798 let scale = 0.65 + 0.35 * f32::from(strand % 4) / 3.0;
@@ -1796,6 +1810,7 @@ pub(crate) fn visualizer_i420(
1796 if let Some((px, py)) = prev {1810 if let Some((px, py)) = prev {
1797 viz_line(1811 viz_line(
1798 &mut y, &mut u, &mut v, w, h, cw, ch, px, py, x, row, bg_y, iy, iu, iv,1812 &mut y, &mut u, &mut v, w, h, cw, ch, px, py, x, row, bg_y, iy, iu, iv,
1813+ glow,
1799 );1814 );
1800 }1815 }
1801 prev = Some((x, row));1816 prev = Some((x, row));
@@ -1810,7 +1825,7 @@ pub(crate) fn visualizer_i420(
1810 if let Some((px, py)) = prev {1825 if let Some((px, py)) = prev {
1811 viz_line(1826 viz_line(
1812 &mut y, &mut u, &mut v, w, h, cw, ch, px, py, x, y_pt, bg_y, ink_y, ink_u,1827 &mut y, &mut u, &mut v, w, h, cw, ch, px, py, x, y_pt, bg_y, ink_y, ink_u,
1813- ink_v,1828+ ink_v, viz_glow_of(paint),
1814 );1829 );
1815 }1830 }
1816 prev = Some((x, y_pt));1831 prev = Some((x, y_pt));
@@ -1819,7 +1834,7 @@ pub(crate) fn visualizer_i420(
1819 _ => {1834 _ => {
1820 // Timeline envelope: one filled body, tops then bottoms, after1835 // Timeline envelope: one filled body, tops then bottoms, after
1821 // the fold+smooth above. Default look.1836 // the fold+smooth above. Default look.
1822- let glow = i32::from(viz_glow_of(paint)).max(1);1837+ let glow = i32::from(viz_glow_of(paint));
1823 for col in 0..w {1838 for col in 0..w {
1824 let top = (center - hi[col] * half).round() as i32;1839 let top = (center - hi[col] * half).round() as i32;
1825 let bot = (center - lo[col] * half).round() as i32;1840 let bot = (center - lo[col] * half).round() as i32;