From 4b780f9e91de17084fad5f065564bfb97531b465 Mon Sep 17 00:00:00 2001 From: Olive Vaughn Date: Sat, 10 Oct 2026 18:28:03 -0400 Subject: [PATCH 01/16] Inspector: one row per channel, names from symbols, tweens you can see MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The inspector shows what can be changed and nothing else. Ids, spans and the facts the fields below them already said are gone; explanations are hover text. Performance only appears for a face. Every animatable thing is one row: ◀ ◆ ▶, its name, its value, its gap. The arrows jump to the key before and after on every channel. A drawing's keys are an ordinary `shape` row, as are a palette placement's and a tracing layer's holds. The gap switch is about the gap the playhead is in, and on a key the one arriving at it, so keying B asks about A→B. The timeline draws every gap on a channel row, tween or hold, and a click switches it. An instance has no name of its own: it is called what it places, a rename renames the symbol, and `(n)` says how many places show it. Export numbers two placements of one symbol. Instance names in old documents are ignored. Co-Authored-By: Claude Opus 5.5 --- frontend/src/arthur/domain/clip.cljs | 36 +- frontend/src/arthur/domain/node.cljs | 14 +- frontend/src/arthur/events/export.cljs | 16 +- frontend/src/arthur/events/ui.cljs | 11 +- frontend/src/arthur/ui/icon.cljs | 12 +- frontend/src/arthur/ui/location.cljs | 16 +- frontend/src/arthur/ui/params.cljs | 788 +++++++++--------- frontend/src/arthur/ui/settings.cljs | 6 +- frontend/src/arthur/ui/timeline.cljs | 45 +- .../test/arthur/domain/instance_test.cljs | 7 +- frontend/test/arthur/events/export_test.cljs | 10 +- frontend/test/browser/take.mjs | 34 +- static/arthur/app.css | 84 +- 13 files changed, 569 insertions(+), 510 deletions(-) diff --git a/frontend/src/arthur/domain/clip.cljs b/frontend/src/arthur/domain/clip.cljs index 244938c..595bf97 100644 --- a/frontend/src/arthur/domain/clip.cljs +++ b/frontend/src/arthur/domain/clip.cljs @@ -74,28 +74,28 @@ (defn node-label "What to call node `n` on screen. - A NAME A PERSON TYPED WINS, and for an instance that is the ONLY thing `:name` - now means: `place-symbol` deliberately does not copy the symbol's name onto the - node it makes. Two instances of one symbol are told apart by what somebody - called them — `8625 left` and `8625 right` of one `face` — and reading through - in front of that would collapse them to the same word. + AN INSTANCE IS CALLED WHAT IT PLACES, read through on every render, and has + no name of its own. A name on the placement meant the same drawing could show + under two names, and that a rename in one place reached nowhere else; renaming + an instance renames its symbol (`::ui/rename-node`), so every placement of it + follows. How many places share it is `uses`. - OTHERWISE AN INSTANCE IS LABELLED BY WHAT IT PLACES, read through on every - render. A name copied at creation goes stale the moment the symbol is renamed, - and then the document shows one thing under two names: the symbol reads `bg` in - its tab while an instance of it still reads `symbol-18`, which is how a person - comes to paste a symbol into itself without being able to see that is what they - are doing. `problems` refuses that cycle; this is why it stops looking like a - reasonable thing to try. - - An id is a uuid for a placement and a keyword for an authored node, and neither - reads as a name, so the last resort is a legible stand-in rather than `(str - id)` — `:face-1` keeps its colon and a uuid pushes a column open." + Anything else is called by its own `:name`. An id is a uuid for a placement + and a keyword for an authored node, and neither reads as a name, so the last + resort is a legible stand-in — `:face-1` loses its colon and a uuid is cut." [clip id n] - (or (:name n) - (some->> (node/source n) (symbol-name clip)) + (or (some->> (node/source n) (symbol-name clip)) + (:name n) (if (keyword? id) (subs (str id) 1) (subs (str id) 0 8)))) +(defn uses + "How many nodes in the document place symbol `sid`." + [clip sid] + (count (for [[_ sym] (:symbols clip) + [_ n] (:nodes sym) + :when (= sid (node/source n))] + n))) + (defn frames "A symbol's length. Read off the symbol, never copied beside it." [clip sid] diff --git a/frontend/src/arthur/domain/node.cljs b/frontend/src/arthur/domain/node.cljs index dc118b6..0d65546 100644 --- a/frontend/src/arthur/domain/node.cljs +++ b/frontend/src/arthur/domain/node.cljs @@ -15,7 +15,8 @@ interpolating matrix entries is meaningless: a rotation tweened through its matrix shears on the way. Flat Float64Array for evaluation because at 30fps per-frame allocation is the only thing that will make this stutter." - (:require [arthur.domain.channel :as ch])) + (:require [arthur.domain.channel :as ch] + [clojure.string :as str])) (def kinds "`:bitmap` is in the vocabulary and not implemented; it is @@ -108,6 +109,17 @@ [:audio :pan] (ch/framed 0.0) [:audio :rate] (ch/framed 1.0)}) +(def ^:private channel-names + {[:xform :pos] "pos" [:xform :rot] "rot°" [:xform :scale] "scale" + [:xform :skew] "skew" [:xform :pivot] "pivot" [:geom :pts] "shape" + [:style :color] "color" [:vis] "vis" [:palette] "palette"}) + +(defn channel-name + "What to call channel `path` on screen: the same short word in the inspector + and the timeline." + [path] + (or (channel-names path) (str/join " " (map name path)))) + (defn defaults-of [n] (if (= :audio (:kind n)) audio-defaults defaults)) diff --git a/frontend/src/arthur/events/export.cljs b/frontend/src/arthur/events/export.cljs index 045a742..d0c5b5b 100644 --- a/frontend/src/arthur/events/export.cljs +++ b/frontend/src/arthur/events/export.cljs @@ -78,18 +78,22 @@ the other instances removed, which is why seven instances of one symbol are seven different exports rather than seven copies of one. - Instances are ordered and labelled by `clip/node-label`, never by id: a uuid - sorts at random and means nothing to read." + Instances are labelled by `clip/node-label` — the symbol they place — and + numbered in stacking order where one symbol is placed more than once, never + by id: a uuid sorts at random and means nothing to read." [clip open] (let [label #(clip/node-label clip %1 %2) instances (->> (get-in clip [:symbols open :nodes]) (filter (comp #{:instance} :kind val)) - (sort-by (fn [[id n]] [(label id n) (str id)])))] + (sort-by (fn [[id n]] [(label id n) (or (:z n) "") (str id)]))) + numbered (mapcat (fn [same] + (if (< 1 (count same)) + (map-indexed (fn [i [id n]] [id (str (label id n) " " (inc i))]) same) + (map (fn [[id n]] [id (label id n)]) same))) + (partition-by (fn [[id n]] (label id n)) instances))] (into (mapv (fn [sid] {:symbol sid :label (name sid)}) (sort-by str (keys (:symbols clip)))) - (mapv (fn [[id n]] - {:symbol open :isolate id :label (label id n)}) - instances)))) + (mapv (fn [[id l]] {:symbol open :isolate id :label l}) numbered)))) (defn target "What the export is pointed at. A nil symbol is whichever one is open, so a diff --git a/frontend/src/arthur/events/ui.cljs b/frontend/src/arthur/events/ui.cljs index 7f2670f..97a33ff 100644 --- a/frontend/src/arthur/events/ui.cljs +++ b/frontend/src/arthur/events/ui.cljs @@ -45,14 +45,19 @@ (rf/reg-event-db ::rename-node + ;; An instance has no name of its own — see `clip/node-label` — so renaming one + ;; renames the symbol it places, everywhere it is placed. Blank removes the + ;; name, which falls back to the id. (fn [db [_ sid id value]] (let [document (:clip (store/entry (:clip/current db))) + n (get-in document [:symbols sid :nodes id]) + path (if-let [of (node/source n)] [:symbols of] [:symbols sid :nodes id]) value (not-empty (str/trim (str value)))] - (if-not (get-in document [:symbols sid :nodes id]) + (if (or (nil? n) (nil? (get-in document path))) db (edit/transaction db #(if value - (assoc-in % [:symbols sid :nodes id :name] value) - (update-in % [:symbols sid :nodes id] dissoc :name))))))) + (assoc-in % (conj path :name) value) + (update-in % path dissoc :name))))))) (defn selected "`db` with `selection` as its primary active row. diff --git a/frontend/src/arthur/ui/icon.cljs b/frontend/src/arthur/ui/icon.cljs index bc7cb6b..7c986b4 100644 --- a/frontend/src/arthur/ui/icon.cljs +++ b/frontend/src/arthur/ui/icon.cljs @@ -50,7 +50,17 @@ ;; row out of a dozen says at a glance that its blocks follow one another in ;; time instead of being on screen together. Whole and half coordinates, so ;; the three dividers land on pixels at 11px. - :lane {:stroke ["M1.5 3.5h9v5h-9z" "M4.5 3.5v5" "M7.5 3.5v5"]}}) + :lane {:stroke ["M1.5 3.5h9v5h-9z" "M4.5 3.5v5" "M7.5 3.5v5"]} + ;; To the key before and after: the transport's step, without its bar. + :prev {:fill ["M8.5 3v6L4 6z"]} + :next {:fill ["M3.5 3v6L8 6z"]} + ;; The gap between two keys as a value graph draws it: a ramp from one to + ;; the other, or a step that holds and then jumps. + :tween {:fill ["M1.5 8h2v2h-2z" "M8.5 2h2v2h-2z"] :stroke ["M3 8.5 9 3.5"]} + :hold {:fill ["M1.5 8h2v2h-2z" "M8.5 2h2v2h-2z"] :stroke ["M3.5 9H9.5V4"]} + ;; How an instance plays: through once into a stop, round, or one frame. + :once {:fill ["M2.4 2.6 7.6 6 2.4 9.4z" "M8.4 2.6h1.4v6.8H8.4z"]} + :still {:stroke ["M3.5 2.5h5v7h-5z"] :fill ["M5 4.5h2v3H5z"]}}) (defn view "The glyph named `k`, sized by CSS and inked in `currentColor` — so a button's diff --git a/frontend/src/arthur/ui/location.cljs b/frontend/src/arthur/ui/location.cljs index 2af94c1..fd6595f 100644 --- a/frontend/src/arthur/ui/location.cljs +++ b/frontend/src/arthur/ui/location.cljs @@ -111,20 +111,6 @@ (when (and (nil? t) (not held?)) " · repeats; no single frame above")) :else nil))) -(defn- shared-with - "How many places in the document use the same drawing as `n`, or nil where it - places none. Counted rather than flagged, because \"used in 4 places\" is the - fact somebody needs before deciding to decouple one — and counted over every - node that places it, not only over cels, because a drawing reused as a plain - instance somewhere else is just as shared and `make unique` is just as much - the answer." - [clip n] - (when-let [of (and n (node/source n))] - (count (for [[_ sym] (:symbols clip) - [_ other] (:nodes sym) - :when (= of (node/source other))] - other)))) - (defn view [] (let [clip @(rf/subscribe [::render/clip]) open @(rf/subscribe [::render/open]) @@ -134,7 +120,7 @@ n (when (= :node kind) (get-in clip [:symbols sid :nodes id])) crumbs (trail clip open (if (and n (seq path)) path (when n [id]))) last-i (dec (count crumbs)) - shared (shared-with clip n) + shared (some->> n node/source (clip/uses clip)) says (whereabouts clip n inside)] [:section.loc [:nav.crumbs {:aria-label "editing location"} diff --git a/frontend/src/arthur/ui/params.cljs b/frontend/src/arthur/ui/params.cljs index ad1a0d6..b8ec41a 100644 --- a/frontend/src/arthur/ui/params.cljs +++ b/frontend/src/arthur/ui/params.cljs @@ -1,10 +1,12 @@ (ns arthur.ui.params "The right pane: what the selection is, and what can be changed about it. - Sections rather than a mode switch. The clip's facts are always true, so the - clip section is always there; node, footage, face and tracking sections follow - the thing actually selected. Nothing here computes — every control dispatches - an intent and every readout comes off a subscription." + ONLY WHAT CAN BE CHANGED. An id, a span, a count of nodes are either in the + timeline already or of no use to somebody drawing, so the pane shows controls + and nothing else, densely: a header naming the selection, then one row per + thing that can be keyed, then whatever else the selection has. Nothing here + computes — every control dispatches an intent and every readout comes off a + subscription." (:require [clojure.string :as str] [arthur.domain.clip :as clip-domain] [arthur.domain.channel :as channel] @@ -17,32 +19,24 @@ [arthur.domain.pose :as pose] [arthur.domain.symbol :as symbol] [arthur.events.history :as history] - [arthur.events.paint :as paint-events] [arthur.events.playback :as pb] [arthur.events.project :as project] [arthur.events.ui :as ui] [arthur.subs.playback :as playback] [arthur.subs.render :as render] [arthur.subs.ui :as sub] + [arthur.ui.icon :as icon] [arthur.ui.palette :as palette] [arthur.ui.settings :as settings] [re-frame.core :as rf] [reagent.core :as r])) (defn- brief - "A value that fits the column. The `facts` list puts the whole thing in a - `title`, so nothing is lost — but a node id is a uuid and a `:z` is a - timestamp joined to one, and either wrapped over three lines pushes every - parameter below it off the pane." + "A value that fits the column, for the few places an id is still the only name." [v] (let [s (str v)] (if (> (count s) 22) (str (subs s 0 20) "…") s))) -(defn- facts [& pairs] - (into [:dl.facts] - (mapcat (fn [[k v]] (when v [[:dt k] [:dd {:title (str v)} v]]))) - (partition 2 pairs))) - (defn- section [title & body] (into [:section.section [:h2 title]] body)) @@ -70,316 +64,349 @@ (when @draft (reset! draft s)) (when-not (js/isNaN n) (on-number n))))})]))) -(defn- number-field [label value on-change & [placeholder disabled?]] - [:label.inspector-field label - [number-input {:min 1 :step 1 :value value - :placeholder placeholder - :disabled disabled? - :parse #(if (seq %) (js/parseInt % 10) nil) - :on-number on-change}]]) +(defn- count-input + "A whole number of at least 1, blank meaning \"none of its own\"." + [value on-change & [{:keys [placeholder disabled label]}]] + [number-input {:min 1 :step 1 :value value :placeholder placeholder + :disabled disabled :aria-label label :title label + :parse #(if (seq %) (js/parseInt % 10) nil) + :on-number on-change}]) -(defn- name-field [label value commit!] - [:label.inspector-field label - [:input {:type "text" :default-value value - :key value - :on-key-down #(when (= "Enter" (.-key %)) (.. % -target blur)) - :on-blur #(commit! (.. % -target -value))}]]) +(defn- text-input [value commit! & [attrs]] + [:input (merge {:type "text" :default-value value + :key value + :on-key-down #(when (= "Enter" (.-key %)) (.. % -target blur)) + :on-blur #(commit! (.. % -target -value))} + attrs)]) + +(defn- prop + "One labelled row of a form: the label in the narrow column, controls after." + [label & controls] + (into [:div.prop [:span.prop-name label]] controls)) + +(defn- palette-select [value on-change & [disabled?]] + (let [clip @(rf/subscribe [::render/clip])] + [:select {:value (str (or value "")) :disabled disabled? + :on-change (fn [e] + (let [v (.. e -target -value)] + (on-change (first (filter #(= v (str %)) (keys (pal/palettes clip)))))))} + [:option {:value ""} "inherit"] + (for [[id p] (sort-by (comp str :name val) (pal/palettes clip))] + ^{:key (str id)} [:option {:value (str id)} (:name p)])])) ;; --------------------------------------------------------------------------- -;; the clip +;; the header -(defn- clip-section [] - (let [clip @(rf/subscribe [::render/clip]) - open @(rf/subscribe [::render/open]) - frames @(rf/subscribe [::render/frames]) - project @(rf/subscribe [::playback/project]) - busy? (:busy? project)] - [section "project" - [facts - "stage" (str (:width clip) "×" (:height clip)) - "open" (some-> open name) - "length" (str frames " frames")] - [:div.inspector-form - [name-field "name" (or (:name project) (:name clip) "") - #(rf/dispatch [::project/rename %])] - [number-field "width" (:width clip) - #(rf/dispatch [::project/project-setting :width %]) nil busy?] - [number-field "height" (:height clip) - #(rf/dispatch [::project/project-setting :height %]) nil busy?] - [settings/rate busy?]]])) +(defn- header + "What is selected, as its name — the one field that says which thing this is. + An instance is called what it places, so its name IS its symbol's and a rename + here reaches every placement; `(n)` says how many that is." + [kind value placeholder commit! uses] + [:div.inspect-head + [:span.inspect-kind kind] + [text-input value commit! {:class "inspect-name" :placeholder placeholder + :aria-label "name"}] + (when (and uses (< 1 uses)) + [:span.uses {:title (str "placed " uses " times · a rename reaches every one")} + (str "(" uses ")")])]) ;; --------------------------------------------------------------------------- -;; a node +;; one row per channel +;; +;; ◀ ◆ ▶, the name, the value, and the gap: the same row for a transform, a +;; colour, a drawing and a palette, as After Effects puts its key navigator by +;; every property. ◆ keys the channel here or takes the key here off; an edit +;; writes a key on a keyed channel or the one value on one that is not. ◀ ▶ go to +;; the key before and after. The gap switch is the same choice as clicking the +;; gap in the timeline. -(defn- channel-state - "One line saying how this channel is animated, which is the only thing about it - this pane can say without an editor for its values." - [ch] - (cond - (:dense ch) (str "dense · " (get-in ch [:dense :frames]) " frames") - (:keys ch) (str (count (:keys ch)) " keys · " (name (or (:interp ch) :hold))) - :else (let [v (:value ch)] - (str "framed · " (if (channel/nothing? v) "absent" (pr-str v)))))) +(def ^:private order + (zipmap [[:xform :pos] [:xform :rot] [:xform :scale] [:xform :skew] [:xform :pivot] + paint/geometry [:style :color] [:vis]] + (range))) -(defn- segment-select - "Hold or tween, for the gap after the key at `left` — the same choice on a - drawing as on a transform." - [sid id path ch left] - [:select.interp {:value (name (or (channel/segment-interp ch left) :hold)) - :on-change #(rf/dispatch [::project/set-segment-interp - sid id path left (keyword (.. % -target -value))])} - [:option {:value "hold"} "hold"] - [:option {:value "linear"} "tween"]]) +(defn- gap-at + "The key whose gap the switch is about, given the keys `ks` and frame `f`: the + gap the playhead is inside, and standing on a key, the gap ARRIVING at it — + keying B after A is asking about A→B. On the first key, the gap leaving it." + [ks f] + (when f + (let [left (or (last (filter #(< % f) ks)) (when (= f (first ks)) f))] + (when (and left (some #(< left %) ks)) left)))) -(defn- drawing-keys - "The polygon controls: jump to a drawing key, add one here, and choose what the - gap after the current one does. Lifted out of the old stage toolbar unchanged — - a drawing key is a parameter of the shape, and this is where the shape's - parameters are. +(defn- seek-own! + "Put the playhead on own frame `f` of something whose clock is `time`." + [time f] + (rf/dispatch [::pb/seek (js/Math.round (+ (:at time) (/ f (:rate time))))])) - Keys are in the shape's OWN frames — the symbol's it lives in, through every - instance above it — and `time` maps the open symbol's frames to them. `frame` - is nil when the shape is not on screen, where there is no here to key." - [sid id n {:keys [frame time]}] - (let [geom (get-in n [:channels paint/geometry]) - active (when geom (paint/active-frame geom frame)) - ks (when geom (sort (keys (:keys geom)))) - next-k (first (filter #(> % active) ks)) - [start end] (:span n)] - [:<> - [:div.row {:style {:margin "5px 0"}} - [:button {:disabled (or (nil? frame) (< frame start) (>= frame end) - (contains? (:keys geom) frame)) - :on-click #(rf/dispatch [::paint-events/add-key sid id frame])} - "drawing key here"]] - (when (seq ks) - [:div.row - [:span.dim "keys"] - (doall - (for [f ks] - ^{:key f} - [:button {:class (when (= frame f) "on") - :disabled (nil? time) - :on-click #(rf/dispatch [::pb/seek (js/Math.round - (+ (:at time) (/ f (:rate time))))])} - (str f)]))]) - (when next-k - [:div.row {:style {:margin-top "5px"}} - [:label.dim (str "key " active " → " next-k " ") - [segment-select sid id paint/geometry geom active]]])])) +(defn- key-nav + "◀ ◆ ▶ over keys `ks`: `frame` is the one being edited, nil off screen, and + `own` is `{:time :frame}`, the clock the jumps go through." + [ks frame {:keys [time] here :frame} on-key title] + (let [ks (sort ks) + here (or frame here) + before (when here (last (filter #(< % here) ks))) + after (when here (first (filter #(> % here) ks)))] + [:span.key-nav + [:button.nav {:disabled (or (nil? before) (nil? time)) + :title (if before (str "key at " before) "no key before") + :aria-label "previous key" + :on-click #(seek-own! time before)} + [icon/view :prev]] + [:button.key {:class (cond (some #{frame} ks) "on" (seq ks) "keyed") + :disabled (nil? frame) + :title title + :on-click on-key} + "◆"] + [:button.nav {:disabled (or (nil? after) (nil? time)) + :title (if after (str "key at " after) "no key after") + :aria-label "next key" + :on-click #(seek-own! time after)} + [icon/view :next]]])) -;; The transform and visibility, which every node has, as one row each: ◆ keys -;; the channel here or takes the key here off, and an edit writes a key on a -;; keyed channel or the one value on one that is not. `frame` is the node's own, -;; nil when it is not on screen, where a keyed channel has no here to write to. -;; Rotation is shown in degrees. Between two keys, the gap after the one here -;; holds or tweens, as a drawing's does. +(defn- gap-switch [ch path frame set-gap!] + (let [ks (sort (keys (:keys ch))) + left (when-not (node/hold-only? path (channel/value-at ch (or frame 0) nil)) + (gap-at ks frame)) + tween? (and left (= :linear (channel/segment-interp ch left)))] + (if left + [:button.gap {:class (when tween? "on") + :title (str (if tween? "tween" "hold") " from key " left + " · click to " (if tween? "hold" "tween")) + :aria-label (if tween? "tween" "hold") + :on-click #(set-gap! left (if tween? :hold :linear))} + [icon/view (if tween? :tween :hold)]] + [:span.gap]))) -(defn- channel-control [sid id path ch frame auto-key? node-path] +(defn- channel-row + "Channel `path`, `ch`, of whatever the row is about. `frame` is its own frame + being edited, nil where it is not on screen and a keyed channel has no here to + write to; `own` is its clock. `on-key` and `set-gap!` are the writes, `value` + the editor." + [{:keys [path ch frame own live? on-key set-gap!]} value] + (let [ks (keys (:keys ch))] + [:div.chan {:class (when live? "live") :data-channel (str/join " " (map name path))} + [key-nav ks frame own on-key + (if (seq ks) (str (count ks) " keys · key or unkey here") "key this here")] + [:span.chan-name (node/channel-name path)] + [:span.chan-value value] + [gap-switch ch path frame set-gap!]])) + +(defn- number-fields + "The value of a number or a vector of them, as boxes. Rotation is shown in + degrees." + [path v off? put] + (let [deg? (= path [:xform :rot]) + field (fn [i x on-number] + ^{:key i} + [number-input {:step "any" :disabled off? + :value (if deg? (/ (js/Math.round (* x (/ 18000 js/Math.PI))) 100) x) + :parse js/parseFloat + :on-number #(on-number (if deg? (* % (/ js/Math.PI 180)) %))}])] + (if (number? v) + (field 0 v put) + (doall (map-indexed (fn [i x] (field i x #(put (assoc (vec v) i %)))) v))))) + +(defn- swatches [value off? palette pick!] + [:span.chan-swatches + (doall + (for [[i {:keys [name hex]}] (map-indexed vector (:slots palette))] + ^{:key i} + [:button.swatch + {:class (when (= i value) "on") + :style {:background hex} + :disabled off? + :aria-label (str "color " i (when name (str " " (clojure.core/name name)))) + :aria-pressed (= i value) + :title (str i (when name (str " · " (clojure.core/name name))) " · " hex) + :on-click #(pick! i)}]))]) + +(defn- channel-value + "The editor for channel `path` of node `n`: boxes, a switch, swatches — or, + where there is nothing to type, what it is." + [sid id n path ch frame palette node-path] (let [keyed? (some? (:keys ch)) - ;; No store: the call site below hands this only channels that are not - ;; `:dense`, which are the only ones with anything in tier 2 to read. - v (channel/value-at ch (or frame 0) nil) off? (and keyed? (nil? frame)) - deg? (= path [:xform :rot]) - ;; A boolean has nothing between true and false to tween through. - left (when (and keyed? frame (not (boolean? v))) (paint/active-frame ch frame)) - gap? (and left (some #(< left %) (keys (:keys ch)))) - put #(rf/dispatch [::project/set-channel sid id path frame %]) - field (fn [i x on-number] - ^{:key i} - [number-input {:step "any" :disabled off? - :value (if deg? (/ (js/Math.round (* x (/ 18000 js/Math.PI))) 100) x) - :parse js/parseFloat - :on-number #(on-number (if deg? (* % (/ js/Math.PI 180)) %))}])] - [:dd.channel {:class (when auto-key? "live")} - [:button.key {:class (cond (contains? (:keys ch) frame) "on" keyed? "keyed") - :disabled (nil? frame) - :title (if keyed? (str (count (:keys ch)) " keys") "key this here") - :on-click #(rf/dispatch [::project/toggle-key sid id path frame])} - "◆"] - (cond - (boolean? v) [:input {:type "checkbox" :checked v :disabled off? - :on-change #(put (.. % -target -checked))}] - (number? v) (field 0 v put) - :else (doall (map-indexed (fn [i x] (field i x #(put (assoc (vec v) i %)))) - v))) - ;; THE WAY BACK TO THE MIDDLE, on the pivot row and nowhere else. A pivot is - ;; a choice and does not follow the drawing, which is what keeps a keyed spin - ;; from being re-aimed by somebody drawing one more shape inside the symbol — - ;; so "put it back in the middle of what is there now" has to be something - ;; you can ask for. `::ui/centre-pivot` moves nothing while it does it. - (when (and (= path [:xform :pivot]) (seq node-path)) - [:button.key {:title "centre the pivot on the middle of what it draws now" - :aria-label "centre pivot" - :on-click #(rf/dispatch [::ui/centre-pivot node-path])} - "⌖"]) - (when gap? [segment-select sid id path ch left])])) + v (when-not (:dense ch) (channel/value-at ch (or frame 0) nil)) + put #(rf/dispatch [::project/set-channel sid id path frame %])] + (cond + (:dense ch) + [:span.dim {:title "measured from the footage · regenerate to change it"} + (str "measured · " (get-in ch [:dense :frames]) "f")] -(defn- color-control [sid id ch frame auto-key? palette] - (let [keyed? (some? (:keys ch)) - value (channel/value-at ch (or frame 0) nil) - ;; A knockout or a remap is no slot, and none is marked. - value (cond - (integer? value) value - (keyword? value) (or (first (keep-indexed #(when (= value (:name %2)) %1) - (:slots palette))) 0)) - off? (and keyed? (nil? frame))] - [:dd.channel {:class (when auto-key? "live")} - [:button.key {:class (cond (contains? (:keys ch) frame) "on" keyed? "keyed") - :disabled (nil? frame) - :title (if keyed? (str (count (:keys ch)) " held keys") "key color here") - :on-click #(rf/dispatch [::project/toggle-key sid id [:style :color] frame])} - "◆"] - [:div.channel-swatches - (doall - (for [[i {:keys [name hex]}] (map-indexed vector (:slots palette))] - ^{:key i} - [:button.swatch - {:class (when (= i value) "on") - :style {:background hex} - :disabled off? - :aria-label (str "color " i (when name (str " " (clojure.core/name name)))) - :aria-pressed (= i value) - :title (str i (when name (str " · " (clojure.core/name name))) " · " hex) - :on-click #(rf/dispatch [::project/set-channel sid id [:style :color] frame i])}]))] - (when keyed? [:span.dim "hold"])])) + (= path paint/geometry) + [:span.dim {:title "double-click the shape on the stage to edit its points"} + (str (quot (count v) 2) " points")] -(defn- instance-playback [[sid id n]] + (= path [:style :color]) + (if (symbol/remap? v) + [:span.dim "remap ↓"] + ;; A slot by name is the slot of that name; a knockout is none. + (swatches (if (keyword? v) + (first (keep-indexed #(when (= v (:name %2)) %1) (:slots palette))) + (when (integer? v) v)) + off? palette put)) + + (boolean? v) + [:input {:type "checkbox" :checked v :disabled off? + :on-change #(put (.. % -target -checked))}] + + (or (number? v) (and (sequential? v) (every? number? v))) + [:<> + (number-fields path v off? put) + ;; A pivot does not follow the drawing, so "put it back in the middle of + ;; what is there now" has to be something you can ask for. Moves nothing. + (when (and (= path [:xform :pivot]) (seq node-path)) + [:button.icon {:title "centre the pivot on what it draws now" + :aria-label "centre pivot" + :on-click #(rf/dispatch [::ui/centre-pivot node-path])} + "⌖"])] + + :else [:span.dim (brief (pr-str v))]))) + +(defn- channels + "Every channel of node `n`, transform first." + [[sid id n] node-path] + (let [auto-key? @(rf/subscribe [::sub/auto-key?]) + clip @(rf/subscribe [::render/clip]) + frame (:frame @(rf/subscribe [::sub/selected-placement])) + own @(rf/subscribe [::sub/own-time node-path]) + palette (get (pal/palettes clip) + (or (get-in clip [:symbols sid :palette]) (pal/default-palette-id clip)))] + [:div.chans + (doall + (for [[path ch] (sort-by (fn [[path]] [(get order path 99) (str path)]) (node/channels n))] + ^{:key (str path)} + [channel-row {:path path :ch ch :frame frame :own own + :live? (and auto-key? (not (:dense ch))) + :on-key #(rf/dispatch [::project/toggle-key sid id path frame]) + :set-gap! #(rf/dispatch [::project/set-segment-interp sid id path %1 %2])} + [channel-value sid id n path ch frame palette node-path]]))])) + +;; --------------------------------------------------------------------------- +;; an instance's playback, and a symbol's own settings + +(def ^:private modes + [[:once :once "play once"] [:loop :loop "loop"] [:frame :still "hold one frame"]]) + +(defn- playback-row [[sid id n]] (let [{:keys [in speed end]} (node/playback-of n) mode (cond (zero? speed) :frame (or (= :loop end) (get-in n [:time :loop?])) :loop :else :once) - change! (fn [field value] - (rf/dispatch [::project/instance-playback sid id field value]))] - [section "playback" - [:div.inspector-form - [:label.inspector-field "mode" - [:select {:value (name mode) - :aria-label "instance playback mode" - :on-change #(change! :mode (keyword (.. % -target -value)))} - [:option {:value "once"} "play once"] - [:option {:value "loop"} "loop"] - [:option {:value "frame"} "hold frame"]]] - [:label.inspector-field "start frame" - [number-input {:min 0 :step 1 :value in - :aria-label "instance start frame" - :parse #(js/parseInt % 10) - :on-number #(change! :in %)}]] - [:label.inspector-field "speed" - [number-input {:min 0 :step 0.1 :value speed - :disabled (= :frame mode) - :aria-label "instance playback speed" - :parse js/parseFloat - :on-number #(change! :speed %)}]]]])) + change! #(rf/dispatch [::project/instance-playback sid id %1 %2])] + (prop "play" + [:span.seg + (doall + (for [[m glyph title] modes] + ^{:key m} + [:button {:class (when (= m mode) "on") :title title :aria-label title + :aria-pressed (= m mode) + :on-click #(change! :mode m)} + [icon/view glyph]]))] + [:span.dim "from"] + [number-input {:min 0 :step 1 :value in + :title "the frame of its symbol it starts on" + :aria-label "instance start frame" + :parse #(js/parseInt % 10) + :on-number #(change! :in %)}] + [:span.dim "×"] + [number-input {:min 0 :step 0.1 :value speed + :disabled (= :frame mode) + :title "speed" :aria-label "instance playback speed" + :parse js/parseFloat + :on-number #(change! :speed %)}]))) -(defn- node-section [[sid id n]] - (let [[start end] (:span n) - ;; The selected row path, for the one control that needs to name the node - ;; the way a stage gesture does rather than by `[sid id]`: ⌖ re-centres a - ;; pivot, and finding the middle of what a node draws means resolving it - ;; where it is placed. - node-path (nth @(rf/subscribe [::sub/selection]) 3 nil) - auto-key? @(rf/subscribe [::sub/auto-key?]) - clip @(rf/subscribe [::render/clip]) - placement @(rf/subscribe [::sub/selected-placement]) - frame (:frame placement) - palette-id (or (get-in clip [:symbols sid :palette]) (pal/default-palette-id clip)) - palette (get (pal/palettes clip) palette-id)] - [section (str (name (:kind n)) " · in " (name sid)) - [facts - "id" (brief id) - ;; Which symbol a cel places. The one fact that makes an instance - ;; legible as an instance rather than as a node. - "of" (when (= :instance (:kind n)) (str (node/source n))) - ;; A span is in the node's OWN frames and `at` is where its frame 0 sits - ;; in this symbol. See `node/placed-span`. - "span" (when start (str start " … " end)) - "at" (when (node/mapped-time? n) (str (get-in n [:time :at] 0)))] - [:div.inspector-form - [name-field "name" (or (:name n) "") - #(rf/dispatch [::ui/rename-node sid id %])]] - (when (:paint? n) [drawing-keys sid id n @(rf/subscribe [::sub/selected-local])]) - [:div.row {:style {:margin-top "6px"}} [:span.dim "channels"]] - ;; Channels belong to the placement, before its source playback clock. - ;; Entering the source would wrap keys on loops and pin them on holds. - (let [{:keys [frame]} placement] - [:dl.facts - (doall - (for [[path ch] (sort-by (fn [[path]] - [(cond - (= :xform (first path)) 0 - (= path [:style :color]) 1 - :else 2) - (str path)]) - (node/channels n))] - ^{:key (str path)} - [:<> - [:dt (str/join " " (map name path))] - (cond - (and (= path [:style :color]) (not (:dense ch))) - [color-control sid id ch frame auto-key? palette] +(defn- symbol-fields + "A symbol's length, stage and authoring palette." + [sid] + (let [clip @(rf/subscribe [::render/clip]) + sym (get-in clip [:symbols sid]) + busy? (:busy? @(rf/subscribe [::playback/project])) + put! #(rf/dispatch [::project/symbol-setting sid %1 %2])] + [:<> + (prop "length" + [count-input (:frames sym) #(put! :frames %) {:disabled busy? :label "length in frames"}] + [:span.dim "f"]) + (prop "size" + [count-input (:width sym) #(put! :width %) + {:placeholder (str (:width clip)) :disabled busy? :label "width"}] + [:span.dim "×"] + [count-input (:height sym) #(put! :height %) + {:placeholder (str (:height clip)) :disabled busy? :label "height"}] + (when (or (:width sym) (:height sym)) + [:button.icon {:disabled busy? :title "use the project's stage size" + :aria-label "use project stage" + :on-click #(do (put! :width nil) (put! :height nil))} + "↺"])) + (prop "palette" + [palette-select (:palette sym) #(rf/dispatch [::project/symbol-palette sid %]) busy?])])) - (and (contains? (node/defaults-of n) path) (not (:dense ch))) - [channel-control sid id path ch frame auto-key? node-path] +(defn- project-fields [] + (let [clip @(rf/subscribe [::render/clip]) + project @(rf/subscribe [::playback/project]) + busy? (:busy? project)] + [section "project" + (prop "name" [text-input (or (:name project) (:name clip) "") + #(rf/dispatch [::project/rename %]) {:aria-label "project name"}]) + (prop "stage" + [count-input (:width clip) #(rf/dispatch [::project/project-setting :width %]) + {:disabled busy? :label "width"}] + [:span.dim "×"] + [count-input (:height clip) #(rf/dispatch [::project/project-setting :height %]) + {:disabled busy? :label "height"}]) + (prop "rate" [settings/rate busy?])])) - :else [:dd (channel-state ch)])]))])])) +;; --------------------------------------------------------------------------- +;; a node -(defn- palette-placement-section [[sid id n]] +(defn- node-view + "A selected node: its name, its channels, and for an instance how it plays + and the settings of the symbol it places." + [[sid id n :as selected]] + (let [clip @(rf/subscribe [::render/clip]) + ;; The row path, which names the node the way a stage gesture does: its + ;; clock and its pivot are found where it is placed. + node-path (or (nth @(rf/subscribe [::sub/selection]) 3 nil) [id]) + of (node/source n)] + [:<> + (if of + [header (if (symbol/lane? (clip-domain/symbol clip of)) "lane" "instance") + (clip-domain/symbol-name clip of) (name of) + #(rf/dispatch [::ui/rename-node sid id %]) (clip-domain/uses clip of)] + [header (name (:kind n)) (or (:name n) "") (clip-domain/node-label clip id n) + #(rf/dispatch [::ui/rename-node sid id %]) nil]) + [channels selected node-path] + (when of + [:div.props + [playback-row selected] + [symbol-fields of]])])) + +(defn- palette-placement-view + "A placement on the palette lane: which palette it switches to, keyed and + tweened like any channel." + [[sid id n]] (let [clip @(rf/subscribe [::render/clip]) transition (node/source n) open-frame @(rf/subscribe [::render/open-frame]) [start _] (node/placed-span n) frame (max 0 (- open-frame (or start 0))) + own {:time {:at (or start 0) :rate 1} :frame frame} ch (or (get-in n [:channels [:palette]]) (assoc (channel/framed - (get-in clip [:symbols (node/source n) :palette-ref])) + (get-in clip [:symbols transition :palette-ref])) :semantic :palette)) value (channel/value-at ch frame nil) - chosen (if (map? value) (:from value) value) - keyframes (sort (keys (:keys ch))) - left (when (seq keyframes) - (or (last (filter #(<= % frame) keyframes)) (first keyframes))) - right (when left (first (filter #(< left %) keyframes))) - palettes (sort-by (comp str :name val) (pal/palettes clip))] - [section "palette transition" - [:div.inspector-form - [name-field "name" (clip-domain/symbol-name clip transition) - #(rf/dispatch [::project/rename-symbol transition %])]] - [:div.inspector-form - [:label.inspector-field "palette" - [:span.row - [:button.key {:class (cond (contains? (:keys ch) frame) "on" (:keys ch) "keyed") - :title (if (:keys ch) (str (count (:keys ch)) " keys") "key this here") - :on-click #(rf/dispatch [::project/toggle-palette-key sid id frame])} - "◆"] - [:select {:value (if (= pal/inherit chosen) "" (str chosen)) - :on-change - (fn [e] - (let [v (.. e -target -value) - palette-id (or (first (filter #(= v (str %)) - (keys (pal/palettes clip)))) - pal/inherit)] - (rf/dispatch [::project/set-palette-choice sid id frame palette-id])))} - [:option {:value ""} "inherit"] - (for [[palette-id p] palettes] - ^{:key (str palette-id)} - [:option {:value (str palette-id)} (:name p)])]]] - (when right - [:label.inspector-field (str "key " left " → " right) - [segment-select sid id [:palette] ch left]])]])) - -(defn- palette-symbol-section [sid] - (let [clip @(rf/subscribe [::render/clip]) - sym (get-in clip [:symbols sid])] - [section "palette transition" - [:div.inspector-form - [name-field "name" (clip-domain/symbol-name clip sid) - #(rf/dispatch [::project/rename-symbol sid %])]] - [facts "palette" (or (get-in clip [:palettes (:palette-ref sym) :name]) - (:palette-ref sym))] - [:div.dim "Keyframes and cut/tween interpolation are edited on a placement in the palette lane."]])) - + chosen (if (map? value) (:from value) value)] + [:<> + [header "palette" (clip-domain/symbol-name clip transition) (name transition) + #(rf/dispatch [::ui/rename-node sid id %]) nil] + [:div.chans + [channel-row {:path [:palette] :ch ch :frame frame :own own + :on-key #(rf/dispatch [::project/toggle-palette-key sid id frame]) + :set-gap! #(rf/dispatch [::project/set-segment-interp sid id [:palette] %1 %2])} + [palette-select (when-not (= pal/inherit chosen) chosen) + #(rf/dispatch [::project/set-palette-choice sid id frame (or % pal/inherit)])]]]])) ;; --------------------------------------------------------------------------- ;; corrections @@ -439,8 +466,8 @@ lane-context? (or (symbol/lane? (clip-domain/symbol clip sid)) (and (= :instance (:kind selected)) (symbol/lane? (clip-domain/symbol clip (node/source selected))))) - targets (if lane-context? [selected-id] [])] - (when (seq targets) +] + (when lane-context? (r/with-let [draft (r/atom (correction-initial clip sid selected-id))] (let [target (:target @draft) motion (:motion @draft) @@ -448,16 +475,6 @@ layers (correction-layers clip sid target)] [section "corrections" [:div.correction-grid - [:label.inspector-field "owner" - [:select {:value (or (first (keep-indexed #(when (= %2 target) %1) targets)) 0) - :on-change (fn [e] - (let [i (js/parseInt (.. e -target -value) 10) - id (nth targets i)] - (reset! draft (correction-initial clip sid id))))} - (doall (for [[i id] (map-indexed vector targets)] - ^{:key (str id)} - [:option {:value i} - (str "selected · " (brief id))]))]] [:label.inspector-field "property" [:select {:value (if (= [:xform :rot] (:path @draft)) "rotation" "position") :on-change #(swap! draft assoc :path @@ -471,7 +488,6 @@ [:option {:value "constant"} "constant"] [:option {:value "ramp"} "ramp"] [:option {:value "return"} "return"]]] - [:div] [draft-number draft :from "from owner frame" true] [draft-number draft :through "through owner frame" true] (case motion @@ -524,39 +540,28 @@ (defn- layer-section "Tracing layer `id` of symbol `sid`, at row `path` from the open symbol, under - `title`, with `more` appended." + `title`, with `more` appended. Its holds are keys like any other: ◆ holds the + picture here until the next one, ◀ ▶ go between them." [title sid id path & more] (let [n (get-in @(rf/subscribe [::render/clip]) [:symbols sid :nodes id]) {:keys [on? hidden]} @(rf/subscribe [::render/tracing]) shown? (and on? (not (contains? hidden [sid id]))) - {:keys [frame time]} @(rf/subscribe [::sub/own-time path]) - holds (get-in n [:time :holds] []) - seek! #(rf/dispatch [::pb/seek (js/Math.round (+ (:at time) (/ % (:rate time))))])] + {:keys [frame] :as own} @(rf/subscribe [::sub/own-time path]) + holds (get-in n [:time :holds] [])] (into [section title - [:div.row - [:label.dim {:title "show it over the picture · a reference, never exported"} - [:input {:type "checkbox" :checked (boolean shown?) - :on-change #(rf/dispatch [::ui/show-trace [sid id] (not shown?)])}] - " show"]] - [:div.row {:style {:margin "5px 0"}} - ;; A DEAD BUTTON WITH NO REASON GIVEN is what reads as the feature not - ;; working, so say why there is nothing to hold. - (if (nil? frame) - [:span.dim "move the playhead over this layer to hold a frame"] - [:button {:title "hold the picture on this frame until the next hold" - :on-click #(rf/dispatch [::project/toggle-hold sid id frame])} - (if (some #{frame} holds) (str "remove hold at " frame) (str "hold at " frame))])] - (when (seq holds) - [:div.row - [:span.dim "holds"] - (doall - (for [f holds] - ^{:key f} - [:button {:class (when (= frame f) "on") - :disabled (nil? time) - :on-click #(seek! f)} - (str f)]))])] + [:div.chan + [key-nav holds frame own #(rf/dispatch [::project/toggle-hold sid id frame]) + (if (nil? frame) + "move the playhead over this layer to hold a frame" + "hold the picture on this frame until the next hold")] + [:span.chan-name "hold"] + [:span.chan-value + [:label.dim {:title "show it over the picture · a reference, never exported"} + [:input {:type "checkbox" :checked (boolean shown?) + :on-change #(rf/dispatch [::ui/show-trace [sid id] (not shown?)])}] + " show"]] + [:span.gap]]] more))) (def ^:private origins @@ -571,8 +576,8 @@ [face path] (let [reads (get-in @(rf/subscribe [::render/clip]) [:symbols face :nodes :head :reads])] [layer-section (str "tracing · " (name face)) face :plate (conj path :plate) - [:div.row {:style {:margin-top "5px"}} - [:span.dim "head"] + [:div.prop + [:span.prop-name "head"] (doall (for [[label r title] origins] ^{:key label} @@ -604,9 +609,10 @@ marks (pose/marks (:nodes sym) (:frames sym) store) on? (contains? smart face)] [section (str "performance \u00b7 " (name face)) - [:div.row {:style {:margin "5px 0"}} - [:label.dim {:title (str "let a closure the grid drops move the frame a slot " - "reads \u2014 backward, and only within that slot's own gap")} + [:div.row + [:label {:title (str "let a closure the grid drops move the frame a slot " + "reads \u2014 backward, and only within that slot's own gap" + " \u00b7 the stage only: an export is unaffected until this is a saved setting")} [:input {:type "checkbox" :checked on? :on-change #(rf/dispatch [::ui/smart-picking face (not on?)])}] " smart frame picking"]] @@ -622,48 +628,7 @@ (str/join " " (take 24 fs)) (when (> (count fs) 24) " \u2026"))} (str (if (vector? group) (str/join "/" (map name group)) (name group)) - " " (count fs))]))]) - [:div.row - [:span.dim "the stage only \u00b7 an export is unaffected until this is a saved setting"]]])) - -;; --------------------------------------------------------------------------- -;; a symbol - -(defn- symbol-section [sid & [title]] - (let [clip @(rf/subscribe [::render/clip]) - sym (get-in clip [:symbols sid]) - frame @(rf/subscribe [::render/open-frame]) - busy? (:busy? @(rf/subscribe [::playback/project]))] - [section (or title "symbol") - [facts - "id" (str sid) - "length" (str (:frames sym) " frames") - "stage" (let [[w h] (clip-domain/stage clip sid)] (str w "×" h)) - "nodes" (str (count (:nodes sym)))] - [:div.inspector-form - [name-field "name" (clip-domain/symbol-name clip sid) - #(rf/dispatch [::project/rename-symbol sid %])] - [number-field "length (frames)" (:frames sym) - #(rf/dispatch [::project/symbol-setting sid :frames %]) nil busy?] - [number-field "width" (:width sym) - #(rf/dispatch [::project/symbol-setting sid :width %]) "project default" busy?] - [number-field "height" (:height sym) - #(rf/dispatch [::project/symbol-setting sid :height %]) "project default" busy?] - [:label.inspector-field "authoring palette" - [:select {:value (str (or (:palette sym) "")) :disabled busy? - :on-change (fn [e] - (let [v (.. e -target -value) - id (first (filter #(= v (str %)) (keys (pal/palettes clip))))] - (rf/dispatch [::project/symbol-palette sid id])))} - [:option {:value ""} "inherit"] - (for [[id p] (sort-by (comp str :name val) (pal/palettes clip))] - ^{:key (str id)} [:option {:value (str id)} (:name p)])]] - (when (or (:width sym) (:height sym)) - [:div.row - [:button {:disabled busy? :on-click #(do - (rf/dispatch [::project/symbol-setting sid :width nil]) - (rf/dispatch [::project/symbol-setting sid :height nil]))} - "use project stage"]])]])) + " " (count fs))]))])])) ;; --------------------------------------------------------------------------- ;; tracked objects @@ -809,8 +774,8 @@ offset (if gaze (channel/value-at (:values gaze) current nil) [0 0])] (swap! draft assoc :opening opening :gaze-x (* 100 (first offset)) :gaze-y (* 100 (second offset))))))] - [:div {:style {:margin-top "8px"}} - [:div.dim "Eye adjustments · key a pose, then scrub and key another. Adjustments tween within this interval."] + [:div {:style {:margin-top "8px"} + :title "eye adjustments · key a pose, then scrub and key another; they tween within this interval"} [:label.inspector-field "eye" [:select {:value (name side) :on-change #(swap! draft assoc :side (keyword (.. % -target -value)))} @@ -846,8 +811,8 @@ repairs (distinct (for [[_ n] (get-in clip [:symbols sid :nodes]) [_ c] (:channels n) r (:repairs c)] r))] (r/with-let [draft (r/atom {:from 0 :through 1 :donor 2 :head? false})] - [section "repair intervals" - [:div.dim "Hold a clean pose across damaged frames. Face settings still apply. Frame numbers are local to this face, starting at 0."] + [section [:span {:title "hold a clean pose across damaged frames · face settings still apply · frames are this face's own, from 0"} + "repair intervals"] (for [[field label] [[:from "from face frame"] [:through "through face frame"] [:donor "clean donor frame"]]] @@ -874,6 +839,24 @@ [:button {:on-click #(rf/dispatch [::ui/remove-repair sid id])} "remove"]] [eye-repair-controls sid repair current]])]))) +;; --------------------------------------------------------------------------- + +(defn- symbol-view + "A symbol, selected or open with nothing selected: its name and settings." + [sid] + (let [clip @(rf/subscribe [::render/clip]) + sym (get-in clip [:symbols sid])] + [:<> + [header (if (= :palette (:type sym)) "palette" "symbol") + (clip-domain/symbol-name clip sid) (name sid) + #(rf/dispatch [::project/rename-symbol sid %]) (clip-domain/uses clip sid)] + [:div.props + (if (= :palette (:type sym)) + (prop "palette" + [:span {:title "keys and tweens are set on a placement in the palette lane"} + (or (get-in clip [:palettes (:palette-ref sym) :name]) (str (:palette-ref sym)))]) + [symbol-fields sid])]])) + (defn view [] (let [clip @(rf/subscribe [::render/clip]) open @(rf/subscribe [::render/open]) @@ -882,49 +865,40 @@ ;; tab would. inspected (or selection [:symbol open]) node @(rf/subscribe [::sub/selected-node]) - ;; The face the tracing section is about: the SELECTED PLACEMENT's symbol, - ;; or, when the selection is not an instance or there is none, the OPEN - ;; symbol — which is the face itself when a face is open to be drawn over. - ;; That last case had no section at all before, and it is the one where - ;; the keys are actually being set. - ;; The symbol this cel places, or nil for a lane: which face a - ;; lane traces is not a question with one answer, and naming the drawing - ;; showing now would move the section under the playhead. + ;; The symbol the selected node places, or nil. placed (node/source (peek node)) - footage-faces (footage-faces clip selection node) tracking-owners (tracking-owners clip selection node) palette-placement? (and node (= :palette-track (get-in clip [:symbols (first node) :type]))) palette-symbol? (and (= :symbol (first inspected)) (= :palette (get-in clip [:symbols (second inspected) :type]))) + ;; The face the face sections are about: the selected placement's symbol, + ;; or the open symbol when that is a face being drawn over. face (or placed (when (face? clip open) open)) layer? (and placed (clip-domain/trace? (clip-domain/symbol clip placed))) ;; Where that face or layer sits, as a row path from the open symbol. A ;; selection made on the stage has no path and names a node directly in ;; the open symbol; the open symbol itself is at no path at all. - path (if placed (or (nth selection 3 nil) [(second node)]) [])] + path (if placed (or (nth selection 3 nil) [(second node)]) []) + a-face? (and face (face? clip face) (not layer?))] [:section.pane.params [:div.pane-head "inspector"] - [:div {:style {:min-height 0}} - (when palette-placement? [palette-placement-section node]) - (when (= [:symbol (clip-domain/opens-on clip)] inspected) - [clip-section]) - (when (and node (not palette-placement?)) [node-section node]) - (when (and placed (not palette-placement?)) [instance-playback node]) + [:div.inspect + (cond + palette-placement? [palette-placement-view node] + node [node-view node] + (= :symbol (first inspected)) [symbol-view (second inspected)]) (when (and node (not palette-placement?)) [palette/remap-section]) - (when (and placed (not palette-placement?)) [symbol-section placed "source symbol"]) (when (and node (not palette-placement?)) ^{:key (str (first node) "/" (second node))} [correction-section node]) (when layer? - [layer-section (str "tracing · " (clip-domain/symbol-name clip placed)) - (first node) (second node) path]) + [layer-section "tracing" (first node) (second node) path]) (when (get-in clip [:symbols face :nodes :plate]) [face-section face path]) - (when (and face (face? clip face) (not layer?)) ^{:key (str "repair/" face)} [repair-section face path]) - (when (and face (not layer?)) ^{:key (str "perf/" face)} [performance-section face]) - (when palette-symbol? [palette-symbol-section (second inspected)]) - (when (and (= :symbol (first inspected)) (not palette-symbol?)) - [symbol-section (second inspected)]) + (when a-face? ^{:key (str "repair/" face)} [repair-section face path]) + (when a-face? ^{:key (str "perf/" face)} [performance-section face]) (when (and (seq tracking-owners) (not palette-placement?) (not palette-symbol?)) - [tracking-section tracking-owners])]])) + [tracking-section tracking-owners]) + (when (= [:symbol (clip-domain/opens-on clip)] inspected) + [project-fields])]])) diff --git a/frontend/src/arthur/ui/settings.cljs b/frontend/src/arthur/ui/settings.cljs index 35e25d5..e1a6e53 100644 --- a/frontend/src/arthur/ui/settings.cljs +++ b/frontend/src/arthur/ui/settings.cljs @@ -92,9 +92,9 @@ apply! (fn [mode] (close!) (rf/dispatch [::project/set-fps to mode])) changed? (and to (not= to fps))] [:<> - [:label.inspector-field "frame rate" - [:button {:disabled disabled? :on-click #(do (reset! draft fps) (reset! open? true))} - (str fps " fps")]] + [:button {:disabled disabled? :title "frame rate · change it" + :on-click #(do (reset! draft fps) (reset! open? true))} + (str fps " fps")] (when @open? [dialog "Frame rate" close! [chips (str "from " fps " fps to") rates to #(str % " fps") #(reset! draft %) diff --git a/frontend/src/arthur/ui/timeline.cljs b/frontend/src/arthur/ui/timeline.cljs index 0c315ce..aac831a 100644 --- a/frontend/src/arthur/ui/timeline.cljs +++ b/frontend/src/arthur/ui/timeline.cljs @@ -21,6 +21,7 @@ first pass is drawn. An expanded loop therefore shows keys where they first happen and not where they happen again." (:require [clojure.string :as str] + [arthur.domain.channel :as channel] [arthur.domain.node :as node] [arthur.domain.keyframes :as keyframes] [arthur.domain.clipboard :as clipboard] @@ -29,6 +30,7 @@ [arthur.domain.span :as span] [arthur.domain.symbol :as symbol] [arthur.events.playback :as pb] + [arthur.events.project :as project] [arthur.events.ui :as ui] [arthur.footage.store :as store] [arthur.ui.icon :as icon] @@ -89,6 +91,19 @@ {:sid sid :id (:id n) :channel channel :frame f :at (->open f) :scale (- (->open 1) (->open 0))}))) +(defn- gaps + "The stretches between one key of a channel and the next, each holding or + tweening, as Flash draws a classic tween between two keyframes. Nil for a + channel whose values are choices — a colour, a switch — which only ever hold." + [n sid path ch ->open] + (let [fs (keyed-frames ch)] + (when-not (node/hold-only? path (val (first (:keys ch)))) + (mapv (fn [[a b]] + {:sid sid :id (:id n) :channel path :left a + :from (->open a) :to (->open b) + :tween? (= :linear (channel/segment-interp ch a))}) + (partition 2 1 fs))))) + (defn- channel-rows [n sid path depth ->open span] (let [keyed (filter (comp seq :keys val) (sort-by (comp str key) (node/channels n)))] @@ -96,12 +111,13 @@ (for [[cpath ch] keyed] {:path (conj path cpath) :depth depth - :label (str/join " " (map name cpath)) + :label (node/channel-name cpath) :kind :channel :select nil :span span :keys (mapv ->open (keyed-frames ch)) :key-items (filterv #(= cpath (:channel %)) (key-items n sid ->open)) + :gaps (gaps n sid cpath ch ->open) :dense? (boolean (:dense ch))}) [{:path (conj path ::automation-hint) :depth depth @@ -171,6 +187,7 @@ :kind :node :node-kind (:kind child) :of (node/source child) + :uses (some->> (node/source child) (clip/uses clip)) :portal? true :select [:node sid (:id child) cpath] :expandable? true @@ -283,6 +300,7 @@ :node-kind (:kind n) :lane? lane? :of (node/source n) + :uses (some->> (node/source n) (clip/uses clip)) :select [:node sid id rpath] :expandable? true :expanded? open? @@ -623,7 +641,7 @@ on every render after, which would fight a person scrolling away." (memoize (fn [_selection] (fn [el] (some-> el (.scrollIntoView #js {:block "nearest"})))))) -(defn- label-cell [{:keys [path depth label kind node-kind lane? span select expandable? expanded? of via]} +(defn- label-cell [{:keys [path depth label kind node-kind lane? span select expandable? expanded? of via uses]} selection selections target-path over solo tracing renaming draft choose-row!] (let [node? (= :node kind) selected? (contains? selections select) @@ -639,6 +657,7 @@ (when (and select (= select selection)) " primary") (when (= path target-path) " target") (when lane? " lane") + (when (= :palette kind) " palette") (when (= :ghost kind) " ghost") (when (= path over-path) (case where @@ -726,6 +745,11 @@ "Escape" (do (.preventDefault e) (reset! renaming nil)) nil))}] [:span.name label]) + ;; How many places show this same drawing: rename it here and every one + ;; of them changes, and `make unique` is how to stop that. + (when (and uses (< 1 uses) (not editing?)) + [:span.uses {:title (str "placed " uses " times · a rename reaches every one")} + (str "(" uses ")")]) (cond lane? [:span.kind "·lane"] node? [:span.kind (if via (str "· in " via) (str "·" (name node-kind)))]) @@ -875,7 +899,7 @@ `:from` is the frame the press was on and `:df` how many frames the pointer has moved since. What it looks like mid-drag is `[:ui :sliding]`, which the clip every row and the stage are drawn from already has in it." - [{:keys [path span keys key-items dense? kind node-kind select slides cels lane? of unmapped? owner]} + [{:keys [path span keys key-items gaps dense? kind node-kind select slides cels lane? of unmapped? owner]} frames sliding hint {:keys [clip store open selection selections target-path key-selection key-preview key-anchor key-state key-elements choose-row!]}] (let [selected-set (set selections) active-row (:row @sliding) @@ -1224,6 +1248,21 @@ (when select [:span.tl-edge.out {:title "Drag endpoint · Shift-drag ripples later clips" :on-pointer-down #(begin! % (nth select 3) :out select nil nil)}])])) + ;; Click a gap between two keys to switch it between holding and tweening. + (doall + (for [{:keys [sid id channel left from to tween?]} gaps + :when (and (< from frames) (< 0 to))] + ^{:key left} + [:button.tl-gap + {:type "button" :class (when tween? "tween") + :title (if tween? "tween · click to hold" "hold · click to tween") + :style {:left (at% from frames) + :width (str (* 100 (/ (- to from) (max 1 frames))) "%")} + :on-pointer-down #(.stopPropagation %) + :on-click (fn [^js e] + (.stopPropagation e) + (rf/dispatch [::project/set-segment-interp sid id channel left + (if tween? :hold :linear)]))}])) ;; A dense channel has a value on every frame, so ticking each one is a solid ;; block that says less than the bar behind it already does. ;; The lane's own keys, and those of the clips on it drawn after the diff --git a/frontend/test/arthur/domain/instance_test.cljs b/frontend/test/arthur/domain/instance_test.cljs index 6667c84..9f715cb 100644 --- a/frontend/test/arthur/domain/instance_test.cljs +++ b/frontend/test/arthur/domain/instance_test.cljs @@ -281,9 +281,10 @@ (testing "an unnamed symbol falls back to its id, not to the node's uuid" (is (= "inner" (clip/node-label (update-in c [:symbols :inner] dissoc :name) id n)))) - (testing "but a name somebody typed on the instance still wins" - ;; Two instances of one symbol are told apart only by this. - (is (= "left eye" (clip/node-label c id (assoc n :name "left eye"))))) + (testing "and a name left on the instance is not read: it has none of its own" + (is (= "mouth" (clip/node-label c id (assoc n :name "left eye"))))) + (testing "every placement of a symbol is counted" + (is (= 1 (clip/uses c :inner)))) (testing "and a node that places nothing is labelled by its own name or id" (is (= "lid" (clip/node-label c :lid {:id :lid :kind :rect :name "lid"}))) (is (= "lid" (clip/node-label c :lid {:id :lid :kind :rect})))))) diff --git a/frontend/test/arthur/events/export_test.cljs b/frontend/test/arthur/events/export_test.cljs index 13d3ec7..a92c334 100644 --- a/frontend/test/arthur/events/export_test.cljs +++ b/frontend/test/arthur/events/export_test.cljs @@ -61,26 +61,26 @@ #uuid "22222222-2222-4222-8222-222222222222" {:id #uuid "22222222-2222-4222-8222-222222222222" :kind :instance :parent :root :z "a2" - :name "8625 right" :source {:symbol :sym/face}} #uuid "11111111-1111-4111-8111-111111111111" {:id #uuid "11111111-1111-4111-8111-111111111111" :kind :instance :parent :root :z "a1" - :name "8625 left" :source {:symbol :sym/face}} :a-rect {:id :a-rect :kind :rect :parent :root :z "a3"}}} :sym/face {:frames 40 :nodes {:root {:id :root :kind :group :z "a1"}}}}}) (deftest the-picker-offers-every-symbol-then-every-instance-in-the-open-one (let [ts (export/targets clip :main)] - (is (= ["main" "face" "8625 left" "8625 right"] (mapv :label ts)) + (is (= ["main" "face" "face 1" "face 2"] (mapv :label ts)) "every symbol, then the instances in the open one") (testing "the instances isolate a node in the open symbol and the symbols do not" (is (= [nil nil] (mapv :isolate (take 2 ts)))) (is (every? uuid? (mapv :isolate (drop 2 ts)))) (is (every? #(= :main (:symbol %)) (drop 2 ts)))) - (testing "ordered by label, because a uuid sorts at random" - (is (= ["8625 left" "8625 right"] (mapv :label (drop 2 ts))))) + (testing "one symbol placed twice is numbered in stacking order, because a uuid sorts at random" + (is (= [#uuid "11111111-1111-4111-8111-111111111111" + #uuid "22222222-2222-4222-8222-222222222222"] + (mapv :isolate (drop 2 ts))))) (testing "and a node that is not an instance is not offered" (is (not-any? #{"a-rect"} (map :label ts)))))) diff --git a/frontend/test/browser/take.mjs b/frontend/test/browser/take.mjs index 93d3721..6b3162c 100644 --- a/frontend/test/browser/take.mjs +++ b/frontend/test/browser/take.mjs @@ -562,31 +562,26 @@ async function main() { await page.eval(SEEK(f)); await sleep(100); check(await page.eval(`(() => { - const button = [...document.querySelectorAll('.params button')] - .find(b => b.textContent === 'drawing key here'); - if (!button || button.disabled) return false; + const button = document.querySelector('.params .chan[data-channel="geom pts"] button.key'); + if (!button || button.disabled || button.classList.contains('on')) return false; button.click(); return true; })()`), `a drawing key can be added at frame ${f}`); await sleep(100); } - await page.eval(SEEK(8)); + // Standing on key 16, the gap switch is about the gap arriving at it, 8 → 16. + const GAP = `document.querySelector('.params .chan[data-channel="geom pts"] button.gap')`; + await page.eval(SEEK(16)); await sleep(100); const tweenSelected = await page.eval(`(() => { - const label = [...document.querySelectorAll('.params label')] - .find(el => el.textContent.startsWith('key 8 → 16')); - const select = label?.querySelector('select'); - if (!select) return false; - select.value = 'linear'; - select.dispatchEvent(new Event('change', { bubbles: true })); + const gap = ${GAP}; + if (!gap || gap.getAttribute('aria-label') !== 'hold') return false; + gap.click(); return true; })()`); await sleep(100); - check(tweenSelected && await page.eval(`(() => { - const label = [...document.querySelectorAll('.params label')] - .find(el => el.textContent.startsWith('key 8 → 16')); - return label?.querySelector('select')?.value === 'linear'; - })()`), 'the second drawing gap can be set to tween'); + check(tweenSelected && await page.eval(`${GAP}?.getAttribute('aria-label') === 'tween'`), + 'the second drawing gap can be set to tween'); check((await statusMatching(/saved r\d+/)) !== null, 'the painted shape saves by itself', await page.eval(STATUS)); check(await fromMenu(MENU_PICK_NEWEST), 'the painted document can be reopened'); @@ -610,13 +605,10 @@ async function main() { re_frame.core.dispatch_sync(c.vector(k('arthur.events.ui/select'), c.vector(k('node'), k('main'), id, c.vector(id)))); })()`); - await page.eval(SEEK(8)); + await page.eval(SEEK(16)); await sleep(100); - check(await page.eval(`(() => { - const label = [...document.querySelectorAll('.params label')] - .find(el => el.textContent.startsWith('key 8 → 16')); - return label?.querySelector('select')?.value === 'linear'; - })()`), 'the per-gap tween setting survives the project round trip'); + check(await page.eval(`${GAP}?.getAttribute('aria-label') === 'tween'`), + 'the per-gap tween setting survives the project round trip'); // The local 8625 study is optional in a fresh test database. When present, // tune its shared symbol while its stage is playing. diff --git a/static/arthur/app.css b/static/arthur/app.css index dd5267f..6fe786e 100644 --- a/static/arthur/app.css +++ b/static/arthur/app.css @@ -926,7 +926,6 @@ button.share-button:hover, button.share-button.on { filter: brightness(1.1); } letter-spacing: .07em; } -.inspector-form { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; margin-top: 7px; } .inspector-field { display: grid; gap: 2px; color: var(--dim); } .inspector-field input { width: 100%; color: var(--fg); } @@ -936,11 +935,6 @@ button.share-button:hover, button.share-button.on { filter: brightness(1.1); } .correction-item { display: flex; align-items: center; gap: 4px; min-width: 0; } .correction-item > span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } -/* Label / value, once, for every read-only fact in the pane. */ -.facts { display: grid; grid-template-columns: auto 1fr; gap: 2px 8px; margin: 0; } -.facts dt { color: var(--dim); } -.facts dd { margin: 0; overflow: hidden; text-overflow: ellipsis; } - .knob { display: grid; gap: 1px; margin-bottom: 6px; } .knob .top-line { display: flex; justify-content: space-between; gap: 8px; } .knob .top-line .name { color: var(--dim); } @@ -1402,28 +1396,70 @@ button.share-button:hover, button.share-button.on { filter: brightness(1.1); } border-top: 1px solid var(--hair); } -/* A transform or visibility channel: its key button, then a field per component. */ -.facts dd.channel { display: flex; gap: 3px; align-items: center; overflow: visible; } -.facts dd.channel input[type=number] { width: 0; flex: 1; min-width: 0; } -.facts dd.channel .key { padding: 0 3px; color: var(--dim); } -.facts dd.channel .key.keyed { color: var(--fg); } -.facts dd.channel .key.on { color: var(--sel); } -.facts dd.channel .channel-swatches { - display: flex; - flex: 1; - flex-wrap: wrap; - gap: 3px; - min-width: 0; +/* The inspector. One column of names, 46px, and controls after it: the + header, then a row per channel, then labelled rows. */ +.inspect-head { + display: flex; align-items: center; gap: 5px; + padding: 6px; border-bottom: 1px solid var(--hair); + position: sticky; top: 0; z-index: 1; background: var(--pane); } -.facts dd.channel .channel-swatches .swatch { flex: 0 0 15px; } -.facts dd.channel.live { - margin: -2px; - padding: 2px; +.inspect-kind { color: var(--dim); flex: 0 0 auto; } +.inspect-name { flex: 1; min-width: 0; font-weight: 600; } +.uses, .tl-label .uses { color: var(--dim); flex: 0 0 auto; } + +.chans, .props { padding: 4px 6px; display: grid; gap: 3px; border-bottom: 1px solid var(--hair); } + +/* ◀ ◆ ▶ · name · value · gap */ +.chan { display: grid; grid-template-columns: auto 38px 1fr 16px; gap: 4px; align-items: center; min-height: 20px; } +.chan-name, .prop-name { color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } +.chan-value { display: flex; gap: 3px; align-items: center; min-width: 0; } +.chan-value input[type=number], .prop input[type=number] { width: 0; flex: 1; min-width: 0; } +.chan-value select, .prop select { flex: 1; min-width: 0; } +.chan.live { + margin: -1px -3px; padding: 1px 3px; border-radius: 3px; background: var(--live-bg); - box-shadow: 0 0 0 1px rgba(35, 148, 71, .45), 0 0 6px rgba(35, 148, 71, .28); + box-shadow: 0 0 0 1px rgba(35, 148, 71, .45); } -.facts dd.channel.live input { border-color: var(--live); } +.chan.live input { border-color: var(--live); } + +.key-nav { display: flex; align-items: center; } +.key-nav button, .chan .gap, .prop .icon, .chan-value .icon { + padding: 0; border: 0; background: none; width: 14px; height: 18px; + display: inline-flex; align-items: center; justify-content: center; + color: var(--dim); +} +.key-nav button:disabled { opacity: .3; } +.key-nav .key { width: 16px; } +.key-nav .key.keyed { color: var(--fg); } +.key-nav .key.on { color: var(--sel); } +.key-nav svg, .chan .gap svg, .prop .seg svg { width: 11px; height: 11px; } +.key-nav button:hover:not(:disabled), .chan button.gap:hover, .icon:hover:not(:disabled) { color: var(--fg); } +.chan .gap.on { color: var(--sel); } + +.chan-swatches { display: flex; flex-wrap: wrap; gap: 2px; min-width: 0; } +.chan-swatches .swatch { flex: 0 0 11px; width: 11px; height: 11px; } + +.prop { display: flex; gap: 4px; align-items: center; min-height: 20px; } +.prop > .prop-name { flex: 0 0 46px; } +.prop input[type=text] { flex: 1; min-width: 0; } + +.prop .seg button { padding: 1px 4px; display: inline-flex; align-items: center; } + +/* A gap between two keys of a channel row: empty where it holds, a ramp where + it tweens, as Flash draws a classic tween. Click to switch. */ +button.tl-gap { + position: absolute; top: 50%; height: 9px; margin-top: -4.5px; + padding: 0; border: 0; border-radius: 0; background: transparent; + cursor: pointer; z-index: 3; +} +button.tl-gap::after { + content: ""; position: absolute; left: 6px; right: 6px; top: 4px; height: 1px; + background: var(--line); +} +button.tl-gap.tween { background: rgba(47, 111, 192, .22); } +button.tl-gap.tween::after { top: 3px; height: 3px; background: var(--sel); } +button.tl-gap:hover { background: rgba(47, 111, 192, .28); } /* The selected node's transform box, in stage pixels (the SVG's viewBox). */ .paint-overlay .handles .box { fill: none; stroke: #e6ca8b; stroke-width: 0.5; stroke-dasharray: 2 1; pointer-events: none; } From b2b6af8f265bd347cfc8a03ea41982daa2ea60a0 Mon Sep 17 00:00:00 2001 From: Olive Vaughn Date: Sat, 10 Oct 2026 18:28:03 -0400 Subject: [PATCH 02/16] Bring the browser tests up to date - automation: pin the fixture to 120 frames; a blank document is 48 now, and the drags measure frames as fractions of a 120-frame ruler. - lane: create from the timeline's symbol/lane buttons, skip the palette lane when looking for lanes and rename buttons, and expect a lane's rename on its symbol. - lane, peg: wait out the page reloading under the first probes. Co-Authored-By: Claude Opus 5.5 --- frontend/test/browser/automation.mjs | 4 ++- frontend/test/browser/lane.mjs | 40 +++++++++++++++------------- frontend/test/browser/peg.mjs | 4 ++- 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/frontend/test/browser/automation.mjs b/frontend/test/browser/automation.mjs index b5f5e7a..a748c4d 100644 --- a/frontend/test/browser/automation.mjs +++ b/frontend/test/browser/automation.mjs @@ -78,7 +78,9 @@ try { await evaluate(`(() => { const k = cljs.core.keyword, v = cljs.core.vector, m = cljs.core.hash_map; - let c = arthur.domain.clip.blank(); + // The drags below measure frames as fractions of a 120-frame ruler, so the + // ruler is pinned rather than left to the blank document's length. + let c = cljs.core.assoc_in(arthur.domain.clip.blank(), v(k('symbols'), k('main'), k('frames')), 120); const rect = (id, at, keys) => m(k('id'), k(id), k('kind'), k('rect'), k('z'), id, k('time'), m(k('at'), at, k('rate'), 1), k('span'), v(0, 20), k('channels'), keys ? m(v(k('xform'), k('pos')), arthur.domain.channel.keyed(m(2, v(2,0), 4, v(4,0)), k('linear'))) : m()); diff --git a/frontend/test/browser/lane.mjs b/frontend/test/browser/lane.mjs index 6f7b32a..29b2fab 100644 --- a/frontend/test/browser/lane.mjs +++ b/frontend/test/browser/lane.mjs @@ -58,7 +58,11 @@ try { await send('Runtime.enable'); for (let i = 0; i < 100; i++) { - if (await evaluate('typeof arthur !== "undefined" && !!document.querySelector("canvas.stage")')) break; + try { + if (await evaluate('typeof arthur !== "undefined" && !!document.querySelector("canvas.stage")')) break; + } catch (error) { + if (!error.message.includes("Cannot find default execution context")) throw error; + } await sleep(100); } await evaluate(`(() => { @@ -78,21 +82,16 @@ try { await evaluate(`(() => { document.querySelectorAll('.menu-scrim').forEach(x => x.click()); return true })()`); await sleep(80); }; + // Creation is two buttons in the timeline's toolbar: a symbol, or a lane. const clickNew = async label => { await closeMenus(); assert(await evaluate(`(() => { - const menu = document.querySelector('.loc .menu-wrap > button'); - if (!menu) return false; - menu.click(); return true; - })()`), 'new menu exists'); - await sleep(100); - assert(await evaluate(`(() => { - const item = [...document.querySelectorAll('.menu-item')].find(${named(label)}); - if (!item || item.disabled) return false; - item.click(); return true; + const button = [...document.querySelectorAll('.creation-controls button')] + .find(b => b.textContent.trim() === ${JSON.stringify(label)}); + if (!button || button.disabled) return false; + button.click(); return true; })()`), `enabled creation command: ${label}`); await sleep(220); - await closeMenus(); }; const shot = async () => JSON.parse(JSON.stringify(await evaluate('laneSnapshot()'), (_key, value) => value?.uuid ?? value)); @@ -111,7 +110,7 @@ try { assert.equal((await shot()).clip.symbols.main.display, undefined, 'a blank document starts as an ordinary symbol'); - await clickNew('inside'); + await clickNew('symbol'); let s = await shot(); let placed = mainInstances(s); assert.equal(placed.length, 1, 'new symbol places one instance'); @@ -130,12 +129,12 @@ try { placed = mainInstances(s); assert.equal(placed.length, 2, 'explicit lane places a second symbol'); assert.equal(laneSymbols(s).length, 1, 'only the lane command marks a symbol as a lane'); - assert.equal(await evaluate('[...document.querySelectorAll(".tl-track")].filter(t => t.arthurLane).length'), 1, + assert.equal(await evaluate('[...document.querySelectorAll(".tl-track:not(.palette)")].filter(t => t.arthurLane).length'), 1, 'the explicit lane is drawn as one linear track'); - assert.equal(await evaluate('document.querySelectorAll(".tl-rename").length'), 1, + assert.equal(await evaluate('document.querySelectorAll(".tl-label:not(.palette) .tl-rename").length'), 1, 'the lane exposes its rename control'); - await evaluate('document.querySelector(".tl-rename").click()'); + await evaluate('document.querySelector(".tl-label:not(.palette) .tl-rename").click()'); await sleep(80); assert(await evaluate(`(() => { const input = document.querySelector('.tl-name-input'); @@ -147,13 +146,16 @@ try { })()`), 'lane rename editor opens'); await sleep(180); s = await shot(); - assert(mainInstances(s).some(n => n.name === 'Foreground'), 'lane name persists'); + // A lane is an instance, and an instance is called what it places: the + // rename lands on the lane's symbol, not on the placement. + assert(laneSymbols(s).some(sym => sym.name === 'Foreground'), 'lane name persists on its symbol'); + assert(!mainInstances(s).some(n => n.name), 'and the placement carries no name of its own'); // Drag a library symbol into the explicit lane. The row itself is the target; // no temporary lane is previewed or created. const drop = await evaluate(`(() => { const source = document.querySelector('.pool-row:not(.main) .pool-item[draggable="true"]'); - const track = [...document.querySelectorAll('.tl-track')].find(t => t.arthurLane); + const track = [...document.querySelectorAll('.tl-track:not(.palette)')].find(t => t.arthurLane); if (!source || !track) return null; source.scrollIntoView({block: 'center'}); const a = source.getBoundingClientRect(), b = track.getBoundingClientRect(); @@ -192,7 +194,7 @@ try { s = await shot(); assert.equal(laneSymbols(s).length, 2, 'a second explicit command creates a second lane'); const move = await evaluate(`(() => { - const tracks = [...document.querySelectorAll('.tl-track')].filter(t => t.arthurLane); + const tracks = [...document.querySelectorAll('.tl-track:not(.palette)')].filter(t => t.arthurLane); const from = tracks.find(t => t.querySelector('.tl-cel')); const to = tracks.find(t => t !== from); const cel = from?.querySelector('.tl-cel'); @@ -218,7 +220,7 @@ try { await evaluate(`re_frame.core.dispatch_sync(cljs.core.vector( cljs.core.keyword('arthur.events.project/new'))) `); await sleep(250); - await clickNew('inside'); + await clickNew('symbol'); const clipboardBaseline = (await shot()).clip; await shortcut('d', 'KeyD'); assert.equal(mainInstances(await shot()).length, 2, 'duplicate copies the selected instance'); diff --git a/frontend/test/browser/peg.mjs b/frontend/test/browser/peg.mjs index 8d30c02..cb44973 100644 --- a/frontend/test/browser/peg.mjs +++ b/frontend/test/browser/peg.mjs @@ -62,7 +62,9 @@ try { await send('Runtime.enable'); await send('Page.enable'); for (let i = 0; i < 160; i++) { - if (await evalJS('return !!(window.cljs && window.re_frame && window.arthur)')) break; + // The page can reload under the first probes, which then have no context + // to run in; that is not the page being broken, so wait it out. + try { if (await evalJS('return !!(window.cljs && window.re_frame && window.arthur)')) break; } catch {} await sleep(250); } From cd02eb04774b06eef16e08712b51d0e98ed8082b Mon Sep 17 00:00:00 2001 From: Olive Vaughn Date: Sat, 10 Oct 2026 18:29:42 -0400 Subject: [PATCH 03/16] Add symbols and uploads from the foot of the media pool MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A "+ symbol" and an "upload…" button pinned to the bottom of the pool, where a list's own "add one" goes. A new symbol goes into the library only, one empty frame placed nowhere, as Flash's New Symbol, and its name opens for editing. The pane head loses its "+". Converting footage reads "make roto". Co-Authored-By: Claude Opus 5.5 --- frontend/src/arthur/events/project.cljs | 11 +++++++++ frontend/src/arthur/ui/convert.cljs | 2 +- frontend/src/arthur/ui/pool.cljs | 32 ++++++++++++++++++------- static/arthur/app.css | 16 +++++++++++++ 4 files changed, 52 insertions(+), 9 deletions(-) diff --git a/frontend/src/arthur/events/project.cljs b/frontend/src/arthur/events/project.cljs index 4b4b962..2e2f4a7 100644 --- a/frontend/src/arthur/events/project.cljs +++ b/frontend/src/arthur/events/project.cljs @@ -697,6 +697,17 @@ (assoc-in % [:symbols sid :name] value) (update-in % [:symbols sid] dissoc :name))))))) +(rf/reg-event-db + ::add-symbol + (fn [db [_ sid]] + ;; Into the library and nowhere else, as Flash's New Symbol: one empty + ;; frame, placed in nothing until it is dragged somewhere. `sid` comes from + ;; the caller so the pool can open the new row's name for editing. + (if (clip/symbol (:clip (store/entry (:clip/current db))) sid) + db + (edit/transaction db #(assoc-in % [:symbols sid] + {:id sid :name (name sid) :frames 1 :nodes {}}))))) + (rf/reg-event-db ::symbol-setting (fn [db [_ sid key value]] diff --git a/frontend/src/arthur/ui/convert.cljs b/frontend/src/arthur/ui/convert.cljs index 6cc6f2a..6394dc8 100644 --- a/frontend/src/arthur/ui/convert.cljs +++ b/frontend/src/arthur/ui/convert.cljs @@ -91,4 +91,4 @@ "tracing layer"] [:button.on {:disabled (or loading? (< n 1) (empty? name)) :on-click #(rf/dispatch [::footage/convert])} - (if loading? "working…" "make symbol")]]]])))) + (if loading? "working…" "make roto")]]]])))) diff --git a/frontend/src/arthur/ui/pool.cljs b/frontend/src/arthur/ui/pool.cljs index d182cb5..7080cc6 100644 --- a/frontend/src/arthur/ui/pool.cljs +++ b/frontend/src/arthur/ui/pool.cljs @@ -38,6 +38,10 @@ `events.footage/relabel`. A symbol of ANOTHER project is renameable where it lives and not from here. + ADDING IS AT THE FOOT: a new empty symbol, which goes into the library and is + placed nowhere until it is dragged, and an upload, which is the same as a file + dropped on the pane. + THE WHOLE PANE IS THE DROP TARGET for a file. A video dropped anywhere in it uploads and lands in THIS PROJECT's media, and goes no further: which frames of it become a symbol, and what that symbol is called, is asked when it is dropped @@ -610,13 +614,7 @@ (reset! depth 0) (when-let [file (aget (.. e -dataTransfer -files) 0)] (rf/dispatch [::footage/upload file])))} - [:div.pane-head - "media pool" - [:span.spacer] - [:button {:title "add a video, a sound or an image" - :disabled loading? - :on-click #(.click (js/document.getElementById "pool-file"))} - "+"]] + [:div.pane-head "media pool"] [:input {:id "pool-file" :type "file" :accept "video/*,audio/*,image/*" :style {:display "none"} :on-change (fn [^js event] @@ -646,4 +644,22 @@ [:span.count (get tallies k)])]))] [:div.pane-body (if (= :project @scope) [this-project ctx] [all-assets ctx]) - (when status [:div.dim status])]]))) + (when status [:div.dim status])] + ;; At the foot, where a list's own "add one" goes, and pinned there so it + ;; does not scroll away under a long one. + [:div.pool-foot + [:button {:title "a new empty symbol in this project's library" + :on-click (fn [_] + (let [sid (clip/fresh-id document)] + (rf/dispatch [::project/add-symbol sid]) + (rf/dispatch [::ui/select [:symbol sid]]) + ;; Show its row and open its name, so what it + ;; is called is the next thing you type. + (reset! scope :project) + (reset! query "") + (reset! editing [:symbol sid])))} + "+ symbol"] + [:button {:title "add a video, a sound or an image — or drop one on this pane" + :disabled loading? + :on-click #(.click (js/document.getElementById "pool-file"))} + "upload…"]]]))) diff --git a/static/arthur/app.css b/static/arthur/app.css index 6fe786e..7985c5b 100644 --- a/static/arthur/app.css +++ b/static/arthur/app.css @@ -525,6 +525,22 @@ button.share-button:hover, button.share-button.on { filter: brightness(1.1); } } .pool-clear:hover { background: var(--hair); color: var(--fg); } +/* The pool's add buttons. Pushed to the bottom by the auto margin and sticky + there, so they sit at the foot of a short list and stay in view under a long + one. */ +.pool-foot { + position: sticky; + bottom: 0; + z-index: 2; + margin-top: auto; + display: flex; + gap: 4px; + padding: 3px 5px; + background: var(--chrome); + border-top: 1px solid var(--line); +} +.pool-foot > button { flex: 1; } + /* The scope tabs, in the vocabulary `ui/tabs` already established for symbols — the same object, so two rows of tabs on one screen read as one idea. */ .pool > .tabs { top: 45px; position: sticky; z-index: 2; } From 641f1fa18cb6c85b155a80542f129fe5e72cc680 Mon Sep 17 00:00:00 2001 From: Olive Vaughn Date: Sat, 10 Oct 2026 19:45:38 -0400 Subject: [PATCH 04/16] Hold a new cel in a lane, so stretching it shows what is drawn in it A double-clicked or newly created cel in a lane was a one-frame symbol playing at speed 1 and stopping at its end, so dragging its edge out left every frame past the first empty. It is now held at speed 0, as a drawing cel already is: the two are the same lane-creation operation. Co-Authored-By: Claude Opus 5.5 --- frontend/src/arthur/domain/clip.cljs | 6 ++++-- frontend/src/arthur/events/ui.cljs | 13 ++++++++++--- frontend/test/arthur/domain/sequence_test.cljs | 14 ++++++++++++++ 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/frontend/src/arthur/domain/clip.cljs b/frontend/src/arthur/domain/clip.cljs index 595bf97..d060042 100644 --- a/frontend/src/arthur/domain/clip.cljs +++ b/frontend/src/arthur/domain/clip.cljs @@ -555,7 +555,9 @@ of the symbol plays on `frame` of `host`, which is what dragging something onto a playhead is asking for. Its `:span` is in its OWN frames — the whole symbol, 0 to its length at `speed` — wherever it was dropped; see `node/placed-span`. - `speed` is 1 unless the symbol's frames are footage's at another rate. + `speed` is 1 unless the symbol's frames are footage's at another rate, and 0 + for a held cel, which shows its symbol's first frame and so starts one frame + long, as `span/held` does. Refused, returning the clip unchanged, when it would make a cycle: a symbol cannot be placed inside itself or inside anything it places." @@ -575,7 +577,7 @@ ;; Lexicographic draw order, as `domain/paint` does it: an instance made ;; later sits above one made earlier, and neither has to renumber. :z (str "z" (js/Date.now) "-" (name sid)) - :span [0 (js/Math.ceil (/ (:frames target) speed))] + :span [0 (if (pos? speed) (js/Math.ceil (/ (:frames target) speed)) 1)] :time {:mode :map :at frame :rate 1} :source {:symbol sid} :playback {:in 0 :speed speed :end :stop} diff --git a/frontend/src/arthur/events/ui.cljs b/frontend/src/arthur/events/ui.cljs index 97a33ff..6474729 100644 --- a/frontend/src/arthur/events/ui.cljs +++ b/frontend/src/arthur/events/ui.cljs @@ -883,7 +883,13 @@ seeded (assoc-in document [:symbols sid] new-symbol)] (span/place-symbol seeded st host instance-id sid at {:extent :grow-symbol - :remainder-id (random-uuid)})))] + :remainder-id (random-uuid) + ;; Held like a drawing cel, so + ;; stretching it shows what is drawn + ;; in it across the whole cel. + :speed (if (and (= :lane destination-kind) + (not lane?)) + 0 1)})))] (if-let [why (:refused result)] (update db :project merge {:status why}) (let [selection [:node host instance-id (conj (vec down) instance-id)]] @@ -1026,7 +1032,7 @@ (rf/reg-event-db ::new-symbol-at ;; ONE GESTURE AND ONE CREATION PATH FOR EVERY LANE. Empty space in a lane - ;; takes a new one-frame symbol at the frame double-clicked -- the pointer + ;; takes a new one-frame held symbol at the frame double-clicked -- the pointer ;; names a place in time as well as a lane, which is the whole of the gesture ;; and the reason it is not the playhead's. The DESTINATION decides what is ;; created there: a clip of a palette track is a palette symbol whose @@ -1047,7 +1053,8 @@ palette? (assoc :type :palette))) result (span/place-symbol seeded st (:sid where) uuid sid (:at where) {:extent :grow-symbol - :remainder-id (random-uuid)}) + :remainder-id (random-uuid) + :speed 0}) result (if-let [placed (and palette? (:clip result))] (assoc result :clip (assoc-in placed [:symbols (:sid where) :nodes uuid diff --git a/frontend/test/arthur/domain/sequence_test.cljs b/frontend/test/arthur/domain/sequence_test.cljs index 5248810..6a4481f 100644 --- a/frontend/test/arthur/domain/sequence_test.cljs +++ b/frontend/test/arthur/domain/sequence_test.cljs @@ -879,3 +879,17 @@ (is (= 10 (get-in result [:clip :symbols :main :nodes :insert :time :at]))) (is (= (get-in doc [:symbols :wave :nodes]) (get-in result [:clip :symbols :wave :nodes]))))) + +(deftest a-held-placement-shows-its-first-frame-for-as-long-as-it-lasts + (let [lane (-> (document) + (assoc-in [:symbols :main] {:id :main :frames 40 :display :lane :nodes {}}) + (assoc-in [:symbols :blank] {:id :blank :frames 1 :nodes {}})) + placed (:clip (span/place-symbol lane nil :main :cel :blank 0 + {:extent :grow-symbol :remainder-id :r :speed 0})) + stretched (:clip (span/resize-out placed :main :cel 6 {:extent :grow-symbol})) + n (get-in stretched [:symbols :main :nodes :cel])] + (is (= [0 1] (node/placed-span (get-in placed [:symbols :main :nodes :cel]))) + "a held cel starts one frame long rather than its symbol's length over zero") + (is (= [0 6] (node/placed-span n))) + (is (every? #(= {:symbol :blank :frame 0} (node/placed-frame n % 1)) (range 6)) + "stretched, every frame of it shows the one drawing"))) From 1a6d6564c55b9133aed4aed55862ba545b456805 Mon Sep 17 00:00:00 2001 From: Olive Vaughn Date: Sat, 10 Oct 2026 19:47:44 -0400 Subject: [PATCH 05/16] One palette per frame, chosen by the shallowest override in the open tab MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A frame is drawn in exactly one palette, or one blend of two while a palette lane tweens. Shapes store slots and the raster index is the slot, so the palette is only the ramp a frame is expanded through: there is no way for two palettes' colours to share a frame. The per-palette index banks are gone. Every symbol drawn says which palette it chooses — its lane, its instance's palette, its own — and the shallowest wins, so a palette set on the open symbol beats anything inside it, and a child set to one turns the whole frame while it is drawn. Nothing chosen is the project's palette. The palette grid follows the palette the stage is in, per tab, read from the player rather than worked out again; mid-tween it holds the start palette. Another can be opened per tab, with a button back to the active one. The chooser puts the palettes the open symbol uses first, saying where, then the project's, then palettes made in other projects (with their project, and searchable by either name), each with the playhead's frame drawn in it; hovering previews on the stage, `use` sets the symbol to it. The classics are a folded shelf, now with VGA, Commodore 64, CGA and Workbench 1.3, and a new project carries only the palette it was made with. Unused slots are marked; solo shows and lets you click only what is drawn in the chosen colour; ⌫ empties the open palette's unused slots in place. The project palette can be changed in the inspector. The palette lane's label no longer collides with the sidebar grid's styles. Co-Authored-By: Claude Opus 5.5 --- clips/tests/test_api.py | 4 +- clips/views.py | 23 ++ frontend/src/arthur/domain/clip.cljs | 190 ++++++----- frontend/src/arthur/domain/palette.cljs | 220 ++++++++----- frontend/src/arthur/events/export.cljs | 2 +- frontend/src/arthur/events/playback.cljs | 5 + frontend/src/arthur/events/project.cljs | 54 ++- frontend/src/arthur/export.cljs | 2 +- frontend/src/arthur/flow/freeze.cljs | 11 +- frontend/src/arthur/subs/render.cljs | 33 +- frontend/src/arthur/ui/palette.cljs | 311 +++++++++++++----- frontend/src/arthur/ui/params.cljs | 49 ++- frontend/src/arthur/ui/player.cljs | 52 +-- frontend/src/arthur/ui/pool.cljs | 21 +- frontend/src/arthur/ui/timeline.cljs | 7 +- .../test/arthur/domain/instance_test.cljs | 164 ++++----- frontend/test/arthur/domain/leaf_test.cljs | 2 +- frontend/test/arthur/domain/rate_test.cljs | 3 +- frontend/test/arthur/flow/freeze_test.cljs | 12 +- .../test/arthur/flow/multi_face_test.cljs | 4 +- frontend/test/browser/take.mjs | 6 +- static/arthur/app.css | 118 +++++-- 22 files changed, 865 insertions(+), 428 deletions(-) diff --git a/clips/tests/test_api.py b/clips/tests/test_api.py index 706c89a..5d2aa52 100644 --- a/clips/tests/test_api.py +++ b/clips/tests/test_api.py @@ -436,8 +436,8 @@ class DocumentTests(TestCase): self.assertEqual(200, self.save(leaves).status_code) rows = self.client.get("/api/symbols").json()["palettes"] self.assertEqual( - [("Moonlit", "night", "c1")], - [(r["name"], r["palette"], r["cid"]) for r in rows], + [("Moonlit", "night", "c1", ["#001122"])], + [(r["name"], r["palette"], r["cid"], r["hexes"]) for r in rows], ) def test_a_document_comes_back_exactly(self): diff --git a/clips/views.py b/clips/views.py index 597a286..1f6306e 100644 --- a/clips/views.py +++ b/clips/views.py @@ -413,6 +413,26 @@ def footage_list(request): _SYMBOL_LEAF = re.compile(r"^clip/([^/]+)/symbol/([^/]+)$") _PALETTE_LEAF = re.compile(r"^clip/([^/]+)/palette/([^/]+)$") +_HEX = re.compile(r"#[0-9a-fA-F]{6}") + + +def _slot_hexes(value): + """A palette leaf's slot colours, in order. Every slot carries exactly one + hex, so they are read off whatever follows `:slots` without decoding + transit's caches.""" + if not isinstance(value, list) or "~:slots" not in value: + return [] + out = [] + + def walk(x): + if isinstance(x, list): + for y in x: + walk(y) + elif isinstance(x, str) and _HEX.fullmatch(x): + out.append(x.lower()) + + walk(value[value.index("~:slots") + 1]) + return out def _transit_fields(value, *keys): @@ -459,6 +479,9 @@ def symbols(request): "cid": m.group(1), "palette": m.group(2), "name": fields.get("name") or m.group(2).replace("~", "/"), + # Every slot carries exactly one hex, in order, so the strip is + # read off the value without decoding transit's caches. + "hexes": _slot_hexes(leaf.value), }) palettes.sort(key=lambda r: (r["project_name"], r["project"], r["name"])) return JsonResponse({"symbols": rows, "palettes": palettes}) diff --git a/frontend/src/arthur/domain/clip.cljs b/frontend/src/arthur/domain/clip.cljs index d060042..9bb0257 100644 --- a/frontend/src/arthur/domain/clip.cljs +++ b/frontend/src/arthur/domain/clip.cljs @@ -188,17 +188,18 @@ and the swarm carry no `:subjects` — so every reader already reads absence as none, and `clip-keys` says which fields MAY be here, not which must. - `settings` overrides any of `blank-settings`. It starts with every one of - `palette/presets`, and `:palette` is the id of the one it draws with." + `settings` overrides any of `blank-settings`. `:palette` names the preset it + draws with, and that one is the project's only palette until more are added." ([] (blank {})) ([settings] (let [{:keys [fps seconds width height palette] :as s} (merge blank-settings (into {} (remove (comp nil? val)) settings)) - presets (into {} (map (juxt :id identity)) pal/presets)] + presets (into {} (map (juxt :id identity)) pal/presets) + palette (if (contains? presets palette) palette pal/default-id)] {:name (:name s) :fps fps :width width :height height - :palettes presets - :default-palette (if (contains? presets palette) palette pal/default-id) + :palettes (select-keys presets [palette]) + :default-palette palette :root :main :symbols {:main {:id :main :frames (max 1 (js/Math.round (* seconds fps))) :nodes {}}}}))) @@ -306,80 +307,115 @@ (ch/value-at selection frame store) :else selection)) -(defn palette-at - "The palette symbol `owner` draws in at `frame`, as the stage's root does: a - palette id, or `{:from :to :t}` while its palette lane blends from one to the - next. `inherited` is what an unset palette falls back to, then `default`." - [clip store default owner frame inherited] - ;; A palette track has meaningful uncovered time. Ordinary held - ;; channels clamp to their first key before it, but doing that - ;; here would erase the gap before the first palette segment. - (let [channel-value (partial channel-value store) - fallback (or (channel-value (:palette owner) frame) - inherited default) - materialize (fn [choice] - (cond - (= pal/inherit choice) fallback - (map? choice) (-> choice - (update :from #(if (= pal/inherit %) fallback %)) - (update :to #(if (= pal/inherit %) fallback %))) - :else choice)) - track (:palette-channel owner) - track-value (if-let [ks (:keys track)] - (some->> (keys ks) - (filter #(<= % frame)) - sort last - (get ks)) - (channel-value track frame))] - (or (when-let [track-sid (and (keyword? (:palette-track owner)) - (:palette-track owner))] - (let [track-symbol (symbol clip track-sid) - palette-clip (first +(defn- own-palette + "The palette symbol `owner` itself chooses at `frame`, or nil when it chooses + none and takes what it is in: its palette lane where a segment covers the + frame, else its own `:palette` (which an instance's palette stands in for). + A lane's `inherit` end means the symbol's own palette when it has one, and + stays `inherit` — whatever the frame is in without this lane — when not. + A palette lane has meaningful uncovered time: ordinary held channels clamp to + their first key before it, which here would erase the gap before the first + segment." + [clip store owner frame] + (let [own (channel-value store (:palette owner) frame) + fill #(if (and own (= pal/inherit %)) own %) + settle (fn [choice] (if (map? choice) (-> choice (update :from fill) (update :to fill)) (fill choice))) + track (:palette-channel owner)] + (or (when-let [track-symbol (some->> (:palette-track owner) (symbol clip))] + (let [palette-clip (first (filter (fn [n] (let [[a b] (node/placed-span n)] (and a (<= a frame) (< frame b)))) (symbol/children (:nodes track-symbol)))) - palette-symbol (some-> palette-clip node/source - (#(symbol clip %))) - fallback (when (= :palette (:type palette-symbol)) - (:palette-ref palette-symbol)) + palette-symbol (some-> palette-clip node/source (#(symbol clip %))) choice (get-in palette-clip [:channels [:palette]]) start (some-> palette-clip node/placed-span first)] (or (when (and choice start) - (materialize (channel-value choice (- frame start)))) - fallback))) - track-value - fallback))) + (settle (channel-value store choice (- frame start)))) + (when (= :palette (:type palette-symbol)) + (:palette-ref palette-symbol))))) + (if-let [ks (:keys track)] + (some->> (keys ks) (filter #(<= % frame)) sort last (get ks)) + (channel-value store track frame)) + own))) + +(defn- settle + "`choice` with an `inherit` end standing for `under`, what the frame would be + in without it." + [choice under] + (let [under (if (map? under) (:from under) under) + fill #(if (= pal/inherit %) under %)] + (cond + (nil? choice) under + (map? choice) (-> choice (update :from fill) (update :to fill)) + :else (fill choice)))) + +(defn palette-at + "The palette symbol `owner` chooses at `frame`, with what it does not choose + standing for `inherited`, then `default`: an id, or `{:from :to :t}` while + its palette lane blends." + [clip store default owner frame inherited] + (settle (own-palette clip store owner frame) (or inherited default))) + +(defn frame-palette + "THE ONE PALETTE A FRAME IS IN, from what each symbol drawn in it chooses: + `choices` is `[depth choice]` in draw order, the open symbol at depth 0. + The SHALLOWEST choice wins — a palette set on the open symbol overrides + anything inside it — and between two at one depth the one drawn last, on + top. What the winner leaves to `inherit` is the next choice down, and under + them all the project's." + [default choices] + (reduce (fn [under [_ choice]] (settle choice under)) + default + ;; Deepest first, so the shallowest settles last; `sort-by` is + ;; stable, so at one depth the one drawn last does. + (sort-by (comp - first) choices))) + +(defn palette-uses + "Every palette symbol `sid` and what it places choose, and where: + `{:palette :sid :via}`, `:via` being `:symbol` for a symbol's own, `:lane` for + its palette lane and `:instance` for an instance set to one. Outermost first, + each once. A palette nothing chooses is the one inherited, so is not here." + [clip sid] + (loop [todo [sid] seen #{} out []] + (if-let [s (first todo)] + (if (contains? seen s) + (recur (rest todo) seen out) + (let [sym (symbol clip s) + lane (symbol clip (:palette-track sym)) + use (fn [via x] (map (fn [p] {:palette p :sid s :via via}) (pal/choices x))) + nodes (vals (:nodes sym))] + (recur (concat (rest todo) (mapcat node/sources (filter #(= :instance (:kind %)) nodes))) + (conj seen s) + (into out (distinct) + (concat (use :symbol (:palette sym)) + (use :lane (:palette-channel sym)) + (mapcat (fn [n] + (concat (use :lane (:palette-ref (some->> (node/source n) (symbol clip)))) + (use :lane (get-in n [:channels [:palette]])))) + (vals (:nodes lane))) + (mapcat #(use :instance (:palette %)) nodes)))))) + (vec (distinct out))))) (defn resolver "Resolve an output frame, selecting native content at each symbol boundary. Every instance owns its cursors and buffers. The IResolver queries return native node frames and world matrices for the last rendered output frame." [clip sid store palette opts] - (let [context? (and (map? palette) (:palettes palette) (:offsets palette)) - active-palette-state (atom (:default palette))] - (letfn [(root-selection-at [owner frame inherited] - (palette-at clip store (:default palette) owner frame inherited)) - (selection-at [owner frame inherited] - (let [selection (:palette owner) - chosen (cond - (nil? selection) nil - (and (map? selection) (contains? selection :animated?)) - (ch/value-at selection frame store) - :else selection)] - (or chosen inherited (:default palette)))) - (build [sid chain pose-tracks root?] + (let [context? (and (map? palette) (contains? palette :palettes)) + active-palette-state (atom (:default palette)) + ;; What each symbol drawn this frame chooses, as `[depth choice]`. + chosen (volatile! [])] + (letfn [(build [sid chain pose-tracks root?] (when (some #{sid} chain) (throw (ex-info "symbol cycle" {:chain (conj chain sid)}))) (let [sym (or (symbol clip sid) (throw (ex-info "an instance names a missing symbol" {:symbol sid}))) - active (volatile! (when context? (:default palette))) + depth (count chain) nodes (:nodes sym) rank (symbol/draw-rank nodes (symbol/order nodes)) ids (sort-by rank (keys nodes)) - own (symbol/resolver sym store (if context? - #(pal/render-index palette @active %) - palette) + own (symbol/resolver sym store (if context? pal/slot palette) (assoc opts :pose-tracks pose-tracks)) ;; Each cel owns its source resolver and mutable buffers. A ;; tracing symbol has nothing to resolve: it is one op. @@ -399,16 +435,18 @@ ;; A symbol that knocks out is drawn into a layer of its own, ;; so what it clears is only ever its own. layered? (symbol/knocks? nodes) - step (fn [f pre inherited forced] + ;; Each symbol drawn says which palette it chooses, if any; + ;; the root, once all are drawn, makes the frame's ONE + ;; palette of them. Shapes draw slots, so nothing drawn + ;; depends on which. An instance's palette stands in for the + ;; symbol's own, so its lane still plays. + step (fn [f pre override] + (when root? (vreset! chosen [])) (when context? - (vreset! active (or forced - (if root? - (root-selection-at sym (js/Math.floor f) inherited) - inherited) - (:default palette)))) - ;; The same decision that maps local drawing slots to - ;; the active bank also names the clear colour. - (when root? (reset! active-palette-state @active)) + (when-let [c (own-palette clip store + (cond-> sym override (assoc :palette override)) + (js/Math.floor f))] + (vswap! chosen conj [depth c]))) (vreset! entered {}) (let [by-id (into {} (map (juxt :node identity)) (own (js/Math.floor f) (js/Math.floor pre)))] @@ -450,17 +488,15 @@ (or (:frame (when (number? prior) (placed-frame clip n prior))) (dec frame)) - @active - (when (and context? (:palette n)) - (selection-at n frame nil))))))) + (:palette n)))))) (when-let [op (get by-id id)] [op])))) ids)) layered? (conj {:kind :end :node []}))))] (reify IFn - (-invoke [_ f] (step f (dec f) nil nil)) - (-invoke [_ f pre] (step f pre nil nil)) - (-invoke [_ f pre inherited forced] (step f pre inherited forced)) + (-invoke [_ f] (step f (dec f) nil)) + (-invoke [_ f pre] (step f pre nil)) + (-invoke [_ f pre override] (step f pre override)) symbol/IResolver (world-of [_ [id & more]] (if more @@ -484,7 +520,11 @@ IFn ;; `pre` is the frame before, so a child placed at a speed is handed ;; the interval `(pre, f]` its preserve-snap may reach back into. - (-invoke [_ f] (r f (dec f) (when context? (:default palette)) nil)) + (-invoke [_ f] + (let [ops (r f (dec f))] + (when context? + (reset! active-palette-state (frame-palette (:default palette) @chosen))) + ops)) symbol/IResolver (world-of [_ path] (symbol/world-of r path)) (frame-of [_ path] (symbol/frame-of r path)) diff --git a/frontend/src/arthur/domain/palette.cljs b/frontend/src/arthur/domain/palette.cljs index 4e5fa9d..d213375 100644 --- a/frontend/src/arthur/domain/palette.cljs +++ b/frontend/src/arthur/domain/palette.cljs @@ -64,10 +64,30 @@ free)}) (def presets - "Palettes a new project starts with, borrowed from worlds that already work - in sixteen colours or fewer. Only the one a project draws with costs it - anything; the rest are there to switch to." + "Palettes borrowed from worlds that already work in sixteen colours or fewer: + a shelf to start a project from or add to one, kept out of the project until + then. A sixteen-colour machine's palette is all sixteen of its colours, each + once, the face tones picked from them; a four-colour one repeats, and a face + in it reads by value alone, as on a Game Boy." [default-palette + ;; The sixteen colours of the IBM PC's text modes, which VGA kept from EGA + ;; and CGA: the DOS blue behind, the light red and brown every EGA face was. + (preset :arthur/vga "VGA" + ["#0000aa" "#ff5555" "#aa5500" "#aa0000" "#ffffff" "#aaaaaa" "#00aaaa" "#000000" "#555555"] + ["#00aa00" "#aa00aa" "#55ff55" "#55ffff" "#ff55ff" "#ffff55" "#5555ff"]) + ;; The Commodore 64's VIC-II as Pepto measured it, on its own blue screen. + (preset :arthur/c64 "Commodore 64" + ["#352879" "#9a6759" "#6f4f25" "#68372b" "#ffffff" "#959595" "#70a4b2" "#000000" "#433900"] + ["#6f3d86" "#588d43" "#b8c76f" "#444444" "#6c6c6c" "#9ad284" "#6c5eb5"]) + ;; CGA's four-colour mode, palette 1 at high intensity: magenta skin shaded + ;; in cyan, as it was. + (preset :arthur/cga "CGA" + ["#000000" "#ff55ff" "#55ffff" "#000000" "#ffffff" "#ffffff" "#55ffff" "#000000" "#000000"] + ["#ff55ff" "#55ffff" "#ffffff" "#000000" "#ff55ff" "#55ffff" "#ffffff"]) + ;; The Amiga's Workbench 1.3: four colours, blue, white, black and orange. + (preset :arthur/workbench "Workbench 1.3" + ["#0055aa" "#ff8800" "#000022" "#000022" "#ffffff" "#ffffff" "#0055aa" "#000022" "#000022"] + ["#0055aa" "#ffffff" "#000022" "#ff8800" "#0055aa" "#ffffff" "#ff8800"]) ;; Lexaloffle's PICO-8, all sixteen, its peach and brown as the skin ramp. (preset :arthur/pico-8 "PICO-8" ["#1d2b53" "#ffccaa" "#ab5236" "#7e2553" "#fff1e8" "#c2c3c7" "#29adff" "#000000" "#5f574f"] @@ -99,89 +119,133 @@ (when (contains? ps default-id) default-id) (first (sort-by str (keys ps)))))) -(defn- slot-index [p value] +;; ONE PALETTE PER FRAME +;; +;; A frame is drawn in exactly one palette, or one blend of two while a palette +;; lane tweens. Drawing data stores slot numbers, so the raster index IS the +;; slot, and the palette is only the ramp the raster is expanded through. Which +;; palette a frame is in is decided by the open symbol's tree; see +;; `clip/resolver`. + +(def bg-slot + "Slot zero is what a frame is cleared to, in whichever palette it is in." + 0) + +(defn slot + "A shape's colour as a raster index: its slot number, or a legacy tone + keyword's place in `entries`. Anything else is 255, the conspicuous + bad-data sentinel, which the ramp has no colour for and so shows MAGENTA." + [value] (cond - (and (integer? value) (<= 0 value) (< value (count (:slots p)))) value + (and (integer? value) (<= 0 value) (< value 255)) value ;; Compatibility for existing documents. New drawing data is numeric. - (keyword? value) (first (keep-indexed #(when (= value (:name %2)) %1) (:slots p))) - :else nil)) + (keyword? value) (get index-of value 255) + :else 255)) + +(defn choices + "The palette ids a palette setting can name: the one it holds, or each its + keys do. `inherit` is not one." + [x] + (remove #(= inherit %) + (cond + (nil? x) [] + (and (map? x) (:keys x)) (vals (:keys x)) + (and (map? x) (contains? x :value)) [(:value x)] + :else [x]))) (defn compile - "Compile the project's palette assets into the one ramp used by the raster. - Index 255 remains the conspicuous bad-data sentinel." + "The project's palettes and the one a frame falls back to, for a renderer." [clip] - (let [selection-values (fn [x] - (cond - (nil? x) [] - (and (map? x) (:keys x)) (vals (:keys x)) - (and (map? x) (contains? x :value)) [(:value x)] - :else [x])) - used (into #{(default-palette-id clip)} - (mapcat selection-values) - (concat (map :palette (vals (:symbols clip))) - (map :palette-channel (vals (:symbols clip))) - (map (fn [sym] - (when (= :palette (:type sym)) (:palette-ref sym))) - (vals (:symbols clip))) - (for [sym (vals (:symbols clip)) - n (vals (:nodes sym))] - (:palette n)) - (for [sym (vals (:symbols clip)) - n (vals (:nodes sym))] - (get-in n [:channels [:palette]])))) - ps (select-keys (palettes clip) used) - ordered (sort-by (comp str key) ps) - offsets (loop [xs ordered at 0 out {}] - (if-let [[id p] (first xs)] - (recur (next xs) (+ at (count (:slots p))) (assoc out id at)) - out)) - total (reduce + (map #(count (:slots (val %))) ordered))] - (when (> total 255) - (throw (ex-info "palettes visible in one render use more than 255 slots" - {:slots total :palettes (count ps)}))) - {:palettes ps - :default (default-palette-id clip) - :offsets offsets - :ramp (vec (mapcat (fn [[_ p]] (map #(hex->rgb (:hex %)) (:slots p))) ordered)) - :bg (get offsets (default-palette-id clip) 0)})) + {:palettes (palettes clip) + :default (default-palette-id clip)}) -(defn render-index - "A local slot (or a legacy tone keyword) in palette `id` -> raster index." - [{:keys [palettes offsets]} id value] - (let [id (if (map? id) (:from id) id) - p (get palettes id) - i (and p (slot-index p value))] - (if (some? i) (+ (get offsets id 0) i) 255))) - -(defn background-index - "The raster index of slot zero in the resolver's active palette. - - `index-of` remains a supported legacy palette map for domain callers; it has - no palette banks or active selection, so its established `:bg` index applies." - [palette active] - (if (and (:palettes palette) (:offsets palette)) - (render-index palette active 0) - (get palette :bg 0))) +(defn ramp-of + "A strip of hex colours as the ramp a raster is expanded through." + [hexes] + (mapv hex->rgb hexes)) (defn effective-ramp - "The compiled ramp with the active palette blend applied. A hold returns the - original vector; a linear palette segment rewrites only the left palette's - bank, which is the bank the indexed raster was drawn into." - [{:keys [palettes offsets ramp]} active] - (if-let [{:keys [from to t]} (when (map? active) active)] - (let [a (get palettes from) - b (get palettes to) - at (get offsets from) - n (min (count (:slots a)) (count (:slots b)))] - (if (and a b (number? at) (number? t)) - (reduce (fn [out i] - (let [x (hex->rgb (get-in a [:slots i :hex])) - y (hex->rgb (get-in b [:slots i :hex]))] - (assoc out (+ at i) - (mapv #(js/Math.round (+ %1 (* t (- %2 %1)))) x y)))) - ramp (range n)) - ramp)) - ramp)) + "The ramp of the active palette: an id, or `{:from :to :t}` while a palette + lane blends, which is one pseudopalette mixed slot by slot. A slot only one + end has keeps its colour." + [{:keys [palettes default]} active] + (let [ramp #(ramp-of (map :hex (:slots (get palettes %))))] + (if-let [{:keys [from to t]} (when (map? active) active)] + (let [a (ramp from) b (ramp to)] + (if (number? t) + (into (mapv (fn [x y] (mapv #(js/Math.round (+ %1 (* t (- %2 %1)))) x y)) a b) + (drop (count b) a)) + a)) + (ramp (if (contains? palettes active) active default))))) + +(defn solo-ramp + "`ramp` with every slot but `shown` faded most of the way to the background, + so what is drawn in `shown` is all that stands out." + [ramp shown] + (let [bg (get ramp bg-slot [0 0 0]) + fade (fn [c] (mapv (fn [x b] (js/Math.round (+ b (* 0.2 (- x b))))) c bg))] + (into [] (map-indexed (fn [i c] (if (= i shown) c (fade c)))) ramp))) + +;; --------------------------------------------------------------------------- +;; which slots drawing uses +;; +;; A slot number means the same place in EVERY palette — that is what lets one +;; drawing be shown in any of them — so a slot is in use when any shape names +;; it, whichever palette it is seen in. + +(defn- colour-slots + "The slots a colour channel names at any key: a slot, a legacy tone, or both + sides of a remap's map. A knockout names none." + [ch] + (let [values (if (:keys ch) (vals (:keys ch)) [(:value ch)])] + (into #{} + (comp (mapcat (fn [v] + (cond + (and (vector? v) (= :remap (first v))) (mapcat identity (second v)) + (= :clear v) [] + :else [v]))) + (map slot) + (remove #{255})) + values))) + +(defn slots-used + "Every slot a shape in `symbols` names." + [symbols] + (into #{} + (mapcat #(some-> (get-in % [:channels [:style :color]]) colour-slots)) + (mapcat (comp vals :nodes) symbols))) + +(def empty-slot + "A slot with nothing in it: black, unnamed, as a new palette's free ones are." + {:hex "#000000"}) + +(defn emptyable + "The slots of palette `p` that can be emptied: none of `used` names them, and + they are not already empty. Slot zero is the background, and a NAMED slot is + a face tone measurement draws in whether or not anything uses it yet." + [p used] + (into [] + (keep-indexed (fn [i s] (when-not (or (contains? used i) (= bg-slot i) (:name s) + (= empty-slot (select-keys s [:hex :name]))) + i))) + (:slots p))) + +(defn empty-slots + "Palette `p` with slots `is` emptied. They stay where they are, so no + drawing's slot number changes and the palette keeps its size." + [p is] + (reduce #(assoc-in %1 [:slots %2] empty-slot) p is)) + +(defn hexes-of [p] (mapv :hex (:slots p))) + +(defn from-hexes + "A palette asset from a strip of colours, its slots named as `entries` are so + a legacy tone keyword still finds its slot." + [id label hexes] + {:id id :name label + :slots (into (mapv (fn [e hex] {:name (:name e) :hex hex}) entries hexes) + (map (fn [hex] {:hex hex})) + (drop (count entries) hexes))}) (defn valid-palette? [{:keys [id name slots]}] (and id (string? name) (seq name) (vector? slots) (pos? (count slots)) diff --git a/frontend/src/arthur/events/export.cljs b/frontend/src/arthur/events/export.cljs index d0c5b5b..dcbfc67 100644 --- a/frontend/src/arthur/events/export.cljs +++ b/frontend/src/arthur/events/export.cljs @@ -159,7 +159,7 @@ ;; through. Read here rather than in the fx so that the effect ;; takes data and nothing else. :palette (pal/compile (:clip entry)) - :ramp (:ramp (pal/compile (:clip entry))) + :ramp (let [p (pal/compile (:clip entry))] (pal/effective-ramp p (:default p))) :zoom zoom :audio-url (:audio entry) :name (stem (:label entry) diff --git a/frontend/src/arthur/events/playback.cljs b/frontend/src/arthur/events/playback.cljs index 4cb197f..994b8e8 100644 --- a/frontend/src/arthur/events/playback.cljs +++ b/frontend/src/arthur/events/playback.cljs @@ -252,3 +252,8 @@ :else (let [i (.indexOf tabs sid)] {:db (assoc-in db [:ui :tabs] left) :dispatch [::open-symbol (get left (min i (dec (count left))))]}))))) + +(rf/reg-event-db + ::frame-palette + ;; Written by the player as it paints: see `subs.render/frame-palette`. + (fn [db [_ active]] (assoc-in db [:ui :frame-palette (get-in db [:ui :open])] active))) diff --git a/frontend/src/arthur/events/project.cljs b/frontend/src/arthur/events/project.cljs index 2e2f4a7..b9121ba 100644 --- a/frontend/src/arthur/events/project.cljs +++ b/frontend/src/arthur/events/project.cljs @@ -162,6 +162,12 @@ :host (get-in db [:ui :open]) :frame frame :point point :target target)})) +(defn choose-palette + "Show palette `id` in the open tab's palette grid, rather than the one the + tab draws in. Each tab keeps its own." + [db id] + (assoc-in db [:ui :palette (get-in db [:ui :open])] id)) + (rf/reg-event-fx ::import-palette (fn [{:keys [db]} [_ {:keys [project cid palette name]}]] @@ -187,7 +193,7 @@ (let [id (random-uuid)] (-> (edit/edit db #(assoc-in % [:palettes id] (assoc palette :id id :name (str (:name palette) " copy")))) - (assoc-in [:ui :palette] id) + (choose-palette id) (assoc-in [:project :status] (str "imported " (:name palette))))))) (rf/reg-event-fx @@ -341,7 +347,8 @@ (array-seq (.-symbols listed))) (mapv (fn [^js r] {:project (.-project r) :project-name (.-project_name r) - :cid (.-cid r) :palette (.-palette r) :name (.-name r)}) + :cid (.-cid r) :palette (.-palette r) :name (.-name r) + :hexes (vec (or (.-hexes r) #js []))}) (array-seq (.-palettes listed)))]))) (.catch (fn [error] (rf/dispatch [::failed (or (ex-message error) (str error))])))))) @@ -727,14 +734,41 @@ p {:id id :name "Untitled palette" :slots (mapv #(select-keys % [:name :hex]) (:slots pal/default-palette))}] (-> (edit/edit db #(assoc-in % [:palettes id] p)) - (assoc-in [:ui :palette] id))))) + (choose-palette id))))) (rf/reg-event-db ::add-palette ;; One of `palette/presets` into a project that does not have it yet. (fn [db [_ p]] (-> (edit/edit db #(assoc-in % [:palettes (:id p)] p)) - (assoc-in [:ui :palette] (:id p))))) + (choose-palette (:id p))))) + +(rf/reg-event-db + ::use-palette + ;; Symbol `sid` draws in palette `p`, adding it to the project first when it + ;; is from the shelf or another project: one edit, so one undo. The grid goes + ;; back to following the tab, which now draws in it. + (fn [db [_ sid p]] + (-> (edit/edit db #(-> % + (update-in [:palettes (:id p)] (fn [had] (or had p))) + (assoc-in [:symbols sid :palette] (:id p)))) + (update-in [:ui :palette] dissoc (get-in db [:ui :open]))))) + +(rf/reg-event-db + ::empty-unused-slots + ;; Every slot of palette `id` no shape in the project names goes back to + ;; empty, in place: slot numbers are shared by every palette and every drawing, + ;; so nothing moves. One edit, so one undo. + (fn [db [_ id]] + (let [clip (:clip (store/entry (:clip/current db))) + p (get (pal/palettes clip) id) + gone (pal/emptyable p (pal/slots-used (vals (:symbols clip))))] + (if (empty? gone) + (assoc-in db [:project :status] "no unused colours to empty") + (-> (edit/edit db #(assoc-in % [:palettes id] (pal/empty-slots p gone))) + (assoc-in [:project :status] + (str "emptied " (count gone) " unused colour" (when (< 1 (count gone)) "s") + " in " (:name p)))))))) (rf/reg-event-db ::duplicate-palette @@ -752,7 +786,7 @@ (-> (edit/edit db #(assoc-in % [:palettes new-id] (assoc p :id new-id :name (str (:name p) " copy")))) - (assoc-in [:ui :palette] new-id))))))) + (choose-palette new-id))))))) (rf/reg-event-db ::palette-name @@ -881,6 +915,16 @@ (fn [n] (if reads (assoc n :reads reads) (dissoc n :reads))))))) +;; How far node `id` reads ahead of its parent — a mouth's lead — in its own +;; frames. Zero is no offset at all rather than an offset of zero. +(rf/reg-event-db + ::set-lead + (fn [db [_ sid id frames]] + (edit/edit db #(update-in % [:symbols sid :nodes id] + (fn [n] (if (zero? frames) + (update n :time dissoc :offset) + (assoc-in n [:time :offset] frames))))))) + (rf/reg-event-db ::set-segment-interp (fn [db [_ sid id path left interp]] diff --git a/frontend/src/arthur/export.cljs b/frontend/src/arthur/export.cljs index b07452f..22b5ca0 100644 --- a/frontend/src/arthur/export.cljs +++ b/frontend/src/arthur/export.cljs @@ -213,7 +213,7 @@ (let [ops (resolve-frame i) active (clip/active-palette resolve-frame)] (-> ras - (raster/clear! (pal/background-index palette active)) + (raster/clear! pal/bg-slot) (raster/draw-ops! ops)) (-> (js/Promise.resolve (frame! exporter i diff --git a/frontend/src/arthur/flow/freeze.cljs b/frontend/src/arthur/flow/freeze.cljs index b578e9e..596896d 100644 --- a/frontend/src/arthur/flow/freeze.cljs +++ b/frontend/src/arthur/flow/freeze.cljs @@ -468,8 +468,16 @@ [:xform :pos] (ch/framed [(- (/ w 2) (* k (:x c))) (- (* 0.25 h) (* k (:y c)))])})))) +;; MOUTH LEAD, in seconds. Roto drawn a frame or two ahead of the sound reads as +;; in sync, and roto drawn exactly on it reads late: an animator's standard +;; practice, and a 12fps hold already shows each pose up to a frame after it +;; happened. 1.5 frames at 12fps. It is stored as the mouth's `:time :offset` in +;; the face's own (camera) frames, so the head and the footage under it stay +;; where they are and only the mouth anticipates. See docs/animation-model.md. +(def mouth-lead 0.125) + (defn- mouth-part [subject absent? obs - {:keys [analysis verts anchor-avg contour-avg aperture-cut] :as params} + {:keys [analysis verts anchor-avg contour-avg aperture-cut fps] :as params} {:keys [outer inner] :as inputs}] (let [own (partial feature/owned subject) mouth (own :mouth) @@ -484,6 +492,7 @@ :verts verts}})] {:nodes {:mouth {:id :mouth :name "mouth" :kind :poly :parent :head :z "a1" + :time {:offset (js/Math.round (* mouth-lead (or fps 0)))} :channels {[:geom :pts] (dense rings 0 (prov :roto/lips-outer)) [:style :color] (ch/framed 2)}} :mouth-in diff --git a/frontend/src/arthur/subs/render.cljs b/frontend/src/arthur/subs/render.cljs index 163e2b5..be13ff6 100644 --- a/frontend/src/arthur/subs/render.cljs +++ b/frontend/src/arthur/subs/render.cljs @@ -130,28 +130,21 @@ (fn [clip _] (when clip (pal/compile clip)))) (rf/reg-sub - ::ramp - :<- [::palette] - (fn [compiled _] (:ramp compiled))) + ::frame-palette + ;; The palette the open tab's stage is in at the frame last painted: an id, + ;; or `{:from :to :t}` mid-blend. Each tab keeps its own. + (fn [db _] (get-in db [:ui :frame-palette (get-in db [:ui :open])]))) (rf/reg-sub - ::palettes-shown - :<- [::clip] - :<- [::open] - :<- [::store] - :<- [::open-frame] - :<- [::palette] - ;; The palettes the stage is drawing in at the playhead: the open symbol's own, - ;; BOTH ends while its palette lane blends from one to the next, and any an - ;; instance in it is set to. The palette strip asks it whether the palette it - ;; is editing is one of these. - (fn [[document sid store frame compiled] _] - (when-let [sym (and document (clip/symbol document sid))] - (let [at #(clip/palette-at document store (:default compiled) % (or frame 0) nil) - ends #(if (map? %) [(:from %) (:to %)] [%])] - (into (set (ends (at sym))) - (comp (filter :palette) (mapcat (comp ends at))) - (vals (:nodes sym))))))) + ::palette-solo? + ;; Show only what is drawn in the chosen colour, and let only it be clicked. + (fn [db _] (get-in db [:ui :palette-solo?]))) + +(rf/reg-sub + ::palette-preview + ;; A palette under the pointer in the chooser: `{:bank id :hexes […]}`, the + ;; bank the stage would draw it into. Viewing only; nothing is edited. + (fn [db _] (get-in db [:ui :palette-preview]))) (rf/reg-sub ::store diff --git a/frontend/src/arthur/ui/palette.cljs b/frontend/src/arthur/ui/palette.cljs index b9e32f2..c96bbf8 100644 --- a/frontend/src/arthur/ui/palette.cljs +++ b/frontend/src/arthur/ui/palette.cljs @@ -16,29 +16,62 @@ set before you draw, so it is a section of the inspector. See `ui/params`." (:require [arthur.domain.channel :as channel] [arthur.domain.clip :as clip] + [arthur.domain.raster :as raster] + [arthur.footage.store :as store] [arthur.domain.node :as node] [arthur.domain.palette :as pal] [arthur.domain.symbol :as symbol] + [arthur.subs.playback :as playback] [arthur.events.project :as project] [arthur.events.ui :as ui] [arthur.subs.render :as render] [arthur.subs.ui :as sub] + [arthur.ui.canvas :as canvas] [arthur.ui.menu :as menu] [clojure.string :as str] [re-frame.core :as rf] [reagent.core :as r])) -(rf/reg-sub ::chosen (fn [db _] (get-in db [:ui :palette]))) +;; WHICH PALETTE THE GRID SHOWS +;; +;; The one the open tab's stage is in at the playhead — there is only ever one +;; — read from where the player decided it, so the grid can never disagree with +;; the picture. Another can be picked to look at or retone, and each tab keeps +;; its own pick until the active one is picked again. -(rf/reg-event-db ::select (fn [db [_ id]] (assoc-in db [:ui :palette] id))) +(rf/reg-sub ::chosen (fn [db _] (get-in db [:ui :palette (get-in db [:ui :open])]))) + +(rf/reg-sub + ::followed + :<- [::render/frame-palette] + :<- [::render/palette] + ;; Mid-tween, the palette it starts from, held still for the whole tween: + ;; the only things to do with a tween are change its ends, so the grid shows + ;; the start's own colours rather than the mix. + (fn [[active compiled] _] + (let [id (if (map? active) (:from active) active)] + (if (contains? (:palettes compiled) id) id (:default compiled))))) + +(rf/reg-event-db ::solo (fn [db _] (update-in db [:ui :palette-solo?] not))) + +(rf/reg-event-db + ::select + (fn [db [_ id followed]] + (let [open (get-in db [:ui :open])] + (if (= id followed) + (update-in db [:ui :palette] dissoc open) + (project/choose-palette db id))))) + +(rf/reg-event-db ::preview (fn [db [_ p]] (assoc-in db [:ui :palette-preview] p))) (defn- shown - "The palette asset the grid shows: the one chosen, or the project's default." + "The palette asset the grid shows, and the one the tab draws in." [] - (let [clip @(rf/subscribe [::render/clip]) - chosen @(rf/subscribe [::chosen]) - pid (if (contains? (:palettes clip) chosen) chosen (pal/default-palette-id clip))] - [clip pid (get (pal/palettes clip) pid)])) + (let [clip @(rf/subscribe [::render/clip]) + chosen @(rf/subscribe [::chosen]) + followed @(rf/subscribe [::followed]) + pid (if (contains? (:palettes clip) chosen) chosen followed)] + [clip pid (get (pal/palettes clip) pid) followed])) (defn- pick! "Make `tone` the colour new shapes get, and recolour what is selected." @@ -123,14 +156,14 @@ :title (if (= i from) (str i " — as it is") (str "slot " i)) :on-click #(do (map-slot! rm from i) (reset! open nil))}]))])])))) -(defn- swatch [pid i {:keys [name hex]} tone placements rm hex-of] +(defn- swatch [pid i {:keys [name hex]} tone placements rm hex-of used?] (let [picker-id (str "palette-picker-" pid "-" i) to (get (:map rm) i)] [:div.slot {:key i} - [:button {:class (str "cell" (when (= i tone) " on")) + [:button {:class (str "cell" (when (= i tone) " on") (when-not used? " unused")) :style {:background hex} :title (str "slot " i (when name (str " · " (clojure.core/name name))) - " · " hex + " · " hex (when-not used? " · nothing in the project draws with it") (when to (str " · lit as " to " under the selected remap")) " — double-click to edit" (when rm ", drag onto another to remap it under the selected remap")) @@ -153,11 +186,18 @@ (defn grid "The colour chip and the slots, for the tool strip." [] - (let [[_ pid palette] (shown) + (let [[clip pid palette followed] (shown) tone @(rf/subscribe [::sub/tone]) + solo? @(rf/subscribe [::render/palette-solo?]) placements @(rf/subscribe [::sub/selected-placements]) + used (conj (pal/slots-used (vals (:symbols clip))) pal/bg-slot) hex (when (number? tone) (:hex (get (:slots palette) tone)))] - [:div.palette + [:div.palette-grid + (when (not= pid followed) + [:button.back {:title (str "back to " (:name (get (pal/palettes clip) followed)) + ", the palette the stage is in") + :on-click #(rf/dispatch [::select followed followed])} + "↩ active"]) [:div {:class (str "chip" (cond (= :clear tone) " clear" (symbol/remap? tone) " map")) :style (when hex {:background hex}) :title (cond (= :clear tone) "clear: what is drawn knocks out what is under it in its symbol" @@ -166,7 +206,8 @@ [:span (cond (= :clear tone) "×" (symbol/remap? tone) "⇄" :else tone)]] [:div.cells (let [rm (remap) hex-of #(:hex (get (:slots palette) %))] - (doall (map-indexed #(swatch pid %1 %2 tone placements rm hex-of) (:slots palette)))) + (doall (map-indexed #(swatch pid %1 %2 tone placements rm hex-of (contains? used %1)) + (:slots palette)))) [:div.slot [:button {:class (str "cell clear" (when (= :clear tone) " on")) :title "clear — draws a knockout: a hole in its symbol" @@ -175,7 +216,22 @@ [:button {:class (str "cell map" (when (symbol/remap? tone) " on")) :title "remap — draws light: what is under it is drawn in other slots of the palette. Set which in the inspector." :on-click #(pick! [:remap {}] placements)} - "⇄"]]]])) + "⇄"]]] + [:div.grid-tools + [:button {:class (when solo? "on") + :disabled (not (number? tone)) + :title (if solo? + "showing only what is drawn in this colour — click one to select it; click again to show everything" + "show only what is drawn in the chosen colour, to find and recolour it") + :aria-pressed (boolean solo?) + :on-click #(rf/dispatch [::solo])} + "◎"] + [:button {:title (str "empty the colours of " (:name palette) + " no shape in the project draws with — they stay as free slots." + " The background and the named face tones are kept.") + :aria-label "empty unused colours" + :on-click #(rf/dispatch [::project/empty-unused-slots pid])} + "⌫"]]])) (defn strip "Every slot of a palette, side by side: what it looks like at a glance." @@ -201,71 +257,168 @@ (.blur (.-target e))) nil))}]) -(defn- chooser - "Every palette in the project as a row — its strip and its name — so what you - would switch to is visible before you switch. The open one carries the edit - button that renames it; the ones the stage is drawing in at the playhead carry - a dot." - [clip pid] - (r/with-let [renaming? (r/atom false)] - (let [on-stage @(rf/subscribe [::render/palettes-shown])] - [:div.palette-list {:role "listbox" :aria-label "palettes"} - (doall - (for [[id p] (sort-by (comp str :name val) (pal/palettes clip)) - :let [open? (= id pid)]] - ^{:key (str id)} - [:div.palette-row {:class (when open? "on")} - (if (and open? @renaming?) - [:div.choose [strip p] [rename id p #(reset! renaming? false)]] - [:button.choose {:role "option" :aria-selected open? - :title (if open? (str "editing " (:name p)) (str "edit " (:name p))) - :on-click (fn [] - (when-not open? - (reset! renaming? false) - (rf/dispatch [::ui/set-tone 0]) - (rf/dispatch [::select id])))} - [strip p] - [:span.name (:name p)] - (when (contains? on-stage id) - [:span.on-stage {:title "on the stage at the playhead"}])]) - (when open? - [:button.rename {:title (str "rename " (:name p)) :aria-label "rename palette" - :on-click #(swap! renaming? not)} - "✎"])]))]))) +(defn- authored? + "Not exactly one of the shelf's: a palette someone made or retoned." + [hexes] + (not-any? #(= hexes (pal/hexes-of %)) pal/presets)) -(defn- elsewhere - "An info badge on the palette button when the palette being edited is not one - the stage draws in at the playhead — not an error: editing another palette is - how one is made ready for a palette lane. Hovering says where to change it. - The card is placed in the viewport, as `ui/menu` places its panels, because - the tool strip scrolls and clips its overflow." - [pid palette] - (r/with-let [at (r/atom nil)] - (let [on-stage @(rf/subscribe [::render/palettes-shown]) - clip @(rf/subscribe [::render/clip]) - sid @(rf/subscribe [::render/open])] - (when (and (seq on-stage) (not (contains? on-stage pid))) - [:span.palette-info - {:aria-label "palette not on the stage here" - :on-mouse-enter (fn [^js e] - (let [r (.getBoundingClientRect (.-currentTarget e))] - (reset! at [(+ (.-right r) 8) (- (.-top r) 6)]))) - :on-mouse-leave #(reset! at nil)} - "i" - (when-let [[x y] @at] - [:span.info-card {:role "tooltip" :style {:left (str x "px") :top (str y "px")}} - [:strong (str (:name palette) " isn't on the stage here")] - (str (or (clip/symbol-name clip sid) "This symbol") - " draws in " (str/join " and " (map #(:name (get (pal/palettes clip) %)) on-stage)) - " at this frame. To draw in " (:name palette) - ", set the authoring palette in the symbol inspector, or blend to it with a palette lane.")])])))) +(defonce ^:private thumbs (atom {:key nil :raster nil :urls {}})) + +(defn- frame-raster + "The open symbol's frame at the playhead, as indices: drawn once, then shown + through each palette's colours, so a list of thumbnails costs one render and a + colour lookup per row." + [clip store compiled open frame] + (let [k [clip open frame]] + (when-not (= k (:key @thumbs)) + (reset! thumbs + {:key k :urls {} + :raster (try + (let [resolve (clip/resolver clip open store compiled {}) + [w h] (clip/stage clip open) + ops (resolve (or frame 0))] + (-> (raster/make w h) + (raster/clear! pal/bg-slot) + (raster/draw-ops! ops))) + (catch :default _ nil))})) + (:raster @thumbs))) + +(defn- thumb + "The playhead's frame in `hexes`." + [hexes] + (let [k hexes] + (or (get-in @thumbs [:urls k]) + (when-let [r (:raster @thumbs)] + (let [url (canvas/->png r (pal/ramp-of hexes))] + (swap! thumbs assoc-in [:urls k] url) + url))))) + +(defn- hit? [needle & texts] + (or (str/blank? needle) + (some #(str/includes? (str/lower-case (str %)) needle) texts))) + +(def ^:private via-words {:symbol "set on symbol" :lane "palette lane" :instance "instance"}) + +(defn- candidate-row + "One palette to switch to: a thumbnail of the playhead's frame in it, its strip, + its name and where it is from. Hovering shows it on the stage; clicking opens + it in the grid; `use` makes the open symbol draw in it." + [{:keys [p note on? thumb-url sid followed]}] + (let [hexes (pal/hexes-of p)] + [:div.palette-row {:class (when on? "on") + :on-mouse-enter #(rf/dispatch [::preview {:hexes hexes}]) + :on-mouse-leave #(rf/dispatch [::preview nil])} + [:button.choose {:role "option" :aria-selected (boolean on?) + :title (str "show " (:name p) " in the palette grid") + :on-click (fn [] + (rf/dispatch [::preview nil]) + (if (contains? (pal/palettes @(rf/subscribe [::render/clip])) (:id p)) + (rf/dispatch [::select (:id p) followed]) + (rf/dispatch [::project/add-palette p])))} + (when thumb-url [:img.thumb {:src thumb-url :alt ""}]) + [:span.text + [strip p] + [:span.name (:name p)] + (when note [:span.note note])]] + [:button.use {:title (str "draw " (clip/symbol-name @(rf/subscribe [::render/clip]) sid) + " in " (:name p)) + :on-click (fn [] + (rf/dispatch [::preview nil]) + (rf/dispatch [::project/use-palette sid p]))} + "use"]])) + +(defn- shelf + "The classics, small: a strip each and a name under it, folded away until + wanted. Hovering previews; a click brings one into the project." + [ps followed searching? sid] + [:details.palette-shelf {:open searching?} + [:summary (str "classics · " (count ps))] + [:div.shelf + (doall + (for [p ps] + ^{:key (str (:id p))} + [:button.tile {:title (str (:name p) " — click to open it, double-click to use it") + :on-mouse-enter #(rf/dispatch [::preview {:hexes (pal/hexes-of p)}]) + :on-mouse-leave #(rf/dispatch [::preview nil]) + :on-click (fn [] + (rf/dispatch [::preview nil]) + (if (contains? (pal/palettes @(rf/subscribe [::render/clip])) (:id p)) + (rf/dispatch [::select (:id p) followed]) + (rf/dispatch [::project/add-palette p]))) + :on-double-click #(rf/dispatch [::project/use-palette sid p])} + [strip p] [:span.name (:name p)]]))]]) + +(defn- chooser + "Every palette worth switching to, most relevant first: those the open + symbol's tree draws in, saying where; the rest of this project's; those made + in other projects, with the project's name; then the classics, folded. One + search reaches palette names and project names." + [clip pid followed] + (r/with-let [renaming? (r/atom false) query (r/atom "")] + (let [sid @(rf/subscribe [::render/open]) + compiled @(rf/subscribe [::render/palette]) + frame @(rf/subscribe [::render/open-frame]) + clip-id @(rf/subscribe [::render/clip-id]) + listed (:palettes @(rf/subscribe [::project/assets])) + {project-id :id} @(rf/subscribe [::playback/project]) + needle (str/lower-case (str/trim @query)) + searching? (not (str/blank? needle)) + _ (frame-raster clip (:store (store/entry clip-id)) compiled sid frame) + own (pal/palettes clip) + uses (group-by :palette + (cons {:palette (pal/default-palette-id clip) :project? true} + (clip/palette-uses clip sid))) + note-of (fn [id] + (str/join ", " (for [{:keys [sid via project?]} (get uses id)] + (if project? "project" + (str (clip/symbol-name clip sid) " · " (via-words via)))))) + row (fn [p note] + {:p p :note note :on? (= (:id p) pid) :sid sid :followed followed + :thumb-url (thumb (pal/hexes-of p))}) + here (for [[id p] own :when (contains? uses id)] (row p (note-of id))) + project (for [[id p] own + :when (and (not (contains? uses id)) (authored? (pal/hexes-of p)))] + (row p nil)) + have (set (map pal/hexes-of (vals own))) + elsewhere (->> listed + (remove #(= project-id (:project %))) + (filter #(and (seq (:hexes %)) (authored? (:hexes %)) + (not (contains? have (:hexes %))))) + (group-by (juxt :name :hexes)) + (map (fn [[[label hexes] rows]] + (let [projects (str/join ", " (distinct (map :project-name rows)))] + (assoc (row (pal/from-hexes (random-uuid) label hexes) projects) + :key [label hexes] :search projects)))) + (sort-by (comp str/lower-case :name :p))) + keep (fn [rows] (filter #(hit? needle (:name (:p %)) (:note %)) rows)) + section (fn [title rows] + (when (seq rows) + [:<> + [:div.palette-head title] + (doall (for [r rows] ^{:key (str (or (:key r) (:id (:p r))))} [candidate-row r]))]))] + [:div.palette-chooser + [:input.palette-search {:type "search" :placeholder "search palettes and projects" + :aria-label "search palettes" + :value @query :on-change #(reset! query (.. % -target -value))}] + [:div.palette-list {:role "listbox" :aria-label "palettes"} + [section (str "in " (clip/symbol-name clip sid)) (keep here)] + [section "this project" (keep project)] + [section "your palettes" (keep elsewhere)]] + (when-let [open-p (and (not searching?) (get own pid))] + [:div.palette-editing + (if @renaming? + [rename pid open-p #(reset! renaming? false)] + [:<> [:span.dim "editing"] [:span.name (:name open-p)] + [:button.rename {:title (str "rename " (:name open-p)) :aria-label "rename palette" + :on-click #(swap! renaming? not)} "✎"]])]) + [shelf (filter #(hit? needle (:name %)) pal/presets) followed searching? sid]]))) (defn assets "The palettes behind a button at the foot of the strip: switch, rename, add. The name is NOT printed in the strip: 44px holds no palette's name, and a name broken over three lines is worse than one shown when asked for." [] - (let [[clip pid palette] (shown)] + (let [[clip pid palette followed] (shown)] [:div.palette-assets-wrap [menu/popover {:class "palette-assets" :title (str "palette: " (:name palette)) :label [:svg {:view-box "0 0 18 18" :width 18 :height 18} @@ -275,18 +428,8 @@ [:circle {:cx 12.5 :cy 6.5 :r 1.3}]]} (fn [_] [:div.palette-popout - [chooser clip pid] + [chooser clip pid followed] [:div.row [:button {:title "a new 16-slot palette" :on-click #(rf/dispatch [::project/new-palette])} "new"] [:button {:title (str "a copy of " (:name palette) " you can retone") - :on-click #(rf/dispatch [::project/duplicate-palette pid])} "duplicate"]] - (when-let [missing (seq (remove #(contains? (pal/palettes clip) (:id %)) pal/presets))] - [:div.palette-list {:aria-label "presets"} - (doall - (for [p missing] - ^{:key (str (:id p))} - [:div.palette-row - [:button.choose {:title (str "add " (:name p) " to this project") - :on-click #(rf/dispatch [::project/add-palette p])} - [strip p] [:span.name (str "+ " (:name p))]]]))])])] - [elsewhere pid palette]])) + :on-click #(rf/dispatch [::project/duplicate-palette pid])} "duplicate"]]])]])) diff --git a/frontend/src/arthur/ui/params.cljs b/frontend/src/arthur/ui/params.cljs index b8ec41a..569abde 100644 --- a/frontend/src/arthur/ui/params.cljs +++ b/frontend/src/arthur/ui/params.cljs @@ -84,13 +84,17 @@ [label & controls] (into [:div.prop [:span.prop-name label]] controls)) -(defn- palette-select [value on-change & [disabled?]] +(defn- palette-select + "A choice of the project's palettes. `inherit` names the empty choice — what + an unset palette falls back to — and false leaves it out." + [value on-change & [disabled? inherit]] (let [clip @(rf/subscribe [::render/clip])] [:select {:value (str (or value "")) :disabled disabled? :on-change (fn [e] (let [v (.. e -target -value)] (on-change (first (filter #(= v (str %)) (keys (pal/palettes clip)))))))} - [:option {:value ""} "inherit"] + (when-not (false? inherit) + [:option {:value ""} (or inherit "inherit")]) (for [[id p] (sort-by (comp str :name val) (pal/palettes clip))] ^{:key (str id)} [:option {:value (str id)} (:name p)])])) @@ -271,8 +275,8 @@ clip @(rf/subscribe [::render/clip]) frame (:frame @(rf/subscribe [::sub/selected-placement])) own @(rf/subscribe [::sub/own-time node-path]) - palette (get (pal/palettes clip) - (or (get-in clip [:symbols sid :palette]) (pal/default-palette-id clip)))] + ;; What the shape is drawn in, which is what the grid follows. + palette (get (pal/palettes clip) @(rf/subscribe [:arthur.ui.palette/followed]))] [:div.chans (doall (for [[path ch] (sort-by (fn [[path]] [(get order path 99) (str path)]) (node/channels n))] @@ -340,7 +344,12 @@ :on-click #(do (put! :width nil) (put! :height nil))} "↺"])) (prop "palette" - [palette-select (:palette sym) #(rf/dispatch [::project/symbol-palette sid %]) busy?])])) + [palette-select (:palette sym) #(rf/dispatch [::project/symbol-palette sid %]) busy? + ;; Unset, a symbol draws in what it is placed in, and on its own in + ;; the project's palette. + (if (pos? (clip-domain/uses clip sid)) + "from where it's placed" + (str "project's · " (:name (get (pal/palettes clip) (pal/default-palette-id clip)))))])])) (defn- project-fields [] (let [clip @(rf/subscribe [::render/clip]) @@ -355,7 +364,10 @@ [:span.dim "×"] [count-input (:height clip) #(rf/dispatch [::project/project-setting :height %]) {:disabled busy? :label "height"}]) - (prop "rate" [settings/rate busy?])])) + (prop "rate" [settings/rate busy?]) + (prop "palette" + [palette-select (pal/default-palette-id clip) + #(when % (rf/dispatch [::project/default-palette %])) busy? false])])) ;; --------------------------------------------------------------------------- ;; a node @@ -691,6 +703,26 @@ (when (seq faces) (filterv #(contains? faces (subject-of-owner clip %)) (owners clip))))) +(defn- lead-row + "How far feature `fid`'s drawing reads ahead of the sound, as its first node's + `:time :offset`. Stored in the face's own camera frames and typed in the + document's, because the document's grid is what a lead is felt against." + [clip fid] + (let [{face :symbol [id] :nodes} (get-in clip [:features fid]) + face-fps (get-in clip [:analyses (get-in clip [:subjects face :analysis]) :fps]) + fps (:fps clip) + offset (get-in clip [:symbols face :nodes id :time :offset] 0)] + (when (and face-fps fps) + [:div.prop {:style {:margin-top "6px"} + :title "roto drawn a frame or two ahead of the sound reads as in sync"} + [:span.prop-name "lead"] + [number-input {:step 0.5 :aria-label "lead in frames" + :value (/ (js/Math.round (* 10 offset (/ fps face-fps))) 10) + :parse js/parseFloat + :on-number #(rf/dispatch [::project/set-lead face id + (js/Math.round (* % (/ face-fps fps)))])}] + [:span.dim (str "f · " (js/Math.round (/ (* 1000 offset) face-fps)) "ms")]]))) + (defn- tracking-section [all] (let [clip @(rf/subscribe [::render/clip]) selection @(rf/subscribe [::sub/selection]) @@ -723,6 +755,7 @@ (for [[i [kind object-id]] (map-indexed vector all)] ^{:key i} [:option {:value i} (str (name kind) " · " (subs (str object-id) 1))]))] + (when (= :mouth area) [lead-row clip id]) (when area [:div {:style {:margin-top "6px"}} (doall @@ -896,9 +929,9 @@ [layer-section "tracing" (first node) (second node) path]) (when (get-in clip [:symbols face :nodes :plate]) [face-section face path]) - (when a-face? ^{:key (str "repair/" face)} [repair-section face path]) - (when a-face? ^{:key (str "perf/" face)} [performance-section face]) (when (and (seq tracking-owners) (not palette-placement?) (not palette-symbol?)) [tracking-section tracking-owners]) + (when a-face? ^{:key (str "repair/" face)} [repair-section face path]) + (when a-face? ^{:key (str "perf/" face)} [performance-section face]) (when (= [:symbol (clip-domain/opens-on clip)] inspected) [project-fields])]])) diff --git a/frontend/src/arthur/ui/player.cljs b/frontend/src/arthur/ui/player.cljs index 627f24c..b18fb22 100644 --- a/frontend/src/arthur/ui/player.cljs +++ b/frontend/src/arthur/ui/player.cljs @@ -118,7 +118,8 @@ (fn [_ _] {:resolver (rf/subscribe [::render/shown]) :palette (rf/subscribe [::render/palette]) - :ramp (rf/subscribe [::render/ramp]) + :preview (rf/subscribe [::render/palette-preview]) + :solo? (rf/subscribe [::render/palette-solo?]) :fps (rf/subscribe [::sub/fps]) :frames (rf/subscribe [::render/frames]) :width (rf/subscribe [::sub/width]) @@ -160,8 +161,8 @@ ;; in the editor's own state, so it changes what the canvases should ;; show without touching the frame number OR the resolver. (when-not (and (identical? (:resolver before) (:resolver now)) - (= (select-keys before [:tracing :pen :mat :onion :selection :playing?]) - (select-keys now [:tracing :pen :mat :onion :selection :playing?]))) + (= (select-keys before [:tracing :pen :mat :onion :selection :playing? :preview :solo?]) + (select-keys now [:tracing :pen :mat :onion :selection :playing? :preview :solo?]))) (repaint!)))))) ;; The brush or eraser stroke being painted: its mask, mutated in place as the @@ -309,11 +310,6 @@ (defn in-rect [rect depth] (pick/in-rect (:ops @state) rect depth)) -(defn- index-of-slot [palette active slot] - (if (and (:palettes palette) (:offsets palette)) - (pal/render-index palette active slot) - slot)) - (defn- traced "Stroke `s` as the rings letting go would make of it, `[outer & holes]` per piece: traced and simplified by the same function the saved shapes are, so @@ -346,17 +342,17 @@ (defn- inked "Op `op` drawn in tone `tone`: a slot's colour, or — for a remap — light on what is under it, through the same table the saved shape gets." - [op tone palette active] + [op tone] (if (symbol/remap? tone) - (assoc op :lut (symbol/lut #(index-of-slot palette active %) tone) :color 0) - (assoc op :color (index-of-slot palette active tone)))) + (assoc op :lut (symbol/lut pal/slot tone) :color 0) + (assoc op :color (pal/slot tone)))) (defn- with-previews "What is being drawn and is not in the document yet, added to `ops` in the stacking context of the symbol it will land in: the pen's draft as far as the pointer, a brush stroke as the polygons it will be, and an eraser's cut as the shapes it will leave." - [ops palette active] + [ops] (let [{:keys [draft hover tone fit target]} (:pen @snapshot) target (or target []) pts (cond-> (vec draft) (and (seq draft) hover) (into hover)) @@ -364,13 +360,13 @@ rings (when (:mask s) (traced s fit))] (cond-> ops (and (<= 6 (count pts)) (or (number? tone) (symbol/remap? tone))) - (clip/atop target (inked (poly pts {}) tone palette active)) + (clip/atop target (inked (poly pts {}) tone)) paths (cut-ops paths rings) (and rings (not paths) (nil? knock)) - (as-> ops (reduce #(clip/atop %1 target (inked (poly (outline/join %2) {}) slot palette active)) + (as-> ops (reduce #(clip/atop %1 target (inked (poly (outline/join %2) {}) slot)) ops rings)) (and rings (not paths) knock) @@ -383,7 +379,9 @@ rasterised before the next frame is asked for." [f] (let [{:keys [canvas]} @state - {:keys [resolver palette ramp width height tracing playing? mat]} @snapshot] + {:keys [resolver palette width height tracing playing? mat preview solo?] :as snap} @snapshot + tone (get-in snap [:pen :tone]) + solo (when (and solo? (number? tone)) tone)] (when (and canvas resolver width height) ;; User Timing, so a profile in the DevTools performance panel has named ;; spans in the Timings track instead of a wall of anonymous frames. Three @@ -400,12 +398,21 @@ traces (when (:on? tracing) (into [] (remove #(contains? (:hidden tracing) (:layer %))) traces)) active (clip/active-palette resolver) - bg (pal/background-index palette active)] - (swap! state assoc :ops (into (vec picture) traces)) + bg pal/bg-slot] + ;; The palette grid shows the frame's palette from here, the one place + ;; it is decided, rather than working it out again. + ;; Keyed by the resolver too, as a new tab brings a new one. + (when (not= [resolver active] (:active @state)) + (swap! state assoc :active [resolver active]) + (rf/dispatch [::pb/frame-palette active])) + ;; Soloed, only what is drawn in the chosen colour can be clicked. + (swap! state assoc :ops (if solo + (filterv #(or (#{:begin :end} (:kind %)) (= solo (:color %))) picture) + (into (vec picture) traces))) ;; What is drawn, cut to what is on screen: a frame with nothing off the ;; stage costs what the stage does, and a drawing a dozen stages wide ;; costs no more than the pane it is seen through. - (let [ops (with-previews picture palette active) + (let [ops (with-previews picture) [ax ay bx by :as all] (reach ops width height) [vx vy wx wy] rect x0 (max ax vx) y0 (max ay vy) x1 (min bx wx) y1 (min by wy)] @@ -415,7 +422,14 @@ (let [off? (or (neg? x0) (neg? y0) (< width x1) (< height y1)) ras (raster-for (- x1 x0) (- y1 y0) [x0 y0] off?)] (-> ras (raster/clear! bg) (raster/draw-ops! ops)) - (canvas/blit! canvas ras (pal/effective-ramp palette active) [width height])) + (canvas/blit! canvas ras + ;; THE frame's colours: the one palette it is in, + ;; or the one being previewed in its place. + (cond-> (if preview + (pal/ramp-of (:hexes preview)) + (pal/effective-ramp palette active)) + solo (pal/solo-ramp solo)) + [width height])) (canvas/hide! canvas))) (tracing/paint! traces (assoc tracing :rect rect :zoom zoom :stage [width height] :playing? playing?) repaint!)) (js/performance.measure "arthur/resolve+draw" "arthur/paint:start" "arthur/blit:start") diff --git a/frontend/src/arthur/ui/pool.cljs b/frontend/src/arthur/ui/pool.cljs index 7080cc6..e574bbc 100644 --- a/frontend/src/arthur/ui/pool.cljs +++ b/frontend/src/arthur/ui/pool.cljs @@ -98,29 +98,29 @@ most phone footage opens on. A symbol's frame 0 is authored: what is on it is there because somebody put it there, and the frame a person names a symbol by is the one it starts on." - [document sid store palette ramp] + [document sid store palette] (try (when (clip/symbol document sid) (let [resolve (clip/resolver document sid store palette {}) [w h] (clip/stage document sid)] (let [ops (resolve 0)] (-> (raster/make w h) - (raster/clear! (pal/background-index palette (clip/active-palette resolve))) + (raster/clear! pal/bg-slot) (raster/draw-ops! ops) - (canvas/->png ramp))))) + (canvas/->png (pal/effective-ramp palette (clip/active-palette resolve))))))) (catch :default _ nil))) (defn- symbol-thumb "`draw-symbol`, once per symbol per version of the document. Rasterising and PNG-encoding the stage is milliseconds, and the pool redraws on every selection click." - [document sid store palette ramp] + [document sid store palette] (when-not (identical? document (:clip @thumbs)) (reset! thumbs {:clip document :urls {}})) (let [urls (:urls @thumbs)] (if (contains? urls sid) (get urls sid) - (let [url (draw-symbol document sid store palette ramp)] + (let [url (draw-symbol document sid store palette)] (swap! thumbs assoc-in [:urls sid] url) url)))) @@ -256,7 +256,7 @@ ;; --------------------------------------------------------------------------- ;; the rows of each kind -(defn- symbol-row [document sid {:keys [clip-id store palette ramp selection open main rename]}] +(defn- symbol-row [document sid {:keys [clip-id store palette selection open main rename]}] (let [sym (clip/symbol document sid) label (clip/symbol-name document sid) nodes (count (:nodes sym))] @@ -271,7 +271,7 @@ " — double-click to open, drag to place")) :thumb (if (= :trace (:type sym)) [tracing-thumb (:media sym)] - [picture (symbol-thumb document sid store palette ramp)]) + [picture (symbol-thumb document sid store palette)]) :sub2 (str (:frames sym) "f · " nodes (if (= 1 nodes) " node" " nodes")) :on? (= selection [:symbol sid]) :open? (= sid open) @@ -441,7 +441,7 @@ Still not `:main` being special. The document says which symbol that is by its structure; rename it, place it inside something else, and the pool follows." - [{:keys [document query searching? media sounds images chosen rename main palette-choice selection] :as ctx}] + [{:keys [document query searching? media sounds images chosen rename main selection] :as ctx}] (let [named? #(hit? query (clip/symbol-name document %)) top (when (and main (named? main)) main) symbol-ids (sort-by str (keys (:symbols document))) @@ -566,9 +566,7 @@ clip-id @(rf/subscribe [::render/clip-id]) store @(rf/subscribe [::render/store]) palette @(rf/subscribe [::render/palette]) - ramp @(rf/subscribe [::render/ramp]) selection @(rf/subscribe [::sub/selection]) - palette-choice @(rf/subscribe [:arthur.ui.palette/chosen]) open @(rf/subscribe [::render/open]) media @(rf/subscribe [::sub/project-footage]) {:keys [symbols palettes]} @(rf/subscribe [::project/assets]) @@ -588,12 +586,11 @@ needle (str/lower-case (str/trim @query)) searching? (boolean (seq needle)) ctx {:document document :clip-id clip-id :store store :palette palette - :ramp ramp :selection selection :open open + :selection selection :open open :media media :sounds own-sounds :images own-images :chosen chosen :available (vec available) :all-sounds (vec sounds) :all-images (vec images) :symbols symbols :palettes palettes :project-id project-id - :palette-choice palette-choice :query needle :searching? searching? ;; `clip/opens-on` and not `:main`: the longest symbol nothing ;; else places is the timeline the work happens in, and it is the diff --git a/frontend/src/arthur/ui/timeline.cljs b/frontend/src/arthur/ui/timeline.cljs index aac831a..8d6a833 100644 --- a/frontend/src/arthur/ui/timeline.cljs +++ b/frontend/src/arthur/ui/timeline.cljs @@ -644,6 +644,9 @@ (defn- label-cell [{:keys [path depth label kind node-kind lane? span select expandable? expanded? of via uses]} selection selections target-path over solo tracing renaming draft choose-row!] (let [node? (= :node kind) + ;; The palette row is the symbol's one palette lane: "palette" says all + ;; there is to say, and it has no name of its own to change. + named-lane? (and lane? (not= :palette kind)) selected? (contains? selections select) editing? (and lane? (= select @renaming)) begin-rename! (fn [] (reset! draft label) (reset! renaming select)) @@ -751,9 +754,9 @@ [:span.uses {:title (str "placed " uses " times · a rename reaches every one")} (str "(" uses ")")]) (cond - lane? [:span.kind "·lane"] + named-lane? [:span.kind "·lane"] node? [:span.kind (if via (str "· in " via) (str "·" (name node-kind)))]) - (when lane? + (when named-lane? [:button.tl-rename {:title "rename lane" :on-click (fn [^js e] (.stopPropagation e) (begin-rename!))} diff --git a/frontend/test/arthur/domain/instance_test.cljs b/frontend/test/arthur/domain/instance_test.cljs index 9f715cb..f4585e9 100644 --- a/frontend/test/arthur/domain/instance_test.cljs +++ b/frontend/test/arthur/domain/instance_test.cljs @@ -423,79 +423,95 @@ (is (= [55 35] (gesture/pivot (gesture/values (get-in out [:symbols :main :nodes :cel]) 0 nil) nil)) "and from then on it is the node's own, whatever the symbol does next")))))) -(deftest palette-context-is-inherited-keyed-and-overridable - (let [palette (fn [id name a b] - {:id id :name name :slots [{:hex a} {:hex b}]}) +(def ^:private one-palette-doc + (let [palette (fn [id color] {:id id :name (name id) :slots [{:hex "#000000"} {:hex color}]}) mark {:id :mark :kind :rect :z "a1" :channels {[:geom :size] (ch/framed 2) - [:style :color] (ch/framed 1)}} - instance (fn [id child z] - {:id id :kind :instance :z z :source {:symbol child}}) - document {:fps 30 :width 20 :height 20 - :palettes {:day (palette :day "Day" "#000000" "#112233") - :flash (palette :flash "Flash" "#ffffff" "#aabbcc")} - :default-palette :day - :symbols - {:main {:id :main :frames 4 - :palette (ch/keyed {0 :day 2 :flash} :hold) - :nodes {:inherited (instance :inherited :drawing "a1") - :fixed (assoc (instance :fixed :fixed "a2") - :palette (ch/framed :day))}} - :drawing {:id :drawing :frames 4 :nodes {:mark mark}} - :fixed {:id :fixed :frames 4 :palette (ch/framed :flash) - :nodes {:mark mark}}}} - context (pal/compile document) - resolve (clip/resolver document :main nil context nil) - colors #(mapv :color (resolve %))] - (is (= [1 1] (colors 0)) "both children start in the day bank") - (is (= [3 1] (colors 2)) - "the inheriting child follows the lightning cut; an instance override wins") - (is (= [17 34 51] (nth (:ramp context) 1))) - (is (= [170 187 204] (nth (:ramp context) 3))))) + [:style :color] (ch/framed 1)}}] + {:fps 30 :width 20 :height 20 + :palettes {:day (palette :day "#112233") :night (palette :night "#aabbcc") + :ink (palette :ink "#101010") :dusk (palette :dusk "#664422")} + :default-palette :day + :symbols + {:main {:id :main :frames 6 + :nodes {:plain {:id :plain :kind :instance :z "a1" :source {:symbol :plain}} + :face {:id :face :kind :instance :z "a2" :source {:symbol :face} + :span [0 3] :time {:at 0}}}} + :plain {:id :plain :frames 6 :nodes {:mark mark}} + :face {:id :face :frames 6 :palette :night :nodes {:mark mark}} + :lane {:id :lane :type :palette-track :display :lane :frames 6 + :nodes {:n {:id :n :kind :instance :z "a1" :source {:symbol :ink-palette} + :span [0 1] :time {:at 1}}}} + :ink-palette {:id :ink-palette :type :palette :palette-ref :ink :frames 1 :nodes {}}}})) -(deftest symbol-authoring-palettes-seed-only-the-view-root - (let [palette (fn [id name color] - {:id id :name name :slots [{:hex color} {:hex color}]}) - mark {:id :mark :kind :rect :z "a1" - :channels {[:geom :size] (ch/framed 2) - [:style :color] (ch/framed 1)}} - document {:fps 30 :width 20 :height 20 - :palettes {:day (palette :day "Day" "#112233") - :night (palette :night "Night" "#aabbcc")} - :default-palette :day - :symbols - {:main {:id :main :frames 4 :palette :day :palette-track :palette-lane - :nodes {:child {:id :child :kind :instance :z "a1" - :source {:symbol :drawing}}}} - :palette-lane {:id :palette-lane :name "palette" - :type :palette-track :display :lane :frames 4 - :nodes {:night {:id :night :kind :instance :z "a1" - :source {:symbol :night-palette} - :span [0 1] :time {:at 1}}}} - :night-palette {:id :night-palette :name "Night" - :type :palette :palette-ref :night - :frames 1 :nodes {}} - :drawing {:id :drawing :frames 4 :palette :night - :nodes {:mark mark}}}} - context (pal/compile document) - main (clip/resolver document :main nil context nil) - drawing (clip/resolver document :drawing nil context nil) - color #(-> (%1 %2) first :color)] - (is (= (pal/render-index context :day 1) (color main 0)) - "a nested symbol's authoring palette does not override the viewed root") - (is (= (pal/render-index context :night 1) (color main 1)) - "a covered palette-track interval overrides the root fallback") - (is (= (pal/render-index context :day 1) (color main 2)) - "a nil track interval is a real gap and restores the authoring palette") - (is (= (pal/render-index context :night 1) (color drawing 0)) - "the same nested symbol uses its authoring palette when viewed directly") - ;; The renderer clears with this exact resolver state before rasterising the - ;; returned ops, so a palette cut changes the stage background as well as - ;; authored shapes. - (main 1) - (is (= :night (clip/active-palette main))) - (is (= (pal/render-index context :night 0) - (pal/background-index context (clip/active-palette main)))))) +(defn- frame-of + "What frame `f` of symbol `sid` draws, and the one palette it is in." + [document sid f] + (let [context (pal/compile document) + r (clip/resolver document sid nil context nil) + ops (vec (r f))] + {:colors (mapv :color (remove #(#{:begin :end} (:kind %)) ops)) + :active (clip/active-palette r) + :ramp (pal/effective-ramp context (clip/active-palette r))})) + +(deftest a-frame-is-in-one-palette-and-the-shallowest-choice-wins + (let [doc one-palette-doc] + (is (= {:colors [1 1] :active :night} + (select-keys (frame-of doc :main 0) [:colors :active])) + "a face set to night turns ALL of main night while it is drawn; shapes keep their slot") + (is (= :day (:active (frame-of doc :main 4))) + "once the face is gone main is back in the project's palette") + (is (= :day (:active (frame-of (assoc-in doc [:symbols :main :palette] :day) :main 0))) + "a palette set on the open symbol beats anything inside it") + (is (= :ink (:active (frame-of (assoc-in doc [:symbols :main :palette-track] :lane) :main 1))) + "and so does the open symbol's palette lane") + (is (= :dusk (:active (frame-of (assoc-in doc [:symbols :main :nodes :face :palette] :dusk) :main 0))) + "an instance set to a palette stands in for the symbol's own") + (is (= :ink (:active (frame-of (assoc-in doc [:symbols :face :palette-track] :lane) :main 1))) + "a child's palette lane turns the whole frame, not just the child") + (is (= :night (:active (frame-of doc :face 0))) + "the face's own tab is in its palette") + (is (= [[0 0 0] [170 187 204]] (:ramp (frame-of doc :main 0))) + "the frame's colours are that one palette's and nothing else's"))) + +(deftest between-two-choices-at-one-depth-the-one-on-top-wins + (let [doc (-> one-palette-doc + (assoc-in [:symbols :plain :palette] :dusk))] + (is (= :night (:active (frame-of doc :main 0))) "face is drawn over plain") + (is (= :dusk (:active (frame-of doc :main 4))) "and without the face, plain's"))) + +(deftest an-inherit-end-of-a-blend-is-what-the-frame-is-in-without-it + (let [choice (assoc (ch/keyed {0 pal/inherit 2 :ink} :linear) :semantic :palette) + doc (-> one-palette-doc + (assoc-in [:symbols :main :palette-track] :lane) + (assoc-in [:symbols :lane :nodes :n] + {:id :n :kind :instance :z "a1" :source {:symbol :ink-palette} + :span [0 3] :time {:at 0} :channels {[:palette] choice}}))] + (is (= {:from :night :to :ink :t 0.5} (:active (frame-of doc :main 1))) + "main's lane blends from what the face makes the frame, to ink"))) + +(deftest the-palettes-a-tree-uses + (let [doc (-> one-palette-doc + (assoc-in [:symbols :main :nodes :plain :palette] :ink))] + (is (= [{:palette :ink :sid :main :via :instance} + {:palette :night :sid :face :via :symbol}] + (clip/palette-uses doc :main))))) + +(deftest unused-slots-are-emptied-in-place + (let [p {:id :a :name "a" + :slots [{:name :bg :hex "#000000"} {:hex "#111111"} {:name :teeth :hex "#222222"} + {:hex "#333333"} {:hex "#444444"} {:hex "#000000"}]} + mark (fn [id c] {:id id :kind :rect :z "a1" :channels {[:style :color] c}}) + nodes {:x (mark :x (ch/keyed {0 3 1 1} :hold)) + :y (mark :y (ch/framed [:remap {4 1}]))} + used (pal/slots-used [{:nodes nodes}])] + (is (= #{1 3 4} used) "every key counts, and both sides of a remap") + (is (= [] (pal/emptyable p used)) + "the background, a named face tone and an already empty slot are left alone") + (is (= [3] (pal/emptyable p #{1 4}))) + (is (= ["#000000" "#111111" "#222222" "#000000" "#444444" "#000000"] + (mapv :hex (:slots (pal/empty-slots p [3])))) + "emptied where it is, so no slot number moves"))) (deftest a-palette-lane-can-blend-between-keyed-palettes (let [palette (fn [id color] @@ -531,8 +547,7 @@ (clip/palette-at document nil :day (clip/symbol document :main) 2 nil)) "the palette strip asks the same question the resolver answers: both ends of a blend") (is (= [128 128 128] - (nth (pal/effective-ramp context (clip/active-palette resolve)) - (pal/render-index context :day 1)))) + (nth (pal/effective-ramp context (clip/active-palette resolve)) 1))) (is (nil? (:refused slid)) (:refused slid)) (is (= [1 6] (node/placed-span (get-in slid [:clip :symbols :palettes :nodes :change])))) @@ -569,8 +584,7 @@ (resolve 2) (is (= {:from day :to night :t 0.5} (clip/active-palette resolve))) (is (= [128 128 128] - (nth (pal/effective-ramp context (clip/active-palette resolve)) - (pal/render-index context day 1)))))) + (nth (pal/effective-ramp context (clip/active-palette resolve)) 1))))) (deftest a-knockout-makes-a-hole-in-its-own-symbol-only (let [sq (fn [x0 y0 x1 y1] [x0 y0 x1 y0 x1 y1 x0 y1]) document @@ -634,7 +648,7 @@ ops (vec ((clip/resolver document :main nil context nil) 0)) ras (raster/draw-ops! (raster/clear! (raster/make 320 200) 0) ops) at (fn [x y] (aget (:buf ras) (+ x (* y 320)))) - slot #(pal/render-index context (pal/default-palette-id document) %)] + slot identity] (is (= (slot 5) (at 7 10)) "the wall under the beam is lit") (is (= (slot 3) (at 12 10)) "the door under it is a slot the map leaves alone") (is (= (slot 2) (at 30 10)) "and the wall outside it is as it was") diff --git a/frontend/test/arthur/domain/leaf_test.cljs b/frontend/test/arthur/domain/leaf_test.cljs index 553c1b3..9844023 100644 --- a/frontend/test/arthur/domain/leaf_test.cljs +++ b/frontend/test/arthur/domain/leaf_test.cljs @@ -73,7 +73,7 @@ (let [ls (leaf/leaves :c1 @take/clip) n (get ls "clip/c1/symbol/face-1/node/mouth")] (is (= {:id :mouth :name "mouth" :kind :poly :parent :head - :z "a1" :pose-group :mouth} n)) + :z "a1" :time {:offset 4} :pose-group :mouth} n)) (is (nil? (:channels n))) (is (:animated? (get ls "clip/c1/symbol/face-1/channel/mouth/geom.pts"))))) diff --git a/frontend/test/arthur/domain/rate_test.cljs b/frontend/test/arthur/domain/rate_test.cljs index a50da27..497dd40 100644 --- a/frontend/test/arthur/domain/rate_test.cljs +++ b/frontend/test/arthur/domain/rate_test.cljs @@ -50,7 +50,8 @@ (is (= [15 60 640 360 :arthur/pico-8] [(:fps doc) (clip/frames doc :main) (:width doc) (:height doc) (:default-palette doc)])) (is (every? pal/valid-palette? (vals (:palettes doc)))) - (is (= (count pal/presets) (count (:palettes doc)))))) + (is (= [:arthur/pico-8] (keys (:palettes doc))) + "a project carries the palette it draws with, not the whole shelf"))) (testing "a drawing made in a nested lane is one project frame long" ;; The bug that started this: a lane made at 30 in a project then set to ;; 12 got drawings a thirtieth of a second long, which the output either diff --git a/frontend/test/arthur/flow/freeze_test.cljs b/frontend/test/arthur/flow/freeze_test.cljs index de37998..dde9ea3 100644 --- a/frontend/test/arthur/flow/freeze_test.cljs +++ b/frontend/test/arthur/flow/freeze_test.cljs @@ -98,7 +98,9 @@ (is (= [:mouth :head :place] (symbol/lineage (:nodes @sym*) :mouth))) (is (= [:mouth-in :mouth :head :place] (symbol/lineage (:nodes @sym*) :mouth-in))) (is (= {:mode :map :expose 2} (:time (node :root)))) - (is (every? #(nil? (:time (node %))) [:place :head :mouth :mouth-in]))) + ;; The mouth leads, 125ms at the take's 30fps; its interior inherits that. + (is (= {:offset 4} (:time (node :mouth)))) + (is (every? #(nil? (:time (node %))) [:place :head :mouth-in]))) (deftest geometry-is-flat-and-dense-and-the-interior-shares-the-outline-s-block (doseq [id [:mouth :mouth-in]] @@ -204,7 +206,9 @@ res (clip/resolver c :main @store pal/index-of nil) k (first (:value (chan :place [:xform :scale]))) pos (:value (chan :place [:xform :pos])) - tfs (:transforms @take/measured)] + tfs (:transforms @take/measured) + lead (get-in c [:symbols :face-1 :nodes :mouth :time :offset] 0)] + (is (pos? lead) "a frozen mouth leads by default") (doseq [f (range 0 take/frames 13)] (let [ops (res f) op (first (filter #(= [:face-1 :mouth] (:node %)) ops)) @@ -216,7 +220,9 @@ ef (node/expose f 2) ;; The frozen, quantised vertex — so the fixed point is not part of ;; what is being asserted here; it has its own test. - flat (pts-at :mouth ef) + ;; The mouth LEADS: its pose is read `lead` frames ahead of the + ;; head it hangs off, held at the last frame. See `freeze/mouth-lead`. + flat (pts-at :mouth (min (dec take/frames) (+ ef lead))) g {:x (nth flat 0) :y (nth flat 1)} ;; Where the anchor fit says that head-local point was in the image: ;; the fit removed the head's motion, so putting it back is the fit's diff --git a/frontend/test/arthur/flow/multi_face_test.cljs b/frontend/test/arthur/flow/multi_face_test.cljs index b17e639..b455917 100644 --- a/frontend/test/arthur/flow/multi_face_test.cljs +++ b/frontend/test/arthur/flow/multi_face_test.cljs @@ -101,7 +101,9 @@ cut (pose/put-cut clip :main :face-2 :mouth 0 20) original (by-node clip store 4) held (by-node cut store 4) - source (by-node clip store 20)] + ;; Uncut, frame f shows pose f + lead, so pose 20 is on frame 20 − lead. + lead (get-in clip [:symbols :face-2 :nodes :mouth :time :offset] 0) + source (by-node clip store (- 20 lead))] (is (empty? (clip/problems cut))) (is (= (get held [:face-2 :mouth]) (get source [:face-2 :mouth]))) (is (not= (get held [:face-2 :mouth]) (get original [:face-2 :mouth]))) diff --git a/frontend/test/browser/take.mjs b/frontend/test/browser/take.mjs index 6b3162c..3a5224f 100644 --- a/frontend/test/browser/take.mjs +++ b/frontend/test/browser/take.mjs @@ -619,7 +619,7 @@ async function main() { const stageLoaded = await statusMatching(/loaded 8625 stage study/, 160); check(stageLoaded !== null, 'the 8625 stage is ready', stageLoaded ?? (await page.eval(STATUS))); const eyeSelected = await page.eval(`(() => { - const select = document.querySelector('.params .section:last-child select'); + const select = [...document.querySelectorAll('.params .section')].find(s => s.querySelector('h2')?.textContent === 'tracking')?.querySelector('select'); // Settings belong to tracked features shared by the stage placements. const option = [...select.options] .find(o => o.textContent.trim().endsWith('feature · face-1/eye-r')); @@ -663,7 +663,7 @@ async function main() { await page.eval(CLICK('pause')); } const subjectSelected = await page.eval(`(() => { - const select = document.querySelector('.params .section:last-child select'); + const select = [...document.querySelectorAll('.params .section')].find(s => s.querySelector('h2')?.textContent === 'tracking')?.querySelector('select'); const option = [...select.options] .find(o => o.textContent.includes('subject · face-1')); if (!option) return false; @@ -712,7 +712,7 @@ async function main() { } } const teethSelected = await page.eval(`(() => { - const select = document.querySelector('.params .section:last-child select'); + const select = [...document.querySelectorAll('.params .section')].find(s => s.querySelector('h2')?.textContent === 'tracking')?.querySelector('select'); const option = [...select.options] .find(o => o.textContent.trim().endsWith('feature · face-1/teeth')); if (!option) return false; diff --git a/static/arthur/app.css b/static/arthur/app.css index 7985c5b..9a09734 100644 --- a/static/arthur/app.css +++ b/static/arthur/app.css @@ -1446,7 +1446,7 @@ button.share-button:hover, button.share-button.on { filter: brightness(1.1); } color: var(--dim); } .key-nav button:disabled { opacity: .3; } -.key-nav .key { width: 16px; } +.key-nav .key { width: 16px; font-size: 15px; line-height: 1; } .key-nav .key.keyed { color: var(--fg); } .key-nav .key.on { color: var(--sel); } .key-nav svg, .chan .gap svg, .prop .seg svg { width: 11px; height: 11px; } @@ -1675,38 +1675,38 @@ button.tl-gap:hover { background: rgba(47, 111, 192, .28); } .tool svg .cut { fill: none; stroke: var(--chrome); stroke-width: 1.2; } .tool.on svg .cut { stroke: var(--sel-bg); } -.palette { display: grid; gap: 7px; justify-items: center; padding-top: 9px; border-top: 1px solid var(--hair); } +.palette-grid { display: grid; gap: 7px; justify-items: center; padding-top: 9px; border-top: 1px solid var(--hair); } /* The colour a new shape gets: Photoshop's foreground chip. */ -.palette .chip { +.palette-grid .chip { width: 36px; height: 36px; display: grid; place-items: end start; border: 1px solid var(--fg); border-radius: 3px; box-shadow: inset 0 0 0 2px var(--pane); } -.palette .chip span { +.palette-grid .chip span { margin: 0 0 2px 3px; padding: 0 3px; border-radius: 2px; background: rgba(255, 255, 255, .85); color: var(--fg); font-size: 9px; line-height: 12px; } -.palette .cells { display: grid; grid-template-columns: repeat(2, 17px); gap: 2px; } -.palette .slot { display: contents; } -.palette .cell { +.palette-grid .cells { display: grid; grid-template-columns: repeat(2, 17px); gap: 2px; } +.palette-grid .slot { display: contents; } +.palette-grid .cell { width: 17px; height: 17px; padding: 0; border: 1px solid rgba(0, 0, 0, .35); border-radius: 2px; cursor: pointer; } -.palette .cell:hover { border-color: var(--fg); transform: scale(1.12); } -.palette .cell.on { border-color: var(--fg); box-shadow: 0 0 0 1px var(--pane), 0 0 0 2px var(--sel); position: relative; z-index: 1; } +.palette-grid .cell:hover { border-color: var(--fg); transform: scale(1.12); } +.palette-grid .cell.on { border-color: var(--fg); box-shadow: 0 0 0 1px var(--pane), 0 0 0 2px var(--sel); position: relative; z-index: 1; } /* Clear is no colour: a knockout. Checkered, as transparency is everywhere. */ -.palette .clear, -.palette .chip.clear { +.palette-grid .clear, +.palette-grid .chip.clear { background-color: #fff; background-image: linear-gradient(45deg, #c9c9c5 25%, transparent 25%, transparent 75%, #c9c9c5 75%), @@ -1756,13 +1756,13 @@ button.tl-gap:hover { background: rgba(47, 111, 192, .28); } /* Remap: the map swatch, and the inspector's grid for a remap shape. A slot is shown as what is under the shape will be drawn in; the original is the chip in its corner. */ -.palette .cell.map, -.palette .chip.map { +.palette-grid .cell.map, +.palette-grid .chip.map { background: linear-gradient(135deg, #3a3f52 0 50%, #e8d9a8 50% 100%); color: #fff; font-size: 11px; line-height: 1; text-shadow: 0 1px 1px rgba(0, 0, 0, .6); } -.palette .cell { position: relative; } -.palette .cell .badge { +.palette-grid .cell { position: relative; } +.palette-grid .cell .badge { position: absolute; right: -2px; bottom: -2px; width: 7px; height: 7px; border: 1px solid var(--pane); border-radius: 50%; @@ -1829,35 +1829,81 @@ button.tl-gap:hover { background: rgba(47, 111, 192, .28); } .palette-row .rename { align-self: stretch; padding: 0 7px; border-color: transparent; background: none; } .palette-row .rename:hover:not(:disabled) { border-color: var(--sel); background: #fff; } +/* The chooser: search, then sections most relevant first, then the classics + folded small at the foot. Each row is the playhead's frame in that palette, + its strip, its name and where it is from; `use` sits beside it. */ +/* The list scrolls and nothing else does, so search sits at the top and the + shelf at the foot however many palettes there are between them. */ +.menu.popout:has(.palette-chooser) { width: 300px; display: flex; flex-direction: column; overflow: hidden; } +.palette-popout:has(.palette-chooser) { display: flex; flex-direction: column; min-height: 0; flex: 1; } +.palette-chooser { display: flex; flex-direction: column; gap: 6px; min-width: 0; min-height: 0; flex: 1; } +.palette-chooser .palette-list { flex: 1 1 auto; min-height: 80px; max-height: none; } +.palette-search { width: 100%; } +.palette-head { + padding: 6px 2px 2px; font-size: 10px; letter-spacing: .06em; text-transform: uppercase; + color: var(--dim); +} +.palette-head:first-child { padding-top: 0; } +.palette-row .choose { grid-template-columns: auto 1fr; } +.palette-row .choose .text { display: grid; gap: 2px; min-width: 0; } +.palette-row .choose .strip { height: 9px; } +.palette-row .thumb { + width: 48px; height: 36px; object-fit: contain; border-radius: 2px; + background: #000; box-shadow: 0 0 0 1px rgba(0, 0, 0, .3); +} +.palette-row .note { + overflow: hidden; text-overflow: ellipsis; white-space: nowrap; + font-size: 10px; color: var(--dim); +} +.palette-row .use { + align-self: stretch; padding: 0 7px; font-size: 10px; + border-color: transparent; background: none; opacity: 0; +} +.palette-row:hover .use, .palette-row .use:focus { opacity: 1; } +.palette-row .use:hover:not(:disabled) { border-color: var(--sel); background: #fff; } +.palette-editing { display: flex; align-items: center; gap: 6px; min-width: 0; } +.palette-editing .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; } +.palette-editing .rename { padding: 0 7px; border-color: transparent; background: none; } +.palette-editing .palette-name { flex: 1; min-width: 0; } + +.palette-shelf > summary { + cursor: pointer; font-size: 10px; letter-spacing: .06em; text-transform: uppercase; + color: var(--dim); padding: 2px; +} +.palette-shelf .shelf { + display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; + padding-top: 4px; max-height: 30vh; overflow: auto; +} +.palette-shelf .tile { + display: grid; gap: 2px; min-width: 0; padding: 3px; + border: 1px solid transparent; border-radius: 3px; background: none; text-align: left; +} +.palette-shelf .tile:hover { background: var(--sunk); border-color: var(--hair); } +.palette-shelf .tile .strip { height: 8px; } +.palette-shelf .tile .name { + font-size: 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; +} + .strip { display: flex; height: 14px; border: 1px solid rgba(0, 0, 0, .35); border-radius: 2px; overflow: hidden; } .strip i { flex: 1; } /* On the stage at the playhead. */ .on-stage { width: 7px; height: 7px; border-radius: 50%; background: var(--live); } -/* A palette being edited that the stage is not drawing in here. Information, - not alarm: the accent of a selection, not of a warning. */ .palette-assets-wrap { position: relative; } -.palette-info { - position: absolute; top: -3px; right: -5px; - width: 13px; height: 13px; border-radius: 50%; - display: grid; place-items: center; - background: var(--sel); color: #fff; - font: italic 600 9px/1 Georgia, serif; - cursor: help; - box-shadow: 0 0 0 1.5px var(--chrome); + +/* Back to the palette the stage is in, when another is open in the grid. */ +.palette-grid .back { padding: 1px 4px; font-size: 10px; white-space: nowrap; } +/* A slot nothing in the open symbol draws with. */ +.palette-grid .cell.unused { opacity: .5; } +.palette-grid .cell.unused::after { + content: ""; position: absolute; inset: 0; pointer-events: none; + background: linear-gradient(135deg, transparent 45%, rgba(255, 255, 255, .8) 45% 55%, transparent 55%); } -.info-card { - position: fixed; z-index: 60; - width: 240px; padding: 8px 10px; - display: grid; gap: 3px; - background: var(--pane); color: var(--fg); - font: 11px/1.45 "Lucida Grande", "Segoe UI", system-ui, sans-serif; - border: 1px solid var(--sel); border-left-width: 3px; border-radius: 3px; - box-shadow: 0 3px 10px rgba(0, 0, 0, .25); - cursor: default; -} -.info-card strong { color: #14395f; } +.palette-grid .grid-tools { display: flex; gap: 2px; } +.palette-grid .grid-tools button { padding: 0 4px; min-width: 17px; font-size: 11px; } +.palette-grid .grid-tools button.on { background: var(--sel-bg); border-color: var(--sel); } + .view-popout label { display: block; margin-bottom: 8px; } .view-popout label:last-child { margin-bottom: 0; } .view-popout input, .view-popout select { width: 100%; } From c359ac650fdf88dec1fe732759ca7328779b9c47 Mon Sep 17 00:00:00 2001 From: Olive Vaughn Date: Sat, 10 Oct 2026 19:52:34 -0400 Subject: [PATCH 06/16] Open the palette lane onto its selected transition, like any lane Co-Authored-By: Claude Opus 5.5 --- frontend/src/arthur/ui/timeline.cljs | 43 ++++++++++++++-------- frontend/test/arthur/events/lane_test.cljs | 27 +++++++++++++- 2 files changed, 53 insertions(+), 17 deletions(-) diff --git a/frontend/src/arthur/ui/timeline.cljs b/frontend/src/arthur/ui/timeline.cljs index 8d6a833..76c3f11 100644 --- a/frontend/src/arthur/ui/timeline.cljs +++ b/frontend/src/arthur/ui/timeline.cljs @@ -365,26 +365,39 @@ (walk sid [] 0 identity) []))))) -(defn palette-track-row - "`sid`'s palette row: ONE LANE ROW WHETHER OR NOT THE LANE EXISTS YET, because +(defn palette-track-rows + "`sid`'s palette rows. Its row: ONE LANE ROW WHETHER OR NOT THE LANE EXISTS YET, because a person putting a palette transition somewhere is doing the same thing in either case. Empty, it names the symbol whose palette it would be; filled, it - is the lane symbol's own row under this pane's name for it." + is the lane symbol's own row under this pane's name for it, and opens as any + lane does: onto the selected transition, its keys and channels." [clip sid frames expanded chosen] (let [track-id (get-in clip [:symbols sid :palette-track]) track (get-in clip [:symbols track-id])] (if (= :palette-track (:type track)) - ;; A MATERIALIZED TRACK IS AN ORDINARY LANE ROW, selection and all: it is - ;; the row `rows` already draws for a lane symbol, wearing this pane's - ;; name for it. Only the row of a track that does not exist yet has to say - ;; whose palette it would be, which is what creating in it needs. - (-> (first (rows clip track-id expanded chosen)) - (assoc :path [::palette-track] :owner track-id - :label "palette" :kind :palette - :expandable? false :expanded? false)) - {:path [::palette-track] :depth 0 :label "palette" :kind :palette - :lane? true :owner nil :select [::palette-track sid] - :span [0 frames] :keys [] :cels []}))) + ;; A MATERIALIZED TRACK IS AN ORDINARY LANE ROW, selection, portal and + ;; all: it is what `rows` already draws for a lane symbol, wearing this + ;; pane's name for it. Only the row of a track that does not exist yet has + ;; to say whose palette it would be, which is what creating in it needs. + ;; + ;; `rows` calls a lane's own row `[::lane]`, which is also the open + ;; symbol's when that is a lane, so this row goes by `[::palette-track]` + ;; and is translated on the way in. The portal's rows keep their authored + ;; paths -- the clip ids are the track's own -- and carry the track as + ;; their `:owner`, so dragging them slides the clip in the track. + (let [expanded (cond-> (disj (set expanded) [::lane]) + (contains? (set expanded) [::palette-track]) (conj [::lane])) + [lane & more] (rows clip track-id expanded chosen)] + (into [(assoc lane :path [::palette-track] :owner track-id + :label "palette" :kind :palette)] + (comp (take-while #(pos? (:depth %))) + (map #(cond-> (assoc % :owner track-id) + (= ::lane (first (:path %))) + (assoc :path (into [::palette-track] (rest (:path %))))))) + more)) + [{:path [::palette-track] :depth 0 :label "palette" :kind :palette + :lane? true :owner nil :select [::palette-track sid] + :span [0 frames] :keys [] :cels []}]))) (defn sound-rows "Audio rows use the same flattened intervals as the mixer, including source @@ -1395,7 +1408,7 @@ {:id ::drop :label (str "+ " (:label drop)) :ghost? true :span drop-span}) chosen (when (= :node (first selection)) (nth selection 3)) - picture (cond-> (cond->> (into [(palette-track-row clip open frames expanded chosen)] + picture (cond-> (cond->> (into (palette-track-rows clip open frames expanded chosen) (rows clip open expanded chosen)) lane-ghost (mapv (fn [row] diff --git a/frontend/test/arthur/events/lane_test.cljs b/frontend/test/arthur/events/lane_test.cljs index 4dac1fa..aefaa67 100644 --- a/frontend/test/arthur/events/lane_test.cljs +++ b/frontend/test/arthur/events/lane_test.cljs @@ -98,19 +98,42 @@ "creating in a lane does not move the playhead")))) (deftest the-palette-row-is-a-lane-row-whether-or-not-its-track-exists - (let [empty-row (timeline/palette-track-row (clip/blank) :main 120 #{} nil) + (let [empty-row (first (timeline/palette-track-rows (clip/blank) :main 120 #{} nil)) filled (-> (clip/blank) (assoc-in [:symbols :main :palette-track] :track) (assoc-in [:symbols :track] {:id :track :type :palette-track :display :lane :frames 120 :nodes {}})) - filled-row (timeline/palette-track-row filled :main 120 #{} nil)] + filled-row (first (timeline/palette-track-rows filled :main 120 #{} nil))] ;; The double-click that creates in a lane asks nothing else of a row. (is (:lane? empty-row)) (is (:lane? filled-row)) (is (= [:node :track nil []] (:select filled-row)) "a track that exists is addressed as the lane it is"))) +(deftest the-palette-row-opens-onto-the-selected-transition-like-any-lane + (let [doc (-> (clip/blank) + (assoc-in [:symbols :main :palette-track] :track) + (assoc-in [:symbols :night] {:id :night :type :palette :frames 1 :nodes {}}) + (assoc-in [:symbols :track] + {:id :track :type :palette-track :display :lane :frames 120 + :nodes {:p {:id :p :kind :instance :source :night :span [10 40] + :time {:mode :map :at 10 :rate 1} + :channels {[:pos] {:keys {0 [0 0] 12 [5 0]}}}}}})) + closed (timeline/palette-track-rows doc :main 120 #{} [:p]) + [lane portal & channels] (timeline/palette-track-rows + doc :main 120 #{[:arthur.ui.timeline/palette-track] [:p]} [:p])] + (is (= 1 (count closed))) + (is (:expandable? (first closed)) "the palette lane has a disclosure like any lane") + (is (:expanded? lane)) + (is (= [:p] (:path portal)) "the portal is the selected transition, by its own path") + (is (= [:node :track :p [:p]] (:select portal))) + (is (= :track (:owner portal)) "dragging its bar slides it in the track") + (is (= [10 22] (:keys portal)) "its keys are on this ruler") + (is (= [:p [:pos]] (:path (first channels))) "and it opens onto its channels") + (is (not (contains? #{[:arthur.ui.timeline/lane]} (:path lane))) + "the palette lane never shares the open lane's expansion"))) + (deftest the-same-double-click-command-creates-a-palette-symbol-on-the-palette-row (let [doc (clip/blank) id (store/install! {:clip doc :store {}} "double-click-palette-symbol")] From fcf2e20f7863c3bc8b96d49f394ea27c4cc22704 Mon Sep 17 00:00:00 2001 From: Olive Vaughn Date: Sat, 10 Oct 2026 20:02:42 -0400 Subject: [PATCH 07/16] Play from the last frame starts over, rather than playing one frame Co-Authored-By: Claude Opus 5.5 --- frontend/src/arthur/events/playback.cljs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/frontend/src/arthur/events/playback.cljs b/frontend/src/arthur/events/playback.cljs index 994b8e8..8687a7f 100644 --- a/frontend/src/arthur/events/playback.cljs +++ b/frontend/src/arthur/events/playback.cljs @@ -63,11 +63,18 @@ (get-in db [:ui :gesture :auto-key?]) (assoc :dispatch [:arthur.events.ui/record-gesture f]))))) -(rf/reg-event-fx - ::play - (fn [{:keys [db]} _] - {:db (assoc-in db [:playback :playing?] true) - ::play-from! [(fps db) (frames db) (get-in db [:playback :frame] 0)]})) +(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." + [db] + (let [n (frames db) + f (get-in db [:playback :frame] 0) + f (if (< f (dec n)) f 0)] + {:db (update db :playback assoc :playing? true :frame f) + ::play-from! [(fps db) n f]})) + +(rf/reg-event-fx ::play (fn [{:keys [db]} _] (start db))) (rf/reg-event-fx ::pause @@ -80,8 +87,7 @@ (fn [{:keys [db]} _] (if (get-in db [:playback :playing?]) {:db (assoc-in db [:playback :playing?] false) ::pause! nil} - {:db (assoc-in db [:playback :playing?] true) - ::play-from! [(fps db) (frames db) (get-in db [:playback :frame] 0)]}))) + (start db)))) (rf/reg-event-fx ::seek From e96464459da945933faa2d345bfda156067e5914 Mon Sep 17 00:00:00 2001 From: Olive Vaughn Date: Sat, 10 Oct 2026 20:08:26 -0400 Subject: [PATCH 08/16] One table of keyboard shortcuts, and ? to see it Space plays and pauses, and still pans when held and dragged on the stage. Arrows and WASD step frames and jump between keys and cel edges; Home/End and shift go to the first and last frame; alt-O toggles onion skin. The tool, undo and clipboard keys move into the same table, which the ? sheet prints. Co-Authored-By: Claude Opus 5.5 --- frontend/src/arthur/core.cljs | 5 +- frontend/src/arthur/events/history.cljs | 25 --- frontend/src/arthur/events/ui.cljs | 2 - frontend/src/arthur/ui/shell.cljs | 2 + frontend/src/arthur/ui/shortcuts.cljs | 181 ++++++++++++++++++++ frontend/src/arthur/ui/stage.cljs | 23 +-- frontend/src/arthur/ui/timeline.cljs | 8 +- frontend/src/arthur/ui/tools.cljs | 21 --- frontend/src/arthur/ui/topbar.cljs | 4 +- frontend/test/arthur/ui/shortcuts_test.cljs | 13 ++ static/arthur/app.css | 21 +++ 11 files changed, 232 insertions(+), 73 deletions(-) create mode 100644 frontend/src/arthur/ui/shortcuts.cljs create mode 100644 frontend/test/arthur/ui/shortcuts_test.cljs diff --git a/frontend/src/arthur/core.cljs b/frontend/src/arthur/core.cljs index cd61510..af33ac6 100644 --- a/frontend/src/arthur/core.cljs +++ b/frontend/src/arthur/core.cljs @@ -17,7 +17,7 @@ [arthur.ui.index :as index] [arthur.ui.player :as player] [arthur.ui.shell :as shell] - [arthur.ui.tools :as tools] + [arthur.ui.shortcuts :as shortcuts] [re-frame.core :as rf] [reagent.dom.client :as rdc])) @@ -46,8 +46,7 @@ ;; After the blank document, so an address that names a project opens it over ;; the blank one, and the blank one is what a bad address leaves on screen. (collab/start!) - (history/install-keys!) - (tools/install-keys!) + (shortcuts/install!) (reset! root (rdc/create-root (js/document.getElementById "app"))) (mount) (player/start!)) diff --git a/frontend/src/arthur/events/history.cljs b/frontend/src/arthur/events/history.cljs index d45ddc7..d5f56e6 100644 --- a/frontend/src/arthur/events/history.cljs +++ b/frontend/src/arthur/events/history.cljs @@ -71,28 +71,3 @@ (:paint/revision db) (history/steps (:history (store/entry (:clip/current db)))))) -(defn- typing? [^js target] - (or (#{"INPUT" "TEXTAREA" "SELECT"} (.-tagName target)) (.-isContentEditable target))) - -(defn install-keys! - "The document edit keys. Not while typing in a field, where the browser's own - clipboard and undo stack are the ones wanted." - [] - (.addEventListener - js/window "keydown" - (fn [^js e] - (when-not (typing? (.-target e)) - (let [k (.toLowerCase (.-key e))] - (when-let [ev (if (and (or (.-metaKey e) (.-ctrlKey e)) - (not (.-altKey e))) - (cond (and (= k "z") (.-shiftKey e)) ::redo - (= k "z") ::undo - (= k "y") ::redo - (= k "c") ::ui/copy - (= k "x") ::ui/cut - (= k "v") ::ui/paste - (and (= k "d") (.-shiftKey e)) ::ui/duplicate-unique - (= k "d") ::ui/duplicate) - (when (#{"delete" "backspace"} k) ::ui/delete-selected))] - (.preventDefault e) - (rf/dispatch [ev]))))))) diff --git a/frontend/src/arthur/events/ui.cljs b/frontend/src/arthur/events/ui.cljs index 6474729..373bccb 100644 --- a/frontend/src/arthur/events/ui.cljs +++ b/frontend/src/arthur/events/ui.cljs @@ -562,8 +562,6 @@ ::hover (fn [db [_ p]] (if p (assoc-in db [:ui :hover] p) (update db :ui dissoc :hover)))) -(def tool-keys #{"v" "p" "b" "e" "[" "]" "enter" "escape"}) - (rf/reg-event-fx ::tool-key ;; A key from `ui/tools`, decided here against the state it changes, and diff --git a/frontend/src/arthur/ui/shell.cljs b/frontend/src/arthur/ui/shell.cljs index f96bf99..20015d7 100644 --- a/frontend/src/arthur/ui/shell.cljs +++ b/frontend/src/arthur/ui/shell.cljs @@ -16,6 +16,7 @@ [arthur.ui.location :as location] [arthur.ui.params :as params] [arthur.ui.pool :as pool] + [arthur.ui.shortcuts :as shortcuts] [arthur.ui.stage :as stage] [arthur.ui.tabs :as tabs] [arthur.ui.timeline :as timeline] @@ -70,6 +71,7 @@ gone? #(contains? shut %)] [:div.app {:style (layout/vars state)} [topbar/view] + [shortcuts/sheet] (when-not (gone? :pool) [pool/view]) (when-not (gone? :pool) [layout/grip :pool pool :col 1]) [:section.view diff --git a/frontend/src/arthur/ui/shortcuts.cljs b/frontend/src/arthur/ui/shortcuts.cljs new file mode 100644 index 0000000..d974a76 --- /dev/null +++ b/frontend/src/arthur/ui/shortcuts.cljs @@ -0,0 +1,181 @@ +(ns arthur.ui.shortcuts + "Every key the window answers to, as one table, and the sheet that lists them. + + A COMMAND IS DATA: what it is called, which keys reach it, and a function of + the db that answers the event to send, or nil for nothing to do. One listener + reads the table, the `?` sheet prints it, and nothing else in the app listens + to the window for keys. What a key does in one element only — nudging the + timeline's selected keys, Enter in a rename field — stays on that element, + which handles it first and stops it, as Blender's modal operators do. + + NO MODES. A key means one thing everywhere and what it acts on is the + selection, so there is no state to remember besides the tool. Space is the one + key with two meanings, and they are told apart by the hand rather than by a + mode: tapped it plays, held and dragged on the stage it pans, as in Photoshop. + + THE KEYS ARE BLENDER'S, then Resolve's, then Flash's. WASD repeats the arrows + for a hand that stays on the left of the keyboard while the other holds the + pen. Letters are matched by where they are on the keyboard, not by what they + type, so WASD is WASD on any layout and ⌥O is O on a Mac too." + (: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] + [re-frame.core :as rf] + [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]) + +(def commands + [["Time" + [{:label "Play / pause" :keys ["Space"] :run (constantly [::pb/toggle]) + :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 "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 "Onion skin" :keys ["alt+o"] + :run #(let [on? (get-in % [:ui :onion (:clip/current %) (get-in % [:ui :open]) :on?])] + [::layout/onion :on? (not on?)])}]] + ["Draw" + [{:label "Select" :keys ["v"] :run (constantly [::ui/tool-key "v"])} + {:label "Pen" :keys ["p"] :run (constantly [::ui/tool-key "p"])} + {:label "Brush" :keys ["b"] :run (constantly [::ui/tool-key "b"])} + {:label "Eraser" :keys ["e"] :run (constantly [::ui/tool-key "e"])} + {:label "Smaller brush" :keys ["["] :run (constantly [::ui/tool-key "["])} + {:label "Bigger brush" :keys ["]"] :run (constantly [::ui/tool-key "]"])} + {:label "Close the pen's shape" :keys ["Enter"] :run (constantly [::ui/tool-key "enter"])} + {:label "Leave the pen" :keys ["Escape"] :run (constantly [::ui/tool-key "escape"])}]] + ["Edit" + [{:label "Undo" :keys ["mod+z"] :run (constantly [::history/undo])} + {:label "Redo" :keys ["mod+shift+z" "mod+y"] :run (constantly [::history/redo])} + {:label "Copy" :keys ["mod+c"] :run (constantly [::ui/copy])} + {:label "Cut" :keys ["mod+x"] :run (constantly [::ui/cut])} + {:label "Paste" :keys ["mod+v"] :run (constantly [::ui/paste])} + {:label "Duplicate" :keys ["mod+d"] :run (constantly [::ui/duplicate])} + {:label "Duplicate as new symbol" :keys ["mod+shift+d"] :run (constantly [::ui/duplicate-unique])} + {:label "Delete" :keys ["Delete" "Backspace"] :run (constantly [::ui/delete-selected])}]] + ["Help" + [{:label "These shortcuts" :keys ["?"]}]]]) + +(def ^:private by-chord + (into {} (for [[_ cs] commands c cs k (:keys c)] [k c]))) + +(defn- chord + "The key as the table spells it: `mod+` for ⌘ or Ctrl, then `alt+`, then + `shift+` — except on a character that shift itself typed, like `?`." + [^js e] + (let [code (.-code e) + letter (when (str/starts-with? code "Key") (str/lower-case (subs code 3))) + k (cond letter letter (= "Space" code) "Space" :else (.-key e))] + (str (when (or (.-metaKey e) (.-ctrlKey e)) "mod+") + (when (.-altKey e) "alt+") + (when (and (.-shiftKey e) (or letter (< 1 (count k)))) "shift+") + k))) + +(defn- typing? + "Is a key going into a field? A slider or a checkbox has focus without taking + letters, so the window's keys still work there, as a tool's key does in + Photoshop." + [^js target] + (or (#{"TEXTAREA" "SELECT"} (.-tagName target)) + (and (= "INPUT" (.-tagName target)) + (not (#{"range" "checkbox" "radio" "button" "color"} (.-type target)))) + (.-isContentEditable target))) + +(defn- press! + "Send what key `k` answers now, against the db as it is. + + SYNCHRONOUSLY, so a held arrow counts every repeat. Dispatched instead, two + presses in quick succession both read the frame before either had moved it, + and D D went one frame." + [k] + (when-let [ev (some-> (get-in by-chord [k :run]) (#(% @db/app-db)))] + (rf/dispatch-sync ev))) + +;; Nil, :held, or :panned once a drag on the stage has used the hold — see +;; `ui/stage`. A tap is a hold that was never used. +(defonce space (atom nil)) +(defonce ^:private open? (r/atom false)) + +(defn- on-key-down [^js e] + (when-not (typing? (.-target e)) + (let [k (chord e)] + (cond + (and @open? (#{"Escape" "?"} k)) (do (.preventDefault e) (reset! open? false)) + (= "?" k) (do (.preventDefault e) (reset! open? true)) + ;; Played on the way UP, because only then is it known to be a tap. + ;; Default prevented both ways, or a focused button clicks as well. + (= "Space" k) (do (.preventDefault e) + (when-not (.-repeat e) (reset! space :held))) + (by-chord k) (do (.preventDefault e) (press! k)))))) + +(defn- on-key-up [^js e] + (when (= "Space" (.-code e)) + (when (= :held @space) + (.preventDefault e) + (press! "Space")) + (reset! space nil))) + +(defn install! [] + (.addEventListener js/window "keydown" on-key-down) + (.addEventListener js/window "keyup" on-key-up) + (.addEventListener js/window "blur" #(reset! space nil))) + +(def ^:private glyphs + {"mod" "⌘" "alt" "⌥" "shift" "⇧" "ArrowLeft" "←" "ArrowRight" "→" + "ArrowUp" "↑" "ArrowDown" "↓" "Backspace" "⌫" "Escape" "Esc"}) + +(defn- spell [k] + (apply str (map #(or (glyphs %) (str/upper-case %)) (str/split k #"\+")))) + +(defn sheet + "The `?` sheet. Shut by Esc, by `?` again, or by a click anywhere off it." + [] + (when @open? + [:<> + [:div.keys-scrim {:on-click #(reset! open? false)}] + [:section.keys-sheet {:role "dialog" :aria-modal true :aria-label "Keyboard shortcuts"} + (for [[title cs] commands] + ^{:key title} + [:div.keys-group + [:h3 title] + (for [{:keys [label note] ks :keys} cs] + ^{:key label} + [:div.keys-row + [:span label (when note [:small note])] + [:span.keys (for [k ks] ^{:key k} [:kbd (spell k)])]])])]])) + +(defn button [] + [:button {:title "keyboard shortcuts (?)" :aria-label "keyboard shortcuts" + :on-click #(reset! open? true)} "?"]) diff --git a/frontend/src/arthur/ui/stage.cljs b/frontend/src/arthur/ui/stage.cljs index 0575312..ea11433 100644 --- a/frontend/src/arthur/ui/stage.cljs +++ b/frontend/src/arthur/ui/stage.cljs @@ -28,6 +28,7 @@ [arthur.ui.layout :as layout] [arthur.ui.player :as player] [arthur.ui.tracing :as tracing] + [arthur.ui.shortcuts :as shortcuts] [arthur.ui.tools :as tools] [arthur.ui.timeline :as timeline] [re-frame.core :as rf] @@ -758,24 +759,10 @@ (when pen? [draft-lines draft hover]) (when paints? [cursor tool])])) -(defonce space-held? (atom false)) (defonce pan (atom nil)) -(defn- stage-key-target? [target] - (and (.closest target ".stage-area") - (not (.closest target "input, textarea, select, button, a, summary, [role='button']")) - (not (.-isContentEditable target)))) - -(defonce navigation-keys +(defonce navigation-blur (when (exists? js/window) - (.addEventListener js/window "keydown" - (fn [e] - (when (and (= "Space" (.-code e)) - (not (or (.-ctrlKey e) (.-metaKey e) (.-altKey e))) - (stage-key-target? (.-target e))) - (.preventDefault e) - (reset! space-held? true)))) - (.addEventListener js/window "keyup" #(when (= "Space" (.-code %)) (reset! space-held? false))) - (.addEventListener js/window "blur" #(do (reset! space-held? false) (reset! pan nil))))) + (.addEventListener js/window "blur" #(reset! pan nil)))) (defonce pinch-start-zoom (atom nil)) @@ -817,8 +804,10 @@ (fn [e] (.preventDefault e) (reset! pinch-start-zoom nil)))) nil) :on-pointer-down-capture - (fn [e] (when (or (= 1 (.-button e)) (and (= 0 (.-button e)) @space-held?)) + (fn [e] (when (or (= 1 (.-button e)) (and (= 0 (.-button e)) @shortcuts/space)) (.preventDefault e) (.stopPropagation e) + ;; Space held and used to pan, so letting go does not also play. + (when @shortcuts/space (reset! shortcuts/space :panned)) (let [el (.-currentTarget e)] (reset! pan [(.-clientX e) (.-clientY e) (.-scrollLeft el) (.-scrollTop el)]) (.setPointerCapture el (.-pointerId e))))) diff --git a/frontend/src/arthur/ui/timeline.cljs b/frontend/src/arthur/ui/timeline.cljs index 76c3f11..7583a1d 100644 --- a/frontend/src/arthur/ui/timeline.cljs +++ b/frontend/src/arthur/ui/timeline.cljs @@ -542,15 +542,15 @@ ;; 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. [:div.group - [:button.ico {:aria-label "go to start" :title "go to the first frame" + [:button.ico {:aria-label "go to start" :title "go to the first frame (Home)" :on-click (act [::pb/seek 0])} [icon/view :start]] - [:button {:aria-label "−1" :title "step back one frame" + [: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") - :title (if playing? "pause" "play") + :title (if playing? "pause (Space)" "play (Space)") :on-click (act [::pb/toggle])} [icon/view (if playing? :pause :play)]] - [:button {:aria-label "+1" :title "step forward one frame" + [:button {:aria-label "+1" :title "step forward one frame (→ or D)" :on-click (act [::pb/step 1])} "+1"]] [:div.group [:button.ico {:class (when loop? "on") :aria-label "loop" diff --git a/frontend/src/arthur/ui/tools.cljs b/frontend/src/arthur/ui/tools.cljs index 2042177..f4823ce 100644 --- a/frontend/src/arthur/ui/tools.cljs +++ b/frontend/src/arthur/ui/tools.cljs @@ -109,24 +109,3 @@ (when (and (= :brush kind) (< 1 (count ids))) [:span.dim (str (count ids) " pieces")]) [fit-control fit ::ui/adjust-last]])) -(defn- typing? - "Is a key going into a field? A slider or a checkbox has focus without - taking letters, and a tool's key still picks the tool there, as in Photoshop." - [^js target] - (or (#{"TEXTAREA" "SELECT"} (.-tagName target)) - (and (= "INPUT" (.-tagName target)) - (not (#{"range" "checkbox" "radio" "button" "color"} (.-type target)))) - (.-isContentEditable target))) - -(defn install-keys! - "V, P, B and E pick a tool. Enter closes the pen's polygon, or takes the pen - to the selected shape's points; Esc closes it too, and then leaves the pen. - [ and ] size the brush. Delete and undo are `events/history`'s." - [] - (.addEventListener - js/window "keydown" - (fn [^js e] - (when-not (or (typing? (.-target e)) (.-metaKey e) (.-ctrlKey e) (.-altKey e)) - (when (contains? ui/tool-keys (.toLowerCase (.-key e))) - (.preventDefault e) - (rf/dispatch [::ui/tool-key (.toLowerCase (.-key e))])))))) diff --git a/frontend/src/arthur/ui/topbar.cljs b/frontend/src/arthur/ui/topbar.cljs index 0d46a8f..f7510e4 100644 --- a/frontend/src/arthur/ui/topbar.cljs +++ b/frontend/src/arthur/ui/topbar.cljs @@ -16,6 +16,7 @@ [arthur.ui.openmenu :as openmenu] [arthur.ui.settings :as settings] [arthur.ui.share :as share] + [arthur.ui.shortcuts :as shortcuts] [arthur.ui.snapshots :as snapshots] [arthur.ui.undo :as undo] [re-frame.core :as rf] @@ -115,4 +116,5 @@ title (when project-seq (str " r" project-seq))]) [:span.status (or export-status status footage-status)] [exporter export-open?] - [share/view]]))) + [share/view] + [shortcuts/button]]))) diff --git a/frontend/test/arthur/ui/shortcuts_test.cljs b/frontend/test/arthur/ui/shortcuts_test.cljs new file mode 100644 index 0000000..9eeb46e --- /dev/null +++ b/frontend/test/arthur/ui/shortcuts_test.cljs @@ -0,0 +1,13 @@ +(ns arthur.ui.shortcuts-test + (:require [cljs.test :refer [deftest is]] + [arthur.domain.sequence-test :as fixture] + [arthur.footage.store :as store] + [arthur.ui.shortcuts :as shortcuts])) + +(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 + ;; at 4 and 5; the plate keyed at 0 and 11. The lane's end, 12, is past the + ;; 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}})))))) diff --git a/static/arthur/app.css b/static/arthur/app.css index 9a09734..459866e 100644 --- a/static/arthur/app.css +++ b/static/arthur/app.css @@ -1932,3 +1932,24 @@ button.tl-key.selected { background: var(--pick); box-shadow: 0 0 0 2px var(--pi .choice { display: grid; gap: 6px; margin: 12px 0; } .choice button { display: grid; gap: 2px; text-align: left; padding: 8px; white-space: normal; height: auto; } .choice button .dim { font-size: 11px; } + +/* -------------------------------------------------------------------------- + the keyboard sheet, `?` */ + +.keys-scrim { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .45); } +.keys-sheet { + position: fixed; z-index: 51; top: 50%; left: 50%; transform: translate(-50%, -50%); + width: min(760px, calc(100vw - 32px)); max-height: calc(100vh - 32px); overflow: auto; + padding: 16px 20px; columns: 2 300px; column-gap: 32px; + background: var(--pane); border: 1px solid var(--line); border-radius: 3px; + box-shadow: 0 8px 30px rgba(0, 0, 0, .45); +} +.keys-group { break-inside: avoid; margin-bottom: 14px; } +.keys-group h3 { margin: 0 0 6px; font: inherit; font-weight: 600; color: var(--dim); } +.keys-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 2px 0; } +.keys-row small { display: block; color: var(--dim); } +.keys-row .keys { display: flex; gap: 4px; flex-shrink: 0; } +.keys-row kbd { + 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; +} From 246b6d6468984a50d8034b49488e8ae7ce7141a1 Mon Sep 17 00:00:00 2001 From: Olive Vaughn Date: Sat, 10 Oct 2026 20:17:30 -0400 Subject: [PATCH 09/16] K keys or draws on, shift-K draws blank, = and - change a hold In a lane, K is Flash's F6: a copy of the drawing showing, taking over from the playhead, or on the next frame when the playhead is on a drawing's first one, so pressing it again and again draws on. Shift-K is F7, the same with an empty drawing. Elsewhere K is Blender's I: what is animated, or else position, turn and scale, keyed at the playhead. = and - lengthen and shorten the selected hold by a frame, as in Harmony. Co-Authored-By: Claude Opus 5.5 --- frontend/src/arthur/domain/node.cljs | 13 +++++ frontend/src/arthur/domain/span.cljs | 45 ++++++++++++++ frontend/src/arthur/events/ui.cljs | 58 +++++++++++++++++++ frontend/src/arthur/ui/shortcuts.cljs | 9 ++- frontend/test/arthur/domain/node_test.cljs | 14 +++++ .../test/arthur/domain/sequence_test.cljs | 41 +++++++++++++ 6 files changed, 179 insertions(+), 1 deletion(-) diff --git a/frontend/src/arthur/domain/node.cljs b/frontend/src/arthur/domain/node.cljs index 0d65546..cc7b305 100644 --- a/frontend/src/arthur/domain/node.cljs +++ b/frontend/src/arthur/domain/node.cljs @@ -210,6 +210,19 @@ (:segments c) (update :segments dissoc f)) :else (ch/framed v)))))) +(defn key-at + "Key `n` on its own frame `f` with the values it has there: every channel + already keyed, or its position, turn and scale when none is — Blender's I. + A channel with a key at `f` already keeps it." + [n f store] + (let [chs (channels n) + keyed (keep (fn [[path c]] (when (:keys c) path)) chs)] + (reduce (fn [n path] + (if (contains? (:keys (get (channels n) path)) f) n (toggle-key n path f store))) + n + (or (seq keyed) + (filter #(contains? chs %) [[:xform :pos] [:xform :rot] [:xform :scale]]))))) + (defn set-segment-interp "Choose how channel `path`'s key at `left` leads to the next one: `:hold` cuts there, `:linear` tweens. The same for a drawing's points as for a transform — diff --git a/frontend/src/arthur/domain/span.cljs b/frontend/src/arthur/domain/span.cljs index c9b29dc..26d56f2 100644 --- a/frontend/src/arthur/domain/span.cljs +++ b/frontend/src/arthur/domain/span.cljs @@ -778,6 +778,51 @@ nodes (assoc nodes id (held id drawing-id at))] (claim c sid nodes id extent remainder-id))))) +(defn drawing-at + "A new drawing in lane `sid` from frame `f`, as Flash's F6 and F7 make one: + a copy of the drawing showing there when `copy?`, an empty one when not. + + IT TAKES OVER FROM `f`. Inside a hold, the held cel ends at `f` and the new + one has the rest of it, so the timing already there is kept and only the + drawing changes. In a gap it runs to the next cel; past the last one it is one + frame. On a cel's first frame there is a drawing starting there already, so + the new one goes on the frame after — pressing F6 again and again draws on, + one frame at a time — and shows the drawing it came after. + + The copy is of the content, shallow, as `duplicate-drawing`'s is, under a name + of its own. `:frame` in the result is where it landed." + [clip sid f new-id drawing-id {:keys [copy? extent] :or {extent :keep}}] + (let [nodes (get-in clip [:symbols sid :nodes]) + cels (symbol/children nodes) + lo-of #(first (node/placed-span %)) + hi-of #(second (node/placed-span %)) + on (some #(when (= f (lo-of %)) %) cels) + f (if on (inc f) f) + holding (some #(when (< (lo-of %) f (hi-of %)) %) cels) + shown (or holding on (last (filter #(<= (hi-of %) f) cels))) + next-lo (some #(when (<= f (lo-of %)) (lo-of %)) cels) + from (when copy? (some-> shown node/source))] + (cond + (not (and (integer? f) (not (neg? f)))) {:refused "a position is a nonnegative whole frame"} + (contains? nodes new-id) {:refused "the new clip ID is already used"} + (clip/symbol clip drawing-id) {:refused "the new drawing ID is already used"} + (and copy? (not (clip/symbol clip from))) {:refused "there is no drawing here to copy"} + :else + (let [c (assoc-in clip [:symbols drawing-id] + (if from + ;; Its own name: it is a new drawing, and two of one + ;; name in the library is a question nobody asked. + (assoc (clip/symbol clip from) :id drawing-id :name (name drawing-id)) + {:id drawing-id :name (name drawing-id) :frames 1 :nodes {}}))] + (if (= f next-lo) + ;; A cel starts right here, so there is no room: make some. + (place c sid new-id drawing-id f extent true) + (let [end (cond holding (hi-of holding) next-lo next-lo :else (inc f)) + nodes (cond-> (assoc nodes new-id (assoc (held new-id drawing-id f) :span [0 (- end f)])) + holding (assoc (:id holding) (edged holding :out f)))] + (let [result (finish c sid nodes new-id extent)] + (cond-> result (:clip result) (assoc :frame f))))))))) + (defn make-unique "Point clip `id` at a private copy of its content, leaving every other clip of that drawing sharing the original. diff --git a/frontend/src/arthur/events/ui.cljs b/frontend/src/arthur/events/ui.cljs index 373bccb..8d4b867 100644 --- a/frontend/src/arthur/events/ui.cljs +++ b/frontend/src/arthur/events/ui.cljs @@ -30,6 +30,7 @@ [arthur.domain.palette :as pal] [arthur.domain.pick :as pick] [arthur.domain.span :as span] + [arthur.domain.symbol :as symbol] [arthur.events.edit :as edit] [arthur.domain.paint :as paint] [arthur.events.playback :as playback] @@ -362,6 +363,63 @@ result (span/extend-hold clip sid id delta {:extent (or extent :keep)})] (apply-command db sid result [::extend-hold delta :grow-symbol])))) +(defn lane-here + "The lane the playhead is in, as `nest/inside` answers it with its `:path` + from the open symbol: the nearest lane the selection is in, at any depth — + so a stroke just drawn in a cel counts as being in that cel's lane — or else + the lane the selection would draw into. Nil where there is none." + [db] + (let [{clip :clip st :store} (store/entry (:clip/current db)) + open (get-in db [:ui :open]) + f (editing-frame db clip) + [kind _ _ path :as selection] (get-in db [:ui :selection]) + lane-at (fn [p] + (when-let [in (nest/inside clip st open p f)] + (when (symbol/lane? (clip/symbol clip (:sid in))) + (assoc in :path p))))] + (or (when (= :node kind) + (some #(lane-at (pop %)) (take-while seq (iterate pop (vec path))))) + (let [t (creation/target clip st open selection f)] + (when (= :lane (:kind t)) (lane-at (:path t))))))) + +(rf/reg-event-fx + ::drawing-here + ;; K and ⇧K in a lane: see `span/drawing-at`. The new cel is selected and the + ;; playhead put on it, because it is there to be drawn in. + (fn [{:keys [db]} [_ copy?]] + (let [clip (:clip (store/entry (:clip/current db))) + {:keys [sid frame path time]} (lane-here db) + id (random-uuid) + result (if sid + (span/drawing-at clip sid frame id (clip/fresh-id clip) + {:copy? copy? :extent :grow-symbol}) + {:refused "select a lane, or a drawing in one"})] + (if-let [why (:refused result)] + {:db (assoc-in db [:project :status] why)} + (cond-> {:db (-> db + (edit/transaction (constantly (:clip result))) + (selected [:node sid id (conj path id)]))} + time (assoc :dispatch [::playback/seek + (js/Math.ceil (+ (:at time) (/ (:frame result) (:rate time))))])))))) + +(rf/reg-event-db + ::key-selected + ;; K on anything that is not in a lane: Blender's I. + (fn [db _] + (let [{clip :clip st :store} (store/entry (:clip/current db)) + f (editing-frame db clip) + places (keep (fn [[kind _ _ path]] + (when (and (= :node kind) (seq path)) + (nest/placement clip st (get-in db [:ui :open]) path f))) + (get-in db [:ui :selections]))] + (if (empty? places) + (assoc-in db [:project :status] (if (seq (get-in db [:ui :selections])) + "what is selected is not on screen at this frame" + "select something to key")) + (edit/edit db #(reduce (fn [c {:keys [sid id frame]}] + (update-in c [:symbols sid :nodes id] node/key-at frame st)) + % places)))))) + (rf/reg-event-fx ::retry (fn [{:keys [db]} _] diff --git a/frontend/src/arthur/ui/shortcuts.cljs b/frontend/src/arthur/ui/shortcuts.cljs index d974a76..989afe0 100644 --- a/frontend/src/arthur/ui/shortcuts.cljs +++ b/frontend/src/arthur/ui/shortcuts.cljs @@ -13,7 +13,7 @@ key with two meanings, and they are told apart by the hand rather than by a mode: tapped it plays, held and dragged on the stage it pans, as in Photoshop. - THE KEYS ARE BLENDER'S, then Resolve's, then Flash's. WASD repeats the arrows + THE KEYS ARE BLENDER'S, then Resolve's, then Flash's and Harmony's. WASD repeats the arrows for a hand that stays on the left of the keyboard while the other holds the pen. Letters are matched by where they are on the keyboard, not by what they type, so WASD is WASD on any layout and ⌥O is O on a Mac too." @@ -67,6 +67,13 @@ {: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?)])}]] + ["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])} + {: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])}]] ["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/test/arthur/domain/node_test.cljs b/frontend/test/arthur/domain/node_test.cljs index 669ee07..2746ed1 100644 --- a/frontend/test/arthur/domain/node_test.cljs +++ b/frontend/test/arthur/domain/node_test.cljs @@ -331,3 +331,17 @@ "editing repairs an older tweened colour channel") (is (= :hold (get-in (node/toggle-key n [:style :color] 3 nil) [:channels [:style :color] :interp]))))) + +(deftest keying-here-keys-what-is-animated-or-else-the-transform + (let [n {:id :x :kind :group} + fresh (node/key-at n 4 nil) + keyed-at #(set (keep (fn [[path c]] (when (contains? (:keys c) %2) path)) (node/channels %1)))] + (is (= #{[:xform :pos] [:xform :rot] [:xform :scale]} (keyed-at fresh 4)) + "nothing animated: position, turn and scale, as Blender's I") + (let [turning (node/set-keyed-channel n [:xform :rot] 0 0.0) + turning (node/set-keyed-channel turning [:xform :rot] 10 2.0) + keyed (node/key-at turning 5 nil)] + (is (= #{[:xform :rot]} (keyed-at keyed 5)) "only what is already animated") + (is (= 1.0 (ch/value-at (get (node/channels keyed) [:xform :rot]) 5 nil)) + "with the value it had there, so nothing moves")) + (is (= fresh (node/key-at fresh 4 nil)) "a key already there is kept, not toggled off"))) diff --git a/frontend/test/arthur/domain/sequence_test.cljs b/frontend/test/arthur/domain/sequence_test.cljs index 6a4481f..bd90ddd 100644 --- a/frontend/test/arthur/domain/sequence_test.cljs +++ b/frontend/test/arthur/domain/sequence_test.cljs @@ -893,3 +893,44 @@ (is (= [0 6] (node/placed-span n))) (is (every? #(= {:symbol :blank :frame 0} (node/placed-frame n % 1)) (range 6)) "stretched, every frame of it shows the one drawing"))) + +(defn- cel-spans [result sid] + (into {} (map (juxt :id node/placed-span)) + (symbol/children (get-in result [:clip :symbols sid :nodes])))) + +(deftest a-new-drawing-takes-over-from-the-playhead + (let [doc (document)] + (testing "inside a hold: the hold ends there and the copy has the rest of it" + (let [r (span/drawing-at doc :main 2 :new :copy {:copy? true})] + (is (= {:a [0 2] :new [2 4] :b [4 8] :insert [8 12]} (cel-spans r :main))) + (is (= 2 (:frame r))) + (is (= (get-in doc [:symbols :drawing-a :nodes]) + (get-in r [:clip :symbols :copy :nodes]))))) + (testing "on a drawing's first frame it goes on the frame after, as F6 does again and again" + (let [r (span/drawing-at doc :main 4 :new :copy {:copy? true})] + (is (= {:a [0 4] :b [4 5] :new [5 8] :insert [8 12]} (cel-spans r :main))) + (is (= (get-in doc [:symbols :drawing-b :nodes]) + (get-in r [:clip :symbols :copy :nodes]))))) + (testing "past the last cel: one frame, of the drawing before it, or empty" + (let [r (span/drawing-at doc :main 12 :new :blank {:extent :grow-symbol})] + (is (= [12 13] (get (cel-spans r :main) :new))) + (is (= {} (get-in r [:clip :symbols :blank :nodes]))) + (is (= 13 (get-in r [:clip :symbols :main :frames])))) + (is (:required-frames (span/drawing-at doc :main 12 :new :blank {})) + "growing the shot is the caller's say")))) + +(deftest a-new-drawing-in-a-gap-or-before-a-cel + (let [lane (fn [& cels] + (-> (document) + (assoc-in [:symbols :main] {:id :main :frames 12 :display :lane + :nodes (into {} (map (juxt :id identity)) cels)})))] + (is (= {:x [0 2] :new [3 5] :y [5 6]} + (cel-spans (span/drawing-at (lane (cel :x :drawing-a 0 2 0) (cel :y :drawing-b 5 1 0)) + :main 3 :new :copy {:copy? true}) :main)) + "in a gap it runs to the next cel, copying the one before") + (is (= {:x [0 1] :new [1 2] :y [2 4]} + (cel-spans (span/drawing-at (lane (cel :x :drawing-a 0 1 0) (cel :y :drawing-b 1 2 0)) + :main 0 :new :copy {:copy? true}) :main)) + "on a one-frame drawing with the next right after, room is made") + (is (:refused (span/drawing-at (lane) :main 0 :new :copy {:copy? true})) + "an empty lane has nothing to copy"))) From 1c6c45e4654b41b65339ca647123be46303dbc92 Mon Sep 17 00:00:00 2001 From: Olive Vaughn Date: Sat, 10 Oct 2026 20:20:33 -0400 Subject: [PATCH 10/16] 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 --- frontend/src/arthur/events/playback.cljs | 36 ++++++++++++++++++++---- frontend/src/arthur/subs/playback.cljs | 1 + frontend/src/arthur/ui/player.cljs | 14 +++++++-- frontend/src/arthur/ui/shortcuts.cljs | 4 +++ frontend/src/arthur/ui/timeline.cljs | 14 +++++++++ static/arthur/app.css | 11 ++++++++ 6 files changed, 72 insertions(+), 8 deletions(-) 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); +} From b45f7307a3cead47ed9568450a7888d80dbfd675 Mon Sep 17 00:00:00 2001 From: Olive Vaughn Date: Sat, 10 Oct 2026 20:31:20 -0400 Subject: [PATCH 11/16] 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; +} From e72d63214c3110c10834d728dbd0c7662631ab9f Mon Sep 17 00:00:00 2001 From: Olive Vaughn Date: Sat, 10 Oct 2026 20:36:51 -0400 Subject: [PATCH 12/16] Frames are cells: a grid through the rows, and a playhead a frame wide As in Flash, a hairline at every frame over the rows and through the cels, stronger at every second; too narrow to see, it steps by the fewest frames that divide a second, and goes when even that is too dense. The playhead is the frame it is on: a tinted cell with its line on the frame's left edge, where the ruler's number is, and a head carrying the frame number. Too narrow to tint, it is the line alone, as in Resolve. Co-Authored-By: Claude Opus 5.5 --- frontend/src/arthur/ui/timeline.cljs | 31 ++++++++++++++-- static/arthur/app.css | 55 +++++++++++++++++++++------- 2 files changed, 69 insertions(+), 17 deletions(-) diff --git a/frontend/src/arthur/ui/timeline.cljs b/frontend/src/arthur/ui/timeline.cljs index 407bf53..ef29c74 100644 --- a/frontend/src/arthur/ui/timeline.cljs +++ b/frontend/src/arthur/ui/timeline.cljs @@ -1316,7 +1316,9 @@ to move two elements' `left`. That cost more than painting the frame did and starved the rAF loop painting it, which ran at 16fps against a 60fps ceiling." [tag frames] - [tag {:style {:left (at% @(rf/subscribe [::render/open-frame]) frames)}}]) + (let [f @(rf/subscribe [::render/open-frame])] + [tag {:style {:left (edge% f frames) :width (edge% 1 frames)}} + (when (= tag :div.tl-knob) f)])) (defn- outside-marks "The frames playback leaves out, shaded, and the span it plays, banded on the @@ -1352,8 +1354,22 @@ :width (str (abs (- x2 x)) "px") :height (str (abs (- y2 y)) "px") :border "1px solid var(--pick)" :background "color-mix(in srgb, var(--pick) 15%, transparent)"}}]))) +(defn- frame-step + "How many frames apart the grid's fine lines are: every frame where a frame + is wide enough to see, else the fewest that divide a second evenly and are — + so a line still falls on every second — or nil when not even that fits under + the second lines." + [frame-px fps] + (first (filter #(and (zero? (mod fps %)) (<= 6 (* % frame-px)) (< % fps)) + (range 1 fps)))) + (defn- timeline-view [] (r/with-let [scrubbing (r/atom false) + ;; How wide the tracks are drawn, for how many pixels a frame + ;; gets: the grid and the playhead change with it. + tracks-px (r/atom nil) + sizer (js/ResizeObserver. + (fn [entries] (reset! tracks-px (.. (aget entries 0) -contentRect -width)))) ;; The row a carried row is over and which part of it, for the ;; highlight. over (r/atom nil) @@ -1461,6 +1477,8 @@ ;; FPS-blind 20/40/60 ruler. fps (max 1 (or (:fps clip) 1)) step (* fps (max 1 (js/Math.ceil (/ frames (* fps 10))))) + frame-px (/ (or @tracks-px 0) frames) + fine (frame-step frame-px fps) choose-row! (fn [e target] (let [xs (vec (keep :select visible)) anchor (or @row-anchor selection target) @@ -1595,7 +1613,10 @@ ;; The rows and ruler share this exact major interval. Keeping a ;; second, hard-coded five-frame grid here made its lines disagree ;; with the numbered marks whenever the project's FPS changed. - :style {"--tick" (str (* 100 (/ step frames)) "%")}} + :ref #(when % (.observe sizer %)) + :class (when (< frame-px 4) "narrow") + :style {"--tick" (str (* 100 (/ step frames)) "%") + "--fine" (if fine (str (* 100 (/ fine frames)) "%") "none")}} [:div.tl-ruler {:on-pointer-down (fn [^js e] (rf/dispatch [::pb/seek (frame-at e frames)]) @@ -1633,10 +1654,14 @@ :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"]) + ;; Over the rows, through the cels, as Flash draws its frames: a frame + ;; is a cell you can see wherever there is time. + [:div.tl-grid {:class (when-not fine "coarse")}] [outside-marks frames false] [playhead :div.tl-playhead frames] [key-marquee marquee]]] - [cursor-hint hint]]))) + [cursor-hint hint]]) + (finally (.disconnect sizer)))) (defn view [] [timeline-view]) diff --git a/static/arthur/app.css b/static/arthur/app.css index 0477276..bb016f1 100644 --- a/static/arthur/app.css +++ b/static/arthur/app.css @@ -1066,12 +1066,21 @@ button.share-button:hover, button.share-button.on { filter: brightness(1.1); } min-width: max(340px, calc((100% - var(--label)) * var(--tl-zoom, 1))); position: relative; background: #fff; - /* The major frame grid, using the same whole-second interval as the numbered - ruler. It is a background rather than an element per mark; `--tick` is set - by the component because only it knows the open symbol's length and FPS. */ +} + +/* THE FRAME GRID, over the rows so it shows through the cels as Flash's does: + a hairline at every frame (or every few, when a frame is too narrow to see — + `--fine` is set by the component, which knows how wide a frame is drawn) and + a stronger line at every whole second, the interval the ruler numbers. */ +.tl-grid { + position: absolute; inset: 0; z-index: 1; pointer-events: none; background-image: - repeating-linear-gradient(90deg, - var(--grid-5) 0 1px, transparent 1px var(--tick, 10%)); + repeating-linear-gradient(90deg, var(--grid-5) 0 1px, transparent 1px var(--tick, 10%)), + repeating-linear-gradient(90deg, rgba(0, 0, 0, .07) 0 1px, transparent 1px var(--fine)); +} +.tl-grid.coarse { + background-image: + repeating-linear-gradient(90deg, var(--grid-5) 0 1px, transparent 1px var(--tick, 10%)); } .tl-label, @@ -1180,6 +1189,12 @@ button.share-button:hover, button.share-button.on { filter: brightness(1.1); } .tl-ruler { cursor: pointer; user-select: none; + /* The fine grid's ticks along its foot, so the frames under the numbers can + be counted too. */ + background-image: repeating-linear-gradient(90deg, var(--line) 0 1px, transparent 1px var(--fine)); + background-size: 100% 4px; + background-position: bottom; + background-repeat: no-repeat; } .tl-ruler .tick { @@ -1315,27 +1330,39 @@ button.share-button:hover, button.share-button.on { filter: brightness(1.1); } pointer-events: none; } +/* THE PLAYHEAD IS THE FRAME, a cell wide: tinted over the tracks, with its line + on the frame's left edge, where its time begins and where the ruler's number + sits. A frame too narrow to tint is the line alone. */ .tl-playhead { position: absolute; top: 0; bottom: 0; - width: 1px; - background: var(--playhead); + min-width: 1px; + box-sizing: border-box; + border-left: 1px solid var(--playhead); + background: color-mix(in srgb, var(--playhead) 13%, transparent); pointer-events: none; z-index: 3; } +.tl-tracks.narrow .tl-playhead { background: none; } -/* The playhead's head, in the ruler rather than on the line, so it stays at the - top with the ruler while the rows scroll. */ +/* Its head, on the same cell in the ruler and carrying the frame number, so + where you are is read where you are looking. In the ruler rather than on the + line, so it stays at the top while the rows scroll. */ .tl-knob { position: absolute; + top: 0; + bottom: 0; + z-index: 1; + min-width: 16px; + box-sizing: border-box; + padding: 0 3px; pointer-events: none; - margin-left: -4px; - top: 1px; - width: 9px; - height: 9px; - border-radius: 50%; background: var(--playhead); + color: #fff; + font-size: 10px; + line-height: var(--ruler); + font-variant-numeric: tabular-nums; } .tl-empty { padding: 9px; color: var(--dim); } From 285a195fee397144ece3139ece647e915bc8f9f5 Mon Sep 17 00:00:00 2001 From: Olive Vaughn Date: Sat, 10 Oct 2026 20:38:41 -0400 Subject: [PATCH 13/16] The playhead's head is as wide as its number Co-Authored-By: Claude Opus 5.5 --- frontend/src/arthur/ui/timeline.cljs | 8 +++++--- static/arthur/app.css | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/frontend/src/arthur/ui/timeline.cljs b/frontend/src/arthur/ui/timeline.cljs index ef29c74..93e5af4 100644 --- a/frontend/src/arthur/ui/timeline.cljs +++ b/frontend/src/arthur/ui/timeline.cljs @@ -1316,9 +1316,11 @@ to move two elements' `left`. That cost more than painting the frame did and starved the rAF loop painting it, which ran at 16fps against a 60fps ceiling." [tag frames] - (let [f @(rf/subscribe [::render/open-frame])] - [tag {:style {:left (edge% f frames) :width (edge% 1 frames)}} - (when (= tag :div.tl-knob) f)])) + (let [f @(rf/subscribe [::render/open-frame]) + head? (= tag :div.tl-knob)] + ;; The head is as wide as its number needs and never narrower than the frame. + [tag {:style {:left (edge% f frames) (if head? :min-width :width) (edge% 1 frames)}} + (when head? f)])) (defn- outside-marks "The frames playback leaves out, shaded, and the span it plays, banded on the diff --git a/static/arthur/app.css b/static/arthur/app.css index bb016f1..d3363bb 100644 --- a/static/arthur/app.css +++ b/static/arthur/app.css @@ -1354,9 +1354,9 @@ button.share-button:hover, button.share-button.on { filter: brightness(1.1); } top: 0; bottom: 0; z-index: 1; - min-width: 16px; box-sizing: border-box; padding: 0 3px; + white-space: nowrap; pointer-events: none; background: var(--playhead); color: #fff; From af0df98a15d7f198027e791dba80249cd941e7ad Mon Sep 17 00:00:00 2001 From: Olive Vaughn Date: Sat, 10 Oct 2026 20:38:41 -0400 Subject: [PATCH 14/16] N makes a symbol, shift-N a lane, alt for the top of the tab; alt-T traces N and shift-N make a symbol or a lane where the selection says, as the timeline's buttons do; with alt, at the top of the tab whatever is selected. A new symbol in a lane is a new drawing, so there N is shift-K: one meaning for a new empty thing in a lane. Alt-T switches tracing, beside alt-O for onion skin. Co-Authored-By: Claude Opus 5.5 --- frontend/src/arthur/events/ui.cljs | 28 ++++++++++++++++++++++----- frontend/src/arthur/ui/shortcuts.cljs | 8 ++++++++ 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/frontend/src/arthur/events/ui.cljs b/frontend/src/arthur/events/ui.cljs index 551c2ad..5cf25d7 100644 --- a/frontend/src/arthur/events/ui.cljs +++ b/frontend/src/arthur/events/ui.cljs @@ -394,10 +394,11 @@ (rf/reg-event-fx ::drawing-here ;; K and ⇧K in a lane: see `span/drawing-at`. The new cel is selected and the - ;; playhead put on it, because it is there to be drawn in. - (fn [{:keys [db]} [_ copy?]] + ;; playhead put on it, because it is there to be drawn in. `lane` is + ;; `lane-here`'s answer unless the caller has already chosen one. + (fn [{:keys [db]} [_ copy? lane]] (let [clip (:clip (store/entry (:clip/current db))) - {:keys [sid frame path time]} (lane-here db) + {:keys [sid frame path time]} (or lane (lane-here db)) id (random-uuid) result (if sid (span/drawing-at clip sid frame id (clip/fresh-id clip) @@ -971,10 +972,27 @@ (rf/reg-event-db ::new-lane - (fn [db _] + (fn [db [_ where]] ;; A lane is an explicit persistent row across the effective target symbol. ;; The playhead validates that nested target; the row itself begins at zero. - (create-container db :inside true))) + (create-container db (or where :inside) true))) + +(rf/reg-event-fx + ::new + ;; N and its variants: a new symbol or lane where the selection says, or at + ;; the top of the tab (`:top`). + ;; + ;; A NEW SYMBOL IN A LANE IS A NEW DRAWING, so there it is ⇧K — one meaning + ;; for "a new empty thing in a lane", rather than two that differ in how + ;; much of the hold they take. A lane made in a lane is still a lane. + (fn [{:keys [db]} [_ where lane?]] + (let [{document :clip st :store} (store/entry (:clip/current db)) + into (creation/target document st (get-in db [:ui :open]) + (when-not (= :top where) (get-in db [:ui :selection])) + (editing-frame db document))] + (if (and (not lane?) (= :lane (:kind into))) + {:fx [[:dispatch [::drawing-here false into]]]} + {:db (create-container db where lane?)})))) ;; --------------------------------------------------------------------------- ;; a drop in flight diff --git a/frontend/src/arthur/ui/shortcuts.cljs b/frontend/src/arthur/ui/shortcuts.cljs index f6496ad..59d5c18 100644 --- a/frontend/src/arthur/ui/shortcuts.cljs +++ b/frontend/src/arthur/ui/shortcuts.cljs @@ -68,6 +68,8 @@ :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 "Tracing" :keys ["alt+t"] + :run #(vector ::ui/tracing-on (not (get-in % [:ui :tracing :on?])))} {: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?)])}]] @@ -80,6 +82,12 @@ :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])}]] + ["Make" + [{:label "New symbol" :keys ["n"] :run (constantly [::ui/new :inside false]) + :note "in the selected symbol; in a lane, a blank drawing"} + {:label "New lane" :keys ["shift+n"] :run (constantly [::ui/new :inside true])} + {:label "New symbol at the top of the tab" :keys ["alt+n"] :run (constantly [::ui/new :top false])} + {:label "New lane at the top of the tab" :keys ["alt+shift+n"] :run (constantly [::ui/new :top true])}]] ["Draw" [{:label "Select" :keys ["v"] :run (constantly [::ui/tool-key "v"])} {:label "Pen" :keys ["p"] :run (constantly [::ui/tool-key "p"])} From ea2becf4c7ed4a41b0de45921f3bf1f72487b8df Mon Sep 17 00:00:00 2001 From: Olive Vaughn Date: Sat, 10 Oct 2026 20:43:41 -0400 Subject: [PATCH 15/16] Plain letters, shift for a companion, never alt T switches tracing and G onion skin (ghosts); shift-I and shift-O clear the in and out marks; M and shift-M make a symbol or a lane at the top of the tab. Alt types characters on a Mac and belongs to the browser elsewhere, so no key uses it now, and shift only ever pairs with the plain key it modifies. Co-Authored-By: Claude Opus 5.5 --- frontend/src/arthur/events/playback.cljs | 8 ++++++-- frontend/src/arthur/ui/shortcuts.cljs | 19 ++++++++++++------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/frontend/src/arthur/events/playback.cljs b/frontend/src/arthur/events/playback.cljs index 59395f7..d96a40f 100644 --- a/frontend/src/arthur/events/playback.cljs +++ b/frontend/src/arthur/events/playback.cljs @@ -135,8 +135,12 @@ :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])))) + ::clear-mark + ;; ⇧I and ⇧O. With neither mark left, the tab plays as it did before marks. + (fn [db [_ which]] + (let [path [:playback :range (get-in db [:ui :open])] + marks (dissoc (get-in db path) which)] + (if (seq marks) (assoc-in db path marks) (update-in db (pop path) dissoc (peek path)))))) (rf/reg-event-fx ::set-rate diff --git a/frontend/src/arthur/ui/shortcuts.cljs b/frontend/src/arthur/ui/shortcuts.cljs index 59d5c18..e3fbb5c 100644 --- a/frontend/src/arthur/ui/shortcuts.cljs +++ b/frontend/src/arthur/ui/shortcuts.cljs @@ -16,7 +16,11 @@ THE KEYS ARE BLENDER'S, then Resolve's, then Flash's and Harmony's. WASD repeats the arrows for a hand that stays on the left of the keyboard while the other holds the pen. Letters are matched by where they are on the keyboard, not by what they - type, so WASD is WASD on any layout and ⌥O is O on a Mac too." + type, so WASD is WASD on any layout. + + SHIFT IS THE ONE MODIFIER, and ⌘ only where the browser's own convention is + (undo, the clipboard). Alt types characters on a Mac and is the browser's + elsewhere, so nothing here uses it — a key with it passes through untouched." (:require [arthur.events.history :as history] [arthur.events.playback :as pb] [arthur.events.ui :as ui] @@ -67,10 +71,11 @@ {: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 "Tracing" :keys ["alt+t"] + {:label "Clear in" :keys ["shift+i"] :run (constantly [::pb/clear-mark :in])} + {:label "Clear out" :keys ["shift+o"] :run (constantly [::pb/clear-mark :out])} + {:label "Tracing" :keys ["t"] :run #(vector ::ui/tracing-on (not (get-in % [:ui :tracing :on?])))} - {:label "Onion skin" :keys ["alt+o"] + {:label "Onion skin" :keys ["g"] :note "ghosts" :run #(let [on? (get-in % [:ui :onion (:clip/current %) (get-in % [:ui :open]) :on?])] [::layout/onion :on? (not on?)])}]] ["Animate" @@ -86,8 +91,8 @@ [{:label "New symbol" :keys ["n"] :run (constantly [::ui/new :inside false]) :note "in the selected symbol; in a lane, a blank drawing"} {:label "New lane" :keys ["shift+n"] :run (constantly [::ui/new :inside true])} - {:label "New symbol at the top of the tab" :keys ["alt+n"] :run (constantly [::ui/new :top false])} - {:label "New lane at the top of the tab" :keys ["alt+shift+n"] :run (constantly [::ui/new :top true])}]] + {:label "New symbol at the top of the tab" :keys ["m"] :run (constantly [::ui/new :top false])} + {:label "New lane at the top of the tab" :keys ["shift+m"] :run (constantly [::ui/new :top true])}]] ["Draw" [{:label "Select" :keys ["v"] :run (constantly [::ui/tool-key "v"])} {:label "Pen" :keys ["p"] :run (constantly [::ui/tool-key "p"])} @@ -174,7 +179,7 @@ (.addEventListener js/window "blur" #(reset! space nil))) (def ^:private glyphs - {"mod" "⌘" "alt" "⌥" "shift" "⇧" "ArrowLeft" "←" "ArrowRight" "→" + {"mod" "⌘" "shift" "⇧" "ArrowLeft" "←" "ArrowRight" "→" "ArrowUp" "↑" "ArrowDown" "↓" "Backspace" "⌫" "Escape" "Esc"}) (defn- spell [k] From 4fe620f50a05f6263add1305a7a1c5a34907fac7 Mon Sep 17 00:00:00 2001 From: Olive Vaughn Date: Sat, 10 Oct 2026 20:50:47 -0400 Subject: [PATCH 16/16] Shift-T traces the selection only MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tracing on for the tracing layers in the selection — the selected node, what it places at any depth, its children, a face's own footage — and every other layer off. Again, and every layer shows. Co-Authored-By: Claude Opus 5.5 --- frontend/src/arthur/events/ui.cljs | 33 ++++ frontend/src/arthur/ui/params.cljs | 145 ++++++++++-------- frontend/src/arthur/ui/shortcuts.cljs | 2 + frontend/test/arthur/events/tracing_test.cljs | 38 +++++ 4 files changed, 155 insertions(+), 63 deletions(-) create mode 100644 frontend/test/arthur/events/tracing_test.cljs diff --git a/frontend/src/arthur/events/ui.cljs b/frontend/src/arthur/events/ui.cljs index 5cf25d7..9815690 100644 --- a/frontend/src/arthur/events/ui.cljs +++ b/frontend/src/arthur/events/ui.cljs @@ -477,6 +477,39 @@ #(cond-> (update % :hidden (fnil (if on? disj conj) #{}) layer) on? (assoc :on? true))))) +(defn- trace-layers + "The tracing layers in symbol `sid` and everything it places, as + `arthur.db/tracing` names them: a placement of a tracing symbol is + `[sid id]`, a face's footage `[face :plate]`. Only nodes `keep?` says yes to + are looked in at the top; below that, everything is." + [clip sid keep?] + (let [nodes (:nodes (clip/symbol clip sid))] + (into (if (get nodes :plate) #{[sid :plate]} #{}) + (mapcat (fn [[id n]] + (when (keep? id) + (let [src (node/source n)] + (cond (and src (clip/trace? (clip/symbol clip src))) [[sid id]] + src (trace-layers clip src (constantly true))))))) + nodes))) + +(rf/reg-event-db + ::trace-selection + ;; ⇧T: tracing on for what is in the selection only — the selected node, what + ;; it places, its children — and every other layer off. Again, all of them. + (fn [db _] + (let [clip (:clip (store/entry (:clip/current db))) + [kind sid id] (get-in db [:ui :selection]) + nodes (:nodes (clip/symbol clip sid)) + mine (if (and (= :node kind) id) + (trace-layers clip sid #(some #{id} (symbol/lineage nodes %))) + #{}) + every (into #{} (mapcat #(trace-layers clip % (constantly true))) (keys (:symbols clip))) + solo (assoc (get-in db [:ui :tracing]) :on? true :hidden (reduce disj every mine))] + (cond + (empty? mine) (assoc-in db [:project :status] "no tracing in the selection") + (= solo (get-in db [:ui :tracing])) (assoc-in db [:ui :tracing :hidden] #{}) + :else (assoc-in db [:ui :tracing] solo))))) + (rf/reg-event-db ::tracing-on ;; Every tracing layer at once, from the bar above the stage. diff --git a/frontend/src/arthur/ui/params.cljs b/frontend/src/arthur/ui/params.cljs index 569abde..0747888 100644 --- a/frontend/src/arthur/ui/params.cljs +++ b/frontend/src/arthur/ui/params.cljs @@ -715,7 +715,7 @@ (when (and face-fps fps) [:div.prop {:style {:margin-top "6px"} :title "roto drawn a frame or two ahead of the sound reads as in sync"} - [:span.prop-name "lead"] + [:span.prop-name {:style {:flex "none"}} "mouth lead"] [number-input {:step 0.5 :aria-label "lead in frames" :value (/ (js/Math.round (* 10 offset (/ fps face-fps))) 10) :parse js/parseFloat @@ -723,68 +723,87 @@ (js/Math.round (* % (/ face-fps fps)))])}] [:span.dim (str "f · " (js/Math.round (/ (* 1000 offset) face-fps)) "ms")]]))) -(defn- tracking-section [all] - (let [clip @(rf/subscribe [::render/clip]) - selection @(rf/subscribe [::sub/selection]) - knobs @(rf/subscribe [::sub/knobs]) - busy? (:busy? @(rf/subscribe [::playback/project])) - report @(rf/subscribe [::project/regeneration]) - [scope id :as owner] (if (some #{selection} all) selection (first all)) - area (case scope - :subject :subject - :feature (get-in clip [:features id :area]) - :group :eye - nil) - values (case scope - :subject (merge (params/for-area :subject) - (get-in clip [:subjects id :params])) - :feature (when id (feature/effective-params clip id)) - :group (merge (params/for-area :eye) - (get-in clip [:groups id :params])) - nil)] - [section "tracking" - ;; The option VALUE is the INDEX, not the owner. A `[scope id]` pair written - ;; into the DOM comes back as a string that has to be parsed back into a - ;; keyword pair, and `subs`/`keyword` on a namespaced id loses its namespace - ;; — the same trap `events/export/target-value` exists to avoid. An index - ;; into a vector both ends agree on cannot be misread. - [:select {:value (or (first (keep-indexed #(when (= %2 owner) %1) all)) 0) - :on-change #(rf/dispatch - [::ui/select (nth all (js/parseInt (.. % -target -value) 10))])} - (doall - (for [[i [kind object-id]] (map-indexed vector all)] - ^{:key i} - [:option {:value i} (str (name kind) " · " (subs (str object-id) 1))]))] - (when (= :mouth area) [lead-row clip id]) - (when area - [:div {:style {:margin-top "6px"}} - (doall - (for [[knob spec] (sort-by (comp str key) params/definitions) - :when (= area (:area spec))] - (let [k (get knobs [scope id knob] (get values knob)) - {:keys [min max step]} (bounds knob spec)] - ^{:key knob} - [:label.knob - [:span.top-line [:span.name (name knob)] [:span (str k)]] - [:input {:type "range" :min min :max max :step step :value k - :disabled busy? - :on-change - (fn [^js event] - (let [s (.. event -target -value) - v (if (= :integer (:type spec)) - (js/parseInt s 10) - (js/parseFloat s))] - (rf/dispatch [::ui/set-knob scope id knob v]) - (rf/dispatch [::project/preview-settings - {:scope scope :id id :knob knob :value v}])))}]])))]) - (when report - ;; `regeneration-debug` is a hook rather than a style: `test/browser` reads - ;; this line to assert which feature a knob dirtied and which tier it - ;; reached, and that is the one thing on the page that says so. - [:div.dim.regeneration-debug {:style {:margin-top "6px"}} - (str "dirty: " (pr-str (:features report)) - " · blocks: " (if (seq (:roles report)) - (pr-str (sort (:roles report))) "tier 1 only"))])])) +(defn- tracking-section + "The generated settings of one of `all`, the tracked objects in view. + + WHICH ONE IS SHOWN IS NOT THE SELECTION. The dropdown used to select the + object it picked, which deselected the placement every other section of the + inspector is about, so the inspector emptied under the person using it. The + pick is kept here instead, `[selection owner]`, and only for as long as the + selection it was made under: select something else and the section follows." + [_] + (let [shown (r/atom nil)] + (fn [all] + (let [clip @(rf/subscribe [::render/clip]) + selection @(rf/subscribe [::sub/selection]) + knobs @(rf/subscribe [::sub/knobs]) + busy? (:busy? @(rf/subscribe [::playback/project])) + report @(rf/subscribe [::project/regeneration]) + [under picked] @shown + [scope id :as owner] (cond + (and (= under selection) (some #{picked} all)) picked + (some #{selection} all) selection + :else (first all)) + ;; The face's mouth, whose lead is shown with its face and with itself. + mouth (case scope + :subject (let [m (feature/owned id :mouth)] + (when (get-in clip [:features m]) m)) + :feature (when (= :mouth (get-in clip [:features id :area])) id) + nil) + area (case scope + :subject :subject + :feature (get-in clip [:features id :area]) + :group :eye + nil) + values (case scope + :subject (merge (params/for-area :subject) + (get-in clip [:subjects id :params])) + :feature (when id (feature/effective-params clip id)) + :group (merge (params/for-area :eye) + (get-in clip [:groups id :params])) + nil)] + [section "tracking" + ;; The option VALUE is the INDEX, not the owner. A `[scope id]` pair written + ;; into the DOM comes back as a string that has to be parsed back into a + ;; keyword pair, and `subs`/`keyword` on a namespaced id loses its namespace + ;; — the same trap `events/export/target-value` exists to avoid. An index + ;; into a vector both ends agree on cannot be misread. + [:select {:value (or (first (keep-indexed #(when (= %2 owner) %1) all)) 0) + :on-change #(reset! shown [selection (nth all (js/parseInt (.. % -target -value) 10))])} + (doall + (for [[i [kind object-id]] (map-indexed vector all)] + ^{:key i} + [:option {:value i} (str (name kind) " · " (subs (str object-id) 1))]))] + (when mouth [lead-row clip mouth]) + (when area + [:div {:style {:margin-top "6px"}} + (doall + (for [[knob spec] (sort-by (comp str key) params/definitions) + :when (= area (:area spec))] + (let [k (get knobs [scope id knob] (get values knob)) + {:keys [min max step]} (bounds knob spec)] + ^{:key knob} + [:label.knob + [:span.top-line [:span.name (name knob)] [:span (str k)]] + [:input {:type "range" :min min :max max :step step :value k + :disabled busy? + :on-change + (fn [^js event] + (let [s (.. event -target -value) + v (if (= :integer (:type spec)) + (js/parseInt s 10) + (js/parseFloat s))] + (rf/dispatch [::ui/set-knob scope id knob v]) + (rf/dispatch [::project/preview-settings + {:scope scope :id id :knob knob :value v}])))}]])))]) + (when report + ;; `regeneration-debug` is a hook rather than a style: `test/browser` reads + ;; this line to assert which feature a knob dirtied and which tier it + ;; reached, and that is the one thing on the page that says so. + [:div.dim.regeneration-debug {:style {:margin-top "6px"}} + (str "dirty: " (pr-str (:features report)) + " · blocks: " (if (seq (:roles report)) + (pr-str (sort (:roles report))) "tier 1 only"))])])))) ;; --------------------------------------------------------------------------- diff --git a/frontend/src/arthur/ui/shortcuts.cljs b/frontend/src/arthur/ui/shortcuts.cljs index e3fbb5c..8b9045d 100644 --- a/frontend/src/arthur/ui/shortcuts.cljs +++ b/frontend/src/arthur/ui/shortcuts.cljs @@ -75,6 +75,8 @@ {:label "Clear out" :keys ["shift+o"] :run (constantly [::pb/clear-mark :out])} {:label "Tracing" :keys ["t"] :run #(vector ::ui/tracing-on (not (get-in % [:ui :tracing :on?])))} + {:label "Tracing for the selection only" :keys ["shift+t"] + :run (constantly [::ui/trace-selection])} {:label "Onion skin" :keys ["g"] :note "ghosts" :run #(let [on? (get-in % [:ui :onion (:clip/current %) (get-in % [:ui :open]) :on?])] [::layout/onion :on? (not on?)])}]] diff --git a/frontend/test/arthur/events/tracing_test.cljs b/frontend/test/arthur/events/tracing_test.cljs new file mode 100644 index 0000000..10c14f4 --- /dev/null +++ b/frontend/test/arthur/events/tracing_test.cljs @@ -0,0 +1,38 @@ +(ns arthur.events.tracing-test + (:require [cljs.test :refer [deftest is]] + [arthur.events.ui :as ui] + [arthur.footage.store :as store] + [re-frame.core :as rf] + [re-frame.db :as rf-db])) + +(defn- placed [id src] {:id id :kind :instance :z (name id) :source {:symbol src}}) + +(def document + ;; Two references side by side, and a face traced from footage of its own. + {:fps 12 :width 320 :height 200 + :symbols {:main {:id :main :frames 12 + :nodes {:a (placed :a :ref) :c (placed :c :ref) :b (placed :b :face)}} + :ref {:id :ref :frames 12 :type :trace :nodes {}} + :face {:id :face :frames 12 + :nodes {:plate {:id :plate :kind :rect :z "a"} + :mouth {:id :mouth :kind :rect :z "b"}}}}}) + +(defn- shift-t [selection tracing] + (let [id (store/install! {:clip document :store {}} "trace-selection")] + (reset! rf-db/app-db {:clip/current id :ui {:open :main :selection selection :tracing tracing}}) + (rf/dispatch-sync [::ui/trace-selection]) + (get-in @rf-db/app-db [:ui :tracing]))) + +(deftest shift-t-traces-the-selection-only + (is (= {:on? true :opacity 0.5 :hidden #{[:main :c] [:face :plate]}} + (shift-t [:node :main :a [:a]] {:on? false :opacity 0.5 :hidden #{}})) + "one reference: the other and the face's footage go") + (is (= #{[:main :a] [:main :c]} + (:hidden (shift-t [:node :main :b [:b]] {:on? false :opacity 0.5 :hidden #{}}))) + "the face: its own footage, wherever it is placed") + (is (= #{} (:hidden (shift-t [:node :main :a [:a]] + {:on? true :opacity 0.5 :hidden #{[:main :c] [:face :plate]}}))) + "again, and every layer is back") + (is (= {:on? false :opacity 0.5 :hidden #{}} + (shift-t nil {:on? false :opacity 0.5 :hidden #{}})) + "nothing selected changes nothing"))