From 6bcf739390842dc00f94ba1e99f2baea1b989717 Mon Sep 17 00:00:00 2001 From: Vance Ingalls Date: Thu, 13 Aug 2026 13:06:56 -0700 Subject: [PATCH] fix(studio): audition from the playhead while paused, and let an author out of a menu (#3190) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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) * 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) * 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) * 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) --- packages/core/src/audio/audioFxGraph.ts | 3 +- packages/core/src/audioFx.ts | 5 +- .../editor/propertyPanelAudioFxGroup.test.tsx | 39 +++++ .../editor/propertyPanelAudioFxGroup.tsx | 35 ++++ .../editor/propertyPanelFxPresetMenu.tsx | 17 +- .../editor/propertyPanelFxSection.test.tsx | 154 ++++++++++++++++++ .../editor/propertyPanelFxSection.tsx | 125 ++++++++++---- .../src/player/hooks/useTimelinePlayer.ts | 14 +- .../studio/src/player/store/playerStore.ts | 40 +++++ packages/studio/src/styles/studio.css | 89 ++++++++++ 10 files changed, 488 insertions(+), 33 deletions(-) diff --git a/packages/core/src/audio/audioFxGraph.ts b/packages/core/src/audio/audioFxGraph.ts index ba34c8b58..3c50ad95e 100644 --- a/packages/core/src/audio/audioFxGraph.ts +++ b/packages/core/src/audio/audioFxGraph.ts @@ -705,7 +705,8 @@ export function buildFxChain( if (!wrap) continue; wrap.wet.gain.value = run.amount; wrap.dry.gain.value = 1 - run.amount; - } // `shape` is not reassigned: the early return above already established + } + // `shape` is not reassigned: the early return above already established // that `shapeOf(next)` equals it, so recomputing was a whole normalise + // join per observer tick to write back the string that was already there. return true; diff --git a/packages/core/src/audioFx.ts b/packages/core/src/audioFx.ts index 84f48f613..0e1382864 100644 --- a/packages/core/src/audioFx.ts +++ b/packages/core/src/audioFx.ts @@ -843,10 +843,11 @@ export interface HfAudioFxNode { * the first node of each run. Absent means fully applied, which is what every * chain written before this means. */ - presetAmount?: number /** + presetAmount?: number; + /** * Set on the gain stage the leveller writes, so re-running replaces it rather * than stacking a second one — the same contract `fromCarve` has. - */; + */ fromLeveller?: boolean; /** Absent means enabled — chain files written before the field existed still load. */ enabled?: boolean; diff --git a/packages/studio/src/components/editor/propertyPanelAudioFxGroup.test.tsx b/packages/studio/src/components/editor/propertyPanelAudioFxGroup.test.tsx index 5175f2ffb..f14ec48eb 100644 --- a/packages/studio/src/components/editor/propertyPanelAudioFxGroup.test.tsx +++ b/packages/studio/src/components/editor/propertyPanelAudioFxGroup.test.tsx @@ -435,6 +435,45 @@ describe("AudioFxGroup dynamic carve", () => { * nobody asked to level, through a channel that does not persist: audible, * absent from the document, and gone on the next reload. */ + describe("auditioning starts the transport when it has to", () => { + const store = () => usePlayerStore.getState(); + + const hoverPreset = (host: HTMLElement) => { + act(() => byTextButton(host, "Presets")?.click()); + act(() => host.querySelector(".hf-fx-preset-item")?.focus()); + }; + const leaveShelf = (host: HTMLElement) => + act(() => { + host + .querySelector(".hf-fx-preset-menu") + ?.dispatchEvent(new FocusEvent("focusout", { bubbles: true })); + }); + + it("plays from the playhead, then puts it back exactly where it was", () => { + // Browsing the shelf must not cost the author their place: hovering is not + // an edit, so the playhead it borrows has to be returned. + act(() => usePlayerStore.setState({ isPlaying: false, currentTime: 42 })); + const { host } = mount({ "fx-chain": CHAIN }); + hoverPreset(host); + expect(store().playbackRequest?.playing).toBe(true); + + leaveShelf(host); + expect(store().playbackRequest?.playing).toBe(false); + expect(store().playbackRequest?.returnTo).toBe(42); + }); + + it("leaves a transport the author started alone", () => { + // Stopping their playback because they passed over a preset would be the + // panel taking a decision nobody offered it. + act(() => usePlayerStore.setState({ isPlaying: true, currentTime: 12 })); + const { host } = mount({ "fx-chain": CHAIN }); + const before = store().playbackRequest?.nonce ?? 0; + hoverPreset(host); + leaveShelf(host); + expect(store().playbackRequest?.nonce ?? 0).toBe(before); + }); + }); + it("drops a levelling measurement that lands after the pointer has gone", async () => { const { release, decoded } = stubGatedDecode(); const { host, onSetAttributeLive } = mount({ "fx-chain": CHAIN }); diff --git a/packages/studio/src/components/editor/propertyPanelAudioFxGroup.tsx b/packages/studio/src/components/editor/propertyPanelAudioFxGroup.tsx index f6c720bf6..d99d045af 100644 --- a/packages/studio/src/components/editor/propertyPanelAudioFxGroup.tsx +++ b/packages/studio/src/components/editor/propertyPanelAudioFxGroup.tsx @@ -578,6 +578,40 @@ export function AudioFxGroup({ } }; + /** + * Where the playhead was when an audition started the transport, so leaving + * can put it back. Null means this audition did not start playback — the + * transport was already running and must be left alone. + */ + const auditionReturn = useRef(null); + + /** + * Start playback for an audition, and stop it again on the way out. + * + * An audition writes the preset to the running graph, which is silent while + * the transport is paused — so a paused author hovering a preset heard + * nothing at all, and the whole affordance only worked mid-playback. Hovering + * now plays from the playhead, and leaving stops and rewinds to exactly where + * it started: browsing the shelf must not cost the author their place. + * + * Already playing, this does nothing in either direction. The author started + * that, and stopping their transport because they passed over a preset would + * be the panel taking a decision that was not offered to it. + */ + const auditionTransport = (on: boolean): void => { + const store = usePlayerStore.getState(); + if (on) { + if (store.isPlaying || auditionReturn.current !== null) return; + auditionReturn.current = store.currentTime; + store.requestPlayback(true); + return; + } + const returnTo = auditionReturn.current; + if (returnTo === null) return; + auditionReturn.current = null; + store.requestPlayback(false, returnTo); + }; + const [auditioningLevel, setAuditioningLevel] = useState(false); /** * Bumped on every enter and leave, so a measurement can tell whether the @@ -812,6 +846,7 @@ export function AudioFxGroup({ next.nodes.length ? serializeAudioFxChain(next) : null, ) } + onAuditionTransport={auditionTransport} onChainPreview={(next) => // Live writes skip the preview refresh entirely, so dragging a knob no // longer reloads the composition and restarts playback on every pixel. diff --git a/packages/studio/src/components/editor/propertyPanelFxPresetMenu.tsx b/packages/studio/src/components/editor/propertyPanelFxPresetMenu.tsx index e661024c7..257a3c28d 100644 --- a/packages/studio/src/components/editor/propertyPanelFxPresetMenu.tsx +++ b/packages/studio/src/components/editor/propertyPanelFxPresetMenu.tsx @@ -68,7 +68,8 @@ export function FxPresetMenu({ onPick, onAudition }: FxPresetMenuProps) { ))} diff --git a/packages/studio/src/components/editor/propertyPanelFxSection.test.tsx b/packages/studio/src/components/editor/propertyPanelFxSection.test.tsx index 36090f92a..d5a0b8260 100644 --- a/packages/studio/src/components/editor/propertyPanelFxSection.test.tsx +++ b/packages/studio/src/components/editor/propertyPanelFxSection.test.tsx @@ -90,6 +90,7 @@ function mount(overrides: Partial[0]> = {}) { onRemoveNodeAutomation={overrides.onRemoveNodeAutomation} onAutomatePreset={overrides.onAutomatePreset} onRemovePresetAutomation={overrides.onRemovePresetAutomation} + onAuditionTransport={overrides.onAuditionTransport} automatedPresets={overrides.automatedPresets} onLevel={overrides.onLevel} onRemoveLevel={overrides.onRemoveLevel} @@ -563,6 +564,7 @@ describe("FxSection chain", () => { expect(onRemoveNodeAutomation).toHaveBeenCalled(); }); }); + it("brackets only nodes a preset still sits next to", () => { // Pulled apart by a reorder, they are no longer a unit — and a bracket // around the gap would claim an adjacency the signal path does not have. @@ -696,6 +698,158 @@ describe("FxSection chain", () => { expect(item?.querySelector(".hf-fx-preset-name")?.textContent).toBe("Telephone"); }); + describe("auditioning while the transport is paused", () => { + it("starts playback so a paused author can hear the preset at all", () => { + // The audition is written to the running graph, which is silent while the + // transport is paused — so without this, hovering a preset did nothing + // whatsoever unless the author happened to be mid-playback. + const onAuditionTransport = vi.fn(); + const { host } = mount({ chain: chainOf("peaking"), onAuditionTransport }); + click(byText(host, "button", "Presets")); + act(() => (presetButton(host, "telephone") as HTMLElement | null)?.focus()); + expect(onAuditionTransport).toHaveBeenLastCalledWith(true); + }); + + it("stops it again on the way out", () => { + const onAuditionTransport = vi.fn(); + const { host } = mount({ chain: chainOf("peaking"), onAuditionTransport }); + click(byText(host, "button", "Presets")); + act(() => (presetButton(host, "telephone") as HTMLElement | null)?.focus()); + act(() => { + host + .querySelector(".hf-fx-preset-menu") + ?.dispatchEvent(new FocusEvent("focusout", { bubbles: true })); + }); + expect(onAuditionTransport).toHaveBeenLastCalledWith(false); + }); + + it("stops it when the preset is applied, rather than playing on", () => { + // The click means "keep this", not "and carry on playing from wherever + // the audition reached". + const onAuditionTransport = vi.fn(); + const { host } = mount({ chain: { version: 1, nodes: [] }, onAuditionTransport }); + click(byText(host, "button", "Presets")); + act(() => (presetButton(host, "telephone") as HTMLElement | null)?.focus()); + click(presetButton(host, "telephone")); + expect(onAuditionTransport).toHaveBeenLastCalledWith(false); + }); + + it("stops it if the panel goes away mid-audition", () => { + const onAuditionTransport = vi.fn(); + const { host, root } = mount({ chain: chainOf("peaking"), onAuditionTransport }); + click(byText(host, "button", "Presets")); + act(() => (presetButton(host, "telephone") as HTMLElement | null)?.focus()); + act(() => root.unmount()); + expect(onAuditionTransport).toHaveBeenLastCalledWith(false); + }); + }); + + describe("getting back out of a menu", () => { + /** Escape, from inside the section, the way a keystroke really arrives. */ + const escape = (host: HTMLElement) => + act(() => { + host + .querySelector(".hf-fx-section") + ?.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", bubbles: true })); + }); + + it("closes the preset shelf with the button that opened it", () => { + // Opening a menu used to hide both buttons, and picking something was the + // only thing that set them back — so an author who changed their mind had + // to add an effect they did not want, or deselect the clip. + const { host } = mount(); + click(byText(host, "button", "Presets")); + expect(host.querySelector(".hf-fx-preset-menu")).toBeTruthy(); + + click(byText(host, "button", "Close")); + expect(host.querySelector(".hf-fx-preset-menu")).toBeNull(); + expect(byText(host, "button", "Presets")).toBeTruthy(); + }); + + it("closes the add menu the same way", () => { + const { host } = mount(); + click(host.querySelector(".hf-fx-add")); + expect(host.querySelector(".hf-fx-add-menu")).toBeTruthy(); + + click(host.querySelector(".hf-fx-add")); + expect(host.querySelector(".hf-fx-add-menu")).toBeNull(); + expect(byText(host, "button", "Add effect")).toBeTruthy(); + }); + + it("opens one menu in place of the other", () => { + // Two open at once is two surfaces covering the rack, and neither says + // which one the next click belongs to. + const { host } = mount(); + click(byText(host, "button", "Presets")); + click(host.querySelector(".hf-fx-add")); + expect(host.querySelector(".hf-fx-add-menu")).toBeTruthy(); + expect(host.querySelector(".hf-fx-preset-menu")).toBeNull(); + + // And back the other way, which is a separate handler. + click(byText(host, "button", "Presets")); + expect(host.querySelector(".hf-fx-preset-menu")).toBeTruthy(); + expect(host.querySelector(".hf-fx-add-menu")).toBeNull(); + }); + + it("closes on Escape, which is what anyone reaches for first", () => { + const { host } = mount(); + click(byText(host, "button", "Presets")); + escape(host); + expect(host.querySelector(".hf-fx-preset-menu")).toBeNull(); + + click(host.querySelector(".hf-fx-add")); + escape(host); + expect(host.querySelector(".hf-fx-add-menu")).toBeNull(); + }); + + it("puts the chain back when a closing menu was auditioning", () => { + // Leaving the shelf by closing it is still leaving it, and an audition + // left playing is audible over a chain the document does not have. + const { host, onChainPreview } = mount({ chain: chainOf("peaking") }); + click(byText(host, "button", "Presets")); + act(() => (presetButton(host, "telephone") as HTMLElement | null)?.focus()); + click(byText(host, "button", "Close")); + + const back = onChainPreview.mock.calls.at(-1)?.[0] as HfAudioFxChain; + expect(back.nodes.map((n) => n.type)).toEqual(["peaking"]); + }); + + it("leaves Escape alone when no menu is open", () => { + // The panel has its own Escape handling; swallowing the key when this has + // nothing to close would break it. + const { host } = mount(); + let reached = false; + host.addEventListener("keydown", () => { + reached = true; + }); + escape(host); + expect(reached).toBe(true); + }); + }); + + it("shows a wave on a preset only when hovering it can be heard", () => { + // Hovering plays the preset, and playing is otherwise invisible — the panel + // looks identical whether the audition is sounding or the pointer is just + // resting there. Without an audition channel there is no audio to claim. + const { host } = mount({ chain: { version: 1, nodes: [] } }); + click(byText(host, "button", "Presets")); + expect(presetButton(host, "telephone")?.querySelector(".hf-fx-preset-wave")).toBeTruthy(); + + // Rendered directly rather than through `mount`, which supplies a preview + // handler by default — the case being covered is a section that has none. + const { host: dry } = renderInto( + , + ); + click(byText(dry, "button", "Presets")); + expect(presetButton(dry, "telephone")?.querySelector(".hf-fx-preset-wave")).toBeNull(); + }); + describe("hover-audition", () => { /** Focus is the keyboard's hover, and both go through the same handler. */ const enter = (el: Element | null | undefined) => { diff --git a/packages/studio/src/components/editor/propertyPanelFxSection.tsx b/packages/studio/src/components/editor/propertyPanelFxSection.tsx index fc0c22c1d..6853759fc 100644 --- a/packages/studio/src/components/editor/propertyPanelFxSection.tsx +++ b/packages/studio/src/components/editor/propertyPanelFxSection.tsx @@ -5,7 +5,7 @@ * is not an entry in the chain. */ -import { useCallback, useEffect, useMemo, useRef, useState } from "react"; +import { useCallback, useEffect, useMemo, useRef, useState, type KeyboardEvent } from "react"; import { defaultAudioFxParams, getAudioFxDef, @@ -68,6 +68,7 @@ const PRESET_AMOUNT_PARAM: HfAudioFxParam = { default: 1, hint: "How much of this preset is applied. Automate it to bring the whole preset in or out over time.", }; + export interface FxSectionProps { chain: HfAudioFxChain; /** Targets this track already automates, as `fx..` strings. */ @@ -110,6 +111,14 @@ export interface FxSectionProps { onAuditionLevel?(on: boolean): void; /** Whether that measurement is running, so the button can say so. */ auditioningLevel?: boolean; + /** + * Start the transport for an audition, and stop it on the way out. + * + * An audition is written to the running graph, which is silent while the + * transport is paused — so without this, hovering a preset does nothing at all + * for a paused author. + */ + onAuditionTransport?(on: boolean): void; /** Structural edits and gesture-end writes; this is the one that persists. */ onChainChange(chain: HfAudioFxChain): void; /** Continuous updates while a control is being dragged. */ @@ -155,6 +164,7 @@ export function FxSection({ onAutomatePreset, onRemovePresetAutomation, automatedPresets, + onAuditionTransport, }: FxSectionProps) { const presetAutomated = automatedPresets ?? new Set(); // Falls back to the persisting write when no preview handler is supplied, which @@ -227,12 +237,18 @@ export function FxSection({ if (make) { auditionBase.current ??= chain; onChainPreview(make(auditionBase.current)); + // After the chain is in the graph, not before: starting the transport + // first plays a moment of the un-auditioned mix. + onAuditionTransport?.(true); } else if (auditionBase.current) { + // Stop before reverting, for the mirror of that reason — the last thing + // heard should be the preset, not a frame of the chain coming back. + onAuditionTransport?.(false); onChainPreview(auditionBase.current); auditionBase.current = null; } }, - [chain, onChainPreview], + [chain, onChainPreview, onAuditionTransport], ); /** @@ -252,9 +268,14 @@ export function FxSection({ // Leaving by any route other than the pointer — the element deselected, the // panel closed — would otherwise leave the audition playing over a chain the // document does not have. + const transportRef = useRef(onAuditionTransport); + transportRef.current = onAuditionTransport; useEffect( () => () => { - if (auditionBase.current) previewRef.current?.(auditionBase.current); + if (auditionBase.current) { + transportRef.current?.(false); + previewRef.current?.(auditionBase.current); + } }, [], ); @@ -271,13 +292,14 @@ export function FxSection({ // old chain back over the write that just landed is a race the author // hears as the preset arriving and then leaving again. auditionBase.current = null; + onAuditionTransport?.(false); mutate(next.nodes); // Land on the first node the preset wrote, so the author can hear what // arrived and immediately see what it is made of. setOpenNode(next.nodes.findIndex((n) => n.fromPreset === preset.id)); setPicking(false); }, - [chain, mutate], + [chain, mutate, onAuditionTransport], ); /** @@ -321,21 +343,23 @@ export function FxSection({ const addJob = useCallback( (job: HfAudioFxJob) => { auditionBase.current = null; + onAuditionTransport?.(false); mutate(withJob(chain, job).nodes); setOpenNode(chain.nodes.length); setAdding(false); }, - [chain, mutate, withJob], + [chain, mutate, withJob, onAuditionTransport], ); const addEffect = useCallback( (type: string) => { auditionBase.current = null; + onAuditionTransport?.(false); mutate(withEffect(chain, type).nodes); setOpenNode(chain.nodes.length); setAdding(false); }, - [chain, mutate, withEffect], + [chain, mutate, withEffect, onAuditionTransport], ); const updateNode = useCallback( @@ -457,11 +481,12 @@ export function FxSection({ const addEq = useCallback(() => { auditionBase.current = null; + onAuditionTransport?.(false); const { chain: next, eqId } = addAudioEq(chain); mutate(next.nodes); setOpenEq(eqId); setAdding(false); - }, [chain, mutate]); + }, [chain, mutate, onAuditionTransport]); // Dragging a fader is heard immediately and written once on release, the same // split every other control in the rack uses. @@ -498,8 +523,34 @@ export function FxSection({ [chain.nodes, mutate], ); + /** + * Escape closes whichever menu is open. + * + * The first thing anyone reaches for, and on a surface that covers the rack it + * is the one that needs no discovering. Bound on the section rather than the + * window: a keystroke aimed at the timeline is not aimed at this. + */ + const closeMenus = useCallback( + (event: KeyboardEvent) => { + if (event.key !== "Escape" || (!adding && !picking)) return; + // Stops the panel's own Escape handling from also firing — closing a menu + // and deselecting the clip on one keystroke loses the author their place. + event.stopPropagation(); + audition(null); + onAuditionLevel?.(false); + setAdding(false); + setPicking(false); + }, + [adding, picking, audition, onAuditionLevel], + ); + return ( -
+
{/* The rack IS the signal path, and saying so costs two lines. Without them the order reads as a list, which is the one reading that makes @@ -790,26 +841,44 @@ export function FxSection({ /> ) : null} - {adding || picking ? null : ( -
- - -
- )} + {/* The buttons stay while their menu is open, and close it — an author who + opened one and changed their mind had no way back: picking something + was the only thing that set these false, so the only exits were adding + an effect they did not want or deselecting the clip. */} +
+ + +
); } diff --git a/packages/studio/src/player/hooks/useTimelinePlayer.ts b/packages/studio/src/player/hooks/useTimelinePlayer.ts index b53efd3f3..2faff57a2 100644 --- a/packages/studio/src/player/hooks/useTimelinePlayer.ts +++ b/packages/studio/src/player/hooks/useTimelinePlayer.ts @@ -389,8 +389,20 @@ export function useTimelinePlayer() { seek(state.requestedSeekTime); usePlayerStore.getState().clearSeekRequest(); } + // Play or stop from outside the loop — the FX rack auditioning a preset + // while paused, which is silent otherwise. `returnTo` puts the playhead + // back where the request found it: hovering is not an edit. + const request = state.playbackRequest; + if (request && request.nonce !== prev.playbackRequest?.nonce) { + if (request.playing) play(); + else { + pause(); + if (request.returnTo !== null) seek(request.returnTo); + } + usePlayerStore.getState().clearPlaybackRequest(); + } }); - }, [seek]); + }, [seek, play, pause]); const { playbackKeyDownRef, playbackKeyUpRef, attachIframeShortcutListeners, togglePlay } = usePlaybackKeyboard({ iframeRef, diff --git a/packages/studio/src/player/store/playerStore.ts b/packages/studio/src/player/store/playerStore.ts index 4523d8577..966a031fb 100644 --- a/packages/studio/src/player/store/playerStore.ts +++ b/packages/studio/src/player/store/playerStore.ts @@ -166,6 +166,32 @@ interface PlayerState extends KeyframeSlice, AutomationSelectionSlice, Thumbnail requestSeek: (time: number) => void; clearSeekRequest: () => void; + /** + * Request the transport start or stop from outside the player loop. + * + * The FX rack auditions a preset by writing it to the running graph, which is + * silent while the transport is paused — so hovering one has to start + * playback, and leaving has to put the playhead back where it was. Hovering is + * not an edit and must not cost the author their place. + * + * A nonce rather than a bare boolean: two hovers in a row both want play, and + * without it the second request is indistinguishable from the first having + * already been served. + */ + playbackRequest: { playing: boolean; returnTo: number | null; nonce: number } | null; + requestPlayback: (playing: boolean, returnTo?: number | null) => void; + clearPlaybackRequest: () => void; + + /** + * Request the timeline to scroll a clip into view (e.g. clicking an + * already-added asset card in the sidebar). Consumed and cleared by + * useTimelineRevealClip. The nonce makes repeat requests for the same + * clip observable so a second click re-reveals after the user scrolls away. + */ + clipRevealRequest: { elementId: string; nonce: number } | null; + requestClipReveal: (elementId: string) => void; + clearClipRevealRequest: () => void; + timelineFocus: TimelineFocusRequest | null; timelineFocusNonce: number; requestTimelineFocus: (id: string) => void; @@ -322,6 +348,20 @@ export const usePlayerStore = create((set, get) => ({ requestSeek: (time) => set({ requestedSeekTime: time }), clearSeekRequest: () => set({ requestedSeekTime: null }), + playbackRequest: null, + requestPlayback: (playing, returnTo = null) => + set((s) => ({ + playbackRequest: { playing, returnTo, nonce: (s.playbackRequest?.nonce ?? 0) + 1 }, + })), + clearPlaybackRequest: () => set({ playbackRequest: null }), + + clipRevealRequest: null, + requestClipReveal: (elementId) => + set((s) => ({ + clipRevealRequest: { elementId, nonce: (s.clipRevealRequest?.nonce ?? 0) + 1 }, + })), + clearClipRevealRequest: () => set({ clipRevealRequest: null }), + timelineFocus: null, timelineFocusNonce: 0, requestTimelineFocus: (id) => diff --git a/packages/studio/src/styles/studio.css b/packages/studio/src/styles/studio.css index 50e3a02fe..ed97c1eb6 100644 --- a/packages/studio/src/styles/studio.css +++ b/packages/studio/src/styles/studio.css @@ -469,3 +469,92 @@ body { animation: none; } } + +/* Preset shelf: the hovered row, and the wave that says it is being heard. + * + * Hovering a preset auditions it on the running audio, which is invisible — the + * panel looks identical whether the audition is playing or the pointer just + * happens to be resting there. The bars are that feedback: they run only while a + * preset is actually sounding, so they are a readout of the audio rather than a + * hover decoration. */ +.hf-fx-preset-item { + position: relative; +} + +@media (prefers-reduced-motion: no-preference) { + .hf-fx-preset-item { + transition: + background-color 120ms ease, + color 120ms ease; + } +} + +.hf-fx-preset-item:hover, +.hf-fx-preset-item:focus-visible { + /* The accent at low alpha rather than a grey: the row is lit by the thing that + is playing, and it should read as the same event as the bars. */ + background-color: rgba(60, 230, 172, 0.12); +} + +.hf-fx-preset-wave { + position: absolute; + top: 50%; + right: 0.5rem; + display: flex; + align-items: center; + gap: 2px; + height: 0.75rem; + transform: translateY(-50%); + opacity: 0; + transition: opacity 120ms ease; + pointer-events: none; +} + +.hf-fx-preset-item:hover .hf-fx-preset-wave, +.hf-fx-preset-item:focus-visible .hf-fx-preset-wave { + opacity: 1; +} + +.hf-fx-preset-wave span { + width: 2px; + height: 100%; + border-radius: 1px; + background: #3ce6ac; + transform: scaleY(0.25); + transform-origin: center; +} + +@media (prefers-reduced-motion: no-preference) { + .hf-fx-preset-wave span { + animation: hf-fx-preset-wave 900ms ease-in-out infinite; + } + /* Staggered so it reads as a waveform travelling rather than four bars + pumping in unison, which reads as a loading spinner. */ + .hf-fx-preset-wave span:nth-child(2) { + animation-delay: 150ms; + } + .hf-fx-preset-wave span:nth-child(3) { + animation-delay: 300ms; + } + .hf-fx-preset-wave span:nth-child(4) { + animation-delay: 450ms; + } +} + +/* Still visible without motion — it is telling the author something is + playing, and that fact does not go away because the bars hold still. */ +@media (prefers-reduced-motion: reduce) { + .hf-fx-preset-wave span { + transform: scaleY(0.7); + } +} + +@keyframes hf-fx-preset-wave { + 0%, + 100% { + transform: scaleY(0.25); + } + 50% { + transform: scaleY(1); + } +}