Skip to content

armgit / raea

Public Imported from GitHub
0

Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.

TL11a, TL13: a plugin's tools and snap grids as data in the timeline SDK; the window's drag told apart (a hit test a step, now gone: 27 to 36 frames a second) and what is left

shinyobjectze31056b6ad78
diff --git a/docs/timeline.feature b/docs/timeline.feature
index 26e65689..81d5c5fd 100644
--- a/docs/timeline.feature
+++ b/docs/timeline.feature
@@ -94,7 +94,8 @@ Feature: The timeline SDK (0.1.5): CapCut's timeline, on the composition, in the
of CSS filter functions, drawn by <Effect parts> and by the preview alike), TL8a
(waveform, level line, fades), TL8b's beats as ticks that edges snap to, each turned off by a
click, TL8c (Record from the playhead, the picture playing; the recording a clip named by what was
- said, its file in the project's attachments), TL11a for easings, speed curves, transitions and effects as data,
+ said, its file in the project's attachments), TL11a for easings, speed curves, transitions, effects, text styles, tools (presets put
+ on the picked clips) and snap grids as data,
TL9d (an item's own timeline: an edit kept in the item's data, Send telling its agent), TL12a-b,
TL14a-c
in code a composition's sequences: move, trim, split, delete (E3), keys on x, y, scale, rotate and opacity
@@ -112,7 +113,8 @@ Feature: The timeline SDK (0.1.5): CapCut's timeline, on the composition, in the
seconds at a time at draft quality and kept by range, each range under what it is drawn from (the
code outside the scene's sequences and the sequences on in it), so an edit to one sequence draws
again only the ranges it is on and an undo plays what it had; the store stays under a size
- (RAEA_SCENE_FRAMES_LIMIT, 1 GiB), the least recently played going first; the scene's timeline
+ (RAEA_SCENE_FRAMES_LIMIT, 1 GiB), the least recently played going first, and beside the switch the
+ scene's kept frames say what they take and are cleared by a click; the scene's timeline
shows what is kept, and Play runs it over the stage from the scene's own camera, handing back to
the live stage where nothing is kept. Seen in a headless raea window on the real host: the sample
room drawn, kept, and played at its own rate; a 9 s copy of it opened again with every range
@@ -121,8 +123,10 @@ Feature: The timeline SDK (0.1.5): CapCut's timeline, on the composition, in the
decided TL10b, c and e in the SDK (which ranges an edit changes, a range's key, what goes first); a
composition's drafts are kept by their source, the least recently played going first under 1 GiB
(RAEA_DRAFTS_LIMIT), so an undo plays its draft again at once
- not built TL11a's tools and snapping targets; TL13a's drag at the window's rate with 400 clips (measured
- below: Chrome keeps it, raea's window draws 27 to 31 frames a second). The skills guide's note
+ not built TL13a's drag at the window's rate with 400 clips (measured below: Chrome keeps it, raea's window
+ draws 35 to 37 frames a second, and what is left is the window's own frame after a change). A
+ plugin's tools, snap grids, effects and text styles are checked as data and offered in the bar, but
+ not yet seen with a plugin installed. The skills guide's note
on an item's `timeline` field waits for PR #19 to merge
Background:
@@ -433,7 +437,14 @@ Feature: The timeline SDK (0.1.5): CapCut's timeline, on the composition, in the
# 48) and what a drag step adds to it (about 18 ms, 8 with 48). Keeping the clips' drawings did not move the
# window's numbers, so the step's cost there is not React's work on the clips: it is not yet told apart
# between the operation itself (snapping and settling 400 clips) and the window laying the moved clips out.
- # Not yet: that attribution and the fix, and the picture following an edit within 100 ms on the stage.
+ # Told apart since (the measurement times a step's operation and React's commit of it): a drag step asked
+ # the page what was under the pointer (document.elementFromPoint, for the track a clip is carried to), which
+ # in raea's window took 7.7 ms a step (0.2 ms in Chrome). The tracks' places are now read once when a clip
+ # is first carried: the operation is 0.1 ms a step, its commit 2.5 ms, and the window's drag 35 to 37 frames
+ # a second (a frame's median 24 to 26 ms), with nothing moving 80. What is left is the window's: a frame
+ # after any change to the page costs about twice a still one with 400 clips on screen (a clip placed by a
+ # transform instead of its left edge made no difference), so the rest is the engine's layout, not the app's.
+ # Not yet: that, and the picture following an edit within 100 ms on the stage.
Rule: TL14. Watch, Listen and Scene are one timeline
Scenario: TL14a. Watch
diff --git a/sdk/timeline/src/registry.ts b/sdk/timeline/src/registry.ts
index fd3f55e1..aabc3136 100644
--- a/sdk/timeline/src/registry.ts
+++ b/sdk/timeline/src/registry.ts
@@ -59,6 +59,43 @@ export function textStyleError(t: unknown): string | undefined {
return undefined
}
+/** A tool a plugin adds (TL11a): one press sets these on every picked clip, as one edit each. */
+export interface Preset {
+ id: string
+ title: string
+ set: { props?: Record<string, number | boolean>; speed?: number; volume?: number }
+}
+/** Marks edges snap to that a plugin adds (TL11a): a grid, one mark every `every` seconds from the start. */
+export interface SnapGrid {
+ id: string
+ title: string
+ every: number
+}
+/** The props a preset may set: a clip's placement (what the editor's own tools set). */
+export const PRESET_PROPS = ["x", "y", "scale", "rotate", "opacity", "mirror", "cropLeft", "cropTop", "cropRight", "cropBottom"]
+const titled = (x: { id?: unknown; title?: unknown } | null) => !!x && typeof x.id === "string" && /^[a-z][a-z0-9-]*$/.test(x.id) && typeof x.title === "string" && !!x.title.trim()
+/** Why `p` isn't a preset, or undefined when it is. */
+export function presetError(p: unknown): string | undefined {
+ const x = p as Partial<Preset> | null
+ if (!titled(x)) return "is { id, title, set }: id in lowercase letters, digits and dashes, title what the person sees"
+ const set = x!.set
+ if (!set || typeof set !== "object" || Array.isArray(set) || !Object.keys(set).length) return "set is what it puts on a clip: props, speed or volume"
+ for (const k of Object.keys(set)) if (!["props", "speed", "volume"].includes(k)) return `set.${k}: a tool sets props, speed or volume`
+ if (set.speed !== undefined && !(typeof set.speed === "number" && set.speed >= SLOWEST && set.speed <= FASTEST)) return `set.speed runs from ${SLOWEST} to ${FASTEST}`
+ if (set.volume !== undefined && !(typeof set.volume === "number" && set.volume >= 0 && set.volume <= 2)) return "set.volume runs from 0 to 2"
+ for (const [k, v] of Object.entries(set.props ?? {})) {
+ if (!PRESET_PROPS.includes(k)) return `set.props.${k}: a tool places a clip by ${PRESET_PROPS.join(", ")}`
+ if (!(k === "mirror" ? typeof v === "boolean" : typeof v === "number" && Number.isFinite(v))) return `set.props.${k} is ${k === "mirror" ? "true or false" : "a number"}`
+ }
+ return undefined
+}
+/** The frames a snap grid marks in a timeline `length` frames long (none for a grid finer than a frame, or of more than 5,000 marks). */
+export function gridFrames(grid: SnapGrid, fps: number, length: number): number[] {
+ const step = grid.every * fps
+ if (!(step >= 1) || length / step > 5000) return []
+ return Array.from({ length: Math.floor(length / step) }, (_, i) => Math.round((i + 1) * step))
+}
+
/** What one plugin adds. */
export interface Adds {
eases?: Record<string, Ease>
@@ -70,6 +107,10 @@ export interface Adds {
effects?: EffectInfo[]
/** text styles of its own (TL7c, TL11a) */
texts?: TextStyle[]
+ /** tools of its own: presets put on the picked clips */
+ tools?: Preset[]
+ /** marks edges snap to: grids in seconds */
+ snaps?: SnapGrid[]
}
/** raea's own kinds of track, in the order they stack (TL1a). */
@@ -99,7 +140,7 @@ export function readAdds(raw: unknown): { adds: Adds; errors: string[] } {
const errors: string[] = []
const adds: Adds = {}
if (raw === undefined) return { adds, errors }
- if (!raw || typeof raw !== "object" || Array.isArray(raw)) return { adds, errors: ["timeline is an object: { eases, curves, transitions, tracks, effects }"] }
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) return { adds, errors: ["timeline is an object: { eases, curves, transitions, tracks, effects, texts, tools, snaps }"] }
const r = raw as Record<string, unknown>
const named = (v: unknown, what: string): [string, unknown][] => (v === undefined ? [] : v && typeof v === "object" && !Array.isArray(v) ? Object.entries(v) : (errors.push(`timeline.${what} is an object of named ${what}`), []))
for (const [name, e] of named(r.eases, "eases")) {
@@ -144,6 +185,24 @@ export function readAdds(raw: unknown): { adds: Adds; errors: string[] } {
else (adds.effects ??= []).push({ kind: e.kind, title: e.title, parts: e.parts! })
}
}
+ if (r.tools !== undefined) {
+ if (!Array.isArray(r.tools)) errors.push("timeline.tools is a list of { id, title, set }")
+ else
+ for (const [i, x] of r.tools.entries()) {
+ const why = presetError(x)
+ if (why) errors.push(`timeline.tools[${i}] ${why}`)
+ else (adds.tools ??= []).push(x as Preset)
+ }
+ }
+ if (r.snaps !== undefined) {
+ if (!Array.isArray(r.snaps)) errors.push("timeline.snaps is a list of { id, title, every }")
+ else
+ for (const [i, x] of r.snaps.entries()) {
+ const g = x as Partial<SnapGrid> | null
+ if (!titled(g) || !(typeof g!.every === "number" && g!.every >= 0.01 && g!.every <= 600)) errors.push(`timeline.snaps[${i}] is { id, title, every }: every the seconds between marks, from 0.01 to 600`)
+ else (adds.snaps ??= []).push({ id: g!.id!, title: g!.title!, every: g!.every! })
+ }
+ }
if (r.texts !== undefined) {
if (!Array.isArray(r.texts)) errors.push("timeline.texts is a list of { kind, title, place, style }")
else
@@ -158,21 +217,24 @@ export function readAdds(raw: unknown): { adds: Adds; errors: string[] } {
}
/** Everything offered: raea's own, then each plugin's in order (a name a plugin before it took stays that one's). */
-export function palette(plugins: Adds[] = []): { eases: Record<string, Ease>; curves: Record<string, SpeedPoint[]>; transitions: TransitionKind[]; tracks: TrackKindInfo[]; /** the effects a clip of its own puts on the picture (TL7b) */ effects: EffectInfo[]; /** the ways words are put on the picture (TL7c) */ texts: TextStyle[] } {
+export function palette(plugins: Adds[] = []): { eases: Record<string, Ease>; curves: Record<string, SpeedPoint[]>; transitions: TransitionKind[]; tracks: TrackKindInfo[]; /** the effects a clip of its own puts on the picture (TL7b) */ effects: EffectInfo[]; /** the ways words are put on the picture (TL7c) */ texts: TextStyle[]; /** a plugin's tools: presets for the picked clips */ tools: Preset[]; /** a plugin's snap grids */ snaps: SnapGrid[] } {
const eases = { ...EASES }, curves = { ...CURVES }, transitions = [...TRANSITIONS], tracks = [...TRACKS]
const effects: EffectInfo[] = EFFECTS.map(({ kind, title }) => ({ kind, title }))
const texts = [...TEXTS]
+ const tools: Preset[] = [], snaps: SnapGrid[] = []
for (const p of plugins) {
for (const [n, e] of Object.entries(p.eases ?? {})) if (!(n in eases)) eases[n] = e
for (const [n, c] of Object.entries(p.curves ?? {})) if (!(n in curves)) curves[n] = c
for (const t of p.transitions ?? []) if (!transitions.some((o) => o.kind === t.kind)) transitions.push(t)
for (const e of p.effects ?? []) if (!effects.some((o) => o.kind === e.kind)) effects.push(e)
for (const x of p.texts ?? []) if (!texts.some((o) => o.kind === x.kind)) texts.push(x)
+ for (const x of p.tools ?? []) if (!tools.some((o) => o.id === x.id)) tools.push(x)
+ for (const x of p.snaps ?? []) if (!snaps.some((o) => o.id === x.id)) snaps.push(x)
for (const t of p.tracks ?? [])
if (!tracks.some((o) => o.kind === t.kind)) {
tracks.push(t)
if (t.under) under.add(t.kind)
}
}
- return { eases, curves, transitions, tracks, effects, texts }
+ return { eases, curves, transitions, tracks, effects, texts, tools, snaps }
}
diff --git a/sdk/timeline/test/registry.test.ts b/sdk/timeline/test/registry.test.ts
index 74d4f71e..f4d3ee79 100644
--- a/sdk/timeline/test/registry.test.ts
+++ b/sdk/timeline/test/registry.test.ts
@@ -1,5 +1,5 @@
import { describe, expect, test } from "bun:test"
-import { CURVES, EASES, palette, readAdds, seqEdits, fromSequences, TEXTS, TRANSITIONS } from "../src"
+import { CURVES, EASES, gridFrames, palette, readAdds, seqEdits, fromSequences, TEXTS, TRANSITIONS } from "../src"
describe("TL11a: a plugin adds easings, speed curves and transitions", () => {
const raw = {
@@ -33,7 +33,7 @@ describe("TL11a: a plugin adds easings, speed curves and transitions", () => {
test("with no plugin it is raea's own, and a manifest with no timeline adds nothing", () => {
expect(palette().transitions).toEqual(TRANSITIONS)
expect(readAdds(undefined)).toEqual({ adds: {}, errors: [] })
- expect(readAdds([1]).errors).toEqual(["timeline is an object: { eases, curves, transitions, tracks, effects }"])
+ expect(readAdds([1]).errors).toEqual(["timeline is an object: { eases, curves, transitions, tracks, effects, texts, tools, snaps }"])
})
})
@@ -71,3 +71,20 @@ describe("TL7c, TL11a: text styles", () => {
expect(seqEdits(t, { op: "add", kind: "text", clip: { id: "text-1", kind: "text", name: "Hi", props: { style: JSON.stringify(neon) }, start: 0, length: 60 } })).toEqual([{ op: "text", at: 0, frames: 60, text: "Hi", style: neon }])
})
})
+
+describe("TL11a: a plugin's tools and snapping targets", () => {
+ test("a tool is a preset put on the picked clips; a snap grid is marks every so many seconds; both checked", () => {
+ const { adds, errors } = readAdds({
+ tools: [{ id: "punch-in", title: "Punch in", set: { props: { scale: 1.2 } } }, { id: "slow", title: "Half speed", set: { speed: 0.5 } }, { id: "bad", title: "Bad", set: { props: { colour: 1 } } }, { id: "loud", title: "Loud", set: { volume: 9 } }],
+ snaps: [{ id: "bars", title: "Bars at 120", every: 2 }, { id: "fine", title: "Too fine", every: 0.001 }],
+ })
+ expect(adds.tools?.map((t) => t.id)).toEqual(["punch-in", "slow"])
+ expect(adds.snaps).toEqual([{ id: "bars", title: "Bars at 120", every: 2 }])
+ expect(errors).toEqual([expect.stringContaining("timeline.tools[2] set.props.colour: a tool places a clip by"), "timeline.tools[3] set.volume runs from 0 to 2", "timeline.snaps[1] is { id, title, every }: every the seconds between marks, from 0.01 to 600"])
+ const all = palette([adds])
+ expect([all.tools.length, all.snaps.length]).toEqual([2, 1])
+ expect(gridFrames(all.snaps[0], 30, 300)).toEqual([60, 120, 180, 240, 300])
+ expect(gridFrames({ id: "x", title: "x", every: 0.01 }, 30, 300)).toEqual([])
+ expect(palette().tools).toEqual([])
+ })
+})