Shift-T traces the selection only

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 <noreply@anthropic.com>
This commit is contained in:
Olive Vaughn 2026-10-10 20:50:47 -04:00
parent ea2becf4c7
commit 4fe620f50a
4 changed files with 155 additions and 63 deletions

View file

@ -477,6 +477,39 @@
#(cond-> (update % :hidden (fnil (if on? disj conj) #{}) layer) #(cond-> (update % :hidden (fnil (if on? disj conj) #{}) layer)
on? (assoc :on? true))))) 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 (rf/reg-event-db
::tracing-on ::tracing-on
;; Every tracing layer at once, from the bar above the stage. ;; Every tracing layer at once, from the bar above the stage.

View file

@ -715,7 +715,7 @@
(when (and face-fps fps) (when (and face-fps fps)
[:div.prop {:style {:margin-top "6px"} [:div.prop {:style {:margin-top "6px"}
:title "roto drawn a frame or two ahead of the sound reads as in sync"} :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" [number-input {:step 0.5 :aria-label "lead in frames"
:value (/ (js/Math.round (* 10 offset (/ fps face-fps))) 10) :value (/ (js/Math.round (* 10 offset (/ fps face-fps))) 10)
:parse js/parseFloat :parse js/parseFloat
@ -723,68 +723,87 @@
(js/Math.round (* % (/ face-fps fps)))])}] (js/Math.round (* % (/ face-fps fps)))])}]
[:span.dim (str "f · " (js/Math.round (/ (* 1000 offset) face-fps)) "ms")]]))) [:span.dim (str "f · " (js/Math.round (/ (* 1000 offset) face-fps)) "ms")]])))
(defn- tracking-section [all] (defn- tracking-section
(let [clip @(rf/subscribe [::render/clip]) "The generated settings of one of `all`, the tracked objects in view.
selection @(rf/subscribe [::sub/selection])
knobs @(rf/subscribe [::sub/knobs]) WHICH ONE IS SHOWN IS NOT THE SELECTION. The dropdown used to select the
busy? (:busy? @(rf/subscribe [::playback/project])) object it picked, which deselected the placement every other section of the
report @(rf/subscribe [::project/regeneration]) inspector is about, so the inspector emptied under the person using it. The
[scope id :as owner] (if (some #{selection} all) selection (first all)) pick is kept here instead, `[selection owner]`, and only for as long as the
area (case scope selection it was made under: select something else and the section follows."
:subject :subject [_]
:feature (get-in clip [:features id :area]) (let [shown (r/atom nil)]
:group :eye (fn [all]
nil) (let [clip @(rf/subscribe [::render/clip])
values (case scope selection @(rf/subscribe [::sub/selection])
:subject (merge (params/for-area :subject) knobs @(rf/subscribe [::sub/knobs])
(get-in clip [:subjects id :params])) busy? (:busy? @(rf/subscribe [::playback/project]))
:feature (when id (feature/effective-params clip id)) report @(rf/subscribe [::project/regeneration])
:group (merge (params/for-area :eye) [under picked] @shown
(get-in clip [:groups id :params])) [scope id :as owner] (cond
nil)] (and (= under selection) (some #{picked} all)) picked
[section "tracking" (some #{selection} all) selection
;; The option VALUE is the INDEX, not the owner. A `[scope id]` pair written :else (first all))
;; into the DOM comes back as a string that has to be parsed back into a ;; The face's mouth, whose lead is shown with its face and with itself.
;; keyword pair, and `subs`/`keyword` on a namespaced id loses its namespace mouth (case scope
;; — the same trap `events/export/target-value` exists to avoid. An index :subject (let [m (feature/owned id :mouth)]
;; into a vector both ends agree on cannot be misread. (when (get-in clip [:features m]) m))
[:select {:value (or (first (keep-indexed #(when (= %2 owner) %1) all)) 0) :feature (when (= :mouth (get-in clip [:features id :area])) id)
:on-change #(rf/dispatch nil)
[::ui/select (nth all (js/parseInt (.. % -target -value) 10))])} area (case scope
(doall :subject :subject
(for [[i [kind object-id]] (map-indexed vector all)] :feature (get-in clip [:features id :area])
^{:key i} :group :eye
[:option {:value i} (str (name kind) " · " (subs (str object-id) 1))]))] nil)
(when (= :mouth area) [lead-row clip id]) values (case scope
(when area :subject (merge (params/for-area :subject)
[:div {:style {:margin-top "6px"}} (get-in clip [:subjects id :params]))
(doall :feature (when id (feature/effective-params clip id))
(for [[knob spec] (sort-by (comp str key) params/definitions) :group (merge (params/for-area :eye)
:when (= area (:area spec))] (get-in clip [:groups id :params]))
(let [k (get knobs [scope id knob] (get values knob)) nil)]
{:keys [min max step]} (bounds knob spec)] [section "tracking"
^{:key knob} ;; The option VALUE is the INDEX, not the owner. A `[scope id]` pair written
[:label.knob ;; into the DOM comes back as a string that has to be parsed back into a
[:span.top-line [:span.name (name knob)] [:span (str k)]] ;; keyword pair, and `subs`/`keyword` on a namespaced id loses its namespace
[:input {:type "range" :min min :max max :step step :value k ;; — the same trap `events/export/target-value` exists to avoid. An index
:disabled busy? ;; into a vector both ends agree on cannot be misread.
:on-change [:select {:value (or (first (keep-indexed #(when (= %2 owner) %1) all)) 0)
(fn [^js event] :on-change #(reset! shown [selection (nth all (js/parseInt (.. % -target -value) 10))])}
(let [s (.. event -target -value) (doall
v (if (= :integer (:type spec)) (for [[i [kind object-id]] (map-indexed vector all)]
(js/parseInt s 10) ^{:key i}
(js/parseFloat s))] [:option {:value i} (str (name kind) " · " (subs (str object-id) 1))]))]
(rf/dispatch [::ui/set-knob scope id knob v]) (when mouth [lead-row clip mouth])
(rf/dispatch [::project/preview-settings (when area
{:scope scope :id id :knob knob :value v}])))}]])))]) [:div {:style {:margin-top "6px"}}
(when report (doall
;; `regeneration-debug` is a hook rather than a style: `test/browser` reads (for [[knob spec] (sort-by (comp str key) params/definitions)
;; this line to assert which feature a knob dirtied and which tier it :when (= area (:area spec))]
;; reached, and that is the one thing on the page that says so. (let [k (get knobs [scope id knob] (get values knob))
[:div.dim.regeneration-debug {:style {:margin-top "6px"}} {:keys [min max step]} (bounds knob spec)]
(str "dirty: " (pr-str (:features report)) ^{:key knob}
" · blocks: " (if (seq (:roles report)) [:label.knob
(pr-str (sort (:roles report))) "tier 1 only"))])])) [: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"))])]))))
;; --------------------------------------------------------------------------- ;; ---------------------------------------------------------------------------

View file

@ -75,6 +75,8 @@
{:label "Clear out" :keys ["shift+o"] :run (constantly [::pb/clear-mark :out])} {:label "Clear out" :keys ["shift+o"] :run (constantly [::pb/clear-mark :out])}
{:label "Tracing" :keys ["t"] {:label "Tracing" :keys ["t"]
:run #(vector ::ui/tracing-on (not (get-in % [:ui :tracing :on?])))} :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" {:label "Onion skin" :keys ["g"] :note "ghosts"
:run #(let [on? (get-in % [:ui :onion (:clip/current %) (get-in % [:ui :open]) :on?])] :run #(let [on? (get-in % [:ui :onion (:clip/current %) (get-in % [:ui :open]) :on?])]
[::layout/onion :on? (not on?)])}]] [::layout/onion :on? (not on?)])}]]

View file

@ -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"))