diff --git a/frontend/src/arthur/ui/icon.cljs b/frontend/src/arthur/ui/icon.cljs index 7c986b4..60d147a 100644 --- a/frontend/src/arthur/ui/icon.cljs +++ b/frontend/src/arthur/ui/icon.cljs @@ -30,6 +30,7 @@ (def ^:private glyphs {:start {:fill ["M2 2.5h1.3v7H2z" ; the bar it stops against "M10 2.5v7L4.2 6z"]} ; and the triangle into it + :end {:fill ["M8.7 2.5H10v7H8.7z" "M2 2.5v7L7.8 6z"]} :play {:fill ["M3.4 2.3L10 6 3.4 9.7z"]} :pause {:fill ["M3.3 2.4h1.9v7.2H3.3z" "M6.8 2.4h1.9v7.2H6.8z"]} diff --git a/frontend/src/arthur/ui/shortcuts.cljs b/frontend/src/arthur/ui/shortcuts.cljs index 8b9045d..64b2c75 100644 --- a/frontend/src/arthur/ui/shortcuts.cljs +++ b/frontend/src/arthur/ui/shortcuts.cljs @@ -24,7 +24,6 @@ (:require [arthur.events.history :as history] [arthur.events.playback :as pb] [arthur.events.ui :as ui] - [arthur.footage.store :as store] [arthur.ui.layout :as layout] [arthur.ui.timeline :as timeline] [clojure.string :as str] @@ -32,27 +31,6 @@ [re-frame.db :as db] [reagent.core :as r])) -(defn stops - "The frames ↑ and ↓ stop on: every key and every clip edge the timeline shows, - as frames of the open symbol. In a lane that is drawing to drawing, on a tween - key to key — one rule, read off the rows the timeline draws, so a jump lands - on something you can see." - [db] - (let [{document :clip} (store/entry (:clip/current db)) - selection (get-in db [:ui :selection]) - n (pb/frames db)] - (into (sorted-set) - (comp (mapcat (fn [{:keys [keys span cels]}] - (concat keys span (mapcat (juxt :span :keys) cels)))) - (mapcat #(if (number? %) [%] %)) - ;; The first whole frame that shows it, forgiving the rounding - ;; a mapped key picks up on its way through a clock. - (map #(js/Math.ceil (- % 1e-6))) - (filter #(< -1 % n))) - (when document - (timeline/rows document (get-in db [:ui :open]) (get-in db [:ui :expanded]) - (when (= :node (first selection)) (nth selection 3))))))) - (defn- frame [db] (get-in db [:playback :frame] 0)) (defn- seek [f] [::pb/seek f]) @@ -62,12 +40,10 @@ :note "hold and drag on the stage to pan"} {:label "Previous frame" :keys ["ArrowLeft" "a"] :run #(seek (dec (frame %)))} {:label "Next frame" :keys ["ArrowRight" "d"] :run #(seek (inc (frame %)))} - {:label "Previous key" :keys ["ArrowDown" "s"] - :run #(some-> (first (rsubseq (stops %) < (frame %))) seek)} - {:label "Next key" :keys ["ArrowUp" "w"] - :run #(some-> (first (subseq (stops %) > (frame %))) seek)} + {:label "Previous key" :keys ["ArrowDown" "s"] :run timeline/prev-key} + {:label "Next key" :keys ["ArrowUp" "w"] :run timeline/next-key} {: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 timeline/last-frame} {: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])} @@ -83,12 +59,12 @@ ["Animate" [{:label "Key here" :keys ["k"] :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])} + :run timeline/key-here} {:label "Blank drawing here" :keys ["shift+k"] :run (constantly [::ui/drawing-here false])} {: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])} + :run (timeline/hold 1)} {:label "One frame shorter" :keys ["-"] - :run #(when-let [p (ui/span-path %)] [::ui/slide p -1 :out true])}]] + :run (timeline/hold -1)}]] ["Make" [{:label "New symbol" :keys ["n"] :run (constantly [::ui/new :inside false]) :note "in the selected symbol; in a lane, a blank drawing"} diff --git a/frontend/src/arthur/ui/timeline.cljs b/frontend/src/arthur/ui/timeline.cljs index 93e5af4..fa6dc86 100644 --- a/frontend/src/arthur/ui/timeline.cljs +++ b/frontend/src/arthur/ui/timeline.cljs @@ -41,6 +41,7 @@ [arthur.ui.layout :as layout] [arthur.ui.player :as player] [re-frame.core :as rf] + [re-frame.db :as rf-db] [reagent.core :as r])) ;; --------------------------------------------------------------------------- @@ -497,9 +498,60 @@ (aget cel "arthurCel"))) (array-seq (.elementsFromPoint js/document (.-clientX event) (.-clientY event))))) +(defn stops + "The frames ↑ and ↓ stop on: every key and every clip edge the timeline shows, + as frames of the open symbol. In a lane that is drawing to drawing, on a tween + key to key — one rule, read off the rows the timeline draws, so a jump lands + on something you can see." + [db] + (let [{document :clip} (store/entry (:clip/current db)) + selection (get-in db [:ui :selection]) + n (pb/frames db)] + (into (sorted-set) + (comp (mapcat (fn [{:keys [keys span cels]}] + (concat keys span (mapcat (juxt :span :keys) cels)))) + (mapcat #(if (number? %) [%] %)) + ;; The first whole frame that shows it, forgiving the rounding + ;; a mapped key picks up on its way through a clock. + (map #(js/Math.ceil (- % 1e-6))) + (filter #(< -1 % n))) + (when document + (rows document (get-in db [:ui :open]) (get-in db [:ui :expanded]) + (when (= :node (first selection)) (nth selection 3))))))) + +(defn- at [db] (get-in db [:playback :frame] 0)) + +;; WHAT A KEY AND ITS BUTTON BOTH SEND, as functions of the db answering the +;; event, or nil for nothing to do. `ui/shortcuts` puts them on keys and the +;; toolbar on buttons, so the two cannot come to mean different things. + +(defn prev-key [db] (some->> (first (rsubseq (stops db) < (at db))) (vector ::pb/seek))) +(defn next-key [db] (some->> (first (subseq (stops db) > (at db))) (vector ::pb/seek))) +(defn last-frame [db] [::pb/seek (dec (pb/frames db))]) + +(defn key-here + "K: in a lane, a new drawing from the playhead on, copying the one there; on + anything else, a key of what is selected." + [db] + (if (ui/lane-here db) [::ui/drawing-here true] [::ui/key-selected])) + +(defn hold + "= and −: the end of the selection's span, `delta` frames later." + [delta] + (fn [db] (when-let [p (ui/span-path db)] [::ui/slide p delta :out true]))) + +(rf/reg-sub + ::here + ;; Which of the toolbar's commands mean something for the selection right now. + (fn [db _] + {:lane? (some? (ui/lane-here db)) + :span? (some? (ui/span-path db))})) + ;; --------------------------------------------------------------------------- ;; the panes +(def ^:private speeds [[0.25 "¼×"] [0.5 "½×"] [1 "1×"] [2 "2×"] [4 "4×"]]) + (defn- transport [] (let [playing? @(rf/subscribe [::playback/playing?]) rate @(rf/subscribe [::playback/rate]) @@ -536,14 +588,27 @@ host (when (number? owner-frame) (span/host-frame clip sid id owner-frame)) cuttable? (and span? (integer? host) (let [[lo hi] (node/placed-span n)] (< lo host hi))) - act (fn [event] #(rf/dispatch event))] + act (fn [event] #(rf/dispatch event)) + ;; A command that reads the db when it is pressed, as a key does. + run (fn [f] #(some-> (f @rf-db/app-db) rf/dispatch)) + here @(rf/subscribe [::here]) + marks @(rf/subscribe [::playback/range]) + selections @(rf/subscribe [::sub/selections]) + ;; A peg goes over ONE node: it takes that node's place in the + ;; hierarchy, and there is no one place a pair of them would go. + one-node (when (= 1 (count selections)) + (let [[kind _ _ path] (first selections)] + (when (and (= :node kind) (seq path)) path)))] [:div.pane-head ;; ----------------------------------------------------------------- time ;; Where the playhead is and how it moves. Nothing here depends on a ;; selection, which is why it is the one group that is never greyed. + ;; Blender's timeline header: the ends, the keys, a frame, play. [:div.group [:button.ico {:aria-label "go to start" :title "go to the first frame (Home)" :on-click (act [::pb/seek 0])} [icon/view :start]] + [:button.ico {:aria-label "previous key" :title "back to the key or drawing before (↓ or S)" + :on-click (run prev-key)} [icon/view :prev]] [:button {:aria-label "−1" :title "step back one frame (← or A)" :on-click (act [::pb/step -1])} "−1"] [:button.ico.ico-play {:aria-label (if playing? "pause" "play") @@ -551,7 +616,11 @@ :on-click (act [::pb/toggle])} [icon/view (if playing? :pause :play)]] [:button {:aria-label "+1" :title "step forward one frame (→ or D)" - :on-click (act [::pb/step 1])} "+1"]] + :on-click (act [::pb/step 1])} "+1"] + [:button.ico {:aria-label "next key" :title "on to the key or drawing after (↑ or W)" + :on-click (run next-key)} [icon/view :next]] + [:button.ico {:aria-label "go to end" :title "go to the last frame (End)" + :on-click (run last-frame)} [icon/view :end]]] [:div.group [:button.ico {:class (when loop? "on") :aria-label "loop" :title "loop playback" :on-click (act [::pb/toggle-loop])} @@ -563,36 +632,68 @@ ;; read WHILE scrubbing, and tabular figures keep it from twitching as it ;; counts. [:span.readout.at-frame (str frame " / " frames)] - ;; Five buttons for one mutually exclusive choice that is 1× almost always. - ;; A select says "pick one of these" in the width of the answer. - ;; playbackRate on the audio element and nothing else: the sound slows, - ;; currentTime advances proportionally, and the derived frame follows. Slow - ;; motion cannot desync by construction. - [:span.pick - [:select {:value rate :aria-label "playback speed" :title "playback speed" - :on-change #(rf/dispatch [::pb/set-rate - (js/parseFloat (.. % -target -value))])} - (doall (for [[r label] [[0.25 "¼×"] [0.5 "½×"] [1.0 "1×"] [2.0 "2×"] [4.0 "4×"]]] - ^{:key r} [:option {:value r} label]))]] - [:span.sep] - ;; The same direct timing operations apply to any selected symbol clip, - ;; whether it is placed freely or lives in a lane. - [:div.group.timing-controls {:aria-label "timing"} - [:button {:disabled (not cuttable?) :aria-label "split" - :title "split the selected clip at the playhead" - :on-click (act [::ui/split])} "split"] - [:button {:disabled (not cuttable?) :aria-label "trim in" - :title "move the selected clip's start to the playhead" - :on-click (act [::ui/trim :in])} "in"] - [:button {:disabled (not cuttable?) :aria-label "trim out" - :title "move the selected clip's end to the playhead" - :on-click (act [::ui/trim :out])} "out"]] + ;; ONE BUTTON THAT SAYS THE SPEED AND STEPS IT, rather than a menu: it is + ;; 1× almost always, and a click is all the other four are away. Shift goes + ;; back. playbackRate on the audio element and nothing else: the sound + ;; slows, currentTime advances proportionally, and the derived frame + ;; follows. Slow motion cannot desync by construction. + (let [i (or (first (keep-indexed #(when (= rate (first %2)) %1) speeds)) 2)] + [:button.speed {:class (when (not= 1 rate) "on") :aria-label "playback speed" + :title "playback speed · click for faster, shift-click for slower" + :on-click (fn [^js e] + (let [j (mod (+ i (if (.-shiftKey e) -1 1)) (count speeds))] + (rf/dispatch [::pb/set-rate (first (nth speeds j))])))} + (second (nth speeds i))]) + ;; Resolve's I and O: where playback loops in the open tab. Lit while set, + ;; and shift takes one away, as on the keys. + [:div.group {:aria-label "loop marks"} + (doall + (for [[which word k] [[:in "in" "I"] [:out "out" "O"]]] + ^{:key which} + [:button {:class (when (get marks which) "on") + :title (str "mark " word " at the playhead (" k ")" + " · shift-click clears it (⇧" k ")") + :on-click (fn [^js e] + (rf/dispatch (if (.-shiftKey e) + [::pb/clear-mark which] + [::pb/mark which])))} + word]))] [:span.sep] + ;; WHAT THE SELECTION CAN HAVE DONE TO IT, and nothing else. A drawing in + ;; a lane takes a new drawing and a longer hold; a symbol placed anywhere + ;; takes a cut and a longer span; a node takes a key and a peg. Shown, not + ;; greyed, so the strip says what is possible here, and each says its key. + (let [{:keys [lane?] hold? :span?} here] + [:div.group.context-controls {:aria-label "selection"} + (when (or lane? one-node) + [:button {:title (if lane? + "a new drawing from the playhead on, copying the one there (K)" + "key the selection at the playhead (K)") + :on-click (run key-here)} "◆ key"]) + (when lane? + [:button {:title "a blank drawing from the playhead on (⇧K)" + :on-click (act [::ui/drawing-here false])} "□ blank"]) + (when hold? + [:<> + [:button {:aria-label "one frame shorter" :title "one frame shorter (−)" + :on-click (run (hold -1))} "−"] + [:button {:aria-label "one frame longer" :title "one frame longer (=)" + :on-click (run (hold 1))} "="]]) + (when cuttable? + [:button {:title "split the selected clip at the playhead" + :on-click (act [::ui/split])} "split"]) + (when (and one-node (not lane?)) + ;; The only way to keep a pivot, and the only way to transform a + ;; measured part by hand — which is what `gesture/refusal` tells you + ;; to do, so it has to be reachable from somewhere. + [:button {:title "a transform node over the selection · ⌃/⌘-drag its cross to place the pivot" + :on-click (act [::ui/peg one-node])} "peg"])]) + [:span.spacer] [:div.group.creation-controls {:aria-label "create"} - [:button {:title "create a symbol in the selected location" + [:button {:title "create a symbol in the selected location (N)" :on-click (act [::ui/new-symbol :inside])} [icon/view :symbol] " symbol"] - [:button {:title "create a lane in the selected location" + [:button {:title "create a lane in the selected location (⇧N)" :on-click (act [::ui/new-lane])} [icon/view :lane] " lane"]] [:button.auto-key {:class (when auto? "on") @@ -602,7 +703,7 @@ "auto-key edited parameters at this frame") :on-click (act [::ui/toggle-auto-key])} "◆ auto key"] - [:span.spacer] + [:span.sep] ;; How many pixels a frame is. The tracks are positioned in percentages of ;; their own width, so this is one custom property on the grid and no ;; arithmetic here — see `ui/layout`. diff --git a/frontend/src/arthur/ui/topbar.cljs b/frontend/src/arthur/ui/topbar.cljs index f7510e4..0ccb234 100644 --- a/frontend/src/arthur/ui/topbar.cljs +++ b/frontend/src/arthur/ui/topbar.cljs @@ -8,11 +8,8 @@ (:require [arthur.events.collab :as collab] [arthur.events.export :as export] [arthur.events.project :as project] - [arthur.events.ui :as ui] [arthur.subs.playback :as playback] - [arthur.subs.ui :as sub] [arthur.ui.layout :as layout] - [arthur.ui.menu :as menu] [arthur.ui.openmenu :as openmenu] [arthur.ui.settings :as settings] [arthur.ui.share :as share] @@ -57,14 +54,6 @@ (let [{project-name :name project-seq :seq :keys [busy? status]} @(rf/subscribe [::playback/project]) {footage-status :status} @(rf/subscribe [::playback/footage]) {export-status :status} @(rf/subscribe [::export/state]) - selections @(rf/subscribe [::sub/selections]) - clipboard @(rf/subscribe [::sub/clipboard]) - selected? (boolean (seq selections)) - ;; A peg goes over ONE node: it takes that node's place in the - ;; hierarchy, and there is no one place a pair of them would go. - one-node (when (= 1 (count selections)) - (let [[kind _ _ path] (first selections)] - (when (and (= :node kind) (seq path)) path))) title (or project-name "untitled") commit! (fn [] (rf/dispatch [::project/rename @draft]) @@ -79,27 +68,6 @@ [settings/new-project "new"] [openmenu/view] [undo/view] - [menu/view - {:label "edit" :title "selection and clipboard" - :items [{:label "copy" :sub "Copy selection · ⌘/Ctrl C" - :disabled? (not selected?) :on-click #(rf/dispatch [::ui/copy])} - {:label "cut" :sub "Cut selection · ⌘/Ctrl X" - :disabled? (not selected?) :on-click #(rf/dispatch [::ui/cut])} - {:label "paste" :sub "Paste at playhead into the active row · ⌘/Ctrl V" - :disabled? (nil? clipboard) :on-click #(rf/dispatch [::ui/paste])} - {:label "duplicate" :sub "Duplicate beside selection; lanes repeat forward · ⌘/Ctrl D" - :disabled? (not selected?) :on-click #(rf/dispatch [::ui/duplicate])} - {:label "duplicate unique" - :sub "Duplicate with a private nested symbol graph · ⇧⌘/Ctrl D" - :disabled? (not selected?) - :on-click #(rf/dispatch [::ui/duplicate-unique])} - ;; The only way to keep a pivot, and the only way to transform a - ;; measured part by hand — which is what `gesture/refusal` tells - ;; you to do, so it has to be reachable from somewhere. - {:label "add peg" - :sub "A transform node over the selection · ⌃/⌘-drag its cross to place the pivot" - :disabled? (nil? one-node) - :on-click #(rf/dispatch [::ui/peg one-node])}]}] [snapshots/view] (if @renaming? [:input.project-name {:auto-focus true :value @draft diff --git a/frontend/test/arthur/ui/shortcuts_test.cljs b/frontend/test/arthur/ui/shortcuts_test.cljs index 9eeb46e..75784f9 100644 --- a/frontend/test/arthur/ui/shortcuts_test.cljs +++ b/frontend/test/arthur/ui/shortcuts_test.cljs @@ -2,7 +2,7 @@ (:require [cljs.test :refer [deftest is]] [arthur.domain.sequence-test :as fixture] [arthur.footage.store :as store] - [arthur.ui.shortcuts :as shortcuts])) + [arthur.ui.timeline :as timeline])) (deftest the-key-jumps-stop-on-every-cel-edge-and-key-the-timeline-shows ;; Cels at 0, 4 and 8; `:b` keyed on its own frames 0 and 1, which it shows @@ -10,4 +10,4 @@ ;; last frame and is not somewhere to stand. (let [id (store/install! {:clip (fixture/document) :store {}} "shortcut-stops")] (is (= [0 4 5 8 11] - (vec (shortcuts/stops {:clip/current id :ui {:open :main}})))))) + (vec (timeline/stops {:clip/current id :ui {:open :main}})))))) diff --git a/static/arthur/app.css b/static/arthur/app.css index e16348d..b80fc30 100644 --- a/static/arthur/app.css +++ b/static/arthur/app.css @@ -1024,6 +1024,9 @@ button.share-button:hover, button.share-button.on { filter: brightness(1.1); } .loc-shared { flex: 0 0 auto; display: inline-flex; align-items: baseline; gap: 5px; } .loc .spacer { flex: 1; } .creation-controls button { display: inline-flex; align-items: center; gap: 4px; } +/* Wide enough for the widest speed it steps through, so the strip does not + shift as it changes. */ +.pane-head button.speed { min-width: 3.2em; font-variant-numeric: tabular-nums; } .creation-controls svg { width: 11px; height: 11px; } /* --------------------------------------------------------------------------