I and O mark where playback loops, and the timeline dims the rest

Resolve's in and out marks, per tab. Play starts from the in mark when the
playhead is outside them and goes round from the out mark back to the in,
as Blender's preview range does; the loop is in the player's frame loop, so
both clocks do it the same way. Alt-X clears them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Olive Vaughn 2026-10-10 20:20:33 -04:00
parent 246b6d6468
commit 1c6c45e465
6 changed files with 72 additions and 8 deletions

View file

@ -63,14 +63,24 @@
(get-in db [:ui :gesture :auto-key?]) (get-in db [:ui :gesture :auto-key?])
(assoc :dispatch [:arthur.events.ui/record-gesture f]))))) (assoc :dispatch [:arthur.events.ui/record-gesture f])))))
(defn- start (defn bounds
"Play from the playhead, or from the top when the playhead is on the last "The frames playback runs between, both included: the open tab's in and out
frame. Playing the last frame alone is a twenty-fourth of a second and then marks, or the whole symbol where one is not set."
silence, so play there looked like a button that did nothing."
[db] [db]
(let [n (frames db) (let [n (frames db)
{:keys [in out]} (get-in db [:playback :range (get-in db [:ui :open])])]
[(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."
[db]
(let [n (frames db)
[lo hi] (bounds db)
f (get-in db [:playback :frame] 0) f (get-in db [:playback :frame] 0)
f (if (< f (dec n)) f 0)] f (if (and (<= lo f) (< f hi)) f lo)]
{:db (update db :playback assoc :playing? true :frame f) {:db (update db :playback assoc :playing? true :frame f)
::play-from! [(fps db) n f]})) ::play-from! [(fps db) n f]}))
@ -101,6 +111,22 @@
(fn [{:keys [db]} [_ delta]] (fn [{:keys [db]} [_ delta]]
{:fx [[:dispatch [::seek (+ (get-in db [:playback :frame]) delta)]]]})) {:fx [[:dispatch [::seek (+ (get-in db [:playback :frame]) delta)]]]}))
(rf/reg-event-db
::mark
;; Resolve's I and O, on the open tab. A mark the other one has passed goes,
;; rather than leaving a range that ends before it starts.
(fn [db [_ which]]
(let [f (get-in db [:playback :frame] 0)]
(update-in db [:playback :range (get-in db [:ui :open])]
(fn [{:keys [in out] :as marks}]
(case which
: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
::clear-marks
(fn [db _] (update-in db [:playback :range] dissoc (get-in db [:ui :open]))))
(rf/reg-event-fx (rf/reg-event-fx
::set-rate ::set-rate
(fn [{:keys [db]} [_ r]] (fn [{:keys [db]} [_ r]]

View file

@ -11,6 +11,7 @@
(rf/reg-sub ::rate (fn [db _] (get-in db [:playback :rate]))) (rf/reg-sub ::rate (fn [db _] (get-in db [:playback :rate])))
(rf/reg-sub ::loop? (fn [db _] (get-in db [:playback :loop?]))) (rf/reg-sub ::loop? (fn [db _] (get-in db [:playback :loop?])))
(rf/reg-sub ::muted? (fn [db _] (get-in db [:playback :muted?]))) (rf/reg-sub ::muted? (fn [db _] (get-in db [:playback :muted?])))
(rf/reg-sub ::range (fn [db _] (get-in db [:playback :range (get-in db [:ui :open])])))
(rf/reg-sub ::fps (fn [db _] (get-in db [:clip :fps]))) (rf/reg-sub ::fps (fn [db _] (get-in db [:clip :fps])))
;; The open symbol can have a local stage size; otherwise it follows the project. ;; The open symbol can have a local stage size; otherwise it follows the project.
(rf/reg-sub ::stage-size (rf/reg-sub ::stage-size

View file

@ -128,6 +128,7 @@
:tracing (rf/subscribe [::render/tracing]) :tracing (rf/subscribe [::render/tracing])
:frame (rf/subscribe [::sub/frame]) :frame (rf/subscribe [::sub/frame])
:playing? (rf/subscribe [::sub/playing?]) :playing? (rf/subscribe [::sub/playing?])
:range (rf/subscribe [::sub/range])
;; The pen's draft is drawn INTO the picture, filled, so what is on screen ;; The pen's draft is drawn INTO the picture, filled, so what is on screen
;; while placing points is the pixels a finished shape will be. ;; while placing points is the pixels a finished shape will be.
:draft (rf/subscribe [::ui-sub/draft]) :draft (rf/subscribe [::ui-sub/draft])
@ -449,13 +450,19 @@
(atom nil)) (atom nil))
(defn- tick! [] (defn- tick! []
(let [{:keys [fps frames frame playing?]} @snapshot (let [{:keys [fps frames frame playing? range]} @snapshot
live? (clock/playing?) live? (clock/playing?)
ready? (some? (:canvas @state)) ready? (some? (:canvas @state))
;; DERIVED, never counted. A slow frame drops the frames it missed and ;; DERIVED, never counted. A slow frame drops the frames it missed and
;; the next one lands where the audio already is, so the failure mode is ;; the next one lands where the audio already is, so the failure mode is
;; a visible stutter rather than an invisible slide out of sync. ;; a visible stutter rather than an invisible slide out of sync.
f (if live? (clock/frame fps frames) frame)] f (if live? (clock/frame fps frames) frame)
;; 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))
f (if wrap? (or (:in range) 0) f)]
(when wrap? (rf/dispatch [::pb/seek f]))
;; A paused scrub is an explicit seek, not a playback sample. Clear the ;; 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 ;; meter before the next play so its first frame cannot count the seek as
;; dropped frames or leave a stale low rate in the transport. ;; dropped frames or leave a stale low rate in the transport.
@ -481,8 +488,9 @@
(when live? (rf/dispatch [::pb/tick f]))) (when live? (rf/dispatch [::pb/tick f])))
;; The audio ending is the authority on playback having stopped; nothing ;; The audio ending is the authority on playback having stopped; nothing
;; counts frames to notice it. ;; counts frames to notice it.
;; With marks, running off the end goes round again from the in.
(when (and (not live?) playing?) (when (and (not live?) playing?)
(rf/dispatch [::pb/pause])))) (rf/dispatch (if range [::pb/play] [::pb/pause])))))
(defn- frame-loop [] (defn- frame-loop []
;; Scheduled BEFORE the tick, so nothing the tick does can end the loop. ;; Scheduled BEFORE the tick, so nothing the tick does can end the loop.

View file

@ -64,6 +64,10 @@
:run #(some-> (first (subseq (stops %) > (frame %))) seek)} :run #(some-> (first (subseq (stops %) > (frame %))) seek)}
{:label "First frame" :keys ["Home" "shift+ArrowLeft" "shift+a"] :run (constantly (seek 0))} {:label "First frame" :keys ["Home" "shift+ArrowLeft" "shift+a"] :run (constantly (seek 0))}
{:label "Last frame" :keys ["End" "shift+ArrowRight" "shift+d"] :run #(seek (dec (pb/frames %)))} {:label "Last frame" :keys ["End" "shift+ArrowRight" "shift+d"] :run #(seek (dec (pb/frames %)))}
{:label "Mark in" :keys ["i"] :run (constantly [::pb/mark :in])
:note "playback loops between the marks"}
{:label "Mark out" :keys ["o"] :run (constantly [::pb/mark :out])}
{:label "Clear the marks" :keys ["alt+x"] :run (constantly [::pb/clear-marks])}
{:label "Onion skin" :keys ["alt+o"] {:label "Onion skin" :keys ["alt+o"]
:run #(let [on? (get-in % [:ui :onion (:clip/current %) (get-in % [:ui :open]) :on?])] :run #(let [on? (get-in % [:ui :onion (:clip/current %) (get-in % [:ui :open]) :on?])]
[::layout/onion :on? (not on?)])}]] [::layout/onion :on? (not on?)])}]]

View file

@ -1318,6 +1318,18 @@
[tag frames] [tag frames]
[tag {:style {:left (at% @(rf/subscribe [::render/open-frame]) frames)}}]) [tag {:style {:left (at% @(rf/subscribe [::render/open-frame]) frames)}}])
(defn- outside-marks
"The frames playback leaves out, shaded, and the span it plays, banded on the
ruler. Its own component, deref'ing the marks itself, as `playhead` does."
[frames ruler?]
(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)}}]
[:<>
(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}}])]))))
(defn- key-marquee [marquee] (defn- key-marquee [marquee]
(when-let [{:keys [x y x2 y2]} @marquee] (when-let [{:keys [x y x2 y2]} @marquee]
(when (and x2 y2) (when (and x2 y2)
@ -1594,6 +1606,7 @@
(doall (doall
(for [f (range 0 frames step)] (for [f (range 0 frames step)]
^{:key f} [:div.tick {:style {:left (edge% f frames)}} f])) ^{:key f} [:div.tick {:style {:left (edge% f frames)}} f]))
[outside-marks frames true]
[playhead :div.tl-knob frames]] [playhead :div.tl-knob frames]]
(if (seq visible) (if (seq visible)
(doall (for [row visible] (doall (for [row visible]
@ -1606,6 +1619,7 @@
:key-anchor key-anchor :key-state key-state :key-elements key-elements :choose-row! choose-row!}]) :key-anchor key-anchor :key-state key-state :key-elements key-elements :choose-row! choose-row!}])
{:key (str (:path row))}))) {:key (str (:path row))})))
[:div.tl-empty "nothing in this symbol"]) [:div.tl-empty "nothing in this symbol"])
[outside-marks frames false]
[playhead :div.tl-playhead frames] [playhead :div.tl-playhead frames]
[key-marquee marquee]]] [key-marquee marquee]]]
[cursor-hint hint]]))) [cursor-hint hint]])))

View file

@ -1953,3 +1953,14 @@ button.tl-key.selected { background: var(--pick); box-shadow: 0 0 0 2px var(--pi
min-width: 1.6em; padding: 0 5px; text-align: center; font: inherit; font-size: .92em; min-width: 1.6em; padding: 0 5px; text-align: center; font: inherit; font-size: .92em;
background: var(--chrome); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 3px; background: var(--chrome); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 3px;
} }
/* What the in and out marks leave out of playback: dimmed over the tracks, and
the span that plays banded along the foot of the ruler. */
.tl-outside {
position: absolute; top: 0; bottom: 0; z-index: 2; pointer-events: none;
background: rgba(0, 0, 0, .16);
}
.tl-range {
position: absolute; bottom: 0; height: 3px; pointer-events: none;
background: var(--sel);
}