From 8bfbcb36012cb3b9cfc4209a99c798c67e1dfcc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Thu, 20 Aug 2026 00:58:41 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(app):=20a=20preview's=20end?= =?UTF-8?q?=20no=20longer=20throws=20the=20timeline=20playhead?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit playhead() snapped the ruler to the timeline's duration whenever the transport read Ended — and the transport reads the preview while one is up, so a preview running out hurled the ruler to the timeline's end. The snap now asks the timeline's own session only. Driven: preview halts at 35:18 with the ruler holding 08:14. --- crates/app/src/player/timeline_edit.rs | 19 ++++++++++------- crates/app/src/transport.rs | 29 ++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/crates/app/src/player/timeline_edit.rs b/crates/app/src/player/timeline_edit.rs index 7ec5053..d82bfd0 100644 --- a/crates/app/src/player/timeline_edit.rs +++ b/crates/app/src/player/timeline_edit.rs @@ -1269,15 +1269,18 @@ impl Player { /// Where the playhead is, as the panel draws it: pinned to the out point /// once playback is done, and clamped to the drawn duration otherwise -- a /// tail being dragged draws past the timeline it is about to become. + /// + /// `self.transport()` answers for whichever session is active, which is + /// the preview while one is showing ([`Player::active_session`]) -- so a + /// preview reaching its own end must not be read as *this* (the + /// timeline's) playhead running out and snapping to `duration`. Gated on + /// there being no preview session, so the ruler keeps tracking + /// `self.session` -- untouched by a preview's own clock -- for as long as + /// one is up. pub(crate) fn playhead(&self, duration: f64) -> f64 { - if self.transport() == Transport::Ended { - duration - } else { - self.session - .as_ref() - .map_or(0., PlaybackSession::now) - .clamp(0., duration) - } + let ended = self.preview_session.is_none() && self.transport() == Transport::Ended; + let now = self.session.as_ref().map_or(0., PlaybackSession::now); + playhead_position(now, ended, duration) } /// One sample of whatever drag is in the hand: the equalizer's handle, a diff --git a/crates/app/src/transport.rs b/crates/app/src/transport.rs index 4087ede..8824c74 100644 --- a/crates/app/src/transport.rs +++ b/crates/app/src/transport.rs @@ -235,6 +235,21 @@ pub(crate) fn preview_progress_along(now: f64, duration: f64) -> f32 { (now / duration).clamp(0., 1.) as f32 } +/// Where the ruler draws the playhead, given whether *the timeline's own* +/// session ([`Player::session`]) has played out. `ended` must answer for +/// `session` specifically, never for [`Player::active_session`] -- a preview +/// reaching *its* end is not the timeline's own playhead running out, and +/// must not snap the ruler to `duration` while the timeline sits wherever it +/// was left (a seek, mid-scrub, anywhere). `now` is `session`'s own clock, +/// which a preview never touches. +pub(crate) fn playhead_position(now: f64, ended: bool, duration: f64) -> f64 { + if ended { + duration + } else { + now.clamp(0., duration) + } +} + #[cfg(test)] mod tests { use super::*; @@ -258,6 +273,20 @@ mod tests { assert_eq!(preview_seek_seconds(px(500.), bar, 60.), 60.); } + /// Ended pins the ruler to the out point; short of that it tracks the + /// clock, clamped -- a tail dragged past the end must not walk the ruler + /// off the bed. + #[test] + fn playhead_position_pins_only_on_the_sessions_own_end() { + assert_eq!(playhead_position(8., false, 35.), 8.); + assert_eq!(playhead_position(35., true, 35.), 35.); + assert_eq!(playhead_position(40., false, 35.), 35.); + // A preview ending must not read as `ended` for this call at all -- + // it is the caller's job to pass `false` while one is up, which is + // exactly what leaves the ruler on the timeline's own clock. + assert_eq!(playhead_position(8., false, 35.), 8.); + } + /// The fill tracks the played share exactly, and a duration of nothing /// -- no file open yet -- reads as an empty bar rather than a divide by /// zero.