The plate reads the map the file is written from, and a knob past the end leaves the end alone
Browse files at this commit2bee9c3cf546c0b6f7eebc97eb5037a9974f39a6Parent: 874f762- fix
- the plate reads the map the file is written from, and a knob past the end leaves the end alone
4 changed files +159 -10
- crates/app/src/main.rs +57 -2
- crates/engine/src/export.rs +9 -6
- crates/engine/src/playback.rs +37 -2
- crates/engine/tests/invalidation.rs +56 -0
crates/app/src/main.rsmodified+57 -2
| @@ -5328,11 +5328,17 @@ impl Player { | ||
| 5328 | 5328 | /// `None` -- no element at all -- while the toggle is off, with no track |
| 5329 | 5329 | /// picked, and between cues: the picture is what this window is for, and a |
| 5330 | 5330 | /// permanent empty band across it would be in the way of exactly that. |
| 5331 | + /// | |
| 5332 | + /// The cues are the *timeline's* ([`PlaybackSession::timeline_cues`]) and | |
| 5333 | + /// not the track's own: on a cut timeline an embedded track's cues ride the | |
| 5334 | + /// pictures they belong to, and this is the same map the export writes the | |
| 5335 | + /// file with -- so what is read here is what the file says. | |
| 5331 | 5336 | fn subtitle_overlay(&self, at: f64) -> Option<impl IntoElement + use<>> { |
| 5332 | 5337 | if !self.subs_on { |
| 5333 | 5338 | return None; |
| 5334 | 5339 | } |
| 5335 | - let cues = cues_at(&self.subtitle_track()?.cues, at); | |
| 5340 | + let mapped = self.session.as_ref()?.timeline_cues(self.sub_track); | |
| 5341 | + let cues = cues_at(&mapped, at); | |
| 5336 | 5342 | if cues.is_empty() { |
| 5337 | 5343 | return None; |
| 5338 | 5344 | } |
| @@ -8392,7 +8398,17 @@ impl Player { | ||
| 8392 | 8398 | ), |
| 8393 | 8399 | } |
| 8394 | 8400 | .into(); |
| 8395 | - let cues: Vec<(f32, f32)> = track.cues.iter().map(|cue| cue_box(scale, cue)).collect(); | |
| 8401 | + // Where the cues are on *this* timeline and not in the file they came | |
| 8402 | + // from ([`PlaybackSession::timeline_cues`]) -- the same map the plate | |
| 8403 | + // over the picture and the export both go through, which is what keeps | |
| 8404 | + // a mark under the take it is spoken over after a cut. | |
| 8405 | + let cues: Vec<(f32, f32)> = self | |
| 8406 | + .session | |
| 8407 | + .as_ref()? | |
| 8408 | + .timeline_cues(self.sub_track) | |
| 8409 | + .iter() | |
| 8410 | + .map(|cue| cue_box(scale, cue)) | |
| 8411 | + .collect(); | |
| 8396 | 8412 | Some( |
| 8397 | 8413 | div() |
| 8398 | 8414 | .flex_none() |
| @@ -15317,6 +15333,45 @@ mod tests { | ||
| 15317 | 15333 | }; |
| 15318 | 15334 | assert!(subtitle_detail(&refused).contains("pictures")); |
| 15319 | 15335 | assert!(cues_at(&refused.cues, 1.).is_empty()); |
| 15336 | + | |
| 15337 | + // ...and what the plate and the strip draw after a *cut*: the timeline's | |
| 15338 | + // own clock, asked of the engine through the very map an export writes | |
| 15339 | + // the file with (`PlaybackSession::timeline_cues`), so the preview and | |
| 15340 | + // the file cannot drift apart. The numbers are the export's own | |
| 15341 | + // (`export::a_subtitle_file_beside_the_media_keeps_the_timelines_own_ | |
| 15342 | + // clock`): 0.5s..2.5s rippled out of a five-second timeline leaves | |
| 15343 | + // three seconds, which clips the second cue and takes the third away | |
| 15344 | + // altogether -- while the track itself still holds all three, which is | |
| 15345 | + // exactly why the drawing may not read them straight. | |
| 15346 | + let lanes = session.lanes(); | |
| 15347 | + session | |
| 15348 | + .cut_regions(&[(15, 60)], &lanes) | |
| 15349 | + .expect("cut 0.5s..2.5s out"); | |
| 15350 | + assert_eq!(session.timeline_duration(), 3.0); | |
| 15351 | + assert_eq!(session.subtitles()[0].cues.len(), 3, "the track is untouched"); | |
| 15352 | + let mapped = session.timeline_cues(0); | |
| 15353 | + assert_eq!( | |
| 15354 | + mapped | |
| 15355 | + .iter() | |
| 15356 | + .map(|c| (c.start_us, c.end_us)) | |
| 15357 | + .collect::<Vec<_>>(), | |
| 15358 | + vec![(500_000, 1_500_000), (2_000_000, 3_000_000)] | |
| 15359 | + ); | |
| 15360 | + // The overlay's own two lines, at the same moments as above. | |
| 15361 | + let drawn = |t: f64| -> Vec<String> { | |
| 15362 | + cues_at(&mapped, t) | |
| 15363 | + .into_iter() | |
| 15364 | + .map(|c| c.text.clone()) | |
| 15365 | + .collect() | |
| 15366 | + }; | |
| 15367 | + assert_eq!(drawn(0.7), ["first line"]); | |
| 15368 | + assert_eq!(drawn(2.5), ["second line\nwith a break"]); | |
| 15369 | + assert!( | |
| 15370 | + drawn(4.2).is_empty(), | |
| 15371 | + "a cue past the cut end is drawn where the file writes none" | |
| 15372 | + ); | |
| 15373 | + // ...and the strip's: the second cue is one second wide now, not 1.25. | |
| 15374 | + assert_eq!(cue_box(scale, &mapped[1]), (80., 40.)); | |
| 15320 | 15375 | } |
| 15321 | 15376 | |
| 15322 | 15377 | #[test] |
crates/engine/src/export.rsmodified+9 -6
| @@ -578,12 +578,15 @@ fn export_subtitles( | ||
| 578 | 578 | /// is the timeline's own clock, which is where it was drawn while editing |
| 579 | 579 | /// (`Player::subtitle_overlay`). Clipped to the exported length and no more. |
| 580 | 580 | /// |
| 581 | -/// ponytail: the overlay draws *every* track on the timeline's clock, so on a | |
| 582 | -/// rippled timeline what the picture shows and what an embedded track exports | |
| 583 | -/// now disagree. The upgrade path is this function: the overlay should ask it | |
| 584 | -/// too, at which point both halves move together. It is left because the app is | |
| 585 | -/// another lane's file this week. | |
| 586 | -fn timeline_cues(project: &Project, track: &SubtitleTrack, fps: f64) -> Vec<Cue> { | |
| 581 | +/// This is also what the *preview* draws: the plate over the picture and the | |
| 582 | +/// timeline strip both ask it through | |
| 583 | +/// [`PlaybackSession::timeline_cues`](crate::PlaybackSession::timeline_cues), so | |
| 584 | +/// what a rippled timeline shows and what its export writes are one answer by | |
| 585 | +/// construction rather than two maps kept in step by hand. | |
| 586 | +/// | |
| 587 | +/// Pure and cheap enough to ask per repaint (a walk of the spans and of the | |
| 588 | +/// cues, no file opened), which is how a front-end asks it. | |
| 589 | +pub fn timeline_cues(project: &Project, track: &SubtitleTrack, fps: f64) -> Vec<Cue> { | |
| 587 | 590 | let frames = project.timeline_frames(); |
| 588 | 591 | let us = |frame: u32| (f64::from(frame) / fps * 1e6).round() as i64; |
| 589 | 592 | let end = us(frames); |
crates/engine/src/playback.rsmodified+37 -2
| @@ -855,6 +855,25 @@ impl PlaybackSession { | ||
| 855 | 855 | crate::export::planned_subtitles(&self.project, format, pick) |
| 856 | 856 | } |
| 857 | 857 | |
| 858 | + /// Where the cues of the track at `pick` land on *this* timeline -- | |
| 859 | + /// [`crate::export::timeline_cues`], the very map an export writes the file | |
| 860 | + /// with, so a front-end that draws these draws what the file will say. On a | |
| 861 | + /// rippled or cut timeline that is the whole point: an embedded track rides | |
| 862 | + /// the spans that still play it, and a standalone `.srt` keeps the | |
| 863 | + /// timeline's own clock, clipped to its length. | |
| 864 | + /// | |
| 865 | + /// Empty for a row that is not there and for a track that could not be read. | |
| 866 | + /// Pure and file-free, so it may be asked per repaint; the cost is a walk of | |
| 867 | + /// the spans and of the cues. | |
| 868 | + pub fn timeline_cues(&self, pick: usize) -> Vec<crate::subtitle::Cue> { | |
| 869 | + self.project | |
| 870 | + .subtitles() | |
| 871 | + .get(pick) | |
| 872 | + .map_or_else(Vec::new, |t| { | |
| 873 | + crate::export::timeline_cues(&self.project, t, self.meta.frame_rate) | |
| 874 | + }) | |
| 875 | + } | |
| 876 | + | |
| 858 | 877 | /// Why the sound's rate is not a choice for this timeline in this format -- |
| 859 | 878 | /// [`crate::export::audio_rate_refusal`], asked of the project a front-end |
| 860 | 879 | /// is holding, and pure for the same reason. |
| @@ -1002,8 +1021,20 @@ impl PlaybackSession { | ||
| 1002 | 1021 | } |
| 1003 | 1022 | } |
| 1004 | 1023 | |
| 1005 | - /// Whether the timeline has been played out. Any seek clears it, so an edit | |
| 1006 | - /// after the end (which reseeks) revives the session. | |
| 1024 | + /// Whether the timeline has been played out: the picture worker ran to the | |
| 1025 | + /// end and there was no next clip. It is exactly that and nothing more, | |
| 1026 | + /// which is what decides who clears it -- **starting a picture does** | |
| 1027 | + /// (`start_picture`), so a seek clears it and so does every edit that | |
| 1028 | + /// rebuilds the picture (`Dirty::Picture`, `Dirty::Both` -- a paste or a | |
| 1029 | + /// placement past the end revives the session, and it has a new picture to | |
| 1030 | + /// show for it). | |
| 1031 | + /// | |
| 1032 | + /// A **sound-only** edit does not (`Dirty::Sound`: an equalizer, a fader): | |
| 1033 | + /// it rebuilds the sound where the playhead stands and starts no picture | |
| 1034 | + /// worker, so the last frame is still the last frame and this is still the | |
| 1035 | + /// end. A front-end's `Ended` therefore survives an EQ tweak made after the | |
| 1036 | + /// timeline ran out -- the parameters are on the project either way, and the | |
| 1037 | + /// next press restarts from the top with them, which is what `Ended` means. | |
| 1007 | 1038 | pub fn is_eos(&self) -> bool { |
| 1008 | 1039 | self.eos |
| 1009 | 1040 | } |
| @@ -2239,6 +2270,10 @@ impl PlaybackSession { | ||
| 2239 | 2270 | /// the picture does not blink -- and the clock, held still by |
| 2240 | 2271 | /// [`resume`](Self::resume) until the new stream is audible, puts the sound |
| 2241 | 2272 | /// back exactly where the picture already is. |
| 2273 | + /// | |
| 2274 | + /// End of stream is deliberately left alone -- no picture worker is started | |
| 2275 | + /// here, so a timeline that was played out still is; see | |
| 2276 | + /// [`is_eos`](Self::is_eos). | |
| 2242 | 2277 | fn reseek_audio(&mut self) { |
| 2243 | 2278 | let (t, target) = self.landing(self.now()); |
| 2244 | 2279 | let was_playing = self.clock.is_playing(); |
crates/engine/tests/invalidation.rsmodified+56 -0
| @@ -250,3 +250,59 @@ fn an_equalizer_rebuilds_the_sound_and_only_the_sound() { | ||
| 250 | 250 | eprintln!("{frames} frames across an equalizer change, clock at {:.3}s", session.now()); |
| 251 | 251 | assert!(frames > 0, "the picture stopped when the sound was rebuilt"); |
| 252 | 252 | } |
| 253 | + | |
| 254 | +/// The same classification asked at the one place it decides something a person | |
| 255 | +/// can see: **after the timeline has played out**. A sound edit rebuilds the | |
| 256 | +/// sound and starts no picture worker, so end of stream stands -- the last frame | |
| 257 | +/// is still the last frame, the transport is still `Ended`, and the next press | |
| 258 | +/// restarts from the top with the new curve on it. A revival here would spend | |
| 259 | +/// that state on an edit with nothing new to show, leaving a play press to run | |
| 260 | +/// the clock off the end instead of starting the film again. | |
| 261 | +#[test] | |
| 262 | +fn a_sound_edit_after_the_end_leaves_the_end_where_it_is() { | |
| 263 | + let mut session = open(&asset("test_av.mp4")); | |
| 264 | + // A breath short of the end: the tail is what this is about. | |
| 265 | + session.seek(4.8); | |
| 266 | + session.play(); | |
| 267 | + let deadline = std::time::Instant::now() + Duration::from_secs(20); | |
| 268 | + while !session.is_eos() { | |
| 269 | + assert!( | |
| 270 | + std::time::Instant::now() < deadline, | |
| 271 | + "never reached the end of a 5 s file" | |
| 272 | + ); | |
| 273 | + session.tick(); | |
| 274 | + while session.try_frame().is_some() {} | |
| 275 | + } | |
| 276 | + // What the front-end does on the crossing (`Player::pump`): stopped, on the | |
| 277 | + // out point, and still ended. | |
| 278 | + session.halt_at_end(); | |
| 279 | + let ended_at = session.now(); | |
| 280 | + assert_eq!(ended_at, session.timeline_duration()); | |
| 281 | + | |
| 282 | + let mut curve = engine::eq::EqParams::default_layout(); | |
| 283 | + curve.bands[0].gain_db = 6.0; | |
| 284 | + assert!(session.set_eq(Lane::A1, 0, Some(curve)), "equalize at the end"); | |
| 285 | + assert!( | |
| 286 | + session.is_eos(), | |
| 287 | + "an equalizer past the end revived the session: nothing new to show" | |
| 288 | + ); | |
| 289 | + assert!(!session.is_playing(), "...and it started the transport again"); | |
| 290 | + assert!( | |
| 291 | + (session.now() - ended_at).abs() < 1e-9, | |
| 292 | + "the playhead left the out point: {:.6}s", | |
| 293 | + session.now() | |
| 294 | + ); | |
| 295 | + // The parameters landed all the same -- that is what "the edit took" means. | |
| 296 | + assert!(session.eq_of(Lane::A1, 0).is_some(), "the curve did not apply"); | |
| 297 | + | |
| 298 | + // The fader's first move at the end goes down the same road (no mix is | |
| 299 | + // running to push it into, so it reseeks the audio too). | |
| 300 | + assert!(session.set_lane_gain_db(Lane::A1, -6.0), "fader at the end"); | |
| 301 | + assert!(session.is_eos(), "a fader past the end revived the session"); | |
| 302 | + assert_eq!(session.lane_gain_db(Lane::A1), -6.0); | |
| 303 | + | |
| 304 | + // And the restart off that end is still there, which is what the state was | |
| 305 | + // being kept for. | |
| 306 | + session.seek(0.0); | |
| 307 | + assert!(!session.is_eos(), "a seek revives a played-out session"); | |
| 308 | +} |