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.

music: breadth - meters 2/4 5/4 7/8 9/8, moods anger/eerie/mischief/heroic/sensual/grief, style rows orchestral/suspense/rock/hipHop/house/synthwave/world/choral/playful, orchestra voices (organ, brass, woodwind, choir, timpani, lead synth, bowed solo), dense master true-peak trim

Alex Greenshpunf68b534b7e5c
diff --git a/skills/anidoodle/engine/src/canvas-core/music/lofiElectronic.ts b/skills/anidoodle/engine/src/canvas-core/music/lofiElectronic.ts
deleted file mode 100644
index ec69557..0000000
--- a/skills/anidoodle/engine/src/canvas-core/music/lofiElectronic.ts
+++ /dev/null
@@ -1,130 +0,0 @@
-// LO-FI ELECTRONIC, the style as an API. Chill, upbeat, clean electronic built on the lofiKit voices
-// (warmPad, softPluck, sub) and the drum kit: a 4-bar chord loop, sections that add and remove
-// layers, the kick pumping the pad, a dotted-eighth ping-pong on the hook, tape barely there.
-// No electric piano, no vinyl, no bit-crush (Alex: "upbeat, clear, not noisy"). The mix is set by
-// measured stem RMS against LOFI_STEM_TARGETS (LUFS alone once hid a sub 7-10 dB too hot).
-//
-// const piece = lofiElectronic({ bpm: 96, key: "D", progression: [...4 chords], home: 0,
-// sections: [{ kind: "intro", bars: 2 }, { kind: "hook", bars: 8, stretch: true }, { kind: "outro", bars: 2 }] });
-//
-// Section kinds and their layers (hook / sparkle flags add the lead and the high plucks anywhere):
-// intro pad only (the `intro` chords if given) groove pad, sub, full drums
-// hook groove + hook half pad, sub, half-time drums
-// breakdown pad only, drums and sub out drop groove + hook (the landing)
-// outro the home chord held, sub on the home root, the home note on the last bar
-// Harmony phase: bar `land` (a bar number or a section id; default the last drop, else the first
-// bar after the intro) plays progression[home]. `refit(seconds)` adds or removes whole loop cycles
-// of the `stretch` section so a film score still ends on its outro, never chopped at the last frame.
-import { line, type Note, type Piece, type Part, type Role } from "./plan";
-import type { ModeId } from "./theory";
-import type { MoodId } from "./tables";
-import { perform } from "./perform";
-
-/** One chord of the loop: pad voicing (notation chord), sub root and the walk note into the next bar, optional hook and sparkle bars. */
-export type LofiChord = { name: string; pad: string; root: string; walk: string; hook?: string | string[]; sparkle?: string };
-export type LofiKind = "intro" | "groove" | "hook" | "half" | "breakdown" | "drop" | "outro";
-export type LofiSection = { kind: LofiKind; bars: number; id?: string; hook?: boolean; sparkle?: boolean; stretch?: boolean };
-export type LofiDrums = { kick: [string, string]; snare: string; ghost: [string, string]; hats: string; halfKick: string; halfSnare: string; halfHats: string };
-export type LofiSpec = {
- title?: string; seed?: number; bpm: number; key: string; mode?: ModeId; mood?: MoodId;
- progression: LofiChord[]; home?: number; land?: number | string; intro?: { name: string; pad: string }[]; outroNote?: string;
- sections: LofiSection[];
- /** a seamless loop: no final ritard, no cadence relax, render it with renderLoop */ loop?: boolean;
- swing?: number; dyn?: [number, number]; tail?: number;
- /** gainDb per part id (pad, lead, sparkle, sub, kick, snare, ghost, hat), set by measuring stems */ levels?: Record<string, number>;
- drums?: Partial<LofiDrums>;
-};
-
-/** Stem RMS targets, dBFS over each stem's active samples (unmastered, pre-room). Calibrated on the approved launch score. */
-export const LOFI_STEM_TARGETS: Record<string, number> = { kick: -14, snare: -20, hat: -28, sub: -18, pad: -21, lead: -16.5, sparkle: -24 };
-
-const HATS16 = Array.from({ length: 16 }, (_, i) => `C4:.25@${[0.85, 0.35, 0.6, 0.4][i % 4]}`).join(" ");
-export const LOFI_DRUMS: LofiDrums = {
- kick: ["C4:1.5 C4:[email protected] C4:[email protected]", "C4:1.5 C4:[email protected] C4:[email protected] C4:[email protected] C4:[email protected]"], snare: "r:1 C4:2 C4:1",
- ghost: ["r:3.75 C4:[email protected]", "r:1.75 C4:[email protected] r:2"], hats: HATS16,
- halfKick: "C4:2 r:2", halfSnare: "r:2 C4:2", halfHats: "C4:[email protected] C4:[email protected] C4:[email protected] C4:[email protected]",
-};
-
-const HOOKED: LofiKind[] = ["hook", "drop"], DRUMMED: LofiKind[] = ["groove", "hook", "drop"], SUBBED: LofiKind[] = ["groove", "hook", "drop", "half"];
-const mod = (a: number, m: number) => ((a % m) + m) % m;
-
-/** Where each section starts, in bars. */
-export const lofiLayout = (sections: LofiSection[]) => { let b = 0; return sections.map((s, i) => { const from = b; b += s.bars; return { s, id: s.id ?? `${s.kind}${i}`, from, to: b }; }); };
-
-export const lofiElectronic = (spec: LofiSpec): Piece => {
- const lay = lofiLayout(spec.sections), B = lay[lay.length - 1].to, last = B - 1, P = spec.progression, len = P.length, home = spec.home ?? 0;
- const dr = { ...LOFI_DRUMS, ...spec.drums };
- const firstBody = lay.find((x) => x.s.kind !== "intro")?.from ?? 0, drops = lay.filter((x) => x.s.kind === "drop");
- const land = typeof spec.land === "number" ? spec.land : typeof spec.land === "string" ? lay.find((x) => x.id === spec.land)!.from : drops.length ? drops[drops.length - 1].from : firstBody;
- const anchor = spec.land !== undefined || drops.length ? home : 0; // with no landing asked for, the loop starts at its first chord
- const ci = (b: number) => mod(b - land + anchor, len), pass = (b: number) => Math.floor((b - land + anchor) / len);
- const at = (b: number) => lay.find((x) => b >= x.from && b < x.to)!;
- const H = P[home], outroNote = spec.outroNote ?? `${spec.key.replace(/m$/, "")}5`;
- const bars = (role: Role, v: number, fn: (b: number) => string | null, extra: { roll?: number } = {}): Note[] => {
- const out: Note[] = [];
- for (let b = 0; b < B; b++) { const s = fn(b); if (s) out.push(...line(b * 4, s, { role, v, bpb: 4, ...extra })); }
- return out;
- };
- const kind = (b: number) => at(b).s.kind, introIdx = (b: number) => b - at(b).from;
- const introChord = (b: number) => (kind(b) === "intro" && spec.intro?.length ? spec.intro[introIdx(b) % spec.intro.length] : null);
- const hookOn = (b: number) => at(b).s.hook ?? HOOKED.includes(kind(b));
- const pickHook = (c: LofiChord, b: number) => (Array.isArray(c.hook) ? c.hook[mod(pass(b), c.hook.length)] : c.hook) ?? null;
-
- const pad = bars("accomp", 0.62, (b) => { const ic = introChord(b); return kind(b) === "outro" ? `${H.pad}:[email protected]` : ic ? `${ic.pad}:[email protected]` : `${P[ci(b)].pad}:4`; }, { roll: 0.03 });
- const sub = bars("bass", 0.85, (b) => (kind(b) === "outro" ? `${H.root}:4` : SUBBED.includes(kind(b)) ? `${P[ci(b)].root}:3 r:.5 ${P[ci(b)].walk}:.5` : null));
- const drum = (full: (b: number) => string | null, half: string | null) => (b: number) => (DRUMMED.includes(kind(b)) ? full(b) : kind(b) === "half" ? half : null);
- const kick = bars("drum", 0.85, drum((b) => dr.kick[b % 2], dr.halfKick));
- const snare = bars("drum", 0.7, drum(() => dr.snare, dr.halfSnare));
- const ghost = bars("drum", 0.5, drum((b) => dr.ghost[b % 2], null));
- const hats = bars("drum", 0.5, drum(() => dr.hats, dr.halfHats));
- const lead = bars("melody", 0.72, (b) => (kind(b) === "outro" ? (b === last ? `${outroNote}:4` : null) : hookOn(b) ? pickHook(P[ci(b)], b) : null));
- const sparkle = bars("color", 0.5, (b) => (at(b).s.sparkle && kind(b) !== "outro" ? P[ci(b)].sparkle ?? null : null));
- const harmony = Array.from({ length: B }, (_, b) => ({ t: b * 4, name: kind(b) === "outro" ? H.name : introChord(b)?.name ?? P[ci(b)].name }));
-
- const bpm = spec.bpm, DE = (60 / bpm) * 0.75, lv = spec.levels ?? {};
- const g = (id: string, d: number) => lv[id] ?? d;
- const parts: Part[] = [
- { id: "pad", inst: "warmPad", role: "accomp", notes: pad, gainDb: g("pad", -3), opts: { cut: 2600, attack: 0.5, release: 1.4, spread: 0.55 }, send: 0.35 },
- { id: "lead", inst: "softPluck", role: "melody", notes: lead, gainDb: g("lead", 6), opts: { decay: 0.42, bright: 6000, delay: DE, feedback: 0.28, delayMix: 0.24 }, send: 0.25 },
- { id: "sparkle", inst: "softPluck", role: "color", notes: sparkle, gainDb: g("sparkle", 8), opts: { decay: 0.35, bright: 5200, pan: 0.35, delay: DE, feedback: 0.3, delayMix: 0.35 }, send: 0.6 },
- { id: "sub", inst: "sub", role: "bass", notes: sub, gainDb: g("sub", -6), opts: { cut: 150 } },
- { id: "kick", inst: "kick", role: "drum", notes: kick, gainDb: g("kick", 0.5), send: 0.1 },
- { id: "snare", inst: "snare", role: "drum", notes: snare, gainDb: g("snare", 8), send: 0.3 },
- { id: "ghost", inst: "snare", role: "drum", notes: ghost, opts: { rim: true }, gainDb: g("ghost", 4), send: 0.2 },
- { id: "hat", inst: "hat", role: "drum", notes: hats, opts: { pan: 0.25 }, gainDb: g("hat", 20), send: 0.1 },
- ];
- return {
- title: spec.title ?? `lo-fi electronic in ${spec.key}`, seed: spec.seed ?? 2027, tail: spec.tail ?? 3.2, harmony, parts,
- plan: { style: "lofiElectronic", tempo: bpm, meter: "4/4", swing: spec.swing ?? 0.54, ritard: spec.loop ? 1 : 0.92, loop: spec.loop,
- sections: [{ id: "a", bars: B, mood: spec.mood ?? "calm", key: spec.key, mode: spec.mode ?? "major", melody: ["stepwise", "hook"], dyn: spec.dyn ?? [0.62, 0.66], ending: "tail", repeatable: false }] },
- fx: { clean: true, duck: { by: "kick", parts: ["pad", "sparkle"], depth: 0.38, release: 0.24 }, tape: { wowCents: 2.5, wowHz: 0.4, flutterCents: 0, flutterHz: 6, drive: 1.02 } },
- stemTargets: LOFI_STEM_TARGETS,
- arrangement: lay.map((x) => ({ id: x.id, kind: x.s.kind, from: x.from, bars: x.s.bars })),
- refit: spec.loop ? undefined : (seconds: number) => lofiElectronic(refitLofi(spec, seconds)),
- };
-};
-
-/**
- * The same arrangement for a film `seconds` long: the `stretch` section (default the longest hook,
- * groove or drop section) gains or loses whole loop cycles so, at the written bpm, the last onset
- * lands nearest `seconds - tail`. fitToDuration then trims the tempo by the remaining few percent.
- * Harmony stays in phase because only whole cycles move; a numeric `land` after the stretch moves with it.
- */
-export const refitLofi = (spec: LofiSpec, seconds: number): LofiSpec => {
- const secs = spec.sections, len = spec.progression.length, want = seconds - (spec.tail ?? 3.2);
- let si = secs.findIndex((s) => s.stretch);
- if (si < 0) secs.forEach((s, i) => { if (["hook", "groove", "drop"].includes(s.kind) && (si < 0 || s.bars > secs[si].bars)) si = i; });
- if (si < 0 || want <= 0) return spec;
- const from = lofiLayout(secs)[si].from, b0 = secs[si].bars;
- let best: { spec: LofiSpec; cost: number } | null = null;
- for (let k = -Math.floor(b0 / len); k <= 64; k++) {
- const bars = b0 + k * len; // 0 = the section drops out for a short film
- const land = typeof spec.land === "number" && spec.land >= from + b0 ? spec.land + k * len : spec.land;
- const s2: LofiSpec = { ...spec, land, sections: secs.map((s, i) => (i === si ? { ...s, bars } : s)) };
- const p = lofiElectronic({ ...s2 }), t = perform(p, spec.bpm, { expressive: true }).lastOnset, tempo = spec.bpm * (t / want);
- const cost = Math.abs(Math.log(tempo / spec.bpm));
- if (!best || cost < best.cost) best = { spec: s2, cost };
- if (tempo > spec.bpm * 1.3) break;
- }
- return best!.spec;
-};
diff --git a/skills/anidoodle/engine/src/canvas-core/music/orchestra.ts b/skills/anidoodle/engine/src/canvas-core/music/orchestra.ts
new file mode 100644
index 0000000..1dd887b
--- /dev/null
+++ b/skills/anidoodle/engine/src/canvas-core/music/orchestra.ts
@@ -0,0 +1,110 @@
+// ORCHESTRA AND BAND VOICES, added for breadth (orchestral, choral, suspense, rock, synthwave,
+// world). Procedural approximations, deterministic, pure in (keys, sr, n, opts, rng). Acoustic
+// timbres made this way are approximations: a human listens before one carries a film (spec 08
+// DECISION B). Each voice states the physics it borrows.
+import { type Rng, TAU, clamp, pan, SVF, blep, gauss } from "./dsp";
+import type { Played } from "./perform";
+
+type Out = { L: Float32Array; R: Float32Array };
+type Opts = Record<string, number | boolean | string>;
+const num = (o: Opts, k: string, d: number) => (typeof o[k] === "number" ? (o[k] as number) : d);
+const f0 = (m: number) => 440 * Math.pow(2, (m - 69) / 12);
+const out0 = (n: number): Out => ({ L: new Float32Array(n), R: new Float32Array(n) });
+const byPitch = (p: number, w: number) => pan(clamp((p - 60) / 30, -1, 1) * w);
+/** attack / sustain / release envelope for a held key */
+const asr = (t: number, dur: number, atk: number, rel: number) => (t < dur ? Math.min(1, t / atk) : Math.min(1, dur / atk) * Math.exp(-(t - dur) / (rel / 4)));
+
+/** Pipe organ: drawbar ranks (harmonics 1 2 3 4 6 8) summed per pipe, two detuned copies (chorus), a slow tremulant. `bright` weights the upper ranks. */
+export const organ = (keys: Played[], sr: number, n: number, o: Opts): Out => {
+ const out = out0(n), bright = num(o, "bright", 1), trem = num(o, "trem", 5.5), ranks = [[1, 1], [2, 0.7], [3, 0.35 * bright], [4, 0.35 * bright], [6, 0.18 * bright], [8, 0.12 * bright]];
+ for (const k of keys) {
+ const f = f0(k.p), i0 = Math.round(k.t * sr), dur = k.off - k.t, len = Math.min(n - i0, Math.ceil((dur + 0.15) * sr)), [gl, gr] = byPitch(k.p, 0.5);
+ for (let i = 0; i < len; i++) { const t = i / sr, e = asr(t, dur, 0.015, 0.08) * k.v * 0.09 * (1 + 0.06 * Math.sin(TAU * trem * t));
+ let s = 0; for (const [h, a] of ranks) if (f * h < sr / 2.2) s += a * (Math.sin(TAU * f * h * t) + Math.sin(TAU * f * h * 1.0012 * t + 1.3)) * 0.5;
+ out.L[i0 + i] += s * e * gl; out.R[i0 + i] += s * e * gr; }
+ }
+ return out;
+};
+
+/** Brass: a PolyBLEP saw whose low-pass opens with loudness (the brass "bite"), the pitch rising ~25 cents into the note, vibrato delayed. `attack`, `bright`. */
+export const brass = (keys: Played[], sr: number, n: number, o: Opts): Out => {
+ const out = out0(n), atk = num(o, "attack", 0.06), bright = num(o, "bright", 1), w = num(o, "width", 0.5);
+ for (const k of keys) {
+ const f = f0(k.p), i0 = Math.round(k.t * sr), dur = k.off - k.t, len = Math.min(n - i0, Math.ceil((dur + 0.3) * sr)), lp = new SVF(sr, 800, 0.8), [gl, gr] = byPitch(k.p, w); let ph = 0;
+ for (let i = 0; i < len; i++) { const t = i / sr, e = asr(t, dur, atk, 0.25), cents = -25 * Math.exp(-t / 0.05) + (t > 0.25 ? 12 * Math.sin(TAU * 5.2 * t) * Math.min(1, (t - 0.25) / 0.3) : 0), inc = (f * Math.pow(2, cents / 1200)) / sr;
+ ph += inc; if (ph >= 1) ph -= 1; if ((i & 15) === 0) lp.set(clamp(f * (1.5 + 7 * e * k.v * bright), 200, 12000), 0.8);
+ const y = lp.tick(2 * ph - 1 - blep(ph, inc)) * e * k.v * 0.22; out.L[i0 + i] += y * gl; out.R[i0 + i] += y * gr; }
+ }
+ return out;
+};
+
+/** Woodwind: flute (sine + weak 2nd/3rd + breath noise at the pitch) or `reed: true` clarinet (odd harmonics, darker). Delayed vibrato. */
+export const woodwind = (keys: Played[], sr: number, n: number, o: Opts, r: Rng): Out => {
+ const out = out0(n), reed = o.reed === true, breath = num(o, "breath", reed ? 0.02 : 0.08), w = num(o, "width", 0.3);
+ for (const k of keys) {
+ const f = f0(k.p), i0 = Math.round(k.t * sr), dur = k.off - k.t, len = Math.min(n - i0, Math.ceil((dur + 0.2) * sr)), bp = new SVF(sr, f, 4), [gl, gr] = byPitch(k.p, w); let ph = 0;
+ for (let i = 0; i < len; i++) { const t = i / sr, e = asr(t, dur, reed ? 0.04 : 0.07, 0.15), vib = t > 0.2 ? 1 + 0.004 * Math.sin(TAU * 5 * t) * Math.min(1, (t - 0.2) / 0.3) : 1;
+ ph += (f * vib) / sr; if (ph >= 1) ph -= 1; const x = TAU * ph;
+ const tone = reed ? Math.sin(x) + 0.33 * Math.sin(3 * x) + 0.18 * Math.sin(5 * x) + 0.08 * Math.sin(7 * x) : Math.sin(x) + 0.12 * Math.sin(2 * x) + 0.05 * Math.sin(3 * x);
+ bp.tick(gauss(r)); const y = (tone * 0.8 + bp.bp * breath * 6) * e * k.v * 0.16; out.L[i0 + i] += y * gl; out.R[i0 + i] += y * gr; }
+ }
+ return out;
+};
+
+const VOWELS: Record<string, [number, number, number]> = { a: [700, 1220, 2600], o: [450, 800, 2830], u: [325, 700, 2530], e: [530, 1840, 2480], i: [300, 2200, 3000] };
+/** Choir: three detuned saws per note through the formants of a vowel (`vowel`: a o u e i), slow attack. Texture and pads; never a lead. */
+export const choir = (keys: Played[], sr: number, n: number, o: Opts, r: Rng): Out => {
+ const out = out0(n), fm = VOWELS[String(o.vowel ?? "a")] ?? VOWELS.a, atk = num(o, "attack", 0.35), w = num(o, "width", 0.8);
+ for (const k of keys) {
+ const f = f0(k.p), i0 = Math.round(k.t * sr), dur = k.off - k.t, len = Math.min(n - i0, Math.ceil((dur + 0.8) * sr));
+ const dets = [-9, 0, 8], phs = dets.map(() => r()), vr = dets.map(() => 4.5 + r()), pans = dets.map((_, j) => pan((j - 1) * w));
+ const fl = [0, 1].map(() => fm.map((q, j) => new SVF(sr, q, [9, 11, 13][j])));
+ for (let i = 0; i < len; i++) { const t = i / sr, e = asr(t, dur, atk, 0.7) * k.v * 0.14; let sl = 0, sR = 0;
+ for (let v = 0; v < 3; v++) { const inc = (f * Math.pow(2, (dets[v] + 10 * Math.sin(TAU * vr[v] * t)) / 1200)) / sr; let ph = phs[v] + inc; if (ph >= 1) ph -= 1; phs[v] = ph; const s = 2 * ph - 1 - blep(ph, inc); sl += s * pans[v][0]; sR += s * pans[v][1]; }
+ let yl = 0, yr = 0; for (let j = 0; j < 3; j++) { fl[0][j].tick(sl); fl[1][j].tick(sR); yl += fl[0][j].bp * [1, 0.6, 0.3][j]; yr += fl[1][j].bp * [1, 0.6, 0.3][j]; }
+ out.L[i0 + i] += yl * e; out.R[i0 + i] += yr * e; }
+ }
+ return out;
+};
+
+/** Timpani (`pitch`: a MIDI note to tune it when it plays a drum lane): a tuned membrane (modal partials 1, 1.5, 1.99, 2.44, 2.97 with their own decays), a small downward pitch settle, a felt-mallet thump. Pitched on the note. */
+export const timpani = (keys: Played[], sr: number, n: number, o: Opts, r: Rng): Out => {
+ const out = out0(n), dec = num(o, "decay", 1.6), P = [[1, 1, 1], [1.5, 0.5, 0.7], [1.99, 0.35, 0.5], [2.44, 0.2, 0.35], [2.97, 0.12, 0.25]];
+ for (const k of keys) {
+ const f = f0(typeof o.pitch === "number" ? (o.pitch as number) : k.p), i0 = Math.round(k.t * sr), len = Math.min(n - i0, Math.ceil(dec * 4 * sr)), lp = new SVF(sr, 400, 0.7);
+ for (let i = 0; i < len; i++) { const t = i / sr, bend = 1 + 0.03 * Math.exp(-t / 0.08); let s = 0;
+ for (const [h, a, d] of P) s += a * Math.sin(TAU * f * h * bend * t) * Math.exp(-t / (dec * d));
+ lp.tick(gauss(r)); const y = (s + lp.lp * Math.exp(-t / 0.012) * 3) * k.v * 0.3; out.L[i0 + i] += y; out.R[i0 + i] += y * 0.97; }
+ }
+ return out;
+};
+
+/** Lead synth: monophonic saw + square, portamento `glide` s between touching notes, a filter envelope re-struck each note, vibrato blooming on long notes (spec 06 lead). */
+export const leadSynth = (keys: Played[], sr: number, n: number, o: Opts): Out => {
+ const out = out0(n), glide = num(o, "glide", 0.03), cut = num(o, "cut", 1700), envAmt = num(o, "env", 4500), sq = num(o, "square", 0.4), [gl, gr] = pan(num(o, "pan", 0));
+ const ks = keys.slice().sort((a, b) => a.t - b.t); let prevF = 0, prevOff = -1, ph = 0, ph2 = 0; const lp = new SVF(sr, cut, 1.2);
+ ks.forEach((k, idx) => {
+ const f = f0(k.p), i0 = Math.round(k.t * sr), nextT = idx + 1 < ks.length ? ks[idx + 1].t : Infinity, dur = Math.min(k.off, nextT) - k.t, tail = nextT < k.off + 0.12 ? nextT - k.t : dur + 0.12;
+ const len = Math.min(n - i0, Math.ceil(Math.max(0.01, tail) * sr)), from = prevF && k.t - prevOff < 0.05 ? prevF : f;
+ for (let i = 0; i < len; i++) { const t = i / sr, fr = from + (f - from) * Math.min(1, t / Math.max(1e-4, glide)), vib = t > 0.3 ? 1 + 0.006 * Math.sin(TAU * 5.5 * t) * Math.min(1, (t - 0.3) / 0.4) : 1, inc = (fr * vib) / sr;
+ ph += inc; if (ph >= 1) ph -= 1; ph2 += inc; if (ph2 >= 1) ph2 -= 1;
+ const e = Math.min(1, t / 0.006) * (t < dur ? 1 : Math.exp(-(t - dur) / 0.03));
+ if ((i & 15) === 0) lp.set(clamp(cut + envAmt * k.v * Math.exp(-t / 0.18), 150, 14000), 1.2);
+ const y = lp.tick((2 * ph - 1 - blep(ph, inc)) + sq * (ph2 < 0.5 ? 1 : -1)) * e * k.v * 0.18; out.L[i0 + i] += y * gl; out.R[i0 + i] += y * gr; }
+ prevF = f; prevOff = k.t + dur;
+ });
+ return out;
+};
+
+/** Bowed solo (violin / cello): one saw with delayed vibrato and bow noise through body resonances (~280, 450, 2800 Hz), a bowed attack. */
+export const bowedSolo = (keys: Played[], sr: number, n: number, o: Opts, r: Rng): Out => {
+ const out = out0(n), atk = num(o, "attack", 0.09), vibC = num(o, "vibrato", 22), [gl, gr] = pan(num(o, "pan", -0.1));
+ const body = o.cello === true ? [140, 300, 1600] : [280, 450, 2800];
+ for (const k of keys) {
+ const f = f0(k.p), i0 = Math.round(k.t * sr), dur = k.off - k.t, len = Math.min(n - i0, Math.ceil((dur + 0.35) * sr)), bs = body.map((q) => new SVF(sr, q, 2.2)), lp = new SVF(sr, 5000, 0.7); let ph = 0;
+ for (let i = 0; i < len; i++) { const t = i / sr, e = asr(t, dur, atk, 0.3), vib = t > 0.15 ? vibC * Math.sin(TAU * 5.6 * t) * Math.min(1, (t - 0.15) / 0.35) : 0, inc = (f * Math.pow(2, vib / 1200)) / sr;
+ ph += inc; if (ph >= 1) ph -= 1; const x = 2 * ph - 1 - blep(ph, inc) + gauss(r) * 0.06;
+ let y = lp.tick(x) * 0.35; for (const b of bs) { b.tick(x); y += b.bp * 0.5; } y *= e * k.v * 0.16; out.L[i0 + i] += y * gl; out.R[i0 + i] += y * gr; }
+ }
+ return out;
+};
diff --git a/skills/anidoodle/engine/src/canvas-core/music/pieces/lofi.ts b/skills/anidoodle/engine/src/canvas-core/music/pieces/copyFixture.ts
similarity index 100%
rename from skills/anidoodle/engine/src/canvas-core/music/pieces/lofi.ts
rename to skills/anidoodle/engine/src/canvas-core/music/pieces/copyFixture.ts
diff --git a/skills/anidoodle/engine/src/canvas-core/music/plan.ts b/skills/anidoodle/engine/src/canvas-core/music/plan.ts
index d7ef357..ba16107 100644
--- a/skills/anidoodle/engine/src/canvas-core/music/plan.ts
+++ b/skills/anidoodle/engine/src/canvas-core/music/plan.ts
@@ -4,13 +4,15 @@
import { midi, type ModeId, MODES, detectMode, pcOf } from "./theory";
import { MOODS, STYLES, REFUSED_BLENDS, type MoodId, type StyleId, type MelodyType } from "./tables";
-export type Meter = "3/4" | "4/4" | "6/8" | "12/8";
-export const beatsPerBar = (m: Meter) => (m === "3/4" ? 3 : m === "4/4" ? 4 : m === "6/8" ? 2 : 4);
+export type Meter = "2/4" | "3/4" | "4/4" | "5/4" | "6/8" | "7/8" | "9/8" | "12/8";
+/** Beats per bar. Simple meters count quarters (7/8 = 3.5 quarters, write eighths as .5); compound meters (6/8, 9/8, 12/8) count dotted quarters (write eighths as 1/3). */
+export const beatsPerBar = (m: Meter) => ({ "2/4": 2, "3/4": 3, "4/4": 4, "5/4": 5, "6/8": 2, "7/8": 3.5, "9/8": 3, "12/8": 4 })[m];
+export const isCompound = (m: Meter) => m === "6/8" || m === "9/8" || m === "12/8";
export type Role = "melody" | "inner" | "bass" | "accomp" | "color" | "drum";
/** t, d in beats from the piece start; p = MIDI; v = written velocity 0..1 (performance shapes it). */
export type Note = { t: number; d: number; p: number; v: number; role: Role; roll?: number; kind?: string };
-export type InstId = "piano" | "musicBox" | "bell" | "celesta" | "marimba" | "vibes" | "harp" | "guitar" | "strings" | "fmBell" | "ePiano" | "pulse" | "triangle" | "noiseDrum" | "kick" | "snare" | "hat" | "bass" | "vinyl" | "warmPad" | "softPluck" | "sub";
+export type InstId = "piano" | "musicBox" | "bell" | "celesta" | "marimba" | "vibes" | "harp" | "guitar" | "strings" | "fmBell" | "ePiano" | "pulse" | "triangle" | "noiseDrum" | "kick" | "snare" | "hat" | "bass" | "vinyl" | "warmPad" | "softPluck" | "sub" | "organ" | "brass" | "woodwind" | "choir" | "timpani" | "leadSynth" | "bowedSolo";
export type Part = { id: string; inst: InstId; role: Role; notes: Note[]; gainDb?: number; pan?: number; opts?: Record<string, number | boolean | string>; send?: number };
export type Section = {
id: string; bars: number; mood: MoodId | [MoodId, MoodId, number]; key: string; mode: ModeId; melody: MelodyType[];
diff --git a/skills/anidoodle/engine/src/canvas-core/music/render.ts b/skills/anidoodle/engine/src/canvas-core/music/render.ts
index 8c5ec0f..d14a4fb 100644
--- a/skills/anidoodle/engine/src/canvas-core/music/render.ts
+++ b/skills/anidoodle/engine/src/canvas-core/music/render.ts
@@ -6,6 +6,7 @@ import { type Piece, type Part, resequence, beatsPerBar } from "./plan";
import { perform, type Performance, type Played } from "./perform";
import { renderPiano, PIANO_REAL, type PianoOpts } from "./piano";
import * as I from "./instruments";
+import * as O from "./orchestra";
import { room, Biquad, db } from "./dsp";
import { warmPad, softPluck, sub, duckCurve, tape } from "./lofiKit";
import { loudness, truePeak, stemBalance } from "./meter";
@@ -40,6 +41,13 @@ const voice = (pt: Part, keys: Played[], sr: number, n: number, seed: number) =>
case "warmPad": return warmPad(keys, sr, n, o, r);
case "softPluck": return softPluck(keys, sr, n, o);
case "sub": return sub(keys, sr, n, o);
+ case "organ": return O.organ(keys, sr, n, o);
+ case "brass": return O.brass(keys, sr, n, o);
+ case "woodwind": return O.woodwind(keys, sr, n, o, r);
+ case "choir": return O.choir(keys, sr, n, o, r);
+ case "timpani": return O.timpani(keys, sr, n, o, r);
+ case "leadSynth": return O.leadSynth(keys, sr, n, o);
+ case "bowedSolo": return O.bowedSolo(keys, sr, n, o, r);
default: throw new Error(`no instrument ${pt.inst}`);
}
};
@@ -100,7 +108,11 @@ export const master = (L: Float32Array, R: Float32Array, sr: number, masterMode:
const tp = truePeak([L, R]).dbtp;
if (tp > -1) {
if (masterMode === "gentle") { const cut = tp + 1.05; gainDb -= cut; for (let i = 0; i < n; i++) { L[i] *= db(-cut); R[i] *= db(-cut); } }
- else { limiter(L, R, sr, db(-1.3)); const again = target - loudness([L, R], sr).integrated; if (again > 0) { const g = db(Math.min(again, 1)); for (let i = 0; i < n; i++) { L[i] *= g; R[i] *= g; } limiter(L, R, sr, db(-1.3)); } }
+ else {
+ limiter(L, R, sr, db(-1.3)); const again = target - loudness([L, R], sr).integrated; if (again > 0) { const g = db(Math.min(again, 1)); for (let i = 0; i < n; i++) { L[i] *= g; R[i] *= g; } limiter(L, R, sr, db(-1.3)); }
+ const tp2 = truePeak([L, R]).dbtp; // harsh waveforms (pulses) can still overshoot between samples: a last static trim
+ if (tp2 > -1) { const cut = tp2 + 1.05; gainDb -= cut; for (let i = 0; i < n; i++) { L[i] *= db(-cut); R[i] *= db(-cut); } }
+ }
}
return gainDb;
};
diff --git a/skills/anidoodle/engine/src/canvas-core/music/tables.ts b/skills/anidoodle/engine/src/canvas-core/music/tables.ts
index e9c137c..2e2ddc4 100644
--- a/skills/anidoodle/engine/src/canvas-core/music/tables.ts
+++ b/skills/anidoodle/engine/src/canvas-core/music/tables.ts
@@ -4,14 +4,14 @@
import type { ModeId } from "./theory";
export type MelodyType = "arpeggio" | "stepwise" | "hook" | "ostinato" | "drone" | "callResponse" | "counterMelody" | "sequence" | "themeTransformation";
-export type Family = "piano" | "musicBox" | "celesta" | "mallets" | "pluck" | "harp" | "guitar" | "strings" | "fmBell" | "ePiano" | "chip" | "drums" | "organ" | "bass" | "pad";
+export type Family = "piano" | "musicBox" | "celesta" | "mallets" | "pluck" | "harp" | "guitar" | "strings" | "fmBell" | "ePiano" | "chip" | "drums" | "organ" | "bass" | "pad" | "brass" | "woodwind" | "choir" | "orchPerc" | "synthLead" | "bowed";
export type Range = [number, number];
export type Mood = {
id: MoodId; modes: ModeId[]; tempo: Range; meters: string[]; harmonicRhythmBars: Range; register: Range;
onsetsPerBeat: Range; attackMs: Range; lra: Range; centroidHz: Range | null; families: Family[]; melody: MelodyType[];
master: "gentle" | "dense"; confirmedBy?: { date: string; words: string };
};
-export type MoodId = "joy" | "playful" | "tender" | "wistful" | "melancholy" | "hopeful" | "curious" | "tension" | "dread" | "awe" | "triumph" | "drive" | "calm" | "nostalgic" | "romantic";
+export type MoodId = "joy" | "playful" | "tender" | "wistful" | "melancholy" | "hopeful" | "curious" | "tension" | "dread" | "awe" | "triumph" | "drive" | "calm" | "nostalgic" | "romantic" | "anger" | "eerie" | "mischief" | "heroic" | "sensual" | "grief";
// centroid null = report only (spec 08 drive row; ADVISORY 4.1: piano brightness is never gated).
export const MOODS: Record<MoodId, Mood> = {
@@ -29,6 +29,12 @@ export const MOODS: Record<MoodId, Mood> = {
drive: { id: "drive", modes: ["aeolian", "dorian", "mixolydian"], tempo: [110, 140], meters: ["4/4"], harmonicRhythmBars: [1, 1], register: [60, 86], onsetsPerBeat: [4, 8], attackMs: [1, 5], lra: [4, 8], centroidHz: null, families: ["drums", "bass", "pluck"], melody: ["hook", "arpeggio", "ostinato"], master: "dense" },
calm: { id: "calm", modes: ["mixolydian", "majorPentatonic", "major"], tempo: [60, 90], meters: ["6/8", "3/4"], harmonicRhythmBars: [2, 2], register: [60, 84], onsetsPerBeat: [1, 2], attackMs: [5, 30], lra: [4, 8], centroidHz: [1000, 2000], families: ["guitar", "fmBell"], melody: ["stepwise", "drone"], master: "gentle" },
nostalgic: { id: "nostalgic", modes: ["major"], tempo: [70, 95], meters: ["4/4"], harmonicRhythmBars: [0.5, 1], register: [60, 84], onsetsPerBeat: [1.5, 3], attackMs: [5, 20], lra: [6, 10], centroidHz: [900, 1600], families: ["ePiano", "drums", "bass"], melody: ["stepwise", "hook"], master: "dense" },
+ anger: { id: "anger", modes: ["phrygian", "aeolian", "harmonicMinor"], tempo: [120, 170], meters: ["4/4", "7/8"], harmonicRhythmBars: [1, 2], register: [40, 72], onsetsPerBeat: [3, 8], attackMs: [1, 5], lra: [4, 8], centroidHz: [1200, 5000], families: ["drums", "bass", "brass", "synthLead"], melody: ["ostinato", "hook"], master: "dense" },
+ eerie: { id: "eerie", modes: ["wholeTone", "locrian", "phrygian", "harmonicMinor"], tempo: [50, 90], meters: ["4/4", "3/4", "5/4"], harmonicRhythmBars: [2, 4], register: [48, 96], onsetsPerBeat: [0.25, 1], attackMs: [50, 400], lra: [10, 18], centroidHz: null, families: ["bowed", "choir", "celesta", "fmBell"], melody: ["drone", "sequence"], master: "gentle" },
+ mischief: { id: "mischief", modes: ["blues", "dorian", "mixolydian", "wholeTone"], tempo: [100, 150], meters: ["4/4", "2/4", "6/8"], harmonicRhythmBars: [0.5, 1], register: [55, 90], onsetsPerBeat: [1.5, 3], attackMs: [2, 8], lra: [6, 12], centroidHz: [1200, 4000], families: ["woodwind", "pluck", "mallets", "bass"], melody: ["callResponse", "hook"], master: "gentle" },
+ heroic: { id: "heroic", modes: ["major", "mixolydian", "dorian"], tempo: [90, 130], meters: ["4/4", "3/4"], harmonicRhythmBars: [1, 2], register: [55, 84], onsetsPerBeat: [1, 3], attackMs: [10, 60], lra: [8, 14], centroidHz: null, families: ["brass", "strings", "orchPerc", "choir"], melody: ["hook", "themeTransformation"], master: "gentle" },
+ sensual: { id: "sensual", modes: ["dorian", "aeolian", "mixolydian"], tempo: [65, 95], meters: ["4/4", "12/8"], harmonicRhythmBars: [1, 2], register: [55, 80], onsetsPerBeat: [0.75, 2], attackMs: [10, 60], lra: [6, 10], centroidHz: [800, 2000], families: ["ePiano", "bass", "woodwind", "drums"], melody: ["stepwise", "counterMelody"], master: "dense" },
+ grief: { id: "grief", modes: ["aeolian", "harmonicMinor"], tempo: [40, 62], meters: ["3/4", "4/4"], harmonicRhythmBars: [2, 4], register: [48, 76], onsetsPerBeat: [0.5, 1], attackMs: [40, 200], lra: [10, 16], centroidHz: null, families: ["bowed", "piano", "strings", "choir"], melody: ["stepwise", "themeTransformation"], master: "gentle" },
romantic: { id: "romantic", modes: ["major", "aeolian"], tempo: [60, 85], meters: ["3/4", "4/4"], harmonicRhythmBars: [1, 1], register: [60, 88], onsetsPerBeat: [1, 2.5], attackMs: [10, 60], lra: [8, 14], centroidHz: [1000, 2000], families: ["piano", "strings"], melody: ["stepwise", "counterMelody"], master: "gentle" },
};
@@ -36,7 +42,7 @@ export const MOODS: Record<MoodId, Mood> = {
export const REFUSED_BLENDS: [MoodId, MoodId][] = [["joy", "dread"], ["playful", "melancholy"], ["calm", "tension"]];
export const ARCS: Record<string, MoodId[]> = { rise: ["melancholy", "hopeful", "triumph"], turn: ["joy", "tension", "joy"], fallAndReturn: ["tender", "melancholy", "tender"], wonder: ["curious", "awe"], comic: ["playful", "tension", "playful"] };
-export type StyleId = "musicBox" | "nocturne" | "drive" | "cinematic" | "chiptune" | "lofi" | "lofiElectronic" | "folk" | "minimalist" | "jazz" | "lullaby" | "ambient";
+export type StyleId = "musicBox" | "nocturne" | "drive" | "cinematic" | "chiptune" | "lofi" | "lofiElectronic" | "folk" | "minimalist" | "jazz" | "lullaby" | "ambient" | "playful" | "orchestral" | "suspense" | "rock" | "hipHop" | "house" | "synthwave" | "world" | "choral";
export type Style = { id: StyleId; tempo: Range; meters: string[]; families: Family[]; moods: MoodId[]; master: "gentle" | "dense"; arrangement: string; guards: string[]; reverb: "none" | "room" | "hall"; swing?: Range };
export const STYLES: Record<StyleId, Style> = {
musicBox: { id: "musicBox", tempo: [110, 130], meters: ["12/8"], families: ["musicBox", "fmBell"], moods: ["joy", "curious", "tender", "playful", "wistful"], master: "gentle", reverb: "room", arrangement: "melody -> +bass -> +arp -> +octave sparkle -> bell", guards: ["pluck-only instruments", "more notes, never longer notes"] },
@@ -46,6 +52,15 @@ export const STYLES: Record<StyleId, Style> = {
chiptune: { id: "chiptune", tempo: [120, 160], meters: ["4/4"], families: ["chip"], moods: ["joy", "playful", "drive", "tension"], master: "dense", reverb: "none", arrangement: "2 pulses, triangle bass, noise drums; fast arpeggios fake chords", guards: ["<= 4 voices", "no reverb", "PolyBLEP pulses"] },
lofi: { id: "lofi", tempo: [70, 90], meters: ["4/4"], families: ["ePiano", "drums", "bass"], moods: ["nostalgic", "calm", "wistful"], master: "dense", reverb: "room", swing: [0.55, 0.62], arrangement: "4 or 8 bar loop with small variations", guards: ["no 2 consecutive identical 8-bar blocks", "master low-pass <= 9 kHz allowed"] },
lofiElectronic: { id: "lofiElectronic", tempo: [80, 100], meters: ["4/4"], families: ["pad", "pluck", "bass", "drums"], moods: ["calm", "joy", "hopeful", "nostalgic"], master: "dense", reverb: "room", swing: [0.52, 0.56], arrangement: "4-bar chord loop; sections add and remove layers (intro, groove, hook, half-time, breakdown, drop, outro); a chosen bar lands on the home chord", guards: ["no ePiano, no vinyl, no bit-crush: clean", "balance by stem RMS vs targets, not LUFS alone"] },
+ playful: { id: "playful", tempo: [100, 150], meters: ["4/4", "6/8", "2/4"], families: ["mallets", "pluck", "bass", "drums"], moods: ["playful", "joy", "curious", "mischief"], master: "gentle", reverb: "room", swing: [0.5, 0.6], arrangement: "short sections, stop-time, call and response", guards: ["a button ending"] },
+ orchestral: { id: "orchestral", tempo: [70, 140], meters: ["4/4", "3/4", "6/8"], families: ["strings", "brass", "choir", "orchPerc", "woodwind", "harp"], moods: ["heroic", "triumph", "awe", "tension", "grief"], master: "gentle", reverb: "hall", arrangement: "theme in brass or strings, ostinato engine, build to a tutti climax", guards: ["max 4 families at once outside the climax"] },
+ suspense: { id: "suspense", tempo: [50, 110], meters: ["4/4", "5/4", "3/4"], families: ["bowed", "strings", "choir", "orchPerc", "bass"], moods: ["tension", "dread", "eerie"], master: "gentle", reverb: "hall", arrangement: "drone + pulse, stingers on picture hits, withheld resolution", guards: ["ghost guard: a pulse or a motif at least every 4 bars"] },
+ rock: { id: "rock", tempo: [90, 160], meters: ["4/4", "6/8"], families: ["guitar", "bass", "drums", "organ"], moods: ["drive", "anger", "triumph", "joy"], master: "dense", reverb: "room", arrangement: "riff intro, verse, chorus, bridge, chorus; tight kit", guards: ["the riff returns"] },
+ hipHop: { id: "hipHop", tempo: [70, 100], meters: ["4/4"], families: ["drums", "bass", "piano", "strings", "pluck"], moods: ["drive", "calm", "nostalgic", "sensual", "anger"], master: "dense", reverb: "room", swing: [0.52, 0.6], arrangement: "4 or 8 bar loop, drops and switch-ups every 8 bars", guards: ["808 carries content above 500 Hz"] },
+ house: { id: "house", tempo: [118, 128], meters: ["4/4"], families: ["drums", "bass", "pad", "pluck", "organ"], moods: ["joy", "drive", "sensual", "hopeful"], master: "dense", reverb: "room", arrangement: "16-bar blocks, filter builds, breakdown, drop", guards: ["kick on every beat in the groove sections"] },
+ synthwave: { id: "synthwave", tempo: [80, 118], meters: ["4/4"], families: ["synthLead", "pad", "bass", "drums"], moods: ["nostalgic", "drive", "heroic", "romantic"], master: "dense", reverb: "hall", arrangement: "intro pad, arpeggiated bass, big gated snare, lead hook", guards: ["one lead at a time"] },
+ world: { id: "world", tempo: [60, 140], meters: ["7/8", "9/8", "12/8", "6/8", "4/4", "5/4"], families: ["pluck", "woodwind", "drums", "mallets"], moods: ["calm", "joy", "curious", "mischief", "awe"], master: "gentle", reverb: "room", arrangement: "drone + modal melody + hand percussion cycle; odd meters welcome", guards: ["name the tradition you draw on, write your own melody"] },
+ choral: { id: "choral", tempo: [50, 90], meters: ["4/4", "3/4"], families: ["choir", "organ", "strings", "fmBell"], moods: ["awe", "grief", "hopeful", "tender", "heroic"], master: "gentle", reverb: "hall", arrangement: "voices in 4 parts, chorale phrases with cadences, a swell to the last chord", guards: ["choir is harmony and texture; the line on top must still move"] },
folk: { id: "folk", tempo: [80, 120], meters: ["6/8", "3/4", "4/4"], families: ["guitar", "harp", "fmBell"], moods: ["calm", "wistful", "joy", "nostalgic"], master: "gentle", reverb: "room", arrangement: "fingerpicked pattern + lead", guards: ["strum spread 10-30 ms low to high"] },
minimalist: { id: "minimalist", tempo: [100, 140], meters: ["4/4", "12/8"], families: ["mallets", "piano"], moods: ["curious", "tension", "awe"], master: "gentle", reverb: "room", arrangement: "interlocking ostinatos; one change every 8-16 bars", guards: ["a change at least every 16 bars"] },
jazz: { id: "jazz", tempo: [90, 180], meters: ["4/4"], families: ["piano", "bass", "drums"], moods: ["playful", "nostalgic", "romantic", "curious"], master: "gentle", reverb: "room", swing: [0.6, 0.67], arrangement: "walking bass on quarters, comping off the beat", guards: ["7th chords required"] },
diff --git a/skills/anidoodle/engine/src/canvas-core/music/theory.ts b/skills/anidoodle/engine/src/canvas-core/music/theory.ts
index f20e846..d380aa3 100644
--- a/skills/anidoodle/engine/src/canvas-core/music/theory.ts
+++ b/skills/anidoodle/engine/src/canvas-core/music/theory.ts
@@ -7,7 +7,7 @@ export type Mode = { id: ModeId; intervals: number[]; color: string; use: string
// Intervals are semitones above the tonic. `color` is the degree that makes the mode read as itself.
export const MODES: Record<ModeId, Mode> = {
- major: { id: "major", intervals: [0, 2, 4, 5, 7, 9, 11], color: "3, 7", use: "joy, arrival, sunlight; the music-box default", guard: "section 7 only" },
+ major: { id: "major", intervals: [0, 2, 4, 5, 7, 9, 11], color: "3, 7", use: "joy, arrival, sunlight", guard: "section 7 only" },
aeolian: { id: "aeolian", intervals: [0, 2, 3, 5, 7, 8, 10], color: "b3, b6", use: "sadness, longing, gravity, night", guard: "tonic clarity" },
harmonicMinor: { id: "harmonicMinor", intervals: [0, 2, 3, 5, 7, 8, 11], color: "raised 7 over V", use: "drama, fate, cadences inside minor", guard: "augmented step b6-7 only as a passing figure, max 2 per phrase" },
melodicMinor: { id: "melodicMinor", intervals: [0, 2, 3, 5, 7, 9, 11], color: "raised 6 and 7", use: "hopeful minor, yearning lines that climb", guard: "rising lines only; falling lines revert to aeolian" },