Files
hyperframes/packages/studio/src/components/editor/propertyPanelFxNodeRow.tsx
T
Vance IngallsandClaude Sonnet 5 d6c4774ef4 feat(studio): instrument the audio FX rack, including work an agent did (#3229)
* 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.

* refactor(studio): break up the FX rack's largest functions and files

Fallow flagged 9 complexity findings and 2 file-size violations after the
telemetry stack landed. Extracts FxPresetRun, FxAddMenu, FxRackChain,
FxNodeOpenBody, FxNodeParams, and useFxAudition/useFxCarve/useFxLevelling/
useFxChainObserved out of propertyPanelFxSection.tsx and
propertyPanelAudioFxGroup.tsx, splits propertyPanelFxNodeRow.tsx's open-face
rendering into its own component, and dedupes a clone in studioTelemetry.ts.
Pure structural move — no behavior change; full test suite still green.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-13 15:05:51 -07:00

340 lines
12 KiB
TypeScript

/**
* One effect in the FX rack: its header controls, and its knobs when open.
*
* An entry in the chain, as opposed to a composite module — the carve and the
* Tone EQ own several nodes each and have their own files.
*
* The row speaks the author's language, not the registry's. `EFFECT_COPY`
* supplies the name and every knob's name, `SUMMARY` the sentence under it, and
* the DSP name moves inside — it is a fact about the mechanism, so it belongs
* with the mechanism. See `plans/audio-fx-ux/README.md` §Decided.
*/
import { useMemo, useState } from "react";
import {
defaultAudioFxParams,
getAudioFxDef,
type HfAudioFxDef,
type HfAudioFxNode,
type HfAudioFxParam,
type HfAudioFxParamValues,
} from "@hyperframes/core/audio-fx";
import { EFFECT_COPY, SUMMARY } from "@hyperframes/core/audio-fx-copy";
import { trackNodeBypassed } from "./audioFxTelemetry.js";
import { getAudioFxProfile } from "@hyperframes/core/audio-fx-profiles";
import { FX_FAMILY_TYPE, fxFamilyOf, fxFamilyTint } from "./propertyPanelFxFamily.js";
import { FxNodeOpenBody } from "./propertyPanelFxNodeOpenBody.js";
/**
* The one control that carries the module, if it has one.
*
* "Two faces": a module opens on its name, a line about what it is for, and one
* knob — the rest is one click away and never in the way. Nothing is hidden; it
* is ordered.
*
* `primary` is either a real parameter key or the string "strength", which means
* the module wants a single DERIVED control over several parameters — the
* `PROFILES` idea, whose figures are proposed rather than measured and which has
* not shipped. Until it does, those five effects (compressor, gate, saturate,
* reverb, bitcrush) open on all of their controls, which is honest: the one knob
* they want does not exist yet, and inventing one would be a knob that lies.
*/
function primaryParamOf(def: HfAudioFxDef): string | null {
const primary = EFFECT_COPY[def.id]?.primary;
// "strength" names no real parameter, and for the five effects that declare it
// that is the point: their one knob is derived, and `profileRow` below builds
// it. Anything else has to be a parameter the effect actually has.
if (!primary || primary === "strength") return null;
return def.params.some((p) => p.key === primary) ? primary : null;
}
/**
* The derived knob, as a parameter the existing controls can render.
*
* A profile is not in the registry — it sets five real parameters and is none of
* them — so this fabricates the one row it needs rather than teaching `FxParams`
* about a second kind of control. 0..1 in hundredths, the same shape and the
* same feel as the carve's Strength.
*/
function profileParam(type: string): HfAudioFxParam | null {
const profile = getAudioFxProfile(type);
if (!profile) return null;
return {
kind: "number",
key: "strength",
label: profile.label,
unit: "",
min: 0,
max: 1,
step: 0.01,
default: 0.5,
hint: `Sets ${profile.derives.length} settings at once. Open Details to see where they land.`,
};
}
/**
* The registry's definition with the plain names written over it.
*
* Over rather than instead of: the registry stays the authority on range, step,
* unit and what is automatable, and only the words change. A parameter with no
* copy keeps its own label rather than disappearing — `audioFxCopy.test.ts` is
* what makes sure there is never one.
*/
function plainDef(def: HfAudioFxDef): HfAudioFxDef {
const copy = EFFECT_COPY[def.id];
if (!copy) return def;
return {
...def,
params: def.params.map((param) => {
const plain = copy.params[param.key];
if (!plain) return param;
// The registry's hint explains the mechanism, which is still the better
// tooltip than none — but the plain one wins where it exists.
return { ...param, label: plain.label, ...(plain.hint ? { hint: plain.hint } : {}) };
}),
};
}
interface FxNodeRowProps {
node: HfAudioFxNode;
index: number;
/** Where it sits in the signal path, as the rack counts it. Absent means unnumbered. */
position?: number;
automatedTargets?: ReadonlySet<string>;
liveAutomationValues?: ReadonlyMap<string, number>;
onAutomateParam?(nodeId: string, paramKey: string): void;
onRemoveParamAutomation?(nodeId: string, paramKey: string): void;
open: boolean;
/** Last in the chain, so it cannot move further down. */
last: boolean;
disabled?: boolean;
onToggleOpen(): void;
onUpdate(index: number, patch: Partial<HfAudioFxNode>): void;
onMove(index: number, delta: number): void;
onRemove(index: number): void;
onPreview(index: number, params: HfAudioFxParamValues): void;
/** What the track reads as, carried onto this row own events. */
trackKind?: string;
}
/** Reorder arrow. Disabled at the end of the chain it would move past. */
function FxMoveButton({
label,
glyph,
disabled,
onClick,
}: {
label: string;
glyph: string;
disabled: boolean;
onClick(): void;
}) {
return (
<button
type="button"
className="hf-fx-move px-1 font-mono text-[10px] text-panel-text-2 hover:text-panel-text-0 disabled:opacity-25"
title={label}
disabled={disabled}
onClick={onClick}
>
{glyph}
</button>
);
}
/** Name, bypass, reorder and remove for one effect. */
function FxNodeHeader({
label,
family,
position,
open,
bypassed,
first,
last,
disabled,
onToggleOpen,
onToggleBypass,
onMove,
onRemove,
}: {
label: string;
/** How this family letters, so the KIND reads before the word does. */
family: string;
position?: number;
open: boolean;
bypassed: boolean;
first: boolean;
last: boolean;
disabled?: boolean;
onToggleOpen(): void;
onToggleBypass(): void;
onMove(delta: number): void;
onRemove(): void;
}) {
return (
<div className="hf-fx-node-head flex min-h-7 items-center gap-1 px-1.5">
{/* Two digits, because a rack reads as a path when its steps are numbered
and as a list when they are not — and the difference decides whether an
author thinks the order matters. It does; it is audible. */}
{position !== undefined ? (
<span className="hf-fx-node-index shrink-0 font-mono text-[9px] tabular-nums text-panel-text-2">
{String(position).padStart(2, "0")}
</span>
) : null}
<button
type="button"
className={`hf-fx-node-name flex-1 truncate text-left text-[11px] text-panel-text-1 hover:text-panel-text-0 ${family}`}
aria-expanded={open}
onClick={onToggleOpen}
>
{label}
</button>
<button
type="button"
className="hf-fx-bypass rounded-[3px] border border-panel-border-input px-1.5 py-0.5 font-mono text-[9px] text-panel-text-2 hover:text-panel-text-0 disabled:opacity-40"
aria-pressed={bypassed}
title={bypassed ? "Enable" : "Bypass"}
disabled={disabled}
onClick={onToggleBypass}
>
{bypassed ? "Off" : "On"}
</button>
<FxMoveButton
label="Move up"
glyph="&uarr;"
disabled={Boolean(disabled) || first}
onClick={() => onMove(-1)}
/>
<FxMoveButton
label="Move down"
glyph="&darr;"
disabled={Boolean(disabled) || last}
onClick={() => onMove(1)}
/>
<button
type="button"
className="hf-fx-remove px-1 font-mono text-[11px] text-panel-text-2 hover:text-red-400 disabled:opacity-40"
title="Remove"
disabled={disabled}
onClick={onRemove}
>
&times;
</button>
</div>
);
}
/** One effect in the chain: its header controls, and its knobs when open. */
export function FxNodeRow({
node,
index,
position,
automatedTargets,
liveAutomationValues,
onAutomateParam,
onRemoveParamAutomation,
open,
last,
disabled,
onToggleOpen,
onUpdate,
onMove,
onRemove,
onPreview,
trackKind,
}: FxNodeRowProps) {
const registryDef = getAudioFxDef(node.type);
const def = useMemo(() => (registryDef ? plainDef(registryDef) : null), [registryDef]);
const primary = registryDef ? primaryParamOf(registryDef) : null;
/**
* The derived knob, for a module with no real parameter that can be its face.
*
* It behaves like the primary one everywhere below — one control on the open
* face, everything it sets behind Details — so the two are the same shape and
* only their source differs.
*/
const profile = getAudioFxProfile(node.type);
const derived = useMemo(() => profileParam(node.type), [node.type]);
/** The same def cut down to the one knob, so the open face reuses every wire. */
const onlyPrimary = useMemo(
() => (def && primary ? { ...def, params: def.params.filter((p) => p.key === primary) } : def),
[def, primary],
);
// Local, because nothing outside the row needs to know. Keyed by node id like
// the row itself, so it stays with its effect across a reorder.
const [details, setDetails] = useState(false);
if (!registryDef || !def || !onlyPrimary) return null;
const oneKnob = primary !== null || derived !== null;
const copy = EFFECT_COPY[node.type];
const bypassed = node.enabled === false;
const params = node.params ?? defaultAudioFxParams(node.type);
// What this effect is doing to the sound, as a sentence. The rack is read top
// to bottom far more often than any one module is opened, so this is the line
// that decides whether an author can follow their own mix.
const summary = SUMMARY[node.type]?.(params);
return (
<div
className={`hf-fx-node rounded-[4px] border border-l-2 border-panel-border-input${bypassed ? " opacity-50" : ""}`}
data-fx-node={node.type}
data-fx-family={fxFamilyOf(node)}
// The tint is on the edge rather than the text: the name already carries
// the family in its lettering, and colouring it too would fight the
// panel's own tokens for automated and bypassed.
style={{ borderLeftColor: fxFamilyTint(node) }}
>
<FxNodeHeader
family={FX_FAMILY_TYPE[fxFamilyOf(node)]}
position={position}
// The node's own job name when a preset gave it one, because that is the
// most specific truth available: a chain that cuts mud and then lifts
// clarity must not show the same name twice. Then the plain name, and
// the registry's only if an effect somehow has no copy.
label={node.label ?? EFFECT_COPY[node.type]?.title ?? registryDef.label}
open={open}
bypassed={bypassed}
first={index === 0}
last={last}
disabled={disabled}
onToggleOpen={onToggleOpen}
onToggleBypass={() => {
trackNodeBypassed(node.type, !bypassed, { trackKind });
onUpdate(index, { enabled: bypassed });
}}
onMove={(delta) => onMove(index, delta)}
onRemove={() => onRemove(index)}
/>
{summary ? (
<p className="hf-fx-node-summary truncate px-1.5 pb-1 text-[10px] text-panel-text-2">
{summary}
</p>
) : null}
{open ? (
<FxNodeOpenBody
node={node}
registryDef={registryDef}
def={def}
onlyPrimary={onlyPrimary}
primary={primary}
derived={derived}
profile={profile}
oneKnob={oneKnob}
details={details}
onToggleDetails={() => setDetails((was) => !was)}
copy={copy}
params={params}
index={index}
disabled={disabled}
bypassed={bypassed}
automatedTargets={automatedTargets}
liveAutomationValues={liveAutomationValues}
onUpdate={onUpdate}
onPreview={onPreview}
onAutomateParam={onAutomateParam}
onRemoveParamAutomation={onRemoveParamAutomation}
trackKind={trackKind}
/>
) : null}
</div>
);
}