fix frme rte things

This commit is contained in:
Olive Vaughn 2026-10-10 15:13:21 -04:00
parent 9af21c5d10
commit a10d7b2d9f
44 changed files with 889 additions and 716 deletions

View file

@ -1,41 +1,43 @@
# Time selection
# Time
Project `:fps` is the playback and export grid. Each symbol has its own native
`:fps` and `:frames`; keys, spans, trace choices and corrections stay in that
native space. A symbol without an explicit rate inherits the document rate;
changing project fps first records that rate so its existing timing stays put.
The untouched symbol in a new document is deliberately different: it has no
authored timing to preserve, so it stays on the project grid and its empty frame
extent is rescaled to keep the same duration. This makes changing fps before
authoring establish the editor's grid instead of preserving the 30fps default.
A document has ONE rate, `:fps`, and a symbol has none. A symbol is a bag of
frames: frame n of anything plays for one tick of the document's clock, at any
depth of nesting. This is Flash's model — a MovieClip has no frame rate of its
own — and it is what makes "one frame" mean the same thing wherever you are
drawing. New documents are 12fps.
An output frame selects the latest native frame at or before its time:
`floor(output-frame * native-fps / output-fps)`. Thus 30fps content in a 12fps
project reads source frames 0, 2, 5, 7, 10… and retains its duration. A partial
last output frame is included. Changing back to 30 restores the original grid.
Nothing rewrites or discards the dense measurements.
## Footage
The same boundary selection runs when entering a placed symbol. Placement and
artistic speed are applied before selection; the stored `:time :rate` and
`:playback :speed` never contain a frame-rate conversion. The derived maps used
by timeline rows, picking and editing account for the units of each symbol.
`clip/frames` is a native length; `clip/output-frames` is a transport/export
length. Resolver frame queries return native frames for edits.
Footage is the one thing that really has its own rate. A tracing symbol's frames
are the footage's frames and a take's measured faces are the camera's, so they
keep them, and the PLACEMENT plays them at the speed that makes them real time:
30fps footage in a 12fps project is an instance with `:playback :speed 2.5`.
It is an ordinary, visible retime. Output frame f shows source frame
`floor(f · speed)`, the latest at or before its instant; the preserve-snap
(`domain/pose`) is what recovers a one-frame closure that speed skips.
There is one fps control. The old transient picture-fps control and node
sample-fps fields are gone. Existing exposure, trace choices and per-instance
pose tracks remain available: a pose track can hold a chosen closed-mouth frame
without deleting its neighboring measurements. Those choices stay in native
frames when output fps changes. Automatic content-aware frame selection is not
implemented; [frame-selection.md](frame-selection.md) is how it should be. An
event between output frames appears on the next output frame; it cannot create
an extra frame in a 12fps output.
A sound counts in its source's own rate (`:source :fps`), and the audio mix
cancels the document's rate out, so only deliberate speed changes affect pitch
and duration.
Audio uses continuous time through the same derived placement maps, without
picture floors or holds. Frame-rate units cancel before Web Audio playbackRate
is set, so only deliberate speed changes affect pitch and duration. Export and
playback use the same output count and resolver.
## Changing the rate
Earlier imports with frame-rate conversion baked into stored retimes must be
re-imported. There is no second reader for that representation. Source video
presentation timestamps are still future work; this model assumes constant fps.
The rate is changed through a dialog, not typed over, because there are two
honest meanings and they are Animate's two (`domain/retime`):
* **keep frames** — `(assoc clip :fps rate)`. Every frame stays where it is and
plays for the new tick, so the animation runs faster or slower. Sounds still
play in seconds.
* **keep timing** — `retime/scale-spans`, Animate's "scale spans". Every frame
number in every symbol is multiplied by `new/old` and rounded: keys, spans,
`:time :at`, holds, exposure, a symbol's `:frames`. Keys that land on one frame
keep the later one. A symbol of camera frames (footage, dense measurements)
cannot be rewritten frame by frame, so its factor is 1 and its placements
absorb the change — an instance's speed becomes `speed · child/host`, the same
rule read the other way round.
Bringing symbols in from a document at another rate (a take, another project)
keeps their timing the same way.
Source video presentation timestamps are still future work; this model assumes
constant fps.

View file

@ -134,7 +134,7 @@
(defn- render! [document sid sources store]
(let [fps (:fps document)
frames (clip/output-frames document sid)
frames (clip/frames document sid)
tracks (tracks-of document sid)
output (js/OfflineAudioContext.
2 (js/Math.ceil (* (/ frames fps) 44100)) 44100)]
@ -234,12 +234,12 @@
(and fallback-url (= sid (clip/opens-on document)))
(-> (decode! fallback-url)
(.then (fn [b]
(let [seconds (/ (clip/output-frames document sid) (:fps document))]
(let [seconds (/ (clip/frames document sid) (:fps document))]
{:buffer (fit-buffer b seconds) :seconds seconds}))))
:else
{:buffer nil
:seconds (/ (clip/output-frames document sid) (:fps document))})))))
:seconds (/ (clip/frames document sid) (:fps document))})))))
(defn clock!
"Promise of the URL the transport should play while symbol `sid` is open.

View file

@ -13,6 +13,7 @@
(:require [arthur.domain.clip :as clip]
[arthur.domain.feature :as feature]
[arthur.domain.node :as node]
[arthur.domain.retime :as retime]
[clojure.string :as string]))
(defn symbols
@ -28,9 +29,17 @@
Only symbols travel. What else `other` holds — tracking identities, an analysis
— is the caller's decision, because whether it can come too depends on what
`clip` already has."
`clip` already has.
WHAT COMES IN KEEPS ITS TIMING. `other` is moved onto this document's rate
first, with `retime/scale-spans`, so a take measured at 30 plays in seconds
here as it did there; footage and measurements keep their own frames and the
placements of them take up the difference."
[clip other roots wanted]
(let [;; A tree walk is safe because placing cannot make a cycle.
(let [other (cond-> other
(and (:fps clip) (:fps other) (not= (:fps clip) (:fps other)))
(retime/scale-spans (:fps clip)))
;; A tree walk is safe because placing cannot make a cycle.
reach (into #{} (mapcat #(tree-seq any? (partial clip/places other) %)) roots)
ids (reduce (fn [ids sid]
(let [taken? #(or (contains? (:symbols clip) %)
@ -45,7 +54,7 @@
n))
copy (fn [sid]
(-> (clip/symbol other sid)
(assoc :id (ids sid) :fps (or (:fps (clip/symbol other sid)) (:fps other)))
(assoc :id (ids sid))
(update :nodes #(into {} (map (fn [[id n]] [id (repoint n ids)])) %))))]
{:clip (reduce (fn [c sid] (assoc-in c [:symbols (ids sid)] (copy sid))) clip reach)
:ids ids}))
@ -90,11 +99,8 @@
wanted (into {:main root :footage (scoped :footage)}
(map (fn [subject] [subject (scoped subject)]))
(keys (:subjects frozen)))
{c :clip ids :ids} (symbols clip frozen [:main] wanted)
sid (ids :main)
faces (mapv ids (sort-by str (keys (:subjects frozen))))
sound {:id :sound :name "sound" :kind :audio :parent nil
:z "z-sound" :source {:footage footage-id}
:z "z-sound" :source {:footage footage-id :fps (:fps frozen)}
;; All automatic copies name one recording. The audio walk
;; uses this identity only to avoid mixing that recording once
;; per detected face when the complete take is played.
@ -102,6 +108,13 @@
;; Source frame `start` plays on the symbol's 0.
:span range
:time {:mode :map :at (- (first range)) :rate 1}}
;; Into the faces BEFORE they are copied, so the sound is moved onto this
;; document's rate along with the rest of them.
frozen (reduce (fn [document face]
(assoc-in document [:symbols face :nodes :sound] sound))
frozen (keys (:subjects frozen)))
{c :clip ids :ids} (symbols clip frozen [:main] wanted)
sid (ids :main)
feature-ids (into {}
(map (fn [[id f]]
[id (feature/owned (ids (:subject f)) (keyword (name id)))]))
@ -130,9 +143,7 @@
(:groups frozen))]
{:sid sid
:subject-ids (select-keys ids (keys (:subjects frozen)))
:clip (-> (reduce (fn [document face]
(assoc-in document [:symbols face :nodes :sound] sound))
c faces)
:clip (-> c
(assoc-in [:symbols sid :name] (str label))
(update :analyses merge (:analyses frozen))
(update :subjects merge subjects)
@ -147,5 +158,4 @@
when there is none. See `clip/place-symbol`."
[entry brought store sid host frame uuid point]
(let [st (merge (:store entry) store)]
(assoc entry :store st :clip (clip/place-symbol brought st host sid
(* frame (:rate (clip/grid-time brought host))) uuid point))))
(assoc entry :store st :clip (clip/place-symbol brought st host sid frame uuid point))))

View file

@ -1,25 +0,0 @@
(ns arthur.domain.cadence
"Select integer content frames across frame grids. Stored frames never change.")
(defn ratio [grid native]
(if (and grid native (pos? grid) (pos? native)) (/ native grid) 1))
(defn frame
"Latest native frame at or before reader frame f. Never sample the future."
[f grid native]
(js/Math.floor (if (and grid native) (/ (* f native) grid) f)))
(defn frames
"Reader frames covering a native length, including a partial final frame."
[n grid native]
(when n (max 1 (js/Math.ceil (/ n (ratio grid native))))))
(defn reader-frame
"The earliest reader frame whose `frame` is at or after native frame n — the
inverse of `frame`, as far as it has one.
`frame` is a floor, so several reader frames can show one native frame and a
native frame between two of them is shown by none: this answers with the
reader frame that first reaches it, which is what seeking to a mark means."
[n grid native]
(js/Math.ceil (if (and grid native) (/ (* n grid) native) n)))

View file

@ -34,11 +34,11 @@
symbol, the way a Flash file names its scene. See `opens-on` for why that
cannot be worked out instead.
:fps is the output grid. A symbol's optional :fps names the native grid its
frames were authored or measured on; absent means the document's grid."
:fps is the document's one rate. A symbol has none: it is a bag of frames, and
each of them plays for one tick of the document's clock, as in Flash. See
`docs/time.md`."
(:refer-clojure :exclude [symbol])
(:require [arthur.domain.cadence :as cadence]
[arthur.domain.channel :as ch]
(:require [arthur.domain.channel :as ch]
[arthur.domain.feature :as feature]
[arthur.domain.node :as node]
[arthur.domain.palette :as pal]
@ -101,69 +101,12 @@
[clip sid]
(:frames (symbol clip sid)))
(defn fps [clip sid] (or (:fps (symbol clip sid)) (:fps clip)))
(defn set-fps
"Change the output grid without rewriting authored content's frames.
A new document's empty symbol is the one exception: it has no native rate yet,
so it follows the project grid and its empty extent is rescaled to preserve its
duration. Once a symbol contains anything, changing the project rate records
the old effective rate on it before changing the output grid."
[clip rate]
(let [old (:fps clip)]
(-> clip
(update :symbols
#(into {}
(map (fn [[sid sym]]
[sid (cond
(:fps sym) sym
(empty? (:nodes sym))
(update sym :frames cadence/frames rate old)
:else (assoc sym :fps old))]))
%))
(assoc :fps rate))))
(defn output-frames [clip sid]
(cadence/frames (frames clip sid) (:fps clip) (fps clip sid)))
(defn grid-time [clip sid]
{:at 0 :rate (cadence/ratio (:fps clip) (fps clip sid))})
;; ---------------------------------------------------------------------------
;; the only crossing between the output grid and a symbol's own frames
;;
;; Everything authored is in a symbol's own frames and every editing gesture is
;; too — see `docs/one-grid-plan.md`. The output grid belongs to playback: the
;; clock, the audio mix, export, and the frame number the stage is drawing. These
;; two functions are the whole of the way between, so a caller that has a
;; playhead and needs a document coordinate says so in one visible call instead
;; of multiplying by a rate it had to know about.
(defn shown-frame
"Which of symbol `sid`'s own frames the output frame `f` shows."
[clip sid f]
(cadence/frame f (:fps clip) (fps clip sid)))
(defn first-output-frame
"The output frame that first shows symbol `sid`'s own frame `n`: what to seek
to to put the playhead on a mark of `sid`'s ruler."
[clip sid n]
(cadence/reader-frame n (:fps clip) (fps clip sid)))
(defn source-time
"Derived cel-to-content map. Frame-rate units never enter stored retimes."
[clip host n]
(when-let [t (node/source-time n)]
(let [r (cadence/ratio (fps clip host) (fps clip (node/source n)))]
(-> t (update :rate * r) (update :at / r)))))
(defn placed-frame [clip host n f]
(let [child (node/source n)
r (cadence/ratio (fps clip host) (fps clip child))]
(some-> (node/placed-frame (update-in n [:playback :speed] #(* (or % 1) r))
f (frames clip child))
(update :frame js/Math.floor))))
(defn placed-frame
"Which frame of which symbol instance `n` shows on its own frame `f`, as
`{:symbol :frame}`, or nil. See `node/placed-frame`."
[clip n f]
(some-> (node/placed-frame n f (frames clip (node/source n)))
(update :frame js/Math.floor)))
(defn stage
"A symbol's stage as `[width height]`: its own, or the clip's where it has none.
@ -216,41 +159,19 @@
the theory that the one containing everything else is always that. A take
disproves it: imported footage is a symbol a thousand frames long, and the
moment its instance is deleted, or the drop lands somewhere other than the
root, nothing places it and it outranks a 120-frame `:main`. The document then
opened on the take, and `set-root-fps` rewrote the take's rate to the
project's on the way in.
root, nothing places it and it outranks a 120-frame `:main`, and the document
opened on the take.
A document with no `:root` — a demo, a fixture — still gets the old answer."
[clip]
(let [root (:root clip)]
(if (contains? (:symbols clip) root) root (longest-unplaced clip))))
(defn pin-root
"Give a document saved before `:root` existed the root it was made with.
Every such document started as `blank`, whose root is `:main`, and ids never
change, so `:main` is the answer wherever it survives; the old rule is only
for documents that never had one."
[clip]
(cond-> clip
(not (:root clip))
(assoc :root (if (contains? (:symbols clip) :main) :main (longest-unplaced clip)))))
(defn set-root-fps
"Set the document/output rate and the root symbol's editing rate together.
Project FPS is the root timeline's clock. Nested symbols keep their own native
rates and are sampled when placed across that boundary; only the root changes
here. Frame numbers are authored positions, so changing the rate does not
rewrite them or silently move cuts and keys."
[clip rate]
(let [root (opens-on clip)]
(cond-> (assoc clip :fps rate)
root (assoc-in [:symbols root :fps] rate))))
(def ^:const blank-frames
"How long a new document is before anything says otherwise. Four seconds at 30,
which is long enough to key something into and short enough to scrub by hand."
120)
(def blank-settings
"What a new document is before anyone says otherwise. 12fps because the rough
look is the point; four seconds is long enough to key something into and short
enough to scrub by hand."
{:name "untitled" :fps 12 :seconds 4 :width 320 :height 200})
(defn blank
"A new, empty document: one symbol, and nothing in it.
@ -265,17 +186,21 @@
as a different map than it saved from is exactly the round trip that namespace
promises not to have. Nothing drawn by hand has them either — the demo scene
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."
[]
{:name "untitled"
:fps 30
:width 320 :height 200
:palettes {pal/default-id pal/default-palette}
:default-palette pal/default-id
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."
([] (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)]
{:name (:name s)
:fps fps
:width width :height height
:palettes presets
:default-palette (if (contains? presets palette) palette pal/default-id)
:root :main
;; No native fps yet: an untouched canvas follows the project grid. Imported
;; and generated symbols carry their own rate explicitly.
:symbols {:main {:id :main :frames blank-frames :nodes {}}}})
:symbols {:main {:id :main :frames (max 1 (js/Math.round (* seconds fps))) :nodes {}}}})))
(defn- op-path [op] (let [n (:node op)] (if (vector? n) n [n])))
@ -497,7 +422,7 @@
prior (symbol/pre-frame-of own id)
length (frames clip (node/source n))
shown (when (and m (number? local))
(placed-frame clip sid n local))
(placed-frame clip n local))
frame (:frame shown)]
(cond
(not (and frame (<= 0 frame) (< frame length)))
@ -523,7 +448,7 @@
;; the first time on this slot has no
;; previous frame, and so no gap.
(or (:frame (when (number? prior)
(placed-frame clip sid n prior)))
(placed-frame clip n prior)))
(dec frame))
@active
(when (and context? (:palette n))
@ -554,27 +479,12 @@
(when (contains? @entered id)
(symbol/pre-frame-of (get children [id (get @entered id)]) (vec more)))
(symbol/pre-frame-of own id))))))]
(let [r (build sid [] nil true)
grid (or (:grid-fps opts) (:fps clip))
native (fps clip sid)]
(let [r (build sid [] nil true)]
(reify
IFn
(-invoke [_ f]
(r (cadence/frame f grid native)
;; `d(k-1)`: the native frame the slot BEFORE this one selected, which
;; with `d(k)` is the interval `(d(k-1), d(k)]` the preserve-snap may
;; reach back into — the frames this slot is the first to cover, and so
;; the ones the grid would otherwise show to nobody. Slot 0 has no slot
;; before it, so its interval is its own frame alone.
;;
;; THE SNAP DOES NOT HAPPEN HERE, although the interval is born here and
;; nothing would need threading. One native frame per output frame means
;; the WHOLE PICTURE reading 13 instead of 15 — a head going two frames
;; stale, a 67ms hitch at 12fps, to fix one group's mouth. It is per
;; group, so it is seated where groups exist.
(if (pos? f) (cadence/frame (dec f) grid native) -1)
(when context? (:default palette))
nil))
;; `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))
symbol/IResolver
(world-of [_ path] (symbol/world-of r path))
(frame-of [_ path] (symbol/frame-of r path))
@ -601,7 +511,7 @@
cross is draggable so neither is a trap. What the anchor got wrong was being
invisible and unmovable, not being stored."
[clip store sid]
(let [resolve (resolver clip sid store pal/index-of {:grid-fps (fps clip sid)})
(let [resolve (resolver clip sid store pal/index-of {})
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]
@ -644,11 +554,13 @@
The instance's own time starts where it was dropped: `:at frame` means frame 0
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 — wherever it was dropped; see `node/placed-span`.
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.
Refused, returning the clip unchanged, when it would make a cycle: a symbol
cannot be placed inside itself or inside anything it places."
[clip store host sid frame uuid point]
([clip store host sid frame uuid point] (place-symbol clip store host sid frame uuid point 1))
([clip store host sid frame uuid point speed]
(let [target (symbol clip sid)
end (frames clip host)]
(if (or (nil? target) (nil? end) (nil? frame) (neg? frame) (>= frame end)
@ -663,13 +575,13 @@
;; 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 (cadence/frames (:frames target) (fps clip host) (fps clip sid))]
:span [0 (js/Math.ceil (/ (:frames target) speed))]
:time {:mode :map :at frame :rate 1}
:source {:symbol sid}
:playback {:in 0 :speed 1 :end :stop}
:playback {:in 0 :speed speed :end :stop}
:channels {[:xform :pos] {:animated? false
:value (if point (mapv - point middle) [0 0])}
[:xform :pivot] {:animated? false :value middle}}})))))
[:xform :pivot] {:animated? false :value middle}}}))))))
(defn place-sound
"Place a sound at host frame `frame`. Its span uses `source`'s fps when
@ -704,7 +616,7 @@
(if (or (nil? end) (symbol clip sid) (nil? frame) (neg? frame) (>= frame end))
clip
(-> clip
(assoc-in [:symbols sid] {:id sid :name (name sid) :fps (fps clip host)
(assoc-in [:symbols sid] {:id sid :name (name sid)
:frames (- end frame) :nodes {}})
(place-symbol nil host sid frame uuid nil)))))

View file

@ -17,7 +17,7 @@
clip/<cid>/subject/<subj> a tracked subject and its params
clip/<cid>/feature/<fid> one feature: area, nodes, params
clip/<cid>/group/<gid> an eye pair and its shared params
clip/<cid>/symbol/<sid> native frames and fps, optional palette
clip/<cid>/symbol/<sid> frame count, optional palette
clip/<cid>/symbol/<sid>/node/<nid> kind, parent, stencil, z, time
clip/<cid>/symbol/<sid>/channel/<nid>/<prop>
clip/<cid>/symbol/<sid>/measured/<nid> the channels a re-freeze owns
@ -26,8 +26,8 @@
its own nodes, so the symbol id is a path segment. No symbol has a reserved
segment: `main` in a path is an id like any other.
The timing leaf holds output fps. Each symbol leaf holds its native fps
and frame count, so changing the output grid leaves content untouched.
The timing leaf holds the document's one rate. A symbol leaf holds its frame
count and no rate: a symbol is a bag of frames.
WHY THESE BOUNDARIES. Last-writer-wins only clobbers when its unit is too big,
so the cut is chosen so that the things people do simultaneously land on
@ -151,7 +151,7 @@
;; disagree with itself about; `clip` puts it back.
(for [[sid sym] (:symbols clip)]
{(at "symbol" (segment sid))
(select-keys sym [:name :frames :fps :width :height :palette
(select-keys sym [:name :frames :width :height :palette
:palette-track :palette-channel :type :palette-ref :display
:media])})
(for [[sid sym] (:symbols clip)

View file

@ -54,7 +54,7 @@
OUTPUT frame, multiplied into `sid`'s space here, which made the units of the
argument something each caller had to know without being told and put a
2.5-frame step between what the ruler offered and what the document could hold.
A caller holding the playhead converts with `clip/shown-frame`.
Every symbol counts in the document's one rate, so the playhead is one.
THE SAME STEP FOR EVERY NODE. Inside an instance is the symbol it places;
inside a shape is where its points and keys are. Either way it is the node's
@ -78,7 +78,7 @@
;; the hold pins, not on `local`, and inside a playing insert
;; is its animation at its own in-point and speed.
shown (when (number? local)
(clip/placed-frame clip sid (get nodes id) local))
(clip/placed-frame clip (get nodes id) local))
inner (:symbol shown)
lf (if shown (:frame shown) local)]
(if (and m (number? local)
@ -90,9 +90,9 @@
;; Forward sampling above works for holds too. :time is the
;; invertible edit map; source in-points and speeds belong in it.
:time (when (and time (not-any? #(get-in % [:time :loop?]) chain)
(or (not inst?) (clip/source-time clip sid (get nodes id))))
(or (not inst?) (node/source-time (get nodes id))))
(cond-> (reduce node/then-time time (map node/time-of chain))
inst? (node/then-time (clip/source-time clip sid (get nodes id)))))}
inst? (node/then-time (node/source-time (get nodes id)))))}
(reduced nil))))
{:sid sid :frame (js/Math.floor f)
:matrix (node/mat) :time node/same-time}
@ -189,8 +189,8 @@
{:time outer :bounds bounds})
m (node/then-time (:time parent) (node/time-of n))
m (if (= :audio (:kind n))
(update m :rate * (/ (or (get-in n [:source :fps]) (clip/fps clip sid))
(clip/fps clip sid))) m)]
(update m :rate * (/ (or (get-in n [:source :fps]) (:fps clip))
(:fps clip))) m)]
(assoc acc id {:time m :bounds (window m (:span n) (:bounds parent))})))
{} (symbol/order nodes))]
(mapcat
@ -200,7 +200,7 @@
(case (:kind n)
:audio [(-> n
(assoc :parent nil :path (conj path id) :owner sid
:fps (or (get-in n [:source :fps]) (clip/fps clip sid))
:fps (or (get-in n [:source :fps]) (:fps clip))
:span [(to-local m lo) (to-local m hi)]
:time (merge (:time n) {:mode :map :at (:at m) :rate (:rate m) :offset 0})
:channels (channels (:channels n) m)))]
@ -210,7 +210,7 @@
length (clip/frames clip child)]
;; A visual freeze does not emit a sustained audio sample.
(when (and child length (pos? speed))
(let [source (node/then-time m (clip/source-time clip sid
(let [source (node/then-time m (node/source-time
(-> n
(assoc-in [:playback :end] :stop)
(update :time dissoc :loop?))))
@ -225,8 +225,8 @@
periods))))
nil))))
(sort-by (comp str key) nodes))))]
(let [tracks (walk sid (clip/grid-time clip sid)
[0 (clip/output-frames clip sid)] [] #{})]
(let [tracks (walk sid node/same-time
[0 (clip/frames clip sid)] [] #{})]
(second
(reduce (fn [[seen out] track]
(let [link (:media-link track)
@ -394,7 +394,7 @@
(mapcat (fn [n]
(if (get-in n [:time :loop?]) [nil]
(cond-> [(node/time-of n)]
(= :instance (:kind n)) (conj (clip/source-time clip sid n)))))
(= :instance (:kind n)) (conj (node/source-time n)))))
chain)))
sids path)]
{:sid (last sids)
@ -627,7 +627,7 @@
start (js/Math.floor (max 0 (apply min (map first spans))))
end (min (second whole) (apply max (map second spans)))
made (-> clip
(assoc-in [:symbols sid] {:id sid :name (name sid) :fps (clip/fps clip host)
(assoc-in [:symbols sid] {:id sid :name (name sid)
:frames (max 1 (js/Math.ceil (- end start)))
:nodes {}})
(clip/place-symbol store host sid start uuid nil))

View file

@ -243,8 +243,8 @@
the lead in their load-bearing order.
`:rate` is a RETIME SOMEBODY CHOSE and nothing else — half speed on an insert.
Reconciling two frame rates is not a retime and does not belong here: it is a
selection, and it lives in `domain/cadence`."
Footage at another rate than the document's is played by the `:playback
:speed` of its placement, not by this."
[n]
(let [{:keys [mode at rate offset] :or {mode :map at 0 rate 1 offset 0}} (:time n)]
(if (= mode :map)

View file

@ -51,6 +51,45 @@
{:id default-id :name "Arthur"
:slots (into entries (repeat 7 {:hex "#000000"}))})
(defn- preset
"A palette from nine face tones in `entries` order and seven free ones. The
order is the point: a measured mouth draws in slot 3 and an iris in slot 6
whatever palette is on, so a preset that moved them would recolour a face
into nonsense rather than restyle it."
[id label [bg skin-base skin-dark mouth-dark teeth eye-white iris pupil brow] free]
{:id id :name label
:slots (into (mapv (fn [e hex] {:name (:name e) :hex hex})
entries [bg skin-base skin-dark mouth-dark teeth eye-white iris pupil brow])
(map (fn [hex] {:hex hex}))
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."
[default-palette
;; 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"]
["#ff004d" "#ffa300" "#ffec27" "#00e436" "#008751" "#ff77a8" "#83769c"])
;; GrafxKid's Sweetie 16.
(preset :arthur/sweetie-16 "Sweetie 16"
["#1a1c2c" "#ffcd75" "#ef7d57" "#5d275d" "#f4f4f4" "#94b0c2" "#3b5dc9" "#333c57" "#566c86"]
["#b13e53" "#a7f070" "#38b764" "#257179" "#29366f" "#41a6f6" "#73eff7"])
;; The original Game Boy's four greens, lightest behind. Everything is one of
;; four, so the face reads by value alone.
(preset :arthur/dmg "Game Boy"
["#9bbc0f" "#8bac0f" "#306230" "#0f380f" "#9bbc0f" "#9bbc0f" "#306230" "#0f380f" "#0f380f"]
["#0f380f" "#306230" "#8bac0f" "#9bbc0f" "#0f380f" "#306230" "#8bac0f"])
;; Rubber-hose cartoons, on paper gone yellow.
(preset :arthur/sepia "Sepia"
["#f2e6c9" "#e8c39e" "#b98b63" "#4a2c1d" "#fbf4e2" "#f3ead6" "#6b4a2f" "#241610" "#4a2c1d"]
["#8c2f1f" "#c8792c" "#d9b44a" "#6f7d3c" "#3e5a6b" "#a39b8b" "#2b2420"])
;; Ink and a red, for line tests and noir.
(preset :arthur/ink "Ink"
["#101010" "#d8d2c4" "#8a857a" "#2a2a2a" "#f0ece2" "#c8c3b6" "#4a4a4a" "#0a0a0a" "#2a2a2a"]
["#b3261e" "#e4e0d6" "#bdb8ad" "#9e998f" "#6d6961" "#4f4c46" "#1c1c1c"])])
(defn palettes [clip]
(if (seq (:palettes clip)) (:palettes clip) {default-id default-palette}))

View file

@ -183,7 +183,7 @@
;; pixels, in its own coordinates, on every frame it shows one.
:trace
(let [{:keys [width height]} (clip/symbol document (node/source n))]
(fn [f] (when (clip/placed-frame document sid n f) [0 0 width height])))
(fn [f] (when (clip/placed-frame document n f) [0 0 width height])))
:instance
;; ONE RESOLVER PER DRAWING THE LANE CAN SHOW, built once for the reason
@ -192,11 +192,10 @@
;; resolver per frame.
(let [loop? (get-in n [:time :loop?])
resolvers (into {} (map (fn [child]
[child (clip/resolver document child store
pal/index-of {:grid-fps (clip/fps document child)})]))
[child (clip/resolver document child store pal/index-of {})]))
(node/sources n))]
(fn [f0]
(let [shown (clip/placed-frame document sid n f0)
(let [shown (clip/placed-frame document n f0)
frames (when shown (clip/frames document (:symbol shown)))
f (when (number? frames)
(if loop? (mod (:frame shown) frames) (:frame shown)))

View file

@ -6,7 +6,7 @@
AND THE PRESERVE-SNAP, which is the same question asked where nobody has
answered it by hand. A grid slot already picks a native frame — the latest one
at or before its time, see `domain/cadence` — and that pick has no opinion about
at or before its time, `node/placed-frame` floored — and that pick has no opinion about
content, so at 12fps out of 30 it drops two frames in three and cannot know that
one of them is where the mouth shut. The snap gives it one: a slot reads the
latest MARKED frame inside its own gap. `marks` is where the marks come from and
@ -123,8 +123,8 @@
is recovered by the slot whose default is 15, reading 13. It is NOT recovered by
the slot whose default is 12 reaching forward to 13: that slot's instant is
5/12s and native 13's is 13/30s, so it would show the closure 17ms before the
mouth shut. `cadence/frame`'s contract is at-or-before and `cadence_test` asserts
`selected <= f*native/grid` over every grid and native pair, so reaching forward
mouth shut. A placement's frame is a floor, at-or-before, and `rate_test` asserts
`selected <= f*speed` over every speed, so reaching forward
would break a tested invariant as well as the no-lead rule. Reading 13 two
native frames late is the lateness every hold already has.

View file

@ -0,0 +1,106 @@
(ns arthur.domain.retime
"Changing the document's rate.
A symbol is a bag of frames and the document has one rate, so there are two
honest things a new rate can mean, and they are Flash's two:
`(assoc clip :fps rate)` KEEP FRAMES. Every frame stays the frame it was and
plays for the new tick, so the animation runs
faster or slower. Sounds still play in seconds.
`(scale-spans clip rate)` KEEP TIME. Every frame number is moved to where the
same moment falls on the new grid — Animate's
\"scale spans\". Going down, frames that land on
one another are dropped and the later wins, as it
would have been showing; going up, holds just get
longer, because nothing is invented.
ONE RULE FOR EVERY NUMBER: it is multiplied by the factor of the frame space it
lives in. An authored symbol's factor is `rate/old`. A symbol whose frames are
the CAMERA's — footage, or measurements taken from it — cannot be rewritten
frame by frame, so its factor is 1 and its placements absorb the change: an
instance's speed becomes `speed · child/host`, which is the same formula that
scales everything else, read the other way round."
(:require [arthur.domain.clip :as clip]
[arthur.domain.node :as node]))
(defn- camera?
"Are `sym`'s frames the camera's: footage, or anything measured from it?"
[sym]
(or (clip/trace? sym)
(some (fn [n] (some :dense (vals (:channels n)))) (vals (:nodes sym)))))
(defn- at [k f] (js/Math.round (* k f)))
(defn- interval
"Half-open `[in out)` scaled, never collapsing to nothing."
[k [in out]]
(let [in' (at k in)] [in' (max (inc in') (at k out))]))
(defn- by-frame
"Frame-keyed map `m` re-keyed. Sorted first, so where two keys land on one
frame the later one wins."
[k m]
(into {} (map (fn [[f v]] [(at k f) v])) (sort-by key m)))
(defn- channel [k c]
(cond-> c
(:keys c) (update :keys #(by-frame k %))
(:segments c) (update :segments #(by-frame k %))
(seq (:over c))
(update :over (partial mapv #(cond-> (update % :values (partial channel k))
(vector? (:support %)) (update :support (partial interval k)))))))
(defn- channels [k chs]
(into {} (map (fn [[p c]] [p (channel k c)])) chs))
(defn- time-map
"`:at` is in the parent's frames; the floor, holds and lead are the node's own."
[kp ko t]
(cond-> t
(:at t) (update :at #(at kp %))
(:offset t) (update :offset #(at ko %))
(:expose t) (update :expose #(max 1 (at ko %)))
(:holds t) (update :holds (partial mapv #(at ko %)))))
(defn- scale-node
"`kh` is the factor of the symbol `n` is in, `kc` of the one it places and `k`
the document's. A sound's own frames are its source's, which the document's
rate converts, so only its place moves and its rate takes the document's
change back out where the host did not follow it."
[kh kc k n]
(case (:kind n)
:audio
(cond-> (update n :time #(time-map kh 1 %))
(not= k kh) (update :time #(update (merge {:rate 1} %) :rate * (/ k kh))))
(cond-> n
(:time n) (update :time #(time-map kh kh %))
(:channels n) (update :channels #(channels kh %))
(:span n) (update :span #(interval kh %))
(and (= :instance (:kind n)) (or (:playback n) (not= kc kh)))
(update :playback
(fn [{:keys [in speed tracks] :as p :or {in 0 speed 1}}]
(cond-> (assoc p :in (at kc in) :speed (* speed (/ kc kh)))
tracks (assoc :tracks
(into {} (map (fn [[g entries]]
[g (into {} (map (fn [[f s]] [(at kh f) (at kc s)]))
(sort-by key entries))]))
tracks))))))))
(defn scale-spans
"`clip` at `rate`, with every authored frame moved so it happens when it did."
[clip rate]
(let [k (/ rate (:fps clip))
factor (into {} (map (fn [[sid sym]] [sid (if (camera? sym) 1 k)])) (:symbols clip))]
(-> clip
(assoc :fps rate)
(update :symbols
#(into {}
(map (fn [[sid sym]]
(let [kh (factor sid)]
[sid (cond-> (-> sym
(update :frames (fn [n] (max 1 (at kh n))))
(update :nodes (fn [ns] (into {} (map (fn [[id n]] [id (scale-node kh (get factor (node/source n) 1) k n)])) ns))))
(:palette-channel sym) (update :palette-channel (partial channel kh)))])))
%)))))

View file

@ -8,7 +8,7 @@
frames an artist has to draw a head on, and the frames a performance changes a
shape on.
`domain/cadence` answers the same question with no opinion about content, and
A placement's speed answers the same question with no opinion about content, and
cannot know that the one frame where a mouth is fully shut is worth more than
its neighbours. That is the gap `:protect` closes.

View file

@ -565,9 +565,9 @@
drawing creation remains a policy of `append-drawing`/`overwrite-drawing`,
not a different kind of container."
[clip store sid id source-id at
{:keys [extent point remainder-id] :or {extent :keep}}]
{:keys [extent point remainder-id speed] :or {extent :keep speed 1}}]
(let [nodes (get-in clip [:symbols sid :nodes])
seeded (clip/place-symbol clip store sid source-id 0 id point)
seeded (clip/place-symbol clip store sid source-id 0 id point speed)
n (get-in seeded [:symbols sid :nodes id])]
(cond
(contains? nodes id) {:refused "the new clip ID is already used"}
@ -701,7 +701,7 @@
(when (clip/symbol clip drawing-id) "the new drawing ID is already used"))]
{:refused why}
(place (assoc-in clip [:symbols drawing-id]
{:id drawing-id :name (name drawing-id) :fps (clip/fps clip sid) :frames 1 :nodes {}})
{:id drawing-id :name (name drawing-id) :frames 1 :nodes {}})
sid id drawing-id at extent true)))
(defn reuse-drawing
@ -774,8 +774,7 @@
(clip/symbol clip drawing-id) "the new drawing ID is already used")]
{:refused why}
(let [c (assoc-in clip [:symbols drawing-id]
{:id drawing-id :name (name drawing-id)
:fps (clip/fps clip sid) :frames 1 :nodes {}})
{:id drawing-id :name (name drawing-id) :frames 1 :nodes {}})
nodes (assoc nodes id (held id drawing-id at))]
(claim c sid nodes id extent remainder-id)))))

View file

@ -764,11 +764,11 @@
`:media` is what a `:type :trace` symbol shows — `{:footage id :range [in
out]}` or `{:image sha256}` — and such a symbol has no nodes: its frames are
the footage's, its `:fps` the footage's own and its `:width`/`:height` its
pixels. A still shows the same picture on every one of its frames, so how many
it has is only how long it was made to last, and trimming its placement is
how that changes. See `clip/trace-op`."
#{:id :name :frames :fps :width :height :nodes :palette :palette-track
the footage's, played in real time by the speed of its placement, and its
`:width`/`:height` its pixels. A still shows the same picture on every one of
its frames, so how many it has is only how long it was made to last, and
trimming its placement is how that changes. See `clip/trace-op`."
#{:id :name :frames :width :height :nodes :palette :palette-track
:palette-channel :type :palette-ref :display :media})
(defn- media-problems
@ -853,9 +853,6 @@
(into (when-not (or (nil? (:frames sym)) (and (integer? (:frames sym)) (pos? (:frames sym))))
[(str ":frames is " (pr-str (:frames sym))
" — a symbol is a frame SPACE, so its length is a positive integer")]))
(into (when (and (some? (:fps sym))
(not (and (node/finite-number? (:fps sym)) (pos? (:fps sym)))))
[":fps must be a positive finite native rate"]))
(into (for [k [:width :height]
:let [v (get sym k)]
:when (and (some? v) (not (and (integer? v) (pos? v))))]

View file

@ -64,12 +64,25 @@
(rf/reg-fx
::create!
(fn [name]
(-> (http/POST "/api/projects" #js {:name name})
(.then (fn [^js made] (navigate! (project-path (.-id made) (.-name made)))))
(fn [settings]
(-> (http/POST "/api/projects" #js {:name (:name settings)})
(.then (fn [^js made] (rf/dispatch [::created (.-id made) (.-name made) settings])))
(.catch #(rf/dispatch [::refused (ex-message %)])))))
(rf/reg-event-fx ::create (fn [_ [_ name]] {::create! (or name "untitled")}))
(rf/reg-fx ::navigate! navigate!)
;; `settings` is what `clip/blank` takes. The server holds only the name until
;; the first save, so the rest waits under the new id for the first open.
(rf/reg-event-fx
::create
(fn [_ [_ settings]]
{::create! (update settings :name #(or (not-empty %) "untitled"))}))
(rf/reg-event-fx
::created
(fn [{:keys [db]} [_ id name settings]]
{:db (assoc-in db [:new-projects id] settings)
::navigate! (project-path id name)}))
;; ---------------------------------------------------------------------------
;; the socket

View file

@ -571,7 +571,7 @@
{:keys [clip sid subject-ids]}
(bring/take (:clip entry) (:clip built) name footage-id range)
st (merge (:store entry) (:store built))
imported-frames (clip/output-frames clip sid)
imported-frames (clip/frames clip sid)
source-fps (get-in built [:clip :fps])
where (if point
(ui/creation-destination db clip st frame)

View file

@ -24,7 +24,7 @@
the db beside it, because an edit can change it."
[db]
(or (some-> (footage/entry (:clip/current db)) :clip
(clip/output-frames (get-in db [:ui :open])))
(clip/frames (get-in db [:ui :open])))
1))
(defn show

View file

@ -33,6 +33,7 @@
[arthur.demo.stage :as stage]
[arthur.domain.feature :as feature]
[arthur.domain.project :as project]
[arthur.domain.retime :as retime]
[arthur.domain.wire :as wire]
[arthur.events.footage :as footage]
[arthur.events.playback :as pb]
@ -109,13 +110,7 @@
loaded (project/load
cid #js {:leaves (.-leaves clip-json)
:blocks blocks})
;; Project FPS and the root timeline are one clock. This
;; also normalizes documents saved by the earlier model,
;; where changing project FPS left the root on its old
;; editing grid.
built (-> (:clip loaded)
clip/pin-root
(clip/set-root-fps (:fps (:clip loaded))))]
built (:clip loaded)]
(let [entry (merge (select-keys built [:fps :width :height])
{:label (str (or (.-name clip-json) cid) " (saved)")
:cid cid
@ -368,7 +363,7 @@
(rf/reg-fx
::open!
(fn [id]
(fn [[id settings]]
(-> (if id
(js/Promise.resolve #js {:id id})
;; No id: the most recently updated project, which is what "open" means
@ -386,11 +381,12 @@
project/schema-version)
{})))
;; A project made from the index has nothing in it yet: it
;; opens on a blank document, of which the server has seen
;; nothing, so the first save sends all of it.
;; opens on a blank document made with what it was created
;; with, of which the server has seen nothing, so the first
;; save sends all of it.
(-> (if clip-json
(opened-entry! clip-json)
(js/Promise.resolve (assoc (blank-entry) :synced {})))
(js/Promise.resolve (assoc (blank-entry settings) :synced {})))
(.then (fn [entry]
(rf/dispatch [::opened
(store/install! entry "project")
@ -570,15 +566,17 @@
"/static/arthur/audio.wav")
(defn blank-entry
"A blank clip, in the shape `footage/store` and the transport expect."
[]
(let [c (clip/blank)]
{:label "untitled" :clip c :store nil
"A blank clip, in the shape `footage/store` and the transport expect.
`settings` is what `clip/blank` takes."
([] (blank-entry nil))
([settings]
(let [c (clip/blank settings)]
{:label (:name c) :clip c :store nil
:audio blank-audio
;; A content id of its own from the start: `::save!` addresses the clip by
;; it, and two untitled documents saved from two tabs are two documents.
:cid (str (random-uuid))
:fps (:fps c) :width (:width c) :height (:height c)}))
:fps (:fps c) :width (:width c) :height (:height c)})))
(rf/reg-event-fx
::new
@ -594,7 +592,7 @@
:busy? false :status "new document"}))
;; The readout goes home with the document; so must the clock, or play
;; picks up wherever the last document's audio had got to.
::pb/seek! [(:fps entry) (clip/output-frames (:clip entry) (clip/opens-on (:clip entry))) 0]
::pb/seek! [(:fps entry) (clip/frames (:clip entry) (clip/opens-on (:clip entry))) 0]
::pb/pause! nil
::pb/clock! {:id id :sid (clip/opens-on (:clip entry))}})))
@ -657,18 +655,30 @@
(rf/reg-event-fx
::project-setting
(fn [{:keys [db]} [_ key value]]
(if (or (not (#{:fps :width :height} key))
(if (or (not (#{:width :height} key))
(not (and (integer? value) (pos? value))))
{}
(let [db' (edit/edit db #(if (= key :fps) (clip/set-root-fps % value) (assoc % key value)))
db' (assoc-in db' [:clip key] value)
{:db (-> (edit/edit db #(assoc % key value))
(assoc-in [:clip key] value))})))
(rf/reg-event-fx
::set-fps
;; `:keep-frames` plays every frame for the new tick; `:scale-spans` moves
;; every frame to where the same moment falls. See `domain/retime`. The
;; playhead stays on the frame it was on, or on the same moment.
(fn [{:keys [db]} [_ value mode]]
(let [old (get-in db [:clip :fps])]
(if (or (not (and (integer? value) (pos? value))) (= value old))
{}
(let [scale? (= mode :scale-spans)
db' (-> (edit/edit db #(if scale? (retime/scale-spans % value) (assoc % :fps value)))
(assoc-in [:clip :fps] value))
frame (min (dec (pb/frames db'))
(js/Math.floor (* (get-in db [:playback :frame])
(/ value (get-in db [:clip :fps])))))]
(cond-> {:db db'}
(= key :fps) (assoc :db (assoc-in db' [:playback :frame] frame)
(cond-> (get-in db [:playback :frame])
scale? (-> (* (/ value old)) js/Math.round)))]
{:db (assoc-in db' [:playback :frame] frame)
::pb/seek! [value (pb/frames db') frame]
:dispatch [::pb/refresh-clock]))))))
:dispatch [::pb/refresh-clock]})))))
(rf/reg-event-db
::rename-symbol
@ -690,7 +700,7 @@
(rf/reg-event-db
::symbol-setting
(fn [db [_ sid key value]]
(if-not (and (#{:frames :fps :width :height} key)
(if-not (and (#{:frames :width :height} key)
(or (nil? value) (and (integer? value) (pos? value))))
db
(edit/edit db
@ -708,6 +718,13 @@
(-> (edit/edit db #(assoc-in % [:palettes id] p))
(assoc-in [:ui :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)))))
(rf/reg-event-db
::duplicate-palette
;; A copy of an existing palette, selected so the next colour edit lands on the
@ -878,7 +895,8 @@
{}
{:db (update db :project merge {:busy? true :status "opening…"})
::pb/pause! nil
::open! (or id (:id (:project db)))})))
::open! (let [id (or id (:id (:project db)))]
[id (get-in db [:new-projects id])])})))
(rf/reg-event-fx
::load-stage
@ -939,17 +957,22 @@
(rf/reg-event-fx
::opened
(fn [{:keys [db]} [_ clip-id project-id name seq access]]
(cond->
{:db (-> (pb/show db clip-id)
(update :project merge access
{:id project-id :name name :seq seq
:cid (:cid (store/entry clip-id))
:busy? false
:status (str "opened " name " r" seq)}))
:status (str "opened " name " r" seq)})
(update :new-projects dissoc project-id))
::pb/pause! nil
::pb/seek! (let [{c :clip fps :fps} (store/entry clip-id)]
[fps (clip/output-frames c (clip/opens-on c)) 0])
[fps (clip/frames c (clip/opens-on c)) 0])
::pb/clock! {:id clip-id
:sid (clip/opens-on (:clip (store/entry clip-id)))}}))
:sid (clip/opens-on (:clip (store/entry clip-id)))}}
;; A project just made opens on a document built from what it was made
;; with, which only this client knows until it is saved.
(get-in db [:new-projects project-id]) (assoc :dispatch [::save {:auto? true :force? true}]))))
(rf/reg-event-fx
::failed

View file

@ -38,19 +38,10 @@
(defn editing-frame
"The frame of the open symbol the playhead is showing: the coordinate every
command in here works in, and the only thing `[:playback :frame]` is read for.
THE ONE CONVERSION, AND IT IS IN ONE DIRECTION. `[:playback :frame]` counts the
OUTPUT grid — the clock's, the audio's, export's — and everything authored is in
the frames of the symbol it lives in. A 12fps project holding 30fps symbols puts
2.5 of those frames in one of these, so a command handed the raw playhead was
being handed a number in the wrong units; `clip/shown-frame` is which frame of
the symbol that output frame actually shows. See `docs/one-grid-plan.md`.
`::playback/seek` takes the output frame back, through
`clip/first-output-frame`."
[db clip]
(clip/shown-frame clip (get-in db [:ui :open]) (get-in db [:playback :frame])))
command in here works in. Every symbol counts in the document's one rate, so it
is the playhead."
[db _clip]
(get-in db [:playback :frame]))
(rf/reg-event-db
::rename-node
@ -216,12 +207,10 @@
(editing-frame db clip)))]
(cond-> {:db (apply-command db sid result retry)}
(and (:clip result) (:frame result) rate)
;; Out of the made node's frames into the open symbol's, then out of those
;; into the output frame the transport seeks in — the one place that second
;; step is needed, because this is the one command that moves the playhead.
;; Out of the made node's frames into the open symbol's, which the
;; transport counts in too: the first whole frame that shows it.
(assoc :dispatch [::playback/seek
(clip/first-output-frame clip open
(+ at (/ (:frame result) rate)))]))))
(js/Math.ceil (+ at (/ (:frame result) rate)))]))))
(defn selection-frame
"The playhead as a frame of the symbol that owns `selection`.
@ -857,7 +846,6 @@
{:refused "the playhead is past the end of this symbol"}
:else
(let [new-symbol (cond-> {:id sid :name (name sid)
:fps (clip/fps document host)
;; A fresh cel is one frame for
;; frame-by-frame work. In an
;; ordinary composition the new
@ -1004,7 +992,7 @@
(update-in [:symbols track]
#(merge {:id track :name "palette" :type :palette-track
:display :lane :frames (clip/frames document owner)
:fps (clip/fps document owner) :nodes {}}
:nodes {}}
%)))
[:node track nil []]])
[document target]))
@ -1029,7 +1017,6 @@
(let [seeded (assoc-in document [:symbols sid]
(cond-> {:id sid
:name (if palette? "palette transition" (name sid))
:fps (clip/fps document (:sid where))
:frames 1 :nodes {}}
palette? (assoc :type :palette)))
result (span/place-symbol seeded st (:sid where) uuid sid (:at where)
@ -1105,10 +1092,13 @@
;; the same picture, and a second symbol would only be a second name for it.
;;
;; A STILL ARRIVES WITH NO LENGTH, and is made as long as what is left of the
;; symbol it lands in, at that symbol's rate: it shows the same picture on every
;; frame, so its length is only how long it lasts, and trimming is how that
;; changes afterwards.
(fn [db [_ sym frame point target]]
;; symbol it lands in: it shows the same picture on every frame, so its length
;; is only how long it lasts, and trimming is how that changes afterwards.
;;
;; FOOTAGE ARRIVES WITH ITS RATE, and the symbol does not keep it: its frames
;; are the footage's, and the placement plays them at the speed that makes them
;; real time here — 2.5 for 30fps footage in a 12fps project.
(fn [db [_ {source-fps :fps :as sym} frame point target]]
(let [{document :clip st :store} (store/entry (:clip/current db))
where (if point
(creation-destination db document st frame)
@ -1120,13 +1110,13 @@
sid (or same (clip/free-id #(contains? (:symbols document) %) :tracing))
sym (if same
(clip/symbol document same)
(cond-> (assoc sym :id sid)
(nil? (:frames sym)) (assoc :frames (max 1 (- (clip/frames document host) at))
:fps (clip/fps document host))))
(cond-> (-> sym (dissoc :fps) (assoc :id sid))
(nil? (:frames sym)) (assoc :frames (max 1 (- (clip/frames document host) at)))))
uuid (random-uuid)
result (span/place-symbol (assoc-in document [:symbols sid] sym) st host
uuid sid at
{:extent :grow-symbol
:speed (if source-fps (/ source-fps (:fps document)) 1)
:point (destination-point where point)
:remainder-id (random-uuid)})]
(landed db where uuid
@ -1260,7 +1250,7 @@
(if (and auto-key? (seq values))
(let [{document :clip st :store} (store/entry (:clip/current db))]
(if-let [{:keys [sid id frame]} (nest/placement document st open path
(clip/shown-frame document open f))]
f)]
(assoc-in db [:ui :gesture]
(-> g
(assoc :sid sid :id id :frame frame)

View file

@ -164,12 +164,12 @@
[width height] (clip/stage clip sid)
zoom (max 1 (js/Math.floor (or zoom 1)))]
(when sym
{:frames (clip/output-frames clip sid)
{:frames (clip/frames clip sid)
:fps (:fps clip)
:zoom zoom
:width (* width zoom)
:height (* height zoom)
:seconds (/ (clip/output-frames clip sid) (:fps clip))})))
:seconds (/ (clip/frames clip sid) (:fps clip))})))
(defn run!
"Render symbol `sid` into `exporter`. Promise of `{:filename :blob}`.

View file

@ -715,12 +715,12 @@
"The tracing symbol for `:footage` — `{:id :range :width :height}`, the
footage measured and which of its frames — or nil when the measurement came
from no footage: a synthetic take has nothing to show. See `clip/trace?`."
[{:keys [analysis fps footage]}]
[{:keys [analysis footage]}]
(when-let [{:keys [id range width height]} footage]
{:id :footage :name (or (:source analysis) "footage")
:type :trace
:media {:footage id :range range}
:frames (- (second range) (first range)) :fps fps :width width :height height
:frames (- (second range) (first range)) :width width :height height
:nodes {}}))
;; ---------------------------------------------------------------------------
@ -810,7 +810,7 @@
:features (merged :features) :groups (merged :groups)
:symbols
(into {:main
{:id :main :fps fps :frames nf
{:id :main :frames nf
:nodes (into {:root {:id :root :name "clip" :kind :group :z "a1"
:time {:mode :map :expose expose}}}
(map-indexed
@ -821,7 +821,7 @@
ordered)}}
(concat
(map (fn [[id part]]
[id (assoc (place-in (:symbol part) placement) :fps fps)])
[id (place-in (:symbol part) placement)])
parts)
(when-let [footage (footage-symbol params)]
[[:footage footage]])))}]

View file

@ -170,7 +170,7 @@
(throw (ex-info "regeneration needs retained source landmarks"
{:subject subject})))
base-params (merge take/knobs
{:fps (or (get-in changed [:symbols subject :fps]) (:fps changed))
{:fps (or (:fps analysis) (:fps changed))
:aspect (:aspect analysis)
:analysis analysis})
;; One conditioned anchor for the whole edit, and it is the SUBJECT's.

View file

@ -90,11 +90,10 @@
::frames
:<- [::clip]
:<- [::open]
;; THE TRANSPORT'S LENGTH, in output frames: what the clock counts, what the
;; readout reads and what export writes. The timeline's length is
;; `::open-frames`, which is a different number whenever the open symbol was
;; authored on a different grid — see `docs/one-grid-plan.md`.
(fn [[document sid] _] (clip/output-frames document sid)))
;; THE TRANSPORT'S LENGTH: what the clock counts, what the readout reads and
;; what export writes. Nil for a symbol that is not there; `::open-frames` is
;; the same length read as 0, for drawing a ruler.
(fn [[document sid] _] (clip/frames document sid)))
(rf/reg-sub
::open-frames
@ -110,10 +109,9 @@
:<- [::clip]
:<- [::open]
:<- [::playback/frame]
;; Where the playhead is IN THE OPEN SYMBOL — the one crossing from the output
;; grid for everything that draws or edits in the timeline, and an integer
;; frame of the symbol rather than a fraction between two of them.
(fn [[document sid f] _] (clip/shown-frame document sid f)))
;; Where the playhead is in the open symbol. Every symbol counts in the
;; document's one rate, so this is the playhead itself.
(fn [[_ _ f] _] f))
(rf/reg-sub
::exposure

View file

@ -37,7 +37,7 @@
(let [{document :clip st :store} (store/entry clip-id)]
(reset! carrying (merge {:kind :symbol :sid sid
:label (clip/symbol-name document sid)
:frames (clip/output-frames document sid)
:frames (clip/frames document sid)
;; A symbol cannot go inside itself or inside
;; anything it places. Refused by not ACCEPTING the
;; drop, so the pointer says so while it hovers.

View file

@ -6,6 +6,7 @@
the draw loop stay mounted, and opening a project is showing them again."
(:require [arthur.events.collab :as collab]
[arthur.events.project :as project]
[arthur.ui.settings :as settings]
[arthur.ui.share :as share]
[re-frame.core :as rf]))
@ -26,7 +27,7 @@
[:<>
[:div.index-head
[:h1 "projects"]
[:button {:on-click #(rf/dispatch [::collab/create])} "new project"]]
[settings/new-project "new project"]]
(when error [:p.warn error])
(cond
loading? [:p.dim "…"]

View file

@ -177,7 +177,7 @@
:on-click #(pick! [:remap {}] placements)}
"⇄"]]]]))
(defn- strip
(defn strip
"Every slot of a palette, side by side: what it looks like at a glance."
[{:keys [slots]}]
[:span.strip (for [[i {:keys [hex]}] (map-indexed vector slots)]
@ -279,5 +279,14 @@
[: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"]]])]
: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]]))

View file

@ -25,6 +25,7 @@
[arthur.subs.render :as render]
[arthur.subs.ui :as sub]
[arthur.ui.palette :as palette]
[arthur.ui.settings :as settings]
[re-frame.core :as rf]
[reagent.core :as r]))
@ -89,7 +90,6 @@
(defn- clip-section []
(let [clip @(rf/subscribe [::render/clip])
fps @(rf/subscribe [::playback/fps])
open @(rf/subscribe [::render/open])
frames @(rf/subscribe [::render/frames])
project @(rf/subscribe [::playback/project])
@ -98,8 +98,7 @@
[facts
"stage" (str (:width clip) "×" (:height clip))
"open" (some-> open name)
"length" (str frames " frames")
"rate" (str fps " fps")]
"length" (str frames " frames")]
[:div.inspector-form
[name-field "name" (or (:name project) (:name clip) "")
#(rf/dispatch [::project/rename %])]
@ -107,8 +106,7 @@
#(rf/dispatch [::project/project-setting :width %]) nil busy?]
[number-field "height" (:height clip)
#(rf/dispatch [::project/project-setting :height %]) nil busy?]
[number-field "project fps" fps
#(rf/dispatch [::project/project-setting :fps %]) nil busy?]]]))
[settings/rate busy?]]]))
;; ---------------------------------------------------------------------------
;; a node
@ -639,7 +637,7 @@
[section (or title "symbol")
[facts
"id" (str sid)
"length" (str (:frames sym) " frames at " (clip-domain/fps clip sid) " fps")
"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
@ -647,11 +645,6 @@
#(rf/dispatch [::project/rename-symbol sid %])]
[number-field "length (frames)" (:frames sym)
#(rf/dispatch [::project/symbol-setting sid :frames %]) nil busy?]
[number-field "fps" (clip-domain/fps clip sid)
#(rf/dispatch (if (= sid (clip-domain/opens-on clip))
[::project/project-setting :fps %]
[::project/symbol-setting sid :fps %]))
nil busy?]
[number-field "width" (:width sym)
#(rf/dispatch [::project/symbol-setting sid :width %]) "project default" busy?]
[number-field "height" (:height sym)

View file

@ -0,0 +1,114 @@
(ns arthur.ui.settings
"The two dialogs that decide a document's rate: making one, and changing it.
A RATE IS NOT AN INPUT. Typing 12 over 30 used to rewrite the document as you
typed, and what it did to the symbols already in it was a guess the editor made
on your behalf. Changing it now asks the one question that matters — keep the
frames, or keep the time — and says what each does, before anything moves."
(:require [arthur.domain.clip :as clip]
[arthur.domain.palette :as pal]
[arthur.events.collab :as collab]
[arthur.events.project :as project]
[arthur.subs.playback :as playback]
[arthur.ui.palette :as palette]
[re-frame.core :as rf]
[reagent.core :as r]))
(def rates [8 12 15 24 30])
(def sizes [[320 200] [640 360] [1280 720] [1920 1080]])
(defn- whole [s] (let [n (js/parseInt s 10)] (when (pos? n) n)))
(defn- chips
"One button per choice, the chosen one lit, and a field for anything else."
[label choices chosen show choose! & [field]]
[:div.export-field label
[:div.chips
(doall (for [c choices]
^{:key (show c)}
[:button {:class (when (= c chosen) "on") :on-click #(choose! c)} (show c)]))
field]])
(defn- number [value on-number label]
[:input.chip-number {:type "number" :min 1 :step 1 :value (or value "") :aria-label label
:on-change #(on-number (whole (.. % -target -value)))}])
(defn- dialog [title close! & body]
[:<> [:div.export-scrim {:on-click close!}]
(into [:section.export-dialog {:role "dialog" :aria-modal true :aria-label title}
[:h2 title]]
body)])
(defn new-project
"A button that makes a project, after asking what it is: its name, rate, size
and palette, every one already answered with the default."
[label]
(r/with-let [open? (r/atom false)
draft (r/atom nil)]
(let [{title :name chosen :palette :keys [fps width height] :as d} @draft
close! #(reset! open? false)
ok? (and fps width height)]
[:<>
[:button {:on-click #(do (reset! draft (assoc clip/blank-settings :name "" :palette pal/default-id))
(reset! open? true))}
label]
(when @open?
[dialog "New project" close!
[:label.export-field "name"
[:input {:type "text" :value title :placeholder "untitled" :auto-focus true
:on-change #(swap! draft assoc :name (.. % -target -value))}]]
[chips "frame rate" rates fps #(str % " fps") #(swap! draft assoc :fps %)
[number fps #(swap! draft assoc :fps %) "frame rate"]]
[chips "size" sizes [width height] (fn [[w h]] (str w "×" h))
(fn [[w h]] (swap! draft assoc :width w :height h))
[:span.chip-size
[number width #(swap! draft assoc :width %) "width"] "×"
[number height #(swap! draft assoc :height %) "height"]]]
[:div.export-field "palette"
[:div.palette-list {:role "listbox" :aria-label "palette"}
(doall
(for [p pal/presets]
^{:key (str (:id p))}
[:div.palette-row {:class (when (= chosen (:id p)) "on")}
[:button.choose {:role "option" :aria-selected (= chosen (:id p))
:on-click #(swap! draft assoc :palette (:id p))}
[palette/strip p] [:span.name (:name p)]]]))]
[:span.dim "every one comes with the project; this is the one it starts on"]]
[:div.row
[:button {:disabled (not ok?)
:on-click #(do (close!) (rf/dispatch [::collab/create d]))}
"create"]
[:button {:on-click close!} "cancel"]]])])))
(defn rate
"The document's rate as a button, which opens the question of changing it."
[disabled?]
(r/with-let [open? (r/atom false)
draft (r/atom nil)]
(let [fps @(rf/subscribe [::playback/fps])
close! #(reset! open? false)
to @draft
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")]]
(when @open?
[dialog "Frame rate" close!
[chips (str "from " fps " fps to") rates to #(str % " fps") #(reset! draft %)
[number to #(reset! draft %) "frame rate"]]
[:div.choice
[:button {:disabled (not changed?) :on-click #(apply! :keep-frames)}
[:strong "keep frames"]
[:span.dim (str "every frame stays where it is and plays for 1/" (or to "…")
" s, so the animation runs "
(if (and to (< to fps)) "slower" "faster")
". Sounds still play in seconds.")]]
[:button {:disabled (not changed?) :on-click #(apply! :scale-spans)}
[:strong "keep timing"]
[:span.dim (str "every key, drawing and clip moves to where the same moment falls"
(when (and to (< to fps)) ", and frames that land together keep the later one")
". Footage and tracking keep their own frames and are played to fit.")]]]
[:div.row [:button {:on-click close!} "cancel"]]])])))

View file

@ -72,7 +72,7 @@
"How long the thing this node places is, for a placement carrying no span of
its own. 0 for a node that places nothing, or a reference with nothing there."
[clip sid n]
(if-let [{:keys [at rate]} (clip/source-time clip sid n)]
(if-let [{:keys [at rate]} (node/source-time n)]
(+ at (/ (or (clip/frames clip (node/source n)) 0) rate))
(clip/frames clip sid)))
@ -136,7 +136,7 @@
(letfn [(inside-rows [sid n path depth self span]
;; The rows of the symbol a clip places, mapped into this ruler.
;;
;; A HELD CLIP HAS NO INVERTIBLE CLOCK. `clip/source-time` is nil
;; A HELD CLIP HAS NO INVERTIBLE CLOCK. `node/source-time` is nil
;; for a hold, a loop and an endpoint policy: one source frame is
;; shown for the whole span, so no frame inside it has a place on
;; this ruler. That used to mean the contents were not shown at
@ -146,7 +146,7 @@
;; the key positions, and the bars that would imply them. Refuse
;; rather than guess, without refusing the whole subtree.
(when-let [source (and (= :instance (:kind n)) (node/source n))]
(if-let [source-time (clip/source-time clip sid n)]
(if-let [source-time (node/source-time n)]
(walk source path depth (comp self (time->parent source-time)))
(mapv (fn [row]
(-> row
@ -263,10 +263,9 @@
source-sym (when (= :instance (:kind n))
(clip/symbol clip (node/source n)))
;; `self` maps the instance's local clock. Rows of
;; the symbol it places use its source clock too,
;; including the native-FPS ratio.
;; the symbol it places use its source clock too.
source-self (if-let [t (and source-sym
(clip/source-time clip sid n))]
(node/source-time n))]
(comp self (time->parent t))
self)
lane? (symbol/lane? source-sym)
@ -380,22 +379,17 @@
inside the symbols this one places, mapped into this ruler."
[clip sid expanded]
(if-not (get-in clip [:symbols sid]) []
(let [lane? (symbol/lane? (clip/symbol clip sid))
;; THE MIXER'S INTERVALS ARE IN OUTPUT FRAMES and this ruler is in the
;; symbol's own, so these rows -- and only these -- convert.
;; `nest/audio-tracks` is the mixer's own flattening and audio is
;; measured in seconds, which is why it keeps the transport's grid. A
;; sound's bar may land between two marks, and that is honest: a sound
;; does not have to start on a frame boundary.
own (let [rate (:rate (clip/grid-time clip sid))] #(some-> % (* rate)))
own-span (fn [sp] (when-let [[a b] sp] [(own a) (own b)]))]
;; `nest/audio-tracks` is the mixer's own flattening. A sound's bar may land
;; between two marks, and that is honest: a sound does not have to start on
;; a frame boundary.
(let [lane? (symbol/lane? (clip/symbol clip sid))]
(vec
(mapcat
(fn [[path tracks]]
(let [n (first tracks)
authored (get-in clip [:symbols (:owner n) :nodes (:id n)])
authored->open (comp own (local->parent n))
span (own-span (node/placed-span n))
authored->open (local->parent n)
span (node/placed-span n)
select [:node (:owner n) (:id n) path]
open? (contains? expanded path)
via (when (< 1 (count path)) (str (first path)))
@ -404,12 +398,12 @@
:key-items (key-items authored (:owner n) authored->open)
:slides (if via (subvec path 0 1) path)
:select select :expandable? true :expanded? open? :span span
:keys (mapv own (distinct (mapcat keyed-frames (vals (:channels n)))))}]
:keys (vec (distinct (mapcat keyed-frames (vals (:channels n)))))}]
(cons (cond-> row
(< 1 (count tracks))
(assoc :cels (mapv (fn [i track]
{:id i :label (node-label clip (:id track) track)
:span (own-span (node/placed-span track))
:span (node/placed-span track)
:select select})
(range) tracks)))
(when open? (channel-rows authored (:owner n) path 1 authored->open span)))))
@ -502,8 +496,7 @@
;; where the playhead is somewhere it means something -- and in the open
;; symbol's own frames, which is what the commands take. `frame` and
;; `frames` above are the transport's own numbers and are only read out.
owner-frame (ui/selection-frame clip st open selection
(clip/shown-frame clip open frame))
owner-frame (ui/selection-frame clip st open selection frame)
;; TWO COORDINATES AND THEY ARE NOT THE SAME. `host` is the frame of
;; whatever the selection is positioned in — its lane, for a cel; the
;; symbol, for a free placement — and is what the span commands take.
@ -552,7 +545,7 @@
^{:key r} [:option {:value r} label]))]]
[:span.sep]
;; The same direct timing operations apply to any selected symbol clip,
;; whether it is still a legacy root node or lives in a lane.
;; whether it is placed freely or lives in a lane.
[:div.group.timing-controls {:aria-label "timing"}
[:button {:disabled (not cuttable?) :aria-label "split"
:title "split the selected clip at the playhead"
@ -1382,18 +1375,11 @@
visible (cond-> (vec picture)
(seq sounds) (-> (conj {:path [::sounds] :kind :section :label "audio"})
(into sounds)))
;; Major marks are whole seconds in the OPEN symbol's clock. On long
;; timelines use a whole-number multiple of a second to keep roughly
;; ten labels; never invent an FPS-blind 20/40/60 ruler.
fps (max 1 (or (clip/fps clip open) 1))
;; Major marks are whole seconds. On long timelines use a whole-number
;; multiple of a second to keep roughly ten labels; never invent an
;; FPS-blind 20/40/60 ruler.
fps (max 1 (or (:fps clip) 1))
step (* fps (max 1 (js/Math.ceil (/ frames (* fps 10)))))
;; THE OTHER DIRECTION, AND THE ONLY PLACE THIS PANE GOES THERE. The
;; ruler is in the open symbol's frames and the transport counts output
;; frames, so scrubbing names a mark and seeks to the output frame that
;; first shows it. Several marks can share one output frame when the
;; symbol was authored on a finer grid; that is what playing it at this
;; project's rate means, and the playhead lands where it will really be.
seek-to (fn [^js e n] (clip/first-output-frame clip open (frame-at e n)))
choose-row! (fn [e target]
(let [xs (vec (keep :select visible))
anchor (or @row-anchor selection target)
@ -1527,11 +1513,11 @@
(drag/land! (frame-at e frames) nil))
;; 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 symbol's FPS changed.
;; with the numbered marks whenever the project's FPS changed.
:style {"--tick" (str (* 100 (/ step frames)) "%")}}
[:div.tl-ruler
{:on-pointer-down (fn [^js e]
(rf/dispatch [::pb/seek (seek-to e frames)])
(rf/dispatch [::pb/seek (frame-at e frames)])
(reset! scrubbing true)
;; Capture is what keeps a drag scrubbing once it
;; leaves the ruler, and it is an ENHANCEMENT: it
@ -1547,7 +1533,7 @@
(catch :default _ nil)))
:on-pointer-move (fn [^js e]
(when @scrubbing
(rf/dispatch [::pb/seek (seek-to e frames)])))
(rf/dispatch [::pb/seek (frame-at e frames)])))
:on-pointer-up (fn [_] (reset! scrubbing false))
:on-pointer-cancel (fn [_] (reset! scrubbing false))}
(doall

View file

@ -14,6 +14,7 @@
[arthur.ui.layout :as layout]
[arthur.ui.menu :as menu]
[arthur.ui.openmenu :as openmenu]
[arthur.ui.settings :as settings]
[arthur.ui.share :as share]
[arthur.ui.snapshots :as snapshots]
[arthur.ui.undo :as undo]
@ -74,7 +75,7 @@
;; this strip scrolls, and which panes are open is the one control that
;; must not be the thing off the end of it.
[layout/panes]
[:button {:disabled busy? :on-click #(rf/dispatch [::collab/create])} "new"]
[settings/new-project "new"]
[openmenu/view]
[undo/view]
[menu/view

View file

@ -34,10 +34,10 @@
:features {:face-1/mouth {:id :face-1/mouth :subject :face-1
:symbol :face-1 :area :mouth :nodes [:mouth] :params {}}}
:groups {}
:symbols {:main {:id :main :fps 30 :frames 10
:symbols {:main {:id :main :frames 10
:nodes {:face-1 {:id :face-1 :kind :instance :z "a1"
:source {:symbol :face-1}}}}
:face-1 {:id :face-1 :fps 30 :frames 10
:face-1 {:id :face-1 :frames 10
:nodes {:head {:id :head :kind :group :z "a1"
:measured {[:xform :pos]
{:animated? false :value [0 0]}}}

View file

@ -1,284 +0,0 @@
(ns arthur.domain.cadence-test
(:require [cljs.test :refer [deftest is testing]]
[arthur.domain.bring :as bring]
[arthur.domain.cadence :as cadence]
[arthur.domain.channel :as ch]
[arthur.domain.clip :as clip]
[arthur.domain.leaf :as leaf]
[arthur.domain.nest :as nest]
[arthur.domain.node :as node]
[arthur.domain.palette :as pal]
[arthur.domain.pick :as pick]
[arthur.domain.pose :as pose]
[arthur.ui.timeline :as timeline]))
(def footage
{:fps 30 :width 100 :height 100
:symbols {:main {:id :main :fps 30 :frames 60
:nodes {:mark {:id :mark :kind :rect :z "a" :pose-group :mouth
:channels {[:geom :size] {:animated? true :pose-sampled? true
:dense {:store "sizes" :offset 0 :stride 1 :frames 60}}
[:style :color] (ch/framed :brow)}}}}}})
(def store {"sizes" {:data (js/Float64Array. (clj->js (range 1 61)))}})
(deftest selection-is-integral-and-never-early
(is (= [0 2 5 7 10 12] (mapv #(cadence/frame % 12 30) (range 6))))
(doseq [grid [8 12 24 30 60] native [12 24 30 60] f (range 90)]
(let [selected (cadence/frame f grid native)]
(is (and (integer? selected) (<= selected (/ (* f native) grid))
(< (- (/ (* f native) grid) selected) 1))))))
(deftest changing-output-fps-preserves-dense-content-and-seconds
(let [doc (clip/set-fps footage 12)
draw (clip/resolver doc :main store pal/index-of nil)]
(is (= 24 (clip/output-frames doc :main)))
(is (= (:symbols footage) (:symbols doc)))
(is (= footage (clip/set-fps doc 30)))
(is (= doc (leaf/clip "test" (leaf/leaves "test" doc))))
(is (= [1 3 6 8 11 13] (mapv #(:size (first (draw %))) (range 6))))
;; `nest/inside` and the timeline's rows are in the SYMBOL's own frames --
;; see `docs/one-grid-plan.md`. Frame 7 of :main is frame 7 of :main; the
;; output frame that shows it is 3, and `shown-frame` is the one function
;; that crosses between the two.
(is (= 7 (:frame (nest/inside doc store :main [:mark] 7))))
(is (= 7 (clip/shown-frame doc :main 3)))
(is (= 3 (clip/first-output-frame doc :main 7)))
(is (= [0 60] (:span (first (timeline/rows doc :main #{})))))))
(deftest changing-fps-before-authoring-moves-the-empty-canvas-to-that-grid
(let [doc (clip/set-fps (clip/blank) 12)]
(is (= 12 (:fps doc)))
(is (nil? (get-in doc [:symbols :main :fps])))
(is (= 48 (clip/frames doc :main)))
(is (= 48 (clip/output-frames doc :main)))
(is (= 8 (clip/shown-frame doc :main 8)))
(is (= 8 (clip/first-output-frame doc :main 8)))))
(deftest changing-fps-after-authoring-preserves-the-symbols-native-grid
(let [started (assoc-in (clip/blank) [:symbols :main :nodes :mark]
{:id :mark :kind :rect :z "a"})
doc (clip/set-fps started 12)]
(is (= 30 (get-in doc [:symbols :main :fps])))
(is (= 120 (clip/frames doc :main)))
(is (= 48 (clip/output-frames doc :main)))))
(deftest project-fps-is-the-root-symbols-editing-grid
(let [doc (-> (clip/blank)
(assoc-in [:symbols :main :nodes :child]
{:id :child :kind :instance :z "a"
:source {:symbol :nested}})
(assoc-in [:symbols :nested]
{:id :nested :fps 30 :frames 90 :nodes {}})
(clip/set-root-fps 12))]
(is (= 12 (:fps doc)) "the output grid")
(is (= 12 (clip/fps doc :main)) "is also the root editing grid")
(is (= 30 (clip/fps doc :nested)) "while a nested symbol keeps its own grid")
(is (= 120 (clip/frames doc :main)) "frame positions are not rewritten")))
(deftest crossing-to-the-output-grid-and-back-lands-on-the-frame-it-names
;; `first-output-frame` is the inverse of `shown-frame` as far as a floor has
;; one: seeking to the output frame it names puts the playhead on a frame at or
;; after the mark, never before it, and exactly on it whenever an output frame
;; shows it at all.
(doseq [project [8 12 24 30 60] native [12 24 30 60]]
(let [doc (-> footage (assoc :fps project) (assoc-in [:symbols :main :fps] native))]
(doseq [n (range 40)]
(let [f (clip/first-output-frame doc :main n)]
(is (integer? f))
(is (>= (clip/shown-frame doc :main f) n)
(str n " at " project "/" native))
(is (or (zero? f) (< (clip/shown-frame doc :main (dec f)) n))))))))
(deftest imported-footage-uses-selection-for-picture-and-real-speed-for-audio
(let [tracked (-> footage
(assoc :analyses {"a" {:id "a"}}
:subjects {:face-1 {:id :face-1 :analysis "a"
:source-subject :face-1}}
:features {} :groups {}
:symbols {:main {:id :main :fps 30 :frames 60
:nodes {:face-1 {:id :face-1 :kind :instance
:z "a" :source {:symbol :face-1}}}}
:face-1 (get-in footage [:symbols :main])}))
{doc :clip sid :sid} (bring/take (clip/set-fps (clip/blank) 12)
tracked "take" "video" [15 75])
;; A host authored at 12, with a 30fps source starting half a second in.
doc (-> doc (assoc-in [:symbols :main :fps] 12)
(clip/place-symbol store :main sid 6 :insert nil))
n (get-in doc [:symbols :main :nodes :insert])
draw (clip/resolver doc :main store pal/index-of nil)
[sound] (nest/audio-tracks doc :main)]
(is (= 60 (clip/frames doc sid)))
(is (= 1 (get-in doc [:symbols :take.face-1 :nodes :sound :time :rate])))
(is (= [0 24] (:span n)))
(is (empty? (draw 5)))
(is (= 8 (:size (first (draw 9)))))
(is (= 7 (:frame (nest/inside doc store :main [:insert :face-1 :mark] 9))))
(is (= [-4 -4 4 4] ((pick/bounds-of doc store :main n) 3)))
(is (= [6 30] (node/placed-span sound)))
(is (= 15 (node/local-frame sound 6)))
(is (= 1 (* (get-in sound [:time :rate]) (/ (:fps doc) (:fps sound)))))
(is (= [6 30] (:span (first (timeline/rows doc :main #{[:insert]})))))
(testing "a deliberate half speed still retimes audio"
(let [slow (assoc-in doc [:symbols :main :nodes :insert :playback :speed] 0.5)
[track] (nest/audio-tracks slow :main)]
(is (= 0.5 (* (get-in track [:time :rate]) (/ (:fps slow) (:fps track)))))))))
(deftest generated-faces-own-their-footage-sound
(let [face (fn [id] {:id id :fps 30 :frames 20 :nodes {}})
frozen {:fps 30 :analyses {"a" {:id "a"}}
:subjects {:face-1 {:id :face-1 :analysis "a" :source-subject :face-1}
:face-2 {:id :face-2 :analysis "a" :source-subject :face-2}}
:symbols {:main {:id :main :fps 30 :frames 20
:nodes {:face-1 {:id :face-1 :kind :instance :z "a1"
:source {:symbol :face-1}}
:face-2 {:id :face-2 :kind :instance :z "a2"
:source {:symbol :face-2}}}}
:face-1 (face :face-1)
:face-2 (face :face-2)}}
{doc :clip take :sid} (bring/take (clip/blank) frozen "take" "video" [3 13])
alone (clip/place-symbol doc nil :main :take.face-1 4 :placed-face nil)]
(is (nil? (get-in doc [:symbols take :nodes :sound]))
"the wrapper does not own a sound the face would lose")
(is (= {:footage "video"}
(get-in doc [:symbols :take.face-1 :nodes :sound :source])))
(is (= 1 (count (nest/audio-tracks doc take)))
"the same take recording is not mixed once per detected face")
(is (= 1 (count (nest/audio-tracks alone :main)))
"placing a generated face by itself brings its associated sound")))
;; ---------------------------------------------------------------------------
;; the preserve-snap
;;
;; `footage` above is the cadence with no opinion about content: at 12 out of 30
;; it reads 0, 2, 5, 7, 10, 12, 15 … and the frames between those it shows to
;; nobody. `closure` is the same take with something in one of those gaps worth
;; seeing — docs/frame-selection.md's synthetic case, a mouth that shuts for ONE
;; native frame, 13, which no 12-from-30 slot ever samples.
(defn- sized
"A dense `[:geom :size]` over the whole take. The store holds 1..60, so a DRAWN
SIZE NAMES THE NATIVE FRAME it was read from: size = frame + 1. That is the
whole reason the fixture draws rects — the picture says which frame it is."
[]
{:animated? true :dense {:store "sizes" :offset 0 :stride 1 :frames 60}})
(def closure
"A head that holds still and a mouth that shuts for one native frame.
The cut is the one `flow/freeze` already stores and nothing new: `[:vis]` keys
on the interior, `:hold`, provenance `:roto/mouth-aperture`, hidden meaning
shut. The head's size is NOT `:pose-sampled?` and carries no `:pose-group`,
which is what makes it the control — a head reads the cadence whatever the
mouth does."
{:fps 30 :width 100 :height 100
:symbols
{:face
{:id :face :fps 30 :frames 60
:nodes
{:head {:id :head :kind :rect :z "a"
:channels {[:geom :size] (sized)
[:style :color] (ch/framed :brow)}}
:mouth-in {:id :mouth-in :kind :rect :parent :head :z "b"
:pose-group :mouth
:channels {[:geom :size] (assoc (sized) :pose-sampled? true)
[:style :color] (ch/framed :mouth-dark)
[:vis] (assoc (ch/keyed {0 true, 13 false, 14 true} :hold)
:pose-sampled? true
:generated {:by :roto/mouth-aperture})}}}}}})
(defn- drawn
"What each node draws at output frame `f`, as `node -> size`. A node missing
from the map was not drawn at all, which for the mouth interior IS the shut
mouth: `[:vis]` false takes the part off the frame."
[r f]
(into {} (map (juxt :node :size)) (r f)))
(deftest a-dropped-closure-reaches-exactly-one-output-frame
(let [doc (clip/set-fps closure 12)
n (clip/output-frames doc :face)
r (clip/resolver doc :face store pal/index-of {:snap #{:face}})
fs (mapv #(drawn r %) (range n))]
(is (= 24 n))
(is (not-any? #{13} (map #(cadence/frame % 12 30) (range n)))
"the cadence alone never samples the closure — that is the gap")
(testing "off is the cadence alone, and is what an opts map saying nothing gets"
(doseq [[what opts] [["no opts at all" nil]
["another face switched on" {:snap #{:somebody-else}}]]]
(let [off (clip/resolver doc :face store pal/index-of opts)]
(is (every? #(contains? (drawn off %) :mouth-in) (range n))
(str "with " what " the closure is never recovered"))
(is (= (mapv #(inc (cadence/frame % 12 30)) (range n))
(mapv #(:mouth-in (drawn off %)) (range n)))
(str "with " what " every slot reads what the grid says")))))
(is (= [6] (filterv #(not (contains? (nth fs %) :mouth-in)) (range n)))
"the shut mouth reaches exactly one output frame")
(is (= [1 3 6 8 11 13 nil 18] (mapv :mouth-in (take 8 fs)))
"slot 6 snaps back from 15 to 13; no other slot moves")
(is (= (mapv #(inc (cadence/frame % 12 30)) (range n)) (mapv :head fs))
"and the head reads what the cadence says, on every frame including 6")
(testing "through an instance, where the grid becomes native at the boundary"
(let [host (-> doc
(assoc-in [:symbols :stage] {:id :stage :fps 12 :frames 24 :nodes {}})
(clip/place-symbol store :stage :face 0 :cel nil))
hr (clip/resolver host :stage store pal/index-of {:snap #{:face}})
hfs (mapv #(drawn hr %) (range 24))]
(is (= [6] (filterv #(not (contains? (nth hfs %) [:cel :mouth-in])) (range 24))))
(is (= [1 3 6 8 11 13 nil 18] (mapv #(get % [:cel :mouth-in]) (take 8 hfs))))
(is (= (mapv #(inc (cadence/frame % 12 30)) (range 24))
(mapv #(get % [:cel :head]) hfs)))
(is (= (mapv #(inc (cadence/frame % 12 30)) (range 24))
(let [hostly (clip/resolver host :stage store pal/index-of
{:snap #{:stage}})]
(mapv #(get (drawn hostly %) [:cel :mouth-in]) (range 24))))
"the switch is the FACE's: naming the host that places it marks nothing")
(testing "a hand cut beats a snap, always"
(let [held (pose/put-cut host :stage :cel :mouth 0 0)
kr (clip/resolver held :stage store pal/index-of {:snap #{:face}})
kfs (mapv #(drawn kr %) (range 24))]
(is (= (vec (repeat 24 1)) (mapv #(get % [:cel :mouth-in]) kfs))
"the hand said hold frame 0, so the closure is never recovered")))))))
(deftest preserve-marks-are-the-frames-a-closure-cut-calls-shut
(let [nodes (get-in closure [:symbols :face :nodes])
vis (fn [ch] {:solo {:id :solo :kind :rect :pose-group :solo
:channels {[:vis] ch}}})]
(is (= {:mouth [13]} (pose/marks nodes 60 store))
"one mark, per pose group, for the one frame the cut calls shut")
(is (nil? (pose/marks (select-keys nodes [:head]) 60 store))
"a node with no [:vis] has no closure and gets no marks")
(is (nil? (pose/marks nodes nil store))
"a symbol with no length has no frames to mark")
(testing "a hidden feature is not a closure"
(is (nil? (pose/marks (vis (assoc (ch/keyed {0 true, 13 false, 14 true} :hold)
:generated {:by :pixels/teeth}))
60 store))
"the teeth being occluded says nothing about a mouth shutting")
(is (nil? (pose/marks (vis (ch/keyed {0 true, 13 false, 14 true} :hold)) 60 store))
"and a hand-keyed [:vis] with no provenance is not a cut either"))
(testing "an absent measurement is not a closure"
(is (nil? (pose/marks (vis (assoc (ch/keyed {} :hold)
:generated {:by :roto/blink}))
60 store))
"no value on a frame is not the same fact as shut on it"))))
(deftest a-slot-snaps-back-to-a-mark-and-never-forward
(let [m (pose/marks (get-in closure [:symbols :face :nodes]) 60 store)]
(is (= 13 (pose/snapped-frame m :mouth 12 15))
"slot 6, whose default is 15, reads 13")
(is (= 12 (pose/snapped-frame m :mouth 10 12))
"slot 5 does NOT reach forward from 12 to 13 — that would lead the cut")
(is (= 17 (pose/snapped-frame m :mouth 15 17))
"slot 7 cannot reach back past its own gap to a frame slot 6 showed")
(is (= 13 (pose/snapped-frame m :mouth 12 13))
"a mark that IS the default is simply the default")
(is (= 15 (pose/snapped-frame m :mouth 15 15))
"an empty interval — a slot reading what the one before it read — snaps nothing")
(is (= 15 (pose/snapped-frame m :other 12 15))
"marks are per group: another group's closure is not this one's")
(is (= 15 (pose/snapped-frame nil :mouth 12 15))
"and no marks at all is the cadence back again")
(testing "never later than the slot's own instant, over every grid and native pair"
(doseq [grid [8 12 24 30 60] native [12 24 30 60] f (range 90)]
(let [hi (cadence/frame f grid native)
lo (if (pos? f) (cadence/frame (dec f) grid native) -1)]
(is (<= (pose/snapped-frame m :mouth lo hi) (/ (* f native) grid))))))))

View file

@ -250,10 +250,6 @@
(is (seq (clip/problems (assoc c :root :gone)))))
(testing "without a root, the longest symbol nothing places"
(is (= :outer (clip/opens-on (dissoc c :root)))))
(testing "a document saved before roots opens on :main, not a longer take"
(is (= :main (:root (clip/pin-root (dissoc c :root)))))
(is (= :outer (:root (clip/pin-root (-> c (dissoc :root) (update :symbols dissoc :main))))))
(is (= :loose (:root (clip/pin-root (assoc c :root :loose))))))
(testing "an instance can go into any symbol, and spans that symbol's frames"
(let [[n] (vals (get-in c [:symbols :outer :nodes]))]
(is (= #{:inner} (node/sources n)))
@ -323,7 +319,7 @@
made (clip/new-symbol c :outer id 20 u)]
(is (= :symbol-1 id))
(is (= :symbol-2 (clip/fresh-id made)) "the next one does not collide")
(is (= {:id :symbol-1 :name "symbol-1" :fps 30 :frames 180 :nodes {}}
(is (= {:id :symbol-1 :name "symbol-1" :frames 180 :nodes {}}
(clip/symbol made :symbol-1))
"empty, ordinary, and as long as the rest of what it was placed in")
(is (= {:span [0 180] :time {:mode :map :at 20 :rate 1}}

View file

@ -49,8 +49,8 @@
;; A TIMELINE ID IS A SEGMENT, which is what lets a symbol's nodes be
;; addressed by the same path shape as the clip's own. `main` is the root.
(is (contains? ls "clip/c7/symbol/main"))
(is (= {:frames 229 :fps 30} (get ls "clip/c7/symbol/main"))
"a symbol persists its native grid separately from the output grid")
(is (= {:frames 229} (get ls "clip/c7/symbol/main"))
"a symbol persists its frames and no rate: the rate is the document's")
;; Nodes are local to the face timeline; feature and group ids are clip-wide.
(is (contains? ls "clip/c7/symbol/face-1/node/mouth"))
(is (contains? ls "clip/c7/symbol/face-1/channel/mouth/geom.pts"))

View file

@ -13,7 +13,7 @@
(defn- nested
"Three symbols: :outer places :inner, and :loose is placed by nothing."
[]
(-> (clip/blank)
(-> (clip/blank {:seconds 10})
(assoc-in [:symbols :outer] {:id :outer :frames 200 :nodes {}})
(assoc-in [:symbols :inner] {:id :inner :frames 10 :nodes {}})
(assoc-in [:symbols :loose] {:id :loose :frames 30 :nodes {}})
@ -24,8 +24,8 @@
(let [n {:id :insert :kind :instance :source {:symbol :inner}
:time {:at 5 :rate 1} :span [0 100]
:playback {:in 5 :speed speed :end end}}
c (-> (clip/blank)
(assoc-in [:symbols :inner] {:id :inner :frames 10 :fps 30 :nodes {}})
c (-> (clip/blank {:seconds 10})
(assoc-in [:symbols :inner] {:id :inner :frames 10 :nodes {}})
(assoc-in [:symbols :main :nodes :insert] n))
frame (:frame (nest/placement c nil :main [:insert] 29))
keyed (node/set-keyed-channel n [:xform :rot] frame 1)]
@ -46,7 +46,7 @@
(deftest a-shape-drawn-into-an-instance-lands-where-it-was-drawn
(let [u #uuid "00000000-0000-4000-8000-0000000000dd"
c (-> (clip/blank)
c (-> (clip/blank {:seconds 10})
(assoc-in [:symbols :box] {:id :box :frames 30 :nodes {}})
(clip/place-symbol nil :main :box 10 u nil)
;; moved, turned and doubled, so nothing lines up by accident
@ -73,7 +73,7 @@
{[:xform :pos] (ch/framed pos)
[:xform :rot] (ch/framed rot)
[:xform :scale] (ch/framed [k k])}))
c (-> (clip/blank)
c (-> (clip/blank {:seconds 10})
(assoc-in [:symbols :mid] {:id :mid :frames 40 :nodes {}})
(assoc-in [:symbols :box] {:id :box :frames 30 :nodes {}})
(clip/place-symbol nil :main :mid 10 u nil)
@ -108,7 +108,7 @@
(let [voice {:id :v :kind :audio :source {:footage "f"} :z "a1"
:span [10 40] :time {:mode :map :at -10 :rate 1}
:channels {[:audio :gain] (ch/keyed {0 0.0 5 1.0} :hold)}}
c (-> (clip/blank)
c (-> (clip/blank {:seconds 10})
(assoc-in [:symbols :talk] {:id :talk :frames 30 :nodes {:v voice}})
(clip/place-symbol nil :main :talk 50 #uuid "00000000-0000-4000-8000-0000000000bb" nil))
[t] (nest/audio-tracks c :main)]
@ -145,7 +145,7 @@
{:id id :kind :poly :z "a1" :paint? true :span [4 60]
:channels {[:geom :pts] (ch/keyed (into {} (map (fn [[f dx]] [f [x 10 (+ x dx) 10 x 40]])) keyed) :hold)
[:style :color] (ch/framed :brow)}})]
(-> (clip/blank)
(-> (clip/blank {:seconds 10})
(assoc-in [:symbols :main :nodes :tri] (tri :tri 100 {4 20 30 40}))
(assoc-in [:symbols :box] {:id :box :frames 50 :nodes {:inner (tri :inner 5 {0 10})}})
(clip/place-symbol nil :main :box 10 a-uuid nil)
@ -245,7 +245,7 @@
"but through a loop one frame outside is many inside")))
(deftest linked-audio-follows-picture-moves-but-keeps-independent-edges
(let [c (-> (clip/blank)
(let [c (-> (clip/blank {:seconds 10})
(assoc-in [:symbols :drawing] {:id :drawing :frames 8 :nodes {}})
(clip/place-symbol nil :main :drawing 2 :picture nil)
(clip/place-sound :main {:sound "voice"} "voice" 8 1 2 :voice)
@ -265,7 +265,7 @@
(deftest restacking-is-one-write-to-z
(let [shape (fn [z] {:kind :poly :z z :channels {}})
c (-> (clip/blank)
c (-> (clip/blank {:seconds 10})
(assoc-in [:symbols :main :nodes] {:a (shape "a1") :b (shape "a2") :c (shape "a3")}))
order (fn [c] (map key (sort-by (comp :z val) (get-in c [:symbols :main :nodes]))))
front (:clip (nest/restack c :main [:a] [:c] true))
@ -316,10 +316,10 @@
;; `node/time-of` reads an absent one as `:map`.
:time {:at at :rate 1}
:source {:symbol :draw} :playback {:in 0 :speed 0 :end :stop}})]
(-> (clip/blank)
(-> (clip/blank {:seconds 10})
(assoc :fps 12)
(assoc-in [:symbols :draw] {:id :draw :fps 30 :frames 1 :nodes {}})
(assoc-in [:symbols :lane] {:id :lane :fps 30 :frames 60 :display :lane
(assoc-in [:symbols :draw] {:id :draw :frames 1 :nodes {}})
(assoc-in [:symbols :lane] {:id :lane :frames 60 :display :lane
:nodes {:a (held :a 5) :b (held :b 19)}}))))
(deftest a-drag-in-the-open-symbol-is-frame-for-frame
@ -352,7 +352,7 @@
(let [inner (fn [rate]
(-> (on-twos)
(assoc-in [:symbols :outer]
{:id :outer :fps 30 :frames 60
{:id :outer :frames 60
:nodes {:ins {:id :ins :kind :instance :z "a" :span [0 60]
:time {:mode :map :at 0 :rate rate}
:source {:symbol :lane}
@ -403,7 +403,7 @@
"A shape at a known place, turned and scaled, so that `:pinv` has real work to
do rather than cancelling against an identity."
[]
(-> (clip/blank)
(-> (clip/blank {:seconds 10})
(paint/new-shape :main :shape 0 [0 0 10 0 5 10] :brow)
(update-in [:symbols :main :nodes :shape :channels] merge
{[:xform :pos] (ch/framed [40 25])

View file

@ -0,0 +1,285 @@
(ns arthur.domain.rate-test
(:require [cljs.test :refer [deftest is testing]]
[arthur.domain.bring :as bring]
[arthur.domain.channel :as ch]
[arthur.domain.clip :as clip]
[arthur.domain.leaf :as leaf]
[arthur.domain.nest :as nest]
[arthur.domain.node :as node]
[arthur.domain.palette :as pal]
[arthur.domain.pick :as pick]
[arthur.domain.pose :as pose]
[arthur.domain.retime :as retime]
[arthur.domain.span :as span]
[arthur.ui.timeline :as timeline]))
(defn- sampled
"The frame of 30fps footage a 12fps output frame `f` shows: the latest at or
before its instant."
[f]
(js/Math.floor (* f 2.5)))
(def footage
{:fps 30 :width 100 :height 100
:symbols {:main {:id :main :frames 60
:nodes {:mark {:id :mark :kind :rect :z "a" :pose-group :mouth
:channels {[:geom :size] {:animated? true :pose-sampled? true
:dense {:store "sizes" :offset 0 :stride 1 :frames 60}}
[:style :color] (ch/framed :brow)}}}}}})
(def store {"sizes" {:data (js/Float64Array. (clj->js (range 1 61)))}})
(defn- placed
"`doc` with symbol `sid` placed in a new 12fps `:stage` at `speed`."
[doc sid speed]
(-> doc
(assoc :fps 12)
(assoc-in [:symbols :stage] {:id :stage :frames 24 :nodes {}})
(clip/place-symbol store :stage sid 0 :cel nil speed)))
;; ---------------------------------------------------------------------------
;; one rate
(deftest a-symbol-is-a-bag-of-frames
(testing "a new document is 12fps, four seconds of it"
(let [doc (clip/blank)]
(is (= 12 (:fps doc)))
(is (= 48 (clip/frames doc :main)))
(is (nil? (get-in doc [:symbols :main :fps])))))
(testing "and takes what it is told"
(let [doc (clip/blank {:fps 15 :width 640 :height 360 :palette :arthur/pico-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))))))
(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
;; skipped or showed for a sliver.
(let [doc (-> (clip/blank)
(clip/new-symbol :main :lane 0 :lane-cel))
{made :clip} (span/append-drawing doc :lane :cel :drawing {:at 3})
cel (get-in made [:symbols :lane :nodes :cel])]
(is (nil? (get-in made [:symbols :drawing :fps])))
(is (= [3 4] (node/placed-span cel)))
(is (= {:symbol :drawing :frame 0}
(clip/placed-frame made cel (first (node/placed-span cel))))))))
(deftest footage-is-played-in-real-time-by-its-placement
(let [doc (placed footage :main 2.5)
cel (get-in doc [:symbols :stage :nodes :cel])
draw (clip/resolver doc :stage store pal/index-of nil)]
(is (= [0 24] (:span cel)) "60 frames of 30fps footage are 24 of 12fps")
(is (= (mapv #(inc (sampled %)) (range 6))
(mapv #(:size (first (draw %))) (range 6))))
(is (= 7 (:frame (nest/inside doc store :stage [:cel :mark] 3)))
"inside the footage is the footage's own frame")
(is (= doc (leaf/clip "test" (leaf/leaves "test" doc))))))
;; ---------------------------------------------------------------------------
;; changing the rate
(def authored
{:fps 24 :width 100 :height 100
:symbols {:main {:id :main :frames 48
:nodes {:box {:id :box :kind :rect :z "a" :span [0 48]
:channels {[:geom :size] (ch/keyed {0 1, 1 2, 2 3, 12 4, 24 5} :hold)
[:style :color] (ch/framed :brow)}}
:cel {:id :cel :kind :instance :z "b" :source {:symbol :drawing}
:span [0 4] :time {:mode :map :at 6 :rate 1}}
:take {:id :take :kind :instance :z "c" :source {:symbol :footage}
:span [0 48] :time {:mode :map :at 0 :rate 1}
:playback {:in 0 :speed 1.25 :end :stop}}
:voice {:id :voice :kind :audio :z "d" :source {:sound "s" :fps 30}
:span [0 60] :time {:mode :map :at 12 :rate 1}}}}
:drawing {:id :drawing :frames 4 :nodes {}}
:footage (assoc (get-in footage [:symbols :main]) :id :footage)}})
(deftest keeping-time-moves-every-authored-frame
(let [doc (retime/scale-spans authored 12)
main (get-in doc [:symbols :main])]
(is (= 12 (:fps doc)))
(is (= 24 (:frames main)))
(is (= {0 1, 1 3, 6 4, 12 5} (get-in main [:nodes :box :channels [:geom :size] :keys]))
"keys that land on one frame keep the later one, which was showing")
(is (= [0 24] (get-in main [:nodes :box :span])))
(is (= [3 5] (node/placed-span (get-in main [:nodes :cel]))))
(is (= 2 (clip/frames doc :drawing)) "a symbol's own frames move too")
(testing "footage keeps its frames, and its placement plays them in time"
(is (= 60 (clip/frames doc :footage)))
(is (= 2.5 (get-in main [:nodes :take :playback :speed])))
(is (= [0 24] (get-in main [:nodes :take :span]))))
(testing "a sound moves to the same moment and stays in seconds"
(is (= 6 (get-in main [:nodes :voice :time :at])))
(is (= [0 60] (get-in main [:nodes :voice :span])))
(is (= 1 (get-in main [:nodes :voice :time :rate]))))
(testing "going back up returns every frame that survived"
(let [back (retime/scale-spans doc 24)]
(is (= (get-in authored [:symbols :main :nodes :cel])
(get-in back [:symbols :main :nodes :cel])))
(is (= (get-in authored [:symbols :main :nodes :take :playback])
(get-in back [:symbols :main :nodes :take :playback])))
(is (= 48 (clip/frames back :main)))))))
(deftest a-symbol-of-footage-scales-what-it-places
;; A measured symbol keeps its frames, so an authored symbol it places has to
;; be played faster or slower by it: the same rule read the other way round.
(let [doc (-> footage
(assoc-in [:symbols :main :nodes :drawn]
{:id :drawn :kind :instance :z "b" :source {:symbol :d} :span [0 30]})
(assoc-in [:symbols :d] {:id :d :frames 30 :nodes {}})
(retime/scale-spans 12))]
(is (= 60 (clip/frames doc :main)))
(is (= 12 (clip/frames doc :d)))
(is (= 0.4 (get-in doc [:symbols :main :nodes :drawn :playback :speed])))
(is (= [0 30] (get-in doc [:symbols :main :nodes :drawn :span])))))
;; ---------------------------------------------------------------------------
;; footage brought in
(deftest imported-footage-keeps-its-timing
(let [tracked (-> footage
(assoc :analyses {"a" {:id "a"}}
:subjects {:face-1 {:id :face-1 :analysis "a"
:source-subject :face-1}}
:features {} :groups {}
:symbols {:main {:id :main :frames 60
:nodes {:face-1 {:id :face-1 :kind :instance
:z "a" :source {:symbol :face-1}}}}
:face-1 (get-in footage [:symbols :main])}))
{doc :clip sid :sid} (bring/take (clip/blank) tracked "take" "video" [15 75])
doc (clip/place-symbol doc store :main sid 6 :insert nil)
n (get-in doc [:symbols :main :nodes :insert])
draw (clip/resolver doc :main store pal/index-of nil)
[sound] (nest/audio-tracks doc :main)]
(is (= 24 (clip/frames doc sid)) "the take is moved onto the project's rate")
(is (= 60 (clip/frames doc :take.face-1)) "and the measured face keeps its frames")
(is (= 2.5 (get-in doc [:symbols sid :nodes :face-1 :playback :speed])))
(is (= [0 24] (:span n)))
(is (empty? (draw 5)))
(is (= 8 (:size (first (draw 9)))))
(is (= 7 (:frame (nest/inside doc store :main [:insert :face-1 :mark] 9))))
(is (= [-4 -4 4 4] ((pick/bounds-of doc store :main n) 3)))
(is (= [6 30] (node/placed-span sound)))
(is (= 15 (node/local-frame sound 6)))
(is (= 1 (* (get-in sound [:time :rate]) (/ (:fps doc) (:fps sound))))
"the sound plays at its own speed")
(is (= [6 30] (:span (first (timeline/rows doc :main #{[:insert]})))))
(testing "a deliberate half speed still retimes audio"
(let [slow (assoc-in doc [:symbols :main :nodes :insert :playback :speed] 0.5)
[track] (nest/audio-tracks slow :main)]
(is (= 0.5 (* (get-in track [:time :rate]) (/ (:fps slow) (:fps track)))))))))
(deftest generated-faces-own-their-footage-sound
(let [face (fn [id] {:id id :frames 20 :nodes {}})
frozen {:fps 30 :analyses {"a" {:id "a"}}
:subjects {:face-1 {:id :face-1 :analysis "a" :source-subject :face-1}
:face-2 {:id :face-2 :analysis "a" :source-subject :face-2}}
:symbols {:main {:id :main :frames 20
:nodes {:face-1 {:id :face-1 :kind :instance :z "a1"
:source {:symbol :face-1}}
:face-2 {:id :face-2 :kind :instance :z "a2"
:source {:symbol :face-2}}}}
:face-1 (face :face-1)
:face-2 (face :face-2)}}
{doc :clip take :sid} (bring/take (clip/blank) frozen "take" "video" [3 13])
alone (clip/place-symbol doc nil :main :take.face-1 4 :placed-face nil)]
(is (nil? (get-in doc [:symbols take :nodes :sound]))
"the wrapper does not own a sound the face would lose")
(is (= {:footage "video" :fps 30}
(get-in doc [:symbols :take.face-1 :nodes :sound :source])))
(is (= 1 (count (nest/audio-tracks doc take)))
"the same take recording is not mixed once per detected face")
(is (= 1 (count (nest/audio-tracks alone :main)))
"placing a generated face by itself brings its associated sound")))
;; ---------------------------------------------------------------------------
;; the preserve-snap
;;
;; Footage at speed 2.5 reads 0, 2, 5, 7, 10, 12, 15 … and the frames between
;; those it shows to nobody. `closure` is a take with something in one of those
;; gaps worth seeing — docs/frame-selection.md's synthetic case, a mouth that
;; shuts for ONE native frame, 13, which no 12-from-30 slot ever samples.
(defn- sized
"A dense `[:geom :size]` over the whole take. The store holds 1..60, so a DRAWN
SIZE NAMES THE NATIVE FRAME it was read from: size = frame + 1."
[]
{:animated? true :dense {:store "sizes" :offset 0 :stride 1 :frames 60}})
(def closure
"A head that holds still and a mouth that shuts for one native frame. The
head's size is NOT `:pose-sampled?`, which is what makes it the control."
{:fps 30 :width 100 :height 100
:symbols
{:face
{:id :face :frames 60
:nodes
{:head {:id :head :kind :rect :z "a"
:channels {[:geom :size] (sized)
[:style :color] (ch/framed :brow)}}
:mouth-in {:id :mouth-in :kind :rect :parent :head :z "b"
:pose-group :mouth
:channels {[:geom :size] (assoc (sized) :pose-sampled? true)
[:style :color] (ch/framed :mouth-dark)
[:vis] (assoc (ch/keyed {0 true, 13 false, 14 true} :hold)
:pose-sampled? true
:generated {:by :roto/mouth-aperture})}}}}}})
(defn- drawn [r f] (into {} (map (juxt :node :size)) (r f)))
(deftest a-dropped-closure-reaches-exactly-one-output-frame
(let [host (placed closure :face 2.5)
hr (clip/resolver host :stage store pal/index-of {:snap #{:face}})
hfs (mapv #(drawn hr %) (range 24))]
(is (not-any? #{13} (map sampled (range 24)))
"the speed alone never samples the closure — that is the gap")
(testing "off is the speed alone"
(let [off (clip/resolver host :stage store pal/index-of nil)]
(is (= (mapv #(inc (sampled %)) (range 24))
(mapv #(get (drawn off %) [:cel :mouth-in]) (range 24))))))
(is (= [6] (filterv #(not (contains? (nth hfs %) [:cel :mouth-in])) (range 24)))
"the shut mouth reaches exactly one output frame")
(is (= [1 3 6 8 11 13 nil 18] (mapv #(get % [:cel :mouth-in]) (take 8 hfs)))
"slot 6 snaps back from 15 to 13; no other slot moves")
(is (= (mapv #(inc (sampled %)) (range 24)) (mapv #(get % [:cel :head]) hfs))
"and the head reads what the speed says, on every frame including 6")
(is (= (mapv #(inc (sampled %)) (range 24))
(let [hostly (clip/resolver host :stage store pal/index-of {:snap #{:stage}})]
(mapv #(get (drawn hostly %) [:cel :mouth-in]) (range 24))))
"the switch is the FACE's: naming the host that places it marks nothing")
(testing "a hand cut beats a snap, always"
(let [held (pose/put-cut host :stage :cel :mouth 0 0)
kr (clip/resolver held :stage store pal/index-of {:snap #{:face}})]
(is (= (vec (repeat 24 1)) (mapv #(get (drawn kr %) [:cel :mouth-in]) (range 24))))))))
(deftest preserve-marks-are-the-frames-a-closure-cut-calls-shut
(let [nodes (get-in closure [:symbols :face :nodes])
vis (fn [ch] {:solo {:id :solo :kind :rect :pose-group :solo
:channels {[:vis] ch}}})]
(is (= {:mouth [13]} (pose/marks nodes 60 store)))
(is (nil? (pose/marks (select-keys nodes [:head]) 60 store)))
(is (nil? (pose/marks nodes nil store)))
(testing "a hidden feature is not a closure"
(is (nil? (pose/marks (vis (assoc (ch/keyed {0 true, 13 false, 14 true} :hold)
:generated {:by :pixels/teeth}))
60 store)))
(is (nil? (pose/marks (vis (ch/keyed {0 true, 13 false, 14 true} :hold)) 60 store))))
(testing "an absent measurement is not a closure"
(is (nil? (pose/marks (vis (assoc (ch/keyed {} :hold) :generated {:by :roto/blink}))
60 store))))))
(deftest a-slot-snaps-back-to-a-mark-and-never-forward
(let [m (pose/marks (get-in closure [:symbols :face :nodes]) 60 store)]
(is (= 13 (pose/snapped-frame m :mouth 12 15)))
(is (= 12 (pose/snapped-frame m :mouth 10 12)))
(is (= 17 (pose/snapped-frame m :mouth 15 17)))
(is (= 13 (pose/snapped-frame m :mouth 12 13)))
(is (= 15 (pose/snapped-frame m :mouth 15 15)))
(is (= 15 (pose/snapped-frame m :other 12 15)))
(is (= 15 (pose/snapped-frame nil :mouth 12 15)))
(testing "never later than the slot's own instant, at any speed"
(doseq [speed [0.4 0.5 1 1.25 2 2.5 5] f (range 90)]
(let [frame #(js/Math.floor (* % speed))
hi (frame f)
lo (if (pos? f) (frame (dec f)) -1)]
(is (<= (pose/snapped-frame m :mouth lo hi) (* f speed))))))))

View file

@ -7,7 +7,6 @@
a clip or an output grid: `select` is handed a vector of numbers."
(:require [cljs.test :refer [deftest is testing]]
[clojure.set :as set]
[arthur.domain.cadence :as cadence]
[arthur.domain.pose :as pose]
[arthur.domain.select :as select]))
@ -42,7 +41,7 @@
(range (count signal))))
(deftest a-one-frame-closure-survives-only-because-it-is-protected
(let [grid (mapv #(cadence/frame % 12 30) (range 12))
(let [grid (mapv #(js/Math.floor (* % 2.5)) (range 12))
walk (select/propose 30 aperture {:tolerance tol})
kept (select/propose 30 aperture {:tolerance tol :protect :extrema})]
(testing "a uniform 12-from-30 cadence drops it"

View file

@ -66,7 +66,7 @@
(-> doc
(update-in [:symbols :main :nodes] dissoc :plate)
(assoc-in [:symbols :shot]
{:id :shot :frames 12 :fps 24
{:id :shot :frames 12
:nodes {:girl {:id :girl :kind :instance :z "b" :span [0 12]
:time {:mode :map :at 0 :rate 1}
:source {:symbol :main}
@ -818,7 +818,7 @@
;; "wherever the symbol is placed it is heard". A sequence is one of the places
;; it can be placed, and must not be the one place that goes silent.
(let [doc (assoc-in (document) [:symbols :take]
{:id :take :frames 10 :fps 24
{:id :take :frames 10
:nodes {:pic {:id :pic :kind :instance :z "a"
:source {:symbol :wave} :span [0 10]
:time {:mode :map :at 0 :rate 1}

View file

@ -137,7 +137,7 @@
(def ^:private still
{:id :still :name "ref" :type :trace :media {:image "abc"}
:frames 1 :fps 30 :width 400 :height 200 :nodes {}})
:frames 1 :width 400 :height 200 :nodes {}})
(defn- with-still []
(-> (clip/blank)

View file

@ -11,7 +11,7 @@
:span [0 240] :playback {:in 0 :speed 2 :end :stop
:tracks {:mouth []}}}
document (-> (clip/blank)
(assoc-in [:symbols :spin] {:frames 24 :fps 30 :nodes {}})
(assoc-in [:symbols :spin] {:frames 24 :nodes {}})
(assoc-in [:symbols :main :nodes :wheel] n)
(assoc-in [:symbols :main :nodes :other] (assoc n :id :other)))
id (store/install! {:clip document :store {}} "instance-playback-controls")
@ -19,14 +19,14 @@
[:symbols :main :nodes :wheel])]
(reset! rf-db/app-db {:clip/current id :paint/revision 0})
(rf/dispatch-sync [::project/instance-playback :main :wheel :mode :loop])
(is (= 0 (:frame (clip/placed-frame document :main (current) 24))))
(is (= 0 (:frame (clip/placed-frame document (current) 24))))
(is (= :loop (get-in (current) [:playback :end])))
(is (= 2 (get-in (current) [:playback :speed])))
(rf/dispatch-sync [::project/instance-playback :main :wheel :in 5])
(rf/dispatch-sync [::project/instance-playback :main :wheel :mode :frame])
(is (= 5 (:frame (clip/placed-frame document :main (current) 100))))
(is (= 5 (:frame (clip/placed-frame document (current) 100))))
(rf/dispatch-sync [::project/instance-playback :main :wheel :mode :once])
(is (nil? (clip/placed-frame document :main (current) 100)))
(is (nil? (clip/placed-frame document (current) 100)))
(is (= [0 240] (:span (current))))
(is (= {:mouth []} (get-in (current) [:playback :tracks])))
(let [before (current)]

View file

@ -181,7 +181,7 @@
[:node :main :insert [:insert]]]
(mapv :select (:cels lane))))))
(deftest a-nested-lane-is-drawn-in-the-open-symbols-frame-rate
(deftest a-nested-lane-at-a-speed-is-drawn-in-the-open-symbols-frames
(let [child {:id :cel :kind :instance :z "a" :span [0 2]
:time {:at 4 :rate 1}
:source {:symbol :drawing}
@ -189,20 +189,18 @@
placed {:id :take :kind :instance :z "a" :span [0 12]
:time {:at 0 :rate 1}
:source {:symbol :lane}
:playback {:in 0 :speed 1 :end :stop}}
:playback {:in 0 :speed 2 :end :stop}}
doc (-> (clip/blank)
(assoc :fps 12)
(assoc-in [:symbols :main :fps] 12)
(assoc-in [:symbols :main :frames] 12)
(assoc-in [:symbols :main :nodes] {:take placed})
(assoc-in [:symbols :lane]
{:id :lane :fps 24 :frames 24 :display :lane
{:id :lane :frames 24 :display :lane
:nodes {:cel child}})
(assoc-in [:symbols :drawing]
{:id :drawing :fps 24 :frames 1 :nodes {}}))
{:id :drawing :frames 1 :nodes {}}))
lane (first (filter :lane? (timeline/rows doc :main #{})))]
(is (= [[2 3]] (mapv :span (:cels lane)))
"native frames 4–6 occupy ruler frames 2–3 at twice the frame rate")))
"a lane placed at twice the speed draws its frames 4–6 on ruler frames 2–3")))
(deftest an-ordinary-symbol-keeps-a-row-per-node
(let [doc (update-in (fixture/document) [:symbols :main] dissoc :display)
@ -225,13 +223,13 @@
(deftest creation-walks-to-the-nearest-valid-parent-at-the-playhead
(let [doc (-> (fixture/document)
(assoc-in [:symbols :shot]
{:id :shot :frames 12 :fps 24
{:id :shot :frames 12
:nodes {:girl {:id :girl :kind :instance :z "a"
:span [0 12] :time {:mode :map :at 0 :rate 1}
:source {:symbol :main}
:playback {:in 0 :speed 1 :end :stop}}}})
(assoc-in [:symbols :outer]
{:id :outer :frames 30 :fps 24
{:id :outer :frames 30
:nodes {:take {:id :take :kind :instance :z "a"
:span [0 12] :time {:mode :map :at 10 :rate 1}
:source {:symbol :shot}
@ -468,7 +466,7 @@
;; was missing rather than landing in one that is there.
(update-in [:symbols :main :nodes] dissoc :insert)
(assoc-in [:symbols :shot]
{:id :shot :fps 24 :frames 12
{:id :shot :frames 12
:nodes {:girl {:id :girl :kind :instance :z "b" :span [0 12]
:time {:mode :map :at 0 :rate 1}
:source {:symbol :main}

View file

@ -3,6 +3,7 @@
(:require [cljs.test :refer [deftest is testing async]]
[arthur.domain.channel :as ch]
[arthur.domain.clip :as clip]
[arthur.domain.retime :as retime]
[arthur.domain.palette :as pal]
[arthur.export :as export]))
@ -71,9 +72,8 @@
(is (= 1 (zoom-of nil)) "an absent zoom is 1:1")
(is (= 1 (zoom-of 1.9)))))
(deftest a-lower-output-rate-keeps-native-duration
(let [doc (assoc-in (a-clip {:frames 48 :fps 24}) [:symbols :main :fps] 24)
p (export/plan {:clip (clip/set-fps doc 12) :symbol :main})]
(deftest a-lower-rate-keeping-time-keeps-the-duration
(let [p (export/plan {:clip (retime/scale-spans (a-clip {:frames 48 :fps 24}) 12) :symbol :main})]
(is (= 24 (:frames p)))
(is (= 12 (:fps p)))
(is (= 2 (:seconds p)))))
@ -92,9 +92,9 @@
(done)))
(.catch (fn [e] (is false (str "threw: " e)) (done))))))
(deftest a-lower-output-rate-emits-the-selected-grid
(deftest a-lower-rate-keeping-time-emits-the-new-grid
(async done
(-> (run!* (clip/set-fps (a-clip {:frames 12 :fps 24}) 8))
(-> (run!* (retime/scale-spans (a-clip {:frames 12 :fps 24}) 8))
(.then (fn [{:keys [frames spec]}]
(is (= (range 4) (map :i frames)))
(is (= 8 (:fps spec)))

View file

@ -1821,3 +1821,15 @@ button.share-button:hover, button.share-button.on { filter: brightness(1.1); }
/* Expanded automation lanes expose editable keyframe dots. */
button.tl-key { pointer-events: auto; padding: 0; border: 0; width: 11px; height: 11px; margin: -5.5px; cursor: ew-resize; z-index: 4; opacity: 1; border-radius: 50%; }
button.tl-key.selected { background: var(--pick); box-shadow: 0 0 0 2px var(--pick); }
/* --------------------------------------------------------------------------
the rate and new-project dialogs */
.chips { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.chips button.on { border-color: var(--fg); color: var(--fg); }
.chip-number { width: 5em; }
.chip-size { display: inline-flex; gap: 4px; align-items: center; color: var(--dim); }
.export-dialog .palette-list { max-height: 220px; overflow-y: auto; }
.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; }