Skip to content

Commit 9f67620

Browse files
vanceingallsclaude
andauthored
feat(core): name every preset node, and add a multi-band EQ over existing filters (#3178)
* fix(studio): pull TimelineLanes under the 600-line cap TimelineLanes.tsx hit 620 lines. Extracted the three per-clip pointer gestures (resize-start, pointer-down move-arm, click/razor-split) into createClipGestureHandlers — one factory call per rendered clip instead of ~120 lines of inline handler bodies in the render loop. 529 lines now. * fix(studio): split the extracted pointerdown handler under the CRAP threshold Moving the ~120-line gesture logic into timelineClipGestureHandlers.ts concentrated it into two functions fallow flagged (onPointerDown at CRAP 63.6, onResizeStart at 31.6). Split the decision logic (which gesture a pointerdown implies) into a pure resolvePointerDownAction, then split its own intent-blocking check into isIntentBlocked. onResizeStart's guard moved into canStartResize. Every function now scores under 30. * fix(studio): drop the unused DomEditSelection import in PropertyPanelFlat CI caught it on PR #3026 (wa-12-panel-params); a later refactor in the stack removed the last use of the type here without removing the import. * fix(studio): close the typecheck and fallow gaps wa-18b-reschedule opened useAutomationLanes.ts's write() assumed gesture-scoped coalescing and a preview-only commit that useDomEditAttributeCommits.ts never grew — backported that option support from its own later commit so the two sides of the API agree. The paste path and its tests were missing the box selection's v0/v1 bounds a sibling commit added to AutomationSelection. The FX panel's carve controls still edited the six mechanism numbers (maxCutDb, bands, intelligibilityBias) after carveProfile() collapsed authoring to one Strength knob, so those fields no longer existed on HfCarveSettings; UI now edits strength, and analyseCarveBands is called with carveProfile(strength). Also closes fallow's complexity, dead-code and duplication findings on this PR's diff: extracted automationLaneDragMath.ts (pure group/point-move math) and useAutomationRangeDrag.ts (the marquee-select gesture) out of useAutomationLaneGestures.ts, pulled a couple of render-loop ternaries and a resolver into named functions, dropped an export nothing outside its file used, and shared a step-simplifier between audioCarve's two envelope builders. The edge-stretch vs. box-select priority test in TimelineAutomationLane.test was still pinning the pre-box-select rule (edge wins over a point sitting on it) that a sibling commit deliberately reversed — a point inside the box is now selected content, so grabbing it drags the group instead. Updated the test to the shipped rule instead of the old one. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * fix(core): cap the via conic's weight so an edge-clamped via point can't NaN A via point pulled out past the segment (viaX: 5, viaY: -3) clamps to (0.999, 0.001) — exactly on the steady region's edge, where edge - viaX is 0. viaConic divided by that zero to get an infinite weight, and shapeVia turned Infinity into NaN a few steps later (Infinity - Infinity in the quadratic coefficient). NaN reaching setValueCurveAtTime silences the automated parameter for the rest of the render. Capped the weight at 1e6 instead of leaving it unbounded — past that point the arc already reads as touching the via point, so nothing visible is lost. Also hardened shapeVia's existing denominator guard (`<= 0`) to `!(> 0)`, since NaN fails the original comparison and fell through it. Review by Miga (PR #3208). * fix(studio-server): fingerprint the proactive waveform cache key too The route already keys the waveform cache on the asset's size and mtime as well as its path, so a rebuilt-in-place file gets fresh peaks instead of stale ones. generateWaveformCache — the proactive path that runs on upload — still called buildWaveformCacheKey with the path alone, so it wrote to a different key than the route reads from (making the pre-generated cache never found) and kept the exact collision bug this fingerprint exists to fix on its own path. Review by Miga (PR #3211). * style(docs): run oxfmt on the /hyperframes-audio skill docs Table column widths had drifted out of alignment with oxfmt's own rules, failing format:check and blocking the Preflight gate every downstream branch inherits. Whitespace only, no content change. * fix(core): stop \b from missing underscore-separated names, guard clipsOverlap's negative duration \b treats `_` as a word character, so \bbed\b never matched bed_01, music_bed_loop, or theme_song, and \bvo\b/\bvox\b/\btts\b had the same gap — an underscore-separated bed classified as "unknown" and could end up offered as its own carve source. Replaced the short hints with a boundary that actually excludes letters and digits on both sides. clipsOverlap computed end = start + duration without guarding sign, so a negative duration put end before start — an interval that does not describe anything, and one specific case showed it silently dropping a real overlap (a shorter, earlier broken end rejected a clip that genuinely contained the point). Duration clamps to zero instead: a clip cannot un-play time, and a zero-length clip at its start is the sane reading of "duration nobody wrote down as positive." Review by Miga (PR #3212). * fix(studio): widen PropertyPanel's resetModules render timeout again The 20s margin (already once widened for the same reason) is timing out in CI's full-monorepo Test run — the resetModules()+fresh-import render this test needs is uncached and competes with every other package's test suite for the same worker pool, and the same test passes in well under 2s standalone. Went to 45s rather than re-tuning to whatever number happens to clear the current CI load, since that number moves every time CI gains a package. * fix(studio): stop the single-candidate auto-apply carve firing twice Two auto-apply effects both fire when sourceOptions.length === 1: the multi-candidate effect only guards length === 0, so a single candidate passes it too, and the single-candidate effect passes its own guard right after — both compute the same sources list and both call setCarve, so the common case (one narrator, one bed) triggered two decodes, two FFT runs, and two concurrent attribute writes for one decision. The multi-candidate effect now defers to its sibling for exactly one candidate, which already has its own detailed handling for that case. Review by Miga (PR #3213). * feat(core): carve against every voice over a bed, always (#3212) * feat(core): carve against every voice over a bed, always dynamically A bed usually runs under a whole sequence — a narrator, an interview answer, a second presenter — and carving against one of them left the others fighting it. `source` becomes `sources`, and `mixCarveSources` sums every voice onto the BED's clock before anything is measured. That is what keeps one analysis sufficient: the chain is fixed, so there is no per-voice filter to switch between, and bands drawn from all the speech there is with envelopes that rise wherever any of it happens answer the actual question — where and when is speech masking this bed. Summed rather than averaged: two people talking at once mask more than either alone. Audio before the bed starts is dropped rather than folded in at zero, since it plays over nothing and shifting it would put a cut where there is no voice. `dynamic` is gone. A fixed depth thins the bed through every pause, and once both have been heard there is no reason to want it, so every carve follows the speech. Two helpers the panel and the headless script now share instead of each carrying a copy — two definitions of "what does this name suggest" drift, and then the two disagree about which track is the voice: - `classifyAudioName` reads a track's kind from its id and filename together. `unknown` is deliberately common: treating an unrecognised name as "not a voice" would hide the one track somebody needs to pick. - `clipsOverlap` keeps out a voice that never plays while the bed does. An unwritten duration counts as unbounded, not zero — refusing a clip whose length the composition leaves to the media would drop the commonest case there is. Files written before this still load: a single `source` reads as a one-voice list, a stored `dynamic` is ignored, and an absent attribute means the defaults whole. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * fix(core): stop \b from missing underscore-separated names, guard clipsOverlap's negative duration \b treats `_` as a word character, so \bbed\b never matched bed_01, music_bed_loop, or theme_song, and \bvo\b/\bvox\b/\btts\b had the same gap — an underscore-separated bed classified as "unknown" and could end up offered as its own carve source. Replaced the short hints with a boundary that actually excludes letters and digits on both sides. clipsOverlap computed end = start + duration without guarding sign, so a negative duration put end before start — an interval that does not describe anything, and one specific case showed it silently dropping a real overlap (a shorter, earlier broken end rejected a clip that genuinely contained the point). Duration clamps to zero instead: a clip cannot un-play time, and a zero-length clip at its start is the sane reading of "duration nobody wrote down as positive." Review by Miga (PR #3212). --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com> * fix(studio): port the carve UI off the removed source/dynamic fields #3212 (accidentally squash-merged into this branch instead of main) changed HfCarveSettings from a single `source` + `dynamic` toggle to a `sources` list with dynamic mode removed outright — the multi-voice UI consumer that goes with that shape lands in the very next PR, so this branch was left with a type that no longer matched its own code. Minimal port, not the multi-voice redesign that PR does properly: the "Listen to" picker and analyse() treat sources[0] as the one voice this UI still understands, and every dynamic-mode branch (the automated envelope lanes, the toggle, the checkbox) is gone along with the field — a carve is now always the static value the analysis computes, matching what the type change made permanent. Test suite trimmed the same way: the automation-lane and toggle tests covered behavior that no longer exists. --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 7d0d74d commit 9f67620

9 files changed

Lines changed: 617 additions & 59 deletions

File tree

packages/core/package-subpaths.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@
9898
"types": "./dist/audioFx.d.ts",
9999
"environments": ["browser", "bun", "node"]
100100
},
101+
"./audio-fx-eq": {
102+
"source": "./src/audioFxEq.ts",
103+
"runtime": "./dist/audioFxEq.js",
104+
"types": "./dist/audioFxEq.d.ts",
105+
"environments": ["browser", "bun", "node"]
106+
},
101107
"./audio-fx-presets": {
102108
"source": "./src/audioFxPresets.ts",
103109
"runtime": "./dist/audioFxPresets.js",

packages/core/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@
112112
"import": "./src/audioFx.ts",
113113
"types": "./src/audioFx.ts"
114114
},
115+
"./audio-fx-eq": {
116+
"bun": "./src/audioFxEq.ts",
117+
"node": "./dist/audioFxEq.js",
118+
"import": "./src/audioFxEq.ts",
119+
"types": "./src/audioFxEq.ts"
120+
},
115121
"./audio-fx-presets": {
116122
"bun": "./src/audioFxPresets.ts",
117123
"node": "./dist/audioFxPresets.js",
@@ -408,6 +414,10 @@
408414
"import": "./dist/audioFx.js",
409415
"types": "./dist/audioFx.d.ts"
410416
},
417+
"./audio-fx-eq": {
418+
"import": "./dist/audioFxEq.js",
419+
"types": "./dist/audioFxEq.d.ts"
420+
},
411421
"./audio-fx-presets": {
412422
"import": "./dist/audioFxPresets.js",
413423
"types": "./dist/audioFxPresets.d.ts"

packages/core/src/audioFx.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,25 @@ export interface HfAudioFxNode {
813813
* and each has to be able to find its own.
814814
*/
815815
fromPreset?: string;
816+
/**
817+
* What the rack calls this node, when the effect's own name is not specific
818+
* enough to be useful.
819+
*
820+
* A peaking filter is "Shape One Range" wherever it appears, so a chain that
821+
* cuts mud at 250 Hz and lifts clarity at 3 kHz shows the same words twice
822+
* and an author cannot tell the two apart. A preset names each node for the
823+
* JOB it is doing instead — "Reduce Mud", "Add Clarity" — and the rack reads
824+
* as a list of things that were done rather than a list of filter types.
825+
*/
826+
label?: string;
827+
/**
828+
* Id of the multi-band EQ that owns this node, when it is one of its bands.
829+
*
830+
* Same device as `fromCarve`: the module gathers its own nodes out of the
831+
* chain and presents them as one control surface, so an EQ needs no new
832+
* effect type and its bands stay ordinary filters underneath.
833+
*/
834+
fromEq?: string;
816835
/** Absent means enabled — chain files written before the field existed still load. */
817836
enabled?: boolean;
818837
params?: HfAudioFxParamValues;
@@ -862,6 +881,9 @@ export function parseAudioFxChain(json: string): HfAudioFxChain {
862881
enabled?: unknown;
863882
params?: unknown;
864883
fromCarve?: unknown;
884+
fromPreset?: unknown;
885+
label?: unknown;
886+
fromEq?: unknown;
865887
};
866888
if (typeof node.type !== "string" || !BY_ID.has(node.type)) {
867889
throw new AudioFxChainError(`Node ${i} has unknown effect type: ${String(node.type)}`);
@@ -870,6 +892,14 @@ export function parseAudioFxChain(json: string): HfAudioFxChain {
870892
type: node.type,
871893
...(typeof node.id === "string" && node.id ? { id: node.id } : {}),
872894
...(node.fromCarve === true ? { fromCarve: true as const } : {}),
895+
// Both survive the round trip or a preset stops being able to find its
896+
// own nodes after a reload: re-applying would stack a second copy and
897+
// the rack would lose the grouping it braces them with.
898+
...(typeof node.fromPreset === "string" && node.fromPreset
899+
? { fromPreset: node.fromPreset }
900+
: {}),
901+
...(typeof node.label === "string" && node.label ? { label: node.label } : {}),
902+
...(typeof node.fromEq === "string" && node.fromEq ? { fromEq: node.fromEq } : {}),
873903
enabled: node.enabled !== false,
874904
params: normalizeAudioFxParams(
875905
node.type,
@@ -893,6 +923,9 @@ export function serializeAudioFxChain(chain: HfAudioFxChain): string {
893923
type: node.type,
894924
...(node.id ? { id: node.id } : {}),
895925
...(node.fromCarve === true ? { fromCarve: true } : {}),
926+
...(node.fromPreset ? { fromPreset: node.fromPreset } : {}),
927+
...(node.label ? { label: node.label } : {}),
928+
...(node.fromEq ? { fromEq: node.fromEq } : {}),
896929
...(node.enabled === false ? { enabled: false } : {}),
897930
params: normalizeAudioFxParams(node.type, node.params),
898931
})),
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
import { describe, expect, it } from "vitest";
2+
import {
3+
HF_AUDIO_FX_CHAIN_VERSION,
4+
parseAudioFxChain,
5+
serializeAudioFxChain,
6+
type HfAudioFxChain,
7+
} from "./audioFx.js";
8+
import {
9+
addAudioEq,
10+
audioEqIds,
11+
audioEqSummary,
12+
HF_AUDIO_EQ_3,
13+
HF_AUDIO_EQ_5,
14+
HF_AUDIO_EQ_RANGE_DB,
15+
readAudioEqBands,
16+
removeAudioEq,
17+
setAudioEqBandGain,
18+
} from "./audioFxEq.js";
19+
20+
const empty = (): HfAudioFxChain => ({ version: HF_AUDIO_FX_CHAIN_VERSION, nodes: [] });
21+
22+
describe("adding an EQ", () => {
23+
it("writes one ordinary filter per band, in band order", () => {
24+
const { chain } = addAudioEq(empty());
25+
expect(chain.nodes.map((n) => n.type)).toEqual(["lowshelf", "peaking", "highshelf"]);
26+
// Ordinary nodes: an author who opens the details finds filters they could
27+
// have added by hand, not an opaque "eq" the graph has to special-case.
28+
expect(chain.nodes.every((n) => n.enabled)).toBe(true);
29+
expect(chain.nodes.map((n) => n.label)).toEqual(["Bass", "Middle", "Treble"]);
30+
});
31+
32+
it("gives every band an id, because a lane addresses effects by id", () => {
33+
const { chain } = addAudioEq(empty(), HF_AUDIO_EQ_5);
34+
const ids = chain.nodes.map((n) => n.id);
35+
expect(ids.every(Boolean)).toBe(true);
36+
expect(new Set(ids).size).toBe(ids.length);
37+
});
38+
39+
it("starts flat, so adding one changes nothing until a fader moves", () => {
40+
const { chain, eqId } = addAudioEq(empty());
41+
for (const band of readAudioEqBands(chain, eqId)) expect(band.gain).toBe(0);
42+
expect(audioEqSummary(readAudioEqBands(chain, eqId))).toMatch(/^Flat/);
43+
});
44+
45+
it("keeps two EQs apart", () => {
46+
const first = addAudioEq(empty());
47+
const second = addAudioEq(first.chain, HF_AUDIO_EQ_5);
48+
expect(second.eqId).not.toBe(first.eqId);
49+
expect(audioEqIds(second.chain)).toEqual([first.eqId, second.eqId]);
50+
expect(readAudioEqBands(second.chain, first.eqId)).toHaveLength(3);
51+
expect(readAudioEqBands(second.chain, second.eqId)).toHaveLength(5);
52+
expect(new Set(second.chain.nodes.map((n) => n.id)).size).toBe(second.chain.nodes.length);
53+
});
54+
55+
it("leaves effects that were already there alone", () => {
56+
const before: HfAudioFxChain = {
57+
version: HF_AUDIO_FX_CHAIN_VERSION,
58+
nodes: [{ type: "reverb", id: "mine", enabled: true }],
59+
};
60+
const { chain } = addAudioEq(before);
61+
expect(chain.nodes[0]?.id).toBe("mine");
62+
expect(chain.nodes).toHaveLength(4);
63+
});
64+
});
65+
66+
describe("moving a fader", () => {
67+
it("changes only that band", () => {
68+
const { chain, eqId } = addAudioEq(empty());
69+
const next = setAudioEqBandGain(chain, eqId, "Bass", 4.5);
70+
const bands = readAudioEqBands(next, eqId);
71+
expect(bands.find((b) => b.name === "Bass")?.gain).toBe(4.5);
72+
expect(bands.find((b) => b.name === "Middle")?.gain).toBe(0);
73+
expect(bands.find((b) => b.name === "Treble")?.gain).toBe(0);
74+
});
75+
76+
it("leaves the band's frequency and width alone", () => {
77+
// The fader is one control. Moving it must not quietly re-seed the rest of
78+
// the band, or an author who set a frequency by hand loses it on the next drag.
79+
const { chain, eqId } = addAudioEq(empty(), HF_AUDIO_EQ_5);
80+
const before = readAudioEqBands(chain, eqId).find((b) => b.name === "Clarity")!;
81+
const next = setAudioEqBandGain(chain, eqId, "Clarity", -3);
82+
const after = readAudioEqBands(next, eqId).find((b) => b.name === "Clarity")!;
83+
expect(after.frequency).toBe(before.frequency);
84+
expect(after.q).toBe(before.q);
85+
expect(after.gain).toBe(-3);
86+
});
87+
88+
it("holds the fader to a tone control's range, not a repair tool's", () => {
89+
// The filters themselves allow ±40 dB. A tone control that can bury a
90+
// track under 40 dB of bass is not a tone control.
91+
const { chain, eqId } = addAudioEq(empty());
92+
const hot = setAudioEqBandGain(chain, eqId, "Bass", 40);
93+
const cold = setAudioEqBandGain(chain, eqId, "Bass", -40);
94+
expect(readAudioEqBands(hot, eqId)[0]?.gain).toBe(HF_AUDIO_EQ_RANGE_DB);
95+
expect(readAudioEqBands(cold, eqId)[0]?.gain).toBe(-HF_AUDIO_EQ_RANGE_DB);
96+
});
97+
98+
it("ignores a band name that is not in this EQ", () => {
99+
const { chain, eqId } = addAudioEq(empty());
100+
const next = setAudioEqBandGain(chain, eqId, "Nonsense", 6);
101+
expect(readAudioEqBands(next, eqId).every((b) => b.gain === 0)).toBe(true);
102+
});
103+
});
104+
105+
describe("the chain is the truth", () => {
106+
it("reads a frequency the author moved by hand", () => {
107+
// The nodes are authoritative, not a cached band list: opening the details
108+
// and moving a frequency has to show up on the fader's own band.
109+
const { chain, eqId } = addAudioEq(empty());
110+
const edited: HfAudioFxChain = {
111+
...chain,
112+
nodes: chain.nodes.map((n) =>
113+
n.label === "Middle" ? { ...n, params: { ...n.params, frequency: 700 } } : n,
114+
),
115+
};
116+
expect(readAudioEqBands(edited, eqId).find((b) => b.name === "Middle")?.frequency).toBe(700);
117+
});
118+
119+
it("survives being written to an attribute and read back", () => {
120+
const { chain, eqId } = addAudioEq(empty(), HF_AUDIO_EQ_5);
121+
const moved = setAudioEqBandGain(chain, eqId, "Air", 2.5);
122+
const back = parseAudioFxChain(serializeAudioFxChain(moved));
123+
// Without fromEq surviving, the module cannot find its own bands after a
124+
// reload and the EQ silently becomes five loose filters.
125+
expect(audioEqIds(back)).toEqual([eqId]);
126+
expect(readAudioEqBands(back, eqId).map((b) => b.name)).toEqual([
127+
"Bass",
128+
"Warmth",
129+
"Middle",
130+
"Clarity",
131+
"Air",
132+
]);
133+
expect(readAudioEqBands(back, eqId).find((b) => b.name === "Air")?.gain).toBe(2.5);
134+
});
135+
136+
it("removes a whole EQ without touching anything else", () => {
137+
const before: HfAudioFxChain = {
138+
version: HF_AUDIO_FX_CHAIN_VERSION,
139+
nodes: [{ type: "reverb", id: "mine", enabled: true }],
140+
};
141+
const { chain, eqId } = addAudioEq(before);
142+
const gone = removeAudioEq(chain, eqId);
143+
expect(gone.nodes.map((n) => n.id)).toEqual(["mine"]);
144+
});
145+
});
146+
147+
describe("what it says when closed", () => {
148+
it("names only the bands that were moved", () => {
149+
const { chain, eqId } = addAudioEq(empty());
150+
const next = setAudioEqBandGain(setAudioEqBandGain(chain, eqId, "Bass", 3), eqId, "Treble", -2);
151+
expect(audioEqSummary(readAudioEqBands(next, eqId))).toBe("Bass +3, Treble −2");
152+
});
153+
154+
it("says so when nothing has been touched", () => {
155+
expect(audioEqSummary(HF_AUDIO_EQ_3)).toMatch(/^Flat/);
156+
});
157+
});

0 commit comments

Comments
 (0)