From 71b746819dc0c886ed7875cd1ce447bf25fdaebd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sat, 15 Aug 2026 23:06:12 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(timeline):=20a=20caption's?= =?UTF-8?q?=20unity=20gate=20is=20measured=20in=20frames?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The badge's unity gate was two permille, but placement rounding is an absolute error: frames_of_us leaves a short track up to half a frame off real time, which is sixteen permille of a one-second window — most palette drops under two and a half seconds badged, one of them a self-contradicting 1.00x. Unity is now 'the window lands within a frame and a half of the span', in the timeline's own frames; the permille survives only as the rate the badge shows. --- crates/app/src/tests/layout.rs | 15 +++++++++++++++ crates/app/src/timeline_math.rs | 30 +++++++++++++++++------------- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/crates/app/src/tests/layout.rs b/crates/app/src/tests/layout.rs index da2c9a1..6edd880 100644 --- a/crates/app/src/tests/layout.rs +++ b/crates/app/src/tests/layout.rs @@ -289,6 +289,21 @@ fn a_caption_box_wears_the_rate_its_window_plays_at() { None, "placement rounding is not a re-timing" ); + // ...and rounding on SHORT tracks, where half a frame is a large share of + // the window: `frames_of_us` of 1,016,667µs gives 31 frames (16,667µs of + // error -- 16 permille, but half a frame), and of 5,015,000µs gives 150 + // (15,000µs). Both are unity; a relative gate badges one 0.98x and the + // other a self-contradicting 1.00x. + assert_eq!( + caption_rate(sub(31, 1_016_667), 30.), + None, + "half a frame off a one-second window is still unity" + ); + assert_eq!( + caption_rate(sub(150, 5_015_000), 30.), + None, + "a hair under five seconds rounds to 150 frames and stays unity" + ); // A 2x re-rate: a 5s span holding the same 10s of words. assert_eq!( caption_rate(sub(150, 10_000_000), 30.).map(|s| s.permille()), diff --git a/crates/app/src/timeline_math.rs b/crates/app/src/timeline_math.rs index 8e08446..811a071 100644 --- a/crates/app/src/timeline_math.rs +++ b/crates/app/src/timeline_math.rs @@ -160,22 +160,26 @@ pub(crate) fn caption_rate(sub: SubClip, fps: f64) -> Option { if !(fps.is_finite() && fps > 0.0) || sub.window_us() <= 0 { return None; } - let span_us = f64::from(sub.frames) / fps * 1e6; + let (span_us, window_us) = (f64::from(sub.frames) / fps * 1e6, sub.window_us() as f64); + // The unity gate is absolute, in frames of the timeline: placement + // rounding (`frames_of_us`) leaves a short track up to half a frame off + // real time, which against a one-second window is fifteen permille -- a + // relative gate would badge most palette drops under two and a half + // seconds. Unity is "the window lands within a frame and a half of the + // span"; the permille is only ever the rate the badge shows. + if (span_us - window_us).abs() <= 1.5 / fps * 1e6 { + return None; + } // The rate is the window over the span -- content per timeline, a clip's // own `speed` in the same spelling: 10s of words crossing 5s of timeline // is 2.00x. - let permille = (sub.window_us() as f64 / span_us * 1000.).round(); - // The gate is generous by two permille either way: placement rounding - // (`frames_of_us`) leaves an odd-width unity window a frame off real - // time, and that is not a re-timing. - ((permille - 1000.).abs() > 2.).then(|| { - Speed::from_permille( - permille.clamp( - f64::from(Speed::MIN.permille()), - f64::from(Speed::MAX.permille()), - ) as u16, - ) - }) + let permille = (window_us / span_us * 1000.).round(); + Some(Speed::from_permille( + permille.clamp( + f64::from(Speed::MIN.permille()), + f64::from(Speed::MAX.permille()), + ) as u16, + )) } impl Selection {