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 <noreply@anthropic.com>
This commit is contained in:
parent
e96464459d
commit
246b6d6468
6 changed files with 179 additions and 1 deletions
|
|
@ -210,6 +210,19 @@
|
||||||
(:segments c) (update :segments dissoc f))
|
(:segments c) (update :segments dissoc f))
|
||||||
:else (ch/framed v))))))
|
: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
|
(defn set-segment-interp
|
||||||
"Choose how channel `path`'s key at `left` leads to the next one: `:hold` cuts
|
"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 —
|
there, `:linear` tweens. The same for a drawing's points as for a transform —
|
||||||
|
|
|
||||||
|
|
@ -778,6 +778,51 @@
|
||||||
nodes (assoc nodes id (held id drawing-id at))]
|
nodes (assoc nodes id (held id drawing-id at))]
|
||||||
(claim c sid nodes id extent remainder-id)))))
|
(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
|
(defn make-unique
|
||||||
"Point clip `id` at a private copy of its content, leaving every other
|
"Point clip `id` at a private copy of its content, leaving every other
|
||||||
clip of that drawing sharing the original.
|
clip of that drawing sharing the original.
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@
|
||||||
[arthur.domain.palette :as pal]
|
[arthur.domain.palette :as pal]
|
||||||
[arthur.domain.pick :as pick]
|
[arthur.domain.pick :as pick]
|
||||||
[arthur.domain.span :as span]
|
[arthur.domain.span :as span]
|
||||||
|
[arthur.domain.symbol :as symbol]
|
||||||
[arthur.events.edit :as edit]
|
[arthur.events.edit :as edit]
|
||||||
[arthur.domain.paint :as paint]
|
[arthur.domain.paint :as paint]
|
||||||
[arthur.events.playback :as playback]
|
[arthur.events.playback :as playback]
|
||||||
|
|
@ -362,6 +363,63 @@
|
||||||
result (span/extend-hold clip sid id delta {:extent (or extent :keep)})]
|
result (span/extend-hold clip sid id delta {:extent (or extent :keep)})]
|
||||||
(apply-command db sid result [::extend-hold delta :grow-symbol]))))
|
(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
|
(rf/reg-event-fx
|
||||||
::retry
|
::retry
|
||||||
(fn [{:keys [db]} _]
|
(fn [{:keys [db]} _]
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@
|
||||||
key with two meanings, and they are told apart by the hand rather than by a
|
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.
|
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
|
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
|
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 and ⌥O is O on a Mac too."
|
||||||
|
|
@ -67,6 +67,13 @@
|
||||||
{:label "Onion skin" :keys ["alt+o"]
|
{:label "Onion skin" :keys ["alt+o"]
|
||||||
: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?)])}]]
|
||||||
|
["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"
|
["Draw"
|
||||||
[{:label "Select" :keys ["v"] :run (constantly [::ui/tool-key "v"])}
|
[{:label "Select" :keys ["v"] :run (constantly [::ui/tool-key "v"])}
|
||||||
{:label "Pen" :keys ["p"] :run (constantly [::ui/tool-key "p"])}
|
{:label "Pen" :keys ["p"] :run (constantly [::ui/tool-key "p"])}
|
||||||
|
|
|
||||||
|
|
@ -331,3 +331,17 @@
|
||||||
"editing repairs an older tweened colour channel")
|
"editing repairs an older tweened colour channel")
|
||||||
(is (= :hold (get-in (node/toggle-key n [:style :color] 3 nil)
|
(is (= :hold (get-in (node/toggle-key n [:style :color] 3 nil)
|
||||||
[:channels [:style :color] :interp])))))
|
[: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")))
|
||||||
|
|
|
||||||
|
|
@ -893,3 +893,44 @@
|
||||||
(is (= [0 6] (node/placed-span n)))
|
(is (= [0 6] (node/placed-span n)))
|
||||||
(is (every? #(= {:symbol :blank :frame 0} (node/placed-frame n % 1)) (range 6))
|
(is (every? #(= {:symbol :blank :frame 0} (node/placed-frame n % 1)) (range 6))
|
||||||
"stretched, every frame of it shows the one drawing")))
|
"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")))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue