// The instrument sounds compositions can pick: modal-synth's presets (imported live from the // sibling project through the @modal-synth alias) and pasted custom presets. Worker-safe: the // sounds are just parameter sets; the synth workers render them. import { DEFAULTS, type Params } from "@modal-synth/engine/params.ts"; import { PRESETS } from "@modal-synth/presets.ts"; /** Parse a pasted preset (the JSON from modal-synth's Copy button). */ export function parseModalPreset(text: string | undefined): Params | null { if (!text || !text.trim()) return null; try { const v = JSON.parse(text); return v && typeof v === "object" && !Array.isArray(v) ? (v as Params) : null; } catch { return null; } } /** Menu names for note instruments: every preset, plus "modal: custom". */ export const NOTE_SOUNDS: string[] = [...PRESETS.map((p) => `modal: ${p.name}`), "modal: custom"]; /** The full synth parameters for a menu name (custom: the pasted JSON). */ export function soundOf(name: string, custom: string, overrides: Params = {}): Params { const preset = name === "modal: custom" ? parseModalPreset(custom) : PRESETS.find((p) => `modal: ${p.name}` === name)?.p; return { ...DEFAULTS, ...(preset ?? {}), ...overrides }; }