Write HTML. Render video. Built for agents.
JavaScript aiai-agentsanimationclaude-codeffmpegframeworkgsaphtmlhtml-to-videomcpmotion-graphicspuppeteerrenderingtypescriptvideo-editor
feat(core): land the plain-language layer, and test that it covers the rack (#3184)
Vance Ingalls27cdd4d5b168
diff --git a/packages/core/package-subpaths.json b/packages/core/package-subpaths.jsonindex 6ec8fb2c1b..426423cf86 100644--- a/packages/core/package-subpaths.json+++ b/packages/core/package-subpaths.json@@ -98,6 +98,12 @@"types": "./dist/audioFx.d.ts","environments": ["browser", "bun", "node"]},+ "./audio-fx-copy": {+ "source": "./src/audioFxCopy.ts",+ "runtime": "./dist/audioFxCopy.js",+ "types": "./dist/audioFxCopy.d.ts",+ "environments": ["browser", "bun", "node"]+ },"./audio-fx-eq": {"source": "./src/audioFxEq.ts","runtime": "./dist/audioFxEq.js",diff --git a/packages/core/package.json b/packages/core/package.jsonindex 19712f71ff..ea0c3cc05d 100644--- a/packages/core/package.json+++ b/packages/core/package.json@@ -112,6 +112,12 @@"import": "./src/audioFx.ts","types": "./src/audioFx.ts"},+ "./audio-fx-copy": {+ "bun": "./src/audioFxCopy.ts",+ "node": "./dist/audioFxCopy.js",+ "import": "./src/audioFxCopy.ts",+ "types": "./src/audioFxCopy.ts"+ },"./audio-fx-eq": {"bun": "./src/audioFxEq.ts","node": "./dist/audioFxEq.js",@@ -420,6 +426,10 @@"import": "./dist/audioFx.js","types": "./dist/audioFx.d.ts"},+ "./audio-fx-copy": {+ "import": "./dist/audioFxCopy.js",+ "types": "./dist/audioFxCopy.d.ts"+ },"./audio-fx-eq": {"import": "./dist/audioFxEq.js","types": "./dist/audioFxEq.d.ts"diff --git a/packages/core/src/audioFxCopy.test.ts b/packages/core/src/audioFxCopy.test.tsnew file mode 100644index 0000000000..95c9d979f2--- /dev/null+++ b/packages/core/src/audioFxCopy.test.ts@@ -0,0 +1,75 @@+import { describe, expect, it } from "vitest";+import { defaultAudioFxParams, HF_AUDIO_FX } from "./audioFx.js";+import { HF_AUDIO_FX_PRESETS } from "./audioFxPresets.js";+import { BANDS, EFFECT_COPY, PRESET_PROBLEM, SUMMARY } from "./audioFxCopy.js";++/**+ * The copy layer is only worth having if it covers everything that ships. A gap+ * is not a missing nicety — it is a rack panel labelled `highpass` in front of+ * somebody who came here to stop a hum, which is the exact failure this layer+ * exists to prevent.+ *+ * This was a build step in `plans/audio-fx-ux/build-preview.mts`, which meant it+ * only caught a gap when somebody remembered to rebuild the review page. Here it+ * catches it on the commit that adds the effect.+ */+describe("every shipped effect has plain-language copy", () => {+ for (const def of HF_AUDIO_FX) {+ it(`${def.id}`, () => {+ const copy = EFFECT_COPY[def.id];+ expect(copy, `${def.id} has no copy`).toBeDefined();+ if (!copy) return;+ for (const param of def.params) {+ expect(copy.params[param.key], `${def.id}.${param.key} has no plain name`).toBeDefined();+ }+ // "strength" is the one legal fiction: it means the module gets a single+ // derived knob and its real parameters live behind Details. Anything else+ // has to name a parameter the effect actually has, or the panel would put+ // its headline control on a knob that does not exist.+ if (copy.primary !== "strength") {+ expect(+ def.params.map((p) => p.key),+ `${def.id}'s primary "${copy.primary}" is not one of its parameters`,+ ).toContain(copy.primary);+ }+ expect(SUMMARY[def.id], `${def.id} has no closed-state summary`).toBeDefined();+ });+ }+});++it("every preset says which everyday problem it answers", () => {+ const missing = HF_AUDIO_FX_PRESETS.filter((p) => !PRESET_PROBLEM[p.id]).map((p) => p.id);+ expect(missing).toEqual([]);+});++it("describes no effect the registry does not ship", () => {+ const shipped = new Set(HF_AUDIO_FX.map((d) => d.id));+ // The other direction. Copy for an effect that has been removed or renamed is+ // dead text that reads as covered, and the count in the review page would say+ // so too.+ expect(Object.keys(EFFECT_COPY).filter((id) => !shipped.has(id))).toEqual([]);+ expect(Object.keys(SUMMARY).filter((id) => !shipped.has(id))).toEqual([]);+});++it("summarises every effect at its own defaults without throwing", () => {+ for (const def of HF_AUDIO_FX) {+ const summary = SUMMARY[def.id];+ if (!summary) continue;+ // The first thing an author reads after adding an effect, so it has to be a+ // sentence at the values it arrives with — not "undefined dB".+ const text = summary(defaultAudioFxParams(def.id));+ expect(text, `${def.id} summarised as "${text}"`).toMatch(/^[^u].*[^ ]$/);+ expect(text).not.toContain("undefined");+ expect(text).not.toContain("NaN");+ }+});++it("covers the spectrum without a gap or an overlap", () => {+ // The ruler is shared by every spectral module, so a hole in it is a frequency+ // the rack can name in one place and not in another.+ expect(BANDS[0]?.from).toBe(20);+ expect(BANDS.at(-1)?.to).toBe(20000);+ for (let i = 1; i < BANDS.length; i++) {+ expect(BANDS[i]?.from, `gap or overlap before ${BANDS[i]?.name}`).toBe(BANDS[i - 1]?.to);+ }+});diff --git a/packages/core/src/audioFxCopy.ts b/packages/core/src/audioFxCopy.tsnew file mode 100644index 0000000000..2dbcd3f4c8--- /dev/null+++ b/packages/core/src/audioFxCopy.ts@@ -0,0 +1,375 @@+/**+ * The plain-language layer over the effect registry.+ *+ * Every entry is written for somebody who has never opened a mixer. The rule+ * used throughout: name the OUTCOME, never the mechanism, and describe a control+ * by what changes in the sound rather than what it does to the signal.+ *+ * This is a layer *over* the registry, not a replacement for it. `HF_AUDIO_FX`+ * stays the authority on what an effect is and what its parameters do; this says+ * what to call those things in front of an author. `audioFxCopy.test.ts` holds+ * the two together — every shipped effect, every one of its parameters, and+ * every preset must have an entry here, so adding one to the registry without+ * copy fails a test rather than shipping a rack panel labelled `highpass`.+ *+ * Tone and the levelling module are deliberately absent: both carry their own+ * copy in core already (`audioEqSummary`, `levellingSummary`), because a summary+ * that has to read the chain belongs beside the code that writes it.+ *+ * Design rationale, and the review page built from this, in+ * `plans/audio-fx-ux/README.md`.+ */++export interface Ends {+ /** What the low end of the control sounds like. */+ low: string;+ high: string;+}++export interface ParamCopy {+ label: string;+ hint?: string;+ ends?: Ends;+}++export interface EffectCopy {+ /** What the module is called in the rack. Never the DSP name. */+ title: string;+ /** One line: what it is for. Present tense, second person implied. */+ does: string;+ /** The problem an author would say out loud that leads here. */+ reachFor: string;+ /**+ * The single control that carries the module. Either a real parameter key,+ * or "strength" — meaning the module gets one derived knob and the real+ * parameters live behind Details.+ */+ primary: string;+ primaryEnds: Ends;+ /** Plain names for the real parameters, shown only under Details. */+ params: Record<string, ParamCopy>;+ /** Which frequencies it acts on, for the shared ruler. Omit if not spectral. */+ band?: [number, number];+}++export const EFFECT_COPY: Record<string, EffectCopy> = {+ gain: {+ title: "Volume",+ does: "Turns this track up or down.",+ reachFor: "It's too loud, or too quiet, against everything else.",+ primary: "gain",+ primaryEnds: { low: "Silent", high: "Louder" },+ params: { gain: { label: "Level", ends: { low: "Silent", high: "Louder" } } },+ },+ highpass: {+ title: "Remove Rumble",+ does: "Cuts the very bottom — traffic, footsteps, air conditioning, hands on the mic.",+ reachFor: "There's a low hum or thump under everything.",+ primary: "frequency",+ primaryEnds: { low: "Only the deepest", high: "Thins the voice out" },+ band: [20, 300],+ params: {+ frequency: {+ label: "Cut below",+ hint: "Everything under this is removed.",+ ends: { low: "Only the deepest", high: "Thins the voice out" },+ },+ q: { label: "Sharpness", hint: "How abruptly the cut starts." },+ poles: { label: "Steepness", hint: "How fast it falls away below the point." },+ },+ },+ lowpass: {+ title: "Muffle",+ does: "Takes the top off, like the sound is coming through a door.",+ reachFor: "You want something to sound distant, or behind something else.",+ primary: "frequency",+ primaryEnds: { low: "Very muffled", high: "Barely changed" },+ band: [1000, 20000],+ params: {+ frequency: { label: "Cut above", ends: { low: "Very muffled", high: "Barely changed" } },+ q: { label: "Sharpness" },+ poles: { label: "Steepness" },+ },+ },+ peaking: {+ title: "Shape One Range",+ does: "Lifts or lowers one part of the sound and leaves the rest alone.",+ reachFor: "One quality is wrong — boomy, boxy, harsh — but the rest is fine.",+ primary: "gain",+ primaryEnds: { low: "Take it out", high: "Bring it forward" },+ band: [20, 20000],+ params: {+ frequency: { label: "Where", hint: "Which part of the sound to change." },+ gain: { label: "How much", ends: { low: "Take it out", high: "Bring it forward" } },+ q: {+ label: "How wide",+ hint: "A narrow setting fixes one note; a wide one changes the whole character.",+ },+ },+ },+ lowshelf: {+ title: "Bass",+ does: "More or less weight underneath everything.",+ reachFor: "It sounds thin, or too heavy.",+ primary: "gain",+ primaryEnds: { low: "Thinner", high: "Heavier" },+ band: [20, 300],+ params: {+ frequency: { label: "Up to", hint: "Everything below this is lifted or dropped." },+ gain: { label: "How much", ends: { low: "Thinner", high: "Heavier" } },+ },+ },+ highshelf: {+ title: "Brightness",+ does: "More or less sparkle at the top.",+ reachFor: "It sounds dull, or too fizzy.",+ primary: "gain",+ primaryEnds: { low: "Duller", high: "Brighter" },+ band: [2000, 20000],+ params: {+ frequency: { label: "From", hint: "Everything above this is lifted or dropped." },+ gain: { label: "How much", ends: { low: "Duller", high: "Brighter" } },+ },+ },+ compressor: {+ title: "Even Out Loudness",+ does: "Brings the quiet parts up and holds the loud parts down, so nothing jumps out at the listener.",+ reachFor: "Some words are much louder than others.",+ primary: "strength",+ primaryEnds: { low: "Barely touched", high: "Very even, quite squashed" },+ params: {+ threshold: { label: "Starts working at", hint: "Anything louder than this gets held down." },+ ratio: { label: "How hard", hint: "How much of the excess is removed." },+ attack: { label: "How fast it grabs", ends: { low: "Instant", high: "Lets peaks through" } },+ release: { label: "How fast it lets go", ends: { low: "Snappy", high: "Smooth" } },+ knee: { label: "How gradual" },+ makeup: {+ label: "Volume back up",+ hint: "Compression makes things quieter; this puts the level back.",+ },+ mix: { label: "Blend with the original" },+ },+ },+ limiter: {+ title: "Peak Ceiling",+ does: "Nothing gets louder than this, ever. A safety net at the end of the chain.",+ reachFor: "You want to be sure it never clips or spikes.",+ primary: "limit",+ primaryEnds: { low: "A lot of headroom", high: "Right up to the edge" },+ params: {+ limit: {+ label: "Never exceed",+ ends: { low: "A lot of headroom", high: "Right up to the edge" },+ },+ attack: { label: "How fast it catches" },+ release: { label: "How fast it recovers" },+ level_out: { label: "Level after" },+ },+ },+ gate: {+ title: "Silence the Gaps",+ does: "Mutes the pauses between words. Room tone under speech stays — this closes the silences, it does not remove noise.",+ reachFor: "You can hear the room breathing between sentences.",+ primary: "strength",+ primaryEnds: { low: "Only true silence", high: "Cuts quiet words too" },+ params: {+ threshold: { label: "Quieter than this is a gap" },+ range: {+ label: "How far to duck the gaps",+ hint: "Not all the way down, usually — total silence sounds broken.",+ },+ ratio: { label: "How hard" },+ attack: { label: "How fast it opens" },+ release: {+ label: "How fast it closes",+ ends: { low: "Clips word endings", high: "Leaves tails intact" },+ },+ knee: { label: "How gradual" },+ },+ },+ saturate: {+ title: "Warmth",+ does: "Adds a little grit and density, the way analogue gear does.",+ reachFor: "It sounds clean but lifeless.",+ primary: "strength",+ primaryEnds: { low: "Just a sheen", high: "Openly distorted" },+ params: {+ type: {+ label: "Character",+ hint: "Different flavours of the same idea. Tanh is the gentle one.",+ },+ threshold: {+ label: "How much drive",+ ends: { low: "Just a sheen", high: "Openly distorted" },+ },+ output: { label: "Level after", hint: "Drive makes things louder; this puts it back." },+ oversample: { label: "Quality", hint: "Higher costs more but sounds cleaner." },+ },+ },+ bitcrush: {+ title: "Lo-Fi",+ does: "Crushes the sound down to fewer steps, like an old sampler or a bad phone line.",+ reachFor: "You want it to sound cheap or digital on purpose.",+ primary: "strength",+ primaryEnds: { low: "Slightly gritty", high: "Destroyed" },+ params: {+ bits: { label: "How many steps", ends: { low: "Destroyed", high: "Clean" } },+ samples: {+ label: "How rough",+ hint: "Holds each value for longer, which dulls and grits it.",+ },+ mix: { label: "Blend with the original" },+ },+ },+ delay: {+ title: "Echo",+ does: "Repeats the sound after a gap.",+ reachFor: "You want space, or a rhythmic effect.",+ primary: "mix",+ primaryEnds: { low: "A hint", high: "Washed out" },+ params: {+ time: { label: "Gap between repeats" },+ feedback: { label: "How many repeats", ends: { low: "One", high: "Trails away for ages" } },+ mix: { label: "How loud", ends: { low: "A hint", high: "Washed out" } },+ },+ },+ reverb: {+ title: "Room",+ does: "Puts the sound somewhere, instead of nowhere.",+ reachFor: "It sounds dry and stuck to the speaker.",+ primary: "strength",+ primaryEnds: { low: "A small tight room", high: "A big open hall" },+ params: {+ size: { label: "How big the space is" },+ damping: {+ label: "How soft the walls are",+ ends: { low: "Hard and bright", high: "Soft and dark" },+ },+ wet: { label: "How much room" },+ dry: { label: "How much original" },+ },+ },+ chorus: {+ title: "Thicken",+ does: "Doubles the sound slightly out of tune, which makes it wider and less exact.",+ reachFor: "It sounds thin or too plain on its own.",+ primary: "mix",+ primaryEnds: { low: "Just wider", high: "Obviously wobbling" },+ params: {+ delay: { label: "Spread" },+ depth: { label: "How much wobble" },+ speed: { label: "How fast it wobbles" },+ mix: { label: "How much", ends: { low: "Just wider", high: "Obviously wobbling" } },+ },+ },+ phaser: {+ title: "Swirl",+ does: "A filter that sweeps up and down, giving a moving, hollow shimmer.",+ reachFor: "You want movement, or a 1970s flavour.",+ primary: "out_gain",+ primaryEnds: { low: "Subtle", high: "Strong" },+ params: {+ in_gain: { label: "Depth in" },+ out_gain: { label: "How strong", ends: { low: "Subtle", high: "Strong" } },+ delay: { label: "Where it sweeps" },+ decay: { label: "How resonant" },+ speed: { label: "How fast it sweeps" },+ type: { label: "Shape of the sweep" },+ },+ },+};++/**+ * The shared vocabulary. Frequencies mean nothing to somebody who has not been+ * taught them; these words are what the same person would say unprompted, and+ * naming the ranges once teaches them everywhere they appear.+ */+export const BANDS: { from: number; to: number; name: string; says: string }[] = [+ { from: 20, to: 80, name: "Rumble", says: "traffic, footsteps, handling" },+ { from: 80, to: 250, name: "Weight", says: "chest, body, warmth" },+ { from: 250, to: 600, name: "Mud", says: "boxy, muffled, cardboard" },+ { from: 600, to: 2000, name: "Middle", says: "the body of a voice" },+ { from: 2000, to: 5000, name: "Presence", says: "consonants, intelligibility" },+ { from: 5000, to: 10000, name: "Edge", says: "sibilance, harshness" },+ { from: 10000, to: 20000, name: "Air", says: "sparkle, openness" },+];++/** Which everyday complaint each preset answers. Presets ARE the product here. */+export const PRESET_PROBLEM: Record<string, string> = {+ "voice-clean": "My voice sounds amateur",+ "voice-broadcast": "I want it to sound like radio",+ "voice-warm": "I want it intimate and close",+ "rumble-cut": "There's a hum or thump underneath",+ "room-gate": "I can hear the room between sentences",+ "boom-tame": "My voice sounds boomy",+ "harsh-tame": "It's harsh and tiring to listen to",+ telephone: "Make it sound like a phone call",+ "radio-am": "Make it sound like an old radio",+ megaphone: "Make it sound shouted through a horn",+ "lofi-tape": "Make it sound like an old tape",+ "pa-system": "Make it sound like a station announcement",+ intercom: "Make it sound like a door intercom",+ "room-tight": "It sounds dry and stuck to the speaker",+ "room-natural": "It should sound like a real place",+ hall: "It should sound far away and big",+ "slap-echo": "I want one quick echo",+ "dub-throw": "I want long trailing echoes",+};++/**+ * What a module says when it is CLOSED.+ *+ * The most-seen state by a distance: a rack with six modules is six of these+ * and nothing else. So it is a sentence about what is happening to the sound,+ * not a dump of the parameter that happens to be first. An author should be+ * able to read the rack top to bottom and understand their own mix.+ *+ * Numbers stay in — they are what makes it checkable rather than vague — but+ * they arrive inside a phrase instead of on their own.+ */+type P = Record<string, unknown>;+const n = (v: unknown, fallback = 0) => (typeof v === "number" ? v : fallback);+const hz = (v: unknown) => {+ const x = n(v);+ return x >= 1000 ? `${(x / 1000).toFixed(x % 1000 === 0 ? 0 : 1)} kHz` : `${Math.round(x)} Hz`;+};+const strength = (x: number, words: [string, string, string]) =>+ x < 0.34 ? words[0] : x < 0.67 ? words[1] : words[2];++export const SUMMARY: Record<string, (p: P) => string> = {+ gain: (p) =>+ n(p.gain) === 0+ ? "No change"+ : n(p.gain) > 0+ ? `Up ${n(p.gain)} dB`+ : `Down ${Math.abs(n(p.gain))} dB`,+ highpass: (p) => `Cutting everything below ${hz(p.frequency)}`,+ lowpass: (p) => `Muffled above ${hz(p.frequency)}`,+ // A band at 0 dB is doing nothing, and saying "lifting by 0 dB" describes a+ // non-event as though it were a setting. Freshly added effects sit exactly+ // here, so this is the FIRST thing an author reads after adding one.+ peaking: (p) =>+ n(p.gain) === 0+ ? `Sitting on ${hz(p.frequency)}, doing nothing yet`+ : `${n(p.gain) > 0 ? "Lifting" : "Cutting"} ${hz(p.frequency)} by ${Math.abs(n(p.gain))} dB`,+ lowshelf: (p) =>+ n(p.gain) === 0+ ? "Doing nothing yet"+ : `${n(p.gain) > 0 ? "More" : "Less"} weight below ${hz(p.frequency)}`,+ highshelf: (p) =>+ n(p.gain) === 0+ ? "Doing nothing yet"+ : `${n(p.gain) > 0 ? "More" : "Less"} sparkle above ${hz(p.frequency)}`,+ compressor: (p) =>+ `Evening out — ${strength(Math.min(1, (n(p.ratio, 3) - 1) / 7), ["gentle", "moderate", "firm"])}`,+ limiter: (p) => `Nothing louder than ${n(p.limit, -1)} dB`,+ gate: (p) => `Closing gaps quieter than ${n(p.threshold, -45)} dB`,+ saturate: (p) =>+ `${strength(Math.min(1, Math.abs(n(p.threshold, -6)) / 30), ["A little", "Some", "Heavy"])} warmth`,+ bitcrush: (p) => `Crushed to ${n(p.bits, 8)} bits`,+ delay: (p) => `Echo every ${n(p.time, 250)} ms`,+ reverb: (p) =>+ `${strength(n(p.size, 0.7), ["A small", "A medium", "A large"])} room, ${strength(n(p.wet, 0.35), ["lightly", "moderately", "heavily"])}`,+ chorus: (p) => `Thickened${n(p.mix, 0.5) > 0.6 ? ", wobbling" : ""}`,+ phaser: () => "Swirling",+};