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
novelty: a quoted melody fails in any key, meter or rhythm (8-note interval-shape gate); every feature documented
Alex Greenshpun682f60a59155
diff --git a/skills/anidoodle/engine/src/canvas-core/music/novelty.ts b/skills/anidoodle/engine/src/canvas-core/music/novelty.tsindex 611d8b9..9861a5e 100644--- a/skills/anidoodle/engine/src/canvas-core/music/novelty.ts+++ b/skills/anidoodle/engine/src/canvas-core/music/novelty.ts@@ -6,8 +6,9 @@// melody intervals (transposition-free n-grams), other lines' rhythm (counter, bass), drum bars,// chord function (root vs key + quality) n-grams, chord-quality n-grams, section-kind sequence.// Each feature is a bag of n-grams; similarity is the cosine of the bags; the score is a weighted-// mean. `demoReuse` is the stricter gate: any 6-note melody fragment (intervals + durations) taken-// from a demo fails outright, transposed or not.+// mean. Two stricter gates fail outright: any 6-note melody fragment (intervals + durations) taken+// from a shipped piece, transposed or not; and any distinctive 8-note melody shape (intervals only),+// so a quote re-barred into another meter, stretched or re-rhythmed is caught too.import type { Piece, Note } from "./plan";import { beatsPerBar } from "./plan";import { pcOf } from "./theory";@@ -56,17 +57,30 @@ export const similarity = (a: Fingerprint, b: Fingerprint) => {return { score: w ? s / w : 0, by };};+const tune = (p: Piece) => voice(p.parts.flatMap((pt) => pt.notes.filter((n) => n.role === "melody" || n.role === "color")));/** Every melody 6-note fragment as (interval, duration) pairs: transposition-free. */-const fragments = (p: Piece) => { const mel = voice(p.parts.flatMap((pt) => pt.notes.filter((n) => n.role === "melody" || n.role === "color"))); const out = new Set<string>(); for (let i = 0; i + 6 <= mel.length; i++) { const g = mel.slice(i, i + 6); out.add(g.slice(1).map((n, j) => `${n.p - g[j].p}/${q(n.t - g[j].t)}`).join(" ")); } return out; };+const fragments = (p: Piece) => { const mel = tune(p), out = new Set<string>(); for (let i = 0; i + 6 <= mel.length; i++) { const g = mel.slice(i, i + 6); out.add(g.slice(1).map((n, j) => `${n.p - g[j].p}/${q(n.t - g[j].t)}`).join(" ")); } return out; };+/** A quoted tune survives a new key, a new meter and a new rhythm: its intervals do not. The pitch-only fragment gate compares this many notes. */+export const QUOTE_NOTES = 8;+/**+ * Every QUOTE_NOTES-note melody fragment as its interval sequence alone (no rhythm, no key, no meter):+ * the same tune re-barred into 5/4, stretched or transposed has the same intervals. Only distinctive+ * shapes count (3+ different intervals, a leap of 3+ semitones, at most 3 repeated notes), so a scale+ * run or a repeated-note figure, which every tune shares, never fails a piece.+ */+export const melodyShapes = (p: Piece) => { const mel = tune(p), out = new Set<string>();+ for (let i = 0; i + QUOTE_NOTES <= mel.length; i++) { const iv = mel.slice(i + 1, i + QUOTE_NOTES).map((n, j) => n.p - mel[i + j].p);+ if (new Set(iv).size >= 3 && iv.some((x) => Math.abs(x) >= 3) && iv.filter((x) => x === 0).length <= 3) out.add(iv.join(",")); }+ return out; };/** Score a piece against a corpus. `family` names the pieces that ARE this piece (its own cuts) and are skipped. */export const novelty = (p: Piece, corpus: Record<string, () => Piece>, skip: string[] = [], threshold = NOVELTY_THRESHOLD) => {- const fp = fingerprint(p), mine = fragments(p);+ const fp = fingerprint(p), mine = fragments(p), shapes = melodyShapes(p);const rows = Object.entries(corpus).filter(([name]) => !skip.includes(name)).map(([name, mk]) => {- const other = mk(), sim = similarity(fp, fingerprint(other)), theirs = fragments(other);- let reused = 0; for (const f of mine) if (theirs.has(f)) reused++;- return { name, score: +sim.score.toFixed(3), by: sim.by, reusedFragments: reused };+ const other = mk(), sim = similarity(fp, fingerprint(other)), theirs = fragments(other), theirShapes = melodyShapes(other);+ let reused = 0, quoted = 0; for (const f of mine) if (theirs.has(f)) reused++; for (const f of shapes) if (theirShapes.has(f)) quoted++;+ return { name, score: +sim.score.toFixed(3), by: sim.by, reusedFragments: reused, quotedShapes: quoted };}).sort((a, b) => b.score - a.score);const worst = rows[0];- return { rows, threshold, pass: rows.every((r) => r.score <= threshold && r.reusedFragments === 0), worst };+ return { rows, threshold, pass: rows.every((r) => r.score <= threshold && r.reusedFragments === 0 && r.quotedShapes === 0), worst };};diff --git a/skills/anidoodle/engine/tools/music-unit.mjs b/skills/anidoodle/engine/tools/music-unit.mjsindex bb7e779..edfdba8 100644--- a/skills/anidoodle/engine/tools/music-unit.mjs+++ b/skills/anidoodle/engine/tools/music-unit.mjs@@ -175,7 +175,16 @@ for (const secs of [70, 90, 110]) {const quoted = M.composePiece({ ...M.testMaterial(M.VOCAB.playful, { bars: 4 }), sections: [{ kind: "hook", bars: 2, harmony: ["c0"], groove: null, lead: ["G5:1 B5:.5 C6:.5 B5:1 G5:1", "E5:1 G5:.5 A5:.5 G5:1 E5:1"] }] });const src = M.composePiece({ ...M.testMaterial(M.VOCAB.playful, { bars: 4 }), sections: [{ kind: "hook", bars: 2, harmony: ["c0"], groove: null, lead: ["D5:1 F#5:.5 G5:.5 F#5:1 D5:1", "B4:1 D5:.5 E5:.5 D5:1 B4:1"] }] });const r = M.novelty(quoted, { src: () => src }); assert(!r.pass && r.rows[0].reusedFragments > 0, "a transposed quote must be caught");- pass(`novelty: a transposed 6-note quote of a shipped line fails (${r.rows[0].reusedFragments} reused fragments)`); }+ pass(`novelty: a transposed 6-note quote of a shipped line fails (${r.rows[0].reusedFragments} reused fragments)`);+ // a shipped melody re-barred into 5/4 (each 4/4 bar gains a beat on its last note), transposed up a tone: its rhythm and bar+ // positions are new, its 6-note (interval, duration) fragments are broken, but its intervals are the tune: it must FAIL+ const rebar = (name) => { const src = M.DEMOS[name](), bpb = M.beatsPerBar(src.plan.meter), mel = src.parts.flatMap((p) => p.notes.filter((n) => n.role === "melody")).sort((a, b) => a.t - b.t), last = new Map();+ for (const n of mel) { const k = Math.floor(n.t / bpb + 1e-9); last.set(k, Math.max(last.get(k) ?? -1, n.t)); }+ const notes = mel.map((n) => { const k = Math.floor(n.t / bpb + 1e-9); return { ...n, p: n.p + 2, t: n.t + k, d: n.d + (n.t === last.get(k) ? 1 : 0) }; }), bars = Math.ceil((Math.max(...notes.map((n) => n.t + n.d)) + 1) / 5);+ return { title: "re-barred", seed: 5, tail: 1, harmony: [], parts: [{ id: "lead", inst: "piano", role: "melody", notes }], plan: { style: "folk", tempo: 90, meter: "5/4", sections: [{ id: "a", bars, mood: "calm", key: "D", mode: "major", melody: ["stepwise"], dyn: [0.6, 0.6] }] } }; };+ for (const name of ["launchLofi3", "nocturne"]) { const v = M.novelty(rebar(name), M.DEMOS), row = v.rows.find((x) => x.name === name);+ assert(!v.pass && row.quotedShapes > 0, `${name} re-barred into 5/4 passed (score ${row.score}, fragments ${row.reusedFragments}, shapes ${row.quotedShapes})`);+ pass(`novelty: ${name}'s melody re-barred into 5/4 and transposed FAILS (similarity only ${row.score}, 6-note fragments ${row.reusedFragments}, 8-note shapes quoted ${row.quotedShapes})`); } }// 11. Speed without a changed bit: the voice cache and the parallel pool render exactly what a serial render does.{ const p = M.composePiece(M.testMaterial(M.VOCAB.lofi, { bars: 4 })), cache = new Map(), fresh = md5(M.renderPiece(p, SR));diff --git a/skills/anidoodle/engine/tools/music.mjs b/skills/anidoodle/engine/tools/music.mjsindex dafe165..891bbd0 100644--- a/skills/anidoodle/engine/tools/music.mjs+++ b/skills/anidoodle/engine/tools/music.mjs@@ -362,9 +362,11 @@ const report = (M, r, piece, cache, bands) => {return ok && g.ghost.pass && g.reverb.pass && (!g.masking || g.masking.pass);};const printNovelty = (M, name, v, what) => {- console.log(`novelty: ${name} vs ${v.rows.length} ${what} (fail above ${v.threshold}, or on any reused 6-note melody fragment)`);- for (const r of v.rows.slice(0, 5)) console.log(` ${r.name.padEnd(22)} ${r.score.toFixed(3)} ${r.reusedFragments ? `REUSED ${r.reusedFragments} fragment(s) ` : ""}${Object.entries(r.by).map(([k, x]) => `${k} ${x}`).join(" ")}`);- console.log(v.pass ? "novelty PASS" : `novelty FAIL: too close to ${v.worst.name}. Change what the numbers point at (the lead's rhythm, the contour, the groove, the chord colours, the form), not just the key.`);+ console.log(`novelty: ${name} vs ${v.rows.length} ${what} (fail above ${v.threshold}, on any reused 6-note melody fragment, or on an 8-note melody shape quoted in any key, meter or rhythm)`);+ const shown = [...v.rows.slice(0, 5), ...v.rows.slice(5).filter((r) => r.reusedFragments || r.quotedShapes)];+ for (const r of shown) console.log(` ${r.name.padEnd(22)} ${r.score.toFixed(3)} ${r.reusedFragments ? `REUSED ${r.reusedFragments} fragment(s) ` : ""}${r.quotedShapes ? `QUOTED ${r.quotedShapes} melody shape(s) ` : ""}${Object.entries(r.by).map(([k, x]) => `${k} ${x}`).join(" ")}`);+ const q = v.rows.find((r) => r.quotedShapes || r.reusedFragments);+ console.log(v.pass ? "novelty PASS" : q && q.score <= v.threshold ? `novelty FAIL: the melody quotes ${q.name} (the same intervals in a row, whatever the key, meter or rhythm). Write your own line.` : `novelty FAIL: too close to ${v.worst.name}. Change what the numbers point at (the lead's rhythm, the contour, the groove, the chord colours, the form), not just the key.`);console.log(" (idioms are fine: a ii-V-I, a plagal cadence, a two-chord vamp are vocabulary. What fails is the same music: a multi-bar progression WITH its rhythm, groove, contour and form, or a quoted melody.)");return v.pass;};diff --git a/skills/anidoodle/references/music/compose.md b/skills/anidoodle/references/music/compose.mdindex 150b2ab..936ef27 100644--- a/skills/anidoodle/references/music/compose.md+++ b/skills/anidoodle/references/music/compose.md@@ -19,7 +19,8 @@ what to compose. The engine then performs, synthesizes, mixes and masters, deter> **Never reuse shipped material.** The demos (`node tools/music.mjs list`) and our own film scores> are listening references and the novelty corpus. They are never a film's score or a template. Don't> copy them, transpose them or re-rhythm them. `node tools/music.mjs novelty` fails a score that-> sounds like any shipped piece, or that quotes a 6-note fragment of one (transposed or not).+> sounds like any shipped piece, or that quotes one: a 6-note fragment (transposed or not), or an+> 8-note melody shape in any key, meter or rhythm.>> **Idioms are fine.** A ii-V-I, a plagal amen, a two-chord vamp, a I-bVII-IV are vocabulary. The> style pages name them so you can use them. What is not fine is reusing the same music: a@@ -177,9 +178,28 @@ what to compose. The engine then performs, synthesizes, mixes and masters, deterand seconds) and which parts pile up there, loudest first, with the notes they are playing.Fix it in the notes at that spot: stagger the bass under that downbeat, roll the big chord, don'tdouble the climax note.- - **Novelty:** if it fails, change what the numbers point at. The per-feature scores name it:- the lead's rhythm, the contour, the groove, the chord colours, the form. Changing the key fixes- nothing.+ - **Novelty:** if it fails, change what the numbers point at. Changing the key fixes nothing.+ Each feature is a bag of n-grams compared by cosine (0 = nothing shared, 1 = the same); the+ score is their weighted mean, and it fails above 0.5:++ | Feature | Weight | What it counts |+ |---|---|---|+ | `melodyRhythm` | 0.20 | the lead's onset positions in each bar, and its inter-onset-interval trigrams |+ | `melodyContour` | 0.15 | the lead's up / down / same 4-grams |+ | `melodyIntervals` | 0.10 | the lead's interval trigrams, in semitones (transposition-free) |+ | `lineRhythm` | 0.15 | the counter line's rhythm plus the bass's rhythm (bar positions and inter-onset trigrams of each) |+ | `drums` | 0.15 | each drum part's hit positions per bar |+ | `chords` | 0.10 | chord-function trigrams: each root against the key, with its quality |+ | `qualities` | 0.07 | chord-quality trigrams (maj7, min, dom, sus ...) |+ | `form` | 0.08 | the order of section kinds, in pairs |++ The lead is the top note of each onset of the melody part. Bar positions depend on the meter;+ the inter-onset trigrams, the contour, the intervals and both quote gates do not. Two gates fail+ outright whatever the score: a **6-note fragment** of a shipped melody (its intervals and+ durations, in any key), and an **8-note melody shape** (its intervals alone, in any key, meter+ or rhythm: a quote re-barred into 5/4 or stretched is still the tune). Only distinctive shapes+ count (three or more different intervals, a leap of a third or more, at most three repeated+ notes), so a scale run is never a quote.- **Listen:** the person hears it before it is used. Meters prove you aren't obviously wrong.Only an ear says right. For a **loop**, deliver a `.wav`: mp3 adds encoder padding, so it clicksor gaps at the loop point.@@ -315,6 +335,6 @@ mid-bar writes its rest, `C2:3 r:1`, never a silent gap):| masking guard | `check`, `render` | the melody doesn't clear the other parts in 500 Hz-4 kHz || stems | `check`, `render --stems`, `stems` | a part is more than 3 dB off target (lead: up to +6 dB allowed); advisory for uncalibrated styles || craft | `craft`, `check` | (advisory scores and fixes) melody, harmony, rhythm, tension, mood fit; fails only on a note an acoustic instrument cannot play |-| novelty | `check`, `novelty` | similarity above 0.5 to a shipped piece (or to each other), or a reused 6-note melody fragment |+| novelty | `check`, `novelty` | similarity above 0.5 to a shipped piece (or to each other), a reused 6-note melody fragment, or an 8-note melody shape in any key, meter or rhythm |`tools/music-unit.mjs` keeps the engine honest: determinism, no defaults, every vocabulary renders.