Skip to content

Art and animation, written as code. Illustrations, loops, interactive web art, launch-videos and scored films in dozens of styles, identical on every render.

launchTemplate: accept the Material compose.md writes (it crashed on 'tempo'); refuse our pieces by content too, so a retitled or transposed launch score cannot ship; unit test

Alex Greenshpuneace749e4762
diff --git a/skills/anidoodle/engine/src/canvas-core/launchTemplate.ts b/skills/anidoodle/engine/src/canvas-core/launchTemplate.ts
index 04f2bad..8a32921 100644
--- a/skills/anidoodle/engine/src/canvas-core/launchTemplate.ts
+++ b/skills/anidoodle/engine/src/canvas-core/launchTemplate.ts
@@ -31,6 +31,8 @@ import * as launchPieces from "./music/pieces/launch";
import * as nocturnePieces from "./music/pieces/nocturne";
import * as samplers from "./music/pieces/samplers";
import type { Piece } from "./music/plan";
+import { composePiece, type Material } from "./music/compose";
+import { novelty } from "./music/novelty";
export type LaunchAsk = {
prompt: string; // what the user types, in their words
@@ -56,17 +58,25 @@ export type LaunchSpec = {
// The score: a piece COMPOSED for this product's brief (references/music/compose.md), or null for
// a silent film. Required, so no film inherits a score by default. anidoodle's own pieces are
// refused: every user's film gets its own music, never ours.
- score: (() => Piece) | null;
+ // A Material (what compose.md writes) is composed here; a finished Piece is used as is.
+ score: (() => Piece | Material) | null;
audio?: Film["audio"]; // or your own finished mix; wins over score
};
const W = 1920, H = 1080;
// anidoodle's own pieces (the demos and our launch score) are examples of the composer, never a
-// user's soundtrack. Refused by identity and by title, so a thin wrapper does not slip through.
+// user's soundtrack. Refused by identity, by title and by content (the novelty gate), so a thin or
+// retitled wrapper does not slip through. `audio` is the caller's own finished mix and is not checked.
const OURS: (() => Piece)[] = [...Object.values(families), ...Object.values(launchPieces), ...Object.values(nocturnePieces), ...Object.values(samplers)].filter((v): v is () => Piece => typeof v === "function");
-const refuseOurs = (score: () => Piece) => {
+const asPiece = (score: () => Piece | Material) => (): Piece => { const x = score(); return "plan" in x ? x : composePiece(x); };
+const refuseOurs = (score: () => Piece | Material) => {
const ours = () => new Set(OURS.map((f) => { try { return f().title; } catch { return null; } }).filter(Boolean));
- if (OURS.includes(score) || ours().has(score().title)) throw new Error(`launchTemplate: "${score().title}" is one of anidoodle's own pieces; compose a score for this product's brief (references/music/compose.md) or pass score: null`);
+ if ((OURS as unknown[]).includes(score) || ours().has(score().title)) throw new Error(`launchTemplate: "${score().title}" is one of anidoodle's own pieces; compose a score for this product's brief (references/music/compose.md) or pass score: null`);
+ // by content too: a retitled copy, a transposition or a quoted line of ours fails the same novelty gate `music.mjs check` runs
+ const corpus: Record<string, () => Piece> = {};
+ OURS.forEach((f, i) => { try { const p = asPiece(f)(); corpus[`${p.title} #${i}`] = () => p; } catch { /* not a piece */ } });
+ const v = novelty(asPiece(score)(), corpus);
+ if (!v.pass) throw new Error(`launchTemplate: "${score().title}" is too close to anidoodle's own "${v.worst.name.replace(/ #\d+$/, "")}" (similarity ${v.worst.score}, ${v.worst.reusedFragments} reused 6-note fragments); compose a score for this product's brief (references/music/compose.md) or pass score: null`);
};
const TYPE_O = { lead: -4, stagger: 18 }; // the word starts as the bloom closes over the frame; lines run on without a gap
const TOP = 170, VIEW_BOTTOM = INPUT.y - 26, BUBBLE = 58, CARD = 460;
@@ -201,7 +211,7 @@ export const makeLaunchFilm = (spec: LaunchSpec): Film & { cut: ReturnType<typeo
meta: { title: `${spec.title} · launch`, W, H, fps, bpm: spec.bpm, durationFrames: cut.N, raster: "cpu", kind: "launch", holds },
assets: { images: {} },
shots: [{ id: "cut", start: 0, end: cut.N, draw }],
- audio: spec.audio ?? (spec.score ? musicBed(spec.score, cut.N, fps) : undefined),
+ audio: spec.audio ?? (spec.score ? musicBed(asPiece(spec.score), cut.N, fps) : undefined),
cut,
};
};
diff --git a/skills/anidoodle/engine/test/launchTemplate.test.ts b/skills/anidoodle/engine/test/launchTemplate.test.ts
new file mode 100644
index 0000000..446e5d6
--- /dev/null
+++ b/skills/anidoodle/engine/test/launchTemplate.test.ts
@@ -0,0 +1,29 @@
+// LAUNCH TEMPLATE TESTS. makeLaunchFilm takes a score composed for the product: a Material (what
+// compose.md writes) or a Piece. anidoodle's own pieces are refused by identity, by title and by
+// content, so a retitled or transposed copy of our launch score cannot ship as a user's film.
+import { makeLaunchFilm } from "../src/canvas-core/launchTemplate";
+import { chiptunePlayful, daylightCopy, launchLofi3, launchLofi3Material, type Material } from "../src/canvas-core/music";
+import type { Film } from "../src/canvas-core/film";
+
+export const name = "launchTemplate";
+export const run = (ok: (cond: boolean, label: string) => void) => {
+ const plate: Film = { meta: { title: "plate", W: 1080, H: 1080, fps: 30, bpm: 120, durationFrames: 60 }, assets: { images: {} }, shots: [{ id: "p", start: 0, end: 60, draw: () => {} }] };
+ const base = { title: "Tally", asks: [{ prompt: "draw it", plate, label: "l" }], tagline: "t", install: ["npm i tally"], bpm: 120, askBeats: 8, endBeats: 12 };
+ const refused = (score: unknown, re = /anidoodle's own/) => { try { makeLaunchFilm({ ...base, score } as never); return false; } catch (e) { return re.test(String((e as Error).message)); } };
+ const mine = (): Material => ({
+ style: "playful", title: "Tally, counted", seed: 5, mood: "curious", bpm: 120, key: "G", mode: "mixolydian",
+ chords: { G: { voicing: "[D4 G4 B4]", bass: "G2:1.5 D3:.5 G2:1 F2:1" }, F: { voicing: "[C4 F4 A4]", bass: "F2:1.5 C3:.5 F2:1 E2:1" } },
+ motifs: { a: "B4:.5 D5:.5 G5:1 r:.5 F5:.25 E5:.25 D5:1", b: "r:1 A4:.5 C5:.5 F5:1 E5:.5 C5:.5" },
+ grooves: { main: { family: "shuffle", density: 0.45, variation: 0.35 } },
+ sections: [{ kind: "groove", bars: 4, harmony: ["G", "F"], lead: ["a", "b", "a", "b"], groove: "main", stretch: true }, { kind: "outro", bars: 1, harmony: ["G"], lead: ["a"] }],
+ });
+ 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(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");
+ ok(refused(() => ({ ...launchLofi3(), title: "Mine" })), "refuses a retitled copy of our launch score");
+ ok(refused(() => ({ ...launchLofi3Material(), title: "Mine" })), "refuses retitled launch material");
+ ok(refused(daylightCopy), "refuses the transposed copy of our launch score (the Daylight fixture)");
+ ok(refused(undefined, /required/), "a missing score is an error, never a default");
+};
diff --git a/skills/anidoodle/references/workflows/launch-video-kit.md b/skills/anidoodle/references/workflows/launch-video-kit.md
index fab2a0b..7251aa9 100644
--- a/skills/anidoodle/references/workflows/launch-video-kit.md
+++ b/skills/anidoodle/references/workflows/launch-video-kit.md
@@ -56,7 +56,7 @@ product's world in the chosen hand, as a still plus its `*Draw` film. anidoodle'
(the lighthouse and fox in `launchExample.ts`) are placeholders, never a user's film. The score
is composed for the brief's style, mood and length (`references/music/compose.md`); `score` is
required (`null` means silent), `bpm` has no default, and the template refuses anidoodle's own
-pieces, by identity and by title.
+pieces, by identity, by title and by content (the same novelty gate `music.mjs check` runs).
| Spec field | Meaning |
|---|---|
@@ -66,7 +66,7 @@ pieces, by identity and by title.
| `tagline`, `install[]`, `footer` | the end card; install lines are shown exactly as given |
| `bpm` (required), `fps`, `askBeats`, `typeBeats`, `endBeats` | the beat grid (a beat is 60 x fps / bpm frames) and each part's length in beats |
| `claimBar` | land the end card on this bar's downbeat; throws if it cannot |
-| `score` (required) or `audio` | a piece composed for this product, as a bed; `null` for silence; or your own finished mix |
+| `score` (required) or `audio` | the score composed for this product (the `Material` function compose.md writes, or a `Piece`), as a bed; `null` for silence; or your own finished mix (not checked) |
The template refuses a feature list (more than 3 asks) and an end card too short to read.