A preview's end no longer throws the timeline playhead
Browse files at this commit- fix
- a preview's end no longer throws the timeline playhead
2 changed files +40 -8
crates/app/src/player/timeline_edit.rsmodified+11 -8
| @@ -1269,15 +1269,18 @@ impl Player { | |||
| 1269 | /// Where the playhead is, as the panel draws it: pinned to the out point | 1269 | /// Where the playhead is, as the panel draws it: pinned to the out point |
| 1270 | /// once playback is done, and clamped to the drawn duration otherwise -- a | 1270 | /// once playback is done, and clamped to the drawn duration otherwise -- a |
| 1271 | /// tail being dragged draws past the timeline it is about to become. | 1271 | /// tail being dragged draws past the timeline it is about to become. |
| 1272 | + /// | ||
| 1273 | + /// `self.transport()` answers for whichever session is active, which is | ||
| 1274 | + /// the preview while one is showing ([`Player::active_session`]) -- so a | ||
| 1275 | + /// preview reaching its own end must not be read as *this* (the | ||
| 1276 | + /// timeline's) playhead running out and snapping to `duration`. Gated on | ||
| 1277 | + /// there being no preview session, so the ruler keeps tracking | ||
| 1278 | + /// `self.session` -- untouched by a preview's own clock -- for as long as | ||
| 1279 | + /// one is up. | ||
| 1272 | pub(crate) fn playhead(&self, duration: f64) -> f64 { | 1280 | pub(crate) fn playhead(&self, duration: f64) -> f64 { |
| 1273 | - if self.transport() == Transport::Ended { | 1281 | + let ended = self.preview_session.is_none() && self.transport() == Transport::Ended; |
| 1274 | - duration | 1282 | + let now = self.session.as_ref().map_or(0., PlaybackSession::now); |
| 1275 | - } else { | 1283 | + playhead_position(now, ended, duration) |
| 1276 | - self.session | ||
| 1277 | - .as_ref() | ||
| 1278 | - .map_or(0., PlaybackSession::now) | ||
| 1279 | - .clamp(0., duration) | ||
| 1280 | - } | ||
| 1281 | } | 1284 | } |
| 1282 | 1285 | ||
| 1283 | /// One sample of whatever drag is in the hand: the equalizer's handle, a | 1286 | /// One sample of whatever drag is in the hand: the equalizer's handle, a |
crates/app/src/transport.rsmodified+29 -0
| @@ -235,6 +235,21 @@ pub(crate) fn preview_progress_along(now: f64, duration: f64) -> f32 { | |||
| 235 | (now / duration).clamp(0., 1.) as f32 | 235 | (now / duration).clamp(0., 1.) as f32 |
| 236 | } | 236 | } |
| 237 | 237 | ||
| 238 | +/// Where the ruler draws the playhead, given whether *the timeline's own* | ||
| 239 | +/// session ([`Player::session`]) has played out. `ended` must answer for | ||
| 240 | +/// `session` specifically, never for [`Player::active_session`] -- a preview | ||
| 241 | +/// reaching *its* end is not the timeline's own playhead running out, and | ||
| 242 | +/// must not snap the ruler to `duration` while the timeline sits wherever it | ||
| 243 | +/// was left (a seek, mid-scrub, anywhere). `now` is `session`'s own clock, | ||
| 244 | +/// which a preview never touches. | ||
| 245 | +pub(crate) fn playhead_position(now: f64, ended: bool, duration: f64) -> f64 { | ||
| 246 | + if ended { | ||
| 247 | + duration | ||
| 248 | + } else { | ||
| 249 | + now.clamp(0., duration) | ||
| 250 | + } | ||
| 251 | +} | ||
| 252 | + | ||
| 238 | #[cfg(test)] | 253 | #[cfg(test)] |
| 239 | mod tests { | 254 | mod tests { |
| 240 | use super::*; | 255 | use super::*; |
| @@ -258,6 +273,20 @@ mod tests { | |||
| 258 | assert_eq!(preview_seek_seconds(px(500.), bar, 60.), 60.); | 273 | assert_eq!(preview_seek_seconds(px(500.), bar, 60.), 60.); |
| 259 | } | 274 | } |
| 260 | 275 | ||
| 276 | + /// Ended pins the ruler to the out point; short of that it tracks the | ||
| 277 | + /// clock, clamped -- a tail dragged past the end must not walk the ruler | ||
| 278 | + /// off the bed. | ||
| 279 | + #[test] | ||
| 280 | + fn playhead_position_pins_only_on_the_sessions_own_end() { | ||
| 281 | + assert_eq!(playhead_position(8., false, 35.), 8.); | ||
| 282 | + assert_eq!(playhead_position(35., true, 35.), 35.); | ||
| 283 | + assert_eq!(playhead_position(40., false, 35.), 35.); | ||
| 284 | + // A preview ending must not read as `ended` for this call at all -- | ||
| 285 | + // it is the caller's job to pass `false` while one is up, which is | ||
| 286 | + // exactly what leaves the ruler on the timeline's own clock. | ||
| 287 | + assert_eq!(playhead_position(8., false, 35.), 8.); | ||
| 288 | + } | ||
| 289 | + | ||
| 261 | /// The fill tracks the played share exactly, and a duration of nothing | 290 | /// The fill tracks the played share exactly, and a duration of nothing |
| 262 | /// -- no file open yet -- reads as an empty bar rather than a divide by | 291 | /// -- no file open yet -- reads as an empty bar rather than a divide by |
| 263 | /// zero. | 292 | /// zero. |