preset-manager.js — Preset System

Generic preset persistence and UI. Instantiated per-engine with a unique storageKey.

PresetManager

Method Description
constructor(storageKey) Key for localStorage isolation (e.g. 'kick_synth_presets')
load() Returns { name: snapshot } from localStorage
save(presets) Writes full presets map to localStorage
get(name) Returns single snapshot or null
set(name, snapshot) Saves/replaces a named preset
delete(name) Removes a named preset
buildListUI(container, callbacks) Renders preset list into a DOM element

Snapshot format:

{ params: { ... }, stages: [{ type, amount }] }

buildListUI

Renders a scrollable list with: - Default entry (always present, calls onReset) - Named presets sorted alphabetically, each with: - Click to load (calls onSelect(name, snapshot)) - ↻ update button (calls onUpdate(name)) - ✕ delete button with "Sure?" confirmation (calls onDelete(name))

buildSnapshot(params, stages) → { params, stages }

Deep-clones the current params and stages into a snapshot object for saving. Uses JSON.parse(JSON.stringify(...)) for deep cloning.