A caption's unity gate is measured in frames
Browse files at this commit71b746819dc0c886ed7875cd1ce447bf25fdaebdParent: f8f5c46- fix
- a caption's unity gate is measured in frames
2 changed files +32 -13
crates/app/src/tests/layout.rsmodified+15 -0
| @@ -289,6 +289,21 @@ fn a_caption_box_wears_the_rate_its_window_plays_at() { | |||
| 289 | None, | 289 | None, |
| 290 | "placement rounding is not a re-timing" | 290 | "placement rounding is not a re-timing" |
| 291 | ); | 291 | ); |
| 292 | + // ...and rounding on SHORT tracks, where half a frame is a large share of | ||
| 293 | + // the window: `frames_of_us` of 1,016,667µs gives 31 frames (16,667µs of | ||
| 294 | + // error -- 16 permille, but half a frame), and of 5,015,000µs gives 150 | ||
| 295 | + // (15,000µs). Both are unity; a relative gate badges one 0.98x and the | ||
| 296 | + // other a self-contradicting 1.00x. | ||
| 297 | + assert_eq!( | ||
| 298 | + caption_rate(sub(31, 1_016_667), 30.), | ||
| 299 | + None, | ||
| 300 | + "half a frame off a one-second window is still unity" | ||
| 301 | + ); | ||
| 302 | + assert_eq!( | ||
| 303 | + caption_rate(sub(150, 5_015_000), 30.), | ||
| 304 | + None, | ||
| 305 | + "a hair under five seconds rounds to 150 frames and stays unity" | ||
| 306 | + ); | ||
| 292 | // A 2x re-rate: a 5s span holding the same 10s of words. | 307 | // A 2x re-rate: a 5s span holding the same 10s of words. |
| 293 | assert_eq!( | 308 | assert_eq!( |
| 294 | caption_rate(sub(150, 10_000_000), 30.).map(|s| s.permille()), | 309 | caption_rate(sub(150, 10_000_000), 30.).map(|s| s.permille()), |
crates/app/src/timeline_math.rsmodified+17 -13
| @@ -160,22 +160,26 @@ pub(crate) fn caption_rate(sub: SubClip, fps: f64) -> Option<Speed> { | |||
| 160 | if !(fps.is_finite() && fps > 0.0) || sub.window_us() <= 0 { | 160 | if !(fps.is_finite() && fps > 0.0) || sub.window_us() <= 0 { |
| 161 | return None; | 161 | return None; |
| 162 | } | 162 | } |
| 163 | - let span_us = f64::from(sub.frames) / fps * 1e6; | 163 | + let (span_us, window_us) = (f64::from(sub.frames) / fps * 1e6, sub.window_us() as f64); |
| 164 | + // The unity gate is absolute, in frames of the timeline: placement | ||
| 165 | + // rounding (`frames_of_us`) leaves a short track up to half a frame off | ||
| 166 | + // real time, which against a one-second window is fifteen permille -- a | ||
| 167 | + // relative gate would badge most palette drops under two and a half | ||
| 168 | + // seconds. Unity is "the window lands within a frame and a half of the | ||
| 169 | + // span"; the permille is only ever the rate the badge shows. | ||
| 170 | + if (span_us - window_us).abs() <= 1.5 / fps * 1e6 { | ||
| 171 | + return None; | ||
| 172 | + } | ||
| 164 | // The rate is the window over the span -- content per timeline, a clip's | 173 | // The rate is the window over the span -- content per timeline, a clip's |
| 165 | // own `speed` in the same spelling: 10s of words crossing 5s of timeline | 174 | // own `speed` in the same spelling: 10s of words crossing 5s of timeline |
| 166 | // is 2.00x. | 175 | // is 2.00x. |
| 167 | - let permille = (sub.window_us() as f64 / span_us * 1000.).round(); | 176 | + let permille = (window_us / span_us * 1000.).round(); |
| 168 | - // The gate is generous by two permille either way: placement rounding | 177 | + Some(Speed::from_permille( |
| 169 | - // (`frames_of_us`) leaves an odd-width unity window a frame off real | 178 | + permille.clamp( |
| 170 | - // time, and that is not a re-timing. | 179 | + f64::from(Speed::MIN.permille()), |
| 171 | - ((permille - 1000.).abs() > 2.).then(|| { | 180 | + f64::from(Speed::MAX.permille()), |
| 172 | - Speed::from_permille( | 181 | + ) as u16, |
| 173 | - permille.clamp( | 182 | + )) |
| 174 | - f64::from(Speed::MIN.permille()), | ||
| 175 | - f64::from(Speed::MAX.permille()), | ||
| 176 | - ) as u16, | ||
| 177 | - ) | ||
| 178 | - }) | ||
| 179 | } | 183 | } |
| 180 | 184 | ||
| 181 | impl Selection { | 185 | impl Selection { |