template-manager.js — Template System
Templates constrain which parameters are randomised. A template declares a set of locked params (pinned values that won't change) and a distortion configuration — everything else is free for randomisation.
Template Format
{
"name": "Sine Kick",
"description": "Clean sine with subtle shaping",
"params": {
"pitchStart": 220,
"pitchCurve": "linear"
},
"locked": {
"params": {
"oscWaveform": "sine",
"compThreshold": 0
},
"distortion": {
"masterLocked": true,
"stages": []
}
}
}
params(optional): Values set but not locked — used by the "None" template to reset everything to defaults without constraintslocked.params: Values set and locked — these won't be randomisedlocked.distortion: Master lock status and stage definition
Functions
captureTemplate(name, params, lockedParams, pipeline) → template
Creates a template from the current lock state. Only params where
lockedParams[key] === true are captured (with their current values). Captures
pipeline.masterLocked and pipeline.toJSON() for the distortion config.
applyTemplate(tmpl, params, lockedParams, pipeline)
- Unlocks everything: all
lockedParamsset tofalse, pipeline locks cleared - Sets base params:
tmpl.paramsvalues copied (not locked) - Sets locked params:
tmpl.locked.paramsvalues copied and locked - Configures distortion:
masterLocked, stages replaced - Updates activeTemplate:
getActiveTemplate()returns this template
loadBuiltinTemplates(engineId) → [template]
Fetches presets/templates/{engineId}.json from the server. Returns an array
with _builtin: true set on each entry.
loadUserTemplates / saveUserTemplate / deleteUserTemplate
CRUD for user-created templates stored in localStorage[synth_templates_{id}].
downloadTemplate(tmpl)
Triggers a JSON file download of the template.
buildTemplateListUI(container, templates, activeName, onSelect, onDelete)
Renders the template list in the sidebar. Built-in templates show name +
description. User templates additionally show a delete ✕ button with "Sure?"
confirmation. Clicking a template calls onSelect(tmpl).