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.