forge
Explore
Log in

Don't you dare go Hollow

Timeline-smooth fill default, ring look, azure ink

Browse files at this commit

92b906fe0d80fc3574ea8c496353d96f22c0be54Ahmet Kaan GümüşParent: 70a02fb
  • feat
    • timeline-smooth fill default, ring look, azure ink
Show full message
✨ feat(audio): timeline-smooth fill default, ring look, azure ink

Default visualizer is the lane envelope (fold + smooth + fill) in
#4F8FD6, not a signed-peak scribble. CLIP adds Ring (polar strands).
Ribbon stays the linear flowing look. Colour 0 is that azure.
crates/app/src/ui/dock_stance.rsmodified+14 -8
@@ -1270,10 +1270,10 @@ fn viz_style_verbs(player: &Player, cx: &mut Context<Player>) -> impl IntoElemen
1270 .flex_col()1270 .flex_col()
1271 .gap(px(2.))1271 .gap(px(2.))
1272 .child(pick(1272 .child(pick(
1273- "dock-viz-wave",1273+ "dock-viz-fill",
1274- "Waveform",1274+ "Fill",
1275- engine::decode::VIZ_STYLE_WAVE,1275+ engine::decode::VIZ_STYLE_FILL,
1276- engine::decode::viz_style(flags) == engine::decode::VIZ_STYLE_WAVE,1276+ engine::decode::viz_style(flags) == engine::decode::VIZ_STYLE_FILL,
1277 ))1277 ))
1278 .child(pick(1278 .child(pick(
1279 "dock-viz-ribbon",1279 "dock-viz-ribbon",
@@ -1282,10 +1282,16 @@ fn viz_style_verbs(player: &Player, cx: &mut Context<Player>) -> impl IntoElemen
1282 engine::decode::viz_style(flags) == engine::decode::VIZ_STYLE_RIBBON,1282 engine::decode::viz_style(flags) == engine::decode::VIZ_STYLE_RIBBON,
1283 ))1283 ))
1284 .child(pick(1284 .child(pick(
1285- "dock-viz-fill",1285+ "dock-viz-ring",
1286- "Fill",1286+ "Ring",
1287- engine::decode::VIZ_STYLE_FILL,1287+ engine::decode::VIZ_STYLE_RING,
1288- engine::decode::viz_style(flags) == engine::decode::VIZ_STYLE_FILL,1288+ engine::decode::viz_style(flags) == engine::decode::VIZ_STYLE_RING,
1289+ ))
1290+ .child(pick(
1291+ "dock-viz-wave",
1292+ "Waveform",
1293+ engine::decode::VIZ_STYLE_WAVE,
1294+ engine::decode::viz_style(flags) == engine::decode::VIZ_STYLE_WAVE,
1289 ))1295 ))
1290 .child(bit(1296 .child(bit(
1291 "dock-viz-fast",1297 "dock-viz-fast",
crates/engine/src/decode.rsmodified+151 -53
@@ -1411,13 +1411,13 @@ fn rgb_to_i420(rgb: &[u8], width: usize, height: usize) -> (Vec<u8>, Vec<u8>, Ve
1411 pub(crate) const VIZ_BUCKETS_PER_SEC: u32 = 4000;1411 pub(crate) const VIZ_BUCKETS_PER_SEC: u32 = 4000;
1412 /// Bits 1-2: which picture this visualizer paints. Mutually exclusive —1412 /// Bits 1-2: which picture this visualizer paints. Mutually exclusive —
1413 /// a picker, not independent toggles.1413 /// a picker, not independent toggles.
1414-pub const VIZ_STYLE_WAVE: u8 = 0;1414+pub const VIZ_STYLE_FILL: u8 = 0;
1415 pub const VIZ_STYLE_RIBBON: u8 = 1;1415 pub const VIZ_STYLE_RIBBON: u8 = 1;
1416-pub const VIZ_STYLE_FILL: u8 = 2;1416+pub const VIZ_STYLE_RING: u8 = 2;
1417+pub const VIZ_STYLE_WAVE: u8 = 3;
1417 pub const VIZ_FAST: u8 = 1 << 3;1418 pub const VIZ_FAST: u8 = 1 << 3;
1418-/// High nibble of [`crate::project::Clip::visualizer`]: 16 inks. Zero is gold, then around1419+/// High nibble of [`crate::project::Clip::visualizer`]: 16 inks. Zero is the
1419-/// the wheel in 22.5° steps so a picker — not a click-cycle — chooses the1420+/// timeline azure, then around the wheel in 22.5° steps.
1420-/// strand colour.
1421 pub const VIZ_HUE_SHIFT: u8 = 4;1421 pub const VIZ_HUE_SHIFT: u8 = 4;
1422 1422
1423 /// The ink nibble stored in `flags`.1423 /// The ink nibble stored in `flags`.
@@ -1438,9 +1438,10 @@ pub fn with_viz_style(flags: u8, style: u8) -> u8 {
1438 (flags & !0b0110) | ((style & 3) << 1)1438 (flags & !0b0110) | ((style & 3) << 1)
1439 }1439 }
1440 1440
1441-/// Ink colour for the CLIP swatches and the painter. Hue 0 is gold.1441+/// Ink colour for the CLIP swatches and the painter. Hue 0 is the timeline
1442+/// azure (`0x4F8FD6`), then around the wheel.
1442 pub fn viz_ink_rgb(hue: u8) -> (u8, u8, u8) {1443 pub fn viz_ink_rgb(hue: u8) -> (u8, u8, u8) {
1443- hsv_to_rgb(48.0 + f32::from(hue & 15) * 22.5, 0.68, 0.92)1444+ hsv_to_rgb(212.0 + f32::from(hue & 15) * 22.5, 0.63, 0.84)
1444 }1445 }
1445 1446
1446 fn hsv_to_rgb(h: f32, s: f32, v: f32) -> (u8, u8, u8) {1447 fn hsv_to_rgb(h: f32, s: f32, v: f32) -> (u8, u8, u8) {
@@ -1511,6 +1512,50 @@ fn viz_stamp(
1511 }1512 }
1512 }1513 }
1513 1514
1515+fn viz_span(
1516+ y: &mut [u8],
1517+ u: &mut [u8],
1518+ v: &mut [u8],
1519+ w: usize,
1520+ h: usize,
1521+ cw: usize,
1522+ ch: usize,
1523+ x: i32,
1524+ top: i32,
1525+ bot: i32,
1526+ bg_y: u8,
1527+ ink_y: u8,
1528+ ink_u: u8,
1529+ ink_v: u8,
1530+) {
1531+ let (a, b) = if top <= bot { (top, bot) } else { (bot, top) };
1532+ for row in a..=b {
1533+ viz_stamp(y, u, v, w, h, cw, ch, x, row, 1.0, bg_y, ink_y, ink_u, ink_v);
1534+ }
1535+}
1536+
1537+fn viz_smooth(lo: &mut [f32], hi: &mut [f32]) {
1538+ let n = lo.len();
1539+ if n < 5 {
1540+ return;
1541+ }
1542+ let (src_lo, src_hi) = (lo.to_vec(), hi.to_vec());
1543+ for i in 2..n - 2 {
1544+ lo[i] = (src_lo[i - 2]
1545+ + src_lo[i - 1] * 2.0
1546+ + src_lo[i] * 3.0
1547+ + src_lo[i + 1] * 2.0
1548+ + src_lo[i + 2])
1549+ / 9.0;
1550+ hi[i] = (src_hi[i - 2]
1551+ + src_hi[i - 1] * 2.0
1552+ + src_hi[i] * 3.0
1553+ + src_hi[i + 1] * 2.0
1554+ + src_hi[i + 2])
1555+ / 9.0;
1556+ }
1557+}
1558+
1514 fn viz_line(1559 fn viz_line(
1515 y: &mut [u8],1560 y: &mut [u8],
1516 u: &mut [u8],1561 u: &mut [u8],
@@ -1609,15 +1654,34 @@ pub(crate) fn visualizer_i420(
1609 }1654 }
1610 };1655 };
1611 for col in 0..w {1656 for col in 0..w {
1657+ let a = first + (col as f64 * span / w as f64).floor() as usize;
1658+ let b = (first + (((col + 1) as f64 * span / w as f64).ceil() as usize)).min(peaks.len());
1659+ let b = b.max(a + 1);
1660+ let (mut mn, mut mx) = (0.0f32, 0.0f32);
1661+ for &(l, h) in &peaks[a.min(peaks.len() - 1)..b.min(peaks.len()).max(a.min(peaks.len() - 1) + 1)] {
1662+ mn = mn.min(l);
1663+ mx = mx.max(h);
1664+ }
1665+ lo[col] = mn.clamp(-1.0, 0.0);
1666+ hi[col] = mx.clamp(0.0, 1.0);
1612 let pos = first as f64 + (col as f64 + 0.5) * span / w as f64;1667 let pos = first as f64 + (col as f64 + 0.5) * span / w as f64;
1613 let i = pos.floor() as usize;1668 let i = pos.floor() as usize;
1614 let f = (pos - i as f64) as f32;1669 let f = (pos - i as f64) as f32;
1615- let (lo0, hi0) = pair(i);
1616- let (lo1, hi1) = pair(i.saturating_add(1));
1617- lo[col] = (lo0 + (lo1 - lo0) * f).clamp(-1.0, 0.0);
1618- hi[col] = (hi0 + (hi1 - hi0) * f).clamp(0.0, 1.0);
1619 sig[col] = signed(i) + (signed(i.saturating_add(1)) - signed(i)) * f;1670 sig[col] = signed(i) + (signed(i.saturating_add(1)) - signed(i)) * f;
1620 }1671 }
1672+ let peak = lo
1673+ .iter()
1674+ .zip(&hi)
1675+ .map(|(l, h)| l.abs().max(h.abs()))
1676+ .fold(0.0f32, f32::max);
1677+ if peak > 1e-4 {
1678+ for i in 0..w {
1679+ lo[i] /= peak;
1680+ hi[i] /= peak;
1681+ }
1682+ }
1683+ viz_smooth(&mut lo, &mut hi);
1684+ viz_smooth(&mut lo, &mut hi);
1621 }1685 }
1622 1686
1623 match viz_style(flags) {1687 match viz_style(flags) {
@@ -1625,41 +1689,60 @@ pub(crate) fn visualizer_i420(
1625 let tau = std::f64::consts::TAU;1689 let tau = std::f64::consts::TAU;
1626 let travel = t_secs * 1.35;1690 let travel = t_secs * 1.35;
1627 for col in 0..w {1691 for col in 0..w {
1628- let env = lo[col].abs().max(hi[col]).max(0.08);1692+ let env = lo[col].abs().max(hi[col]).max(0.06);
1629 let x_phase = (col as f64 / w.max(1) as f64) * 2.15 * tau;1693 let x_phase = (col as f64 / w.max(1) as f64) * 2.15 * tau;
1630- for s in 0..16 {1694+ for s in 0..24 {
1631- let frac = s as f32 / 15.0;1695+ let frac = s as f32 / 23.0;
1632- let scale = 0.32 + 0.68 * frac;1696+ let scale = 0.28 + 0.72 * frac;
1633- let wave = (x_phase + travel + s as f64 * 0.07).sin() as f32;1697+ let wave = (x_phase + travel + s as f64 * 0.05).sin() as f32;
1634 let row = (center + half * env * scale * wave).round() as i32;1698 let row = (center + half * env * scale * wave).round() as i32;
1635 viz_stamp(1699 viz_stamp(
1636 &mut y, &mut u, &mut v, w, h, cw, ch, col as i32, row, 1.0, bg_y, ink_y,1700 &mut y, &mut u, &mut v, w, h, cw, ch, col as i32, row, 1.0, bg_y, ink_y,
1637 ink_u, ink_v,1701 ink_u, ink_v,
1638 );1702 );
1639 viz_stamp(1703 viz_stamp(
1640- &mut y, &mut u, &mut v, w, h, cw, ch, col as i32, row - 1, 0.4, bg_y,1704+ &mut y, &mut u, &mut v, w, h, cw, ch, col as i32, row - 1, 0.35, bg_y,
1641 ink_y, ink_u, ink_v,1705 ink_y, ink_u, ink_v,
1642 );1706 );
1643 viz_stamp(1707 viz_stamp(
1644- &mut y, &mut u, &mut v, w, h, cw, ch, col as i32, row + 1, 0.4, bg_y,1708+ &mut y, &mut u, &mut v, w, h, cw, ch, col as i32, row + 1, 0.35, bg_y,
1645 ink_y, ink_u, ink_v,1709 ink_y, ink_u, ink_v,
1646 );1710 );
1647 }1711 }
1648 }1712 }
1649 }1713 }
1650- VIZ_STYLE_FILL => {1714+ VIZ_STYLE_RING => {
1651- for col in 0..w {1715+ let cx = w as f32 / 2.0;
1652- let top = (center - hi[col] * half).round() as i32;1716+ let cy = h as f32 / 2.0;
1653- let bot = (center - lo[col] * half).round() as i32;1717+ let r0 = (w.min(h) as f32) * 0.28;
1654- viz_line(1718+ let amp = (w.min(h) as f32) * 0.18;
1655- &mut y, &mut u, &mut v, w, h, cw, ch, col as i32, top, col as i32, bot, bg_y,1719+ let tau = std::f32::consts::TAU;
1656- ink_y, ink_u, ink_v,1720+ let steps = w.max(h) * 4;
1657- );1721+ for strand in 0..8u8 {
1722+ let (ir, ig, ib) = viz_ink_rgb(viz_hue(flags).wrapping_add(if strand < 4 { 0 } else { 8 }));
1723+ let (iy, iu, iv) = rgb_yuv(ir as i32, ig as i32, ib as i32);
1724+ let scale = 0.65 + 0.35 * f32::from(strand % 4) / 3.0;
1725+ let phase = f32::from(strand) * 0.35;
1726+ let mut prev: Option<(i32, i32)> = None;
1727+ for i in 0..=steps {
1728+ let t = i as f32 / steps as f32;
1729+ let theta = t * tau + t_secs as f32 * 1.1 + phase;
1730+ let col = ((t * w as f32) as usize).min(w.saturating_sub(1));
1731+ let env = lo[col].abs().max(hi[col]);
1732+ let wobble = (theta * 3.0 + phase).sin() * 0.12 * env;
1733+ let r = r0 + amp * env * scale + amp * wobble;
1734+ let x = (cx + r * theta.cos()).round() as i32;
1735+ let row = (cy + r * theta.sin()).round() as i32;
1736+ if let Some((px, py)) = prev {
1737+ viz_line(
1738+ &mut y, &mut u, &mut v, w, h, cw, ch, px, py, x, row, bg_y, iy, iu, iv,
1739+ );
1740+ }
1741+ prev = Some((x, row));
1742+ }
1658 }1743 }
1659 }1744 }
1660- _ => {1745+ VIZ_STYLE_WAVE => {
1661- // Signed peak of each column, connected: the Audacity trace.
1662- // Min/max bars are Fill; this is the sample path.
1663 let mut prev: Option<(i32, i32)> = None;1746 let mut prev: Option<(i32, i32)> = None;
1664 for col in 0..w {1747 for col in 0..w {
1665 let y_pt = (center - sig[col] * half).round() as i32;1748 let y_pt = (center - sig[col] * half).round() as i32;
@@ -1673,6 +1756,26 @@ pub(crate) fn visualizer_i420(
1673 prev = Some((x, y_pt));1756 prev = Some((x, y_pt));
1674 }1757 }
1675 }1758 }
1759+ _ => {
1760+ // Timeline envelope: one filled body, tops then bottoms, after
1761+ // the fold+smooth above. Default look.
1762+ for col in 0..w {
1763+ let top = (center - hi[col] * half).round() as i32;
1764+ let bot = (center - lo[col] * half).round() as i32;
1765+ viz_span(
1766+ &mut y, &mut u, &mut v, w, h, cw, ch, col as i32, top, bot, bg_y, ink_y, ink_u,
1767+ ink_v,
1768+ );
1769+ viz_stamp(
1770+ &mut y, &mut u, &mut v, w, h, cw, ch, col as i32, top - 1, 0.4, bg_y, ink_y,
1771+ ink_u, ink_v,
1772+ );
1773+ viz_stamp(
1774+ &mut y, &mut u, &mut v, w, h, cw, ch, col as i32, bot + 1, 0.4, bg_y, ink_y,
1775+ ink_u, ink_v,
1776+ );
1777+ }
1778+ }
1676 }1779 }
1677 (y, u, v)1780 (y, u, v)
1678 }1781 }
@@ -1994,45 +2097,40 @@ mod tests {
1994 }2097 }
1995 2098
1996 #[test]2099 #[test]
1997- fn visualizer_paints_a_trace_not_a_filled_block() {2100+ fn visualizer_default_is_a_blue_envelope() {
1998- // 4000 buckets/sec * 2s window around t=1.
1999 let mut peaks = vec![(0.0, 0.0); 12_000];2101 let mut peaks = vec![(0.0, 0.0); 12_000];
2000 for (i, p) in peaks.iter_mut().enumerate() {2102 for (i, p) in peaks.iter_mut().enumerate() {
2001- let a = ((i as f32 / 9.0) * std::f32::consts::TAU).sin() * 0.8;2103+ let a = ((i as f32 / 400.0) * std::f32::consts::TAU).sin() * 0.8;
2002- *p = (a.min(0.0), a.max(0.0));2104+ *p = (-a.abs(), a.abs());
2003 }2105 }
2004- let wave = 1u8;2106+ let flags = 1u8;
2005- let (y, u, v) = visualizer_i420(&peaks, 1.0, 320, 180, wave);2107+ let (y, u, v) = visualizer_i420(&peaks, 1.0, 320, 180, flags);
2006 let ink = y.iter().filter(|&&p| p > 40).count();2108 let ink = y.iter().filter(|&&p| p > 40).count();
2007- assert!(ink > 80, "trace missing: {ink} ink pixels");2109+ assert!(ink > 200, "envelope missing: {ink}");
2008- assert!(2110+ assert!(ink < y.len() * 9 / 10, "solid frame, not an envelope: {ink}");
2009- ink < y.len() / 4,2111+ let mut blue = 0usize;
2010- "filled block, not a trace: {ink}/{}",
2011- y.len()
2012- );
2013- let mut gold = 0usize;
2014 for i in 0..u.len() {2112 for i in 0..u.len() {
2015- if u[i] < 110 && v[i] > 135 {2113+ if u[i] > 145 && v[i] < 120 {
2016- gold += 1;2114+ blue += 1;
2017 }2115 }
2018 }2116 }
2019- assert!(gold > 10, "default ink was not gold: {gold}");2117+ assert!(blue > 10, "default ink was not timeline blue: {blue}");
2020 2118
2021- let fill = with_viz_style(wave, VIZ_STYLE_FILL);2119+ let ring = with_viz_style(flags, VIZ_STYLE_RING);
2022- let (yf, _, _) = visualizer_i420(&peaks, 1.0, 320, 180, fill);2120+ let (yr, _, _) = visualizer_i420(&peaks, 1.0, 320, 180, ring);
2023- let fill_ink = yf.iter().filter(|&&p| p > 40).count();2121+ let ring_ink = yr.iter().filter(|&&p| p > 40).count();
2024- assert!(fill_ink > 80, "fill missing: {fill_ink}");2122+ assert!(ring_ink > 80, "ring missing: {ring_ink}");
2123+ assert!(ring_ink < ink, "ring should be a stroke, not a fill");
2025 2124
2026- let hue = with_viz_hue(wave, 8);2125+ let hue = with_viz_hue(flags, 8);
2027 let (_, u2, v2) = visualizer_i420(&peaks, 1.0, 64, 32, hue);2126 let (_, u2, v2) = visualizer_i420(&peaks, 1.0, 64, 32, hue);
2028 let mut shifted = 0usize;2127 let mut shifted = 0usize;
2029 for i in 0..u2.len() {2128 for i in 0..u2.len() {
2030- if u2[i] > 130 && v2[i] < 120 {2129+ if u2[i] < 120 && v2[i] > 130 {
2031 shifted += 1;2130 shifted += 1;
2032 }2131 }
2033 }2132 }
2034- assert!(shifted > 2, "hue 8 did not move off gold");2133+ assert!(shifted > 2, "hue 8 did not leave blue");
2035-
2036 }2134 }
2037 }2135 }
2038 2136