mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-10 04:18:01 +00:00
fix(studio): the shared-row follow-ups (#3215)
* fix(core): dedupe the wet/dry mix math between delayFeedback and chorusLfo Both effect builders set wet.gain to the mix and dry.gain to its complement in identical two-line blocks; fallow kept re-flagging it as a 10-line clone on every unrelated change. Extracted setWetDryMix. * fix(core): remove the build-audio-fx-runtime.ts stray resurrected by a main merge An earlier merge with main brought this deleted file back (git's merge/delete handling on an unchanged-on-one-side file); package.json already points at build-inline-artifact.ts, so it sat unreachable and duplicating that file's config, both of which fallow flagged. * 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>
This commit is contained in:
co-authored by
Claude Opus 5
parent
9b18fa7a26
commit
df57ad4bac
@@ -1114,15 +1114,21 @@ describe("AudioFxGroup carve source list", () => {
|
||||
});
|
||||
|
||||
it("keeps the picker when the stored voice is not among the candidates", () => {
|
||||
// The stored track was renamed, or classifies as music now. Reading the one
|
||||
// remaining candidate out would quietly claim the carve listens to it.
|
||||
// The stored track is still there but no longer classifies as a voice.
|
||||
// Reading the one remaining candidate out would quietly claim the carve
|
||||
// listens to it. (A stored track that is GONE is a different case — see the
|
||||
// deleted-voice tests, which re-analyse rather than sit on a measurement of
|
||||
// something that is not there.)
|
||||
const bed = document.createElement("audio");
|
||||
bed.id = "bed";
|
||||
bed.setAttribute(
|
||||
"data-fx-carve",
|
||||
JSON.stringify({ enabled: true, sources: ["gone"], strength: 0.25 }),
|
||||
JSON.stringify({ enabled: true, sources: ["backing-music"], strength: 0.25 }),
|
||||
);
|
||||
document.body.append(bed);
|
||||
const stored = document.createElement("audio");
|
||||
stored.id = "backing-music";
|
||||
document.body.append(stored);
|
||||
const voice = document.createElement("audio");
|
||||
voice.id = "narration";
|
||||
document.body.append(voice);
|
||||
@@ -1136,7 +1142,7 @@ describe("AudioFxGroup carve source list", () => {
|
||||
dataAttributes: {
|
||||
"fx-carve": JSON.stringify({
|
||||
enabled: true,
|
||||
sources: ["gone"],
|
||||
sources: ["backing-music"],
|
||||
strength: 0.25,
|
||||
}),
|
||||
},
|
||||
@@ -1310,3 +1316,154 @@ describe("AudioFxGroup carve across tracks", () => {
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* The filters and envelopes a carve produces are a MEASUREMENT of specific
|
||||
* tracks. Delete one and they describe something nobody can hear any more — the
|
||||
* bed keeps ducking for a voice that is gone.
|
||||
*/
|
||||
describe("AudioFxGroup carve against a deleted voice", () => {
|
||||
const CARVED_CHAIN = JSON.stringify({
|
||||
version: 1,
|
||||
nodes: [
|
||||
{ type: "peaking", id: "c1", enabled: true, fromCarve: true, params: { frequency: 1000 } },
|
||||
{ type: "lowpass", id: "k1", enabled: true, params: { frequency: 8000 } },
|
||||
],
|
||||
});
|
||||
const CARVED_AUTOMATION = JSON.stringify({
|
||||
version: 1,
|
||||
lanes: [
|
||||
{ target: "fx.c1.gain", points: [{ t: 0, v: -6 }] },
|
||||
{ target: "fx.k1.frequency", points: [{ t: 0, v: 8000 }] },
|
||||
],
|
||||
});
|
||||
|
||||
/**
|
||||
* A bed carving against `sources`, with only `present` still in the composition.
|
||||
*
|
||||
* The timeline is what says a track is gone — not the preview DOM, which keeps
|
||||
* a deleted element around — so the store is seeded and the document is left
|
||||
* holding every track, which is exactly the mismatch the studio produces.
|
||||
*/
|
||||
function mountCarved(sources: string[], present: string[]) {
|
||||
const carve = JSON.stringify({ enabled: true, sources, strength: 0.25 });
|
||||
const bed = document.createElement("audio");
|
||||
bed.id = "bed";
|
||||
document.body.append(bed);
|
||||
for (const id of new Set([...sources, ...present])) {
|
||||
const el = document.createElement("audio");
|
||||
el.id = id;
|
||||
document.body.append(el);
|
||||
}
|
||||
usePlayerStore.setState({
|
||||
elements: [
|
||||
{ id: "bed", tag: "audio", start: 0, duration: 10, track: 0 },
|
||||
...present.map((id) => ({ id, tag: "audio", start: 0, duration: 10, track: 1 })),
|
||||
] as never,
|
||||
});
|
||||
const onSetAttributeQuiet = vi.fn();
|
||||
const host = document.createElement("div");
|
||||
document.body.append(host);
|
||||
act(() => {
|
||||
createRoot(host).render(
|
||||
<AudioFxGroup
|
||||
element={
|
||||
{
|
||||
dataAttributes: {
|
||||
"fx-carve": carve,
|
||||
"fx-chain": CARVED_CHAIN,
|
||||
automation: CARVED_AUTOMATION,
|
||||
},
|
||||
id: "bed",
|
||||
element: bed,
|
||||
} as unknown as DomEditSelection
|
||||
}
|
||||
onSetAttributeQuiet={onSetAttributeQuiet}
|
||||
onSetAttributeLive={vi.fn()}
|
||||
/>,
|
||||
);
|
||||
});
|
||||
return { host, onSetAttributeQuiet };
|
||||
}
|
||||
|
||||
it("re-analyses against the voices that are left", () => {
|
||||
// Two voices were measured together into one set of bands. With one gone that
|
||||
// set answers a question nobody asked; the survivor has to be measured again.
|
||||
const { onSetAttributeQuiet } = mountCarved(["narration", "guest"], ["narration"]);
|
||||
const write = writeTo(onSetAttributeQuiet.mock.calls, "data-fx-carve");
|
||||
expect(JSON.parse(String(write![1]))).toMatchObject({
|
||||
enabled: true,
|
||||
sources: ["narration"],
|
||||
});
|
||||
});
|
||||
|
||||
it("leaves a carve alone while every voice it names is still there", () => {
|
||||
const { onSetAttributeQuiet } = mountCarved(["narration", "guest"], ["narration", "guest"]);
|
||||
expect(onSetAttributeQuiet.mock.calls.some((c) => c[0] === "data-fx-carve")).toBe(false);
|
||||
});
|
||||
|
||||
it("does not fall back to carving against an effect when no voice is left", async () => {
|
||||
// Found in the studio, not here: deleting the narration emptied the source
|
||||
// list, and the panel filled it again with the only audio in the composition
|
||||
// — a 200 ms explosion. The picker's fallback (offer everything rather than
|
||||
// hide the track somebody needs) is for the AUTHOR to choose from. The panel
|
||||
// choosing off it is the panel deciding, and that is never the answer.
|
||||
const carve = JSON.stringify({ enabled: true, sources: [], strength: 0.25 });
|
||||
const bed = document.createElement("audio");
|
||||
bed.id = "bed";
|
||||
bed.setAttribute("data-fx-carve", carve);
|
||||
document.body.append(bed);
|
||||
const sfx = document.createElement("audio");
|
||||
sfx.id = "sfx-explosion";
|
||||
document.body.append(sfx);
|
||||
const onSetAttributeQuiet = vi.fn();
|
||||
const host = document.createElement("div");
|
||||
document.body.append(host);
|
||||
act(() => {
|
||||
createRoot(host).render(
|
||||
<AudioFxGroup
|
||||
element={
|
||||
{
|
||||
dataAttributes: { "fx-carve": carve },
|
||||
id: "bed",
|
||||
element: bed,
|
||||
} as unknown as DomEditSelection
|
||||
}
|
||||
onSetAttributeQuiet={onSetAttributeQuiet}
|
||||
onSetAttributeLive={vi.fn()}
|
||||
/>,
|
||||
);
|
||||
});
|
||||
await act(async () => {});
|
||||
// Nothing written: the carve waits rather than picking the explosion.
|
||||
expect(onSetAttributeQuiet.mock.calls.some((c) => c[0] === "data-fx-carve")).toBe(false);
|
||||
// Still offered, so the author can say "actually, listen to that one".
|
||||
expect(
|
||||
Array.from(host.querySelectorAll("[data-carve-source]")).map((e) =>
|
||||
e.getAttribute("data-carve-source"),
|
||||
),
|
||||
).toEqual(["sfx-explosion"]);
|
||||
});
|
||||
|
||||
it("drops what it generated when the last voice goes and none is left to pick", async () => {
|
||||
// Staying on with nothing to listen to is honest — a voice may come back, and
|
||||
// "off" is a different thing the author chose. What cannot stay is the output:
|
||||
// those filters and that envelope are making room for nobody.
|
||||
const { onSetAttributeQuiet } = mountCarved(["narration"], []);
|
||||
// The three writes are sequenced, not fired together: each is a
|
||||
// read-modify-write against the same file, so the carve write lands only
|
||||
// after the two that strip its output.
|
||||
await act(async () => {});
|
||||
const carve = writeTo(onSetAttributeQuiet.mock.calls, "data-fx-carve");
|
||||
expect(JSON.parse(String(carve![1]))).toMatchObject({ enabled: true, sources: [] });
|
||||
|
||||
const chain = writeTo(onSetAttributeQuiet.mock.calls, "data-fx-chain");
|
||||
// The hand-added low-pass survives; only what the carve minted goes.
|
||||
expect(JSON.parse(String(chain![1])).nodes.map((n: { id: string }) => n.id)).toEqual(["k1"]);
|
||||
|
||||
const automation = writeTo(onSetAttributeQuiet.mock.calls, "data-automation");
|
||||
expect(
|
||||
JSON.parse(String(automation![1])).lanes.map((l: { target: string }) => l.target),
|
||||
).toEqual(["fx.k1.frequency"]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -48,6 +48,7 @@ import {
|
||||
} from "./propertyPanelAutomation";
|
||||
import type { DomEditSelection } from "./domEditingTypes";
|
||||
import { useLivePlayheadTime } from "../../hooks/useLivePlayheadTime";
|
||||
import { usePlayerStore } from "../../player";
|
||||
|
||||
/**
|
||||
* Rate the carve source is decoded at. Analysis is self-consistent because it
|
||||
@@ -199,10 +200,12 @@ export function AudioFxGroup({
|
||||
* commit, which does not exist yet.
|
||||
*/
|
||||
const setCarve = async (next: HfCarveSettings | null): Promise<void> => {
|
||||
// Envelopes the carve wrote outlive it otherwise, and an automated gain
|
||||
// ignores the panel's own depth — so switching dynamic off would leave the
|
||||
// filters still following the voice with nothing saying they do.
|
||||
if (!next?.enabled) {
|
||||
// What the carve generated is only justified by the voices it was measured
|
||||
// from: switched off, or left naming none — every source deleted, say —
|
||||
// there is nothing those filters are making room for. Left behind they keep
|
||||
// dipping the bed with nothing in the panel to explain them.
|
||||
const generatedOutputStands = Boolean(next?.enabled) && (next?.sources.length ?? 0) > 0;
|
||||
if (!generatedOutputStands) {
|
||||
const carriedOver = withoutCarveLanes(automation, chain);
|
||||
if (carriedOver.lanes.length !== automation.lanes.length) {
|
||||
await onSetAttributeQuiet(
|
||||
@@ -211,7 +214,7 @@ export function AudioFxGroup({
|
||||
);
|
||||
}
|
||||
}
|
||||
if (!next?.enabled) {
|
||||
if (!generatedOutputStands) {
|
||||
const kept = chain.nodes.filter((n) => !n.fromCarve);
|
||||
if (kept.length !== chain.nodes.length) {
|
||||
await onSetAttributeQuiet(
|
||||
@@ -300,9 +303,12 @@ export function AudioFxGroup({
|
||||
* first, and if filtering would leave nothing at all every track comes back. A
|
||||
* picker that hides the track somebody needs is worse than a long one.
|
||||
*/
|
||||
const sourceOptions: AudioTrackOption[] = (() => {
|
||||
const { sourceOptions, autoSourceIds } = ((): {
|
||||
sourceOptions: AudioTrackOption[];
|
||||
autoSourceIds: string[];
|
||||
} => {
|
||||
const doc = element.element?.ownerDocument;
|
||||
if (!doc) return [];
|
||||
if (!doc) return { sourceOptions: [], autoSourceIds: [] };
|
||||
const others = Array.from(doc.querySelectorAll<HTMLAudioElement>("audio[id]")).filter(
|
||||
(a) => a.id !== element.id,
|
||||
);
|
||||
@@ -324,11 +330,75 @@ export function AudioFxGroup({
|
||||
}));
|
||||
const plausible = described.filter((t) => t.kind === "voice" || t.kind === "unknown");
|
||||
const offered = plausible.length > 0 ? plausible : described;
|
||||
return offered
|
||||
.sort((a, b) => (a.kind === "voice" ? 0 : 1) - (b.kind === "voice" ? 0 : 1))
|
||||
.map(({ id, label }) => ({ id, label }));
|
||||
const byVoiceFirst = (list: typeof described) =>
|
||||
[...list].sort((a, b) => (a.kind === "voice" ? 0 : 1) - (b.kind === "voice" ? 0 : 1));
|
||||
return {
|
||||
sourceOptions: byVoiceFirst(offered).map(({ id, label }) => ({ id, label })),
|
||||
// What the panel may pick WITHOUT being asked — never the fallback. The
|
||||
// fallback exists so the picker can still show a track whose name reads as
|
||||
// music or as an effect, because a name is a hint and the author may know
|
||||
// better. Choosing off that list is a different act: it is the panel
|
||||
// deciding, and "the only audio left is a 200 ms explosion" is not a voice
|
||||
// to make room for. A bed surrounded by nothing plausible waits instead.
|
||||
autoSourceIds: byVoiceFirst(plausible).map((t) => t.id),
|
||||
};
|
||||
})();
|
||||
|
||||
/**
|
||||
* The voices this carve names that are still in the composition.
|
||||
*
|
||||
* Existence, not the candidate list: a voice can stop being offered without
|
||||
* being gone (it stopped overlapping the bed), and dropping it then would
|
||||
* quietly rewrite a relationship the author set. Deleted is the case that has
|
||||
* to be noticed, because what the carve produced was measured from that track.
|
||||
*
|
||||
* Asked of the timeline rather than of `element.element.ownerDocument`, which
|
||||
* is the preview's DOM and outlives a delete: measured in the studio, a bed
|
||||
* selected right after its voice was deleted still found that voice through
|
||||
* the document, so the carve sat on a measurement of a track the timeline had
|
||||
* already dropped. The store is what the delete actually edited.
|
||||
*/
|
||||
const timelineElements = usePlayerStore((s) => s.elements);
|
||||
const survivingSources = ((): string[] => {
|
||||
if (!carve) return [];
|
||||
const present = new Set(timelineElements.map((el) => el.domId ?? el.id));
|
||||
// Absence only means deletion once the timeline is known to describe THIS
|
||||
// composition, and the bed being in it is the proof. Without that check a
|
||||
// store that is empty — not loaded yet, or a panel mounted outside the
|
||||
// player — reads as "every voice was deleted" and throws away a carve that
|
||||
// is perfectly fine. Unchanged sources are what the prune treats as nothing
|
||||
// to do.
|
||||
if (!element.id || !present.has(element.id)) return carve.sources;
|
||||
return carve.sources.filter((id) => present.has(id));
|
||||
})();
|
||||
|
||||
/**
|
||||
* A deleted voice re-analyses the bed.
|
||||
*
|
||||
* The filters and envelopes are a measurement of specific tracks, so losing one
|
||||
* makes them a measurement of something that is no longer there — the bed keeps
|
||||
* ducking for a voice nobody can hear. `analyse` already skips a source it
|
||||
* cannot find, but nothing asked it to run again.
|
||||
*
|
||||
* Pruning is the whole trigger: `setCarve` re-analyses when the source list
|
||||
* changes, so the surviving voices are re-measured together. Losing the LAST
|
||||
* one leaves an empty list, which the effects below repoint at whatever
|
||||
* candidates remain — and if there are none, `setCarve` drops what the carve
|
||||
* generated, since there is nothing left it could be making room for.
|
||||
*
|
||||
* Keyed on the survivors rather than on the candidates: a voice that had
|
||||
* stopped overlapping was never in the candidate list, so its deletion would
|
||||
* not change that identity and this would never fire.
|
||||
*/
|
||||
useEffect(() => {
|
||||
if (carvedAgainstBy || !carve?.enabled) return;
|
||||
if (survivingSources.length === carve.sources.length) return;
|
||||
void setCarve({ ...carve, sources: survivingSources });
|
||||
// Keyed on the identity of the decision, not on setCarve — which is rebuilt
|
||||
// every render and would re-fire this.
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [carve, carvedAgainstBy, survivingSources.join(" ")]);
|
||||
|
||||
/**
|
||||
* A bed with voices above it carves itself.
|
||||
*
|
||||
@@ -346,14 +416,14 @@ export function AudioFxGroup({
|
||||
* off stores `enabled: false`, which is also a configured carve. That is the whole
|
||||
* reason the flag exists rather than "off" being an absent attribute.
|
||||
*/
|
||||
const candidateIds = sourceOptions.map((o) => o.id).join("\u0000");
|
||||
const candidateIds = autoSourceIds.join("\u0000");
|
||||
useEffect(() => {
|
||||
// Exactly one candidate is the sibling effect's case below, not this one's:
|
||||
// both guards passing for a single candidate fired two setCarve calls with
|
||||
// the same result — two decodes, two FFT runs, two concurrent attribute
|
||||
// writes.
|
||||
if (carvedAgainstBy || sourceOptions.length <= 1) return;
|
||||
const all = sourceOptions.map((o) => o.id);
|
||||
if (carvedAgainstBy || autoSourceIds.length <= 1) return;
|
||||
const all = autoSourceIds;
|
||||
// Nothing configured: the default carve, pointed at everything it could hear.
|
||||
if (carve === null) {
|
||||
void setCarve({ ...DEFAULT_CARVE, sources: all });
|
||||
@@ -387,24 +457,23 @@ export function AudioFxGroup({
|
||||
* reason the flag exists rather than "off" being an absent attribute.
|
||||
*/
|
||||
useEffect(() => {
|
||||
if (carvedAgainstBy || sourceOptions.length !== 1) return;
|
||||
const only = sourceOptions[0];
|
||||
if (carvedAgainstBy || autoSourceIds.length !== 1) return;
|
||||
const only = autoSourceIds[0];
|
||||
if (!only) return;
|
||||
// Nothing configured: the default carve, pointed at the one candidate.
|
||||
if (carve === null) {
|
||||
void setCarve({ ...DEFAULT_CARVE, sources: [only.id] });
|
||||
void setCarve({ ...DEFAULT_CARVE, sources: [only] });
|
||||
return;
|
||||
}
|
||||
// Configured but with no voice yet — a carve switched on before there was
|
||||
// anything to listen to, or one whose source was cleared. The panel reads the
|
||||
// sole candidate out as the source, so it has to be the stored one too;
|
||||
// otherwise the card claims a relationship the attribute does not record.
|
||||
if (carve.enabled && carve.sources.length === 0)
|
||||
void setCarve({ ...carve, sources: [only.id] });
|
||||
if (carve.enabled && carve.sources.length === 0) void setCarve({ ...carve, sources: [only] });
|
||||
// Deliberately keyed on the identity of the decision, not on setCarve — which
|
||||
// is rebuilt every render and would re-fire this.
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [carve, carvedAgainstBy, sourceOptions.length, sourceOptions[0]?.id]);
|
||||
}, [carve, carvedAgainstBy, autoSourceIds.length, autoSourceIds[0]]);
|
||||
|
||||
const [analysing, setAnalysing] = useState(false);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user