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: in progress: a plugin adds kinds of track (sdk/timeline registry.ts): its head's title and whether it stacks over the picture or under it with the sound; raea's five are listed the same way and can't be taken; 60 tests

shinyobjectzf732061d9d30
diff --git a/sdk/timeline/src/model.ts b/sdk/timeline/src/model.ts
index d6f0a76f..85d6dd49 100644
--- a/sdk/timeline/src/model.ts
+++ b/sdk/timeline/src/model.ts
@@ -127,11 +127,14 @@ export function timecode(frames: Frames, fps: number): string {
return `${two(Math.floor(f / whole / 60))}:${two(Math.floor(f / whole) % 60)}:${two(f % whole)}`
}
+/** Kinds a plugin said stack under the picture, with the sound (registry.ts sets them). */
+export const under = new Set<string>()
+
/** Where a track of this kind goes among the others (TL1a): after the last of its own kind, else in ORDER's place. */
export function slot(tracks: Track[], kind: TrackKind): number {
const rank = (k: TrackKind) => (ORDER.includes(k) ? ORDER.indexOf(k) : ORDER.indexOf("overlay"))
// sound tracks grow downward (a new one goes under the others); every other kind grows upward
- if (kind === "sound") return tracks.length
+ if (kind === "sound" || under.has(kind)) return tracks.length
const first = tracks.findIndex((t) => rank(t.kind) >= rank(kind))
return first < 0 ? tracks.length : first
}
diff --git a/sdk/timeline/src/registry.ts b/sdk/timeline/src/registry.ts
index 728e526c..6cca0bf9 100644
--- a/sdk/timeline/src/registry.ts
+++ b/sdk/timeline/src/registry.ts
@@ -2,7 +2,7 @@
// curves and transitions, as data. raea's own come first and can't be replaced; a plugin's are checked before they
// are offered, and one that isn't well formed is left out with why.
import { EASES } from "./keys"
-import type { Ease, SpeedPoint } from "./model"
+import { type Ease, type SpeedPoint, under } from "./model"
import { CURVES, FASTEST, SLOWEST } from "./speed"
export interface TransitionKind {
@@ -11,13 +11,32 @@ export interface TransitionKind {
title: string
}
+/** A kind of track: what its head says, and where it stacks (with the tracks over the picture, or with the sound
+ * under it). A clip on it is of that kind. */
+export interface TrackKindInfo {
+ kind: string
+ title: string
+ under?: boolean
+}
+
/** What one plugin adds. */
export interface Adds {
eases?: Record<string, Ease>
curves?: Record<string, SpeedPoint[]>
transitions?: TransitionKind[]
+ /** kinds of track of its own (TL11a): a clip posted or added on one is drawn and edited like any other */
+ tracks?: TrackKindInfo[]
}
+/** raea's own kinds of track, in the order they stack (TL1a). */
+export const TRACKS: TrackKindInfo[] = [
+ { kind: "effect", title: "Effects" },
+ { kind: "text", title: "Text" },
+ { kind: "overlay", title: "Overlay" },
+ { kind: "main", title: "Main" },
+ { kind: "sound", title: "Sound", under: true },
+]
+
/** raea's own transitions (TL7a): the kinds its <Transition> draws (sdk/video transition.tsx). Two parts that only
* touch have no frames of each other to mix, so there is no dissolve: a fade goes through black. */
export const TRANSITIONS: TransitionKind[] = [
@@ -59,16 +78,31 @@ export function readAdds(raw: unknown): { adds: Adds; errors: string[] } {
else (adds.transitions ??= []).push({ kind: t.kind, title: t.title })
}
}
+ if (r.tracks !== undefined) {
+ if (!Array.isArray(r.tracks)) errors.push("timeline.tracks is a list of { kind, title }")
+ else
+ for (const [i, x] of r.tracks.entries()) {
+ const t = x as Partial<TrackKindInfo> | null
+ if (!t || typeof t.kind !== "string" || !/^[a-z][a-z0-9-]*$/.test(t.kind) || typeof t.title !== "string" || !t.title.trim()) errors.push(`timeline.tracks[${i}] is { kind, title }: kind in lowercase letters, digits and dashes, title what the person sees`)
+ else if (TRACKS.some((o) => o.kind === t.kind)) errors.push(`timeline.tracks[${i}]: raea has a track of kind "${t.kind}"`)
+ else (adds.tracks ??= []).push({ kind: t.kind, title: t.title, ...(t.under === true && { under: true }) })
+ }
+ }
return { adds, errors }
}
/** 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[] } {
- const eases = { ...EASES }, curves = { ...CURVES }, transitions = [...TRANSITIONS]
+export function palette(plugins: Adds[] = []): { eases: Record<string, Ease>; curves: Record<string, SpeedPoint[]>; transitions: TransitionKind[]; tracks: TrackKindInfo[] } {
+ const eases = { ...EASES }, curves = { ...CURVES }, transitions = [...TRANSITIONS], tracks = [...TRACKS]
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 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 }
+ return { eases, curves, transitions, tracks }
}
diff --git a/sdk/timeline/test/registry.test.ts b/sdk/timeline/test/registry.test.ts
index 1622b3d7..23ba37c1 100644
--- a/sdk/timeline/test/registry.test.ts
+++ b/sdk/timeline/test/registry.test.ts
@@ -6,11 +6,12 @@ describe("TL11a: a plugin adds easings, speed curves and transitions", () => {
eases: { snap: [0.9, 0, 0.1, 1], back: [0.3, 1.6, 0.6, 1], linear: "hold", bad: [2, 0, 0, 1] },
curves: { pulse: [{ at: 0, speed: 1 }, { at: 0.5, speed: 4 }, { at: 1, speed: 1 }], hero: [{ at: 0, speed: 1 }, { at: 1, speed: 1 }], wild: [{ at: 0, speed: 50 }, { at: 1, speed: 1 }] },
transitions: [{ kind: "Glitch", title: "Glitch" }, { kind: "fade", title: "Mine" }, { kind: "", title: "x" }],
+ tracks: [{ kind: "lighting", title: "Lighting cues" }, { kind: "sound", title: "Mine" }, { kind: "Bad Kind", title: "x" }, { kind: "cues", title: "Cues", under: true }],
}
test("what is well formed is offered after raea's own; the rest is left out with why", () => {
const { adds, errors } = readAdds(raw)
- expect(adds).toEqual({ eases: { snap: [0.9, 0, 0.1, 1], back: [0.3, 1.6, 0.6, 1] }, curves: { pulse: raw.curves.pulse }, transitions: [{ kind: "Glitch", title: "Glitch" }] })
+ expect(adds).toEqual({ eases: { snap: [0.9, 0, 0.1, 1], back: [0.3, 1.6, 0.6, 1] }, curves: { pulse: raw.curves.pulse }, transitions: [{ kind: "Glitch", title: "Glitch" }], tracks: [{ kind: "lighting", title: "Lighting cues" }, { kind: "cues", title: "Cues", under: true }] })
expect(errors).toEqual([
"timeline.eases.linear: raea has an easing of that name",
'timeline.eases.bad is "linear", "hold" or a bezier\'s handles [x1, y1, x2, y2] with x1 and x2 from 0 to 1',
@@ -18,7 +19,10 @@ describe("TL11a: a plugin adds easings, speed curves and transitions", () => {
"timeline.curves.wild is two or more points { at, speed }, at from 0 to 1 and speed from 0.1 to 10",
'timeline.transitions[1]: raea has a transition "fade"',
"timeline.transitions[2] is { kind, title }: kind a name, title what the person sees",
+ 'timeline.tracks[1]: raea has a track of kind "sound"',
+ "timeline.tracks[2] is { kind, title }: kind in lowercase letters, digits and dashes, title what the person sees",
])
+ expect(palette([adds]).tracks.map((t) => t.kind)).toEqual(["effect", "text", "overlay", "main", "sound", "lighting", "cues"])
const all = palette([adds, { eases: { snap: "hold" } }])
expect(Object.keys(all.eases)).toEqual([...Object.keys(EASES), "snap", "back"])
expect(all.eases.snap).toEqual([0.9, 0, 0.1, 1])