The playhead can loop, on the timeline and in a preview
Browse files at this commit935d48bba83e21b24c6e0af42ee4815f6d15375fParent: 47519e8- feat
- the playhead can loop, on the timeline and in a preview
6 changed files +79 -3
- crates/app/src/keymap.rs +13 -1
- crates/app/src/main.rs +6 -0
- crates/app/src/oracle.rs +3 -1
- crates/app/src/player/actions.rs +6 -0
- crates/app/src/player/transport.rs +34 -1
- crates/app/src/ui/toolbar.rs +17 -0
crates/app/src/keymap.rsmodified+13 -1
| @@ -62,6 +62,11 @@ macro_rules! actions { | |||
| 62 | 62 | ||
| 63 | actions! { | 63 | actions! { |
| 64 | Play, | 64 | Play, |
| 65 | + /// Whether the active session -- the timeline or a library preview -- | ||
| 66 | + /// restarts from the top on reaching its end instead of stopping there. | ||
| 67 | + /// Live exactly where Play is: a transport with nothing under it has | ||
| 68 | + /// nothing to loop either. | ||
| 69 | + Loop, | ||
| 65 | StepBack, | 70 | StepBack, |
| 66 | StepForward, | 71 | StepForward, |
| 67 | JumpBack, | 72 | JumpBack, |
| @@ -156,6 +161,7 @@ impl ActionId { | |||
| 156 | pub fn label(self) -> &'static str { | 161 | pub fn label(self) -> &'static str { |
| 157 | match self { | 162 | match self { |
| 158 | ActionId::Play => "Play / Pause", | 163 | ActionId::Play => "Play / Pause", |
| 164 | + ActionId::Loop => "Loop the playhead's end", | ||
| 159 | ActionId::StepBack => "One frame back", | 165 | ActionId::StepBack => "One frame back", |
| 160 | ActionId::StepForward => "One frame forward", | 166 | ActionId::StepForward => "One frame forward", |
| 161 | ActionId::JumpBack => "One second back", | 167 | ActionId::JumpBack => "One second back", |
| @@ -220,6 +226,7 @@ impl ActionId { | |||
| 220 | fn name(self) -> &'static str { | 226 | fn name(self) -> &'static str { |
| 221 | match self { | 227 | match self { |
| 222 | ActionId::Play => "play", | 228 | ActionId::Play => "play", |
| 229 | + ActionId::Loop => "loop", | ||
| 223 | ActionId::StepBack => "step-back", | 230 | ActionId::StepBack => "step-back", |
| 224 | ActionId::StepForward => "step-forward", | 231 | ActionId::StepForward => "step-forward", |
| 225 | ActionId::JumpBack => "jump-back", | 232 | ActionId::JumpBack => "jump-back", |
| @@ -286,6 +293,7 @@ impl ActionId { | |||
| 286 | pub fn category(self) -> Category { | 293 | pub fn category(self) -> Category { |
| 287 | match self { | 294 | match self { |
| 288 | ActionId::Play | 295 | ActionId::Play |
| 296 | + | ActionId::Loop | ||
| 289 | | ActionId::StepBack | 297 | | ActionId::StepBack |
| 290 | | ActionId::StepForward | 298 | | ActionId::StepForward |
| 291 | | ActionId::JumpBack | 299 | | ActionId::JumpBack |
| @@ -793,6 +801,10 @@ impl Keymap { | |||
| 793 | Keymap { | 801 | Keymap { |
| 794 | bindings: vec![ | 802 | bindings: vec![ |
| 795 | b(ActionId::Play, "space", false), | 803 | b(ActionId::Play, "space", false), |
| 804 | + // "r" for repeat, free and bare: its ctrl chord is already the | ||
| 805 | + // project resolution, and the two read as a pair the way the | ||
| 806 | + // mute and its level do. | ||
| 807 | + b(ActionId::Loop, "r", false), | ||
| 796 | // Seeking without a pointer, on the keys every player already | 808 | // Seeking without a pointer, on the keys every player already |
| 797 | // seeks with (gpui names them "left"/"right"/"home"/"end", | 809 | // seeks with (gpui names them "left"/"right"/"home"/"end", |
| 798 | // platform.rs:872-877). The colour card reads the same arrows | 810 | // platform.rs:872-877). The colour card reads the same arrows |
| @@ -1219,7 +1231,7 @@ mod tests { | |||
| 1219 | #[test] | 1231 | #[test] |
| 1220 | fn every_default_stroke_reaches_its_action() { | 1232 | fn every_default_stroke_reaches_its_action() { |
| 1221 | let k = Keymap::defaults(); | 1233 | let k = Keymap::defaults(); |
| 1222 | - assert_eq!(k.entries().len(), 56); | 1234 | + assert_eq!(k.entries().len(), 57); |
| 1223 | assert_eq!(k.lookup("f11", false), Some(ActionId::Fullscreen)); | 1235 | assert_eq!(k.lookup("f11", false), Some(ActionId::Fullscreen)); |
| 1224 | assert_eq!(k.lookup("w", false), Some(ActionId::Screenshot)); | 1236 | assert_eq!(k.lookup("w", false), Some(ActionId::Screenshot)); |
| 1225 | assert_eq!(k.lookup("y", false), Some(ActionId::SubtitleStyle)); | 1237 | assert_eq!(k.lookup("y", false), Some(ActionId::SubtitleStyle)); |
crates/app/src/main.rsmodified+6 -0
| @@ -104,6 +104,11 @@ struct Player { | |||
| 104 | /// about it, so [`Player::act`] reconciles them rather than trusting | 104 | /// about it, so [`Player::act`] reconciles them rather than trusting |
| 105 | /// either alone. | 105 | /// either alone. |
| 106 | player_fullscreen: bool, | 106 | player_fullscreen: bool, |
| 107 | + /// Whether the active session -- the timeline or a library preview, | ||
| 108 | + /// whichever [`Player::active_session`] is reading -- restarts from the | ||
| 109 | + /// top on reaching its end instead of stopping there. One flag for both, | ||
| 110 | + /// since only one of them is ever playing at a time. | ||
| 111 | + loop_on: bool, | ||
| 107 | /// Timeline seconds -> frame index, so the clock can be compared to what | 112 | /// Timeline seconds -> frame index, so the clock can be compared to what |
| 108 | /// the decoder hands over. | 113 | /// the decoder hands over. |
| 109 | fps: f64, | 114 | fps: f64, |
| @@ -734,6 +739,7 @@ fn main() { | |||
| 734 | preview_session: None, | 739 | preview_session: None, |
| 735 | preview_playing: false, | 740 | preview_playing: false, |
| 736 | player_fullscreen: false, | 741 | player_fullscreen: false, |
| 742 | + loop_on: false, | ||
| 737 | // Full and unmuted, which is what the session it was just | 743 | // Full and unmuted, which is what the session it was just |
| 738 | // handed is already set to: nothing to push at startup. | 744 | // handed is already set to: nothing to push at startup. |
| 739 | volume: Volume::default(), | 745 | volume: Volume::default(), |
crates/app/src/oracle.rsmodified+3 -1
| @@ -273,7 +273,9 @@ pub(crate) fn enable(action: ActionId, ctx: Ctx) -> Enable { | |||
| 273 | // A clock started against an empty timeline is a clock counting | 273 | // A clock started against an empty timeline is a clock counting |
| 274 | // nothing: the transport says so by being dim, which is what its own | 274 | // nothing: the transport says so by being dim, which is what its own |
| 275 | // ad-hoc boolean used to say before the oracle knew the question. | 275 | // ad-hoc boolean used to say before the oracle knew the question. |
| 276 | - ActionId::Play if !ctx.playable => Enable::No("put a clip on a lane first"), | 276 | + ActionId::Play | ActionId::Loop if !ctx.playable => { |
| 277 | + Enable::No("put a clip on a lane first") | ||
| 278 | + } | ||
| 277 | // A rate applies to a clip of either kind and to its whole group, so | 279 | // A rate applies to a clip of either kind and to its whole group, so |
| 278 | // there is no lane it means nothing on, and the engine words the one | 280 | // there is no lane it means nothing on, and the engine words the one |
| 279 | // refusal there is (no room). Everything else is the editor's own and | 281 | // refusal there is (no room). Everything else is the editor's own and |
crates/app/src/player/actions.rsmodified+6 -0
| @@ -31,6 +31,12 @@ impl Player { | |||
| 31 | } | 31 | } |
| 32 | match action { | 32 | match action { |
| 33 | ActionId::Play => self.toggle_or_restart(cx), | 33 | ActionId::Play => self.toggle_or_restart(cx), |
| 34 | + // No session touched at all: the pump reads the flag itself at | ||
| 35 | + // the one place that already knows the end was reached. | ||
| 36 | + ActionId::Loop => { | ||
| 37 | + self.loop_on = !self.loop_on; | ||
| 38 | + cx.notify(); | ||
| 39 | + } | ||
| 34 | ActionId::StepBack => self.step(-1, cx), | 40 | ActionId::StepBack => self.step(-1, cx), |
| 35 | ActionId::StepForward => self.step(1, cx), | 41 | ActionId::StepForward => self.step(1, cx), |
| 36 | // A second is however many frames this timeline runs at. | 42 | // A second is however many frames this timeline runs at. |
crates/app/src/player/transport.rsmodified+34 -1
| @@ -154,7 +154,20 @@ impl Player { | |||
| 154 | // otherwise repaint at vsync forever. Held clear for as long as the | 154 | // otherwise repaint at vsync forever. Held clear for as long as the |
| 155 | // state does, not just on the crossing: nothing else is coming. | 155 | // state does, not just on the crossing: nothing else is coming. |
| 156 | self.seek_since = None; | 156 | self.seek_since = None; |
| 157 | - if was != Transport::Ended { | 157 | + if crosses_into_loop(was, Transport::Ended, self.loop_on) { |
| 158 | + // The same door the restart button and key use | ||
| 159 | + // ([`Player::toggle_or_restart`]), minus the `cx` that door | ||
| 160 | + // spends only on a repaint -- the pump is already inside one. | ||
| 161 | + // One seam of a one-frame seam: the restart is a fresh seek | ||
| 162 | + // and its reopen, not a gapless splice. | ||
| 163 | + if let Some(session) = self.active_session_mut() { | ||
| 164 | + session.seek(0.); | ||
| 165 | + } | ||
| 166 | + self.reset_after_reseek(); | ||
| 167 | + if let Some(session) = self.active_session_mut() { | ||
| 168 | + session.play(); | ||
| 169 | + } | ||
| 170 | + } else if was != Transport::Ended { | ||
| 158 | // Ended is a *stopped* transport, so the clock stops with it, | 171 | // Ended is a *stopped* transport, so the clock stops with it, |
| 159 | // on the out point the timecode and the playhead have been | 172 | // on the out point the timecode and the playhead have been |
| 160 | // showing all along. Nothing else ever stopped it: past the | 173 | // showing all along. Nothing else ever stopped it: past the |
| @@ -379,6 +392,14 @@ pub(crate) fn resync_due(late: f64, last: Option<Instant>, priming: bool) -> boo | |||
| 379 | !priming && should_resync(late, last) | 392 | !priming && should_resync(late, last) |
| 380 | } | 393 | } |
| 381 | 394 | ||
| 395 | +/// Whether *this* repaint is the one crossing into `Ended` with loop on -- | ||
| 396 | +/// the moment to restart rather than halt. `now` is always `Ended` at the one | ||
| 397 | +/// call site (it is inside that guard already), but taking it as a parameter | ||
| 398 | +/// keeps this checkable on its own instead of only through a live session. | ||
| 399 | +pub(crate) fn crosses_into_loop(was: Transport, now: Transport, loop_on: bool) -> bool { | ||
| 400 | + now == Transport::Ended && was != Transport::Ended && loop_on | ||
| 401 | +} | ||
| 402 | + | ||
| 382 | #[cfg(test)] | 403 | #[cfg(test)] |
| 383 | mod tests { | 404 | mod tests { |
| 384 | use super::*; | 405 | use super::*; |
| @@ -407,4 +428,16 @@ mod tests { | |||
| 407 | false | 428 | false |
| 408 | )); | 429 | )); |
| 409 | } | 430 | } |
| 431 | + | ||
| 432 | + /// The crossing fires exactly once per end and only with the flag on -- | ||
| 433 | + /// not on every repaint the transport happens to sit at `Ended` through, | ||
| 434 | + /// and not at all with loop off (which is the halt path this test would | ||
| 435 | + /// otherwise silently stop covering). | ||
| 436 | + #[test] | ||
| 437 | + fn the_loop_restarts_only_on_the_crossing_with_loop_on() { | ||
| 438 | + assert!(crosses_into_loop(Transport::Playing, Transport::Ended, true)); | ||
| 439 | + assert!(!crosses_into_loop(Transport::Playing, Transport::Ended, false)); | ||
| 440 | + assert!(!crosses_into_loop(Transport::Ended, Transport::Ended, true)); | ||
| 441 | + assert!(!crosses_into_loop(Transport::Ended, Transport::Playing, true)); | ||
| 442 | + } | ||
| 410 | } | 443 | } |
crates/app/src/ui/toolbar.rsmodified+17 -0
| @@ -201,6 +201,23 @@ impl Player { | |||
| 201 | ActionId::Play, | 201 | ActionId::Play, |
| 202 | cx.listener(|this, _: &ClickEvent, _, cx| this.toggle_or_restart(cx)), | 202 | cx.listener(|this, _: &ClickEvent, _, cx| this.toggle_or_restart(cx)), |
| 203 | )) | 203 | )) |
| 204 | + // Accented while on, the box the export button and the mute glyph | ||
| 205 | + // both use for a state rather than a click: the pump reads | ||
| 206 | + // `loop_on` itself at the one place it already knows the end was | ||
| 207 | + // reached ([`Player::pump`]). | ||
| 208 | + .child(self.action_control( | ||
| 209 | + "loop", | ||
| 210 | + 0., | ||
| 211 | + match self.loop_on { | ||
| 212 | + true => ACCENT_PRIMARY(), | ||
| 213 | + false => BG_RAISED(), | ||
| 214 | + }, | ||
| 215 | + None, | ||
| 216 | + "Loop", | ||
| 217 | + "restarts from the top on reaching the end, instead of stopping", | ||
| 218 | + ActionId::Loop, | ||
| 219 | + cx.listener(|this, _: &ClickEvent, window, cx| this.act(ActionId::Loop, window, cx)), | ||
| 220 | + )) | ||
| 204 | // One line, one fixed width: changing digits must not push the | 221 | // One line, one fixed width: changing digits must not push the |
| 205 | // strip around, and the clock is the one number that changes | 222 | // strip around, and the clock is the one number that changes |
| 206 | // sixty times a second. | 223 | // sixty times a second. |