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
TL0c, TL8a: in progress: a composition's <Video> and <Audio> are clips of their own (sdk/timeline read.ts)
shinyobjectz2b7574de39e7
diff --git a/sdk/timeline/src/read.ts b/sdk/timeline/src/read.tsindex 67db6991..e327f5ed 100644--- a/sdk/timeline/src/read.ts+++ b/sdk/timeline/src/read.ts@@ -22,6 +22,11 @@ export interface SeqRow {/** how it comes in and goes out: its <Transition>'s in and out (TL7a) */in?: { kind: string; frames: number }out?: { kind: string; frames: number }+ /** a <Video> or an <Audio> of its own (TL0c): it plays where the sequence it is in does, from `startFrom` of its+ * file, at its own level */+ media?: "video" | "audio"+ startFrom?: number+ volume?: number}/** The host's edit to a sequence: its new span, a split, a delete. */export type SeqEdit =@@ -34,6 +39,8 @@ export type SeqEdit =| { op: "speed"; i: number; speed: number }/** 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) */+ | { op: "level"; i: number; volume: number }/** The transitions a composition's <Transition> draws (sdk/video transition.tsx). */export const CODE_KINDS = ["fade", "slide", "wipe", "zoom"]@@ -47,6 +54,8 @@ const seqOf = (id: string): number | undefined => (/^seq-\d+$/.test(id) ? Number* lane is the main track, its magnet on, only when its clips already run from frame 0 with no gap: a composition's* sequences are where its code puts them, and nothing here moves one that wasn't dragged. */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.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]) : []@@ -62,8 +71,19 @@ export function fromSequences(rows: SeqRow[], fps: number): Timeline {return out && into && out.kind === into.kind ? [{ id: `x-${c.id}`, kind: out.kind, after: c.id, length: out.frames + into.frames }] : []}),)+ // footage and sound of their own: a track each kind, more where they play at once; a sound's below the picture+ const mediaTracks = (kind: "video" | "audio"): Track[] => {+ const out: Track[] = []+ for (const r of media.filter((m) => m.media === kind).sort((a, b) => a.from - b.from)) {+ const c: Clip = { id: seqId(r.i), kind, name: r.label ?? r.name, start: r.from, length: Math.max(1, r.to - r.from), in: r.startFrom ?? 0, ...(r.speed && r.speed !== 1 && { speed: r.speed }), ...(r.volume !== undefined && { volume: r.volume }), ...(r.locked && { locked: r.locked }) }+ const home = out.find((k) => k.clips.every((o) => end(o) <= c.start || o.start >= end(c)))+ if (home) home.clips.push(c)+ else out.push({ id: `${kind === "audio" ? "sound" : "footage"}-${out.length + 1}`, kind: kind === "audio" ? "sound" : "overlay", name: kind === "audio" ? "Sound" : "Footage", clips: [c] })+ }+ return out+ }// lanes below the first are nested deeper: drawn under it, as the strip has them- return { ...empty(fps), tracks, transitions, magnet: gapless }+ return { ...empty(fps), tracks: [...tracks, ...mediaTracks("video"), ...mediaTracks("audio")], transitions, magnet: gapless }}/** A film with no composition behind it: its scenes as clips of one main track (cut where the picture cuts). Each@@ -89,6 +109,13 @@ export function seqEdits(t: Timeline, op: Op): SeqEdit[] | { why: string } {const i = seqOf(id), at = find(t, id)return i !== undefined && at ? { i, clip: at.clip } : undefined}+ // a <Video> or an <Audio> plays where its sequence does: its level is its own, everything else its sequence's+ const isMedia = (id: string) => ["video", "audio"].includes(find(t, id)?.clip.kind ?? "") && /^(footage|sound)-/.test(find(t, id)?.track.id ?? "")+ const ids = "ids" in op && op.ids ? op.ids : "id" in op && typeof op.id === "string" ? [op.id] : []+ if (ids.some(isMedia)) {+ if (op.op === "set" && Object.keys(op.set).filter((k) => op.set[k as keyof typeof op.set] !== undefined).join() === "volume") return ids.flatMap((id) => { const i = seqOf(id); return i === undefined ? [] : [{ op: "level", i, volume: Math.round(Math.max(0, op.set.volume!) * 1000) / 1000 } as SeqEdit] })+ return { why: "footage and sound play where their sequence does: move, trim or speed the sequence; here only the level is its own" }+ }const each = (ids: string[], f: (r: { i: number; clip: Clip }) => SeqEdit): SeqEdit[] | { why: string } => {const rows = ids.map(row)return rows.every((r) => r) ? rows.map((r) => f(r!)) : { why: "that isn't one of the composition's sequences" }diff --git a/sdk/timeline/test/read.test.ts b/sdk/timeline/test/read.test.tsindex 37214aab..b9d9d6d8 100644--- a/sdk/timeline/test/read.test.ts+++ b/sdk/timeline/test/read.test.ts@@ -43,6 +43,22 @@ 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 <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([+ ["main", "main", ["First scene", "Second scene"]],+ ["overlay-1", "overlay", ["Title", "Outro"]],+ ["footage-1", "overlay", ["take.mp4"]],+ ["sound-1", "sound", ["bed.wav"]],+ ])+ expect(t.tracks[2].clips[0]).toMatchObject({ kind: "video", in: 30, start: 90, length: 90 })+ expect(t.tracks[3].clips[0]).toMatchObject({ kind: "audio", volume: 0.5 })+ expect(seqEdits(t, { op: "set", id: "seq-6", set: { volume: 0.8 } })).toEqual([{ op: "level", i: 6, volume: 0.8 }])+ expect(seqEdits(t, { op: "move", ids: ["seq-6"], by: 10 })).toEqual({ why: "footage and sound play where their sequence does: move, trim or speed the sequence; here only the level is its own" })+ // the sequences themselves are as before+ expect(seqEdits(t, { op: "move", ids: ["seq-1"], by: 10 })).toEqual([{ op: "move", i: 1, from: 25, to: 70 }])+ })+test("a transition on a cut is the part before going out and the part after coming in, and is read back from them", () => {const t = fromSequences(rows, 30)expect(seqEdits(t, { op: "transition", transition: { id: "x-seq-0", kind: "slide", after: "seq-0", length: 15 } })).toEqual([