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.
TypeScript 3dagent-skillsai-agentsai-videobevyclaude-codegame-enginegpulinuxmacosmotion-designmotion-graphicsreactrusttypescriptvideo-editingvideo-renderingwgpuwindows
TL7c: in progress: a composition's sequence of words is a text clip (renamed, its words change; words added are a new sequence), in the timeline's reader and writer
shinyobjectz3620aa1def20
diff --git a/sdk/timeline/src/read.ts b/sdk/timeline/src/read.tsindex d46284cd..3b1d3259 100644--- a/sdk/timeline/src/read.ts+++ b/sdk/timeline/src/read.ts@@ -22,6 +22,8 @@ export interface SeqRow {/** its footage's speed as a curve, each [place 0 to 1, speed] (its media's speedCurve), over `shows` source frames (TL6b) */curve?: [number, number][]shows?: number+ /** the words it shows, when words are all it shows: a text clip, its words changed by renaming it (TL7c) */+ text?: string/** how it comes in and goes out: its <Transition>'s in and out (TL7a) */in?: { kind: string; frames: number }out?: { kind: string; frames: number }@@ -43,6 +45,10 @@ export type SeqEdit =/** the footage it holds played by a speed curve over `source` frames of it, the sequence `frames` long (what the* curve takes); null takes the curve off (TL6b) */| { op: "curve"; i: number; curve: [number, number][] | null; source: number; frames: number }+ /** a text sequence's words (TL7c) */+ | { op: "words"; i: number; text: string }+ /** words put on the picture from `at` for `frames`: a new sequence after the composition's last (TL7c) */+ | { op: "text"; at: number; frames: number; text: string }/** how it comes in ("in") or goes out ("out"): its <Transition>'s edge set, or taken off with 0 frames (TL7a) */| { op: "edge"; i: number; side: "in" | "out"; kind: string; frames: number }/** a <Video>'s or an <Audio>'s own level (TL8a) */@@ -54,6 +60,8 @@ export const CODE_KINDS = ["fade", "slide", "wipe", "zoom"]export const KEYED = ["x", "y", "scale", "rotate", "opacity"]const seqId = (i: number) => `seq-${i}`+// the edits to later elements first (an edit that adds or removes an element moves the places after it)+const later = (a: SeqEdit, b: SeqEdit) => ("i" in b ? b.i : 0) - ("i" in a ? a.i : 0)const seqOf = (id: string): number | undefined => (/^seq-\d+$/.test(id) ? Number(id.slice(4)) : undefined)/** The composition's sequences as a timeline: a track a lane, the first lane on top as the strip draws it. The first@@ -63,7 +71,7 @@ export function fromSequences(rows: SeqRow[], fps: number): Timeline {const media = rows.filter((r) => r.media)rows = rows.filter((r) => !r.media)const lanes = [...new Set(rows.map((r) => r.lane))].sort((a, b) => a - b)- const clipsOf = (lane: number): Clip[] => rows.filter((r) => r.lane === lane).sort((a, b) => a.from - b.from).map((r) => ({ id: seqId(r.i), kind: "sequence", name: r.label ?? r.name, start: r.from, length: Math.max(1, r.to - r.from), ...(r.locked && { locked: r.locked }), ...(r.speed && r.speed !== 1 && { speed: r.speed }), ...(r.curve?.length && r.shows && { curve: r.curve.map(([at, speed]) => ({ at, speed })), shows: r.shows }), ...(r.keys && Object.keys(r.keys).length && { keys: Object.fromEntries(Object.entries(r.keys).map(([p, ks]) => [p, ks.map(([at, value, ease]): Key => ({ at, value, ...(ease !== undefined && { ease }) }))])) }) }))+ const clipsOf = (lane: number): Clip[] => rows.filter((r) => r.lane === lane).sort((a, b) => a.from - b.from).map((r) => ({ id: seqId(r.i), kind: r.text === undefined ? "sequence" : "text", name: r.text ?? r.label ?? r.name, start: r.from, length: Math.max(1, r.to - r.from), ...(r.locked && { locked: r.locked }), ...(r.speed && r.speed !== 1 && { speed: r.speed }), ...(r.curve?.length && r.shows && { curve: r.curve.map(([at, speed]) => ({ at, speed })), shows: r.shows }), ...(r.keys && Object.keys(r.keys).length && { keys: Object.fromEntries(Object.entries(r.keys).map(([p, ks]) => [p, ks.map(([at, value, ease]): Key => ({ at, value, ...(ease !== undefined && { ease }) }))])) }) }))const first = lanes.length ? clipsOf(lanes[0]) : []const gapless = first.length > 0 && first.every((c, n) => c.start === (n ? end(first[n - 1]) : 0))const tracks: Track[] = lanes.map((lane, n) => ({ id: n === 0 && gapless ? "main" : `overlay-${lane}`, kind: n === 0 && gapless ? "main" : "overlay", clips: clipsOf(lane) }))@@ -149,11 +157,11 @@ export function seqEdits(t: Timeline, op: Op): SeqEdit[] | { why: string } {const ids = op.ids ?? t.tracks.flatMap((k) => k.clips.filter((c) => c.start < at && at < end(c) && !c.locked).map((c) => c.id))// a split makes a sequence after the one it cuts, so later ones are named firstconst r = each(ids, (x) => ({ op: "split", i: x.i, at }))- return Array.isArray(r) ? r.sort((a, b) => b.i - a.i) : r+ return Array.isArray(r) ? r.sort(later) : r}case "remove": {const r = each(op.ids, (x) => ({ op: "delete", i: x.i }))- return Array.isArray(r) ? r.sort((a, b) => b.i - a.i) : r+ return Array.isArray(r) ? r.sort(later) : r}case "transition":case "untransition": {@@ -174,6 +182,12 @@ export function seqEdits(t: Timeline, op: Op): SeqEdit[] | { why: string } {case "set": {// a speed or a speed curve is the footage's rate; anything else a sequence has is its own code'sconst only = Object.keys(op.set).filter((k) => op.set[k as keyof typeof op.set] !== undefined)+ // a text clip's name is its words+ if (only.length === 1 && only[0] === "name") {+ if (find(t, op.id)?.clip.kind !== "text") return { why: "a sequence's name is its own code's: only a text clip's words change here" }+ if (!op.set.name!.trim()) return { why: "a text clip says something: delete it to take its words off" }+ return each([op.id], (r) => ({ op: "words", i: r.i, text: op.set.name!.trim() }))+ }if (only.length === 1 && only[0] === "curve") {// the clip as the curve leaves it: the source it shows and how long that now takesconst after = apply(t, op)@@ -200,6 +214,11 @@ export function seqEdits(t: Timeline, op: Op): SeqEdit[] | { why: string } {const keys = find(after.timeline, op.id)?.clip.keys ?? {}return [{ op: "keys", i: r.i, keys: Object.fromEntries(Object.entries(keys).filter(([p]) => KEYED.includes(p)).map(([p, ks]) => [p, ks.map((k): [number, number, Ease?] => (k.ease === undefined || k.ease === "linear" ? [k.at, k.value as number] : [k.at, k.value as number, k.ease]))])) }]}+ case "add": {+ // words put on the picture: a new sequence of its own+ if (op.clip.kind !== "text") return { why: "only words are added to a composition here: footage and sound are its code's to place" }+ return [{ op: "text", at: Math.max(0, Math.round(op.clip.start)), frames: Math.max(1, Math.round(op.clip.length)), text: (op.clip.name ?? "Text").trim() || "Text" }]+ }default:return { why: `the composition's sequences don't take "${op.op}" yet` }}diff --git a/sdk/timeline/test/read.test.ts b/sdk/timeline/test/read.test.tsindex 00803d99..447af5a1 100644--- a/sdk/timeline/test/read.test.ts+++ b/sdk/timeline/test/read.test.ts@@ -51,6 +51,17 @@ describe("TL0c: a timeline is read from a composition", () => {expect(fromSequences([{ ...rows[0], speed: 2 }], 30).tracks[0].clips[0].speed).toBe(2)})+ test("a sequence of words is a text clip: renamed, its words change; words added are a new sequence (TL7c)", () => {+ const t = fromSequences([{ ...rows[0] }, { ...rows[2], text: "Hello there" }], 30)+ const words = t.tracks.flatMap((k) => k.clips).find((c) => c.id === "seq-1")!+ expect([words.kind, words.name]).toEqual(["text", "Hello there"])+ expect(seqEdits(t, { op: "set", id: "seq-1", set: { name: " Goodbye " } })).toEqual([{ op: "words", i: 1, text: "Goodbye" }])+ expect(seqEdits(t, { op: "set", id: "seq-1", set: { name: " " } })).toEqual({ why: "a text clip says something: delete it to take its words off" })+ expect(seqEdits(t, { op: "set", id: "seq-0", set: { name: "x" } })).toEqual({ why: "a sequence's name is its own code's: only a text clip's words change here" })+ expect(seqEdits(t, { op: "add", kind: "text", clip: { id: "new", kind: "text", name: "Sale ends Friday", start: 45, length: 90 } })).toEqual([{ op: "text", at: 45, frames: 90, text: "Sale ends Friday" }])+ expect(seqEdits(t, { op: "add", kind: "video", clip: { id: "new", kind: "video", start: 0, length: 30 } })).toEqual({ why: "only words are added to a composition here: footage and sound are its code's to place" })+ })+test("a <Video> and an <Audio> are clips of their own under their sequence: their level is theirs, the rest the sequence's", () => {const t = fromSequences([...rows, { i: 4, name: "Video", label: "take.mp4", from: 90, to: 180, lane: 0, media: "video", startFrom: 30 }, { i: 6, name: "Audio", label: "bed.wav", from: 0, to: 180, lane: 0, media: "audio", volume: 0.5 }], 30)expect(t.tracks.map((k) => [k.id, k.kind, k.clips.map((c) => c.name)])).toEqual([