diff --git a/packages/superdough/superdough.mjs b/packages/superdough/superdough.mjs index e936d38e..0c4d2395 100644 --- a/packages/superdough/superdough.mjs +++ b/packages/superdough/superdough.mjs @@ -18,6 +18,7 @@ export const DEFAULT_MAX_POLYPHONY = 128; const DEFAULT_AUDIO_DEVICE_NAME = 'System Standard'; let maxPolyphony = DEFAULT_MAX_POLYPHONY; + export function setMaxPolyphony(polyphony) { maxPolyphony = parseInt(polyphony) ?? DEFAULT_MAX_POLYPHONY; } @@ -28,6 +29,16 @@ export function registerSound(key, onTrigger, data = {}) { soundMap.setKey(key, { onTrigger, data }); } +let gainCurveFunc = (val) => val; + +export function applyGainCurve(val) { + return gainCurveFunc(val); +} + +export function setGainCurve(newGainCurveFunc) { + gainCurveFunc = newGainCurveFunc; +} + function aliasBankMap(aliasMap) { // Make all bank keys lower case for case insensitivity for (const key in aliasMap) { @@ -515,7 +526,13 @@ export const superdough = async (value, t, hapDuration) => { compressorRelease, } = value; - gain = nanFallback(gain, 1); + gain = applyGainCurve(nanFallback(gain, 1)); + postgain = applyGainCurve(postgain); + shapevol = applyGainCurve(shapevol); + distortvol = applyGainCurve(distortvol); + delay = applyGainCurve(delay); + velocity = applyGainCurve(velocity); + gain *= velocity; // velocity currently only multiplies with gain. it might do other things in the future const chainID = Math.round(Math.random() * 1000000); @@ -532,7 +549,7 @@ export const superdough = async (value, t, hapDuration) => { //music programs/audio gear usually increments inputs/outputs from 1, so imitate that behavior channels = (Array.isArray(channels) ? channels : [channels]).map((ch) => ch - 1); - gain *= velocity; // velocity currently only multiplies with gain. it might do other things in the future + let audioNodes = []; if (bank && s) {