From 4fe620f50a05f6263add1305a7a1c5a34907fac7 Mon Sep 17 00:00:00 2001 From: Olive Vaughn Date: Sat, 10 Oct 2026 20:50:47 -0400 Subject: [PATCH] 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"))