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 {