From f362f1c9f6e3845cff853ac80ebd93fdeb002693 Mon Sep 17 00:00:00 2001 From: "Lu[ke] Wilson" Date: Sun, 26 Jan 2025 16:28:33 +0000 Subject: [PATCH] add comments and case insensitivity --- packages/superdough/superdough.mjs | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/packages/superdough/superdough.mjs b/packages/superdough/superdough.mjs index 4cb2553a..e5e38f73 100644 --- a/packages/superdough/superdough.mjs +++ b/packages/superdough/superdough.mjs @@ -17,24 +17,39 @@ import { loadBuffer } from './sampler.mjs'; export const soundMap = map(); export function registerSound(key, onTrigger, data = {}) { - soundMap.setKey(key, { onTrigger, data }); + soundMap.setKey(key.toLowerCase(), { onTrigger, data }); } export function aliasBankMap(aliasMap) { + // Make all bank keys lower case for case insensitivity + for (const key in aliasMap) { + aliasMap[key.toLowerCase()] = aliasMap[key]; + } + + // Look through every sound... const soundDictionary = soundMap.get(); for (const key in soundDictionary) { + // Check if the sound is part of a bank... const [bank, suffix] = key.split('_'); + if (!suffix) continue; + + // Check if the bank is aliased... const aliasValue = aliasMap[bank]; if (aliasValue) { if (typeof aliasValue === 'string') { - soundDictionary[`${aliasValue}_${suffix}`] = soundDictionary[key]; + // Alias a single alias + soundDictionary[`${aliasValue}_${suffix}`.toLowerCase()] = soundDictionary[key]; } else if (Array.isArray(aliasValue)) { + // Alias multiple aliases for (const alias of aliasValue) { - soundDictionary[`${alias}_${suffix}`] = soundDictionary[key]; + soundDictionary[`${alias}_${suffix}`.toLowerCase()] = soundDictionary[key]; } } } } + + // Update the sound map! + // We need to destructure here to trigger the update soundMap.set({ ...soundDictionary }); } @@ -55,7 +70,7 @@ export function aliasBank(...args) { } export function getSound(s) { - return soundMap.get()[s]; + return soundMap.get()[s.toLowerCase()]; } const defaultDefaultValues = {