From b45f7307a3cead47ed9568450a7888d80dbfd675 Mon Sep 17 00:00:00 2001 From: Olive Vaughn Date: Sat, 10 Oct 2026 20:31:20 -0400 Subject: [PATCH] Pause sticks while looping, play past the out mark, drag the marks Pause during a loop restarted at once: the player's snapshot still said playing for a frame after the clock stopped, and with marks that read as running off the end. It now asks the db. Playback loops only on crossing the out mark, so playing from past it plays on, as playing from before the in already did. The marks have handles on the ruler. = and - move the end of the selection's span, any symbol's, or the cel a selection in a lane is in, rippling what follows in a lane. Co-Authored-By: Claude Opus 5.5 --- frontend/src/arthur/events/playback.cljs | 23 +++++++++++++++++------ frontend/src/arthur/events/ui.cljs | 9 +++++++++ frontend/src/arthur/ui/player.cljs | 14 ++++++++++++-- frontend/src/arthur/ui/shortcuts.cljs | 6 ++++-- frontend/src/arthur/ui/timeline.cljs | 16 +++++++++++++++- static/arthur/app.css | 5 +++++ 6 files changed, 62 insertions(+), 11 deletions(-) diff --git a/frontend/src/arthur/events/playback.cljs b/frontend/src/arthur/events/playback.cljs index c5b81b6..59395f7 100644 --- a/frontend/src/arthur/events/playback.cljs +++ b/frontend/src/arthur/events/playback.cljs @@ -72,15 +72,15 @@ [(or in 0) (min (dec n) (or out (dec n)))])) (defn- start - "Play from the playhead, or from the in mark when the playhead is outside the - marks or on the last frame they allow. Playing the last frame alone is a - twenty-fourth of a second and then silence, so play there looked like a - button that did nothing." + "Play from the playhead, wherever it is — before the in mark or past the out + — or from the in mark when it is on the last frame. Playing the last frame + alone is a twenty-fourth of a second and then silence, so play there looked + like a button that did nothing." [db] (let [n (frames db) - [lo hi] (bounds db) + [lo] (bounds db) f (get-in db [:playback :frame] 0) - f (if (and (<= lo f) (< f hi)) f lo)] + f (if (< f (dec n)) f lo)] {:db (update db :playback assoc :playing? true :frame f) ::play-from! [(fps db) n f]})) @@ -123,6 +123,17 @@ :in (cond-> (assoc marks :in f) (and out (< out f)) (dissoc :out)) :out (cond-> (assoc marks :out f) (and in (< f in)) (dissoc :in)))))))) +(rf/reg-event-db + ::drag-mark + ;; A mark's handle dragged on the ruler: held short of the other mark rather + ;; than pushing it off, as a key does. + (fn [db [_ which f]] + (update-in db [:playback :range (get-in db [:ui :open])] + (fn [{:keys [in out] :as marks}] + (case which + :in (assoc marks :in (cond-> f out (min out))) + :out (assoc marks :out (cond-> f in (max in)))))))) + (rf/reg-event-db ::clear-marks (fn [db _] (update-in db [:playback :range] dissoc (get-in db [:ui :open])))) diff --git a/frontend/src/arthur/events/ui.cljs b/frontend/src/arthur/events/ui.cljs index 8d4b867..551c2ad 100644 --- a/frontend/src/arthur/events/ui.cljs +++ b/frontend/src/arthur/events/ui.cljs @@ -382,6 +382,15 @@ (let [t (creation/target clip st open selection f)] (when (= :lane (:kind t)) (lane-at (:path t))))))) +(defn span-path + "The row whose span = and − move: the selection's, or — inside a lane — the + cel the selection is in, so a stroke just drawn holds its drawing longer." + [db] + (let [path (vec (nth (get-in db [:ui :selection]) 3 nil)) + lane (some-> (lane-here db) :path count)] + (when (seq path) + (if (and lane (< lane (count path))) (subvec path 0 (inc lane)) path)))) + (rf/reg-event-fx ::drawing-here ;; K and ⇧K in a lane: see `span/drawing-at`. The new cel is selected and the diff --git a/frontend/src/arthur/ui/player.cljs b/frontend/src/arthur/ui/player.cljs index ec4a602..a31a1d8 100644 --- a/frontend/src/arthur/ui/player.cljs +++ b/frontend/src/arthur/ui/player.cljs @@ -35,6 +35,7 @@ [arthur.ui.tracing :as tracing] [arthur.ui.layout :as layout] [re-frame.core :as rf] + [re-frame.db :as rf-db] [reagent.ratom :as ratom])) (defonce ^:private state @@ -460,8 +461,12 @@ ;; PAST THE OUT MARK, BACK TO THE IN, as Blender's preview range loops. ;; Here rather than in either clock, so both backends loop the same ;; way, and before the paint, so the frame after the out is never shown. - wrap? (and live? range (< (or (:out range) (dec frames)) f)) + ;; CROSSING it, from a frame at or before it: played from past the out + ;; mark, playback goes on from there. + out (or (:out range) (dec frames)) + wrap? (and live? range (some-> (:played @state) (<= out)) (< out f)) f (if wrap? (or (:in range) 0) f)] + (swap! state assoc :played (when live? f)) (when wrap? (rf/dispatch [::pb/seek f])) ;; A paused scrub is an explicit seek, not a playback sample. Clear the ;; meter before the next play so its first frame cannot count the seek as @@ -489,7 +494,12 @@ ;; The audio ending is the authority on playback having stopped; nothing ;; counts frames to notice it. ;; With marks, running off the end goes round again from the in. - (when (and (not live?) playing?) + ;; + ;; THE DB, NOT THE SNAPSHOT, says whether it is meant to be playing. The + ;; snapshot catches up a frame late, so straight after a pause it still + ;; said playing — and with marks that read as running off the end and + ;; started it again, so pause never stuck while looping. + (when (and (not live?) playing? (get-in @rf-db/app-db [:playback :playing?])) (rf/dispatch (if range [::pb/play] [::pb/pause]))))) (defn- frame-loop [] diff --git a/frontend/src/arthur/ui/shortcuts.cljs b/frontend/src/arthur/ui/shortcuts.cljs index f66ad4a..f6496ad 100644 --- a/frontend/src/arthur/ui/shortcuts.cljs +++ b/frontend/src/arthur/ui/shortcuts.cljs @@ -76,8 +76,10 @@ :note "in a lane, a copy of the drawing from the playhead on" :run #(if (ui/lane-here %) [::ui/drawing-here true] [::ui/key-selected])} {:label "Blank drawing here" :keys ["shift+k"] :run (constantly [::ui/drawing-here false])} - {:label "Hold a frame longer" :keys ["=" "+"] :run (constantly [::ui/extend-hold 1 :grow-symbol])} - {:label "Hold a frame shorter" :keys ["-"] :run (constantly [::ui/extend-hold -1])}]] + {:label "One frame longer" :keys ["=" "+"] :note "moves the end of the selection's span" + :run #(when-let [p (ui/span-path %)] [::ui/slide p 1 :out true])} + {:label "One frame shorter" :keys ["-"] + :run #(when-let [p (ui/span-path %)] [::ui/slide p -1 :out true])}]] ["Draw" [{:label "Select" :keys ["v"] :run (constantly [::ui/tool-key "v"])} {:label "Pen" :keys ["p"] :run (constantly [::ui/tool-key "p"])} diff --git a/frontend/src/arthur/ui/timeline.cljs b/frontend/src/arthur/ui/timeline.cljs index 4b9407f..407bf53 100644 --- a/frontend/src/arthur/ui/timeline.cljs +++ b/frontend/src/arthur/ui/timeline.cljs @@ -1325,7 +1325,21 @@ (when-let [{:keys [in out]} @(rf/subscribe [::playback/range])] (let [lo (or in 0) hi (inc (min (dec frames) (or out (dec frames))))] (if ruler? - [:div.tl-range {:style {:left (edge% lo frames) :width (edge% (- hi lo) frames)}}] + [:<> + [:div.tl-range {:style {:left (edge% lo frames) :width (edge% (- hi lo) frames)}}] + (for [[which f at] [[:in in lo] [:out out hi]] :when f] + ^{:key which} + [:div.tl-mark + {:class (name which) :style {:left (edge% at frames)} + :title (str (name which) " mark · drag to move") + :on-pointer-down (fn [^js e] + (.stopPropagation e) + (try (.setPointerCapture (.-currentTarget e) (.-pointerId e)) + (catch :default _ nil))) + :on-pointer-move (fn [^js e] + (when (.hasPointerCapture (.-currentTarget e) (.-pointerId e)) + (rf/dispatch [::pb/drag-mark which + (frame-under e frames (.closest (.-currentTarget e) ".tl-ruler"))])))}])] [:<> (when (pos? lo) [:div.tl-outside {:style {:left 0 :width (edge% lo frames)}}]) (when (< hi frames) [:div.tl-outside {:style {:left (edge% hi frames) :right 0}}])])))) diff --git a/static/arthur/app.css b/static/arthur/app.css index 587de94..0477276 100644 --- a/static/arthur/app.css +++ b/static/arthur/app.css @@ -1964,3 +1964,8 @@ button.tl-key.selected { background: var(--pick); box-shadow: 0 0 0 2px var(--pi position: absolute; bottom: 0; height: 3px; pointer-events: none; background: var(--sel); } +.tl-mark { + position: absolute; top: 0; bottom: 0; z-index: 1; width: 9px; margin-left: -4px; + cursor: ew-resize; touch-action: none; + background: linear-gradient(var(--sel), var(--sel)) center / 2px 100% no-repeat; +}