From 2bee9c3cf546c0b6f7eebc97eb5037a9974f39a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 11 Aug 2026 10:35:27 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(subs+eos):=20the=20plate=20r?= =?UTF-8?q?eads=20the=20map=20the=20file=20is=20written=20from,=20and=20a?= =?UTF-8?q?=20knob=20past=20the=20end=20leaves=20the=20end=20alone?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The overlay and the timeline strip drew every subtitle track on the raw timeline clock while the export carried an embedded track through the cuts (export::timeline_cues), so a rippled timeline previewed one thing and wrote another. Both now ask that one map through PlaybackSession::timeline_cues -- preview and file agree by construction, and a standalone .srt keeps the timeline clock it always had. And the end of stream: is_eos promised that "any edit after the end revives the session", which a sound-only edit never did. The transport's own model says it should not -- eos means the picture worker ran out, reseek_audio starts no picture worker, and reviving on an EQ tweak would spend the Ended state that makes the next press restart from the top. The doc now states that rule and a test pins it. --- crates/app/src/main.rs | 59 ++++++++++++++++++++++++++++- crates/engine/src/export.rs | 15 +++++--- crates/engine/src/playback.rs | 39 ++++++++++++++++++- crates/engine/tests/invalidation.rs | 56 +++++++++++++++++++++++++++ 4 files changed, 159 insertions(+), 10 deletions(-) diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index 379f186..4f63080 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -5328,11 +5328,17 @@ impl Player { /// `None` -- no element at all -- while the toggle is off, with no track /// picked, and between cues: the picture is what this window is for, and a /// permanent empty band across it would be in the way of exactly that. + /// + /// The cues are the *timeline's* ([`PlaybackSession::timeline_cues`]) and + /// not the track's own: on a cut timeline an embedded track's cues ride the + /// pictures they belong to, and this is the same map the export writes the + /// file with -- so what is read here is what the file says. fn subtitle_overlay(&self, at: f64) -> Option> { if !self.subs_on { return None; } - let cues = cues_at(&self.subtitle_track()?.cues, at); + let mapped = self.session.as_ref()?.timeline_cues(self.sub_track); + let cues = cues_at(&mapped, at); if cues.is_empty() { return None; } @@ -8392,7 +8398,17 @@ impl Player { ), } .into(); - let cues: Vec<(f32, f32)> = track.cues.iter().map(|cue| cue_box(scale, cue)).collect(); + // Where the cues are on *this* timeline and not in the file they came + // from ([`PlaybackSession::timeline_cues`]) -- the same map the plate + // over the picture and the export both go through, which is what keeps + // a mark under the take it is spoken over after a cut. + let cues: Vec<(f32, f32)> = self + .session + .as_ref()? + .timeline_cues(self.sub_track) + .iter() + .map(|cue| cue_box(scale, cue)) + .collect(); Some( div() .flex_none() @@ -15317,6 +15333,45 @@ mod tests { }; assert!(subtitle_detail(&refused).contains("pictures")); assert!(cues_at(&refused.cues, 1.).is_empty()); + + // ...and what the plate and the strip draw after a *cut*: the timeline's + // own clock, asked of the engine through the very map an export writes + // the file with (`PlaybackSession::timeline_cues`), so the preview and + // the file cannot drift apart. The numbers are the export's own + // (`export::a_subtitle_file_beside_the_media_keeps_the_timelines_own_ + // clock`): 0.5s..2.5s rippled out of a five-second timeline leaves + // three seconds, which clips the second cue and takes the third away + // altogether -- while the track itself still holds all three, which is + // exactly why the drawing may not read them straight. + let lanes = session.lanes(); + session + .cut_regions(&[(15, 60)], &lanes) + .expect("cut 0.5s..2.5s out"); + assert_eq!(session.timeline_duration(), 3.0); + assert_eq!(session.subtitles()[0].cues.len(), 3, "the track is untouched"); + let mapped = session.timeline_cues(0); + assert_eq!( + mapped + .iter() + .map(|c| (c.start_us, c.end_us)) + .collect::>(), + vec![(500_000, 1_500_000), (2_000_000, 3_000_000)] + ); + // The overlay's own two lines, at the same moments as above. + let drawn = |t: f64| -> Vec { + cues_at(&mapped, t) + .into_iter() + .map(|c| c.text.clone()) + .collect() + }; + assert_eq!(drawn(0.7), ["first line"]); + assert_eq!(drawn(2.5), ["second line\nwith a break"]); + assert!( + drawn(4.2).is_empty(), + "a cue past the cut end is drawn where the file writes none" + ); + // ...and the strip's: the second cue is one second wide now, not 1.25. + assert_eq!(cue_box(scale, &mapped[1]), (80., 40.)); } #[test] diff --git a/crates/engine/src/export.rs b/crates/engine/src/export.rs index 4275969..077c5b3 100644 --- a/crates/engine/src/export.rs +++ b/crates/engine/src/export.rs @@ -578,12 +578,15 @@ fn export_subtitles( /// is the timeline's own clock, which is where it was drawn while editing /// (`Player::subtitle_overlay`). Clipped to the exported length and no more. /// -/// ponytail: the overlay draws *every* track on the timeline's clock, so on a -/// rippled timeline what the picture shows and what an embedded track exports -/// now disagree. The upgrade path is this function: the overlay should ask it -/// too, at which point both halves move together. It is left because the app is -/// another lane's file this week. -fn timeline_cues(project: &Project, track: &SubtitleTrack, fps: f64) -> Vec { +/// This is also what the *preview* draws: the plate over the picture and the +/// timeline strip both ask it through +/// [`PlaybackSession::timeline_cues`](crate::PlaybackSession::timeline_cues), so +/// what a rippled timeline shows and what its export writes are one answer by +/// construction rather than two maps kept in step by hand. +/// +/// Pure and cheap enough to ask per repaint (a walk of the spans and of the +/// cues, no file opened), which is how a front-end asks it. +pub fn timeline_cues(project: &Project, track: &SubtitleTrack, fps: f64) -> Vec { let frames = project.timeline_frames(); let us = |frame: u32| (f64::from(frame) / fps * 1e6).round() as i64; let end = us(frames); diff --git a/crates/engine/src/playback.rs b/crates/engine/src/playback.rs index 1942814..002f3d2 100644 --- a/crates/engine/src/playback.rs +++ b/crates/engine/src/playback.rs @@ -855,6 +855,25 @@ impl PlaybackSession { crate::export::planned_subtitles(&self.project, format, pick) } + /// Where the cues of the track at `pick` land on *this* timeline -- + /// [`crate::export::timeline_cues`], the very map an export writes the file + /// with, so a front-end that draws these draws what the file will say. On a + /// rippled or cut timeline that is the whole point: an embedded track rides + /// the spans that still play it, and a standalone `.srt` keeps the + /// timeline's own clock, clipped to its length. + /// + /// Empty for a row that is not there and for a track that could not be read. + /// Pure and file-free, so it may be asked per repaint; the cost is a walk of + /// the spans and of the cues. + pub fn timeline_cues(&self, pick: usize) -> Vec { + self.project + .subtitles() + .get(pick) + .map_or_else(Vec::new, |t| { + crate::export::timeline_cues(&self.project, t, self.meta.frame_rate) + }) + } + /// Why the sound's rate is not a choice for this timeline in this format -- /// [`crate::export::audio_rate_refusal`], asked of the project a front-end /// is holding, and pure for the same reason. @@ -1002,8 +1021,20 @@ impl PlaybackSession { } } - /// Whether the timeline has been played out. Any seek clears it, so an edit - /// after the end (which reseeks) revives the session. + /// Whether the timeline has been played out: the picture worker ran to the + /// end and there was no next clip. It is exactly that and nothing more, + /// which is what decides who clears it -- **starting a picture does** + /// (`start_picture`), so a seek clears it and so does every edit that + /// rebuilds the picture (`Dirty::Picture`, `Dirty::Both` -- a paste or a + /// placement past the end revives the session, and it has a new picture to + /// show for it). + /// + /// A **sound-only** edit does not (`Dirty::Sound`: an equalizer, a fader): + /// it rebuilds the sound where the playhead stands and starts no picture + /// worker, so the last frame is still the last frame and this is still the + /// end. A front-end's `Ended` therefore survives an EQ tweak made after the + /// timeline ran out -- the parameters are on the project either way, and the + /// next press restarts from the top with them, which is what `Ended` means. pub fn is_eos(&self) -> bool { self.eos } @@ -2239,6 +2270,10 @@ impl PlaybackSession { /// the picture does not blink -- and the clock, held still by /// [`resume`](Self::resume) until the new stream is audible, puts the sound /// back exactly where the picture already is. + /// + /// End of stream is deliberately left alone -- no picture worker is started + /// here, so a timeline that was played out still is; see + /// [`is_eos`](Self::is_eos). fn reseek_audio(&mut self) { let (t, target) = self.landing(self.now()); let was_playing = self.clock.is_playing(); diff --git a/crates/engine/tests/invalidation.rs b/crates/engine/tests/invalidation.rs index 2016099..30311f7 100644 --- a/crates/engine/tests/invalidation.rs +++ b/crates/engine/tests/invalidation.rs @@ -250,3 +250,59 @@ fn an_equalizer_rebuilds_the_sound_and_only_the_sound() { eprintln!("{frames} frames across an equalizer change, clock at {:.3}s", session.now()); assert!(frames > 0, "the picture stopped when the sound was rebuilt"); } + +/// The same classification asked at the one place it decides something a person +/// can see: **after the timeline has played out**. A sound edit rebuilds the +/// sound and starts no picture worker, so end of stream stands -- the last frame +/// is still the last frame, the transport is still `Ended`, and the next press +/// restarts from the top with the new curve on it. A revival here would spend +/// that state on an edit with nothing new to show, leaving a play press to run +/// the clock off the end instead of starting the film again. +#[test] +fn a_sound_edit_after_the_end_leaves_the_end_where_it_is() { + let mut session = open(&asset("test_av.mp4")); + // A breath short of the end: the tail is what this is about. + session.seek(4.8); + session.play(); + let deadline = std::time::Instant::now() + Duration::from_secs(20); + while !session.is_eos() { + assert!( + std::time::Instant::now() < deadline, + "never reached the end of a 5 s file" + ); + session.tick(); + while session.try_frame().is_some() {} + } + // What the front-end does on the crossing (`Player::pump`): stopped, on the + // out point, and still ended. + session.halt_at_end(); + let ended_at = session.now(); + assert_eq!(ended_at, session.timeline_duration()); + + let mut curve = engine::eq::EqParams::default_layout(); + curve.bands[0].gain_db = 6.0; + assert!(session.set_eq(Lane::A1, 0, Some(curve)), "equalize at the end"); + assert!( + session.is_eos(), + "an equalizer past the end revived the session: nothing new to show" + ); + assert!(!session.is_playing(), "...and it started the transport again"); + assert!( + (session.now() - ended_at).abs() < 1e-9, + "the playhead left the out point: {:.6}s", + session.now() + ); + // The parameters landed all the same -- that is what "the edit took" means. + assert!(session.eq_of(Lane::A1, 0).is_some(), "the curve did not apply"); + + // The fader's first move at the end goes down the same road (no mix is + // running to push it into, so it reseeks the audio too). + assert!(session.set_lane_gain_db(Lane::A1, -6.0), "fader at the end"); + assert!(session.is_eos(), "a fader past the end revived the session"); + assert_eq!(session.lane_gain_db(Lane::A1), -6.0); + + // And the restart off that end is still there, which is what the state was + // being kept for. + session.seek(0.0); + assert!(!session.is_eos(), "a seek revives a played-out session"); +}