From 935d48bba83e21b24c6e0af42ee4815f6d15375f 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:27:07 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(app):=20the=20playhead=20can?= =?UTF-8?q?=20loop,=20on=20the=20timeline=20and=20in=20a=20preview?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A Loop toggle (transport bar button, bare r) restarts playback from zero on the end crossing instead of halting — the same restart door play-at-end already used, so loop-off semantics are untouched. One flag serves both sessions: pump loops whichever is active. The wrap reopens the decoder; a one-frame seam is the accepted cost. --- crates/app/src/keymap.rs | 14 +++++++++++- crates/app/src/main.rs | 6 +++++ crates/app/src/oracle.rs | 4 +++- crates/app/src/player/actions.rs | 6 +++++ crates/app/src/player/transport.rs | 35 +++++++++++++++++++++++++++++- crates/app/src/ui/toolbar.rs | 17 +++++++++++++++ 6 files changed, 79 insertions(+), 3 deletions(-) diff --git a/crates/app/src/keymap.rs b/crates/app/src/keymap.rs index cdac516..559068a 100644 --- a/crates/app/src/keymap.rs +++ b/crates/app/src/keymap.rs @@ -62,6 +62,11 @@ macro_rules! actions { actions! { Play, + /// Whether the active session -- the timeline or a library preview -- + /// restarts from the top on reaching its end instead of stopping there. + /// Live exactly where Play is: a transport with nothing under it has + /// nothing to loop either. + Loop, StepBack, StepForward, JumpBack, @@ -156,6 +161,7 @@ impl ActionId { pub fn label(self) -> &'static str { match self { ActionId::Play => "Play / Pause", + ActionId::Loop => "Loop the playhead's end", ActionId::StepBack => "One frame back", ActionId::StepForward => "One frame forward", ActionId::JumpBack => "One second back", @@ -220,6 +226,7 @@ impl ActionId { fn name(self) -> &'static str { match self { ActionId::Play => "play", + ActionId::Loop => "loop", ActionId::StepBack => "step-back", ActionId::StepForward => "step-forward", ActionId::JumpBack => "jump-back", @@ -286,6 +293,7 @@ impl ActionId { pub fn category(self) -> Category { match self { ActionId::Play + | ActionId::Loop | ActionId::StepBack | ActionId::StepForward | ActionId::JumpBack @@ -793,6 +801,10 @@ impl Keymap { Keymap { bindings: vec![ b(ActionId::Play, "space", false), + // "r" for repeat, free and bare: its ctrl chord is already the + // project resolution, and the two read as a pair the way the + // mute and its level do. + b(ActionId::Loop, "r", false), // Seeking without a pointer, on the keys every player already // seeks with (gpui names them "left"/"right"/"home"/"end", // platform.rs:872-877). The colour card reads the same arrows @@ -1219,7 +1231,7 @@ mod tests { #[test] fn every_default_stroke_reaches_its_action() { let k = Keymap::defaults(); - assert_eq!(k.entries().len(), 56); + assert_eq!(k.entries().len(), 57); assert_eq!(k.lookup("f11", false), Some(ActionId::Fullscreen)); assert_eq!(k.lookup("w", false), Some(ActionId::Screenshot)); assert_eq!(k.lookup("y", false), Some(ActionId::SubtitleStyle)); diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index f8a016f..a595d46 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -104,6 +104,11 @@ struct Player { /// about it, so [`Player::act`] reconciles them rather than trusting /// either alone. player_fullscreen: bool, + /// Whether the active session -- the timeline or a library preview, + /// whichever [`Player::active_session`] is reading -- restarts from the + /// top on reaching its end instead of stopping there. One flag for both, + /// since only one of them is ever playing at a time. + loop_on: bool, /// Timeline seconds -> frame index, so the clock can be compared to what /// the decoder hands over. fps: f64, @@ -734,6 +739,7 @@ fn main() { preview_session: None, preview_playing: false, player_fullscreen: false, + loop_on: false, // Full and unmuted, which is what the session it was just // handed is already set to: nothing to push at startup. volume: Volume::default(), diff --git a/crates/app/src/oracle.rs b/crates/app/src/oracle.rs index 6c0998d..65babbe 100644 --- a/crates/app/src/oracle.rs +++ b/crates/app/src/oracle.rs @@ -273,7 +273,9 @@ pub(crate) fn enable(action: ActionId, ctx: Ctx) -> Enable { // A clock started against an empty timeline is a clock counting // nothing: the transport says so by being dim, which is what its own // ad-hoc boolean used to say before the oracle knew the question. - ActionId::Play if !ctx.playable => Enable::No("put a clip on a lane first"), + ActionId::Play | ActionId::Loop if !ctx.playable => { + Enable::No("put a clip on a lane first") + } // A rate applies to a clip of either kind and to its whole group, so // there is no lane it means nothing on, and the engine words the one // refusal there is (no room). Everything else is the editor's own and diff --git a/crates/app/src/player/actions.rs b/crates/app/src/player/actions.rs index 2e65e76..78f817b 100644 --- a/crates/app/src/player/actions.rs +++ b/crates/app/src/player/actions.rs @@ -31,6 +31,12 @@ impl Player { } match action { ActionId::Play => self.toggle_or_restart(cx), + // No session touched at all: the pump reads the flag itself at + // the one place that already knows the end was reached. + ActionId::Loop => { + self.loop_on = !self.loop_on; + cx.notify(); + } ActionId::StepBack => self.step(-1, cx), ActionId::StepForward => self.step(1, cx), // A second is however many frames this timeline runs at. diff --git a/crates/app/src/player/transport.rs b/crates/app/src/player/transport.rs index 5578750..723e728 100644 --- a/crates/app/src/player/transport.rs +++ b/crates/app/src/player/transport.rs @@ -154,7 +154,20 @@ impl Player { // otherwise repaint at vsync forever. Held clear for as long as the // state does, not just on the crossing: nothing else is coming. self.seek_since = None; - if was != Transport::Ended { + if crosses_into_loop(was, Transport::Ended, self.loop_on) { + // The same door the restart button and key use + // ([`Player::toggle_or_restart`]), minus the `cx` that door + // spends only on a repaint -- the pump is already inside one. + // One seam of a one-frame seam: the restart is a fresh seek + // and its reopen, not a gapless splice. + if let Some(session) = self.active_session_mut() { + session.seek(0.); + } + self.reset_after_reseek(); + if let Some(session) = self.active_session_mut() { + session.play(); + } + } else if was != Transport::Ended { // Ended is a *stopped* transport, so the clock stops with it, // on the out point the timecode and the playhead have been // showing all along. Nothing else ever stopped it: past the @@ -379,6 +392,14 @@ pub(crate) fn resync_due(late: f64, last: Option, priming: bool) -> boo !priming && should_resync(late, last) } +/// Whether *this* repaint is the one crossing into `Ended` with loop on -- +/// the moment to restart rather than halt. `now` is always `Ended` at the one +/// call site (it is inside that guard already), but taking it as a parameter +/// keeps this checkable on its own instead of only through a live session. +pub(crate) fn crosses_into_loop(was: Transport, now: Transport, loop_on: bool) -> bool { + now == Transport::Ended && was != Transport::Ended && loop_on +} + #[cfg(test)] mod tests { use super::*; @@ -407,4 +428,16 @@ mod tests { false )); } + + /// The crossing fires exactly once per end and only with the flag on -- + /// not on every repaint the transport happens to sit at `Ended` through, + /// and not at all with loop off (which is the halt path this test would + /// otherwise silently stop covering). + #[test] + fn the_loop_restarts_only_on_the_crossing_with_loop_on() { + assert!(crosses_into_loop(Transport::Playing, Transport::Ended, true)); + assert!(!crosses_into_loop(Transport::Playing, Transport::Ended, false)); + assert!(!crosses_into_loop(Transport::Ended, Transport::Ended, true)); + assert!(!crosses_into_loop(Transport::Ended, Transport::Playing, true)); + } } diff --git a/crates/app/src/ui/toolbar.rs b/crates/app/src/ui/toolbar.rs index ca45f5e..a6a795a 100644 --- a/crates/app/src/ui/toolbar.rs +++ b/crates/app/src/ui/toolbar.rs @@ -201,6 +201,23 @@ impl Player { ActionId::Play, cx.listener(|this, _: &ClickEvent, _, cx| this.toggle_or_restart(cx)), )) + // Accented while on, the box the export button and the mute glyph + // both use for a state rather than a click: the pump reads + // `loop_on` itself at the one place it already knows the end was + // reached ([`Player::pump`]). + .child(self.action_control( + "loop", + 0., + match self.loop_on { + true => ACCENT_PRIMARY(), + false => BG_RAISED(), + }, + None, + "Loop", + "restarts from the top on reaching the end, instead of stopping", + ActionId::Loop, + cx.listener(|this, _: &ClickEvent, window, cx| this.act(ActionId::Loop, window, cx)), + )) // One line, one fixed width: changing digits must not push the // strip around, and the clock is the one number that changes // sixty times a second.