Make every caller say what it means: no defaulted arities
Pre-alpha. Nothing here is owed a call shape it used to have.
Twelve convenience arities deleted, and the only reason to single any of
them out is that one of them was a live bug: `channel/value-at`'s `([ch f])`
filled in a nil tier-2 store, so a caller could omit it, read correctly for
every channel that happened not to be dense, and throw the first time one
was. That is the iris crash, and threading the store through `gesture/values`
last commit fixed the symptom while leaving the trapdoor open. Deleting the
arity found `node/toggle-key` standing on it too — the inspector's stopwatch
on a measured channel, the same throw, never reported.
Gone, and what the compiler then made explicit at each site:
channel/value-at, cursor, dense-at the store, and `nil` where a caller
genuinely has none and means it
channel/keyed `:hold`, which is a cut rather than a
tween and not a thing to leave implied
symbol/resolver (4), eval-frame (3) store, palette, pose-tracks, opts
clip/resolver opts
mix/buffer!, store/install! dead: no caller used the short form
`pick/local-bounds` goes the same way — it was `bounds-of` with the closure
thrown away, so callers build the closure and call it.
Every site was found by shadow-cljs `:fn-arity` rather than by grep, which is
the argument for the change: 90-odd call sites, and the compiler listed all of
them. BUILD BOTH TARGETS — the last three only appear in `:app`, since `:test`
compiles what the tests reach and the inspector, the pool drag and the vertex
overlay are not that.
Left alone, because an argument with a default is not the same thing as a
shim: genuine optionality like `fx/http`'s body, `geom`'s iteration count,
`zip`'s injected clock.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
11093079de
commit
ee66680a0c
30 changed files with 224 additions and 217 deletions
|
|
@ -147,14 +147,13 @@
|
|||
The raw product. `mix!` packages it as a WAV URL for the transport and
|
||||
`export/frames` packages it as WAV bytes in an archive; a muxer would take it as
|
||||
it is, which is why this is the function the others are written in terms of."
|
||||
([document sid] (buffer! document sid nil))
|
||||
([document sid store]
|
||||
(let [tracks (tracks-of document sid)]
|
||||
(if (empty? tracks)
|
||||
(js/Promise.resolve nil)
|
||||
(-> (js/Promise.all
|
||||
(into-array (map source! (distinct (map :source tracks)))))
|
||||
(.then (fn [pairs] (render! document sid (into {} (array-seq pairs)) store))))))))
|
||||
[document sid store]
|
||||
(let [tracks (tracks-of document sid)]
|
||||
(if (empty? tracks)
|
||||
(js/Promise.resolve nil)
|
||||
(-> (js/Promise.all
|
||||
(into-array (map source! (distinct (map :source tracks)))))
|
||||
(.then (fn [pairs] (render! document sid (into {} (array-seq pairs)) store)))))))
|
||||
|
||||
(defn decode!
|
||||
"Promise of the `AudioBuffer` behind a URL. What a clip whose audio is a plain
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
validates would not be the one that renders, and the model would be validated
|
||||
against a scene nobody ever looked at."
|
||||
(:require [arthur.domain.clip :as domain-clip]
|
||||
[arthur.domain.palette :as pal]
|
||||
[arthur.domain.symbol :as symbol]
|
||||
[cljs.reader :as reader]
|
||||
[shadow.resource :as rc]))
|
||||
|
|
@ -25,4 +26,4 @@
|
|||
"Draw ops for one frame, via the specification path. The page uses
|
||||
`symbol/resolver` instead; this is here for the REPL."
|
||||
[f]
|
||||
(symbol/eval-frame main f))
|
||||
(symbol/eval-frame main f nil pal/index-of nil nil))
|
||||
|
|
|
|||
|
|
@ -68,8 +68,11 @@
|
|||
(defn framed [v] {:animated? false :value v})
|
||||
|
||||
(defn keyed
|
||||
([ks] (keyed ks :hold))
|
||||
([ks interp] {:animated? true :interp interp :keys ks :over []}))
|
||||
"A channel of keys, and how each one leads to the next. `interp` is an
|
||||
argument, never a default: `:hold` and `:linear` are the difference between a
|
||||
cut and a tween, which is the whole content of the channel."
|
||||
[ks interp]
|
||||
{:animated? true :interp interp :keys ks :over []})
|
||||
|
||||
;; ---------------------------------------------------------------------------
|
||||
|
||||
|
|
@ -147,9 +150,9 @@
|
|||
Decoding costs the view. `out` is a stride-sized destination the caller owns —
|
||||
`cursor` allocates one per channel — because a copy per node per frame is the
|
||||
allocation this whole model is arranged to avoid; passing nil allocates, which
|
||||
is what `value-at`, the specification, does."
|
||||
([blk f st] (dense-at blk f st nil))
|
||||
([{:keys [store offset stride scale] nf :frames} f st out]
|
||||
is what `value-at`, the specification, does — and it says so by passing nil,
|
||||
because there is no arity here that decides it for a caller."
|
||||
[{:keys [store offset stride scale] nf :frames} f st out]
|
||||
(let [{:keys [data state]} (get st store)]
|
||||
(when (nil? data)
|
||||
(throw (ex-info "dense channel's store key is not in the store"
|
||||
|
|
@ -164,7 +167,7 @@
|
|||
:else (let [dst (or out (js/Float64Array. stride))]
|
||||
(dotimes [k stride]
|
||||
(aset dst k (/ (aget data (+ o k)) scale)))
|
||||
dst))))))))
|
||||
dst)))))))
|
||||
|
||||
;; ---------------------------------------------------------------------------
|
||||
;; the specification
|
||||
|
|
@ -201,17 +204,23 @@
|
|||
|
||||
(defn value-at
|
||||
"Sample a channel at frame f. THE SPECIFICATION — correct, allocating, and
|
||||
O(n) in the keys. `cursor`/`sample!` is what playback uses."
|
||||
([ch f] (value-at ch f nil))
|
||||
([ch f store]
|
||||
(check-unimplemented! ch)
|
||||
(cond
|
||||
(not (:animated? ch)) (:value ch)
|
||||
(:dense ch) (dense-at (:dense ch) f store)
|
||||
(:keys ch) (let [ks (:keys ch)]
|
||||
(if (empty? ks) absent (keyed-at ch f)))
|
||||
:else
|
||||
(throw (ex-info "animated channel has neither :keys nor :dense" {:channel ch})))))
|
||||
O(n) in the keys. `cursor`/`sample!` is what playback uses.
|
||||
|
||||
`store` IS AN ARGUMENT, NEVER A DEFAULT. A dense channel cannot be read
|
||||
without the tier-2 store it names, and an arity that filled in nil let a
|
||||
caller omit it, read correctly for every channel that happened not to be
|
||||
dense, and throw the first time a selection landed on one that was. That is
|
||||
how `gesture/values` took the stage down on an iris. A caller with no store
|
||||
says `nil` and means it."
|
||||
[ch f store]
|
||||
(check-unimplemented! ch)
|
||||
(cond
|
||||
(not (:animated? ch)) (:value ch)
|
||||
(:dense ch) (dense-at (:dense ch) f store nil)
|
||||
(:keys ch) (let [ks (:keys ch)]
|
||||
(if (empty? ks) absent (keyed-at ch f)))
|
||||
:else
|
||||
(throw (ex-info "animated channel has neither :keys nor :dense" {:channel ch}))))
|
||||
|
||||
;; ---------------------------------------------------------------------------
|
||||
;; the playback path
|
||||
|
|
@ -244,17 +253,18 @@
|
|||
needs, for the same reason the resolver owns one point buffer per node.
|
||||
|
||||
Only a wide fixed-point block gets a buffer: a stride-1 block decodes to a
|
||||
number and a block with no `:scale` is handed back as a view."
|
||||
([ch] (cursor ch nil))
|
||||
([ch store]
|
||||
(check-unimplemented! ch)
|
||||
(let [d (:dense ch)]
|
||||
(->Cursor ch
|
||||
(when (and (:animated? ch) (not d) (seq (:keys ch))) (frames ch))
|
||||
store
|
||||
(when (and d (:scale d) (> (:stride d) 1))
|
||||
(js/Float64Array. (:stride d)))
|
||||
0))))
|
||||
number and a block with no `:scale` is handed back as a view.
|
||||
|
||||
`store` is an argument for the reason it is one on `value-at`."
|
||||
[ch store]
|
||||
(check-unimplemented! ch)
|
||||
(let [d (:dense ch)]
|
||||
(->Cursor ch
|
||||
(when (and (:animated? ch) (not d) (seq (:keys ch))) (frames ch))
|
||||
store
|
||||
(when (and d (:scale d) (> (:stride d) 1))
|
||||
(js/Float64Array. (:stride d)))
|
||||
0)))
|
||||
|
||||
(defn sample!
|
||||
"Value of the cursor's channel at f. O(1) when f is at or one key past where
|
||||
|
|
|
|||
|
|
@ -174,8 +174,7 @@
|
|||
own frame. Nil for a node that was not on that frame. It is how something
|
||||
drawn beside the picture, like a tracing photo, rides a node inside it without
|
||||
resolving anything a second time."
|
||||
([clip store palette sid] (resolver clip store palette sid nil))
|
||||
([clip store palette sid {:keys [picture-fps] :as opts}]
|
||||
[clip store palette sid {:keys [picture-fps] :as opts}]
|
||||
(letfn [(build [sid chain pose-tracks]
|
||||
(when (some #{sid} chain)
|
||||
(throw (ex-info "symbol cycle" {:chain (conj chain sid)})))
|
||||
|
|
@ -230,7 +229,7 @@
|
|||
(when (contains? @entered id)
|
||||
(symbol/frame-of (get children id) (vec more)))
|
||||
(symbol/frame-of own id))))))]
|
||||
(build sid [] nil))))
|
||||
(build sid [] nil)))
|
||||
|
||||
(defn center
|
||||
"The middle of everything symbol `sid` draws, over all its frames, in its own
|
||||
|
|
@ -244,7 +243,7 @@
|
|||
Effects' anchor point are set once and left. A symbol that grows later keeps
|
||||
its instances' pivots where they were, so nothing on screen moves."
|
||||
[clip store sid]
|
||||
(let [resolve (resolver clip store pal/index-of sid)
|
||||
(let [resolve (resolver clip store pal/index-of sid nil)
|
||||
bounds (fn [[x0 y0 x1 y1 :as b] x y]
|
||||
(if b [(min x0 x) (min y0 y) (max x1 x) (max y1 y)] [x y x y]))
|
||||
[x0 y0 x1 y1]
|
||||
|
|
|
|||
|
|
@ -107,10 +107,13 @@
|
|||
(defn toggle-key
|
||||
"Key channel `path` on the node's own frame `f` with the value it has there, or
|
||||
take the key there off. The first key starts the channel animating and taking
|
||||
the last one off leaves it that one value. A boolean holds; anything else tweens."
|
||||
[n path f]
|
||||
the last one off leaves it that one value. A boolean holds; anything else tweens.
|
||||
|
||||
`store` because the value it keys is read out of the channel, and a measured
|
||||
channel's values live in tier 2."
|
||||
[n path f store]
|
||||
(let [c (get (channels n) path)
|
||||
v (ch/value-at c f)
|
||||
v (ch/value-at c f store)
|
||||
ks (dissoc (:keys c) f)]
|
||||
(assoc-in n [:channels path]
|
||||
(cond
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@
|
|||
{:id id :name (str "shape " (inc (count (shapes clip sid))))
|
||||
:kind :poly :paint? true :parent nil :z z
|
||||
:span [frame end]
|
||||
:channels {geometry (channel/keyed {frame points})
|
||||
:channels {geometry (channel/keyed {frame points} :hold)
|
||||
[:style :color] (channel/framed color)
|
||||
;; Turned and scaled about its middle, as a placed
|
||||
;; symbol is: set once here and never followed.
|
||||
|
|
@ -41,7 +41,9 @@
|
|||
[start end] (:span node)]
|
||||
(if (and (:paint? node) (<= start frame) (< frame end) ch)
|
||||
(assoc-in clip (into path [:channels geometry :keys frame])
|
||||
(vec (channel/value-at ch frame)))
|
||||
;; A drawing is authored and keyed, never dense, so there is
|
||||
;; no tier-2 store to read it out of.
|
||||
(vec (channel/value-at ch frame nil)))
|
||||
clip)))
|
||||
|
||||
(defn set-vertex [clip sid id key-frame vertex [x y]]
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@
|
|||
(let [sid (:of n)
|
||||
frames (clip/frames document sid)
|
||||
loop? (get-in n [:time :loop?])
|
||||
resolve (clip/resolver document store pal/index-of sid)]
|
||||
resolve (clip/resolver document store pal/index-of sid nil)]
|
||||
(fn [f]
|
||||
(let [f (if loop? (mod f frames) f)]
|
||||
(when (< -1 f frames)
|
||||
|
|
@ -128,12 +128,6 @@
|
|||
(when-not (ch/nothing? s) (let [h (/ s 2)] [(- h) (- h) h h]))))
|
||||
(constantly nil))))
|
||||
|
||||
(defn local-bounds
|
||||
"`[x0 y0 x1 y1]` around what node `n` draws on its own frame `f`, in its own
|
||||
coordinates, or nil when it draws nothing there."
|
||||
[document store n f]
|
||||
((bounds-of document store n) f))
|
||||
|
||||
(defn pivot
|
||||
"The middle of everything node `n` draws over its own frames `fs`, in its own
|
||||
coordinates — where it should turn and scale about. Nil for a node that draws
|
||||
|
|
|
|||
|
|
@ -422,10 +422,7 @@
|
|||
the only place the space changes.
|
||||
|
||||
This is the definition of what a frame means. `resolver` is what plays it."
|
||||
([sym f] (eval-frame sym f nil pal/index-of))
|
||||
([sym f store] (eval-frame sym f store pal/index-of))
|
||||
([sym f store palette] (eval-frame sym f store palette nil nil))
|
||||
([sym f store palette pose-tracks opts]
|
||||
[sym f store palette pose-tracks opts]
|
||||
(let [nodes (nodes-of sym)
|
||||
choices (pose/prepare pose-tracks)
|
||||
traces (prepared-traces nodes)
|
||||
|
|
@ -440,7 +437,7 @@
|
|||
:pinv-for (fn [id] (node/pinv (get nodes id)))
|
||||
:buf-for (fn [_id n] (js/Float64Array. (* 2 n)))
|
||||
:scratch (node/mat)}
|
||||
nodes ord (draw-rank nodes ord) f))))
|
||||
nodes ord (draw-rank nodes ord) f)))
|
||||
|
||||
;; ---------------------------------------------------------------------------
|
||||
;; the playback path
|
||||
|
|
@ -485,11 +482,7 @@
|
|||
The op maps themselves are allocated fresh, and deliberately: there are a dozen
|
||||
of them per frame against hundreds of points, so pooling them would buy
|
||||
nothing and cost the ability to hand an op list around as plain data."
|
||||
([sym] (resolver sym nil pal/index-of nil nil))
|
||||
([sym store] (resolver sym store pal/index-of nil nil))
|
||||
([sym store palette] (resolver sym store palette nil nil))
|
||||
([sym store palette pose-tracks] (resolver sym store palette pose-tracks nil))
|
||||
([sym store palette pose-tracks {:keys [source-fps picture-fps]}]
|
||||
[sym store palette pose-tracks {:keys [source-fps picture-fps]}]
|
||||
(let [nodes (nodes-of sym)
|
||||
choices (pose/prepare pose-tracks)
|
||||
traces (prepared-traces nodes)
|
||||
|
|
@ -532,7 +525,7 @@
|
|||
(-invoke [_ f] (step f))
|
||||
IResolver
|
||||
(world-of [_ id] (:m (get @placed id)))
|
||||
(frame-of [_ id] (:f (get @placed id)))))))
|
||||
(frame-of [_ id] (:f (get @placed id))))))
|
||||
|
||||
;; ---------------------------------------------------------------------------
|
||||
|
||||
|
|
|
|||
|
|
@ -622,7 +622,8 @@
|
|||
(rf/reg-event-db
|
||||
::toggle-key
|
||||
(fn [db [_ sid id path frame]]
|
||||
(edit/edit db #(update-in % [:symbols sid :nodes id] node/toggle-key path frame))))
|
||||
(let [st (:store (store/entry (:clip/current db)))]
|
||||
(edit/edit db #(update-in % [:symbols sid :nodes id] node/toggle-key path frame st)))))
|
||||
|
||||
;; A face's trace frames and origin, on its symbol — see `domain/trace`.
|
||||
(rf/reg-event-db
|
||||
|
|
|
|||
|
|
@ -312,7 +312,7 @@
|
|||
(when (or (zero? f)
|
||||
(not= (nth shown f) (nth shown (dec f))))
|
||||
[f (nth shown f)])))
|
||||
(range (count shown))))
|
||||
(range (count shown))) :hold)
|
||||
:generated generated)))
|
||||
|
||||
(defn- keyed-visibility [values generated]
|
||||
|
|
@ -320,7 +320,7 @@
|
|||
(when (or (zero? f)
|
||||
(not= (nth values f) (nth values (dec f))))
|
||||
[f (nth values f)])))
|
||||
(range (count values))))
|
||||
(range (count values))) :hold)
|
||||
:generated generated))
|
||||
|
||||
(def ^:private pose-groups
|
||||
|
|
|
|||
|
|
@ -18,14 +18,13 @@
|
|||
with nothing to evict it, and the timeline that would want several is out of
|
||||
scope. `kind` only names the id — `:footage/3`, `:project/4` — so that a clip's
|
||||
origin is legible in the db without a lookup."
|
||||
([entry] (install! entry "footage"))
|
||||
([entry kind]
|
||||
(let [id (keyword kind (str (swap! serial inc)))]
|
||||
(when-let [old (:audio @loaded)]
|
||||
(when (and (not= old (:audio entry)) (.startsWith old "blob:"))
|
||||
(js/URL.revokeObjectURL old)))
|
||||
(reset! loaded (assoc entry :id id))
|
||||
id)))
|
||||
[entry kind]
|
||||
(let [id (keyword kind (str (swap! serial inc)))]
|
||||
(when-let [old (:audio @loaded)]
|
||||
(when (and (not= old (:audio entry)) (.startsWith old "blob:"))
|
||||
(js/URL.revokeObjectURL old)))
|
||||
(reset! loaded (assoc entry :id id))
|
||||
id))
|
||||
|
||||
(defn entry [id]
|
||||
(if (= id (:id @loaded))
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@
|
|||
(when n
|
||||
(let [st (:store (store/entry clip-id))]
|
||||
(when-let [pl (nest/placement clip st open (or path [id]) f)]
|
||||
(assoc pl :node n :bounds (pick/local-bounds clip st n (:frame pl))))))))
|
||||
(assoc pl :node n :bounds ((pick/bounds-of clip st n) (:frame pl))))))))
|
||||
|
||||
(rf/reg-sub
|
||||
::project-footage
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@
|
|||
:disc (select-keys op [:kind :cx :cy :r])
|
||||
:rect (select-keys op [:kind :cx :cy :size])
|
||||
nil))
|
||||
((clip/resolver document st pal/index-of sid) 0))))
|
||||
((clip/resolver document st pal/index-of sid nil) 0))))
|
||||
|
||||
(defn symbol!
|
||||
"Start carrying symbol `sid` of the loaded document into the open symbol."
|
||||
|
|
|
|||
|
|
@ -180,7 +180,9 @@
|
|||
|
||||
(defn- channel-control [sid id path ch frame]
|
||||
(let [keyed? (some? (:keys ch))
|
||||
v (channel/value-at ch (or frame 0))
|
||||
;; 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.
|
||||
|
|
|
|||
|
|
@ -231,7 +231,8 @@
|
|||
:w w :h h}
|
||||
points? @(rf/subscribe [::sub/points])
|
||||
[sid id geom active editable? frame matrix] (when points? (editing))
|
||||
pts (when geom (through matrix (channel/value-at geom frame)))]
|
||||
pts (when geom (through matrix (channel/value-at geom frame
|
||||
(:store (store/entry clip-id)))))]
|
||||
[:svg {:class (str "paint-overlay" (when drawing? " drawing"))
|
||||
:width (* zoom w) :height (* zoom h)
|
||||
:view-box (str "0 0 " w " " h)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue