Clean up error messages

This commit is contained in:
Aria 2025-12-13 17:15:06 -06:00
parent 63de46ae96
commit 18b3c66eb8
2 changed files with 19 additions and 10 deletions

View file

@ -401,7 +401,7 @@ function _getTargetParamsForControl(control, nodes, subControl) {
const lookupKey = subControl ? `${control}_${subControl}` : control; const lookupKey = subControl ? `${control}_${subControl}` : control;
const targetInfo = _getControlData(lookupKey) ?? _getControlData(control); const targetInfo = _getControlData(lookupKey) ?? _getControlData(control);
if (!targetInfo) { if (!targetInfo) {
errorLogger(`Could not find control data for target '${control}'`, 'superdough'); errorLogger(new Error(`Could not find control data for target '${control}'`), 'superdough');
return { targetParams: [], paramName: control }; return { targetParams: [], paramName: control };
} }
const paramName = targetInfo.param; const paramName = targetInfo.param;
@ -410,7 +410,7 @@ function _getTargetParamsForControl(control, nodes, subControl) {
if (!targetNodes) { if (!targetNodes) {
const keys = Object.keys(nodes); const keys = Object.keys(nodes);
errorLogger( errorLogger(
`Could not connect to target '${nodeKey}' — it does not exist. Available targets: ${keys.join(', ')}`, new Error(`Could not connect to target '${nodeKey}' — it does not exist. Available targets: ${keys.join(', ')}`),
'superdough', 'superdough',
); );
return { targetParams: [], paramName }; return { targetParams: [], paramName };
@ -426,6 +426,7 @@ function _getTargetParamsForControl(control, nodes, subControl) {
function connectLFO(idx, params, nodeTracker) { function connectLFO(idx, params, nodeTracker) {
const { rate = 1, sync, cps, cycle, control = 'lfo', subControl, depth = 1, depthabs, ...filteredParams } = params; const { rate = 1, sync, cps, cycle, control = 'lfo', subControl, depth = 1, depthabs, ...filteredParams } = params;
const { targetParams, paramName } = _getTargetParamsForControl(control, nodeTracker, subControl); const { targetParams, paramName } = _getTargetParamsForControl(control, nodeTracker, subControl);
if (!targetParams.length) return;
const currentValue = targetParams[0].value; const currentValue = targetParams[0].value;
const { min, max } = _getRangeForParam(paramName, currentValue, control); const { min, max } = _getRangeForParam(paramName, currentValue, control);
const depthValue = depthabs != null ? depthabs : depth * currentValue; const depthValue = depthabs != null ? depthabs : depth * currentValue;
@ -446,6 +447,7 @@ function connectLFO(idx, params, nodeTracker) {
function connectEnvelope(idx, params, nodeTracker) { function connectEnvelope(idx, params, nodeTracker) {
const { control, subControl, acurve, dcurve, rcurve, depth = 1, depthabs, ...filteredParams } = params; const { control, subControl, acurve, dcurve, rcurve, depth = 1, depthabs, ...filteredParams } = params;
const { targetParams, paramName } = _getTargetParamsForControl(control, nodeTracker, subControl); const { targetParams, paramName } = _getTargetParamsForControl(control, nodeTracker, subControl);
if (!targetParams.length) return;
const currentValue = targetParams[0].value; const currentValue = targetParams[0].value;
const { min, max } = _getRangeForParam(paramName, currentValue, control); const { min, max } = _getRangeForParam(paramName, currentValue, control);
const depthValue = depthabs != null ? depthabs : depth * currentValue; const depthValue = depthabs != null ? depthabs : depth * currentValue;
@ -466,12 +468,13 @@ function connectEnvelope(idx, params, nodeTracker) {
function connectBusModulator(params, nodeTracker) { function connectBusModulator(params, nodeTracker) {
const ac = getAudioContext(); const ac = getAudioContext();
const { control, subControl, depth = 1, depthabs } = params; const { control, subControl, depth = 1, depthabs } = params;
const { targetParams, paramName } = _getTargetParamsForControl(control, nodeTracker, subControl);
if (!targetParams.length) return { toCleanup: [] };
const signal = controller.getBus(params.bus); const signal = controller.getBus(params.bus);
const dc = new ConstantSourceNode(ac, { offset: params.dc ?? 0 }); const dc = new ConstantSourceNode(ac, { offset: params.dc ?? 0 });
dc.start(params.begin); dc.start(params.begin);
const shifted = dc.connect(gainNode(1)); const shifted = dc.connect(gainNode(1));
signal.connect(shifted); signal.connect(shifted);
const { targetParams, paramName } = _getTargetParamsForControl(control, nodeTracker, subControl);
const currentValue = targetParams[0].value; const currentValue = targetParams[0].value;
const { min, max } = _getRangeForParam(paramName, currentValue, control); const { min, max } = _getRangeForParam(paramName, currentValue, control);
const depthValue = depthabs != null ? depthabs : depth * currentValue; const depthValue = depthabs != null ? depthabs : depth * currentValue;
@ -978,7 +981,7 @@ export const superdough = async (value, t, hapDuration, cps = 0.5, cycle = 0.5)
}, },
nodes, nodes,
); );
audioNodes.push(lfo); lfo && audioNodes.push(lfo);
} }
} }
if (value.env) { if (value.env) {
@ -992,7 +995,7 @@ export const superdough = async (value, t, hapDuration, cps = 0.5, cycle = 0.5)
}, },
nodes, nodes,
); );
audioNodes.push(env); env && audioNodes.push(env);
} }
} }
if (value.bmod) { if (value.bmod) {

View file

@ -1013,9 +1013,15 @@ class EnvelopeProcessor extends AudioWorkletProcessor {
} }
process(_inputs, outputs, params) { process(_inputs, outputs, params) {
const begin = params['begin'][0];
const end = params['end'][0];
if (currentTime >= end) {
return false;
}
if (currentTime <= begin) {
return true;
}
const out = outputs[0][0]; const out = outputs[0][0];
if (!out) return true;
const begin = pv(params.begin, 0);
const retrigger = pv(params.retrigger, 0) >= 0.5; // convert to bool const retrigger = pv(params.retrigger, 0) >= 0.5; // convert to bool
if (begin !== this.beginTime && (this.state === 0 || retrigger)) { if (begin !== this.beginTime && (this.state === 0 || retrigger)) {
// triggered // triggered
@ -1034,8 +1040,8 @@ class EnvelopeProcessor extends AudioWorkletProcessor {
const dCurve = pv(params.decayCurve, i); const dCurve = pv(params.decayCurve, i);
const rCurve = pv(params.releaseCurve, i); const rCurve = pv(params.releaseCurve, i);
const depth = pv(params.depth, i); const depth = pv(params.depth, i);
const clampMin = pv(params.min, i); const min = pv(params.min, i);
const clampMax = pv(params.max, i); const max = pv(params.max, i);
const states = [ const states = [
{ time: Number.POSITIVE_INFINITY, start: 0, target: 0 }, // idle { time: Number.POSITIVE_INFINITY, start: 0, target: 0 }, // idle
{ time: attack, start: this.attackStart, target: 1, curve: aCurve }, { time: attack, start: this.attackStart, target: 1, curve: aCurve },
@ -1049,7 +1055,7 @@ class EnvelopeProcessor extends AudioWorkletProcessor {
this.state = (this.state + 1) % states.length; this.state = (this.state + 1) % states.length;
time = states[this.state].time; time = states[this.state].time;
} }
const clamped = clamp(this.val * depth, Math.min(clampMin, clampMax), Math.max(clampMin, clampMax)); const clamped = clamp(this.val * depth, min, max);
out[i] = clamped; out[i] = clamped;
} }
return true; return true;