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.

notation: hit: true for a one-bar sting on any beat; lessonOwl's pings use it and write their last rests (audio bit-identical)

Alex Greenshpunfffaab406b7d
diff --git a/skills/anidoodle/engine/src/canvas-core/lessonOwlScore.ts b/skills/anidoodle/engine/src/canvas-core/lessonOwlScore.ts
index b36485e..aba6c2b 100644
--- a/skills/anidoodle/engine/src/canvas-core/lessonOwlScore.ts
+++ b/skills/anidoodle/engine/src/canvas-core/lessonOwlScore.ts
@@ -30,6 +30,7 @@ export type FoleyEvent = { t0: number; t1: number; kind: "guide" | "line" | "fil
export type OwlSoundPlan = { bpm: number; seconds: number; stepBeats: number[]; revealBeat: number; endBeat: number; foley: FoleyEvent[] };
const bar = (t: number, src: string, role: Role, v: number, roll?: number) => line(t, src, { role, v, bpb: 4, roll });
+const hit = (t: number, src: string, role: Role, v: number) => line(t, src, { role, v, bpb: 4, hit: true }); // a ping or a sting on any beat
const eighths = (names: string) => names.split(" ").map((n) => `${n}:.5`).join(" ");
type Bar = { ost: string; mel: string; bass: string };
const G: Bar = { ost: "G3 D4 G4 B4 D4 G4 B4 D4", mel: "r:.5 D5:.5 G5:.5 A5:.5 B5:1 G5:1", bass: "G2:2 D3:2" };
@@ -59,9 +60,9 @@ export const owlPiece = (sp: OwlSoundPlan): Piece => {
bass.push(...keep(bar(b, B.bass, "bass", 0.62)));
(cyc % 2 === 0 ? pl : mar).push(...keep(bar(b, B.mel, "melody", 0.8)));
}
- sp.stepBeats.forEach((b, i) => ping.push(...bar(b, `${PINGS[Math.min(i, PINGS.length - 1)]}:1`, "color", 0.62)));
+ sp.stepBeats.forEach((b, i) => ping.push(...hit(b, `${PINGS[Math.min(i, PINGS.length - 1)]}:1`, "color", 0.62)));
// da-DAH
- pl.push(...bar(cut, "[D5 F#5 A5]:.5", "melody", 0.75));
+ pl.push(...hit(cut, "[D5 F#5 A5]:.5", "melody", 0.75));
// peaks are a composing problem: the chord is rolled upward (a strum, not a slab), the bass lands an
// eighth late and the bell a sixteenth late, so no two loud attacks share a sample
mar.push(...bar(R, "[G3 D4 B4]:4", "melody", 0.64, 0.03)); pl.push(...bar(R, "[G4 D5 G5]:2 r:2", "melody", 0.78, 0.036)); // no doubled notes between the two
@@ -69,7 +70,7 @@ export const owlPiece = (sp: OwlSoundPlan): Piece => {
// end card: a rising arpeggio, then the chord rings out
const E = sp.endBeat;
ost.push(...bar(E, eighths("G3 B3 D4 G4 B4 D5 G5 B5"), "accomp", 0.5));
- mar.push(...bar(E + 4, "[G3 D4 G4 B4]:3", "melody", 0.55)); pl.push(...bar(E + 4, "G5:3", "melody", 0.5)); bass.push(...bar(E + 4, "G2:3", "bass", 0.5));
+ mar.push(...bar(E + 4, "[G3 D4 G4 B4]:3 r:1", "melody", 0.55)); pl.push(...bar(E + 4, "G5:3 r:1", "melody", 0.5)); bass.push(...bar(E + 4, "G2:3 r:1", "bass", 0.5));
const grid = { grid: true };
const parts: Part[] = [
{ id: "ostinato", inst: "marimba", role: "accomp", notes: ost, gainDb: -6, opts: grid },
diff --git a/skills/anidoodle/engine/src/canvas-core/music/plan.ts b/skills/anidoodle/engine/src/canvas-core/music/plan.ts
index 22100e2..c7fd979 100644
--- a/skills/anidoodle/engine/src/canvas-core/music/plan.ts
+++ b/skills/anidoodle/engine/src/canvas-core/music/plan.ts
@@ -40,10 +40,12 @@ export type Piece = { title: string; plan: MusicPlan; parts: Part[]; harmony: Ch
// [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.
+// barline, exactly the beats left to the next barline. A `hit` (a ping, a sting placed on any beat)
+// is one bar no longer than the meter, said out loud with `hit: true`.
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[] => {
+export const line = (start: number, src: string, o: { role: Role; v?: number; bpb: number; pickup?: number; roll?: number; kind?: string; hit?: boolean }): 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));
+ if (o.hit && bars.length !== 1) throw new Error(`a hit is one bar, got ${bars.length}: "${src}"`);
bars.forEach((bar, bi) => {
let sum = 0;
for (const tok of bar.split(/\s+(?![^\[]*\])/).filter(Boolean)) {
@@ -56,7 +58,7 @@ export const line = (start: number, src: string, o: { role: Role; v?: number; bp
t += d; sum += d;
}
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);
+ 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) || (o.hit === true && sum <= o.bpb + 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/references/music/compose.md b/skills/anidoodle/references/music/compose.md
index d1ab937..613207a 100644
--- a/skills/anidoodle/references/music/compose.md
+++ b/skills/anidoodle/references/music/compose.md
@@ -194,6 +194,7 @@ mid-bar writes its rest, `C2:3 r:1`, never a silent gap):
- Durations are in beats. In 6/8, 9/8 and 12/8 a beat is a dotted quarter, so an eighth is `1/3`.
In 7/8 a beat is a quarter, so an eighth is `.5` and a bar is 3.5.
- `@VEL` scales the line's velocity (0..1).
+- In a hand-written piece, a one-bar sting on any beat says so: `line(t, "G6:1", { ..., hit: true })`.
## Craft notes (what makes it good, not just valid)