Build Controls from Parameter Descriptors
Every processor the engine can build describes its own parameters: name, type, unit, default, accepted range, display range, axis, sibling constraints, and whether the value can change while audio runs. A host that reads those descriptors can draw a control surface for any insert or mastering stage without a hand-written table, and the surface follows the engine when a build adds a key or a band.
This page builds that surface step by step in plain JavaScript. The field-by-field reference is elsewhere and is linked rather than repeated: The parameter descriptor for each field, Reading a catalog bound for where min, max and default come from, and Capability Catalog for the document as a whole.
Every snippet below is one script, run in Node against the shipped WASM build; the output blocks are what it printed.
What you need
- Install:
npm install @libraz/libsonare(Node.js 22.12 or later). No audio files are needed until the last snippet, which makes its own test tone. - Running it: paste the snippets, in order, into one file named
controls.mjsand runnode controls.mjs. Later snippets use names the earlier ones define (catalog,processor,gate,multiband). - Background: the page assumes you know what an insert and a mastering chain are; Mixing Basics and What Is Mastering? cover both.
Read the descriptors
capabilityCatalog() returns the whole build in one call: every processor with its params array, plus a chain section for the mastering chain. masteringInsertParamInfo({ insert, sampleRate? }) returns the same descriptors for one processor and can resolve a rate-dependent ceiling. A UI usually reads the catalog once at start-up.
import {
init, capabilityCatalog, masteringInsertParamInfo, masteringInsertTiming,
masterAudio, RealtimeEngine,
} from '@libraz/libsonare';
await init();
const catalog = capabilityCatalog();
const processor = (id) => catalog.processors.find((p) => p.id === id);
const gate = processor('dynamics.gate');
for (const p of gate.params) {
console.log(p.name.padEnd(17), p.type, p.unit, p.scale.padEnd(6),
'min', p.min, 'max', p.max, 'ui', p.uiMin, p.uiMax, 'default', p.default,
'rtSafe', p.rtSafe, p.dependsOn.map((d) => `${d.relation} ${d.key}`).join());
}thresholdDb number dB linear min undefined max undefined ui -50 0 default -50 rtSafe true ge closeThresholdDb
attackMs number ms log min 0 max undefined ui 0.1 100 default 2 rtSafe true
releaseMs number ms log min 0 max undefined ui 0.1 2000 default 80 rtSafe true
rangeDb number dB linear min undefined max 0 ui -80 0 default -80 rtSafe true
closeThresholdDb number dB linear min undefined max undefined ui undefined undefined default -50 rtSafe false le thresholdDb
holdMs number ms linear min 0 max undefined ui 0 1000 default 0 rtSafe false
keyHighPassHz number Hz linear min 0 max undefined ui undefined undefined default 0 rtSafe falseThe gate shows most of what the rest of this page handles. Two kinds of range sit side by side: min / max is what construction accepts, uiMin / uiMax is what a control should draw. The attack and release times are drawn on a log axis. closeThresholdDb has no range of its own, only a relation to thresholdDb: a gate opens at one level and closes at a lower one (hysteresis), so a signal hovering at the threshold does not chatter open and shut. keyHighPassHz is the cutoff of a high-pass filter on the signal the gate listens to (its key), so low rumble does not hold the gate open. The last three rows cannot change while audio runs.
Choose a widget per parameter
type and choices decide the widget. A number becomes a slider only when both ends of a range are known, either from the display range or from the accepted range; otherwise it needs a numeric field.
function controlKind(p) {
if (p.type === 'boolean') return 'toggle';
if (p.choices !== undefined) return 'select'; // an enum, or a number whose accepted values have gaps
if (p.type !== 'number') return 'custom'; // 'string' / 'array': an impulse response, a per-band list
const lo = p.uiMin ?? p.min;
const hi = p.uiMax ?? p.max;
return lo !== undefined && hi !== undefined ? 'slider' : 'field';
}
const kinds = {};
for (const proc of catalog.processors) {
for (const p of proc.params) kinds[controlKind(p)] = (kinds[controlKind(p)] ?? 0) + 1;
}
console.log(kinds);{ slider: 1163, toggle: 1014, select: 752, field: 2441, custom: 5 }The field count is large on purpose. Many gains and offsets have no published bound: an absent min or max means construction does not refuse on that side, not that the limit went unmeasured (Two things an absent bound and a default do not tell you). A numeric field with the unit beside it is the honest control for those keys; a slider would need a range the engine never stated. A select sends the choice's numeric value; its name is the label.
Map a slider onto the scale
scale is the axis: 'linear' or 'log'. Times and frequencies are heard proportionally, so equal slider travel should mean an equal ratio, which is what a log axis gives. A log slider needs a positive lower end and a finite upper end. In the current build every log-scaled descriptor publishes both, through uiMin / uiMax or through min / max; uiMin ?? min and uiMax ?? max always find them.
function sliderRange(p) {
const lo = p.uiMin ?? p.min;
let hi = p.uiMax ?? p.max;
// The top of the drawn range is the accepted ceiling itself, and that ceiling is refused.
if (p.uiMax === undefined && p.maxExclusive) hi *= 0.999;
return [lo, hi];
}
function toValue(p, t) {
const [lo, hi] = sliderRange(p);
return p.scale === 'log' ? lo * (hi / lo) ** t : lo + (hi - lo) * t;
}
function toPosition(p, value) {
const [lo, hi] = sliderRange(p);
const v = Math.min(Math.max(value, lo), hi); // pin the thumb; the value itself is kept
return p.scale === 'log' ? Math.log(v / lo) / Math.log(hi / lo) : (v - lo) / (hi - lo);
}
const attack = processor('dynamics.compressor').params.find((p) => p.name === 'attackMs');
console.log(attack.scale, sliderRange(attack), [0, 0.5, 1].map((t) => +toValue(attack, t).toFixed(3)));
const sampleRate = 44100;
const freq = masteringInsertParamInfo({ insert: 'eq.parametric', sampleRate })
.find((p) => p.name === 'band0.frequencyHz');
console.log(freq.scale, freq.maxRelativeTo, sliderRange(freq), +toValue(freq, 0.5).toFixed(1));
const fast = processor('dynamics.transientShaper').params.find((p) => p.name === 'fastAttackMs');
console.log(fast.default, sliderRange(fast), toPosition(fast, fast.default));log [ 0.1, 200 ] [ 0.1, 4.472, 200 ]
log nyquist [ 20, 22027.95 ] 663.7
0 [ 0.1, 10000 ] 0Three cases from that output:
- The compressor attack accepts 0 ms (
min: 0), but a log axis cannot reach 0, so the descriptor draws fromuiMin0.1 ms. The slider's midpoint is 4.47 ms, the geometric mean of the ends. - An EQ band frequency has no
uiMax; its ceiling is the Nyquist frequency and is exclusive. Passing the session rate assampleRatetomasteringInsertParamInfoturns the 48 kHz probe value into 22050 for a 44.1 kHz session, and the slider stops just below it. The engine accepts 22027.95 Hz at that rate and refuses 22050 Hz. - A value can sit outside the display range: the transient shaper's
fastAttackMsdefaults to 0, below itsuiMinof 0.1.toPositionpins the thumb at the end and the value stays 0. Clamping the value to the display range would change the sound on load.
min and max also serve as an early check on typed values. They are measured with every other parameter at its default, so for a parameter coupled to its siblings they describe the default setup only. dependsOn states the couplings that are a plain ordering; coupledWith lists the other siblings whose value moves the range. The room reverb's receiverSpacingM has an empty dependsOn and lists lengthM, widthM, listenerX, listenerY, sourceX and sourceY in coupledWith, because how wide a pair fits depends on the room and placement (Geometric room inserts).
A key with a non-empty coupledWith also carries its own limits with that coupling set aside: domainMin and domainMax, each with a domainMinExclusive / domainMaxExclusive flag. A side is absent when the coupling is its only bound, as on a listener coordinate, whose ceiling is the room. Bound such a control by its domain rather than by the default-setup min / max, and leave the coupling to the engine when the values are sent:
function controlRange(p) {
if (p.coupledWith.length === 0) {
return { lo: p.min, loOpen: p.minExclusive, hi: p.max, hiOpen: p.maxExclusive };
}
// A coupled key's own limits; the relation to its siblings is the engine's to judge.
return { lo: p.domainMin, loOpen: p.domainMinExclusive, hi: p.domainMax, hiOpen: p.domainMaxExclusive };
}
const spacing = processor('effects.reverb.room').params.find((p) => p.name === 'receiverSpacingM');
console.log('max', spacing.max, 'range', controlRange(spacing));
for (const params of [
{ receiverSpacingM: 3 },
{ receiverSpacingM: 3, lengthM: 12, widthM: 9, listenerX: 6, listenerY: 4.5 },
]) {
try {
masteringInsertTiming({ insert: 'effects.reverb.room', params, sampleRate: 48000 });
console.log(JSON.stringify(params), 'accepted');
} catch (e) {
console.log(JSON.stringify(params), 'refused:', e.message);
}
}max 2.5 range { lo: 0, loOpen: true, hi: 4, hiOpen: false }
{"receiverSpacingM":3} refused: masteringInsertTiming: params.receiverSpacingM must place both receivers inside the room for params.lengthM and params.widthM
{"receiverSpacingM":3,"lengthM":12,"widthM":9,"listenerX":6,"listenerY":4.5} acceptedThe receiver spacing's domain is (0, 4] m, while its max is what fits the default room. A 3 m pair lies inside the domain: the default room refuses it, and a 12 × 9 m room with the listener in the middle accepts it. When the user changes a key named in coupledWith, re-validate the dependent control instead of keeping the default-setup bound. Treat a published bound as a warning and the engine's refusal as the decision, as in Send the values back.
Bound a control by its siblings
dependsOn lists the siblings whose current value bounds this key, each read as this <relation> factor * sibling. A UI turns it into a live range that moves when the sibling moves.
function liveBounds(p, values) {
let lo = p.min, hi = p.max, loOpen = p.minExclusive, hiOpen = p.maxExclusive;
for (const { key, relation, factor } of p.dependsOn) {
if (values[key] === undefined) continue; // the sibling is not in effect
const bound = factor * values[key];
if (relation === 'lt' || relation === 'le') {
if (hi === undefined || bound < hi) [hi, hiOpen] = [bound, relation === 'lt'];
} else if (lo === undefined || bound > lo) {
[lo, loOpen] = [bound, relation === 'gt'];
}
}
return { lo, loOpen, hi, hiOpen };
}
const gateValues = { thresholdDb: -40, closeThresholdDb: -50 };
const close = gate.params.find((p) => p.name === 'closeThresholdDb');
console.log('closeThresholdDb', liveBounds(close, gateValues));
const multiband = processor('multiband.compressor');
const cutoff1 = multiband.params.find((p) => p.name === 'cutoff1Hz');
console.log('cutoff1Hz', liveBounds(cutoff1, { cutoff0Hz: 120, cutoff1Hz: 2000 }));
for (const params of [
{ thresholdDb: -40, closeThresholdDb: -40 },
{ thresholdDb: -40, closeThresholdDb: -30 },
]) {
try {
masteringInsertTiming({ insert: 'dynamics.gate', params, sampleRate: 48000 });
console.log(params, 'accepted');
} catch (e) {
console.log(params, 'refused:', e.message);
}
}closeThresholdDb { lo: undefined, loOpen: false, hi: -40, hiOpen: false }
cutoff1Hz { lo: 120, loOpen: true, hi: undefined, hiOpen: false }
{ thresholdDb: -40, closeThresholdDb: -40 } accepted
{ thresholdDb: -40, closeThresholdDb: -30 } refused: masteringInsertTiming: params.closeThresholdDb must be at most params.thresholdDbThe gate's close threshold may equal the open threshold (le) but not exceed it. Crossover cutoffs are strictly ordered (lt / gt), so a cutoff cannot equal its neighbor. Of the relations in the current build, all use a factor of 1 except the classical denoise and dereverb stages, whose hopLength must be at most half of nFft (le, factor 0.5) and whose nFft must be at least twice hopLength (ge, factor 2).
A UI has two reasonable responses when a sibling moves past a dependent value: carry the dependent value along, or mark the pair invalid until the user fixes it. What it should not do is send the pair, because construction refuses it.
dependsOn bounds a value; it does not hide or disable a control. Whether a control exists at all is the slot field's job, below.
Show a band only when it exists
A key with a slot belongs to a group that exists under a condition. The processor's slots array gives each group's activation, parent, and minCrossoverCutoffs (Slot metadata). Two patterns cover the processors:
activation: 'anyKey': the group exists once any of its keys is sent. A parametric EQ band is built by sending one of its keys, so the UI offers "add band" and shows the band's controls from then on.activation: 'always'withminCrossoverCutoffs: the group exists while enough crossover cutoffs are in effect. A multiband compressor has one band more than it has cutoffs. With no cutoff key sent, the default split applies: the cutoffs that publish a default.
function presentSlots(proc, values) {
const cutoffKeys = proc.params.filter((p) => /^cutoff\d+Hz$/.test(p.name));
const sent = cutoffKeys.filter((p) => values[p.name] !== undefined).length;
const cutoffs = sent > 0 ? sent : cutoffKeys.filter((p) => p.default !== undefined).length;
const present = new Set();
for (const slot of proc.slots) { // a parent is always listed before its children
if (slot.parent !== undefined && !present.has(slot.parent)) continue;
if (cutoffs < slot.minCrossoverCutoffs) continue;
const keyed = Object.keys(values).some((k) => k.startsWith(`${slot.name}.`));
if (slot.activation === 'always' || keyed) present.add(slot.name);
}
return [...present];
}
console.log(presentSlots(multiband, {}));
console.log(presentSlots(multiband, { cutoff0Hz: 120, cutoff1Hz: 2000, cutoff2Hz: 6000 }));
console.log(presentSlots(processor('eq.parametric'), { 'band0.gainDb': 3, 'band5.frequencyHz': 8000 }));[ 'band0', 'band1', 'band2' ]
[ 'band0', 'band1', 'band2', 'band3' ]
[ 'band0', 'band5' ]Once any cutoff key is sent, the split is exactly the cutoffs sent, so a UI that adds a band sends the whole cutoff list from cutoff0Hz upward. The engine holds the multiband compressor to this: with the default two cutoffs, masteringInsertTiming refuses a band3.* key as one the insert does not read, and accepts it once three cutoffs are sent.
Decide what changes live
rtSafe splits the controls into two groups. An rtSafe parameter can change while audio runs, through the realtime engine's by-name setters or an automation lane. Every other parameter, including some that carry an automation id, takes effect only when the insert is built, so changing it means rebuilding the strip. Fewer than one descriptor in four is rtSafe, and some carry an id without being rtSafe, so read the flag itself rather than inferring it from the id.
A UI can show the difference before the user touches the control: draw an automation lane only for rtSafe rows, and apply a construction-only change when the control is released rather than on every drag step.
Send the values back
Keep the user's values as a sparse object keyed by name: only the keys the user set, so the processor's own defaults still apply to the rest. Before a construction, masteringInsertTiming({ insert, params, sampleRate }) works as a validator. It builds the insert exactly as a strip would, refuses a value construction rejects, and refuses a key the insert does not read. The one-shot masteringApplyProcessor also refuses a parameter its processor does not read, naming it, but it renders audio, so masteringInsertTiming is the cheaper check.
const changed = { thresholdDb: -45, closeThresholdDb: -55, holdMs: 20 };
console.log(masteringInsertTiming({ insert: 'dynamics.gate', params: changed, sampleRate: 48000 }));
const engine = new RealtimeEngine({ sampleRate: 48000, maxBlockSize: 128 });
engine.setTrackLanes([{ trackId: 1 }]);
engine.setStrip(1, { id: 'vocal', inserts: [{ processor: 'dynamics.gate', params: changed }] });
const isLive = (name) => gate.params.find((p) => p.name === name).rtSafe;
for (const [name, value] of [['thresholdDb', -38], ['holdMs', 40]]) {
if (isLive(name)) {
engine.setStripInsertParam(1, 0, { name, value });
console.log(name, 'set live');
} else {
console.log(name, 'needs a rebuild of the strip');
}
}
try {
engine.setStripInsertParam(1, 0, { name: 'holdMs', value: 40 });
} catch (e) {
console.log('holdMs live:', e.message);
}
engine.destroy();{ latencySamples: 0, tailSamples: 0 }
thresholdDb set live
holdMs needs a rebuild of the strip
holdMs live: RealtimeEngine.setStripInsertParam: param.name must be the name of a parameter of the insert that can be set while runningThe two paths treat a bad value differently. Construction (scene JSON, setStrip, masteringApplyProcessor, masteringInsertTiming) refuses a value outside the accepted range with a message naming the problem, such as params.ratio must be finite and at least 1. The live path does not clamp: writing +12 dB by name to the gate's rangeDb, whose maximum is 0, throws nothing and leaves the strip rendering exactly as it did before the write. A UI gets no feedback from a dropped write, so keep the live control inside the range it draws.
For the live setters, automation ids, and how a live value interacts with a later strip rebuild, see Group routing, sidechains, and live strip controls and Parameter automation. The scene insert format is in Mixing Scene JSON.
Lay out the mastering chain
The mastering chain (masterAudio with a preset or overrides) is addressed by flat dot-notation keys. overrides is typed as the nested MasteringChainConfig, and the same object also accepts the flat keys at run time with an identical render; they are not part of the declared type, so in TypeScript build the nested form or cast. catalog.chain describes the flat keys in three parts, as listed in Chain and preset sections:
stages: one entry per stage, with its keyprefix, the catalogprocessorwhose descriptors its<prefix>.<leaf>keys use, and itsenabledKey.lists: the indexed lists, withminItems/maxItems.params: descriptors for keys no processor carries, such as theenabledswitches andloudness.*.
A stage panel combines the three: a toggle from enabledKey, controls from the stage's processor, controls from params under the stage's prefix, and a row editor for each list the stage owns.
const { stages, lists, params: chainParams } = catalog.chain;
const chainParam = (key) => chainParams.find((p) => p.name === key);
function stagePanel(stage) {
const owned = lists.filter((l) => l.key.startsWith(`${stage.prefix}.`));
const fromProcessor = stage.processor === undefined ? [] : processor(stage.processor).params
// Use the list descriptors for indexed controls.
.filter((p) => owned.length === 0 || !/\d/.test(p.name))
.map((p) => ({ ...p, key: `${stage.prefix}.${p.name}` }));
const chainOnly = chainParams
.filter((p) => p.name.startsWith(`${stage.prefix}.`) && p.name !== stage.enabledKey)
.filter((p) => !owned.some((l) => l.key === p.name))
.map((p) => ({ ...p, key: p.name }));
const keys = new Set();
return {
title: stage.prefix,
enabled: chainParam(stage.enabledKey),
controls: [...fromProcessor, ...chainOnly].filter((c) => !keys.has(c.key) && keys.add(c.key)),
lists: owned.map((l) => ({
key: l.key, minItems: l.minItems, maxItems: l.maxItems,
itemFields: l.processor === undefined ? [chainParam(l.key)] : processor(l.processor).params,
})),
};
}
const panels = stages.map(stagePanel);
for (const panel of panels.filter((p) => /compressor|multiband|loudness/i.test(p.title))) {
console.log(panel.title, panel.enabled.default, panel.controls.map((c) => c.key.slice(panel.title.length + 1)).join(' '));
for (const l of panel.lists) console.log(' list', l.key, `${l.minItems}..${l.maxItems}`, l.itemFields.length, 'fields');
}dynamics.compressor false thresholdDb ratio attackMs releaseMs makeupGainDb kneeDb autoMakeup detector sidechainHighPassHz pdrTimeMs pdrReleaseScale
dynamics.multibandComp false firKernelSize mode slope crossover.firKernelSize crossover.mode crossover.slope
list dynamics.multibandComp.crossover.cutoffsHz 1..63 1 fields
list dynamics.multibandComp.bands 2..64 11 fields
list dynamics.multibandComp.cutoff{i}Hz 1..63 1 fields
loudness false applyGainAtInputRate ceilingDbtp maxLimiterGainReductionDb releaseMs targetLufs truePeakOversampleSet multiband cutoffs with crossover.cutoffsHz or cutoff<i>Hz. Set individual band fields as bands.<i>.<key>. Chain overrides reject band<i>.*. Three cutoffs give four bands. Each band takes the dynamics.compressor fields. The cutoff descriptor covers 20 Hz to 20 kHz on a log scale. The loudness stage has no processor; its controls come from params.
The order of stages is not the order the chain runs: the array lists repair.declick before repair.declip, and the chain runs declip first. A UI that draws the chain as a signal flow takes the order from Chain order.
Applying the panel is one flat object; an enum can be sent by its choices name:
const sr = 48000;
const tone = Float32Array.from({ length: sr }, (_, i) => 0.25 * Math.sin(2 * Math.PI * 220 * i / sr));
const result = masterAudio({ samples: tone, sampleRate: sr, overrides: {
'dynamics.multibandComp.enabled': true,
'dynamics.multibandComp.crossover.cutoffsHz.0': 120,
'dynamics.multibandComp.crossover.cutoffsHz.1': 2000,
'dynamics.multibandComp.crossover.cutoffsHz.2': 6000,
'dynamics.multibandComp.bands.3.ratio': 3,
'dynamics.compressor.enabled': true,
'dynamics.compressor.detector': 'peak',
'loudness.enabled': true,
'loudness.targetLufs': -16,
} });
console.log(result.stages, result.outputLufs.toFixed(2));
try {
masterAudio({ samples: tone, sampleRate: sr, overrides: { 'dynamics.multibandComp.enabled': true, 'dynamics.multibandComp.band3.ratio': 3 } });
} catch (e) {
console.log(e.message.split(' (expected ')[0]);
}[
'dynamics.compressor',
'dynamics.multibandComp',
'loudness.optimize'
] -16.00
masterAudio: unknown key overrides.dynamics.multibandComp.band3.ratioThe chain refuses an unknown override with a TypeError, naming its path and appending the sorted accepted-key list. That list includes the scalar cutoff family dynamics.multibandComp.cutoff{i}Hz; the catalog also publishes the indexed dynamics.multibandComp.crossover.cutoffsHz.<i> list form. The example prints the path without the accepted-key list.
Related
- Effects Inserts — the insert-specific route from a processor id to a control surface
- Capability Catalog — how bounds and defaults are measured
- JavaScript API — the
capabilityCatalog()signature and the TypeScript types - Realtime Engine — live setters and automation lanes for
rtSafeparameters - Build a Browser Mixer — an app that applies strip and insert values through the engine