forge
Explore
Log in

Don't you dare go Hollow

The waveform look carries a strand colour, and a hex/rgb door

Browse files at this commit

1973da295b701c03597741de6d62d4e03f7c1f5bAhmet Kaan GümüşParent: f93a86c
  • feat
    • the waveform look carries a strand colour, and a hex/rgb door
Show full message
✨ feat(audio): the waveform look carries a strand colour, and a hex/rgb door

viz_paint widens to one packed u64: hue/sat/strands/glow in the low bytes
exactly as v22 wrote them, the strand's own hue and sat above, and bit 63
saying the strand colour was chosen rather than left to the +128 complement.
Dialect v23. viz_color_hex/viz_color_from_text read and write the colour a
person would type. set_viz_paint_live joins its colour/transform/speed
twins so a drag is one undo step.
Cargo.lockmodified+1 -0
@@ -1669,6 +1669,7 @@ version = "0.1.0"
16691669 dependencies = [
16701670 "ec-core",
16711671 "ec-dsp",
1672+ "wide",
16721673 ]
16731674
16741675 [[package]]
crates/engine/src/decode.rsmodified+292 -23
@@ -630,7 +630,7 @@ impl DecodeSession {
630630 transform: TransformParams,
631631 canvas: Composer,
632632 flags: u8,
633- paint: u32,
633+ paint: u64,
634634 ) -> crate::Result<FrameStream> {
635635 let (tx, rx) = sync_channel(2);
636636 let cancel = Arc::new(AtomicBool::new(false));
@@ -1447,9 +1447,18 @@ pub fn viz_ink_rgb(hue: u8) -> (u8, u8, u8) {
14471447 }
14481448
14491449 /// 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+pub const VIZ_PAINT_AZURE: u64 = 150 | (160 << 8) | (8 << 16) | (2 << 24);
1451+
1452+/// Where the strand colour sits above the clip's own four bytes: hue at 32
1453+/// and sat at 40, with bit 63 as the flag that says a clip chose one
1454+/// ([`viz_strand_set`]). A clear flag means the automatic complement the
1455+/// ring has always painted -- so a v22 value, whose top half is empty, is
1456+/// nothing new.
1457+const VIZ_STRAND_HUE_SHIFT: u32 = 32;
1458+const VIZ_STRAND_SAT_SHIFT: u32 = 40;
1459+const VIZ_STRAND_CHOSEN: u64 = 1 << 63;
1460+
1461+pub fn viz_materialize(paint: u64) -> u64 {
14531462 if paint == 0 {
14541463 VIZ_PAINT_AZURE
14551464 } else {
@@ -1457,42 +1466,42 @@ pub fn viz_materialize(paint: u32) -> u32 {
14571466 }
14581467 }
14591468
1460-pub fn viz_ink_from_paint(paint: u32) -> (u8, u8, u8) {
1469+pub fn viz_ink_from_paint(paint: u64) -> (u8, u8, u8) {
14611470 let p = viz_materialize(paint);
14621471 let hue = (p & 0xFF) as f32 * 360.0 / 256.0;
14631472 let sat = f32::from(((p >> 8) & 0xFF) as u8) / 255.0;
14641473 hsv_to_rgb(hue, sat, 0.84)
14651474 }
14661475
1467-pub fn viz_strands_of(paint: u32) -> u8 {
1476+pub fn viz_strands_of(paint: u64) -> u8 {
14681477 (((viz_materialize(paint) >> 16) & 0xFF) as u8).clamp(1, 32)
14691478 }
14701479
1471-pub fn viz_glow_of(paint: u32) -> u8 {
1480+pub fn viz_glow_of(paint: u64) -> u8 {
14721481 ((viz_materialize(paint) >> 24) & 0xFF) as u8
14731482 }
14741483
1475-pub fn with_viz_paint_hue(paint: u32, hue: u8) -> u32 {
1476- (viz_materialize(paint) & !0xFF) | u32::from(hue)
1484+pub fn with_viz_paint_hue(paint: u64, hue: u8) -> u64 {
1485+ (viz_materialize(paint) & !0xFF) | u64::from(hue)
14771486 }
14781487
1479-pub fn with_viz_paint_sat(paint: u32, sat: u8) -> u32 {
1480- (viz_materialize(paint) & !(0xFF << 8)) | (u32::from(sat) << 8)
1488+pub fn with_viz_paint_sat(paint: u64, sat: u8) -> u64 {
1489+ (viz_materialize(paint) & !(0xFF << 8)) | (u64::from(sat) << 8)
14811490 }
14821491
1483-pub fn with_viz_paint_strands(paint: u32, n: u8) -> u32 {
1484- (viz_materialize(paint) & !(0xFF << 16)) | (u32::from(n.clamp(1, 32)) << 16)
1492+pub fn with_viz_paint_strands(paint: u64, n: u8) -> u64 {
1493+ (viz_materialize(paint) & !(0xFF << 16)) | (u64::from(n.clamp(1, 32)) << 16)
14851494 }
14861495
1487-pub fn with_viz_paint_glow(paint: u32, n: u8) -> u32 {
1488- (viz_materialize(paint) & !(0xFF << 24)) | (u32::from(n.min(16)) << 24)
1496+pub fn with_viz_paint_glow(paint: u64, n: u8) -> u64 {
1497+ (viz_materialize(paint) & !(0xFF << 24)) | (u64::from(n.min(16)) << 24)
14891498 }
14901499
1491-pub fn viz_hue_ui(paint: u32) -> u8 {
1500+pub fn viz_hue_ui(paint: u64) -> u8 {
14921501 if paint == 0 { 150 } else { (paint & 0xFF) as u8 }
14931502 }
14941503
1495-pub fn viz_sat_ui(paint: u32) -> u8 {
1504+pub fn viz_sat_ui(paint: u64) -> u8 {
14961505 if paint == 0 {
14971506 160
14981507 } else {
@@ -1503,6 +1512,135 @@ pub fn viz_sat_ui(paint: u32) -> u8 {
15031512 }
15041513 }
15051514
1515+/// Whether the clip chose a strand colour of its own (the top bit), rather
1516+/// than taking the automatic complement a ring's dual half has always
1517+/// painted.
1518+pub fn viz_strand_set(paint: u64) -> bool {
1519+ paint & VIZ_STRAND_CHOSEN != 0
1520+}
1521+
1522+/// The chosen strand hue, 0-255 on the wheel [`viz_hue_ui`] reads.
1523+pub fn viz_strand_hue_ui(paint: u64) -> u8 {
1524+ ((paint >> VIZ_STRAND_HUE_SHIFT) & 0xFF) as u8
1525+}
1526+
1527+/// The chosen strand sat, 0-255. A stored zero stays zero here, unlike
1528+/// [`viz_sat_ui`]'s: a grey strand is a colour someone picked, and the flag
1529+/// -- not the byte -- is what says whether there is one.
1530+pub fn viz_strand_sat_ui(paint: u64) -> u8 {
1531+ ((paint >> VIZ_STRAND_SAT_SHIFT) & 0xFF) as u8
1532+}
1533+
1534+/// Set the strand hue and mark the colour chosen, so a ring's dual half
1535+/// inks it instead of the automatic complement.
1536+pub fn with_viz_paint_strand_hue(paint: u64, hue: u8) -> u64 {
1537+ let p = viz_materialize(paint) & !(0xFF_u64 << VIZ_STRAND_HUE_SHIFT);
1538+ (p | (u64::from(hue) << VIZ_STRAND_HUE_SHIFT)) | VIZ_STRAND_CHOSEN
1539+}
1540+
1541+/// Set the strand sat and mark the colour chosen, as
1542+/// [`with_viz_paint_strand_hue`] does.
1543+pub fn with_viz_paint_strand_sat(paint: u64, sat: u8) -> u64 {
1544+ let p = viz_materialize(paint) & !(0xFF_u64 << VIZ_STRAND_SAT_SHIFT);
1545+ (p | (u64::from(sat) << VIZ_STRAND_SAT_SHIFT)) | VIZ_STRAND_CHOSEN
1546+}
1547+
1548+/// Drop the chosen strand colour: the dual half of a ring goes back to the
1549+/// automatic complement, and both strand bytes go with the flag.
1550+pub fn viz_strand_clear(paint: u64) -> u64 {
1551+ paint & !(VIZ_STRAND_CHOSEN
1552+ | (0xFF_u64 << VIZ_STRAND_HUE_SHIFT)
1553+ | (0xFF_u64 << VIZ_STRAND_SAT_SHIFT))
1554+}
1555+
1556+/// `#RRGGBB` for an ink, at the same fixed value the painter draws at, so
1557+/// the swatch a front-end shows is the colour that reaches the picture.
1558+/// The inverse of [`viz_color_from_text`] for the colours a round trip
1559+/// through bytes can carry back.
1560+pub fn viz_color_hex(hue: u8, sat: u8) -> String {
1561+ let (r, g, b) = hsv_to_rgb(f32::from(hue) * 360.0 / 256.0, f32::from(sat) / 255.0, 0.84);
1562+ format!("#{r:02X}{g:02X}{b:02X}")
1563+}
1564+
1565+/// A colour someone typed -- `#4F8FD6`, `4f8fd6`, `rgb(79,143,214)` or
1566+/// `rgba(79,143,214,255)`, any case, commas or `/` between the channels,
1567+/// alpha ignored -- as the `(hue, sat)` pair the sliders and the paint
1568+/// field speak. `None` for everything else rather than a guess: the wrong
1569+/// number of digits, a channel outside 0-255, parentheses missing.
1570+///
1571+/// Brightness is dropped, not carried: the painter draws every ink at its
1572+/// own fixed value, so a typed colour is kept by its hue and saturation.
1573+pub fn viz_color_from_text(text: &str) -> Option<(u8, u8)> {
1574+ let t = text.trim();
1575+ let (r, g, b) = if let Some(inner) = t.strip_suffix(')') {
1576+ let body = if starts_ci(inner, b"rgb(") {
1577+ &inner[4..]
1578+ } else if starts_ci(inner, b"rgba(") {
1579+ &inner[5..]
1580+ } else {
1581+ return None;
1582+ };
1583+ let mut channels = body.split(['/', ',']).map(str::trim);
1584+ let r = channel(channels.next()?)?;
1585+ let g = channel(channels.next()?)?;
1586+ let b = channel(channels.next()?)?;
1587+ // Alpha, when it is spelled: read so a bad one is refused like a
1588+ // channel is, and dropped -- the paint field has no room for it.
1589+ if let Some(a) = channels.next() {
1590+ channel(a)?;
1591+ }
1592+ if channels.next().is_some() {
1593+ return None;
1594+ }
1595+ (r, g, b)
1596+ } else {
1597+ let hex = t.strip_prefix('#').unwrap_or(t);
1598+ if hex.len() != 6 || !hex.bytes().all(|c| c.is_ascii_hexdigit()) {
1599+ return None;
1600+ }
1601+ (
1602+ u8::from_str_radix(&hex[0..2], 16).ok()?,
1603+ u8::from_str_radix(&hex[2..4], 16).ok()?,
1604+ u8::from_str_radix(&hex[4..6], 16).ok()?,
1605+ )
1606+ };
1607+ Some(rgb_to_hue_sat(r, g, b))
1608+}
1609+
1610+fn starts_ci(text: &str, prefix: &[u8]) -> bool {
1611+ text.len() >= prefix.len() && text.as_bytes()[..prefix.len()].eq_ignore_ascii_case(prefix)
1612+}
1613+
1614+/// One 0-255 channel of a typed colour: digits only, so neither a sign nor
1615+/// an exponent slips in the way `u8`'s own parse would take them.
1616+fn channel(text: &str) -> Option<u8> {
1617+ if text.is_empty() || !text.bytes().all(|b| b.is_ascii_digit()) {
1618+ return None;
1619+ }
1620+ text.parse().ok()
1621+}
1622+
1623+/// What a byte RGB is on the paint field's wheel: hue on [`viz_hue_ui`]'s
1624+/// 0-255 scale, sat 0-255, brightness dropped for the same reason
1625+/// [`viz_color_from_text`] drops the typed one.
1626+fn rgb_to_hue_sat(r: u8, g: u8, b: u8) -> (u8, u8) {
1627+ let (r, g, b) = (f32::from(r), f32::from(g), f32::from(b));
1628+ let (max, min) = (r.max(g).max(b), r.min(g).min(b));
1629+ let delta = max - min;
1630+ let hue = if delta == 0.0 {
1631+ 0.0
1632+ } else if max == r {
1633+ 60.0 * ((g - b) / delta).rem_euclid(6.0)
1634+ } else if max == g {
1635+ 60.0 * ((b - r) / delta + 2.0)
1636+ } else {
1637+ 60.0 * ((r - g) / delta + 4.0)
1638+ };
1639+ let hue = ((hue * 256.0 / 360.0).round() as i64).rem_euclid(256) as u8;
1640+ let sat = if max == 0.0 { 0.0 } else { delta / max };
1641+ (hue, (sat * 255.0).round() as u8)
1642+}
1643+
15061644 pub fn viz_hsv_rgb(h: f32, s: f32, v: f32) -> (u8, u8, u8) {
15071645 hsv_to_rgb(h, s, v)
15081646 }
@@ -1654,14 +1792,14 @@ fn viz_line(
16541792 /// One visualizer picture in tightly packed I420. Three looks, picked by
16551793 /// [`viz_style`]: a bipolar sample trace (Audacity), a filled min/max
16561794 /// envelope at pixel resolution, or a multi-strand ribbon. Ink is
1657-/// [`viz_ink_rgb`]. A frame always exists; silence is the zero line.
1795+/// [`viz_ink_from_paint`]. A frame always exists; silence is the zero line.
16581796 pub(crate) fn visualizer_i420(
16591797 peaks: &[(f32, f32)],
16601798 t_secs: f64,
16611799 width: u32,
16621800 height: u32,
16631801 flags: u8,
1664- paint: u32,
1802+ paint: u64,
16651803 ) -> (Vec<u8>, Vec<u8>, Vec<u8>) {
16661804 let width = width & !1;
16671805 let height = height & !1;
@@ -1789,11 +1927,22 @@ pub(crate) fn visualizer_i420(
17891927 let glow = viz_glow_of(paint);
17901928 for strand in 0..strands {
17911929 let dual = strands >= 2 && strand >= strands / 2;
1792- let (ir, ig, ib) = viz_ink_from_paint(if dual {
1793- with_viz_paint_hue(paint, viz_hue_ui(paint).wrapping_add(128))
1930+ // The dual half takes the clip's own strand colour when it
1931+ // chose one; without one it is the wheel half a turn from
1932+ // the clip's hue, at the clip's own saturation, which is
1933+ // the complement every earlier project paints.
1934+ let (ir, ig, ib) = if dual && viz_strand_set(paint) {
1935+ let hue = f32::from(viz_strand_hue_ui(paint)) * 360.0 / 256.0;
1936+ let sat = f32::from(viz_strand_sat_ui(paint)) / 255.0;
1937+ hsv_to_rgb(hue, sat, 0.84)
1938+ } else if dual {
1939+ viz_ink_from_paint(with_viz_paint_hue(
1940+ paint,
1941+ viz_hue_ui(paint).wrapping_add(128),
1942+ ))
17941943 } else {
1795- paint
1796- });
1944+ viz_ink_from_paint(paint)
1945+ };
17971946 let (iy, iu, iv) = rgb_yuv(ir as i32, ig as i32, ib as i32);
17981947 let scale = 0.65 + 0.35 * f32::from(strand % 4) / 3.0;
17991948 let phase = f32::from(strand) * 0.35;
@@ -2211,6 +2360,126 @@ mod tests {
22112360 }
22122361 assert!(shifted > 2, "hue 8 did not leave blue");
22132362 }
2363+
2364+ /// The paint's byte layout: the strand colour lives above the clip's own
2365+ /// four bytes and the top bit is the flag, so either strand setter marks
2366+ /// the colour chosen and clearing drops both bytes with the flag.
2367+ #[test]
2368+ fn the_paint_packs_the_strand_colour_above_the_v22_halves() {
2369+ let p = with_viz_paint_strand_sat(with_viz_paint_strand_hue(VIZ_PAINT_AZURE, 0xAB), 0xCD);
2370+ assert_eq!(p & 0xFFFF_FFFF, VIZ_PAINT_AZURE, "the low half never moves");
2371+ assert_eq!((p >> 32) & 0xFF, 0xAB);
2372+ assert_eq!((p >> 40) & 0xFF, 0xCD);
2373+ assert!(viz_strand_set(p));
2374+ assert_eq!(viz_strand_hue_ui(p), 0xAB);
2375+ assert_eq!(viz_strand_sat_ui(p), 0xCD);
2376+ assert_eq!(viz_strand_clear(p), VIZ_PAINT_AZURE);
2377+ assert!(!viz_strand_set(viz_strand_clear(p)));
2378+ }
2379+
2380+ /// The shapes a colour is typed in all mean the same ink, and everything
2381+ /// else is refused rather than guessed at.
2382+ #[test]
2383+ fn typed_colours_read_as_hex_rgb_and_rgba() {
2384+ let want = viz_color_from_text("#4F8FD6").expect("a hex colour");
2385+ assert_eq!(want, (150, 161), "hue and sat on the field's own scales");
2386+ for text in [
2387+ "#4F8FD6",
2388+ "4f8fd6",
2389+ " #4f8fd6 ",
2390+ "rgb(79,143,214)",
2391+ "rgb(79/143/214)",
2392+ "RGBA(79, 143, 214, 255)",
2393+ ] {
2394+ assert_eq!(viz_color_from_text(text), Some(want), "{text}");
2395+ }
2396+ for text in [
2397+ "#12345",
2398+ "zz",
2399+ "rgb(300,0,0)",
2400+ "rgb(1,2)",
2401+ "",
2402+ "rgb 79,143,214)",
2403+ "rgb(79,143,214",
2404+ "#4F8FD",
2405+ "#4F8FD67",
2406+ "#GGGGGG",
2407+ "rgb(79,143,214,255,0)",
2408+ "rgb(79;143;214)",
2409+ ] {
2410+ assert_eq!(viz_color_from_text(text), None, "{text}");
2411+ }
2412+ }
2413+
2414+ /// A colour's hex is the ink the painter draws, and reading it back
2415+ /// gives the sliders their own value again -- for the 47053 of the 65536
2416+ /// hues and saturations a trip through bytes can carry. The rest land on
2417+ /// a neighbour: their smallest channel rounds to a byte whose ratio is
2418+ /// not the one that was asked for. Full saturation is where that channel
2419+ /// is the one the value sets exactly, and it survives at every hue.
2420+ #[test]
2421+ fn a_sampled_palette_round_trips_through_its_hex() {
2422+ for hue in (0..=255u8).step_by(8) {
2423+ let hex = viz_color_hex(hue, 255);
2424+ assert_eq!(viz_color_from_text(&hex), Some((hue, 255)), "{hex}");
2425+ }
2426+ // The achromatic end, where hue is not a colour at all.
2427+ assert_eq!(viz_color_from_text(&viz_color_hex(0, 0)), Some((0, 0)));
2428+ assert_eq!(viz_color_from_text(&viz_color_hex(200, 0)), Some((0, 0)));
2429+ // ...and the whole grid, so a change that quietly shrinks what the
2430+ // trip can carry cannot pass by leaving the sample above green.
2431+ let exact = (0..=255u8)
2432+ .flat_map(|hue| (0..=255u8).map(move |sat| (hue, sat)))
2433+ .filter(|&(hue, sat)| viz_color_from_text(&viz_color_hex(hue, sat)) == Some((hue, sat)))
2434+ .count();
2435+ assert_eq!(exact, 47_053, "the colours a hex round trip keeps");
2436+ }
2437+
2438+ /// The dual half of a ring takes the clip's own strand colour when it has
2439+ /// one: a choice that names the automatic complement paints the same
2440+ /// frame, another repaints the dual strands in it, and a paint whose flag
2441+ /// is clear is the picture it has always been -- strand bytes or no.
2442+ #[test]
2443+ fn a_chosen_strand_colour_repaints_only_the_dual_half_of_a_ring() {
2444+ let mut peaks = vec![(0.0, 0.0); 12_000];
2445+ for (i, p) in peaks.iter_mut().enumerate() {
2446+ let a = ((i as f32 / 400.0) * std::f32::consts::TAU).sin() * 0.8;
2447+ *p = (-a.abs(), a.abs());
2448+ }
2449+ let ring = with_viz_style(1, VIZ_STYLE_RING);
2450+ let auto = VIZ_PAINT_AZURE;
2451+ let (y0, u0, v0) = visualizer_i420(&peaks, 1.0, 320, 180, ring, auto);
2452+
2453+ // The automatic dual is half a wheel from the clip's hue at the
2454+ // clip's own saturation; choosing exactly that colour changes
2455+ // nothing at all.
2456+ let same = with_viz_paint_strand_sat(
2457+ with_viz_paint_strand_hue(auto, viz_hue_ui(auto).wrapping_add(128)),
2458+ viz_sat_ui(auto),
2459+ );
2460+ assert!(viz_strand_set(same));
2461+ let (ys, us, vs) = visualizer_i420(&peaks, 1.0, 320, 180, ring, same);
2462+ assert_eq!(ys, y0, "the automatic complement, spelled out, is the same frame");
2463+ assert_eq!(us, u0);
2464+ assert_eq!(vs, v0);
2465+
2466+ // A colour of its own repaints the dual strands in it.
2467+ let red = with_viz_paint_strand_sat(with_viz_paint_strand_hue(auto, 0), 255);
2468+ let (_, u1, v1) = visualizer_i420(&peaks, 1.0, 320, 180, ring, red);
2469+ let red_px = (0..u1.len()).filter(|&i| u1[i] < 110 && v1[i] > 200).count();
2470+ let auto_px = (0..u0.len()).filter(|&i| u0[i] < 110 && v0[i] > 200).count();
2471+ assert!(red_px > 20, "the chosen colour did not reach the frame: {red_px}");
2472+ assert_eq!(auto_px, 0, "the automatic ring already painted red: {auto_px}");
2473+
2474+ // ...and the flag is what decides: strand bytes with it clear are
2475+ // the unset picture, byte for byte.
2476+ let stale = auto | (77u64 << 32) | (9u64 << 40);
2477+ assert!(!viz_strand_set(stale));
2478+ let (yt, ut, vt) = visualizer_i420(&peaks, 1.0, 320, 180, ring, stale);
2479+ assert_eq!(yt, y0, "an unset strand colour is the frame it always was");
2480+ assert_eq!(ut, u0);
2481+ assert_eq!(vt, v0);
2482+ }
22142483 }
22152484
22162485 fn run(
crates/engine/src/edith.rsmodified+96 -25
@@ -134,9 +134,12 @@
134134 //! ([`crate::project::Clip::transition_out`], `0` for a hard cut), and last of
135135 //! all the transform line it is placed, sized, turned and cropped by, on top
136136 //! of everything its fit policy already did (`-` for a clip left at its fit
137-//! policy's own spot, [`crate::project::Clip::transform`]), and a visualizer
137+//! policy's own spot, [`crate::project::Clip::transform`]), a visualizer
138138 //! flags byte (`0` for an ordinary picture, bit 0 for a waveform of the
139-//! source's sound, the rest outline/smooth/fast/tint).
139+//! source's sound, the rest outline/smooth/fast/tint) and that waveform's
140+//! packed look ([`crate::project::Clip::viz_paint`]): hue, sat, strands and
141+//! glow in the low four bytes, then the strand colour's own hue and sat,
142+//! with the top bit set once a clip has chosen one.
140143 //! Timeline placement is
141144 //! explicit, so a *gap* is simply a stretch no line covers -- there is nothing
142145 //! to write for one, and nothing that can disagree about its length. The `<in>`
@@ -162,6 +165,9 @@
162165 //! track 3 of a two-track palette is refused here, as a clip naming a source
163166 //! that is not there is.
164167 //!
168+//! **Version 22** was this with a 32-bit packed look: such a project's clips
169+//! chose no strand colour, which is what the top bit still clear means, and
170+//! their value is the low half of the one v23 writes.
165171 //! **Version 19** was this without the clip's transform field: such a project
166172 //! places no clip anywhere but its fit policy's own spot, which is what `-`
167173 //! still means. **Version 18** was that without the clip's transition field:
@@ -205,7 +211,7 @@
205211 //! nothing, and an older one plays everything at real time, and an older one
206212 //! mixes flat, and an older one shows no subtitles, and an older one is shown
207213 //! in the reference rendition, and an older one places none of the words it
208-//! names -- and saving any of them writes v22. An older
214+//! names -- and saving any of them writes v23. An older
209215 //! reader refuses a newer file by name.
210216 //!
211217 //! Text because an edit list is a few integers and a path, and a path is
@@ -242,7 +248,8 @@ use crate::transform::TransformParams;
242248
243249 /// What [`save`] writes. Read support goes back to `edith 1`; see the module
244250 /// docs for what those dialects looked like.
245-const MAGIC: &[u8] = b"edith 22";
251+const MAGIC: &[u8] = b"edith 23";
252+const MAGIC_V22: &[u8] = b"edith 22";
246253 const MAGIC_V21: &[u8] = b"edith 21";
247254 const MAGIC_V20: &[u8] = b"edith 20";
248255 const MAGIC_V19: &[u8] = b"edith 19";
@@ -650,8 +657,11 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> {
650657 // The dialects that wrote a source line without its stream field. Reading
651658 // one is the whole of what "an old project still opens" means here.
652659 let streamless = v1 || first == MAGIC_V2;
660+ // The one that carries a strand colour of its own above the packed
661+ // visualizer paint (hue/sat, with the top bit as the flag)...
662+ let v23 = first == MAGIC;
653663 // The one that carries packed visualizer paint (hue/sat/strands/glow)...
654- let v22 = first == MAGIC;
664+ let v22 = v23 || first == MAGIC_V22;
655665 // The one that carries per-clip visualizer flags...
656666 let v21 = v22 || first == MAGIC_V21;
657667 // The one that carries a per-clip transform (position/scale/rotate/crop)...
@@ -1206,7 +1216,7 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> {
12061216 fade_out: number(f.get(10).copied().unwrap_or(b"0"), n)?.min(frames),
12071217 transition_out: number(f.get(11).copied().unwrap_or(b"0"), n)?.min(frames),
12081218 visualizer: number(f.get(13).copied().unwrap_or(b"0"), n)? as u8,
1209- viz_paint: number(f.get(14).copied().unwrap_or(b"0"), n)? as u32,
1219+ viz_paint: number64(f.get(14).copied().unwrap_or(b"0"), n)?,
12101220 start: number(f[0], n)?,
12111221 in_frame,
12121222 out_frame,
@@ -1473,6 +1483,19 @@ fn number(field: &[u8], line: usize) -> crate::Result<u32> {
14731483 }
14741484 }
14751485
1486+/// [`number`] for the one field wider than a `u32`: the clip's packed
1487+/// visualizer look, whose strand-colour half needs the width (v23).
1488+fn number64(field: &[u8], line: usize) -> crate::Result<u64> {
1489+ match std::str::from_utf8(field).ok().and_then(|s| s.parse().ok()) {
1490+ Some(n) => Ok(n),
1491+ None => Err(format!(
1492+ "line {line}: {:?} is not a number",
1493+ String::from_utf8_lossy(field)
1494+ )
1495+ .into()),
1496+ }
1497+}
1498+
14761499 /// A `sub` line's window field: microseconds, which is the clock a cue is timed
14771500 /// in ([`crate::subtitle::Cue`]) and the one thing in this format counted in
14781501 /// something other than frames. Signed as the cues are, and the negative half
@@ -1636,7 +1659,7 @@ mod tests {
16361659 video 1 0 0 30 0 - - - fit 1000\n";
16371660 let old = parse(v9, &dir).expect("v9 still loads");
16381661 assert_eq!(old.subtitles, Vec::new());
1639- assert!(flat(&dir, &old.sources, &old.lanes, old.playhead).starts_with(b"edith 22\n"));
1662+ assert!(flat(&dir, &old.sources, &old.lanes, old.playhead).starts_with(b"edith 23\n"));
16401663 // ...and the line itself is not a v9 line: a dialect may not be mixed.
16411664 let mixed = parse(b"edith 9\nsource 0 a.mp4\nsubtitle - subs.srt\n", &dir)
16421665 .unwrap_err()
@@ -2116,7 +2139,7 @@ mod tests {
21162139 let bytes = flat(&dir, &sources, &lanes, 12);
21172140 assert_eq!(
21182141 String::from_utf8_lossy(&bytes),
2119- "edith 22\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\
2142+ "edith 23\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\
21202143 source 2 /elsewhere/b.mp4\n\
21212144 video 1 0 0 30 0 0 - - fit 1000 0 0 0 - 0 0\nvideo 1 30 10 20 1 1 - - fit 1000 0 0 0 - 0 0\n\
21222145 audio 1 0 0 30 0 0 - - fit 1000 0 0 0 - 0 0\n",
@@ -2153,7 +2176,7 @@ mod tests {
21532176 let bytes = flat(&dir, &sources, &lanes, 7);
21542177 assert_eq!(
21552178 String::from_utf8_lossy(&bytes),
2156- "edith 22\nplayhead 7\nresolution 1280 720\nsource 0 a.mp4\n\
2179+ "edith 23\nplayhead 7\nresolution 1280 720\nsource 0 a.mp4\n\
21572180 video 1 0 0 30 0 4 - - fit 1000 0 0 0 - 0 0\naudio 1\n\
21582181 video 2 40 0 10 0 - - - fit 1000 0 0 0 - 0 0\naudio 2 0 0 30 0 4 - - fit 1000 0 0 0 - 0 0\n",
21592182 "an empty lane is a line of its own; everything else is its clips"
@@ -2281,7 +2304,7 @@ mod tests {
22812304 let bytes = emit(&dir, &sources, &lanes, &eq, &[], (1280, 720), 0);
22822305 assert_eq!(
22832306 String::from_utf8_lossy(&bytes),
2284- "edith 22\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\
2307+ "edith 23\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\
22852308 eq 80.0:-3.0:0.707:ls 1000.0:4.5:1.0:pk\n\
22862309 eq 16777215.0:-0.1:3.918315e-39:hs\n\
22872310 eq\n\
@@ -2405,7 +2428,7 @@ mod tests {
24052428 let bytes = emit(&dir, &sources, &lanes, &[], &color, (1280, 720), 0);
24062429 assert_eq!(
24072430 String::from_utf8_lossy(&bytes),
2408- "edith 22\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\
2431+ "edith 23\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\
24092432 color 0.1:1.2:0.9:-0.3\n\
24102433 color -1e-7:16777215.0:3.918315e-39:-0.0\n\
24112434 color 0.0:1.0:1.0:0.0\n\
@@ -2470,7 +2493,7 @@ mod tests {
24702493 (1280, 720),
24712494 old.playhead
24722495 )),
2473- "edith 22\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\
2496+ "edith 23\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\
24742497 eq 80.0:-3.0:0.707:ls\n\
24752498 video 1 0 0 30 0 0 0 - fit 1000 0 0 0 - 0 0\naudio 1 0 0 30 0 0 - - fit 1000 0 0 0 - 0 0\n"
24762499 );
@@ -2514,7 +2537,7 @@ mod tests {
25142537 let bytes = emit(&dir, &sources, &lanes, &[], &[], (1280, 720), 0);
25152538 assert_eq!(
25162539 String::from_utf8_lossy(&bytes),
2517- "edith 22\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\
2540+ "edith 23\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\
25182541 video 1 0 0 30 0 - - - fit 2000 0 0 0 - 0 0\nvideo 1 15 30 40 0 - - - fit 250 0 0 0 - 0 0\n\
25192542 audio 1 0 0 30 0 - - - fit 2000 0 0 0 - 0 0\n",
25202543 "the rate is the clip line's last field, in thousandths"
@@ -2543,7 +2566,7 @@ mod tests {
25432566 (1280, 720),
25442567 old.playhead
25452568 )),
2546- "edith 22\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\
2569+ "edith 23\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\
25472570 video 1 0 0 30 0 0 - - fit 1000 0 0 0 - 0 0\naudio 1 0 0 30 0 0 - - fit 1000 0 0 0 - 0 0\n"
25482571 );
25492572 // A rate outside what the editor can set is a corrupt line, by name.
@@ -2594,7 +2617,7 @@ mod tests {
25942617 let bytes = emit(&dir, &sources, &lanes, &[], &[], (1280, 720), 0);
25952618 assert_eq!(
25962619 String::from_utf8_lossy(&bytes),
2597- "edith 22\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\
2620+ "edith 23\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\
25982621 video 1 0 0 30 0 - - - fit 1000 5 7 0 - 0 0\n",
25992622 "the fades are the clip line's last two fields"
26002623 );
@@ -2647,7 +2670,7 @@ mod tests {
26472670 let bytes = emit(&dir, &sources, &lanes, &[], &[], (1280, 720), 0);
26482671 assert_eq!(
26492672 String::from_utf8_lossy(&bytes),
2650- "edith 22\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\
2673+ "edith 23\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\
26512674 video 1 0 0 30 0 - - - fit 1000 0 0 9 - 0 0\n",
26522675 "the dissolve is the clip line's own last field"
26532676 );
@@ -2658,6 +2681,54 @@ mod tests {
26582681 );
26592682 }
26602683
2684+ /// The clip's packed look (v23): a chosen strand colour rides in the
2685+ /// field's own bytes under the top bit and comes back bit-exact, a v22
2686+ /// file's 32-bit value is the low half of that field with no strand
2687+ /// colour, and a file older than the field itself is the zero it always
2688+ /// was.
2689+ #[test]
2690+ fn a_strand_colour_round_trips_and_a_v22_look_stays_32_bit() {
2691+ use crate::decode::{
2692+ viz_hue_ui, viz_sat_ui, viz_strand_set, with_viz_paint_strand_hue,
2693+ with_viz_paint_strand_sat, VIZ_PAINT_AZURE,
2694+ };
2695+ let (dir, sources, lanes) = doc();
2696+ let mut painted = lanes.clone();
2697+ // Azure, its dual half a chosen green rather than the automatic
2698+ // complement of the clip's own hue.
2699+ let chosen = with_viz_paint_strand_sat(with_viz_paint_strand_hue(VIZ_PAINT_AZURE, 64), 200);
2700+ assert!(viz_strand_set(chosen));
2701+ painted[0].1[0].viz_paint = chosen;
2702+ let bytes = flat(&dir, &sources, &painted, 0);
2703+ assert!(
2704+ bytes.starts_with(b"edith 23\n"),
2705+ "a project with a strand colour saves as v23: {}",
2706+ String::from_utf8_lossy(&bytes)
2707+ );
2708+ let back = parse(&bytes, &dir).expect("v23 parses");
2709+ assert_eq!(back.lanes, painted, "the look round-trips bit-exactly");
2710+
2711+ // A v22 file's field is a u32: the value lands in the low half
2712+ // untouched, and a strand colour it cannot carry reads as auto.
2713+ let look = VIZ_PAINT_AZURE as u32;
2714+ let v22 = format!(
2715+ "edith 22\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\
2716+ video 1 0 0 30 0 0 - - fit 1000 0 0 0 - 0 {look}\n"
2717+ );
2718+ let old = parse(v22.as_bytes(), &dir).expect("v22 still loads");
2719+ let paint = old.lanes[0].1[0].viz_paint;
2720+ assert_eq!(paint, u64::from(look), "the low half is the v22 value");
2721+ assert!(!viz_strand_set(paint), "a v22 look chose no strand colour");
2722+ assert_eq!(viz_hue_ui(paint), 150);
2723+ assert_eq!(viz_sat_ui(paint), 160);
2724+ // ...and a file older than the field is the zero that means the
2725+ // azure default, as it was before the field was widened.
2726+ let v21 = b"edith 21\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\
2727+ video 1 0 0 30 0 0 - - fit 1000 0 0 0 - 0\n";
2728+ let older = parse(v21, &dir).expect("v21 still loads");
2729+ assert_eq!(older.lanes[0].1[0].viz_paint, 0);
2730+ }
2731+
26612732 /// A v19 file is a v20 one that places no clip anywhere but its fit
26622733 /// policy's own spot: it loads with every clip's [`Clip::transform`] at
26632734 /// `None`, which is what a v19 file's missing field still means.
@@ -2785,7 +2856,7 @@ mod tests {
27852856 );
27862857 assert_eq!(
27872858 String::from_utf8_lossy(&bytes),
2788- "edith 22\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\
2859+ "edith 23\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\
27892860 transform 0.1:-0.2:1.5:90.0:0.1:0.0:0.0:0.05\n\
27902861 transform -1e-7:16777215.0:3.918315e-39:-0.0:0.0:0.0:0.0:0.0\n\
27912862 transform 0.0:0.0:1.0:0.0:0.0:0.0:0.0:0.0\n\
@@ -2865,7 +2936,7 @@ mod tests {
28652936 );
28662937 assert_eq!(
28672938 String::from_utf8_lossy(&bytes),
2868- "edith 22\nplayhead 0\nresolution 1280 720\nfps 23.976023976023978\n\
2939+ "edith 23\nplayhead 0\nresolution 1280 720\nfps 23.976023976023978\n\
28692940 limiter -1.5 on\nsource 0 a.mp4\n\
28702941 video 1 0 0 30 0 - - - fit 1000 0 0 0 - 0 0\naudio 1 0 0 30 0 - - - fit 1000 0 0 0 - 0 0\n\
28712942 audio 2 0 0 30 0 - - - fit 1000 0 0 0 - 0 0\n\
@@ -2897,7 +2968,7 @@ mod tests {
28972968 (1280, 720),
28982969 old.playhead
28992970 )),
2900- "edith 22\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\
2971+ "edith 23\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\
29012972 video 1 0 0 30 0 - - - fit 1000 0 0 0 - 0 0\naudio 1 0 0 30 0 - - - fit 1000 0 0 0 - 0 0\n"
29022973 );
29032974
@@ -3061,7 +3132,7 @@ mod tests {
30613132 assert!(old.eq.is_empty(), "nothing before v5 equalizes anything");
30623133 assert_eq!(
30633134 String::from_utf8_lossy(&flat(&dir, &old.sources, &old.lanes, old.playhead)),
3064- "edith 22\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\
3135+ "edith 23\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\
30653136 source 2 /elsewhere/b.mp4\n\
30663137 video 1 0 0 30 0 0 - - fit 1000 0 0 0 - 0 0\nvideo 1 30 10 20 1 1 - - fit 1000 0 0 0 - 0 0\n\
30673138 audio 1 0 0 30 0 0 - - fit 1000 0 0 0 - 0 0\n"
@@ -3114,7 +3185,7 @@ mod tests {
31143185 let v5 = flat(&dir, &back.sources, &back.lanes, back.playhead);
31153186 assert_eq!(
31163187 String::from_utf8_lossy(&v5),
3117- "edith 22\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\
3188+ "edith 23\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\
31183189 source 0 /elsewhere/b.mp4\n\
31193190 video 1 0 0 30 0 0 - - fit 1000 0 0 0 - 0 0\nvideo 1 30 10 20 1 1 - - fit 1000 0 0 0 - 0 0\n\
31203191 audio 1 0 0 30 0 0 - - fit 1000 0 0 0 - 0 0\n",
@@ -3146,7 +3217,7 @@ mod tests {
31463217 // Saved again it is the current version, which round-trips to the
31473218 // same document.
31483219 let v5 = flat(&dir, &back.sources, &back.lanes, back.playhead);
3149- assert!(v5.starts_with(b"edith 22\n"));
3220+ assert!(v5.starts_with(b"edith 23\n"));
31503221 let again = parse(&v5, &dir).expect("v5 parses");
31513222 assert_eq!(again.lanes, back.lanes);
31523223 // A dialect may not be mixed: lane lines under v1, `clip` under v2.
@@ -3257,7 +3328,7 @@ mod tests {
32573328 let bytes = std::fs::read(&path).expect("read back");
32583329 assert_eq!(
32593330 String::from_utf8_lossy(&bytes),
3260- "edith 22\nplayhead 0\nresolution 1280 720\nsource 1 a.mp4\n\
3331+ "edith 23\nplayhead 0\nresolution 1280 720\nsource 1 a.mp4\n\
32613332 video 1 0 0 30 0 - - - fit 1000 0 0 0 - 0 0\naudio 1 0 0 30 0 - - - fit 1000 0 0 0 - 0 0\n"
32623333 );
32633334 // Loading rejoins the *given* directory, so the file is reached by the
@@ -3302,10 +3373,10 @@ mod tests {
33023373 #[test]
33033374 fn a_wrong_first_line_is_refused_by_name() {
33043375 let dir = PathBuf::from("/proj");
3305- let err = parse(b"edith 23\nsource 0 a.mp4\nvideo 0 0 5 0 -\n", &dir)
3376+ let err = parse(b"edith 24\nsource 0 a.mp4\nvideo 0 0 5 0 -\n", &dir)
33063377 .unwrap_err()
33073378 .to_string();
3308- assert_eq!(err, "line 1: unsupported version 23");
3379+ assert_eq!(err, "line 1: unsupported version 24");
33093380 for junk in [&b""[..], b"{}\n", b"source a.mp4\n"] {
33103381 assert_eq!(
33113382 parse(junk, &dir).unwrap_err().to_string(),
crates/engine/src/export.rsmodified+2 -2
@@ -4426,7 +4426,7 @@ enum ClipDecoder {
44264426 fps: f64,
44274427 next: u32,
44284428 flags: u8,
4429- paint: u32,
4429+ paint: u64,
44304430 y: Vec<u8>,
44314431 u: Vec<u8>,
44324432 v: Vec<u8>,
@@ -4540,7 +4540,7 @@ impl ClipDecoder {
45404540 height: u32,
45414541 fps: f64,
45424542 flags: u8,
4543- paint: u32,
4543+ paint: u64,
45444544 ) -> crate::Result<Self> {
45454545 let peaks = crate::waveform::peaks(path, stream, crate::decode::VIZ_BUCKETS_PER_SEC)
45464546 .ok()
crates/engine/src/playback.rsmodified+31 -1
@@ -2984,10 +2984,18 @@ impl PlaybackSession {
29842984 self.edit(Dirty::Picture, |p| p.set_visualizer(lane, idx, flags))
29852985 }
29862986
2987- pub fn set_viz_paint(&mut self, lane: Lane, idx: usize, paint: u32) -> bool {
2987+ pub fn set_viz_paint(&mut self, lane: Lane, idx: usize, paint: u64) -> bool {
29882988 self.edit(Dirty::Picture, |p| p.set_viz_paint(lane, idx, paint))
29892989 }
29902990
2991+ /// The same look and the same repaint without the undo step
2992+ /// ([`Project::set_viz_paint_live`]): what the samples inside one drag
2993+ /// across the colour wheel go through, so the picture follows the hand and
2994+ /// the whole gesture is still a single `z`.
2995+ pub fn set_viz_paint_live(&mut self, lane: Lane, idx: usize, paint: u64) -> bool {
2996+ self.edit(Dirty::Picture, |p| p.set_viz_paint_live(lane, idx, paint))
2997+ }
2998+
29912999 /// Timeline frames of ramp-up from silence at the start of the clip at
29923000 /// `idx` of `lane`. `0` for an index that is not there.
29933001 pub fn fade_in_of(&self, lane: Lane, idx: usize) -> u32 {
@@ -4795,5 +4803,27 @@ mod tests {
47954803 assert_eq!(before, s.restarts(), "a live transform edit must reuse the worker");
47964804 assert_eq!(next.index, first.index, "paused: same timeline position before and after");
47974805 }
4806+
4807+ /// The session's live look samples leave its history exactly where the
4808+ /// press left it -- the colour-wheel drag's twin for the packed look, and
4809+ /// what lets the app drive one from a pointer: `z` after a drag lands
4810+ /// before the press, not one sample back down the drag.
4811+ #[test]
4812+ fn a_live_look_drag_is_one_step_of_the_sessions_history() {
4813+ let mut s = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture");
4814+ let (lane, idx) = s.video_clip_at(s.now()).expect("a clip under the playhead");
4815+ let look = |hue: u8| crate::decode::with_viz_paint_hue(crate::decode::VIZ_PAINT_AZURE, hue);
4816+ assert!(s.set_viz_paint(lane, idx, look(1)), "the press");
4817+ for hue in 2..=6u8 {
4818+ assert!(s.set_viz_paint_live(lane, idx, look(hue)), "a sample");
4819+ }
4820+ assert_eq!(s.project.lane(lane)[idx].viz_paint, look(6));
4821+ assert!(s.undo(), "the drag's own step");
4822+ assert_eq!(
4823+ s.project.lane(lane)[idx].viz_paint,
4824+ 0,
4825+ "one undo is the whole drag"
4826+ );
4827+ }
47984828 }
47994829
crates/engine/src/project.rsmodified+76 -10
@@ -461,10 +461,15 @@ pub struct Clip {
461461 /// Zero is an ordinary picture. Older project files have no field and
462462 /// mean zero.
463463 pub visualizer: u8,
464- /// Packed look: hue 0-255, sat 0-255, strands 0-255, glow 0-255.
465- /// All-zero is the default (timeline azure, full sat, 8 strands, glow 2).
466- /// Older files have no field and mean zero.
467- pub viz_paint: u32,
464+ /// Packed look: hue 0-255, sat 0-255, strands 0-255, glow 0-255 in the
465+ /// low four bytes as they have been since v22, then the strand colour's
466+ /// own bytes above them -- its hue at 32 and sat at 40
467+ /// ([`crate::decode::viz_strand_hue_ui`]) -- with the top bit as
468+ /// [`crate::decode::viz_strand_set`]. All-zero is the default (timeline
469+ /// azure, full sat, 8 strands, glow 2, no strand colour of its own).
470+ /// Older files have no field and mean zero; a v22 file's 32-bit value
471+ /// is the low half of this one, byte for byte.
472+ pub viz_paint: u64,
468473 }
469474
470475 impl Clip {
@@ -2653,11 +2658,28 @@ impl Project {
26532658 true
26542659 }
26552660
2656- pub fn set_viz_paint(&mut self, lane: Lane, idx: usize, paint: u32) -> bool {
2661+ /// Give the clip at `idx` of `lane` this packed look: one undo step, and
2662+ /// `false` (with no history) for an index that is not there, the way every
2663+ /// other setter refuses.
2664+ pub fn set_viz_paint(&mut self, lane: Lane, idx: usize, paint: u64) -> bool {
2665+ self.write_viz_paint(lane, idx, paint, true)
2666+ }
2667+
2668+ /// [`set_viz_paint`](Self::set_viz_paint) without the undo step: the
2669+ /// samples *inside* one pointer drag across the colour wheel, whose first
2670+ /// write (a plain `set_viz_paint`) already took the snapshot the gesture
2671+ /// rolls back to. One drag is one undo, not one per sample.
2672+ pub fn set_viz_paint_live(&mut self, lane: Lane, idx: usize, paint: u64) -> bool {
2673+ self.write_viz_paint(lane, idx, paint, false)
2674+ }
2675+
2676+ fn write_viz_paint(&mut self, lane: Lane, idx: usize, paint: u64, snapshot: bool) -> bool {
26572677 if idx >= self.lane(lane).len() {
26582678 return false;
26592679 }
2660- self.snapshot();
2680+ if snapshot {
2681+ self.snapshot();
2682+ }
26612683 self.lane_mut(lane).expect("checked above")[idx].viz_paint = paint;
26622684 true
26632685 }
@@ -3049,7 +3071,10 @@ impl Project {
30493071 .unwrap_or(0)
30503072 }
30513073
3052- pub fn composite_viz_paint_at(&self, timeline_frame: u32) -> u32 {
3074+ /// Packed look ([`Clip::viz_paint`]) of the topmost video clip at
3075+ /// `timeline_frame`, or zero over a gap / a picture that is not a
3076+ /// visualizer.
3077+ pub fn composite_viz_paint_at(&self, timeline_frame: u32) -> u64 {
30533078 self.composite_clip_at(timeline_frame)
30543079 .map(|(lane, idx)| self.lane(lane)[idx].viz_paint)
30553080 .unwrap_or(0)
@@ -7225,13 +7250,17 @@ mod tests {
72257250 /// The transform index is a third `Option<u16>`, same reason as the eq and
72267251 /// colour ones before it -- it lands in bytes already spent on padding, so
72277252 /// the struct still costs 56.
7253+ /// The visualizer look is the first field whose own width outgrows the
7254+ /// padding it lands in: it is a `u64` (a strand colour needs bytes above
7255+ /// the clip's own four), so the words after it come to 60 and the
7256+ /// alignment rounds them to 64 -- one word more than a clip used to cost.
72287257 /// This is the assert that says so: a clip that grows a word grows every
72297258 /// undo snapshot and every clipboard copy with it.
72307259 #[test]
72317260 fn a_fit_policy_costs_the_clip_no_word() {
72327261 assert_eq!(
72337262 std::mem::size_of::<Clip>(),
7234- 56,
7263+ 64,
72357264 "Clip changed size: {} bytes",
72367265 std::mem::size_of::<Clip>()
72377266 );
@@ -8893,6 +8922,40 @@ mod tests {
88938922 );
88948923 }
88958924
8925+ /// A drag across the colour wheel is one gesture -- the look's twin of
8926+ /// [`a_whole_colour_drag_undoes_in_one_step`]: the press snapshots, every
8927+ /// sample after it only repaints, and the single undo lands on the look
8928+ /// the clip had *before* the hand touched it. The committing setter is
8929+ /// still exactly one step, refusals included.
8930+ #[test]
8931+ fn a_whole_look_drag_undoes_in_one_step() {
8932+ let look = |hue: u8| crate::decode::with_viz_paint_hue(crate::decode::VIZ_PAINT_AZURE, hue);
8933+ let mut p = three();
8934+ assert!(p.set_viz_paint(Lane::V1, 0, look(1)), "the press");
8935+ for hue in 2..=8u8 {
8936+ assert!(p.set_viz_paint_live(Lane::V1, 0, look(hue)), "a sample");
8937+ }
8938+ assert_eq!(p.lane(Lane::V1)[0].viz_paint, look(8));
8939+ assert!(p.undo());
8940+ assert_eq!(
8941+ p.lane(Lane::V1)[0].viz_paint,
8942+ 0,
8943+ "one undo is the whole gesture, back to the default look"
8944+ );
8945+
8946+ // The live write refuses an index that is not there -- and a refusal
8947+ // costs no history -- while one committing write is one step back.
8948+ assert!(!p.set_viz_paint_live(Lane::V1, 99, look(1)));
8949+ assert!(p.set_viz_paint(Lane::V1, 0, look(1)), "a click, not a drag");
8950+ assert_eq!(p.lane(Lane::V1)[0].viz_paint, look(1));
8951+ assert!(p.undo());
8952+ assert_eq!(
8953+ p.lane(Lane::V1)[0].viz_paint,
8954+ 0,
8955+ "the committing setter is one undo step, no more"
8956+ );
8957+ }
8958+
88968959 /// The colour table is append-only within a session, exactly as the eq one
88978960 /// is -- and a save is where an undone grade goes.
88988961 #[test]
@@ -9052,12 +9115,15 @@ mod tests {
90529115 /// colour one did not, and the struct grew a word. The transform index is
90539116 /// a third `Option<u16>`, and it fits the padding the fit policy and the
90549117 /// transition byte already left behind, so the struct did not grow again.
9118+ /// The packed visualizer look is a `u64` -- the strand colour has bytes
9119+ /// above the clip's own four -- and nothing left in the struct is wide
9120+ /// enough to hold it, so it grew a word again.
90559121 #[test]
90569122 fn a_clip_is_still_a_small_copy() {
90579123 assert_eq!(
90589124 std::mem::size_of::<Clip>(),
9059- 56,
9060- "Clip changed size -- 32 before the colour index, 40 before the fades, 48 after, 56 with the transition, still 56 with the transform index"
9125+ 64,
9126+ "Clip changed size -- 32 before the colour index, 40 before the fades, 48 after, 56 with the transition, still 56 with the transform index, 64 once the look was a u64"
90619127 );
90629128 }
90639129
crates/engine/tests/export.rsmodified+1 -1
@@ -1253,7 +1253,7 @@ fn a_proxy_is_picture_only_every_frame_a_starting_point_and_cached() {
12531253 session.set_proxies(true);
12541254 session.save_project(&project).expect("save");
12551255 let text = std::fs::read_to_string(&project).expect("read the project back");
1256- assert!(text.starts_with("edith 20\n"), "{text}");
1256+ assert!(text.starts_with("edith 23\n"), "{text}");
12571257 assert!(text.contains("\nproxy on\n"), "{text}");
12581258 let reopened = PlaybackSession::open_project(&project).expect("load");
12591259 assert!(reopened.proxies(), "the switch came back on");
crates/engine/tests/saveload.rsmodified+13 -13
@@ -292,7 +292,7 @@ fn a_version_1_project_loads_fully_grouped_and_saves_as_version_7() {
292292 let v2 = dir.join("new.edith");
293293 loaded.save_project(&v2).expect("save");
294294 let text = std::fs::read_to_string(&v2).expect("read back");
295- assert!(text.starts_with("edith 20\n"), "{text}");
295+ assert!(text.starts_with("edith 23\n"), "{text}");
296296 assert!(
297297 text.contains("\nresolution 1280 720\n"),
298298 "a project with no resolution of its own is saved at source 0's: {text}"
@@ -380,9 +380,9 @@ fn a_version_4_project_holds_more_than_two_lanes() {
380380 loaded.save_project(&again).expect("save");
381381 assert_eq!(
382382 std::fs::read_to_string(&again).expect("read back"),
383- "edith 20\nplayhead 0\nresolution 1280 720\nfps 30.0\nsource 0 test_av.mp4\n\
384- video 1 0 0 30 0 3 - - fit 1000 0 0 0 -\naudio 1\n\
385- video 2 40 0 20 0 - - - fit 1000 0 0 0 -\naudio 2 0 0 30 0 3 - - fit 1000 0 0 0 -\n",
383+ "edith 23\nplayhead 0\nresolution 1280 720\nfps 30.0\nsource 0 test_av.mp4\n\
384+ video 1 0 0 30 0 3 - - fit 1000 0 0 0 - 0 0\naudio 1\n\
385+ video 2 40 0 20 0 - - - fit 1000 0 0 0 - 0 0\naudio 2 0 0 30 0 3 - - fit 1000 0 0 0 - 0 0\n",
386386 "a four-lane project is written as it was read, three versions on"
387387 );
388388 }
@@ -410,11 +410,11 @@ fn a_version_5_project_carries_per_clip_equalizers() {
410410 loaded.save_project(&again).expect("save");
411411 assert_eq!(
412412 std::fs::read_to_string(&again).expect("read back"),
413- "edith 20\nplayhead 0\nresolution 1280 720\nfps 30.0\nsource 0 test_av.mp4\n\
413+ "edith 23\nplayhead 0\nresolution 1280 720\nfps 30.0\nsource 0 test_av.mp4\n\
414414 eq 80.0:-3.0:0.707:ls 1000.0:4.5:1.0:pk\n\
415415 eq 12000.0:6.25:0.5:hs\n\
416- video 1 0 0 30 0 - 0 - fit 1000 0 0 0 -\nvideo 1 30 30 60 0 - 1 - fit 1000 0 0 0 -\n\
417- audio 1 0 0 30 0 - 0 - fit 1000 0 0 0 -\naudio 1 30 30 60 0 - - - fit 1000 0 0 0 -\n",
416+ video 1 0 0 30 0 - 0 - fit 1000 0 0 0 - 0 0\nvideo 1 30 30 60 0 - 1 - fit 1000 0 0 0 - 0 0\n\
417+ audio 1 0 0 30 0 - 0 - fit 1000 0 0 0 - 0 0\naudio 1 30 30 60 0 - - - fit 1000 0 0 0 - 0 0\n",
418418 "the equalizer table and every clip's index survive a round trip"
419419 );
420420 }
@@ -445,12 +445,12 @@ fn a_version_6_project_carries_per_clip_colours() {
445445 loaded.save_project(&again).expect("save");
446446 assert_eq!(
447447 std::fs::read_to_string(&again).expect("read back"),
448- "edith 20\nplayhead 0\nresolution 1280 720\nfps 30.0\nsource 0 test_av.mp4\n\
448+ "edith 23\nplayhead 0\nresolution 1280 720\nfps 30.0\nsource 0 test_av.mp4\n\
449449 eq 80.0:-3.0:0.707:ls\n\
450450 color 0.1:1.2:0.9:-0.3\n\
451451 color -0.25:1.0:0.0:0.5\n\
452- video 1 0 0 30 0 - 0 0 fit 1000 0 0 0 -\nvideo 1 30 30 60 0 - - 1 fit 1000 0 0 0 -\n\
453- audio 1 0 0 30 0 - - 0 fit 1000 0 0 0 -\naudio 1 30 30 60 0 - - - fit 1000 0 0 0 -\n",
452+ video 1 0 0 30 0 - 0 0 fit 1000 0 0 0 - 0 0\nvideo 1 30 30 60 0 - - 1 fit 1000 0 0 0 - 0 0\n\
453+ audio 1 0 0 30 0 - - 0 fit 1000 0 0 0 - 0 0\naudio 1 30 30 60 0 - - - fit 1000 0 0 0 - 0 0\n",
454454 "the colour table and every clip's index survive a round trip"
455455 );
456456 // A dialect that could not say either one means the defaults, and those are
@@ -495,9 +495,9 @@ fn a_version_7_project_carries_a_resolution_and_fit_policies() {
495495 loaded.save_project(&again).expect("save");
496496 assert_eq!(
497497 std::fs::read_to_string(&again).expect("read back"),
498- "edith 20\nplayhead 0\nresolution 960 720\nfps 30.0\nsource 0 test_av.mp4\n\
499- video 1 0 0 30 0 - - - fill 1000 0 0 0 -\nvideo 1 30 30 60 0 - - - center 1000 0 0 0 -\n\
500- audio 1 0 0 60 0 - - - fit 1000 0 0 0 -\n",
498+ "edith 23\nplayhead 0\nresolution 960 720\nfps 30.0\nsource 0 test_av.mp4\n\
499+ video 1 0 0 30 0 - - - fill 1000 0 0 0 - 0 0\nvideo 1 30 30 60 0 - - - center 1000 0 0 0 - 0 0\n\
500+ audio 1 0 0 60 0 - - - fit 1000 0 0 0 - 0 0\n",
501501 "a v7 project is written back as the v8 it now is: the same clips, each \
502502 saying it plays at real time, which is what it always played at"
503503 );
crates/engine/tests/silence.rsmodified+1 -1
@@ -400,7 +400,7 @@ fn scanning_a_clip_and_cutting_what_it_finds() {
400400 .expect("save");
401401 let text = std::fs::read_to_string(&file).expect("read it back");
402402 assert!(
403- text.starts_with("edith 20"),
403+ text.starts_with("edith 23"),
404404 "{:?}",
405405 &text[..16.min(text.len())]
406406 );
crates/engine/tests/subtitles.rsmodified+3 -3
@@ -260,7 +260,7 @@ fn a_project_keeps_its_subtitles_across_a_save() {
260260 let project = dir.join("cut.edith");
261261 session.save_project(&project).expect("save");
262262 let text = std::fs::read_to_string(&project).expect("read the project back");
263- assert!(text.starts_with("edith 20\n"), "{text}");
263+ assert!(text.starts_with("edith 23\n"), "{text}");
264264 assert!(
265265 text.contains("\nsubtitle - test_subs.srt\n"),
266266 "the reference is written relative, and no cue is: {text}"
@@ -1251,7 +1251,7 @@ fn subtitle_lanes_and_their_captions_survive_a_save() {
12511251 let project = dir.join("cut.edith");
12521252 session.save_project(&project).expect("save");
12531253 let text = std::fs::read_to_string(&project).expect("read the project back");
1254- assert!(text.starts_with("edith 20\n"), "{text}");
1254+ assert!(text.starts_with("edith 23\n"), "{text}");
12551255 assert!(
12561256 text.contains("\nsub 1 10 45 0 500000 1500000\n"),
12571257 "the placement is one line: where it sits, how long, whose words, and \
@@ -1317,7 +1317,7 @@ fn a_version_14_project_keeps_its_palette_and_places_nothing() {
13171317 let now = dir.join("new.edith");
13181318 loaded.save_project(&now).expect("save");
13191319 let text = std::fs::read_to_string(&now).expect("read back");
1320- assert!(text.starts_with("edith 20\n"), "{text}");
1320+ assert!(text.starts_with("edith 23\n"), "{text}");
13211321 assert!(
13221322 text.contains("\nsubtitle - test_subs.srt\n"),
13231323 "the row survives the migration: {text}"