From 5738020ac21ee9edbd26b57ceed494e59db008a1 Mon Sep 17 00:00:00 2001 From: Aria Date: Thu, 4 Dec 2025 21:41:52 -0600 Subject: [PATCH] Working version of defaulting --- packages/superdough/nodePools.mjs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/packages/superdough/nodePools.mjs b/packages/superdough/nodePools.mjs index 66b01b408..b1e8c5975 100644 --- a/packages/superdough/nodePools.mjs +++ b/packages/superdough/nodePools.mjs @@ -48,18 +48,23 @@ export const getNodeFromPool = (key, factory, params = {}) => { } node[POOL_KEY] = key; const now = node.context?.currentTime ?? 0; - const paramHolder = node instanceof AudioWorkletNode ? node.parameters : node; - const nodeParams = {}; - Object.getOwnPropertyNames(paramHolder).forEach((name) => { - if (paramHolder[name] instanceof AudioParam) { - nodeParams[name] = paramHolder[name]; + const paramMap = new Map(); + if (node instanceof AudioWorkletNode) { + for (const [name, param] of node.parameters.entries()) { + paramMap.set(name, param); } - }); - Object.entries(nodeParams).forEach(([k, param]) => { + } else { + for (const name of Object.getOwnPropertyNames(node)) { + const value = node[name]; + if (value instanceof AudioParam) { + paramMap.set(name, value); + } + } + } + paramMap.forEach((param, name) => { param.cancelScheduledValues(now); // Set values from `params` or restore defaults - const target = params[k] !== undefined ? params[k] : param.defaultValue; - console.log(k, param, target, key); + const target = params[name] !== undefined ? params[name] : param.defaultValue; param.setValueAtTime(target, now); }); return node;