fix frme rte things
This commit is contained in:
parent
9af21c5d10
commit
a10d7b2d9f
44 changed files with 889 additions and 716 deletions
|
|
@ -134,7 +134,7 @@
|
|||
|
||||
(defn- render! [document sid sources store]
|
||||
(let [fps (:fps document)
|
||||
frames (clip/output-frames document sid)
|
||||
frames (clip/frames document sid)
|
||||
tracks (tracks-of document sid)
|
||||
output (js/OfflineAudioContext.
|
||||
2 (js/Math.ceil (* (/ frames fps) 44100)) 44100)]
|
||||
|
|
@ -234,12 +234,12 @@
|
|||
(and fallback-url (= sid (clip/opens-on document)))
|
||||
(-> (decode! fallback-url)
|
||||
(.then (fn [b]
|
||||
(let [seconds (/ (clip/output-frames document sid) (:fps document))]
|
||||
(let [seconds (/ (clip/frames document sid) (:fps document))]
|
||||
{:buffer (fit-buffer b seconds) :seconds seconds}))))
|
||||
|
||||
:else
|
||||
{:buffer nil
|
||||
:seconds (/ (clip/output-frames document sid) (:fps document))})))))
|
||||
:seconds (/ (clip/frames document sid) (:fps document))})))))
|
||||
|
||||
(defn clock!
|
||||
"Promise of the URL the transport should play while symbol `sid` is open.
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
(:require [arthur.domain.clip :as clip]
|
||||
[arthur.domain.feature :as feature]
|
||||
[arthur.domain.node :as node]
|
||||
[arthur.domain.retime :as retime]
|
||||
[clojure.string :as string]))
|
||||
|
||||
(defn symbols
|
||||
|
|
@ -28,9 +29,17 @@
|
|||
|
||||
Only symbols travel. What else `other` holds — tracking identities, an analysis
|
||||
— is the caller's decision, because whether it can come too depends on what
|
||||
`clip` already has."
|
||||
`clip` already has.
|
||||
|
||||
WHAT COMES IN KEEPS ITS TIMING. `other` is moved onto this document's rate
|
||||
first, with `retime/scale-spans`, so a take measured at 30 plays in seconds
|
||||
here as it did there; footage and measurements keep their own frames and the
|
||||
placements of them take up the difference."
|
||||
[clip other roots wanted]
|
||||
(let [;; A tree walk is safe because placing cannot make a cycle.
|
||||
(let [other (cond-> other
|
||||
(and (:fps clip) (:fps other) (not= (:fps clip) (:fps other)))
|
||||
(retime/scale-spans (:fps clip)))
|
||||
;; A tree walk is safe because placing cannot make a cycle.
|
||||
reach (into #{} (mapcat #(tree-seq any? (partial clip/places other) %)) roots)
|
||||
ids (reduce (fn [ids sid]
|
||||
(let [taken? #(or (contains? (:symbols clip) %)
|
||||
|
|
@ -45,7 +54,7 @@
|
|||
n))
|
||||
copy (fn [sid]
|
||||
(-> (clip/symbol other sid)
|
||||
(assoc :id (ids sid) :fps (or (:fps (clip/symbol other sid)) (:fps other)))
|
||||
(assoc :id (ids sid))
|
||||
(update :nodes #(into {} (map (fn [[id n]] [id (repoint n ids)])) %))))]
|
||||
{:clip (reduce (fn [c sid] (assoc-in c [:symbols (ids sid)] (copy sid))) clip reach)
|
||||
:ids ids}))
|
||||
|
|
@ -90,11 +99,8 @@
|
|||
wanted (into {:main root :footage (scoped :footage)}
|
||||
(map (fn [subject] [subject (scoped subject)]))
|
||||
(keys (:subjects frozen)))
|
||||
{c :clip ids :ids} (symbols clip frozen [:main] wanted)
|
||||
sid (ids :main)
|
||||
faces (mapv ids (sort-by str (keys (:subjects frozen))))
|
||||
sound {:id :sound :name "sound" :kind :audio :parent nil
|
||||
:z "z-sound" :source {:footage footage-id}
|
||||
:z "z-sound" :source {:footage footage-id :fps (:fps frozen)}
|
||||
;; All automatic copies name one recording. The audio walk
|
||||
;; uses this identity only to avoid mixing that recording once
|
||||
;; per detected face when the complete take is played.
|
||||
|
|
@ -102,6 +108,13 @@
|
|||
;; Source frame `start` plays on the symbol's 0.
|
||||
:span range
|
||||
:time {:mode :map :at (- (first range)) :rate 1}}
|
||||
;; Into the faces BEFORE they are copied, so the sound is moved onto this
|
||||
;; document's rate along with the rest of them.
|
||||
frozen (reduce (fn [document face]
|
||||
(assoc-in document [:symbols face :nodes :sound] sound))
|
||||
frozen (keys (:subjects frozen)))
|
||||
{c :clip ids :ids} (symbols clip frozen [:main] wanted)
|
||||
sid (ids :main)
|
||||
feature-ids (into {}
|
||||
(map (fn [[id f]]
|
||||
[id (feature/owned (ids (:subject f)) (keyword (name id)))]))
|
||||
|
|
@ -130,9 +143,7 @@
|
|||
(:groups frozen))]
|
||||
{:sid sid
|
||||
:subject-ids (select-keys ids (keys (:subjects frozen)))
|
||||
:clip (-> (reduce (fn [document face]
|
||||
(assoc-in document [:symbols face :nodes :sound] sound))
|
||||
c faces)
|
||||
:clip (-> c
|
||||
(assoc-in [:symbols sid :name] (str label))
|
||||
(update :analyses merge (:analyses frozen))
|
||||
(update :subjects merge subjects)
|
||||
|
|
@ -147,5 +158,4 @@
|
|||
when there is none. See `clip/place-symbol`."
|
||||
[entry brought store sid host frame uuid point]
|
||||
(let [st (merge (:store entry) store)]
|
||||
(assoc entry :store st :clip (clip/place-symbol brought st host sid
|
||||
(* frame (:rate (clip/grid-time brought host))) uuid point))))
|
||||
(assoc entry :store st :clip (clip/place-symbol brought st host sid frame uuid point))))
|
||||
|
|
|
|||
|
|
@ -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)))
|
||||
|
|
@ -34,11 +34,11 @@
|
|||
symbol, the way a Flash file names its scene. See `opens-on` for why that
|
||||
cannot be worked out instead.
|
||||
|
||||
:fps is the output grid. A symbol's optional :fps names the native grid its
|
||||
frames were authored or measured on; absent means the document's grid."
|
||||
:fps is the document's one rate. A symbol has none: it is a bag of frames, and
|
||||
each of them plays for one tick of the document's clock, as in Flash. See
|
||||
`docs/time.md`."
|
||||
(:refer-clojure :exclude [symbol])
|
||||
(:require [arthur.domain.cadence :as cadence]
|
||||
[arthur.domain.channel :as ch]
|
||||
(:require [arthur.domain.channel :as ch]
|
||||
[arthur.domain.feature :as feature]
|
||||
[arthur.domain.node :as node]
|
||||
[arthur.domain.palette :as pal]
|
||||
|
|
@ -101,69 +101,12 @@
|
|||
[clip sid]
|
||||
(:frames (symbol clip sid)))
|
||||
|
||||
(defn fps [clip sid] (or (:fps (symbol clip sid)) (:fps clip)))
|
||||
|
||||
(defn set-fps
|
||||
"Change the output grid without rewriting authored content's frames.
|
||||
|
||||
A new document's empty symbol is the one exception: it has no native rate yet,
|
||||
so it follows the project grid and its empty extent is rescaled to preserve its
|
||||
duration. Once a symbol contains anything, changing the project rate records
|
||||
the old effective rate on it before changing the output grid."
|
||||
[clip rate]
|
||||
(let [old (:fps clip)]
|
||||
(-> clip
|
||||
(update :symbols
|
||||
#(into {}
|
||||
(map (fn [[sid sym]]
|
||||
[sid (cond
|
||||
(:fps sym) sym
|
||||
(empty? (:nodes sym))
|
||||
(update sym :frames cadence/frames rate old)
|
||||
:else (assoc sym :fps old))]))
|
||||
%))
|
||||
(assoc :fps rate))))
|
||||
|
||||
(defn output-frames [clip sid]
|
||||
(cadence/frames (frames clip sid) (:fps clip) (fps clip sid)))
|
||||
|
||||
(defn grid-time [clip sid]
|
||||
{:at 0 :rate (cadence/ratio (:fps clip) (fps clip sid))})
|
||||
|
||||
;; ---------------------------------------------------------------------------
|
||||
;; the only crossing between the output grid and a symbol's own frames
|
||||
;;
|
||||
;; Everything authored is in a symbol's own frames and every editing gesture is
|
||||
;; too — see `docs/one-grid-plan.md`. The output grid belongs to playback: the
|
||||
;; clock, the audio mix, export, and the frame number the stage is drawing. These
|
||||
;; two functions are the whole of the way between, so a caller that has a
|
||||
;; playhead and needs a document coordinate says so in one visible call instead
|
||||
;; of multiplying by a rate it had to know about.
|
||||
|
||||
(defn shown-frame
|
||||
"Which of symbol `sid`'s own frames the output frame `f` shows."
|
||||
[clip sid f]
|
||||
(cadence/frame f (:fps clip) (fps clip sid)))
|
||||
|
||||
(defn first-output-frame
|
||||
"The output frame that first shows symbol `sid`'s own frame `n`: what to seek
|
||||
to to put the playhead on a mark of `sid`'s ruler."
|
||||
[clip sid n]
|
||||
(cadence/reader-frame n (:fps clip) (fps clip sid)))
|
||||
|
||||
(defn source-time
|
||||
"Derived cel-to-content map. Frame-rate units never enter stored retimes."
|
||||
[clip host n]
|
||||
(when-let [t (node/source-time n)]
|
||||
(let [r (cadence/ratio (fps clip host) (fps clip (node/source n)))]
|
||||
(-> t (update :rate * r) (update :at / r)))))
|
||||
|
||||
(defn placed-frame [clip host n f]
|
||||
(let [child (node/source n)
|
||||
r (cadence/ratio (fps clip host) (fps clip child))]
|
||||
(some-> (node/placed-frame (update-in n [:playback :speed] #(* (or % 1) r))
|
||||
f (frames clip child))
|
||||
(update :frame js/Math.floor))))
|
||||
(defn placed-frame
|
||||
"Which frame of which symbol instance `n` shows on its own frame `f`, as
|
||||
`{:symbol :frame}`, or nil. See `node/placed-frame`."
|
||||
[clip n f]
|
||||
(some-> (node/placed-frame n f (frames clip (node/source n)))
|
||||
(update :frame js/Math.floor)))
|
||||
|
||||
(defn stage
|
||||
"A symbol's stage as `[width height]`: its own, or the clip's where it has none.
|
||||
|
|
@ -216,41 +159,19 @@
|
|||
the theory that the one containing everything else is always that. A take
|
||||
disproves it: imported footage is a symbol a thousand frames long, and the
|
||||
moment its instance is deleted, or the drop lands somewhere other than the
|
||||
root, nothing places it and it outranks a 120-frame `:main`. The document then
|
||||
opened on the take, and `set-root-fps` rewrote the take's rate to the
|
||||
project's on the way in.
|
||||
root, nothing places it and it outranks a 120-frame `:main`, and the document
|
||||
opened on the take.
|
||||
|
||||
A document with no `:root` — a demo, a fixture — still gets the old answer."
|
||||
[clip]
|
||||
(let [root (:root clip)]
|
||||
(if (contains? (:symbols clip) root) root (longest-unplaced clip))))
|
||||
|
||||
(defn pin-root
|
||||
"Give a document saved before `:root` existed the root it was made with.
|
||||
Every such document started as `blank`, whose root is `:main`, and ids never
|
||||
change, so `:main` is the answer wherever it survives; the old rule is only
|
||||
for documents that never had one."
|
||||
[clip]
|
||||
(cond-> clip
|
||||
(not (:root clip))
|
||||
(assoc :root (if (contains? (:symbols clip) :main) :main (longest-unplaced clip)))))
|
||||
|
||||
(defn set-root-fps
|
||||
"Set the document/output rate and the root symbol's editing rate together.
|
||||
|
||||
Project FPS is the root timeline's clock. Nested symbols keep their own native
|
||||
rates and are sampled when placed across that boundary; only the root changes
|
||||
here. Frame numbers are authored positions, so changing the rate does not
|
||||
rewrite them or silently move cuts and keys."
|
||||
[clip rate]
|
||||
(let [root (opens-on clip)]
|
||||
(cond-> (assoc clip :fps rate)
|
||||
root (assoc-in [:symbols root :fps] rate))))
|
||||
|
||||
(def ^:const blank-frames
|
||||
"How long a new document is before anything says otherwise. Four seconds at 30,
|
||||
which is long enough to key something into and short enough to scrub by hand."
|
||||
120)
|
||||
(def blank-settings
|
||||
"What a new document is before anyone says otherwise. 12fps because the rough
|
||||
look is the point; four seconds is long enough to key something into and short
|
||||
enough to scrub by hand."
|
||||
{:name "untitled" :fps 12 :seconds 4 :width 320 :height 200})
|
||||
|
||||
(defn blank
|
||||
"A new, empty document: one symbol, and nothing in it.
|
||||
|
|
@ -265,17 +186,21 @@
|
|||
as a different map than it saved from is exactly the round trip that namespace
|
||||
promises not to have. Nothing drawn by hand has them either — the demo scene
|
||||
and the swarm carry no `:subjects` — so every reader already reads absence as
|
||||
none, and `clip-keys` says which fields MAY be here, not which must."
|
||||
[]
|
||||
{:name "untitled"
|
||||
:fps 30
|
||||
:width 320 :height 200
|
||||
:palettes {pal/default-id pal/default-palette}
|
||||
:default-palette pal/default-id
|
||||
:root :main
|
||||
;; No native fps yet: an untouched canvas follows the project grid. Imported
|
||||
;; and generated symbols carry their own rate explicitly.
|
||||
:symbols {:main {:id :main :frames blank-frames :nodes {}}}})
|
||||
none, and `clip-keys` says which fields MAY be here, not which must.
|
||||
|
||||
`settings` overrides any of `blank-settings`. It starts with every one of
|
||||
`palette/presets`, and `:palette` is the id of the one it draws with."
|
||||
([] (blank {}))
|
||||
([settings]
|
||||
(let [{:keys [fps seconds width height palette] :as s} (merge blank-settings (into {} (remove (comp nil? val)) settings))
|
||||
presets (into {} (map (juxt :id identity)) pal/presets)]
|
||||
{:name (:name s)
|
||||
:fps fps
|
||||
:width width :height height
|
||||
:palettes presets
|
||||
:default-palette (if (contains? presets palette) palette pal/default-id)
|
||||
:root :main
|
||||
:symbols {:main {:id :main :frames (max 1 (js/Math.round (* seconds fps))) :nodes {}}}})))
|
||||
|
||||
(defn- op-path [op] (let [n (:node op)] (if (vector? n) n [n])))
|
||||
|
||||
|
|
@ -497,7 +422,7 @@
|
|||
prior (symbol/pre-frame-of own id)
|
||||
length (frames clip (node/source n))
|
||||
shown (when (and m (number? local))
|
||||
(placed-frame clip sid n local))
|
||||
(placed-frame clip n local))
|
||||
frame (:frame shown)]
|
||||
(cond
|
||||
(not (and frame (<= 0 frame) (< frame length)))
|
||||
|
|
@ -523,7 +448,7 @@
|
|||
;; the first time on this slot has no
|
||||
;; previous frame, and so no gap.
|
||||
(or (:frame (when (number? prior)
|
||||
(placed-frame clip sid n prior)))
|
||||
(placed-frame clip n prior)))
|
||||
(dec frame))
|
||||
@active
|
||||
(when (and context? (:palette n))
|
||||
|
|
@ -554,27 +479,12 @@
|
|||
(when (contains? @entered id)
|
||||
(symbol/pre-frame-of (get children [id (get @entered id)]) (vec more)))
|
||||
(symbol/pre-frame-of own id))))))]
|
||||
(let [r (build sid [] nil true)
|
||||
grid (or (:grid-fps opts) (:fps clip))
|
||||
native (fps clip sid)]
|
||||
(let [r (build sid [] nil true)]
|
||||
(reify
|
||||
IFn
|
||||
(-invoke [_ f]
|
||||
(r (cadence/frame f grid native)
|
||||
;; `d(k-1)`: the native frame the slot BEFORE this one selected, which
|
||||
;; with `d(k)` is the interval `(d(k-1), d(k)]` the preserve-snap may
|
||||
;; reach back into — the frames this slot is the first to cover, and so
|
||||
;; the ones the grid would otherwise show to nobody. Slot 0 has no slot
|
||||
;; before it, so its interval is its own frame alone.
|
||||
;;
|
||||
;; THE SNAP DOES NOT HAPPEN HERE, although the interval is born here and
|
||||
;; nothing would need threading. One native frame per output frame means
|
||||
;; the WHOLE PICTURE reading 13 instead of 15 — a head going two frames
|
||||
;; stale, a 67ms hitch at 12fps, to fix one group's mouth. It is per
|
||||
;; group, so it is seated where groups exist.
|
||||
(if (pos? f) (cadence/frame (dec f) grid native) -1)
|
||||
(when context? (:default palette))
|
||||
nil))
|
||||
;; `pre` is the frame before, so a child placed at a speed is handed
|
||||
;; the interval `(pre, f]` its preserve-snap may reach back into.
|
||||
(-invoke [_ f] (r f (dec f) (when context? (:default palette)) nil))
|
||||
symbol/IResolver
|
||||
(world-of [_ path] (symbol/world-of r path))
|
||||
(frame-of [_ path] (symbol/frame-of r path))
|
||||
|
|
@ -601,7 +511,7 @@
|
|||
cross is draggable so neither is a trap. What the anchor got wrong was being
|
||||
invisible and unmovable, not being stored."
|
||||
[clip store sid]
|
||||
(let [resolve (resolver clip sid store pal/index-of {:grid-fps (fps clip sid)})
|
||||
(let [resolve (resolver clip sid store pal/index-of {})
|
||||
bounds (fn [[x0 y0 x1 y1 :as b] x y]
|
||||
(if b [(min x0 x) (min y0 y) (max x1 x) (max y1 y)] [x y x y]))
|
||||
[x0 y0 x1 y1]
|
||||
|
|
@ -644,11 +554,13 @@
|
|||
The instance's own time starts where it was dropped: `:at frame` means frame 0
|
||||
of the symbol plays on `frame` of `host`, which is what dragging something onto
|
||||
a playhead is asking for. Its `:span` is in its OWN frames — the whole symbol,
|
||||
0 to its length — wherever it was dropped; see `node/placed-span`.
|
||||
0 to its length at `speed` — wherever it was dropped; see `node/placed-span`.
|
||||
`speed` is 1 unless the symbol's frames are footage's at another rate.
|
||||
|
||||
Refused, returning the clip unchanged, when it would make a cycle: a symbol
|
||||
cannot be placed inside itself or inside anything it places."
|
||||
[clip store host sid frame uuid point]
|
||||
([clip store host sid frame uuid point] (place-symbol clip store host sid frame uuid point 1))
|
||||
([clip store host sid frame uuid point speed]
|
||||
(let [target (symbol clip sid)
|
||||
end (frames clip host)]
|
||||
(if (or (nil? target) (nil? end) (nil? frame) (neg? frame) (>= frame end)
|
||||
|
|
@ -663,13 +575,13 @@
|
|||
;; Lexicographic draw order, as `domain/paint` does it: an instance made
|
||||
;; later sits above one made earlier, and neither has to renumber.
|
||||
:z (str "z" (js/Date.now) "-" (name sid))
|
||||
:span [0 (cadence/frames (:frames target) (fps clip host) (fps clip sid))]
|
||||
:span [0 (js/Math.ceil (/ (:frames target) speed))]
|
||||
:time {:mode :map :at frame :rate 1}
|
||||
:source {:symbol sid}
|
||||
:playback {:in 0 :speed 1 :end :stop}
|
||||
:playback {:in 0 :speed speed :end :stop}
|
||||
:channels {[:xform :pos] {:animated? false
|
||||
:value (if point (mapv - point middle) [0 0])}
|
||||
[:xform :pivot] {:animated? false :value middle}}})))))
|
||||
[:xform :pivot] {:animated? false :value middle}}}))))))
|
||||
|
||||
(defn place-sound
|
||||
"Place a sound at host frame `frame`. Its span uses `source`'s fps when
|
||||
|
|
@ -704,7 +616,7 @@
|
|||
(if (or (nil? end) (symbol clip sid) (nil? frame) (neg? frame) (>= frame end))
|
||||
clip
|
||||
(-> clip
|
||||
(assoc-in [:symbols sid] {:id sid :name (name sid) :fps (fps clip host)
|
||||
(assoc-in [:symbols sid] {:id sid :name (name sid)
|
||||
:frames (- end frame) :nodes {}})
|
||||
(place-symbol nil host sid frame uuid nil)))))
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
clip/<cid>/subject/<subj> a tracked subject and its params
|
||||
clip/<cid>/feature/<fid> one feature: area, nodes, params
|
||||
clip/<cid>/group/<gid> an eye pair and its shared params
|
||||
clip/<cid>/symbol/<sid> native frames and fps, optional palette
|
||||
clip/<cid>/symbol/<sid> frame count, optional palette
|
||||
clip/<cid>/symbol/<sid>/node/<nid> kind, parent, stencil, z, time
|
||||
clip/<cid>/symbol/<sid>/channel/<nid>/<prop>
|
||||
clip/<cid>/symbol/<sid>/measured/<nid> the channels a re-freeze owns
|
||||
|
|
@ -26,8 +26,8 @@
|
|||
its own nodes, so the symbol id is a path segment. No symbol has a reserved
|
||||
segment: `main` in a path is an id like any other.
|
||||
|
||||
The timing leaf holds output fps. Each symbol leaf holds its native fps
|
||||
and frame count, so changing the output grid leaves content untouched.
|
||||
The timing leaf holds the document's one rate. A symbol leaf holds its frame
|
||||
count and no rate: a symbol is a bag of frames.
|
||||
|
||||
WHY THESE BOUNDARIES. Last-writer-wins only clobbers when its unit is too big,
|
||||
so the cut is chosen so that the things people do simultaneously land on
|
||||
|
|
@ -151,7 +151,7 @@
|
|||
;; disagree with itself about; `clip` puts it back.
|
||||
(for [[sid sym] (:symbols clip)]
|
||||
{(at "symbol" (segment sid))
|
||||
(select-keys sym [:name :frames :fps :width :height :palette
|
||||
(select-keys sym [:name :frames :width :height :palette
|
||||
:palette-track :palette-channel :type :palette-ref :display
|
||||
:media])})
|
||||
(for [[sid sym] (:symbols clip)
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@
|
|||
OUTPUT frame, multiplied into `sid`'s space here, which made the units of the
|
||||
argument something each caller had to know without being told and put a
|
||||
2.5-frame step between what the ruler offered and what the document could hold.
|
||||
A caller holding the playhead converts with `clip/shown-frame`.
|
||||
Every symbol counts in the document's one rate, so the playhead is one.
|
||||
|
||||
THE SAME STEP FOR EVERY NODE. Inside an instance is the symbol it places;
|
||||
inside a shape is where its points and keys are. Either way it is the node's
|
||||
|
|
@ -78,7 +78,7 @@
|
|||
;; the hold pins, not on `local`, and inside a playing insert
|
||||
;; is its animation at its own in-point and speed.
|
||||
shown (when (number? local)
|
||||
(clip/placed-frame clip sid (get nodes id) local))
|
||||
(clip/placed-frame clip (get nodes id) local))
|
||||
inner (:symbol shown)
|
||||
lf (if shown (:frame shown) local)]
|
||||
(if (and m (number? local)
|
||||
|
|
@ -90,9 +90,9 @@
|
|||
;; Forward sampling above works for holds too. :time is the
|
||||
;; invertible edit map; source in-points and speeds belong in it.
|
||||
:time (when (and time (not-any? #(get-in % [:time :loop?]) chain)
|
||||
(or (not inst?) (clip/source-time clip sid (get nodes id))))
|
||||
(or (not inst?) (node/source-time (get nodes id))))
|
||||
(cond-> (reduce node/then-time time (map node/time-of chain))
|
||||
inst? (node/then-time (clip/source-time clip sid (get nodes id)))))}
|
||||
inst? (node/then-time (node/source-time (get nodes id)))))}
|
||||
(reduced nil))))
|
||||
{:sid sid :frame (js/Math.floor f)
|
||||
:matrix (node/mat) :time node/same-time}
|
||||
|
|
@ -189,8 +189,8 @@
|
|||
{:time outer :bounds bounds})
|
||||
m (node/then-time (:time parent) (node/time-of n))
|
||||
m (if (= :audio (:kind n))
|
||||
(update m :rate * (/ (or (get-in n [:source :fps]) (clip/fps clip sid))
|
||||
(clip/fps clip sid))) m)]
|
||||
(update m :rate * (/ (or (get-in n [:source :fps]) (:fps clip))
|
||||
(:fps clip))) m)]
|
||||
(assoc acc id {:time m :bounds (window m (:span n) (:bounds parent))})))
|
||||
{} (symbol/order nodes))]
|
||||
(mapcat
|
||||
|
|
@ -200,7 +200,7 @@
|
|||
(case (:kind n)
|
||||
:audio [(-> n
|
||||
(assoc :parent nil :path (conj path id) :owner sid
|
||||
:fps (or (get-in n [:source :fps]) (clip/fps clip sid))
|
||||
:fps (or (get-in n [:source :fps]) (:fps clip))
|
||||
:span [(to-local m lo) (to-local m hi)]
|
||||
:time (merge (:time n) {:mode :map :at (:at m) :rate (:rate m) :offset 0})
|
||||
:channels (channels (:channels n) m)))]
|
||||
|
|
@ -210,7 +210,7 @@
|
|||
length (clip/frames clip child)]
|
||||
;; A visual freeze does not emit a sustained audio sample.
|
||||
(when (and child length (pos? speed))
|
||||
(let [source (node/then-time m (clip/source-time clip sid
|
||||
(let [source (node/then-time m (node/source-time
|
||||
(-> n
|
||||
(assoc-in [:playback :end] :stop)
|
||||
(update :time dissoc :loop?))))
|
||||
|
|
@ -225,8 +225,8 @@
|
|||
periods))))
|
||||
nil))))
|
||||
(sort-by (comp str key) nodes))))]
|
||||
(let [tracks (walk sid (clip/grid-time clip sid)
|
||||
[0 (clip/output-frames clip sid)] [] #{})]
|
||||
(let [tracks (walk sid node/same-time
|
||||
[0 (clip/frames clip sid)] [] #{})]
|
||||
(second
|
||||
(reduce (fn [[seen out] track]
|
||||
(let [link (:media-link track)
|
||||
|
|
@ -394,7 +394,7 @@
|
|||
(mapcat (fn [n]
|
||||
(if (get-in n [:time :loop?]) [nil]
|
||||
(cond-> [(node/time-of n)]
|
||||
(= :instance (:kind n)) (conj (clip/source-time clip sid n)))))
|
||||
(= :instance (:kind n)) (conj (node/source-time n)))))
|
||||
chain)))
|
||||
sids path)]
|
||||
{:sid (last sids)
|
||||
|
|
@ -627,7 +627,7 @@
|
|||
start (js/Math.floor (max 0 (apply min (map first spans))))
|
||||
end (min (second whole) (apply max (map second spans)))
|
||||
made (-> clip
|
||||
(assoc-in [:symbols sid] {:id sid :name (name sid) :fps (clip/fps clip host)
|
||||
(assoc-in [:symbols sid] {:id sid :name (name sid)
|
||||
:frames (max 1 (js/Math.ceil (- end start)))
|
||||
:nodes {}})
|
||||
(clip/place-symbol store host sid start uuid nil))
|
||||
|
|
|
|||
|
|
@ -243,8 +243,8 @@
|
|||
the lead in their load-bearing order.
|
||||
|
||||
`:rate` is a RETIME SOMEBODY CHOSE and nothing else — half speed on an insert.
|
||||
Reconciling two frame rates is not a retime and does not belong here: it is a
|
||||
selection, and it lives in `domain/cadence`."
|
||||
Footage at another rate than the document's is played by the `:playback
|
||||
:speed` of its placement, not by this."
|
||||
[n]
|
||||
(let [{:keys [mode at rate offset] :or {mode :map at 0 rate 1 offset 0}} (:time n)]
|
||||
(if (= mode :map)
|
||||
|
|
|
|||
|
|
@ -51,6 +51,45 @@
|
|||
{:id default-id :name "Arthur"
|
||||
:slots (into entries (repeat 7 {:hex "#000000"}))})
|
||||
|
||||
(defn- preset
|
||||
"A palette from nine face tones in `entries` order and seven free ones. The
|
||||
order is the point: a measured mouth draws in slot 3 and an iris in slot 6
|
||||
whatever palette is on, so a preset that moved them would recolour a face
|
||||
into nonsense rather than restyle it."
|
||||
[id label [bg skin-base skin-dark mouth-dark teeth eye-white iris pupil brow] free]
|
||||
{:id id :name label
|
||||
:slots (into (mapv (fn [e hex] {:name (:name e) :hex hex})
|
||||
entries [bg skin-base skin-dark mouth-dark teeth eye-white iris pupil brow])
|
||||
(map (fn [hex] {:hex hex}))
|
||||
free)})
|
||||
|
||||
(def presets
|
||||
"Palettes a new project starts with, borrowed from worlds that already work
|
||||
in sixteen colours or fewer. Only the one a project draws with costs it
|
||||
anything; the rest are there to switch to."
|
||||
[default-palette
|
||||
;; Lexaloffle's PICO-8, all sixteen, its peach and brown as the skin ramp.
|
||||
(preset :arthur/pico-8 "PICO-8"
|
||||
["#1d2b53" "#ffccaa" "#ab5236" "#7e2553" "#fff1e8" "#c2c3c7" "#29adff" "#000000" "#5f574f"]
|
||||
["#ff004d" "#ffa300" "#ffec27" "#00e436" "#008751" "#ff77a8" "#83769c"])
|
||||
;; GrafxKid's Sweetie 16.
|
||||
(preset :arthur/sweetie-16 "Sweetie 16"
|
||||
["#1a1c2c" "#ffcd75" "#ef7d57" "#5d275d" "#f4f4f4" "#94b0c2" "#3b5dc9" "#333c57" "#566c86"]
|
||||
["#b13e53" "#a7f070" "#38b764" "#257179" "#29366f" "#41a6f6" "#73eff7"])
|
||||
;; The original Game Boy's four greens, lightest behind. Everything is one of
|
||||
;; four, so the face reads by value alone.
|
||||
(preset :arthur/dmg "Game Boy"
|
||||
["#9bbc0f" "#8bac0f" "#306230" "#0f380f" "#9bbc0f" "#9bbc0f" "#306230" "#0f380f" "#0f380f"]
|
||||
["#0f380f" "#306230" "#8bac0f" "#9bbc0f" "#0f380f" "#306230" "#8bac0f"])
|
||||
;; Rubber-hose cartoons, on paper gone yellow.
|
||||
(preset :arthur/sepia "Sepia"
|
||||
["#f2e6c9" "#e8c39e" "#b98b63" "#4a2c1d" "#fbf4e2" "#f3ead6" "#6b4a2f" "#241610" "#4a2c1d"]
|
||||
["#8c2f1f" "#c8792c" "#d9b44a" "#6f7d3c" "#3e5a6b" "#a39b8b" "#2b2420"])
|
||||
;; Ink and a red, for line tests and noir.
|
||||
(preset :arthur/ink "Ink"
|
||||
["#101010" "#d8d2c4" "#8a857a" "#2a2a2a" "#f0ece2" "#c8c3b6" "#4a4a4a" "#0a0a0a" "#2a2a2a"]
|
||||
["#b3261e" "#e4e0d6" "#bdb8ad" "#9e998f" "#6d6961" "#4f4c46" "#1c1c1c"])])
|
||||
|
||||
(defn palettes [clip]
|
||||
(if (seq (:palettes clip)) (:palettes clip) {default-id default-palette}))
|
||||
|
||||
|
|
|
|||
|
|
@ -183,7 +183,7 @@
|
|||
;; pixels, in its own coordinates, on every frame it shows one.
|
||||
:trace
|
||||
(let [{:keys [width height]} (clip/symbol document (node/source n))]
|
||||
(fn [f] (when (clip/placed-frame document sid n f) [0 0 width height])))
|
||||
(fn [f] (when (clip/placed-frame document n f) [0 0 width height])))
|
||||
|
||||
:instance
|
||||
;; ONE RESOLVER PER DRAWING THE LANE CAN SHOW, built once for the reason
|
||||
|
|
@ -192,11 +192,10 @@
|
|||
;; resolver per frame.
|
||||
(let [loop? (get-in n [:time :loop?])
|
||||
resolvers (into {} (map (fn [child]
|
||||
[child (clip/resolver document child store
|
||||
pal/index-of {:grid-fps (clip/fps document child)})]))
|
||||
[child (clip/resolver document child store pal/index-of {})]))
|
||||
(node/sources n))]
|
||||
(fn [f0]
|
||||
(let [shown (clip/placed-frame document sid n f0)
|
||||
(let [shown (clip/placed-frame document n f0)
|
||||
frames (when shown (clip/frames document (:symbol shown)))
|
||||
f (when (number? frames)
|
||||
(if loop? (mod (:frame shown) frames) (:frame shown)))
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
AND THE PRESERVE-SNAP, which is the same question asked where nobody has
|
||||
answered it by hand. A grid slot already picks a native frame — the latest one
|
||||
at or before its time, see `domain/cadence` — and that pick has no opinion about
|
||||
at or before its time, `node/placed-frame` floored — and that pick has no opinion about
|
||||
content, so at 12fps out of 30 it drops two frames in three and cannot know that
|
||||
one of them is where the mouth shut. The snap gives it one: a slot reads the
|
||||
latest MARKED frame inside its own gap. `marks` is where the marks come from and
|
||||
|
|
@ -123,8 +123,8 @@
|
|||
is recovered by the slot whose default is 15, reading 13. It is NOT recovered by
|
||||
the slot whose default is 12 reaching forward to 13: that slot's instant is
|
||||
5/12s and native 13's is 13/30s, so it would show the closure 17ms before the
|
||||
mouth shut. `cadence/frame`'s contract is at-or-before and `cadence_test` asserts
|
||||
`selected <= f*native/grid` over every grid and native pair, so reaching forward
|
||||
mouth shut. A placement's frame is a floor, at-or-before, and `rate_test` asserts
|
||||
`selected <= f*speed` over every speed, so reaching forward
|
||||
would break a tested invariant as well as the no-lead rule. Reading 13 two
|
||||
native frames late is the lateness every hold already has.
|
||||
|
||||
|
|
|
|||
106
frontend/src/arthur/domain/retime.cljs
Normal file
106
frontend/src/arthur/domain/retime.cljs
Normal 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)))])))
|
||||
%)))))
|
||||
|
|
@ -8,7 +8,7 @@
|
|||
frames an artist has to draw a head on, and the frames a performance changes a
|
||||
shape on.
|
||||
|
||||
`domain/cadence` answers the same question with no opinion about content, and
|
||||
A placement's speed answers the same question with no opinion about content, and
|
||||
cannot know that the one frame where a mouth is fully shut is worth more than
|
||||
its neighbours. That is the gap `:protect` closes.
|
||||
|
||||
|
|
|
|||
|
|
@ -565,9 +565,9 @@
|
|||
drawing creation remains a policy of `append-drawing`/`overwrite-drawing`,
|
||||
not a different kind of container."
|
||||
[clip store sid id source-id at
|
||||
{:keys [extent point remainder-id] :or {extent :keep}}]
|
||||
{:keys [extent point remainder-id speed] :or {extent :keep speed 1}}]
|
||||
(let [nodes (get-in clip [:symbols sid :nodes])
|
||||
seeded (clip/place-symbol clip store sid source-id 0 id point)
|
||||
seeded (clip/place-symbol clip store sid source-id 0 id point speed)
|
||||
n (get-in seeded [:symbols sid :nodes id])]
|
||||
(cond
|
||||
(contains? nodes id) {:refused "the new clip ID is already used"}
|
||||
|
|
@ -701,7 +701,7 @@
|
|||
(when (clip/symbol clip drawing-id) "the new drawing ID is already used"))]
|
||||
{:refused why}
|
||||
(place (assoc-in clip [:symbols drawing-id]
|
||||
{:id drawing-id :name (name drawing-id) :fps (clip/fps clip sid) :frames 1 :nodes {}})
|
||||
{:id drawing-id :name (name drawing-id) :frames 1 :nodes {}})
|
||||
sid id drawing-id at extent true)))
|
||||
|
||||
(defn reuse-drawing
|
||||
|
|
@ -774,8 +774,7 @@
|
|||
(clip/symbol clip drawing-id) "the new drawing ID is already used")]
|
||||
{:refused why}
|
||||
(let [c (assoc-in clip [:symbols drawing-id]
|
||||
{:id drawing-id :name (name drawing-id)
|
||||
:fps (clip/fps clip sid) :frames 1 :nodes {}})
|
||||
{:id drawing-id :name (name drawing-id) :frames 1 :nodes {}})
|
||||
nodes (assoc nodes id (held id drawing-id at))]
|
||||
(claim c sid nodes id extent remainder-id)))))
|
||||
|
||||
|
|
|
|||
|
|
@ -764,11 +764,11 @@
|
|||
|
||||
`:media` is what a `:type :trace` symbol shows — `{:footage id :range [in
|
||||
out]}` or `{:image sha256}` — and such a symbol has no nodes: its frames are
|
||||
the footage's, its `:fps` the footage's own and its `:width`/`:height` its
|
||||
pixels. A still shows the same picture on every one of its frames, so how many
|
||||
it has is only how long it was made to last, and trimming its placement is
|
||||
how that changes. See `clip/trace-op`."
|
||||
#{:id :name :frames :fps :width :height :nodes :palette :palette-track
|
||||
the footage's, played in real time by the speed of its placement, and its
|
||||
`:width`/`:height` its pixels. A still shows the same picture on every one of
|
||||
its frames, so how many it has is only how long it was made to last, and
|
||||
trimming its placement is how that changes. See `clip/trace-op`."
|
||||
#{:id :name :frames :width :height :nodes :palette :palette-track
|
||||
:palette-channel :type :palette-ref :display :media})
|
||||
|
||||
(defn- media-problems
|
||||
|
|
@ -853,9 +853,6 @@
|
|||
(into (when-not (or (nil? (:frames sym)) (and (integer? (:frames sym)) (pos? (:frames sym))))
|
||||
[(str ":frames is " (pr-str (:frames sym))
|
||||
" — a symbol is a frame SPACE, so its length is a positive integer")]))
|
||||
(into (when (and (some? (:fps sym))
|
||||
(not (and (node/finite-number? (:fps sym)) (pos? (:fps sym)))))
|
||||
[":fps must be a positive finite native rate"]))
|
||||
(into (for [k [:width :height]
|
||||
:let [v (get sym k)]
|
||||
:when (and (some? v) (not (and (integer? v) (pos? v))))]
|
||||
|
|
|
|||
|
|
@ -64,12 +64,25 @@
|
|||
|
||||
(rf/reg-fx
|
||||
::create!
|
||||
(fn [name]
|
||||
(-> (http/POST "/api/projects" #js {:name name})
|
||||
(.then (fn [^js made] (navigate! (project-path (.-id made) (.-name made)))))
|
||||
(fn [settings]
|
||||
(-> (http/POST "/api/projects" #js {:name (:name settings)})
|
||||
(.then (fn [^js made] (rf/dispatch [::created (.-id made) (.-name made) settings])))
|
||||
(.catch #(rf/dispatch [::refused (ex-message %)])))))
|
||||
|
||||
(rf/reg-event-fx ::create (fn [_ [_ name]] {::create! (or name "untitled")}))
|
||||
(rf/reg-fx ::navigate! navigate!)
|
||||
|
||||
;; `settings` is what `clip/blank` takes. The server holds only the name until
|
||||
;; the first save, so the rest waits under the new id for the first open.
|
||||
(rf/reg-event-fx
|
||||
::create
|
||||
(fn [_ [_ settings]]
|
||||
{::create! (update settings :name #(or (not-empty %) "untitled"))}))
|
||||
|
||||
(rf/reg-event-fx
|
||||
::created
|
||||
(fn [{:keys [db]} [_ id name settings]]
|
||||
{:db (assoc-in db [:new-projects id] settings)
|
||||
::navigate! (project-path id name)}))
|
||||
|
||||
;; ---------------------------------------------------------------------------
|
||||
;; the socket
|
||||
|
|
|
|||
|
|
@ -571,7 +571,7 @@
|
|||
{:keys [clip sid subject-ids]}
|
||||
(bring/take (:clip entry) (:clip built) name footage-id range)
|
||||
st (merge (:store entry) (:store built))
|
||||
imported-frames (clip/output-frames clip sid)
|
||||
imported-frames (clip/frames clip sid)
|
||||
source-fps (get-in built [:clip :fps])
|
||||
where (if point
|
||||
(ui/creation-destination db clip st frame)
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
the db beside it, because an edit can change it."
|
||||
[db]
|
||||
(or (some-> (footage/entry (:clip/current db)) :clip
|
||||
(clip/output-frames (get-in db [:ui :open])))
|
||||
(clip/frames (get-in db [:ui :open])))
|
||||
1))
|
||||
|
||||
(defn show
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@
|
|||
[arthur.demo.stage :as stage]
|
||||
[arthur.domain.feature :as feature]
|
||||
[arthur.domain.project :as project]
|
||||
[arthur.domain.retime :as retime]
|
||||
[arthur.domain.wire :as wire]
|
||||
[arthur.events.footage :as footage]
|
||||
[arthur.events.playback :as pb]
|
||||
|
|
@ -109,13 +110,7 @@
|
|||
loaded (project/load
|
||||
cid #js {:leaves (.-leaves clip-json)
|
||||
:blocks blocks})
|
||||
;; Project FPS and the root timeline are one clock. This
|
||||
;; also normalizes documents saved by the earlier model,
|
||||
;; where changing project FPS left the root on its old
|
||||
;; editing grid.
|
||||
built (-> (:clip loaded)
|
||||
clip/pin-root
|
||||
(clip/set-root-fps (:fps (:clip loaded))))]
|
||||
built (:clip loaded)]
|
||||
(let [entry (merge (select-keys built [:fps :width :height])
|
||||
{:label (str (or (.-name clip-json) cid) " (saved)")
|
||||
:cid cid
|
||||
|
|
@ -368,7 +363,7 @@
|
|||
|
||||
(rf/reg-fx
|
||||
::open!
|
||||
(fn [id]
|
||||
(fn [[id settings]]
|
||||
(-> (if id
|
||||
(js/Promise.resolve #js {:id id})
|
||||
;; No id: the most recently updated project, which is what "open" means
|
||||
|
|
@ -386,11 +381,12 @@
|
|||
project/schema-version)
|
||||
{})))
|
||||
;; A project made from the index has nothing in it yet: it
|
||||
;; opens on a blank document, of which the server has seen
|
||||
;; nothing, so the first save sends all of it.
|
||||
;; opens on a blank document made with what it was created
|
||||
;; with, of which the server has seen nothing, so the first
|
||||
;; save sends all of it.
|
||||
(-> (if clip-json
|
||||
(opened-entry! clip-json)
|
||||
(js/Promise.resolve (assoc (blank-entry) :synced {})))
|
||||
(js/Promise.resolve (assoc (blank-entry settings) :synced {})))
|
||||
(.then (fn [entry]
|
||||
(rf/dispatch [::opened
|
||||
(store/install! entry "project")
|
||||
|
|
@ -570,15 +566,17 @@
|
|||
"/static/arthur/audio.wav")
|
||||
|
||||
(defn blank-entry
|
||||
"A blank clip, in the shape `footage/store` and the transport expect."
|
||||
[]
|
||||
(let [c (clip/blank)]
|
||||
{:label "untitled" :clip c :store nil
|
||||
"A blank clip, in the shape `footage/store` and the transport expect.
|
||||
`settings` is what `clip/blank` takes."
|
||||
([] (blank-entry nil))
|
||||
([settings]
|
||||
(let [c (clip/blank settings)]
|
||||
{:label (:name c) :clip c :store nil
|
||||
:audio blank-audio
|
||||
;; A content id of its own from the start: `::save!` addresses the clip by
|
||||
;; it, and two untitled documents saved from two tabs are two documents.
|
||||
:cid (str (random-uuid))
|
||||
:fps (:fps c) :width (:width c) :height (:height c)}))
|
||||
:fps (:fps c) :width (:width c) :height (:height c)})))
|
||||
|
||||
(rf/reg-event-fx
|
||||
::new
|
||||
|
|
@ -594,7 +592,7 @@
|
|||
:busy? false :status "new document"}))
|
||||
;; The readout goes home with the document; so must the clock, or play
|
||||
;; picks up wherever the last document's audio had got to.
|
||||
::pb/seek! [(:fps entry) (clip/output-frames (:clip entry) (clip/opens-on (:clip entry))) 0]
|
||||
::pb/seek! [(:fps entry) (clip/frames (:clip entry) (clip/opens-on (:clip entry))) 0]
|
||||
::pb/pause! nil
|
||||
::pb/clock! {:id id :sid (clip/opens-on (:clip entry))}})))
|
||||
|
||||
|
|
@ -657,18 +655,30 @@
|
|||
(rf/reg-event-fx
|
||||
::project-setting
|
||||
(fn [{:keys [db]} [_ key value]]
|
||||
(if (or (not (#{:fps :width :height} key))
|
||||
(if (or (not (#{:width :height} key))
|
||||
(not (and (integer? value) (pos? value))))
|
||||
{}
|
||||
(let [db' (edit/edit db #(if (= key :fps) (clip/set-root-fps % value) (assoc % key value)))
|
||||
db' (assoc-in db' [:clip key] value)
|
||||
frame (min (dec (pb/frames db'))
|
||||
(js/Math.floor (* (get-in db [:playback :frame])
|
||||
(/ value (get-in db [:clip :fps])))))]
|
||||
(cond-> {:db db'}
|
||||
(= key :fps) (assoc :db (assoc-in db' [:playback :frame] frame)
|
||||
::pb/seek! [value (pb/frames db') frame]
|
||||
:dispatch [::pb/refresh-clock]))))))
|
||||
{:db (-> (edit/edit db #(assoc % key value))
|
||||
(assoc-in [:clip key] value))})))
|
||||
|
||||
(rf/reg-event-fx
|
||||
::set-fps
|
||||
;; `:keep-frames` plays every frame for the new tick; `:scale-spans` moves
|
||||
;; every frame to where the same moment falls. See `domain/retime`. The
|
||||
;; playhead stays on the frame it was on, or on the same moment.
|
||||
(fn [{:keys [db]} [_ value mode]]
|
||||
(let [old (get-in db [:clip :fps])]
|
||||
(if (or (not (and (integer? value) (pos? value))) (= value old))
|
||||
{}
|
||||
(let [scale? (= mode :scale-spans)
|
||||
db' (-> (edit/edit db #(if scale? (retime/scale-spans % value) (assoc % :fps value)))
|
||||
(assoc-in [:clip :fps] value))
|
||||
frame (min (dec (pb/frames db'))
|
||||
(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
|
||||
::rename-symbol
|
||||
|
|
@ -690,7 +700,7 @@
|
|||
(rf/reg-event-db
|
||||
::symbol-setting
|
||||
(fn [db [_ sid key value]]
|
||||
(if-not (and (#{:frames :fps :width :height} key)
|
||||
(if-not (and (#{:frames :width :height} key)
|
||||
(or (nil? value) (and (integer? value) (pos? value))))
|
||||
db
|
||||
(edit/edit db
|
||||
|
|
@ -708,6 +718,13 @@
|
|||
(-> (edit/edit db #(assoc-in % [:palettes id] p))
|
||||
(assoc-in [:ui :palette] id)))))
|
||||
|
||||
(rf/reg-event-db
|
||||
::add-palette
|
||||
;; One of `palette/presets` into a project that does not have it yet.
|
||||
(fn [db [_ p]]
|
||||
(-> (edit/edit db #(assoc-in % [:palettes (:id p)] p))
|
||||
(assoc-in [:ui :palette] (:id p)))))
|
||||
|
||||
(rf/reg-event-db
|
||||
::duplicate-palette
|
||||
;; A copy of an existing palette, selected so the next colour edit lands on the
|
||||
|
|
@ -878,7 +895,8 @@
|
|||
{}
|
||||
{:db (update db :project merge {:busy? true :status "opening…"})
|
||||
::pb/pause! nil
|
||||
::open! (or id (:id (:project db)))})))
|
||||
::open! (let [id (or id (:id (:project db)))]
|
||||
[id (get-in db [:new-projects id])])})))
|
||||
|
||||
(rf/reg-event-fx
|
||||
::load-stage
|
||||
|
|
@ -939,17 +957,22 @@
|
|||
(rf/reg-event-fx
|
||||
::opened
|
||||
(fn [{:keys [db]} [_ clip-id project-id name seq access]]
|
||||
{:db (-> (pb/show db clip-id)
|
||||
(cond->
|
||||
{:db (-> (pb/show db clip-id)
|
||||
(update :project merge access
|
||||
{:id project-id :name name :seq seq
|
||||
:cid (:cid (store/entry clip-id))
|
||||
:busy? false
|
||||
:status (str "opened " name " r" seq)}))
|
||||
:status (str "opened " name " r" seq)})
|
||||
(update :new-projects dissoc project-id))
|
||||
::pb/pause! nil
|
||||
::pb/seek! (let [{c :clip fps :fps} (store/entry clip-id)]
|
||||
[fps (clip/output-frames c (clip/opens-on c)) 0])
|
||||
[fps (clip/frames c (clip/opens-on c)) 0])
|
||||
::pb/clock! {:id clip-id
|
||||
:sid (clip/opens-on (:clip (store/entry clip-id)))}}))
|
||||
:sid (clip/opens-on (:clip (store/entry clip-id)))}}
|
||||
;; A project just made opens on a document built from what it was made
|
||||
;; with, which only this client knows until it is saved.
|
||||
(get-in db [:new-projects project-id]) (assoc :dispatch [::save {:auto? true :force? true}]))))
|
||||
|
||||
(rf/reg-event-fx
|
||||
::failed
|
||||
|
|
|
|||
|
|
@ -38,19 +38,10 @@
|
|||
|
||||
(defn editing-frame
|
||||
"The frame of the open symbol the playhead is showing: the coordinate every
|
||||
command in here works in, and the only thing `[:playback :frame]` is read for.
|
||||
|
||||
THE ONE CONVERSION, AND IT IS IN ONE DIRECTION. `[:playback :frame]` counts the
|
||||
OUTPUT grid — the clock's, the audio's, export's — and everything authored is in
|
||||
the frames of the symbol it lives in. A 12fps project holding 30fps symbols puts
|
||||
2.5 of those frames in one of these, so a command handed the raw playhead was
|
||||
being handed a number in the wrong units; `clip/shown-frame` is which frame of
|
||||
the symbol that output frame actually shows. See `docs/one-grid-plan.md`.
|
||||
|
||||
`::playback/seek` takes the output frame back, through
|
||||
`clip/first-output-frame`."
|
||||
[db clip]
|
||||
(clip/shown-frame clip (get-in db [:ui :open]) (get-in db [:playback :frame])))
|
||||
command in here works in. Every symbol counts in the document's one rate, so it
|
||||
is the playhead."
|
||||
[db _clip]
|
||||
(get-in db [:playback :frame]))
|
||||
|
||||
(rf/reg-event-db
|
||||
::rename-node
|
||||
|
|
@ -216,12 +207,10 @@
|
|||
(editing-frame db clip)))]
|
||||
(cond-> {:db (apply-command db sid result retry)}
|
||||
(and (:clip result) (:frame result) rate)
|
||||
;; Out of the made node's frames into the open symbol's, then out of those
|
||||
;; into the output frame the transport seeks in — the one place that second
|
||||
;; step is needed, because this is the one command that moves the playhead.
|
||||
;; Out of the made node's frames into the open symbol's, which the
|
||||
;; transport counts in too: the first whole frame that shows it.
|
||||
(assoc :dispatch [::playback/seek
|
||||
(clip/first-output-frame clip open
|
||||
(+ at (/ (:frame result) rate)))]))))
|
||||
(js/Math.ceil (+ at (/ (:frame result) rate)))]))))
|
||||
|
||||
(defn selection-frame
|
||||
"The playhead as a frame of the symbol that owns `selection`.
|
||||
|
|
@ -857,7 +846,6 @@
|
|||
{:refused "the playhead is past the end of this symbol"}
|
||||
:else
|
||||
(let [new-symbol (cond-> {:id sid :name (name sid)
|
||||
:fps (clip/fps document host)
|
||||
;; A fresh cel is one frame for
|
||||
;; frame-by-frame work. In an
|
||||
;; ordinary composition the new
|
||||
|
|
@ -1004,7 +992,7 @@
|
|||
(update-in [:symbols track]
|
||||
#(merge {:id track :name "palette" :type :palette-track
|
||||
:display :lane :frames (clip/frames document owner)
|
||||
:fps (clip/fps document owner) :nodes {}}
|
||||
:nodes {}}
|
||||
%)))
|
||||
[:node track nil []]])
|
||||
[document target]))
|
||||
|
|
@ -1029,7 +1017,6 @@
|
|||
(let [seeded (assoc-in document [:symbols sid]
|
||||
(cond-> {:id sid
|
||||
:name (if palette? "palette transition" (name sid))
|
||||
:fps (clip/fps document (:sid where))
|
||||
:frames 1 :nodes {}}
|
||||
palette? (assoc :type :palette)))
|
||||
result (span/place-symbol seeded st (:sid where) uuid sid (:at where)
|
||||
|
|
@ -1105,10 +1092,13 @@
|
|||
;; the same picture, and a second symbol would only be a second name for it.
|
||||
;;
|
||||
;; A STILL ARRIVES WITH NO LENGTH, and is made as long as what is left of the
|
||||
;; symbol it lands in, at that symbol's rate: it shows the same picture on every
|
||||
;; frame, so its length is only how long it lasts, and trimming is how that
|
||||
;; changes afterwards.
|
||||
(fn [db [_ sym frame point target]]
|
||||
;; symbol it lands in: it shows the same picture on every frame, so its length
|
||||
;; is only how long it lasts, and trimming is how that changes afterwards.
|
||||
;;
|
||||
;; FOOTAGE ARRIVES WITH ITS RATE, and the symbol does not keep it: its frames
|
||||
;; are the footage's, and the placement plays them at the speed that makes them
|
||||
;; real time here — 2.5 for 30fps footage in a 12fps project.
|
||||
(fn [db [_ {source-fps :fps :as sym} frame point target]]
|
||||
(let [{document :clip st :store} (store/entry (:clip/current db))
|
||||
where (if point
|
||||
(creation-destination db document st frame)
|
||||
|
|
@ -1120,13 +1110,13 @@
|
|||
sid (or same (clip/free-id #(contains? (:symbols document) %) :tracing))
|
||||
sym (if same
|
||||
(clip/symbol document same)
|
||||
(cond-> (assoc sym :id sid)
|
||||
(nil? (:frames sym)) (assoc :frames (max 1 (- (clip/frames document host) at))
|
||||
:fps (clip/fps document host))))
|
||||
(cond-> (-> sym (dissoc :fps) (assoc :id sid))
|
||||
(nil? (:frames sym)) (assoc :frames (max 1 (- (clip/frames document host) at)))))
|
||||
uuid (random-uuid)
|
||||
result (span/place-symbol (assoc-in document [:symbols sid] sym) st host
|
||||
uuid sid at
|
||||
{:extent :grow-symbol
|
||||
:speed (if source-fps (/ source-fps (:fps document)) 1)
|
||||
:point (destination-point where point)
|
||||
:remainder-id (random-uuid)})]
|
||||
(landed db where uuid
|
||||
|
|
@ -1260,7 +1250,7 @@
|
|||
(if (and auto-key? (seq values))
|
||||
(let [{document :clip st :store} (store/entry (:clip/current db))]
|
||||
(if-let [{:keys [sid id frame]} (nest/placement document st open path
|
||||
(clip/shown-frame document open f))]
|
||||
f)]
|
||||
(assoc-in db [:ui :gesture]
|
||||
(-> g
|
||||
(assoc :sid sid :id id :frame frame)
|
||||
|
|
|
|||
|
|
@ -164,12 +164,12 @@
|
|||
[width height] (clip/stage clip sid)
|
||||
zoom (max 1 (js/Math.floor (or zoom 1)))]
|
||||
(when sym
|
||||
{:frames (clip/output-frames clip sid)
|
||||
{:frames (clip/frames clip sid)
|
||||
:fps (:fps clip)
|
||||
:zoom zoom
|
||||
:width (* width zoom)
|
||||
:height (* height zoom)
|
||||
:seconds (/ (clip/output-frames clip sid) (:fps clip))})))
|
||||
:seconds (/ (clip/frames clip sid) (:fps clip))})))
|
||||
|
||||
(defn run!
|
||||
"Render symbol `sid` into `exporter`. Promise of `{:filename :blob}`.
|
||||
|
|
|
|||
|
|
@ -715,12 +715,12 @@
|
|||
"The tracing symbol for `:footage` — `{:id :range :width :height}`, the
|
||||
footage measured and which of its frames — or nil when the measurement came
|
||||
from no footage: a synthetic take has nothing to show. See `clip/trace?`."
|
||||
[{:keys [analysis fps footage]}]
|
||||
[{:keys [analysis footage]}]
|
||||
(when-let [{:keys [id range width height]} footage]
|
||||
{:id :footage :name (or (:source analysis) "footage")
|
||||
:type :trace
|
||||
:media {:footage id :range range}
|
||||
:frames (- (second range) (first range)) :fps fps :width width :height height
|
||||
:frames (- (second range) (first range)) :width width :height height
|
||||
:nodes {}}))
|
||||
|
||||
;; ---------------------------------------------------------------------------
|
||||
|
|
@ -810,7 +810,7 @@
|
|||
:features (merged :features) :groups (merged :groups)
|
||||
:symbols
|
||||
(into {:main
|
||||
{:id :main :fps fps :frames nf
|
||||
{:id :main :frames nf
|
||||
:nodes (into {:root {:id :root :name "clip" :kind :group :z "a1"
|
||||
:time {:mode :map :expose expose}}}
|
||||
(map-indexed
|
||||
|
|
@ -821,7 +821,7 @@
|
|||
ordered)}}
|
||||
(concat
|
||||
(map (fn [[id part]]
|
||||
[id (assoc (place-in (:symbol part) placement) :fps fps)])
|
||||
[id (place-in (:symbol part) placement)])
|
||||
parts)
|
||||
(when-let [footage (footage-symbol params)]
|
||||
[[:footage footage]])))}]
|
||||
|
|
|
|||
|
|
@ -170,7 +170,7 @@
|
|||
(throw (ex-info "regeneration needs retained source landmarks"
|
||||
{:subject subject})))
|
||||
base-params (merge take/knobs
|
||||
{:fps (or (get-in changed [:symbols subject :fps]) (:fps changed))
|
||||
{:fps (or (:fps analysis) (:fps changed))
|
||||
:aspect (:aspect analysis)
|
||||
:analysis analysis})
|
||||
;; One conditioned anchor for the whole edit, and it is the SUBJECT's.
|
||||
|
|
|
|||
|
|
@ -90,11 +90,10 @@
|
|||
::frames
|
||||
:<- [::clip]
|
||||
:<- [::open]
|
||||
;; THE TRANSPORT'S LENGTH, in output frames: what the clock counts, what the
|
||||
;; readout reads and what export writes. The timeline's length is
|
||||
;; `::open-frames`, which is a different number whenever the open symbol was
|
||||
;; authored on a different grid — see `docs/one-grid-plan.md`.
|
||||
(fn [[document sid] _] (clip/output-frames document sid)))
|
||||
;; THE TRANSPORT'S LENGTH: what the clock counts, what the readout reads and
|
||||
;; what export writes. Nil for a symbol that is not there; `::open-frames` is
|
||||
;; the same length read as 0, for drawing a ruler.
|
||||
(fn [[document sid] _] (clip/frames document sid)))
|
||||
|
||||
(rf/reg-sub
|
||||
::open-frames
|
||||
|
|
@ -110,10 +109,9 @@
|
|||
:<- [::clip]
|
||||
:<- [::open]
|
||||
:<- [::playback/frame]
|
||||
;; Where the playhead is IN THE OPEN SYMBOL — the one crossing from the output
|
||||
;; grid for everything that draws or edits in the timeline, and an integer
|
||||
;; frame of the symbol rather than a fraction between two of them.
|
||||
(fn [[document sid f] _] (clip/shown-frame document sid f)))
|
||||
;; Where the playhead is in the open symbol. Every symbol counts in the
|
||||
;; document's one rate, so this is the playhead itself.
|
||||
(fn [[_ _ f] _] f))
|
||||
|
||||
(rf/reg-sub
|
||||
::exposure
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@
|
|||
(let [{document :clip st :store} (store/entry clip-id)]
|
||||
(reset! carrying (merge {:kind :symbol :sid sid
|
||||
:label (clip/symbol-name document sid)
|
||||
:frames (clip/output-frames document sid)
|
||||
:frames (clip/frames document sid)
|
||||
;; A symbol cannot go inside itself or inside
|
||||
;; anything it places. Refused by not ACCEPTING the
|
||||
;; drop, so the pointer says so while it hovers.
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
the draw loop stay mounted, and opening a project is showing them again."
|
||||
(:require [arthur.events.collab :as collab]
|
||||
[arthur.events.project :as project]
|
||||
[arthur.ui.settings :as settings]
|
||||
[arthur.ui.share :as share]
|
||||
[re-frame.core :as rf]))
|
||||
|
||||
|
|
@ -26,7 +27,7 @@
|
|||
[:<>
|
||||
[:div.index-head
|
||||
[:h1 "projects"]
|
||||
[:button {:on-click #(rf/dispatch [::collab/create])} "new project"]]
|
||||
[settings/new-project "new project"]]
|
||||
(when error [:p.warn error])
|
||||
(cond
|
||||
loading? [:p.dim "…"]
|
||||
|
|
|
|||
|
|
@ -177,7 +177,7 @@
|
|||
:on-click #(pick! [:remap {}] placements)}
|
||||
"⇄"]]]]))
|
||||
|
||||
(defn- strip
|
||||
(defn strip
|
||||
"Every slot of a palette, side by side: what it looks like at a glance."
|
||||
[{:keys [slots]}]
|
||||
[:span.strip (for [[i {:keys [hex]}] (map-indexed vector slots)]
|
||||
|
|
@ -279,5 +279,14 @@
|
|||
[:div.row
|
||||
[:button {:title "a new 16-slot palette" :on-click #(rf/dispatch [::project/new-palette])} "new"]
|
||||
[:button {:title (str "a copy of " (:name palette) " you can retone")
|
||||
:on-click #(rf/dispatch [::project/duplicate-palette pid])} "duplicate"]]])]
|
||||
:on-click #(rf/dispatch [::project/duplicate-palette pid])} "duplicate"]]
|
||||
(when-let [missing (seq (remove #(contains? (pal/palettes clip) (:id %)) pal/presets))]
|
||||
[:div.palette-list {:aria-label "presets"}
|
||||
(doall
|
||||
(for [p missing]
|
||||
^{:key (str (:id p))}
|
||||
[:div.palette-row
|
||||
[:button.choose {:title (str "add " (:name p) " to this project")
|
||||
:on-click #(rf/dispatch [::project/add-palette p])}
|
||||
[strip p] [:span.name (str "+ " (:name p))]]]))])])]
|
||||
[elsewhere pid palette]]))
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@
|
|||
[arthur.subs.render :as render]
|
||||
[arthur.subs.ui :as sub]
|
||||
[arthur.ui.palette :as palette]
|
||||
[arthur.ui.settings :as settings]
|
||||
[re-frame.core :as rf]
|
||||
[reagent.core :as r]))
|
||||
|
||||
|
|
@ -89,7 +90,6 @@
|
|||
|
||||
(defn- clip-section []
|
||||
(let [clip @(rf/subscribe [::render/clip])
|
||||
fps @(rf/subscribe [::playback/fps])
|
||||
open @(rf/subscribe [::render/open])
|
||||
frames @(rf/subscribe [::render/frames])
|
||||
project @(rf/subscribe [::playback/project])
|
||||
|
|
@ -98,8 +98,7 @@
|
|||
[facts
|
||||
"stage" (str (:width clip) "×" (:height clip))
|
||||
"open" (some-> open name)
|
||||
"length" (str frames " frames")
|
||||
"rate" (str fps " fps")]
|
||||
"length" (str frames " frames")]
|
||||
[:div.inspector-form
|
||||
[name-field "name" (or (:name project) (:name clip) "")
|
||||
#(rf/dispatch [::project/rename %])]
|
||||
|
|
@ -107,8 +106,7 @@
|
|||
#(rf/dispatch [::project/project-setting :width %]) nil busy?]
|
||||
[number-field "height" (:height clip)
|
||||
#(rf/dispatch [::project/project-setting :height %]) nil busy?]
|
||||
[number-field "project fps" fps
|
||||
#(rf/dispatch [::project/project-setting :fps %]) nil busy?]]]))
|
||||
[settings/rate busy?]]]))
|
||||
|
||||
;; ---------------------------------------------------------------------------
|
||||
;; a node
|
||||
|
|
@ -639,7 +637,7 @@
|
|||
[section (or title "symbol")
|
||||
[facts
|
||||
"id" (str sid)
|
||||
"length" (str (:frames sym) " frames at " (clip-domain/fps clip sid) " fps")
|
||||
"length" (str (:frames sym) " frames")
|
||||
"stage" (let [[w h] (clip-domain/stage clip sid)] (str w "×" h))
|
||||
"nodes" (str (count (:nodes sym)))]
|
||||
[:div.inspector-form
|
||||
|
|
@ -647,11 +645,6 @@
|
|||
#(rf/dispatch [::project/rename-symbol sid %])]
|
||||
[number-field "length (frames)" (:frames sym)
|
||||
#(rf/dispatch [::project/symbol-setting sid :frames %]) nil busy?]
|
||||
[number-field "fps" (clip-domain/fps clip sid)
|
||||
#(rf/dispatch (if (= sid (clip-domain/opens-on clip))
|
||||
[::project/project-setting :fps %]
|
||||
[::project/symbol-setting sid :fps %]))
|
||||
nil busy?]
|
||||
[number-field "width" (:width sym)
|
||||
#(rf/dispatch [::project/symbol-setting sid :width %]) "project default" busy?]
|
||||
[number-field "height" (:height sym)
|
||||
|
|
|
|||
114
frontend/src/arthur/ui/settings.cljs
Normal file
114
frontend/src/arthur/ui/settings.cljs
Normal 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"]]])])))
|
||||
|
|
@ -72,7 +72,7 @@
|
|||
"How long the thing this node places is, for a placement carrying no span of
|
||||
its own. 0 for a node that places nothing, or a reference with nothing there."
|
||||
[clip sid n]
|
||||
(if-let [{:keys [at rate]} (clip/source-time clip sid n)]
|
||||
(if-let [{:keys [at rate]} (node/source-time n)]
|
||||
(+ at (/ (or (clip/frames clip (node/source n)) 0) rate))
|
||||
(clip/frames clip sid)))
|
||||
|
||||
|
|
@ -136,7 +136,7 @@
|
|||
(letfn [(inside-rows [sid n path depth self span]
|
||||
;; The rows of the symbol a clip places, mapped into this ruler.
|
||||
;;
|
||||
;; A HELD CLIP HAS NO INVERTIBLE CLOCK. `clip/source-time` is nil
|
||||
;; A HELD CLIP HAS NO INVERTIBLE CLOCK. `node/source-time` is nil
|
||||
;; for a hold, a loop and an endpoint policy: one source frame is
|
||||
;; shown for the whole span, so no frame inside it has a place on
|
||||
;; this ruler. That used to mean the contents were not shown at
|
||||
|
|
@ -146,7 +146,7 @@
|
|||
;; the key positions, and the bars that would imply them. Refuse
|
||||
;; rather than guess, without refusing the whole subtree.
|
||||
(when-let [source (and (= :instance (:kind n)) (node/source n))]
|
||||
(if-let [source-time (clip/source-time clip sid n)]
|
||||
(if-let [source-time (node/source-time n)]
|
||||
(walk source path depth (comp self (time->parent source-time)))
|
||||
(mapv (fn [row]
|
||||
(-> row
|
||||
|
|
@ -263,10 +263,9 @@
|
|||
source-sym (when (= :instance (:kind n))
|
||||
(clip/symbol clip (node/source n)))
|
||||
;; `self` maps the instance's local clock. Rows of
|
||||
;; the symbol it places use its source clock too,
|
||||
;; including the native-FPS ratio.
|
||||
;; the symbol it places use its source clock too.
|
||||
source-self (if-let [t (and source-sym
|
||||
(clip/source-time clip sid n))]
|
||||
(node/source-time n))]
|
||||
(comp self (time->parent t))
|
||||
self)
|
||||
lane? (symbol/lane? source-sym)
|
||||
|
|
@ -380,22 +379,17 @@
|
|||
inside the symbols this one places, mapped into this ruler."
|
||||
[clip sid expanded]
|
||||
(if-not (get-in clip [:symbols sid]) []
|
||||
(let [lane? (symbol/lane? (clip/symbol clip sid))
|
||||
;; THE MIXER'S INTERVALS ARE IN OUTPUT FRAMES and this ruler is in the
|
||||
;; symbol's own, so these rows -- and only these -- convert.
|
||||
;; `nest/audio-tracks` is the mixer's own flattening and audio is
|
||||
;; measured in seconds, which is why it keeps the transport's grid. A
|
||||
;; sound's bar may land between two marks, and that is honest: a sound
|
||||
;; does not have to start on a frame boundary.
|
||||
own (let [rate (:rate (clip/grid-time clip sid))] #(some-> % (* rate)))
|
||||
own-span (fn [sp] (when-let [[a b] sp] [(own a) (own b)]))]
|
||||
;; `nest/audio-tracks` is the mixer's own flattening. A sound's bar may land
|
||||
;; between two marks, and that is honest: a sound does not have to start on
|
||||
;; a frame boundary.
|
||||
(let [lane? (symbol/lane? (clip/symbol clip sid))]
|
||||
(vec
|
||||
(mapcat
|
||||
(fn [[path tracks]]
|
||||
(let [n (first tracks)
|
||||
authored (get-in clip [:symbols (:owner n) :nodes (:id n)])
|
||||
authored->open (comp own (local->parent n))
|
||||
span (own-span (node/placed-span n))
|
||||
authored->open (local->parent n)
|
||||
span (node/placed-span n)
|
||||
select [:node (:owner n) (:id n) path]
|
||||
open? (contains? expanded path)
|
||||
via (when (< 1 (count path)) (str (first path)))
|
||||
|
|
@ -404,12 +398,12 @@
|
|||
:key-items (key-items authored (:owner n) authored->open)
|
||||
:slides (if via (subvec path 0 1) path)
|
||||
:select select :expandable? true :expanded? open? :span span
|
||||
:keys (mapv own (distinct (mapcat keyed-frames (vals (:channels n)))))}]
|
||||
:keys (vec (distinct (mapcat keyed-frames (vals (:channels n)))))}]
|
||||
(cons (cond-> row
|
||||
(< 1 (count tracks))
|
||||
(assoc :cels (mapv (fn [i track]
|
||||
{:id i :label (node-label clip (:id track) track)
|
||||
:span (own-span (node/placed-span track))
|
||||
:span (node/placed-span track)
|
||||
:select select})
|
||||
(range) tracks)))
|
||||
(when open? (channel-rows authored (:owner n) path 1 authored->open span)))))
|
||||
|
|
@ -502,8 +496,7 @@
|
|||
;; where the playhead is somewhere it means something -- and in the open
|
||||
;; symbol's own frames, which is what the commands take. `frame` and
|
||||
;; `frames` above are the transport's own numbers and are only read out.
|
||||
owner-frame (ui/selection-frame clip st open selection
|
||||
(clip/shown-frame clip open frame))
|
||||
owner-frame (ui/selection-frame clip st open selection frame)
|
||||
;; TWO COORDINATES AND THEY ARE NOT THE SAME. `host` is the frame of
|
||||
;; whatever the selection is positioned in — its lane, for a cel; the
|
||||
;; symbol, for a free placement — and is what the span commands take.
|
||||
|
|
@ -552,7 +545,7 @@
|
|||
^{:key r} [:option {:value r} label]))]]
|
||||
[:span.sep]
|
||||
;; The same direct timing operations apply to any selected symbol clip,
|
||||
;; whether it is still a legacy root node or lives in a lane.
|
||||
;; whether it is placed freely or lives in a lane.
|
||||
[:div.group.timing-controls {:aria-label "timing"}
|
||||
[:button {:disabled (not cuttable?) :aria-label "split"
|
||||
:title "split the selected clip at the playhead"
|
||||
|
|
@ -1382,18 +1375,11 @@
|
|||
visible (cond-> (vec picture)
|
||||
(seq sounds) (-> (conj {:path [::sounds] :kind :section :label "audio"})
|
||||
(into sounds)))
|
||||
;; Major marks are whole seconds in the OPEN symbol's clock. On long
|
||||
;; timelines use a whole-number multiple of a second to keep roughly
|
||||
;; ten labels; never invent an FPS-blind 20/40/60 ruler.
|
||||
fps (max 1 (or (clip/fps clip open) 1))
|
||||
;; Major marks are whole seconds. On long timelines use a whole-number
|
||||
;; multiple of a second to keep roughly ten labels; never invent an
|
||||
;; FPS-blind 20/40/60 ruler.
|
||||
fps (max 1 (or (:fps clip) 1))
|
||||
step (* fps (max 1 (js/Math.ceil (/ frames (* fps 10)))))
|
||||
;; THE OTHER DIRECTION, AND THE ONLY PLACE THIS PANE GOES THERE. The
|
||||
;; ruler is in the open symbol's frames and the transport counts output
|
||||
;; frames, so scrubbing names a mark and seeks to the output frame that
|
||||
;; first shows it. Several marks can share one output frame when the
|
||||
;; symbol was authored on a finer grid; that is what playing it at this
|
||||
;; project's rate means, and the playhead lands where it will really be.
|
||||
seek-to (fn [^js e n] (clip/first-output-frame clip open (frame-at e n)))
|
||||
choose-row! (fn [e target]
|
||||
(let [xs (vec (keep :select visible))
|
||||
anchor (or @row-anchor selection target)
|
||||
|
|
@ -1527,11 +1513,11 @@
|
|||
(drag/land! (frame-at e frames) nil))
|
||||
;; The rows and ruler share this exact major interval. Keeping a
|
||||
;; second, hard-coded five-frame grid here made its lines disagree
|
||||
;; with the numbered marks whenever the symbol's FPS changed.
|
||||
;; with the numbered marks whenever the project's FPS changed.
|
||||
:style {"--tick" (str (* 100 (/ step frames)) "%")}}
|
||||
[:div.tl-ruler
|
||||
{:on-pointer-down (fn [^js e]
|
||||
(rf/dispatch [::pb/seek (seek-to e frames)])
|
||||
(rf/dispatch [::pb/seek (frame-at e frames)])
|
||||
(reset! scrubbing true)
|
||||
;; Capture is what keeps a drag scrubbing once it
|
||||
;; leaves the ruler, and it is an ENHANCEMENT: it
|
||||
|
|
@ -1547,7 +1533,7 @@
|
|||
(catch :default _ nil)))
|
||||
:on-pointer-move (fn [^js e]
|
||||
(when @scrubbing
|
||||
(rf/dispatch [::pb/seek (seek-to e frames)])))
|
||||
(rf/dispatch [::pb/seek (frame-at e frames)])))
|
||||
:on-pointer-up (fn [_] (reset! scrubbing false))
|
||||
:on-pointer-cancel (fn [_] (reset! scrubbing false))}
|
||||
(doall
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
[arthur.ui.layout :as layout]
|
||||
[arthur.ui.menu :as menu]
|
||||
[arthur.ui.openmenu :as openmenu]
|
||||
[arthur.ui.settings :as settings]
|
||||
[arthur.ui.share :as share]
|
||||
[arthur.ui.snapshots :as snapshots]
|
||||
[arthur.ui.undo :as undo]
|
||||
|
|
@ -74,7 +75,7 @@
|
|||
;; this strip scrolls, and which panes are open is the one control that
|
||||
;; must not be the thing off the end of it.
|
||||
[layout/panes]
|
||||
[:button {:disabled busy? :on-click #(rf/dispatch [::collab/create])} "new"]
|
||||
[settings/new-project "new"]
|
||||
[openmenu/view]
|
||||
[undo/view]
|
||||
[menu/view
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue