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
notation: a short final bar throws with the rest to write; compose names the section/slot; demos write their final rests (audio bit-identical)
Alex Greenshpun37852433b5ac
diff --git a/skills/anidoodle/engine/src/canvas-core/music/compose.ts b/skills/anidoodle/engine/src/canvas-core/music/compose.tsindex aca83ca..7d0f296 100644--- a/skills/anidoodle/engine/src/canvas-core/music/compose.ts+++ b/skills/anidoodle/engine/src/canvas-core/music/compose.ts@@ -42,6 +42,8 @@ export type Material = {/** seconds of ring-out after the last onset (default 3.2) */ tail?: number; loop?: boolean;};+/** line() with the composer's context on its error: which section, slot or chord wrote the bad bar. */+const lineIn = (where: string, ...a: Parameters<typeof line>) => { try { return line(...a); } catch (e) { throw new Error(`compose: ${where}: ${(e as Error).message}`); } };const need = (ok: unknown, msg: string) => { if (!ok) throw new Error(`compose: ${msg} The style supplies sound, never notes: compose it yourself (references/music/compose.md).`); };const fmt = (x: number) => String(+x.toFixed(4));const lanes: Lane[] = ["kick", "snare", "ghost", "hat", "perc"];@@ -82,11 +84,11 @@ export const composePiece = (m: Material): Piece => {for (let b = 0; b < B; b++) {const x = at(b), cv = x.s.chordVel, names = chordAt[b], d = bpb / names.length;const src = names.map((n) => `${m.chords[n].voicing}:${fmt(d)}${cv !== undefined ? `@${fmt(cv)}` : ""}`).join(" ");- push("chords", line(b * bpb, src, { role: "accomp", v: vel.chords, bpb, roll: 0.03 }));+ push("chords", lineIn(`section "${x.id}" chords (bar ${b})`, b * bpb, src, { role: "accomp", v: vel.chords, bpb, roll: 0.03 }));if (KINDS[x.s.kind].bass) {const ov = x.s.bass, bl = ov !== undefined ? (Array.isArray(ov) ? ov[(b - x.from) % ov.length] : ov) : names.length === 1 ? m.chords[names[0]].bass : undefined;need(bl !== undefined, names.length > 1 ? `bar ${b} splits into ${names.join(" + ")}: give section "${x.id}" a bass override for it.` : `chord "${names[0]}" (section "${x.id}") has no bass line: add chords["${names[0]}"].bass (one bar), or a section bass override.`);- if (bl) push("bass", line(b * bpb, bl, { role: "bass", v: vel.bass, bpb }));+ if (bl) push("bass", lineIn(`section "${x.id}" bass (bar ${b}${names.length === 1 && ov === undefined ? `, chords["${names[0]}"].bass` : ""})`, b * bpb, bl, { role: "bass", v: vel.bass, bpb }));}// drumsconst def = KINDS[x.s.kind].drums, gname = x.s.groove === undefined ? def : x.s.groove;@@ -94,7 +96,7 @@ export const composePiece = (m: Material): Piece => {const g = m.grooves?.[gname];need(g, `section "${x.id}" (${x.s.kind}) needs a groove "${gname}": add grooves["${gname}"] = { family: one of ${vocab.grooves.join(", ")}, density, variation } or write it (kick/snare/ghost/hat bars), or set groove: null.`);const bar = drumBar(g!, meter, m.seed, b, b - x.from, x.s.bars, x.s.energy ?? 0.5);- for (const ln of lanes) if (bar[ln]) push(ln, line(b * bpb, bar[ln]!, { role: "drum", v: vel[ln], bpb }));+ for (const ln of lanes) if (bar[ln]) push(ln, lineIn(`section "${x.id}" ${ln} (bar ${b})`, b * bpb, bar[ln]!, { role: "drum", v: vel[ln], bpb }));}}const warnings: string[] = [];@@ -105,7 +107,7 @@ export const composePiece = (m: Material): Piece => {if (x.s.loopLines) { const reps = Math.ceil(x.s.bars / lb), all = Array.from({ length: reps }, () => src).join(" | ").split("|").map((z) => z.trim()).filter(Boolean); src = all.slice(0, x.s.bars).join(" | "); }else if (x.pass === 0) warnings.push(`section "${x.id}": the ${slot} is ${lb} bar(s) in a ${x.s.bars}-bar section; it plays once, then rests (set loopLines: true to repeat it)`);}- const ns = line(x.from * bpb, src, { role: role(slot), v: vel[slot], bpb });+ const ns = lineIn(`section "${x.id}" ${slot}`, x.from * bpb, src, { role: role(slot), v: vel[slot], bpb });need(ns.every((n) => n.t < x.to * bpb - 1e-9), `the ${slot} line of section "${x.id}" is longer than its ${x.s.bars} bars.`);push(slot, ns);}diff --git a/skills/anidoodle/engine/src/canvas-core/music/pieces/families.ts b/skills/anidoodle/engine/src/canvas-core/music/pieces/families.tsindex b3832b5..81487fc 100644--- a/skills/anidoodle/engine/src/canvas-core/music/pieces/families.ts+++ b/skills/anidoodle/engine/src/canvas-core/music/pieces/families.ts@@ -11,10 +11,10 @@ const rep = (cell: string, n: number) => Array.from({ length: n }, () => cell).jexport const marimbaCurious = (): Piece => {const B = 4;const ost = L(0, ["D4:.5 A4:.5 E5:.5 F5:.5 A4:.5 E5:.5 D5:.5 A4:.5", "D4:.5 B4:.5 E5:.5 G5:.5 B4:.5 E5:.5 D5:.5 B4:.5",- "D4:.5 A4:.5 E5:.5 F5:.5 A4:.5 E5:.5 D5:.5 A4:.5", "[D4 A4]:1"].join(" | "), "accomp", B, 0.55);+ "D4:.5 A4:.5 E5:.5 F5:.5 A4:.5 E5:.5 D5:.5 A4:.5", "[D4 A4]:1 r:3"].join(" | "), "accomp", B, 0.55);// the hook asks (up to D6, then B natural), answers stepwise down to the tonic- const hook = L(0, "r:1 A5:.5 C6:.5 D6:1 C6:.5 A5:.5 | B5:1.5 G5:.5 A5:1 r:1 | F5:.5 E5:.5 D5:.5 E5:.5 F5:1 E5:1 | D5:1", "melody", B, 0.8);- const low = L(0, "D3:2 A2:2 | G2:2 D3:2 | D3:2 A2:2 | D3:1", "bass", B, 0.7);+ const hook = L(0, "r:1 A5:.5 C6:.5 D6:1 C6:.5 A5:.5 | B5:1.5 G5:.5 A5:1 r:1 | F5:.5 E5:.5 D5:.5 E5:.5 F5:1 E5:1 | D5:1 r:3", "melody", B, 0.8);+ const low = L(0, "D3:2 A2:2 | G2:2 D3:2 | D3:2 A2:2 | D3:1 r:3", "bass", B, 0.7);return {title: "Marimba, curious (D dorian)", seed: 404, tail: 1.2, harmony: H([[0, "Dm"], [4, "G/D"], [8, "Dm"], [12, "Dm"]]),plan: { style: "minimalist", tempo: 108, meter: "4/4", ritard: 0.9, sections: [{ id: "a", bars: 4, mood: "curious", key: "D", mode: "dorian", melody: ["ostinato", "hook"], dyn: [0.65, 0.72], ending: "button", repeatable: true }] },@@ -22,7 +22,7 @@ export const marimbaCurious = (): Piece => {{ id: "ostinato", inst: "marimba", role: "accomp", notes: ost, gainDb: -3 },{ id: "hook", inst: "marimba", role: "melody", notes: hook, gainDb: 1 },{ id: "low", inst: "marimba", role: "bass", notes: low, gainDb: -1 },- { id: "halo", inst: "vibes", role: "color", notes: L(0, "[F4 A4 E5]:4 | [G4 B4 E5]:4 | [F4 A4 E5]:4 | [F4 A4 D5]:1", "color", B, 0.35), gainDb: -12, opts: { trem: 4.5 } },+ { id: "halo", inst: "vibes", role: "color", notes: L(0, "[F4 A4 E5]:4 | [G4 B4 E5]:4 | [F4 A4 E5]:4 | [F4 A4 D5]:1 r:3", "color", B, 0.35), gainDb: -12, opts: { trem: 4.5 } },],};};@@ -42,8 +42,8 @@ export const harpTender = (): Piece => {/** Guitar (Karplus-Strong), WISTFUL. E dorian fingerpicking, Em - A (the dorian IV) - Em, 4/4 at 84. */export const guitarWistful = (): Piece => {const B = 4;- const pick = L(0, "E2:.5 G3:.5 B3:.5 E4:.5 B2:.5 G3:.5 B3:.5 E4:.5 | A2:.5 E3:.5 C#4:.5 E4:.5 E2:.5 E3:.5 A3:.5 C#4:.5 | [E2 B2 E3 G3 B3 F#4]:1", "accomp", B, 0.55, { roll: 0.022 });- const mel = L(0, "B4:1.5 A4:.5 G4:1 F#4:1 | E4:1 C#5:1.5 B4:.5 A4:1 | B4:1", "melody", B, 0.8);+ const pick = L(0, "E2:.5 G3:.5 B3:.5 E4:.5 B2:.5 G3:.5 B3:.5 E4:.5 | A2:.5 E3:.5 C#4:.5 E4:.5 E2:.5 E3:.5 A3:.5 C#4:.5 | [E2 B2 E3 G3 B3 F#4]:1 r:3", "accomp", B, 0.55, { roll: 0.022 });+ const mel = L(0, "B4:1.5 A4:.5 G4:1 F#4:1 | E4:1 C#5:1.5 B4:.5 A4:1 | B4:1 r:3", "melody", B, 0.8);return {title: "Guitar, wistful (E dorian)", seed: 77, tail: 2.0, harmony: H([[0, "Em"], [4, "A"], [8, "Em9"]]),plan: { style: "folk", tempo: 84, meter: "4/4", ritard: 0.8, sections: [{ id: "a", bars: 3, mood: "wistful", key: "E", mode: "dorian", melody: ["stepwise"], dyn: [0.6, 0.55], ending: "tail", repeatable: true }] },@@ -66,8 +66,8 @@ export const celestaWonder = (): Piece => {/** FM bell over FM e-piano, HOPEFUL. C major IV-V-vi-V/3 -> I, the bell line climbing in sequence A5 B5 C6 D6 -> E6. 4/4 at 100. */export const bellsHopeful = (): Piece => {const B = 4;- const bell = L(0, "C5:.5 F5:.5 A5:1 D5:.5 G5:.5 B5:1 | E5:.5 A5:.5 C6:1 D5:.5 G5:.5 D6:1 | E6:2", "melody", B, 0.75);- const keys = L(0, "[F3 A3 C4 E4]:2 [G3 B3 D4]:2 | [A3 C4 E4]:2 [B2 D4 G4]:2 | [C3 G3 C4 E4]:2", "accomp", B, 0.6, { roll: 0.02 });+ const bell = L(0, "C5:.5 F5:.5 A5:1 D5:.5 G5:.5 B5:1 | E5:.5 A5:.5 C6:1 D5:.5 G5:.5 D6:1 | E6:2 r:2", "melody", B, 0.75);+ const keys = L(0, "[F3 A3 C4 E4]:2 [G3 B3 D4]:2 | [A3 C4 E4]:2 [B2 D4 G4]:2 | [C3 G3 C4 E4]:2 r:2", "accomp", B, 0.6, { roll: 0.02 });return {title: "Bells and e-piano, hopeful (C major)", seed: 31, tail: 2.6, harmony: H([[0, "Fmaj7"], [2, "G"], [4, "Am"], [6, "G/B"], [8, "C"]]),plan: { style: "cinematic", tempo: 100, meter: "4/4", ritard: 0.85, sections: [{ id: "a", bars: 3, mood: "hopeful", key: "C", mode: "major", melody: ["sequence"], dyn: [0.5, 0.8], ending: "tail", repeatable: true }] },@@ -78,11 +78,11 @@ export const bellsHopeful = (): Piece => {/** Drive / electronic, DRIVE. A minor i-VI-III-VII at 128: pluck arps and 8th bass from bar 1, the lead hook drops in at bar 3, a stab button. */export const driveElectronic = (): Piece => {const B = 4, a16 = (x: string) => rep(x.split(" ").map((n) => `${n}:.25`).join(" "), 4);- const pluckL = L(0, [a16("A4 C5 E5 A5"), a16("F4 A4 C5 F5"), a16("E4 G4 C5 E5"), a16("D4 G4 B4 D5"), "[A4 C5 E5]:.5"].join(" | "), "accomp", B, 0.6);- const bassL = L(0, [rep("A1:.5 A2:.5", 4), rep("F1:.5 F2:.5", 4), rep("C2:.5 C3:.5", 4), rep("G1:.5 G2:.5", 4), "A1:.5"].join(" | "), "bass", B, 0.85);- const lead = L(8, "E5:.75 D5:.25 C5:.5 E5:.5 G5:1.5 E5:.5 | D5:.75 C5:.25 B4:.5 D5:.5 G5:1 B4:1 | A5:.5", "melody", B, 0.8);+ const pluckL = L(0, [a16("A4 C5 E5 A5"), a16("F4 A4 C5 F5"), a16("E4 G4 C5 E5"), a16("D4 G4 B4 D5"), "[A4 C5 E5]:.5 r:3.5"].join(" | "), "accomp", B, 0.6);+ const bassL = L(0, [rep("A1:.5 A2:.5", 4), rep("F1:.5 F2:.5", 4), rep("C2:.5 C3:.5", 4), rep("G1:.5 G2:.5", 4), "A1:.5 r:3.5"].join(" | "), "bass", B, 0.85);+ const lead = L(8, "E5:.75 D5:.25 C5:.5 E5:.5 G5:1.5 E5:.5 | D5:.75 C5:.25 B4:.5 D5:.5 G5:1 B4:1 | A5:.5 r:3.5", "melody", B, 0.8);const pad = L(0, "[A3 C4 E4]:4 | [F3 A3 C4]:4 | [G3 C4 E4]:4 | [G3 B3 D4]:4", "color", B, 0.45);- const kick = L(0, [rep("C4:1", 4), rep("C4:1", 4), rep("C4:1", 4), rep("C4:1", 4), "C4:.5"].join(" | "), "drum", B, 0.9);+ const kick = L(0, [rep("C4:1", 4), rep("C4:1", 4), rep("C4:1", 4), rep("C4:1", 4), "C4:.5 r:3.5"].join(" | "), "drum", B, 0.9);const clap = L(0, "r:1 C4:1 r:1 C4:1 | r:1 C4:1 r:1 C4:1 | r:1 C4:1 r:1 C4:1 | r:1 C4:1 r:1 C4:.5 C4:.5", "drum", B, 0.7);const hats = L(0, [1, 2, 3, 4].map(() => rep("r:.5 C4:.5", 4)).join(" | "), "drum", B, 0.7, { kind: "o" });return {diff --git a/skills/anidoodle/engine/src/canvas-core/music/pieces/samplers.ts b/skills/anidoodle/engine/src/canvas-core/music/pieces/samplers.tsindex 75794c4..ae66ae8 100644--- a/skills/anidoodle/engine/src/canvas-core/music/pieces/samplers.ts+++ b/skills/anidoodle/engine/src/canvas-core/music/pieces/samplers.ts@@ -9,13 +9,13 @@ const H = (xs: [number, string][]) => xs.map(([t, name]) => ({ t, name }));export const musicBoxJoy = (): Piece => {const B = 4;// melody: the hook is a long-short-short skip (F#-A-B-A); bar 2 repeats its rhythm a fourth up, bar 3 answers on the dominant- const melody = L(0, "F#5:1 A5:2/3 B5:1/3 A5:1 F#5:1 | B5:1 D6:2/3 B5:1/3 G5:2 | A5:1 B5:2/3 A5:1/3 E5:1 C#6:1 | D6:1", "melody", B, 0.75);+ const melody = L(0, "F#5:1 A5:2/3 B5:1/3 A5:1 F#5:1 | B5:1 D6:2/3 B5:1/3 G5:2 | A5:1 B5:2/3 A5:1/3 E5:1 C#6:1 | D6:1 r:3", "melody", B, 0.75);// rolling 1-5-3-5 arpeggio on the triplets (4-note cell over 3-note groups: a gentle hemiola)const arpBar = (r: string, f: string, t: string) => Array.from({ length: 12 }, (_, i) => `${[r, f, t, f][i % 4]}:1/3`).join(" ");- const arp = L(0, [arpBar("D5", "A5", "F#5"), arpBar("D5", "G5", "B5"), arpBar("C#5", "A5", "E5"), "D5:1/3 A5:1/3 F#5:1/3"].join(" | "), "accomp", B, 0.5); // up an octave: brightness- const bassL = L(0, "D3:2 F#3:2 | G3:2 D3:2 | E3:2 C#3:2 | D3:1", "bass", B, 0.62); // the recipe's bass register, C3-G3- const sparkle = L(8, "A6:1 B6:2/3 A6:1/3 E6:1 C#7:1 | D7:1", "color", B, 0.3);- const bell = L(12, "D6:1", "color", B, 0.8);+ const arp = L(0, [arpBar("D5", "A5", "F#5"), arpBar("D5", "G5", "B5"), arpBar("C#5", "A5", "E5"), "D5:1/3 A5:1/3 F#5:1/3 r:3"].join(" | "), "accomp", B, 0.5); // up an octave: brightness+ const bassL = L(0, "D3:2 F#3:2 | G3:2 D3:2 | E3:2 C#3:2 | D3:1 r:3", "bass", B, 0.62); // the recipe's bass register, C3-G3+ const sparkle = L(8, "A6:1 B6:2/3 A6:1/3 E6:1 C#7:1 | D7:1 r:3", "color", B, 0.3);+ const bell = L(12, "D6:1 r:3", "color", B, 0.8);return {title: "Music box, joy", seed: 7, tail: 2,harmony: H([[0, "D"], [4, "G"], [8, "A"], [12, "D"]]),@@ -49,8 +49,8 @@ export const minorPianoMelancholy = (): Piece => {export const cinematicAwe = (): Piece => {const B = 4;// strings: Cadd9 -> D/C (the lydian #4, F#, in the top voice) -> E major held through the arrival- const hi = [...L(0, "[C4 G4 D5 E5]:4 | [D4 A4 F#5]:2", "accomp", B, 0.7), ...L(6, "[E4 B4 E5 G#5]:4", "accomp", B, 0.7)];- const low = [...L(0, "[C2 C3]:4 | [C2 C3]:2", "bass", B, 0.7), ...L(6, "[E2 E3]:4", "bass", B, 0.7)];+ const hi = [...L(0, "[C4 G4 D5 E5]:4 | [D4 A4 F#5]:2 r:2", "accomp", B, 0.7), ...L(6, "[E4 B4 E5 G#5]:4", "accomp", B, 0.7)];+ const low = [...L(0, "[C2 C3]:4 | [C2 C3]:2 r:2", "bass", B, 0.7), ...L(6, "[E2 E3]:4", "bass", B, 0.7)];// harp shimmer: rising eighths over the swell; the piano rolls the arrival chord wideconst shimmer = L(0, "C5:.5 G5:.5 D6:.5 E6:.5 G6:.5 E6:.5 D6:.5 G5:.5 | D5:.5 A5:.5 E6:.5 F#6:.5 B6:.5 G#6:.5 E6:.5 B5:.5", "color", B, 0.55);const arrival = L(6, "[E1 E2 B2 G#3 E4]:2", "bass", B, 0.85, { roll: 0.05 });@@ -72,13 +72,13 @@ export const cinematicAwe = (): Piece => {/** Chiptune, PLAYFUL. C major, 4/4 at 140. Call (bar 1, high) and response (bar 2, low); 16th arps fake the chords; 4 voices. */export const chiptunePlayful = (): Piece => {const B = 4;- const lead = L(0, "E5:.5 G5:.5 C6:.75 B5:.25 C6:.5 G5:.5 E5:1 | A4:.5 C5:.5 E5:.5 A5:.5 G5:1 E5:1 | F5:.5 A5:.5 C6:.75 B5:.25 A5:.5 F5:.5 D5:1 | G5:.5 B5:.5 D6:.5 B5:.5 G5:.5 A5:.25 B5:.25 r:1 | C6:1.5", "melody", B, 0.85);+ const lead = L(0, "E5:.5 G5:.5 C6:.75 B5:.25 C6:.5 G5:.5 E5:1 | A4:.5 C5:.5 E5:.5 A5:.5 G5:1 E5:1 | F5:.5 A5:.5 C6:.75 B5:.25 A5:.5 F5:.5 D5:1 | G5:.5 B5:.5 D6:.5 B5:.5 G5:.5 A5:.25 B5:.25 r:1 | C6:1.5 r:2.5", "melody", B, 0.85);const arp16 = (a: string, b: string, c: string, d: string) => Array.from({ length: 16 }, (_, i) => `${[a, b, c, d][i % 4]}:.25`).join(" ");- const arps = L(0, [arp16("C4", "E4", "G4", "C5"), arp16("A3", "C4", "E4", "A4"), arp16("F3", "A3", "C4", "F4"), arp16("G3", "B3", "D4", "G4"), "C4:.25 E4:.25 G4:.25 C5:.25"].join(" | "), "accomp", B, 0.55);+ const arps = L(0, [arp16("C4", "E4", "G4", "C5"), arp16("A3", "C4", "E4", "A4"), arp16("F3", "A3", "C4", "F4"), arp16("G3", "B3", "D4", "G4"), "C4:.25 E4:.25 G4:.25 C5:.25 r:3"].join(" | "), "accomp", B, 0.55);const oct = (a: string, b: string) => Array.from({ length: 8 }, (_, i) => `${i % 2 ? b : a}:.5`).join(" ");- const tri = L(0, [oct("C2", "C3"), oct("A1", "A2"), oct("F2", "F3"), oct("G2", "G3"), "C2:1.5"].join(" | "), "bass", B, 1);- const kick = L(0, "C4:1 r:1 C4:.5 C4:.5 r:1 | C4:1 r:1 C4:1 r:1 | C4:1 r:1 C4:.5 C4:.5 r:1 | C4:1 r:1 C4:1 r:1 | C4:1", "drum", B, 0.9, { kind: "k" });- const snare = L(0, "r:1 C4:1 r:1 C4:1 | r:1 C4:1 r:1 C4:1 | r:1 C4:1 r:1 C4:1 | r:1 C4:1 r:1 C4:.25 C4:.25 C4:.25 C4:.25 | C4:1.5", "drum", B, 0.75, { kind: "s" });+ const tri = L(0, [oct("C2", "C3"), oct("A1", "A2"), oct("F2", "F3"), oct("G2", "G3"), "C2:1.5 r:2.5"].join(" | "), "bass", B, 1);+ const kick = L(0, "C4:1 r:1 C4:.5 C4:.5 r:1 | C4:1 r:1 C4:1 r:1 | C4:1 r:1 C4:.5 C4:.5 r:1 | C4:1 r:1 C4:1 r:1 | C4:1 r:3", "drum", B, 0.9, { kind: "k" });+ const snare = L(0, "r:1 C4:1 r:1 C4:1 | r:1 C4:1 r:1 C4:1 | r:1 C4:1 r:1 C4:1 | r:1 C4:1 r:1 C4:.25 C4:.25 C4:.25 C4:.25 | C4:1.5 r:2.5", "drum", B, 0.75, { kind: "s" });const hats = L(0, [..."1234"].map(() => Array.from({ length: 8 }, () => "C4:.5").join(" ")).join(" | "), "drum", B, 0.6, { kind: "h" });return {title: "Chiptune, playful", seed: 1985, tail: 1.1,@@ -96,13 +96,13 @@ export const chiptunePlayful = (): Piece => {/** Lo-fi e-piano, NOSTALGIC. F major, 4/4 at 80, swing 58 %. Fmaj9 - Dm9 | Bbmaj7 - C9sus | Fmaj9. */export const lofiNostalgic = (): Piece => {const B = 4;- const chords = L(0, "[A3 C4 E4 G4]:1.5 [A3 C4 E4 G4]:.5 [F3 A3 C4 E4]:2 | [A3 D4 F4]:1.5 [A3 D4 F4]:.5 [Bb3 D4 E4 G4]:2 | [A3 C4 E4 G4]:3", "accomp", B, 0.62, { roll: 0.018 });- const melody = L(0, "r:.5 C5:.5 E5:1 D5:.5 C5:.5 A4:1 | r:.5 F5:.5 D5:1 E5:.5 D5:.5 C5:1 | A4:3", "melody", B, 0.72);- const bassL = L(0, "F2:1.5 F2:.5 D2:2 | Bb1:1.5 Bb1:.5 C2:2 | F2:3", "bass", B, 0.8);- const kick = L(0, "C4:1 r:1.5 C4:1 r:.5 | C4:1 r:1.5 C4:1 r:.5 | C4:1", "drum", B, 0.8);- const rim = L(0, "r:1 C4:1 r:1 C4:1 | r:1 C4:1 r:1 C4:1 | r:1", "drum", B, 0.6);- const hats = L(0, "C4:.5@1 C4:[email protected] C4:.5@1 C4:[email protected] C4:.5@1 C4:[email protected] C4:.5@1 C4:[email protected] | C4:.5@1 C4:[email protected] C4:.5@1 C4:[email protected] C4:.5@1 C4:[email protected] C4:.5@1 C4:[email protected] | C4:.5", "drum", B, 0.55);- const crackle = L(0, "C4:4 | C4:4 | C4:3", "color", B, 1);+ const chords = L(0, "[A3 C4 E4 G4]:1.5 [A3 C4 E4 G4]:.5 [F3 A3 C4 E4]:2 | [A3 D4 F4]:1.5 [A3 D4 F4]:.5 [Bb3 D4 E4 G4]:2 | [A3 C4 E4 G4]:3 r:1", "accomp", B, 0.62, { roll: 0.018 });+ const melody = L(0, "r:.5 C5:.5 E5:1 D5:.5 C5:.5 A4:1 | r:.5 F5:.5 D5:1 E5:.5 D5:.5 C5:1 | A4:3 r:1", "melody", B, 0.72);+ const bassL = L(0, "F2:1.5 F2:.5 D2:2 | Bb1:1.5 Bb1:.5 C2:2 | F2:3 r:1", "bass", B, 0.8);+ const kick = L(0, "C4:1 r:1.5 C4:1 r:.5 | C4:1 r:1.5 C4:1 r:.5 | C4:1 r:3", "drum", B, 0.8);+ const rim = L(0, "r:1 C4:1 r:1 C4:1 | r:1 C4:1 r:1 C4:1 | r:4", "drum", B, 0.6);+ const hats = L(0, "C4:.5@1 C4:[email protected] C4:.5@1 C4:[email protected] C4:.5@1 C4:[email protected] C4:.5@1 C4:[email protected] | C4:.5@1 C4:[email protected] C4:.5@1 C4:[email protected] C4:.5@1 C4:[email protected] C4:.5@1 C4:[email protected] | C4:.5 r:3.5", "drum", B, 0.55);+ const crackle = L(0, "C4:4 | C4:4 | C4:3 r:1", "color", B, 1);return {title: "Lo-fi, nostalgic", seed: 1978, tail: 2.2,harmony: H([[0, "Fmaj9"], [2, "Dm9"], [4, "Bbmaj7"], [6, "C9sus"], [8, "Fmaj9"]]),diff --git a/skills/anidoodle/engine/src/canvas-core/music/plan.ts b/skills/anidoodle/engine/src/canvas-core/music/plan.tsindex 6b911a0..22100e2 100644--- a/skills/anidoodle/engine/src/canvas-core/music/plan.ts+++ b/skills/anidoodle/engine/src/canvas-core/music/plan.ts@@ -37,7 +37,10 @@ export type Piece = { title: string; plan: MusicPlan; parts: Part[]; harmony: Ch// ---------------------------------------------------------------- notation// "Eb4:1 | C5:2 Bb4:.5 Ab4:.5 | [Ab2 Eb3]:1 r:2 | G5:1/[email protected] ..." ; a token is NOTE:DUR[@VEL] or-// [CHORD]:DUR[@VEL] or r:DUR. Every complete bar must sum to the meter: a wrong bar throws.+// [CHORD]:DUR[@VEL] or r:DUR. Every bar must sum to the meter, the last one too (a line that ends+// mid-bar writes its rest: "C2:3 r:1"): a wrong bar throws, so a gap is always written, never+// silent. The first bar may instead be a declared `pickup`, or, when the line starts off the+// barline, exactly the beats left to the next barline.const dur = (s: string) => { if (s.includes("/")) { const [a, b] = s.split("/").map(Number); return a / b; } return Number(s); };export const line = (start: number, src: string, o: { role: Role; v?: number; bpb: number; pickup?: number; roll?: number; kind?: string }): Note[] => {const out: Note[] = []; let t = start; const bars = src.split("|").map((b) => b.trim()).filter((b, i, a) => b.length || (i > 0 && i < a.length - 1));@@ -52,9 +55,9 @@ export const line = (start: number, src: string, o: { role: Role; v?: number; bp}t += d; sum += d;}- const first = bi === 0, last = bi === bars.length - 1;- const ok = Math.abs(sum - o.bpb) < 1e-6 || (first && o.pickup !== undefined && Math.abs(sum - o.pickup) < 1e-6) || (last && sum <= o.bpb + 1e-6);- if (!ok) throw new Error(`bar ${bi} sums to ${sum} beats, meter wants ${o.bpb}: "${bar}"`);+ const first = bi === 0, toBarline = o.bpb - (((start % o.bpb) + o.bpb) % o.bpb);+ const ok = Math.abs(sum - o.bpb) < 1e-6 || (first && o.pickup !== undefined && Math.abs(sum - o.pickup) < 1e-6) || (first && toBarline < o.bpb - 1e-6 && Math.abs(sum - toBarline) < 1e-6);+ if (!ok) throw new Error(`bar ${bi} sums to ${+sum.toFixed(4)} beats, meter wants ${o.bpb}: "${bar}"${sum < o.bpb && bi === bars.length - 1 ? ` (a line that ends mid-bar writes its rest: "${bar} r:${+(o.bpb - sum).toFixed(4)}")` : ""}`);});return out;};diff --git a/skills/anidoodle/engine/tools/music-unit.mjs b/skills/anidoodle/engine/tools/music-unit.mjsindex 516e47c..a60c314 100644--- a/skills/anidoodle/engine/tools/music-unit.mjs+++ b/skills/anidoodle/engine/tools/music-unit.mjs@@ -45,6 +45,15 @@ for (const [what, m] of [{ const sjs = (await build({ entryPoints: [join(import.meta.dirname, "../src/canvas-core/score.ts")], bundle: true, write: false, platform: "neutral", format: "esm", logLevel: "error" })).outputFiles[0].text;const S = await import("data:text/javascript;base64," + Buffer.from(sjs).toString("base64")); assert.throws(() => S.filmScore(S.scoreSkeleton(), 30, 300), /skeleton/); }pass("missing harmony, melody, voicing, groove, form, mood: each throws; the score scaffold is empty and refuses to play");+// A bar that doesn't add up throws, the last one too: a short final bar is a silent gap nobody wrote.+{ const o = { role: "bass", bpb: 4 };+ assert.throws(() => M.line(0, "C2:3", o), /sums to 3 beats.*"C2:3 r:1"/, "a one-bar C2:3 in 4/4 must throw");+ assert.throws(() => M.line(0, "C2:4 | C2:3", o), /bar 1 sums to 3/);+ assert.equal(M.line(0, "C2:3 r:1", o).length, 1);+ assert.equal(M.line(6, "C2:2", o).length, 1, "a line starting off the barline may fill to it");+ const base = M.launchLofi3Material(), k = Object.keys(base.chords)[0];+ assert.throws(() => M.composePiece({ ...base, chords: { ...base.chords, [k]: { ...base.chords[k], bass: "C2:3" } } }), /sums to 3 beats/, "a short bass bar must fail compose (and so check)"); }+pass("notation: a short final bar throws with the rest to write (C2:3 -> C2:3 r:1); compose refuses it");// 4. Groove families: every family parses in every meter, deterministic, and the seed varies the bars.{ const meters = ["2/4", "3/4", "4/4", "5/4", "6/8", "7/8", "9/8", "12/8"]; let n = 0;diff --git a/skills/anidoodle/references/music/compose.md b/skills/anidoodle/references/music/compose.mdindex 611007c..d1ab937 100644--- a/skills/anidoodle/references/music/compose.md+++ b/skills/anidoodle/references/music/compose.md@@ -186,7 +186,8 @@ form to the exact length. `score.ts` is an empty skeleton to copy.- A timpani in a drum lane (orchestral, choral, suspense, world) is tuned to the tonic of `key`,generated grooves included (`epic`).-**Notation** (bar-checked; a bar that doesn't add up throws):+**Notation** (bar-checked; a bar that doesn't add up throws, the last bar too: a line that ends+mid-bar writes its rest, `C2:3 r:1`, never a silent gap):- A token is `NOTE:DUR[@VEL]` (a pitch name with an octave, e.g. `F#4`), `[NOTE NOTE ...]:DUR` (achord) or `r:DUR` (a rest).- Bars are separated by `|`, or given as array items.