Skip to content

Commit 96fd4d0

Browse files
vanceingallsclaude
andauthored
feat(studio): two faces, and the shared frequency ruler (#3186)
* 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 31fa523 commit 96fd4d0

6 files changed

Lines changed: 322 additions & 26 deletions

File tree

packages/core/src/audioFxCopy.test.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { describe, expect, it } from "vitest";
22
import { defaultAudioFxParams, HF_AUDIO_FX } from "./audioFx.js";
33
import { HF_AUDIO_FX_PRESETS } from "./audioFxPresets.js";
4-
import { BANDS, EFFECT_COPY, PRESET_PROBLEM, SUMMARY } from "./audioFxCopy.js";
4+
import { audioBandAt, BANDS, EFFECT_COPY, PRESET_PROBLEM, SUMMARY } from "./audioFxCopy.js";
55

66
/**
77
* The copy layer is only worth having if it covers everything that ships. A gap
@@ -73,3 +73,33 @@ it("covers the spectrum without a gap or an overlap", () => {
7373
expect(BANDS[i]?.from, `gap or overlap before ${BANDS[i]?.name}`).toBe(BANDS[i - 1]?.to);
7474
}
7575
});
76+
77+
describe("audioBandAt", () => {
78+
it("names the range a frequency sits in", () => {
79+
expect(audioBandAt(50)?.name).toBe("Rumble");
80+
expect(audioBandAt(250)?.name).toBe("Mud");
81+
expect(audioBandAt(3000)?.name).toBe("Presence");
82+
expect(audioBandAt(12000)?.name).toBe("Air");
83+
});
84+
85+
it("puts a boundary in the band it opens, not the one it closes", () => {
86+
// Off by one here means a filter at exactly 250 Hz reads as "Weight" while
87+
// the ruler beside it highlights Mud.
88+
for (let i = 1; i < BANDS.length; i++) {
89+
const edge = BANDS[i]?.from;
90+
if (edge === undefined) continue;
91+
expect(audioBandAt(edge)?.name).toBe(BANDS[i]?.name);
92+
}
93+
});
94+
95+
it("clamps past both ends rather than going nameless", () => {
96+
// A filter parked at the edge of its range still has to say where it works.
97+
expect(audioBandAt(5)?.name).toBe(BANDS[0]?.name);
98+
expect(audioBandAt(30000)?.name).toBe(BANDS.at(-1)?.name);
99+
expect(audioBandAt(20000)?.name).toBe(BANDS.at(-1)?.name);
100+
});
101+
102+
it("has no answer for a value that is not a frequency", () => {
103+
expect(audioBandAt(Number.NaN)).toBeUndefined();
104+
});
105+
});

packages/core/src/audioFxCopy.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,24 @@ export const BANDS: { from: number; to: number; name: string; says: string }[] =
294294
{ from: 10000, to: 20000, name: "Air", says: "sparkle, openness" },
295295
];
296296

297+
/**
298+
* Which named range a frequency falls in.
299+
*
300+
* The whole point of `BANDS` is that the words get taught, and they only get
301+
* taught if a module can say which one it is working in. Below the first band
302+
* and above the last both clamp rather than returning nothing: 15 Hz is still
303+
* rumble to anybody who can hear it, and the alternative is a filter at the edge
304+
* of its range having no name at all.
305+
*/
306+
export function audioBandAt(hz: number): (typeof BANDS)[number] | undefined {
307+
if (!Number.isFinite(hz)) return undefined;
308+
const first = BANDS[0];
309+
const last = BANDS.at(-1);
310+
if (first && hz < first.from) return first;
311+
if (last && hz >= last.to) return last;
312+
return BANDS.find((band) => hz >= band.from && hz < band.to);
313+
}
314+
297315
/** Which everyday complaint each preset answers. Presets ARE the product here. */
298316
export const PRESET_PROBLEM: Record<string, string> = {
299317
"voice-clean": "My voice sounds amateur",

packages/studio/src/components/editor/propertyPanelAudioFxGroup.test.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,17 @@ function audioSelection(
6464
return { dataAttributes, id: "bed", element: bed } as unknown as DomEditSelection;
6565
}
6666

67+
/**
68+
* Open a module's Details, where every control that is not the primary one now
69+
* lives — a module opens on one knob and the rest is one click away.
70+
*/
71+
function openDetails(host: HTMLElement, index = 0): void {
72+
const buttons = Array.from(host.querySelectorAll<HTMLButtonElement>(".hf-fx-node-details"));
73+
const button = buttons[index];
74+
if (!button) throw new Error("no Details disclosure to open");
75+
act(() => button.click());
76+
}
77+
6778
/** A button found by the text it contains, since several now read as sentences. */
6879
function byTextButton(host: HTMLElement, text: string): HTMLButtonElement | undefined {
6980
return Array.from(host.querySelectorAll("button")).find((b) => b.textContent?.includes(text));
@@ -111,7 +122,11 @@ const writeTo = (calls: unknown[][], attr: string): unknown[] | undefined =>
111122
describe("AudioFxGroup automation", () => {
112123
it("renders the chain's parameters", () => {
113124
const { host } = mount({ "fx-chain": CHAIN });
125+
// The one knob that carries the module is on the open face; the rest are one
126+
// click away, which is what Details is.
114127
expect(rowFor(host, plainLabel("lowpass", "frequency"))).toBeTruthy();
128+
expect(rowFor(host, plainLabel("lowpass", "q"))).toBeNull();
129+
openDetails(host);
115130
expect(rowFor(host, plainLabel("lowpass", "q"))).toBeTruthy();
116131
});
117132

@@ -139,6 +154,7 @@ describe("AudioFxGroup automation", () => {
139154
lanes: [{ target: "volume", points: [{ t: 0, v: 0.5 }] }],
140155
}),
141156
});
157+
openDetails(host);
142158
act(() =>
143159
(
144160
rowFor(host, plainLabel("lowpass", "q"))!.querySelector(
@@ -164,6 +180,7 @@ describe("AudioFxGroup automation", () => {
164180
const cutoff = rowFor(host, plainLabel("lowpass", "frequency"))!;
165181
expect(cutoff.querySelector<HTMLInputElement>('input[type="range"]')?.disabled).toBe(true);
166182
expect(cutoff.hasAttribute("data-automated")).toBe(true);
183+
openDetails(host);
167184
expect(
168185
rowFor(host, plainLabel("lowpass", "q"))!.querySelector<HTMLInputElement>(
169186
'input[type="range"]',
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/**
2+
* The shared frequency ruler.
3+
*
4+
* Frequencies mean nothing to somebody who has not been taught them, and the
5+
* rack speaks entirely in them. `BANDS` names the ranges in the words the same
6+
* person would use unprompted — rumble, weight, mud, middle, presence, edge,
7+
* air — and every spectral module shows where it acts on this one ruler, so
8+
* naming them once teaches them everywhere they appear.
9+
*
10+
* Two things at once, deliberately. The bar says where this module works
11+
* relative to everything else, which is the spatial fact; the caption under it
12+
* names the range and what lives there, which is the vocabulary. A bar alone
13+
* would be decoration and a caption alone would not teach the shape.
14+
*
15+
* Log-spaced, because hearing is: 20–200 Hz is as much of the range to an ear as
16+
* 2–20 kHz, and a linear ruler would crush six of the seven bands into a corner.
17+
*/
18+
19+
import { audioBandAt, BANDS } from "@hyperframes/core/audio-fx-copy";
20+
21+
const LOW = BANDS[0]?.from ?? 20;
22+
const HIGH = BANDS.at(-1)?.to ?? 20000;
23+
24+
/** Where a frequency sits across the ruler, 0..1. */
25+
function positionOf(hz: number): number {
26+
const span = Math.log10(HIGH) - Math.log10(LOW);
27+
const at = (Math.log10(Math.min(HIGH, Math.max(LOW, hz))) - Math.log10(LOW)) / span;
28+
return Math.min(1, Math.max(0, at));
29+
}
30+
31+
export interface FxBandRulerProps {
32+
/** The range this effect can act over, from its copy. */
33+
band: readonly [number, number];
34+
/** Where it is acting right now. */
35+
at: number;
36+
}
37+
38+
export function FxBandRuler({ band, at }: FxBandRulerProps) {
39+
const here = audioBandAt(at);
40+
if (!here) return null;
41+
const [from, to] = band;
42+
return (
43+
<div className="hf-fx-ruler px-1.5 pb-1" data-band={here.name}>
44+
<div className="hf-fx-ruler-bar relative flex h-1 w-full overflow-hidden rounded-[1px]">
45+
{BANDS.map((range) => {
46+
// Reachable at all, and where it is now: a module that can only work in
47+
// the bottom three bands should not look like it could move anywhere.
48+
const reachable = range.to > from && range.from < to;
49+
return (
50+
<span
51+
key={range.name}
52+
title={`${range.name}${range.says}`}
53+
className={
54+
range.name === here.name
55+
? "hf-fx-ruler-band bg-panel-accent"
56+
: reachable
57+
? "hf-fx-ruler-band bg-panel-text-4/50"
58+
: "hf-fx-ruler-band bg-panel-text-4/15"
59+
}
60+
style={{
61+
width: `${(positionOf(range.to) - positionOf(range.from)) * 100}%`,
62+
}}
63+
/>
64+
);
65+
})}
66+
</div>
67+
<p className="hf-fx-ruler-label truncate pt-0.5 text-[9px] text-panel-text-4">
68+
<span className="hf-fx-ruler-name text-panel-text-1">{here.name}</span>{here.says}
69+
</p>
70+
</div>
71+
);
72+
}

packages/studio/src/components/editor/propertyPanelFxNodeRow.tsx

Lines changed: 104 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* with the mechanism. See `plans/audio-fx-ux/README.md` §Decided.
1111
*/
1212

13-
import { useMemo } from "react";
13+
import { useMemo, useState } from "react";
1414
import {
1515
defaultAudioFxParams,
1616
getAudioFxDef,
@@ -21,6 +21,30 @@ import {
2121
import { EFFECT_COPY, SUMMARY } from "@hyperframes/core/audio-fx-copy";
2222
import { fxAutomationTarget } from "@hyperframes/core/audio-automation";
2323
import { FxParams } from "./propertyPanelFxControls.js";
24+
import { FxBandRuler } from "./propertyPanelFxBandRuler.js";
25+
26+
/**
27+
* The one control that carries the module, if it has one.
28+
*
29+
* "Two faces": a module opens on its name, a line about what it is for, and one
30+
* knob — the rest is one click away and never in the way. Nothing is hidden; it
31+
* is ordered.
32+
*
33+
* `primary` is either a real parameter key or the string "strength", which means
34+
* the module wants a single DERIVED control over several parameters — the
35+
* `PROFILES` idea, whose figures are proposed rather than measured and which has
36+
* not shipped. Until it does, those five effects (compressor, gate, saturate,
37+
* reverb, bitcrush) open on all of their controls, which is honest: the one knob
38+
* they want does not exist yet, and inventing one would be a knob that lies.
39+
*/
40+
function primaryParamOf(def: HfAudioFxDef): string | null {
41+
const primary = EFFECT_COPY[def.id]?.primary;
42+
// "strength" names no parameter, which is exactly what makes this work: the
43+
// day `PROFILES` ships and a derived `strength` knob really is in the
44+
// registry, this starts using it without being told.
45+
if (!primary) return null;
46+
return def.params.some((p) => p.key === primary) ? primary : null;
47+
}
2448

2549
/**
2650
* The registry's definition with the plain names written over it.
@@ -250,7 +274,17 @@ export function FxNodeRow({
250274
}: FxNodeRowProps) {
251275
const registryDef = getAudioFxDef(node.type);
252276
const def = useMemo(() => (registryDef ? plainDef(registryDef) : null), [registryDef]);
253-
if (!registryDef || !def) return null;
277+
const primary = registryDef ? primaryParamOf(registryDef) : null;
278+
/** The same def cut down to the one knob, so the open face reuses every wire. */
279+
const onlyPrimary = useMemo(
280+
() => (def && primary ? { ...def, params: def.params.filter((p) => p.key === primary) } : def),
281+
[def, primary],
282+
);
283+
// Local, because nothing outside the row needs to know. Keyed by node id like
284+
// the row itself, so it stays with its effect across a reorder.
285+
const [details, setDetails] = useState(false);
286+
if (!registryDef || !def || !onlyPrimary) return null;
287+
const copy = EFFECT_COPY[node.type];
254288
const bypassed = node.enabled === false;
255289
const params = node.params ?? defaultAudioFxParams(node.type);
256290
// What this effect is doing to the sound, as a sentence. The rack is read top
@@ -285,24 +319,74 @@ export function FxNodeRow({
285319
) : null}
286320
{open ? (
287321
<>
288-
{/* The DSP name, once, where the mechanism is. An author who wants to
289-
know what "Remove Rumble" really is finds out by opening it; one who
290-
does not never has to meet the word. */}
291-
<p className="hf-fx-node-mechanism border-t border-panel-border-input px-1.5 pt-1 font-mono text-[9px] uppercase tracking-wide text-panel-text-4">
292-
Details — {registryDef.label}
293-
</p>
294-
<FxNodeParams
295-
node={node}
296-
def={def}
297-
index={index}
298-
disabled={Boolean(disabled) || bypassed}
299-
automatedTargets={automatedTargets}
300-
liveAutomationValues={liveAutomationValues}
301-
onUpdate={onUpdate}
302-
onPreview={onPreview}
303-
onAutomateParam={onAutomateParam}
304-
onRemoveParamAutomation={onRemoveParamAutomation}
305-
/>
322+
{/* What it is for, before what it is made of. */}
323+
{copy?.does ? (
324+
<p className="hf-fx-node-does border-t border-panel-border-input px-1.5 py-1 text-[10px] text-panel-text-4">
325+
{copy.does}
326+
</p>
327+
) : null}
328+
{primary && !details ? (
329+
<>
330+
<FxNodeParams
331+
node={node}
332+
def={onlyPrimary}
333+
index={index}
334+
disabled={Boolean(disabled) || bypassed}
335+
automatedTargets={automatedTargets}
336+
liveAutomationValues={liveAutomationValues}
337+
onUpdate={onUpdate}
338+
onPreview={onPreview}
339+
onAutomateParam={onAutomateParam}
340+
onRemoveParamAutomation={onRemoveParamAutomation}
341+
/>
342+
{/* What the two ends of that knob sound like. A number tells an
343+
author where the control is; this tells them which way to move
344+
it, which is the question they actually have. */}
345+
{copy?.primaryEnds ? (
346+
<p className="hf-fx-node-ends flex justify-between gap-2 px-1.5 pb-1 text-[9px] text-panel-text-4">
347+
<span className="truncate">{copy.primaryEnds.low}</span>
348+
<span className="truncate text-right">{copy.primaryEnds.high}</span>
349+
</p>
350+
) : null}
351+
{/* Where it is working, in the words the rack shares. Only for a
352+
module that acts on a range at all — there is nothing spectral
353+
about a limiter, and a ruler under one would be noise. */}
354+
{copy?.band && typeof params.frequency === "number" ? (
355+
<FxBandRuler band={copy.band} at={params.frequency} />
356+
) : null}
357+
</>
358+
) : null}
359+
{/* The DSP name lives on the disclosure, so it is read at the moment
360+
the author asks what this really is — and never before. */}
361+
{primary ? (
362+
<button
363+
type="button"
364+
className="hf-fx-node-details flex w-full items-center gap-1 border-t border-panel-border-input px-1.5 py-1 text-left font-mono text-[9px] uppercase tracking-wide text-panel-text-4 hover:text-panel-text-0"
365+
aria-expanded={details}
366+
onClick={() => setDetails((was) => !was)}
367+
>
368+
<span aria-hidden="true">{details ? "\u25BE" : "\u25B8"}</span>
369+
Details — {registryDef.label}
370+
</button>
371+
) : (
372+
<p className="hf-fx-node-mechanism border-t border-panel-border-input px-1.5 pt-1 font-mono text-[9px] uppercase tracking-wide text-panel-text-4">
373+
Details — {registryDef.label}
374+
</p>
375+
)}
376+
{details || !primary ? (
377+
<FxNodeParams
378+
node={node}
379+
def={def}
380+
index={index}
381+
disabled={Boolean(disabled) || bypassed}
382+
automatedTargets={automatedTargets}
383+
liveAutomationValues={liveAutomationValues}
384+
onUpdate={onUpdate}
385+
onPreview={onPreview}
386+
onAutomateParam={onAutomateParam}
387+
onRemoveParamAutomation={onRemoveParamAutomation}
388+
/>
389+
) : null}
306390
</>
307391
) : null}
308392
</div>

0 commit comments

Comments
 (0)