diff --git a/packages/core/package-subpaths.json b/packages/core/package-subpaths.json index 115fc1cbc9..ff5e739d88 100644 --- a/packages/core/package-subpaths.json +++ b/packages/core/package-subpaths.json @@ -92,6 +92,12 @@ "types": "./dist/audioFx.d.ts", "environments": ["browser", "bun", "node"] }, + "./audio-fx-presets": { + "source": "./src/audioFxPresets.ts", + "runtime": "./dist/audioFxPresets.js", + "types": "./dist/audioFxPresets.d.ts", + "environments": ["browser", "bun", "node"] + }, "./audio-fx-tail": { "source": "./src/audio/audioFxTail.ts", "runtime": "./dist/audio/audioFxTail.js", diff --git a/packages/core/package.json b/packages/core/package.json index 29f6a2a87d..c4f5e16cc4 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -106,6 +106,12 @@ "import": "./src/audioFx.ts", "types": "./src/audioFx.ts" }, + "./audio-fx-presets": { + "bun": "./src/audioFxPresets.ts", + "node": "./dist/audioFxPresets.js", + "import": "./src/audioFxPresets.ts", + "types": "./src/audioFxPresets.ts" + }, "./audio-fx-tail": { "bun": "./src/audio/audioFxTail.ts", "node": "./dist/audio/audioFxTail.js", @@ -392,6 +398,10 @@ "import": "./dist/audioFx.js", "types": "./dist/audioFx.d.ts" }, + "./audio-fx-presets": { + "import": "./dist/audioFxPresets.js", + "types": "./dist/audioFxPresets.d.ts" + }, "./audio-fx-tail": { "import": "./dist/audio/audioFxTail.js", "types": "./dist/audio/audioFxTail.d.ts" diff --git a/packages/studio/src/components/editor/propertyPanelFxPresetMenu.tsx b/packages/studio/src/components/editor/propertyPanelFxPresetMenu.tsx new file mode 100644 index 0000000000..f841968a8b --- /dev/null +++ b/packages/studio/src/components/editor/propertyPanelFxPresetMenu.tsx @@ -0,0 +1,61 @@ +/** + * The preset shelf for the FX rack. + * + * Its own module rather than another block inside the section: the section is + * already the largest file in the panel, and this surface is going to grow — + * search, per-item descriptions and a preview of the chain each preset draws + * are all queued behind it. + */ + +import { + audioFxPresetsByFamily, + HF_AUDIO_FX_PRESET_FAMILIES, + type HfAudioFxPresetFamily, +} from "@hyperframes/core/audio-fx-presets"; + +/** + * Shelf names in the author's language, which is deliberately not the effect + * registry's grouping. `group` says what an effect *is* (filter, dynamics); + * somebody reaching for Telephone is shopping for what they *want*, and + * Telephone is filters and saturation — nobody looks for it under either. + */ +const FAMILY_LABEL: Record = { + voice: "Voice", + repair: "Fix", + character: "Character", + space: "Space", +}; + +export interface FxPresetMenuProps { + onPick(id: string): void; +} + +export function FxPresetMenu({ onPick }: FxPresetMenuProps) { + return ( +
+ {HF_AUDIO_FX_PRESET_FAMILIES.map((family) => ( +
+ + {FAMILY_LABEL[family]} + + {audioFxPresetsByFamily(family).map((preset) => ( + + ))} +
+ ))} +
+ ); +} diff --git a/packages/studio/src/components/editor/propertyPanelFxSection.test.tsx b/packages/studio/src/components/editor/propertyPanelFxSection.test.tsx index c6a35307f7..8e1e6b1938 100644 --- a/packages/studio/src/components/editor/propertyPanelFxSection.test.tsx +++ b/packages/studio/src/components/editor/propertyPanelFxSection.test.tsx @@ -212,6 +212,44 @@ describe("FxSection chain", () => { expect(openFrequency().value).toBe("1600"); }); + it("applies a preset as ordinary nodes, tagged with where they came from", () => { + const { host, onChainChange } = mount({ chain: { version: 1, nodes: [] } }); + click(byText(host, "button", "Presets")); + click(byText(host, "button", "Telephone")); + + const next = onChainChange.mock.calls[0]![0] as HfAudioFxChain; + // The band, its honk and de-mud shaping, and the soft clip — a chain the + // author can now see and edit, not an opaque "telephone" setting. + expect(next.nodes.map((n) => n.type)).toEqual([ + "highpass", + "highpass", + "lowpass", + "lowpass", + "peaking", + "peaking", + "saturate", + ]); + expect(next.nodes.every((n) => n.fromPreset === "telephone")).toBe(true); + // Every node needs an id or its parameters can never be automated. + expect(new Set(next.nodes.map((n) => n.id)).size).toBe(next.nodes.length); + }); + + it("adds a preset to what is already there rather than replacing it", () => { + const existing: HfAudioFxChain = { + version: 1, + nodes: [ + { type: "reverb", id: "mine", enabled: true, params: defaultAudioFxParams("reverb") }, + ], + }; + const { host, onChainChange } = mount({ chain: existing }); + click(byText(host, "button", "Presets")); + click(byText(host, "button", "Cut Rumble")); + + const next = onChainChange.mock.calls[0]![0] as HfAudioFxChain; + expect(next.nodes.map((n) => n.id)).toContain("mine"); + expect(next.nodes.map((n) => n.type)).toEqual(["reverb", "highpass"]); + }); + it("cannot move the ends past themselves", () => { const { host } = mount({ chain: chainOf("peaking", "reverb") }); const ups = host.querySelectorAll('.hf-fx-move[title="Move up"]'); diff --git a/packages/studio/src/components/editor/propertyPanelFxSection.tsx b/packages/studio/src/components/editor/propertyPanelFxSection.tsx index 33fda26891..1c51a84300 100644 --- a/packages/studio/src/components/editor/propertyPanelFxSection.tsx +++ b/packages/studio/src/components/editor/propertyPanelFxSection.tsx @@ -22,8 +22,10 @@ import { type HfAudioFxParamValues, } from "@hyperframes/core/audio-fx"; import { DEFAULT_CARVE, type HfCarveSettings } from "@hyperframes/core/audio-carve"; +import { applyAudioFxPreset, getAudioFxPreset } from "@hyperframes/core/audio-fx-presets"; import { fxAutomationTarget } from "@hyperframes/core/audio-automation"; import { FxParams, FxParamRow } from "./propertyPanelFxControls.js"; +import { FxPresetMenu } from "./propertyPanelFxPresetMenu.js"; // Shared with the timeline's lane labels: a band is named by its frequency in // both places, and two formatters would drift. import { formatHz } from "../../player/components/automationLaneData"; @@ -686,6 +688,7 @@ export function FxSection({ const showCarve = !carvedAgainstBy && (sourceOptions.length > 0 || carve !== null); const [adding, setAdding] = useState(false); + const [picking, setPicking] = useState(false); const [openNode, setOpenNode] = useState(0); const grouped = useMemo( @@ -708,6 +711,23 @@ export function FxSection({ [chain, onChainPreview], ); + const applyPreset = useCallback( + (id: string) => { + const preset = getAudioFxPreset(id); + if (!preset) return; + // Appends. Stacking a character preset onto an already-cleaned voice is a + // real thing to want, and replacing silently would throw work away — so + // the destructive option is a separate gesture, not the default one. + const next = applyAudioFxPreset(chain, preset); + 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], + ); + const addEffect = useCallback( (type: string) => { mutate([ @@ -843,15 +863,29 @@ export function FxSection({ ))} - ) : ( - + ) : null} + + {picking ? : null} + + {adding || picking ? null : ( +
+ + +
)} );