diff --git a/frontend/src/arthur/events/playback.cljs b/frontend/src/arthur/events/playback.cljs index 8687a7f..c5b81b6 100644 --- a/frontend/src/arthur/events/playback.cljs +++ b/frontend/src/arthur/events/playback.cljs @@ -63,14 +63,24 @@ (get-in db [:ui :gesture :auto-key?]) (assoc :dispatch [:arthur.events.ui/record-gesture f]))))) -(defn- start - "Play from the playhead, or from the top when the playhead 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." +(defn bounds + "The frames playback runs between, both included: the open tab's in and out + marks, or the whole symbol where one is not set." [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 (if (< f (dec n)) f 0)] + f (if (and (<= lo f) (< f hi)) f lo)] {:db (update db :playback assoc :playing? true :frame f) ::play-from! [(fps db) n f]})) @@ -101,6 +111,22 @@ (fn [{:keys [db]} [_ 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 ::set-rate (fn [{:keys [db]} [_ r]] diff --git a/frontend/src/arthur/subs/playback.cljs b/frontend/src/arthur/subs/playback.cljs index 01c615f..0cd8ca3 100644 --- a/frontend/src/arthur/subs/playback.cljs +++ b/frontend/src/arthur/subs/playback.cljs @@ -11,6 +11,7 @@ (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 ::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]))) ;; The open symbol can have a local stage size; otherwise it follows the project. (rf/reg-sub ::stage-size diff --git a/frontend/src/arthur/ui/player.cljs b/frontend/src/arthur/ui/player.cljs index b18fb22..ec4a602 100644 --- a/frontend/src/arthur/ui/player.cljs +++ b/frontend/src/arthur/ui/player.cljs @@ -128,6 +128,7 @@ :tracing (rf/subscribe [::render/tracing]) :frame (rf/subscribe [::sub/frame]) :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 ;; while placing points is the pixels a finished shape will be. :draft (rf/subscribe [::ui-sub/draft]) @@ -449,13 +450,19 @@ (atom nil)) (defn- tick! [] - (let [{:keys [fps frames frame playing?]} @snapshot + (let [{:keys [fps frames frame playing? range]} @snapshot live? (clock/playing?) ready? (some? (:canvas @state)) ;; 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 ;; 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 ;; 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. @@ -481,8 +488,9 @@ (when live? (rf/dispatch [::pb/tick f]))) ;; 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?) - (rf/dispatch [::pb/pause])))) + (rf/dispatch (if range [::pb/play] [::pb/pause]))))) (defn- frame-loop [] ;; Scheduled BEFORE the tick, so nothing the tick does can end the loop. diff --git a/frontend/src/arthur/ui/shortcuts.cljs b/frontend/src/arthur/ui/shortcuts.cljs index 989afe0..f66ad4a 100644 --- a/frontend/src/arthur/ui/shortcuts.cljs +++ b/frontend/src/arthur/ui/shortcuts.cljs @@ -64,6 +64,10 @@ :run #(some-> (first (subseq (stops %) > (frame %))) seek)} {: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 "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"] :run #(let [on? (get-in % [:ui :onion (:clip/current %) (get-in % [:ui :open]) :on?])] [::layout/onion :on? (not on?)])}]] diff --git a/frontend/src/arthur/ui/timeline.cljs b/frontend/src/arthur/ui/timeline.cljs index 7583a1d..4b9407f 100644 --- a/frontend/src/arthur/ui/timeline.cljs +++ b/frontend/src/arthur/ui/timeline.cljs @@ -1318,6 +1318,18 @@ [tag 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] (when-let [{:keys [x y x2 y2]} @marquee] (when (and x2 y2) @@ -1594,6 +1606,7 @@ (doall (for [f (range 0 frames step)] ^{:key f} [:div.tick {:style {:left (edge% f frames)}} f])) + [outside-marks frames true] [playhead :div.tl-knob frames]] (if (seq 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 (str (:path row))}))) [:div.tl-empty "nothing in this symbol"]) + [outside-marks frames false] [playhead :div.tl-playhead frames] [key-marquee marquee]]] [cursor-hint hint]]))) diff --git a/static/arthur/app.css b/static/arthur/app.css index 459866e..587de94 100644 --- a/static/arthur/app.css +++ b/static/arthur/app.css @@ -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; 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); +}