Art and animation, written as code. Illustrations, loops, interactive web art, launch-videos and scored films in dozens of styles, identical on every render.
TypeScript agent-skillsanimationcanvasclaude-codeclaude-pluginclaude-skillscodex-plugincreative-codecreative-codingcreative-toolsdeterministicgenerative-arthand-drawnillustrationlaunch-videomotion-designmotion-graphicspluginprocedural-generationskill
Expose film scores to audio hosts
Alex Greenshpunde2b2a0dc375
diff --git a/skills/anidoodle/engine/src/canvas-core/film.ts b/skills/anidoodle/engine/src/canvas-core/film.tsindex f88fc42..10d8e94 100644--- a/skills/anidoodle/engine/src/canvas-core/film.ts+++ b/skills/anidoodle/engine/src/canvas-core/film.ts@@ -1,6 +1,10 @@// FILM RUNTIME. A film is data: meta, an asset manifest, and shots that tile [0, duration).// renderFrame(film, ctx, frame, env) is the whole contract between the art and any backend.import type { Ctx, Env } from "./core";+import type { Piece } from "./music/plan";++/** Hosts preload these scores' verified banks before calling the complete audio mix. */+export type FilmAudio = ((sampleRate: number) => [Float32Array, Float32Array]) & { scores?: Piece[] };export type Shot = { id: string; start: number; end: number; draw: (ctx: Ctx, local: number, env: Env) => void }; // frames, end exclusiveexport type Assets = { images: Record<string, string>; fonts?: Record<string, string> }; // name -> url (the page build inlines them)@@ -28,7 +32,7 @@ export type Film = { meta: {captions?: { from: number; to: number; text: string }[];// a legible frame for the poster image and the thumbnail (render --poster-frame, launch.mjs ship)poster?: number;-}; assets: Assets; shots: Shot[]; audio?: (sampleRate: number) => [Float32Array, Float32Array];+}; assets: Assets; shots: Shot[]; audio?: FilmAudio;// the same film composed for another frame shape (launch template films); hosts/page.ts calls it for <film>-<shape>reshape?: (shape: string) => Film };diff --git a/skills/anidoodle/engine/src/canvas-core/launch.ts b/skills/anidoodle/engine/src/canvas-core/launch.tsindex 16f6dfd..ef52b93 100644--- a/skills/anidoodle/engine/src/canvas-core/launch.ts+++ b/skills/anidoodle/engine/src/canvas-core/launch.ts@@ -428,7 +428,7 @@ export const launch: Film = {shot("run", withRail(sceneRun)), shot("brick", withRail(sceneBrick)), shot("ref", withRail(sceneRef)), shot("emb", withRail(sceneEmb)),shot("web", withRail(sceneWeb)), shot("film", withRail(sceneFilm)), shot("reveal", sceneReveal), shot("end", sceneEnd),],- audio: launchAudio,+ audio: Object.assign(launchAudio, { scores: [launchLofi()] }),};// THE MOTION TEST: the Generate press, the drop and the bloom, on their own.diff --git a/skills/anidoodle/engine/src/canvas-core/launch2.ts b/skills/anidoodle/engine/src/canvas-core/launch2.tsindex ede7a6e..9f20c6a 100644--- a/skills/anidoodle/engine/src/canvas-core/launch2.ts+++ b/skills/anidoodle/engine/src/canvas-core/launch2.ts@@ -324,7 +324,7 @@ export const launch2: Film = {shot("open", sceneOpen), shot("ask", sceneAsk), shot("code", sceneCode), shot("swim", sceneSwim), shot("wall", sceneWall), shot("brick", sceneBrick),shot("hand", sceneHand), shot("loop", sceneLoop), shot("web", sceneWeb), shot("film", sceneFilm), shot("words", sceneWords), shot("end", sceneEnd),],- audio: audio2,+ audio: Object.assign(audio2, { scores: [launchLofi2()] }),};export const KEYS2 = () => ({ SW, HD, KOI_DONE, SWIM_OUT, PUNCHES, LAYOUT: LAYOUT.map((l) => [l.it.kind, l.y, l.h]) });diff --git a/skills/anidoodle/engine/src/canvas-core/launch3.ts b/skills/anidoodle/engine/src/canvas-core/launch3.tsindex f6ad421..4a21756 100644--- a/skills/anidoodle/engine/src/canvas-core/launch3.ts+++ b/skills/anidoodle/engine/src/canvas-core/launch3.ts@@ -103,6 +103,6 @@ export const launch3: Film = {meta: { title: "anidoodle · launch, cut 3", W, H, fps: FPS, bpm: 90, durationFrames: N3, raster: "cpu", kind: "launch", holds: [...HOLDS3, ...ACCEPTED3] },assets: { images: { almond: "assets/refs/vangogh-almond-blossom.jpg" } }, // public domain; provenance in engine/assets/refs/PROVENANCE.jsonshots: [{ id: "cut", start: 0, end: N3, draw: (ctx, F, env) => { const { s, local } = at(F); if (s.kind === "pic") content2(ctx, env, contentOf(s, local)); else drawType(ctx, env, s, local, F); } }],- audio: audio3,+ audio: Object.assign(audio3, { scores: [launchLofi3()] }),};export const SEGS3 = () => SEGS.map((s, i) => [s.kind, STARTS[i], s.len, s.kind === "type" ? s.lines.map((l) => l.text).join(" / ") : `${s.from}-${s.to}`]);diff --git a/skills/anidoodle/engine/src/canvas-core/launchSound.ts b/skills/anidoodle/engine/src/canvas-core/launchSound.tsindex cb2f360..874886f 100644--- a/skills/anidoodle/engine/src/canvas-core/launchSound.ts+++ b/skills/anidoodle/engine/src/canvas-core/launchSound.ts@@ -11,6 +11,7 @@import { placeSfx, sfxDuck, sfxAudibility, type SfxCue, type SfxPlan, type SfxAudibility, type PlacedCue } from "./music/sfx";import { limiter } from "./music/render";import { loudness, truePeak } from "./music/meter";+import type { FilmAudio } from "./film";/** A cue as the template emits it: a kit cue, plus where on screen it happens (px) and what made it. */export type LaunchCue = SfxCue & { x?: number; role: "key" | "press" | "drop" | "bloom" | "land" | "arrive" | "riser" | "impact" };@@ -51,8 +52,8 @@ export const mixLaunch = (music: [Float32Array, Float32Array] | null, plan: Launreturn { L, R, placed, audibility: aud, raised: [...raised].map(([i, db]) => ({ i, role: cues[i].role, db })), lufs: lu, dbtp: truePeak([L, R]).dbtp, ok: aud.every((a) => a.ok) };};/** What a Film's audio(sampleRate) returns; throws when a cue is still buried after raising it. */-export const launchAudio = (music: ((sr: number) => [Float32Array, Float32Array]) | null, plan: LaunchPlan) => (sr: number): [Float32Array, Float32Array] => {+export const launchAudio = (music: FilmAudio | null, plan: LaunchPlan) => Object.assign((sr: number): [Float32Array, Float32Array] => {const m = mixLaunch(music ? music(sr) : null, plan, sr);if (!m.ok) throw new Error(`launch sound: ${m.audibility.filter((a) => !a.ok).map((a) => `cue #${a.i} ${a.kind} @ ${a.atS.toFixed(2)} s is ${a.marginDb.toFixed(1)} dB under the score even raised +8 dB`).join("; ")}: thin the score there or move the cue`);return [m.L, m.R];-};+}, { scores: music?.scores ?? [] });diff --git a/skills/anidoodle/engine/src/canvas-core/launchTemplate.ts b/skills/anidoodle/engine/src/canvas-core/launchTemplate.tsindex 5394115..93c744f 100644--- a/skills/anidoodle/engine/src/canvas-core/launchTemplate.ts+++ b/skills/anidoodle/engine/src/canvas-core/launchTemplate.ts@@ -619,7 +619,9 @@ export const gridScore = (score: () => Piece | Material, bpm: number, fps: numbe// peak ceiling first (render prints how far short); `limit: true` lets a look-ahead limiter take// those few peaks instead so the bed reaches the target. Compose the piece for this film at the// film's bpm, so the cuts sit on its downbeats. `piece` may return a Piece or a fitScore result.-export const musicBed = (piece: () => Piece | Fit, frames: number, fps = 30, lufs = -14, o: { limit?: boolean; tempo?: number } = {}) => (sr: number): [Float32Array, Float32Array] => {+export const musicBed = (piece: () => Piece | Fit, frames: number, fps = 30, lufs = -14, o: { limit?: boolean; tempo?: number } = {}) => {+ const source = piece(), score = "order" in source ? source.piece : o.tempo ? source : fitScore(source, frames / fps).piece;+ return Object.assign((sr: number): [Float32Array, Float32Array] => {const seconds = frames / fps, x = piece(), fit = "order" in x ? x : o.tempo ? { piece: x, tempo: o.tempo } : fitScore(x, seconds);const m = renderPiece(fit.piece, sr, { seconds, tempo: fit.tempo }), n = Math.round(seconds * sr);const L = new Float32Array(n), R = new Float32Array(n); L.set(m.L.subarray(0, n)); R.set(m.R.subarray(0, n));@@ -630,5 +632,5 @@ export const musicBed = (piece: () => Piece | Fit, frames: number, fps = 30, lufconst again = lufs - loudness([L, R], sr).integrated; if (again > 0) { gain(Math.min(again, 1)); limiter(L, R, sr, Math.pow(10, -1.3 / 20)); }const tp = truePeak([L, R]).dbtp; if (tp > -1) gain(-1.05 - tp); // an inter-sample overshoot: a last static trimreturn [L, R];+ }, { scores: [score] });};-diff --git a/skills/anidoodle/engine/src/canvas-core/music/render.ts b/skills/anidoodle/engine/src/canvas-core/music/render.tsindex 5a8685f..7df5a87 100644--- a/skills/anidoodle/engine/src/canvas-core/music/render.ts+++ b/skills/anidoodle/engine/src/canvas-core/music/render.ts@@ -408,7 +408,7 @@ export const fitToDuration = (piece: Piece, seconds: number): { piece: Piece; te};/** What a Film's `audio(sampleRate)` returns: [L, R] at exactly the film's length. */-export const filmAudio = (piece: Piece, seconds: number) => (sr: number): [Float32Array, Float32Array] => {+export const filmAudio = (piece: Piece, seconds: number) => Object.assign((sr: number): [Float32Array, Float32Array] => {const fit = fitScore(piece, seconds), r = renderPiece(fit.piece, sr, { seconds, tempo: fit.tempo });return [r.L, r.R];-};+}, { scores: [fitScore(piece, seconds).piece] });diff --git a/skills/anidoodle/engine/test/launchTemplate.test.ts b/skills/anidoodle/engine/test/launchTemplate.test.tsindex 66078b8..497cf7d 100644--- a/skills/anidoodle/engine/test/launchTemplate.test.ts+++ b/skills/anidoodle/engine/test/launchTemplate.test.ts@@ -20,6 +20,7 @@ export const run = (ok: (cond: boolean, label: string) => void) => {});let film: Film | null = null; try { film = makeLaunchFilm({ ...base, score: mine }); } catch (e) { ok(false, `a composed Material is accepted: ${(e as Error).message}`); }ok(!!film && typeof film.audio === "function", "a composed Material is accepted as the score");+ ok(film?.audio?.scores?.length === 1, "film audio exposes its fitted score so hosts load only its recorded instruments");ok(refused(launchLofi3), "refuses our launch score by identity");ok(refused(launchLofi3Material), "refuses our launch score's material by identity");ok(refused(chiptunePlayful), "refuses a demo");