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 A document has ONE rate, `:fps`, and a symbol has none. A symbol is a bag of
`:fps` and `:frames`; keys, spans, trace choices and corrections stay in that frames: frame n of anything plays for one tick of the document's clock, at any
native space. A symbol without an explicit rate inherits the document rate; depth of nesting. This is Flash's model — a MovieClip has no frame rate of its
changing project fps first records that rate so its existing timing stays put. own — and it is what makes "one frame" mean the same thing wherever you are
The untouched symbol in a new document is deliberately different: it has no drawing. New documents are 12fps.
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.
An output frame selects the latest native frame at or before its time: ## Footage
`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.
The same boundary selection runs when entering a placed symbol. Placement and Footage is the one thing that really has its own rate. A tracing symbol's frames
artistic speed are applied before selection; the stored `:time :rate` and are the footage's frames and a take's measured faces are the camera's, so they
`:playback :speed` never contain a frame-rate conversion. The derived maps used keep them, and the PLACEMENT plays them at the speed that makes them real time:
by timeline rows, picking and editing account for the units of each symbol. 30fps footage in a 12fps project is an instance with `:playback :speed 2.5`.
`clip/frames` is a native length; `clip/output-frames` is a transport/export It is an ordinary, visible retime. Output frame f shows source frame
length. Resolver frame queries return native frames for edits. `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 A sound counts in its source's own rate (`:source :fps`), and the audio mix
sample-fps fields are gone. Existing exposure, trace choices and per-instance cancels the document's rate out, so only deliberate speed changes affect pitch
pose tracks remain available: a pose track can hold a chosen closed-mouth frame and duration.
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.
Audio uses continuous time through the same derived placement maps, without ## Changing the rate
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.
Earlier imports with frame-rate conversion baked into stored retimes must be The rate is changed through a dialog, not typed over, because there are two
re-imported. There is no second reader for that representation. Source video honest meanings and they are Animate's two (`domain/retime`):
presentation timestamps are still future work; this model assumes constant fps.
* **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] (defn- render! [document sid sources store]
(let [fps (:fps document) (let [fps (:fps document)
frames (clip/output-frames document sid) frames (clip/frames document sid)
tracks (tracks-of document sid) tracks (tracks-of document sid)
output (js/OfflineAudioContext. output (js/OfflineAudioContext.
2 (js/Math.ceil (* (/ frames fps) 44100)) 44100)] 2 (js/Math.ceil (* (/ frames fps) 44100)) 44100)]
@ -234,12 +234,12 @@
(and fallback-url (= sid (clip/opens-on document))) (and fallback-url (= sid (clip/opens-on document)))
(-> (decode! fallback-url) (-> (decode! fallback-url)
(.then (fn [b] (.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})))) {:buffer (fit-buffer b seconds) :seconds seconds}))))
:else :else
{:buffer nil {:buffer nil
:seconds (/ (clip/output-frames document sid) (:fps document))}))))) :seconds (/ (clip/frames document sid) (:fps document))})))))
(defn clock! (defn clock!
"Promise of the URL the transport should play while symbol `sid` is open. "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] (:require [arthur.domain.clip :as clip]
[arthur.domain.feature :as feature] [arthur.domain.feature :as feature]
[arthur.domain.node :as node] [arthur.domain.node :as node]
[arthur.domain.retime :as retime]
[clojure.string :as string])) [clojure.string :as string]))
(defn symbols (defn symbols
@ -28,9 +29,17 @@
Only symbols travel. What else `other` holds — tracking identities, an analysis 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 — 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] [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) reach (into #{} (mapcat #(tree-seq any? (partial clip/places other) %)) roots)
ids (reduce (fn [ids sid] ids (reduce (fn [ids sid]
(let [taken? #(or (contains? (:symbols clip) %) (let [taken? #(or (contains? (:symbols clip) %)
@ -45,7 +54,7 @@
n)) n))
copy (fn [sid] copy (fn [sid]
(-> (clip/symbol other 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)])) %))))] (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) {:clip (reduce (fn [c sid] (assoc-in c [:symbols (ids sid)] (copy sid))) clip reach)
:ids ids})) :ids ids}))
@ -90,11 +99,8 @@
wanted (into {:main root :footage (scoped :footage)} wanted (into {:main root :footage (scoped :footage)}
(map (fn [subject] [subject (scoped subject)])) (map (fn [subject] [subject (scoped subject)]))
(keys (:subjects frozen))) (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 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 ;; All automatic copies name one recording. The audio walk
;; uses this identity only to avoid mixing that recording once ;; uses this identity only to avoid mixing that recording once
;; per detected face when the complete take is played. ;; per detected face when the complete take is played.
@ -102,6 +108,13 @@
;; Source frame `start` plays on the symbol's 0. ;; Source frame `start` plays on the symbol's 0.
:span range :span range
:time {:mode :map :at (- (first range)) :rate 1}} :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 {} feature-ids (into {}
(map (fn [[id f]] (map (fn [[id f]]
[id (feature/owned (ids (:subject f)) (keyword (name id)))])) [id (feature/owned (ids (:subject f)) (keyword (name id)))]))
@ -130,9 +143,7 @@
(:groups frozen))] (:groups frozen))]
{:sid sid {:sid sid
:subject-ids (select-keys ids (keys (:subjects frozen))) :subject-ids (select-keys ids (keys (:subjects frozen)))
:clip (-> (reduce (fn [document face] :clip (-> c
(assoc-in document [:symbols face :nodes :sound] sound))
c faces)
(assoc-in [:symbols sid :name] (str label)) (assoc-in [:symbols sid :name] (str label))
(update :analyses merge (:analyses frozen)) (update :analyses merge (:analyses frozen))
(update :subjects merge subjects) (update :subjects merge subjects)
@ -147,5 +158,4 @@
when there is none. See `clip/place-symbol`." when there is none. See `clip/place-symbol`."
[entry brought store sid host frame uuid point] [entry brought store sid host frame uuid point]
(let [st (merge (:store entry) store)] (let [st (merge (:store entry) store)]
(assoc entry :store st :clip (clip/place-symbol brought st host sid (assoc entry :store st :clip (clip/place-symbol brought st host sid frame uuid point))))
(* frame (:rate (clip/grid-time brought host))) 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 symbol, the way a Flash file names its scene. See `opens-on` for why that
cannot be worked out instead. cannot be worked out instead.
:fps is the output grid. A symbol's optional :fps names the native grid its :fps is the document's one rate. A symbol has none: it is a bag of frames, and
frames were authored or measured on; absent means the document's grid." each of them plays for one tick of the document's clock, as in Flash. See
`docs/time.md`."
(:refer-clojure :exclude [symbol]) (:refer-clojure :exclude [symbol])
(:require [arthur.domain.cadence :as cadence] (:require [arthur.domain.channel :as ch]
[arthur.domain.channel :as ch]
[arthur.domain.feature :as feature] [arthur.domain.feature :as feature]
[arthur.domain.node :as node] [arthur.domain.node :as node]
[arthur.domain.palette :as pal] [arthur.domain.palette :as pal]
@ -101,69 +101,12 @@
[clip sid] [clip sid]
(:frames (symbol clip sid))) (:frames (symbol clip sid)))
(defn fps [clip sid] (or (:fps (symbol clip sid)) (:fps clip))) (defn placed-frame
"Which frame of which symbol instance `n` shows on its own frame `f`, as
(defn set-fps `{:symbol :frame}`, or nil. See `node/placed-frame`."
"Change the output grid without rewriting authored content's frames. [clip n f]
(some-> (node/placed-frame n f (frames clip (node/source n)))
A new document's empty symbol is the one exception: it has no native rate yet, (update :frame js/Math.floor)))
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 stage (defn stage
"A symbol's stage as `[width height]`: its own, or the clip's where it has none. "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 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 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 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 root, nothing places it and it outranks a 120-frame `:main`, and the document
opened on the take, and `set-root-fps` rewrote the take's rate to the opened on the take.
project's on the way in.
A document with no `:root` — a demo, a fixture — still gets the old answer." A document with no `:root` — a demo, a fixture — still gets the old answer."
[clip] [clip]
(let [root (:root clip)] (let [root (:root clip)]
(if (contains? (:symbols clip) root) root (longest-unplaced clip)))) (if (contains? (:symbols clip) root) root (longest-unplaced clip))))
(defn pin-root (def blank-settings
"Give a document saved before `:root` existed the root it was made with. "What a new document is before anyone says otherwise. 12fps because the rough
Every such document started as `blank`, whose root is `:main`, and ids never look is the point; four seconds is long enough to key something into and short
change, so `:main` is the answer wherever it survives; the old rule is only enough to scrub by hand."
for documents that never had one." {:name "untitled" :fps 12 :seconds 4 :width 320 :height 200})
[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)
(defn blank (defn blank
"A new, empty document: one symbol, and nothing in it. "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 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 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 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." none, and `clip-keys` says which fields MAY be here, not which must.
[]
{:name "untitled" `settings` overrides any of `blank-settings`. It starts with every one of
:fps 30 `palette/presets`, and `:palette` is the id of the one it draws with."
:width 320 :height 200 ([] (blank {}))
:palettes {pal/default-id pal/default-palette} ([settings]
:default-palette pal/default-id (let [{:keys [fps seconds width height palette] :as s} (merge blank-settings (into {} (remove (comp nil? val)) settings))
:root :main presets (into {} (map (juxt :id identity)) pal/presets)]
;; No native fps yet: an untouched canvas follows the project grid. Imported {:name (:name s)
;; and generated symbols carry their own rate explicitly. :fps fps
:symbols {:main {:id :main :frames blank-frames :nodes {}}}}) :width width :height height
:palettes presets
:default-palette (if (contains? presets palette) palette pal/default-id)
:root :main
: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]))) (defn- op-path [op] (let [n (:node op)] (if (vector? n) n [n])))
@ -497,7 +422,7 @@
prior (symbol/pre-frame-of own id) prior (symbol/pre-frame-of own id)
length (frames clip (node/source n)) length (frames clip (node/source n))
shown (when (and m (number? local)) shown (when (and m (number? local))
(placed-frame clip sid n local)) (placed-frame clip n local))
frame (:frame shown)] frame (:frame shown)]
(cond (cond
(not (and frame (<= 0 frame) (< frame length))) (not (and frame (<= 0 frame) (< frame length)))
@ -523,7 +448,7 @@
;; the first time on this slot has no ;; the first time on this slot has no
;; previous frame, and so no gap. ;; previous frame, and so no gap.
(or (:frame (when (number? prior) (or (:frame (when (number? prior)
(placed-frame clip sid n prior))) (placed-frame clip n prior)))
(dec frame)) (dec frame))
@active @active
(when (and context? (:palette n)) (when (and context? (:palette n))
@ -554,27 +479,12 @@
(when (contains? @entered id) (when (contains? @entered id)
(symbol/pre-frame-of (get children [id (get @entered id)]) (vec more))) (symbol/pre-frame-of (get children [id (get @entered id)]) (vec more)))
(symbol/pre-frame-of own id))))))] (symbol/pre-frame-of own id))))))]
(let [r (build sid [] nil true) (let [r (build sid [] nil true)]
grid (or (:grid-fps opts) (:fps clip))
native (fps clip sid)]
(reify (reify
IFn IFn
(-invoke [_ f] ;; `pre` is the frame before, so a child placed at a speed is handed
(r (cadence/frame f grid native) ;; the interval `(pre, f]` its preserve-snap may reach back into.
;; `d(k-1)`: the native frame the slot BEFORE this one selected, which (-invoke [_ f] (r f (dec f) (when context? (:default palette)) nil))
;; 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))
symbol/IResolver symbol/IResolver
(world-of [_ path] (symbol/world-of r path)) (world-of [_ path] (symbol/world-of r path))
(frame-of [_ path] (symbol/frame-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 cross is draggable so neither is a trap. What the anchor got wrong was being
invisible and unmovable, not being stored." invisible and unmovable, not being stored."
[clip store sid] [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] 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])) (if b [(min x0 x) (min y0 y) (max x1 x) (max y1 y)] [x y x y]))
[x0 y0 x1 y1] [x0 y0 x1 y1]
@ -644,11 +554,13 @@
The instance's own time starts where it was dropped: `:at frame` means frame 0 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 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, 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 Refused, returning the clip unchanged, when it would make a cycle: a symbol
cannot be placed inside itself or inside anything it places." 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) (let [target (symbol clip sid)
end (frames clip host)] end (frames clip host)]
(if (or (nil? target) (nil? end) (nil? frame) (neg? frame) (>= frame end) (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 ;; Lexicographic draw order, as `domain/paint` does it: an instance made
;; later sits above one made earlier, and neither has to renumber. ;; later sits above one made earlier, and neither has to renumber.
:z (str "z" (js/Date.now) "-" (name sid)) :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} :time {:mode :map :at frame :rate 1}
:source {:symbol sid} :source {:symbol sid}
:playback {:in 0 :speed 1 :end :stop} :playback {:in 0 :speed speed :end :stop}
:channels {[:xform :pos] {:animated? false :channels {[:xform :pos] {:animated? false
:value (if point (mapv - point middle) [0 0])} :value (if point (mapv - point middle) [0 0])}
[:xform :pivot] {:animated? false :value middle}}}))))) [:xform :pivot] {:animated? false :value middle}}}))))))
(defn place-sound (defn place-sound
"Place a sound at host frame `frame`. Its span uses `source`'s fps when "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)) (if (or (nil? end) (symbol clip sid) (nil? frame) (neg? frame) (>= frame end))
clip clip
(-> 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 {}}) :frames (- end frame) :nodes {}})
(place-symbol nil host sid frame uuid nil))))) (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>/subject/<subj> a tracked subject and its params
clip/<cid>/feature/<fid> one feature: area, nodes, params clip/<cid>/feature/<fid> one feature: area, nodes, params
clip/<cid>/group/<gid> an eye pair and its shared 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>/node/<nid> kind, parent, stencil, z, time
clip/<cid>/symbol/<sid>/channel/<nid>/<prop> clip/<cid>/symbol/<sid>/channel/<nid>/<prop>
clip/<cid>/symbol/<sid>/measured/<nid> the channels a re-freeze owns 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 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. segment: `main` in a path is an id like any other.
The timing leaf holds output fps. Each symbol leaf holds its native fps The timing leaf holds the document's one rate. A symbol leaf holds its frame
and frame count, so changing the output grid leaves content untouched. 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, 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 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. ;; disagree with itself about; `clip` puts it back.
(for [[sid sym] (:symbols clip)] (for [[sid sym] (:symbols clip)]
{(at "symbol" (segment sid)) {(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 :palette-track :palette-channel :type :palette-ref :display
:media])}) :media])})
(for [[sid sym] (:symbols clip) (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 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 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. 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; 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 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 ;; the hold pins, not on `local`, and inside a playing insert
;; is its animation at its own in-point and speed. ;; is its animation at its own in-point and speed.
shown (when (number? local) shown (when (number? local)
(clip/placed-frame clip sid (get nodes id) local)) (clip/placed-frame clip (get nodes id) local))
inner (:symbol shown) inner (:symbol shown)
lf (if shown (:frame shown) local)] lf (if shown (:frame shown) local)]
(if (and m (number? local) (if (and m (number? local)
@ -90,9 +90,9 @@
;; Forward sampling above works for holds too. :time is the ;; Forward sampling above works for holds too. :time is the
;; invertible edit map; source in-points and speeds belong in it. ;; invertible edit map; source in-points and speeds belong in it.
:time (when (and time (not-any? #(get-in % [:time :loop?]) chain) :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)) (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)))) (reduced nil))))
{:sid sid :frame (js/Math.floor f) {:sid sid :frame (js/Math.floor f)
:matrix (node/mat) :time node/same-time} :matrix (node/mat) :time node/same-time}
@ -189,8 +189,8 @@
{:time outer :bounds bounds}) {:time outer :bounds bounds})
m (node/then-time (:time parent) (node/time-of n)) m (node/then-time (:time parent) (node/time-of n))
m (if (= :audio (:kind n)) m (if (= :audio (:kind n))
(update m :rate * (/ (or (get-in n [:source :fps]) (clip/fps clip sid)) (update m :rate * (/ (or (get-in n [:source :fps]) (:fps clip))
(clip/fps clip sid))) m)] (:fps clip))) m)]
(assoc acc id {:time m :bounds (window m (:span n) (:bounds parent))}))) (assoc acc id {:time m :bounds (window m (:span n) (:bounds parent))})))
{} (symbol/order nodes))] {} (symbol/order nodes))]
(mapcat (mapcat
@ -200,7 +200,7 @@
(case (:kind n) (case (:kind n)
:audio [(-> n :audio [(-> n
(assoc :parent nil :path (conj path id) :owner sid (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)] :span [(to-local m lo) (to-local m hi)]
:time (merge (:time n) {:mode :map :at (:at m) :rate (:rate m) :offset 0}) :time (merge (:time n) {:mode :map :at (:at m) :rate (:rate m) :offset 0})
:channels (channels (:channels n) m)))] :channels (channels (:channels n) m)))]
@ -210,7 +210,7 @@
length (clip/frames clip child)] length (clip/frames clip child)]
;; A visual freeze does not emit a sustained audio sample. ;; A visual freeze does not emit a sustained audio sample.
(when (and child length (pos? speed)) (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 (-> n
(assoc-in [:playback :end] :stop) (assoc-in [:playback :end] :stop)
(update :time dissoc :loop?)))) (update :time dissoc :loop?))))
@ -225,8 +225,8 @@
periods)))) periods))))
nil)))) nil))))
(sort-by (comp str key) nodes))))] (sort-by (comp str key) nodes))))]
(let [tracks (walk sid (clip/grid-time clip sid) (let [tracks (walk sid node/same-time
[0 (clip/output-frames clip sid)] [] #{})] [0 (clip/frames clip sid)] [] #{})]
(second (second
(reduce (fn [[seen out] track] (reduce (fn [[seen out] track]
(let [link (:media-link track) (let [link (:media-link track)
@ -394,7 +394,7 @@
(mapcat (fn [n] (mapcat (fn [n]
(if (get-in n [:time :loop?]) [nil] (if (get-in n [:time :loop?]) [nil]
(cond-> [(node/time-of n)] (cond-> [(node/time-of n)]
(= :instance (:kind n)) (conj (clip/source-time clip sid n))))) (= :instance (:kind n)) (conj (node/source-time n)))))
chain))) chain)))
sids path)] sids path)]
{:sid (last sids) {:sid (last sids)
@ -627,7 +627,7 @@
start (js/Math.floor (max 0 (apply min (map first spans)))) start (js/Math.floor (max 0 (apply min (map first spans))))
end (min (second whole) (apply max (map second spans))) end (min (second whole) (apply max (map second spans)))
made (-> clip 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))) :frames (max 1 (js/Math.ceil (- end start)))
:nodes {}}) :nodes {}})
(clip/place-symbol store host sid start uuid nil)) (clip/place-symbol store host sid start uuid nil))

View file

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

View file

@ -51,6 +51,45 @@
{:id default-id :name "Arthur" {:id default-id :name "Arthur"
:slots (into entries (repeat 7 {:hex "#000000"}))}) :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] (defn palettes [clip]
(if (seq (:palettes clip)) (:palettes clip) {default-id default-palette})) (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. ;; pixels, in its own coordinates, on every frame it shows one.
:trace :trace
(let [{:keys [width height]} (clip/symbol document (node/source n))] (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 :instance
;; ONE RESOLVER PER DRAWING THE LANE CAN SHOW, built once for the reason ;; ONE RESOLVER PER DRAWING THE LANE CAN SHOW, built once for the reason
@ -192,11 +192,10 @@
;; resolver per frame. ;; resolver per frame.
(let [loop? (get-in n [:time :loop?]) (let [loop? (get-in n [:time :loop?])
resolvers (into {} (map (fn [child] resolvers (into {} (map (fn [child]
[child (clip/resolver document child store [child (clip/resolver document child store pal/index-of {})]))
pal/index-of {:grid-fps (clip/fps document child)})]))
(node/sources n))] (node/sources n))]
(fn [f0] (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))) frames (when shown (clip/frames document (:symbol shown)))
f (when (number? frames) f (when (number? frames)
(if loop? (mod (:frame shown) frames) (:frame shown))) (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 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 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 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 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 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 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 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 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 mouth shut. A placement's frame is a floor, at-or-before, and `rate_test` asserts
`selected <= f*native/grid` over every grid and native pair, so reaching forward `selected <= f*speed` over every speed, so reaching forward
would break a tested invariant as well as the no-lead rule. Reading 13 two 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. 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 frames an artist has to draw a head on, and the frames a performance changes a
shape on. 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 cannot know that the one frame where a mouth is fully shut is worth more than
its neighbours. That is the gap `:protect` closes. its neighbours. That is the gap `:protect` closes.

View file

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

View file

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

View file

@ -64,12 +64,25 @@
(rf/reg-fx (rf/reg-fx
::create! ::create!
(fn [name] (fn [settings]
(-> (http/POST "/api/projects" #js {:name name}) (-> (http/POST "/api/projects" #js {:name (:name settings)})
(.then (fn [^js made] (navigate! (project-path (.-id made) (.-name made))))) (.then (fn [^js made] (rf/dispatch [::created (.-id made) (.-name made) settings])))
(.catch #(rf/dispatch [::refused (ex-message %)]))))) (.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 ;; the socket

View file

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

View file

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

View file

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

View file

@ -38,19 +38,10 @@
(defn editing-frame (defn editing-frame
"The frame of the open symbol the playhead is showing: the coordinate every "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. command in here works in. Every symbol counts in the document's one rate, so it
is the playhead."
THE ONE CONVERSION, AND IT IS IN ONE DIRECTION. `[:playback :frame]` counts the [db _clip]
OUTPUT grid — the clock's, the audio's, export's — and everything authored is in (get-in db [:playback :frame]))
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])))
(rf/reg-event-db (rf/reg-event-db
::rename-node ::rename-node
@ -216,12 +207,10 @@
(editing-frame db clip)))] (editing-frame db clip)))]
(cond-> {:db (apply-command db sid result retry)} (cond-> {:db (apply-command db sid result retry)}
(and (:clip result) (:frame result) rate) (and (:clip result) (:frame result) rate)
;; Out of the made node's frames into the open symbol's, then out of those ;; Out of the made node's frames into the open symbol's, which the
;; into the output frame the transport seeks in — the one place that second ;; transport counts in too: the first whole frame that shows it.
;; step is needed, because this is the one command that moves the playhead.
(assoc :dispatch [::playback/seek (assoc :dispatch [::playback/seek
(clip/first-output-frame clip open (js/Math.ceil (+ at (/ (:frame result) rate)))]))))
(+ at (/ (:frame result) rate)))]))))
(defn selection-frame (defn selection-frame
"The playhead as a frame of the symbol that owns `selection`. "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"} {:refused "the playhead is past the end of this symbol"}
:else :else
(let [new-symbol (cond-> {:id sid :name (name sid) (let [new-symbol (cond-> {:id sid :name (name sid)
:fps (clip/fps document host)
;; A fresh cel is one frame for ;; A fresh cel is one frame for
;; frame-by-frame work. In an ;; frame-by-frame work. In an
;; ordinary composition the new ;; ordinary composition the new
@ -1004,7 +992,7 @@
(update-in [:symbols track] (update-in [:symbols track]
#(merge {:id track :name "palette" :type :palette-track #(merge {:id track :name "palette" :type :palette-track
:display :lane :frames (clip/frames document owner) :display :lane :frames (clip/frames document owner)
:fps (clip/fps document owner) :nodes {}} :nodes {}}
%))) %)))
[:node track nil []]]) [:node track nil []]])
[document target])) [document target]))
@ -1029,7 +1017,6 @@
(let [seeded (assoc-in document [:symbols sid] (let [seeded (assoc-in document [:symbols sid]
(cond-> {:id sid (cond-> {:id sid
:name (if palette? "palette transition" (name sid)) :name (if palette? "palette transition" (name sid))
:fps (clip/fps document (:sid where))
:frames 1 :nodes {}} :frames 1 :nodes {}}
palette? (assoc :type :palette))) palette? (assoc :type :palette)))
result (span/place-symbol seeded st (:sid where) uuid sid (:at where) 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. ;; 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 ;; 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 ;; symbol it lands in: it shows the same picture on every frame, so its length
;; frame, so its length is only how long it lasts, and trimming is how that ;; is only how long it lasts, and trimming is how that changes afterwards.
;; changes afterwards. ;;
(fn [db [_ sym frame point target]] ;; 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)) (let [{document :clip st :store} (store/entry (:clip/current db))
where (if point where (if point
(creation-destination db document st frame) (creation-destination db document st frame)
@ -1120,13 +1110,13 @@
sid (or same (clip/free-id #(contains? (:symbols document) %) :tracing)) sid (or same (clip/free-id #(contains? (:symbols document) %) :tracing))
sym (if same sym (if same
(clip/symbol document same) (clip/symbol document same)
(cond-> (assoc sym :id sid) (cond-> (-> sym (dissoc :fps) (assoc :id sid))
(nil? (:frames sym)) (assoc :frames (max 1 (- (clip/frames document host) at)) (nil? (:frames sym)) (assoc :frames (max 1 (- (clip/frames document host) at)))))
:fps (clip/fps document host))))
uuid (random-uuid) uuid (random-uuid)
result (span/place-symbol (assoc-in document [:symbols sid] sym) st host result (span/place-symbol (assoc-in document [:symbols sid] sym) st host
uuid sid at uuid sid at
{:extent :grow-symbol {:extent :grow-symbol
:speed (if source-fps (/ source-fps (:fps document)) 1)
:point (destination-point where point) :point (destination-point where point)
:remainder-id (random-uuid)})] :remainder-id (random-uuid)})]
(landed db where uuid (landed db where uuid
@ -1260,7 +1250,7 @@
(if (and auto-key? (seq values)) (if (and auto-key? (seq values))
(let [{document :clip st :store} (store/entry (:clip/current db))] (let [{document :clip st :store} (store/entry (:clip/current db))]
(if-let [{:keys [sid id frame]} (nest/placement document st open path (if-let [{:keys [sid id frame]} (nest/placement document st open path
(clip/shown-frame document open f))] f)]
(assoc-in db [:ui :gesture] (assoc-in db [:ui :gesture]
(-> g (-> g
(assoc :sid sid :id id :frame frame) (assoc :sid sid :id id :frame frame)

View file

@ -164,12 +164,12 @@
[width height] (clip/stage clip sid) [width height] (clip/stage clip sid)
zoom (max 1 (js/Math.floor (or zoom 1)))] zoom (max 1 (js/Math.floor (or zoom 1)))]
(when sym (when sym
{:frames (clip/output-frames clip sid) {:frames (clip/frames clip sid)
:fps (:fps clip) :fps (:fps clip)
:zoom zoom :zoom zoom
:width (* width zoom) :width (* width zoom)
:height (* height zoom) :height (* height zoom)
:seconds (/ (clip/output-frames clip sid) (:fps clip))}))) :seconds (/ (clip/frames clip sid) (:fps clip))})))
(defn run! (defn run!
"Render symbol `sid` into `exporter`. Promise of `{:filename :blob}`. "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 "The tracing symbol for `:footage` — `{:id :range :width :height}`, the
footage measured and which of its frames — or nil when the measurement came 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?`." 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] (when-let [{:keys [id range width height]} footage]
{:id :footage :name (or (:source analysis) "footage") {:id :footage :name (or (:source analysis) "footage")
:type :trace :type :trace
:media {:footage id :range range} :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 {}})) :nodes {}}))
;; --------------------------------------------------------------------------- ;; ---------------------------------------------------------------------------
@ -810,7 +810,7 @@
:features (merged :features) :groups (merged :groups) :features (merged :features) :groups (merged :groups)
:symbols :symbols
(into {:main (into {:main
{:id :main :fps fps :frames nf {:id :main :frames nf
:nodes (into {:root {:id :root :name "clip" :kind :group :z "a1" :nodes (into {:root {:id :root :name "clip" :kind :group :z "a1"
:time {:mode :map :expose expose}}} :time {:mode :map :expose expose}}}
(map-indexed (map-indexed
@ -821,7 +821,7 @@
ordered)}} ordered)}}
(concat (concat
(map (fn [[id part]] (map (fn [[id part]]
[id (assoc (place-in (:symbol part) placement) :fps fps)]) [id (place-in (:symbol part) placement)])
parts) parts)
(when-let [footage (footage-symbol params)] (when-let [footage (footage-symbol params)]
[[:footage footage]])))}] [[:footage footage]])))}]

View file

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

View file

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

View file

@ -37,7 +37,7 @@
(let [{document :clip st :store} (store/entry clip-id)] (let [{document :clip st :store} (store/entry clip-id)]
(reset! carrying (merge {:kind :symbol :sid sid (reset! carrying (merge {:kind :symbol :sid sid
:label (clip/symbol-name document 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 ;; A symbol cannot go inside itself or inside
;; anything it places. Refused by not ACCEPTING the ;; anything it places. Refused by not ACCEPTING the
;; drop, so the pointer says so while it hovers. ;; 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." the draw loop stay mounted, and opening a project is showing them again."
(:require [arthur.events.collab :as collab] (:require [arthur.events.collab :as collab]
[arthur.events.project :as project] [arthur.events.project :as project]
[arthur.ui.settings :as settings]
[arthur.ui.share :as share] [arthur.ui.share :as share]
[re-frame.core :as rf])) [re-frame.core :as rf]))
@ -26,7 +27,7 @@
[:<> [:<>
[:div.index-head [:div.index-head
[:h1 "projects"] [:h1 "projects"]
[:button {:on-click #(rf/dispatch [::collab/create])} "new project"]] [settings/new-project "new project"]]
(when error [:p.warn error]) (when error [:p.warn error])
(cond (cond
loading? [:p.dim "…"] loading? [:p.dim "…"]

View file

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

View file

@ -25,6 +25,7 @@
[arthur.subs.render :as render] [arthur.subs.render :as render]
[arthur.subs.ui :as sub] [arthur.subs.ui :as sub]
[arthur.ui.palette :as palette] [arthur.ui.palette :as palette]
[arthur.ui.settings :as settings]
[re-frame.core :as rf] [re-frame.core :as rf]
[reagent.core :as r])) [reagent.core :as r]))
@ -89,7 +90,6 @@
(defn- clip-section [] (defn- clip-section []
(let [clip @(rf/subscribe [::render/clip]) (let [clip @(rf/subscribe [::render/clip])
fps @(rf/subscribe [::playback/fps])
open @(rf/subscribe [::render/open]) open @(rf/subscribe [::render/open])
frames @(rf/subscribe [::render/frames]) frames @(rf/subscribe [::render/frames])
project @(rf/subscribe [::playback/project]) project @(rf/subscribe [::playback/project])
@ -98,8 +98,7 @@
[facts [facts
"stage" (str (:width clip) "×" (:height clip)) "stage" (str (:width clip) "×" (:height clip))
"open" (some-> open name) "open" (some-> open name)
"length" (str frames " frames") "length" (str frames " frames")]
"rate" (str fps " fps")]
[:div.inspector-form [:div.inspector-form
[name-field "name" (or (:name project) (:name clip) "") [name-field "name" (or (:name project) (:name clip) "")
#(rf/dispatch [::project/rename %])] #(rf/dispatch [::project/rename %])]
@ -107,8 +106,7 @@
#(rf/dispatch [::project/project-setting :width %]) nil busy?] #(rf/dispatch [::project/project-setting :width %]) nil busy?]
[number-field "height" (:height clip) [number-field "height" (:height clip)
#(rf/dispatch [::project/project-setting :height %]) nil busy?] #(rf/dispatch [::project/project-setting :height %]) nil busy?]
[number-field "project fps" fps [settings/rate busy?]]]))
#(rf/dispatch [::project/project-setting :fps %]) nil busy?]]]))
;; --------------------------------------------------------------------------- ;; ---------------------------------------------------------------------------
;; a node ;; a node
@ -639,7 +637,7 @@
[section (or title "symbol") [section (or title "symbol")
[facts [facts
"id" (str sid) "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)) "stage" (let [[w h] (clip-domain/stage clip sid)] (str w "×" h))
"nodes" (str (count (:nodes sym)))] "nodes" (str (count (:nodes sym)))]
[:div.inspector-form [:div.inspector-form
@ -647,11 +645,6 @@
#(rf/dispatch [::project/rename-symbol sid %])] #(rf/dispatch [::project/rename-symbol sid %])]
[number-field "length (frames)" (:frames sym) [number-field "length (frames)" (:frames sym)
#(rf/dispatch [::project/symbol-setting sid :frames %]) nil busy?] #(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) [number-field "width" (:width sym)
#(rf/dispatch [::project/symbol-setting sid :width %]) "project default" busy?] #(rf/dispatch [::project/symbol-setting sid :width %]) "project default" busy?]
[number-field "height" (:height sym) [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 "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." its own. 0 for a node that places nothing, or a reference with nothing there."
[clip sid n] [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)) (+ at (/ (or (clip/frames clip (node/source n)) 0) rate))
(clip/frames clip sid))) (clip/frames clip sid)))
@ -136,7 +136,7 @@
(letfn [(inside-rows [sid n path depth self span] (letfn [(inside-rows [sid n path depth self span]
;; The rows of the symbol a clip places, mapped into this ruler. ;; 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 ;; 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 ;; 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 ;; 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 ;; the key positions, and the bars that would imply them. Refuse
;; rather than guess, without refusing the whole subtree. ;; rather than guess, without refusing the whole subtree.
(when-let [source (and (= :instance (:kind n)) (node/source n))] (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))) (walk source path depth (comp self (time->parent source-time)))
(mapv (fn [row] (mapv (fn [row]
(-> row (-> row
@ -263,10 +263,9 @@
source-sym (when (= :instance (:kind n)) source-sym (when (= :instance (:kind n))
(clip/symbol clip (node/source n))) (clip/symbol clip (node/source n)))
;; `self` maps the instance's local clock. Rows of ;; `self` maps the instance's local clock. Rows of
;; the symbol it places use its source clock too, ;; the symbol it places use its source clock too.
;; including the native-FPS ratio.
source-self (if-let [t (and source-sym source-self (if-let [t (and source-sym
(clip/source-time clip sid n))] (node/source-time n))]
(comp self (time->parent t)) (comp self (time->parent t))
self) self)
lane? (symbol/lane? source-sym) lane? (symbol/lane? source-sym)
@ -380,22 +379,17 @@
inside the symbols this one places, mapped into this ruler." inside the symbols this one places, mapped into this ruler."
[clip sid expanded] [clip sid expanded]
(if-not (get-in clip [:symbols sid]) [] (if-not (get-in clip [:symbols sid]) []
(let [lane? (symbol/lane? (clip/symbol clip sid)) ;; `nest/audio-tracks` is the mixer's own flattening. A sound's bar may land
;; THE MIXER'S INTERVALS ARE IN OUTPUT FRAMES and this ruler is in the ;; between two marks, and that is honest: a sound does not have to start on
;; symbol's own, so these rows -- and only these -- convert. ;; a frame boundary.
;; `nest/audio-tracks` is the mixer's own flattening and audio is (let [lane? (symbol/lane? (clip/symbol clip sid))]
;; 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)]))]
(vec (vec
(mapcat (mapcat
(fn [[path tracks]] (fn [[path tracks]]
(let [n (first tracks) (let [n (first tracks)
authored (get-in clip [:symbols (:owner n) :nodes (:id n)]) authored (get-in clip [:symbols (:owner n) :nodes (:id n)])
authored->open (comp own (local->parent n)) authored->open (local->parent n)
span (own-span (node/placed-span n)) span (node/placed-span n)
select [:node (:owner n) (:id n) path] select [:node (:owner n) (:id n) path]
open? (contains? expanded path) open? (contains? expanded path)
via (when (< 1 (count path)) (str (first path))) via (when (< 1 (count path)) (str (first path)))
@ -404,12 +398,12 @@
:key-items (key-items authored (:owner n) authored->open) :key-items (key-items authored (:owner n) authored->open)
:slides (if via (subvec path 0 1) path) :slides (if via (subvec path 0 1) path)
:select select :expandable? true :expanded? open? :span span :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 (cons (cond-> row
(< 1 (count tracks)) (< 1 (count tracks))
(assoc :cels (mapv (fn [i track] (assoc :cels (mapv (fn [i track]
{:id i :label (node-label clip (:id track) track) {:id i :label (node-label clip (:id track) track)
:span (own-span (node/placed-span track)) :span (node/placed-span track)
:select select}) :select select})
(range) tracks))) (range) tracks)))
(when open? (channel-rows authored (:owner n) path 1 authored->open span))))) (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 ;; where the playhead is somewhere it means something -- and in the open
;; symbol's own frames, which is what the commands take. `frame` and ;; 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. ;; `frames` above are the transport's own numbers and are only read out.
owner-frame (ui/selection-frame clip st open selection owner-frame (ui/selection-frame clip st open selection frame)
(clip/shown-frame clip open frame))
;; TWO COORDINATES AND THEY ARE NOT THE SAME. `host` is the frame of ;; 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 ;; whatever the selection is positioned in — its lane, for a cel; the
;; symbol, for a free placement — and is what the span commands take. ;; symbol, for a free placement — and is what the span commands take.
@ -552,7 +545,7 @@
^{:key r} [:option {:value r} label]))]] ^{:key r} [:option {:value r} label]))]]
[:span.sep] [:span.sep]
;; The same direct timing operations apply to any selected symbol clip, ;; 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"} [:div.group.timing-controls {:aria-label "timing"}
[:button {:disabled (not cuttable?) :aria-label "split" [:button {:disabled (not cuttable?) :aria-label "split"
:title "split the selected clip at the playhead" :title "split the selected clip at the playhead"
@ -1382,18 +1375,11 @@
visible (cond-> (vec picture) visible (cond-> (vec picture)
(seq sounds) (-> (conj {:path [::sounds] :kind :section :label "audio"}) (seq sounds) (-> (conj {:path [::sounds] :kind :section :label "audio"})
(into sounds))) (into sounds)))
;; Major marks are whole seconds in the OPEN symbol's clock. On long ;; Major marks are whole seconds. On long timelines use a whole-number
;; timelines use a whole-number multiple of a second to keep roughly ;; multiple of a second to keep roughly ten labels; never invent an
;; ten labels; never invent an FPS-blind 20/40/60 ruler. ;; FPS-blind 20/40/60 ruler.
fps (max 1 (or (clip/fps clip open) 1)) fps (max 1 (or (:fps clip) 1))
step (* fps (max 1 (js/Math.ceil (/ frames (* fps 10))))) 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] choose-row! (fn [e target]
(let [xs (vec (keep :select visible)) (let [xs (vec (keep :select visible))
anchor (or @row-anchor selection target) anchor (or @row-anchor selection target)
@ -1527,11 +1513,11 @@
(drag/land! (frame-at e frames) nil)) (drag/land! (frame-at e frames) nil))
;; The rows and ruler share this exact major interval. Keeping a ;; The rows and ruler share this exact major interval. Keeping a
;; second, hard-coded five-frame grid here made its lines disagree ;; 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)) "%")}} :style {"--tick" (str (* 100 (/ step frames)) "%")}}
[:div.tl-ruler [:div.tl-ruler
{:on-pointer-down (fn [^js e] {: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) (reset! scrubbing true)
;; Capture is what keeps a drag scrubbing once it ;; Capture is what keeps a drag scrubbing once it
;; leaves the ruler, and it is an ENHANCEMENT: it ;; leaves the ruler, and it is an ENHANCEMENT: it
@ -1547,7 +1533,7 @@
(catch :default _ nil))) (catch :default _ nil)))
:on-pointer-move (fn [^js e] :on-pointer-move (fn [^js e]
(when @scrubbing (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-up (fn [_] (reset! scrubbing false))
:on-pointer-cancel (fn [_] (reset! scrubbing false))} :on-pointer-cancel (fn [_] (reset! scrubbing false))}
(doall (doall

View file

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

View file

@ -34,10 +34,10 @@
:features {:face-1/mouth {:id :face-1/mouth :subject :face-1 :features {:face-1/mouth {:id :face-1/mouth :subject :face-1
:symbol :face-1 :area :mouth :nodes [:mouth] :params {}}} :symbol :face-1 :area :mouth :nodes [:mouth] :params {}}}
:groups {} :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" :nodes {:face-1 {:id :face-1 :kind :instance :z "a1"
:source {:symbol :face-1}}}} :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" :nodes {:head {:id :head :kind :group :z "a1"
:measured {[:xform :pos] :measured {[:xform :pos]
{:animated? false :value [0 0]}}} {: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))))) (is (seq (clip/problems (assoc c :root :gone)))))
(testing "without a root, the longest symbol nothing places" (testing "without a root, the longest symbol nothing places"
(is (= :outer (clip/opens-on (dissoc c :root))))) (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" (testing "an instance can go into any symbol, and spans that symbol's frames"
(let [[n] (vals (get-in c [:symbols :outer :nodes]))] (let [[n] (vals (get-in c [:symbols :outer :nodes]))]
(is (= #{:inner} (node/sources n))) (is (= #{:inner} (node/sources n)))
@ -323,7 +319,7 @@
made (clip/new-symbol c :outer id 20 u)] made (clip/new-symbol c :outer id 20 u)]
(is (= :symbol-1 id)) (is (= :symbol-1 id))
(is (= :symbol-2 (clip/fresh-id made)) "the next one does not collide") (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)) (clip/symbol made :symbol-1))
"empty, ordinary, and as long as the rest of what it was placed in") "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}} (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 ;; 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. ;; addressed by the same path shape as the clip's own. `main` is the root.
(is (contains? ls "clip/c7/symbol/main")) (is (contains? ls "clip/c7/symbol/main"))
(is (= {:frames 229 :fps 30} (get ls "clip/c7/symbol/main")) (is (= {:frames 229} (get ls "clip/c7/symbol/main"))
"a symbol persists its native grid separately from the output grid") "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. ;; 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/node/mouth"))
(is (contains? ls "clip/c7/symbol/face-1/channel/mouth/geom.pts")) (is (contains? ls "clip/c7/symbol/face-1/channel/mouth/geom.pts"))

View file

@ -13,7 +13,7 @@
(defn- nested (defn- nested
"Three symbols: :outer places :inner, and :loose is placed by nothing." "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 :outer] {:id :outer :frames 200 :nodes {}})
(assoc-in [:symbols :inner] {:id :inner :frames 10 :nodes {}}) (assoc-in [:symbols :inner] {:id :inner :frames 10 :nodes {}})
(assoc-in [:symbols :loose] {:id :loose :frames 30 :nodes {}}) (assoc-in [:symbols :loose] {:id :loose :frames 30 :nodes {}})
@ -24,8 +24,8 @@
(let [n {:id :insert :kind :instance :source {:symbol :inner} (let [n {:id :insert :kind :instance :source {:symbol :inner}
:time {:at 5 :rate 1} :span [0 100] :time {:at 5 :rate 1} :span [0 100]
:playback {:in 5 :speed speed :end end}} :playback {:in 5 :speed speed :end end}}
c (-> (clip/blank) c (-> (clip/blank {:seconds 10})
(assoc-in [:symbols :inner] {:id :inner :frames 10 :fps 30 :nodes {}}) (assoc-in [:symbols :inner] {:id :inner :frames 10 :nodes {}})
(assoc-in [:symbols :main :nodes :insert] n)) (assoc-in [:symbols :main :nodes :insert] n))
frame (:frame (nest/placement c nil :main [:insert] 29)) frame (:frame (nest/placement c nil :main [:insert] 29))
keyed (node/set-keyed-channel n [:xform :rot] frame 1)] 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 (deftest a-shape-drawn-into-an-instance-lands-where-it-was-drawn
(let [u #uuid "00000000-0000-4000-8000-0000000000dd" (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 {}}) (assoc-in [:symbols :box] {:id :box :frames 30 :nodes {}})
(clip/place-symbol nil :main :box 10 u nil) (clip/place-symbol nil :main :box 10 u nil)
;; moved, turned and doubled, so nothing lines up by accident ;; moved, turned and doubled, so nothing lines up by accident
@ -73,7 +73,7 @@
{[:xform :pos] (ch/framed pos) {[:xform :pos] (ch/framed pos)
[:xform :rot] (ch/framed rot) [:xform :rot] (ch/framed rot)
[:xform :scale] (ch/framed [k k])})) [: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 :mid] {:id :mid :frames 40 :nodes {}})
(assoc-in [:symbols :box] {:id :box :frames 30 :nodes {}}) (assoc-in [:symbols :box] {:id :box :frames 30 :nodes {}})
(clip/place-symbol nil :main :mid 10 u nil) (clip/place-symbol nil :main :mid 10 u nil)
@ -108,7 +108,7 @@
(let [voice {:id :v :kind :audio :source {:footage "f"} :z "a1" (let [voice {:id :v :kind :audio :source {:footage "f"} :z "a1"
:span [10 40] :time {:mode :map :at -10 :rate 1} :span [10 40] :time {:mode :map :at -10 :rate 1}
:channels {[:audio :gain] (ch/keyed {0 0.0 5 1.0} :hold)}} :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}}) (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)) (clip/place-symbol nil :main :talk 50 #uuid "00000000-0000-4000-8000-0000000000bb" nil))
[t] (nest/audio-tracks c :main)] [t] (nest/audio-tracks c :main)]
@ -145,7 +145,7 @@
{:id id :kind :poly :z "a1" :paint? true :span [4 60] {: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) :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)}})] [: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 :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})}}) (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) (clip/place-symbol nil :main :box 10 a-uuid nil)
@ -245,7 +245,7 @@
"but through a loop one frame outside is many inside"))) "but through a loop one frame outside is many inside")))
(deftest linked-audio-follows-picture-moves-but-keeps-independent-edges (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 {}}) (assoc-in [:symbols :drawing] {:id :drawing :frames 8 :nodes {}})
(clip/place-symbol nil :main :drawing 2 :picture nil) (clip/place-symbol nil :main :drawing 2 :picture nil)
(clip/place-sound :main {:sound "voice"} "voice" 8 1 2 :voice) (clip/place-sound :main {:sound "voice"} "voice" 8 1 2 :voice)
@ -265,7 +265,7 @@
(deftest restacking-is-one-write-to-z (deftest restacking-is-one-write-to-z
(let [shape (fn [z] {:kind :poly :z z :channels {}}) (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")})) (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])))) 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)) front (:clip (nest/restack c :main [:a] [:c] true))
@ -316,10 +316,10 @@
;; `node/time-of` reads an absent one as `:map`. ;; `node/time-of` reads an absent one as `:map`.
:time {:at at :rate 1} :time {:at at :rate 1}
:source {:symbol :draw} :playback {:in 0 :speed 0 :end :stop}})] :source {:symbol :draw} :playback {:in 0 :speed 0 :end :stop}})]
(-> (clip/blank) (-> (clip/blank {:seconds 10})
(assoc :fps 12) (assoc :fps 12)
(assoc-in [:symbols :draw] {:id :draw :fps 30 :frames 1 :nodes {}}) (assoc-in [:symbols :draw] {:id :draw :frames 1 :nodes {}})
(assoc-in [:symbols :lane] {:id :lane :fps 30 :frames 60 :display :lane (assoc-in [:symbols :lane] {:id :lane :frames 60 :display :lane
:nodes {:a (held :a 5) :b (held :b 19)}})))) :nodes {:a (held :a 5) :b (held :b 19)}}))))
(deftest a-drag-in-the-open-symbol-is-frame-for-frame (deftest a-drag-in-the-open-symbol-is-frame-for-frame
@ -352,7 +352,7 @@
(let [inner (fn [rate] (let [inner (fn [rate]
(-> (on-twos) (-> (on-twos)
(assoc-in [:symbols :outer] (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] :nodes {:ins {:id :ins :kind :instance :z "a" :span [0 60]
:time {:mode :map :at 0 :rate rate} :time {:mode :map :at 0 :rate rate}
:source {:symbol :lane} :source {:symbol :lane}
@ -403,7 +403,7 @@
"A shape at a known place, turned and scaled, so that `:pinv` has real work to "A shape at a known place, turned and scaled, so that `:pinv` has real work to
do rather than cancelling against an identity." 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) (paint/new-shape :main :shape 0 [0 0 10 0 5 10] :brow)
(update-in [:symbols :main :nodes :shape :channels] merge (update-in [:symbols :main :nodes :shape :channels] merge
{[:xform :pos] (ch/framed [40 25]) {[: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." a clip or an output grid: `select` is handed a vector of numbers."
(:require [cljs.test :refer [deftest is testing]] (:require [cljs.test :refer [deftest is testing]]
[clojure.set :as set] [clojure.set :as set]
[arthur.domain.cadence :as cadence]
[arthur.domain.pose :as pose] [arthur.domain.pose :as pose]
[arthur.domain.select :as select])) [arthur.domain.select :as select]))
@ -42,7 +41,7 @@
(range (count signal)))) (range (count signal))))
(deftest a-one-frame-closure-survives-only-because-it-is-protected (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}) walk (select/propose 30 aperture {:tolerance tol})
kept (select/propose 30 aperture {:tolerance tol :protect :extrema})] kept (select/propose 30 aperture {:tolerance tol :protect :extrema})]
(testing "a uniform 12-from-30 cadence drops it" (testing "a uniform 12-from-30 cadence drops it"

View file

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

View file

@ -137,7 +137,7 @@
(def ^:private still (def ^:private still
{:id :still :name "ref" :type :trace :media {:image "abc"} {: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 [] (defn- with-still []
(-> (clip/blank) (-> (clip/blank)

View file

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

View file

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

View file

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