Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bank aliasing and case insensitivity #1245

Merged
merged 16 commits into from
Feb 1, 2025
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ pnpm-lock.yaml
pnpm-workspace.yaml
**/dev-dist
website/.astro
!tidal-drum-machines.json
TodePond marked this conversation as resolved.
Show resolved Hide resolved
!tidal-drum-machines-alias.json
7 changes: 6 additions & 1 deletion packages/repl/prebake.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { noteToMidi, valueToMidi, Pattern, evalScope } from '@strudel/core';
import { registerSynthSounds, registerZZFXSounds, samples } from '@strudel/webaudio';
import { aliasBank, registerSynthSounds, registerZZFXSounds, samples } from '@strudel/webaudio';
import * as core from '@strudel/core';

export async function prebake() {
Expand All @@ -21,6 +21,9 @@ export async function prebake() {
);
// load samples
const ds = 'https://raw.githubusercontent.com/felixroos/dough-samples/main/';

// TODO: move this onto the strudel repo
const ts = 'https://raw.githubusercontent.com/todepond/samples/main/';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

@felixroos felixroos Jan 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it will very likely be available on https://strudel.cc/tidal-drum-machines-alias.json after merge/deploy

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in theory, both github links wouldn't need to be fetched, instead the json could be used directly hmmm

await Promise.all([
modulesLoading,
registerSynthSounds(),
Expand All @@ -36,6 +39,8 @@ export async function prebake() {
samples(`${ds}/EmuSP12.json`),
samples(`${ds}/vcsl.json`),
]);

aliasBank(`${ts}/tidal-drum-machines-alias.json`);
felixroos marked this conversation as resolved.
Show resolved Hide resolved
}

const maxPan = noteToMidi('C8');
Expand Down
65 changes: 63 additions & 2 deletions packages/superdough/superdough.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,72 @@ 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 });
}

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') {
// 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}`.toLowerCase()] = soundDictionary[key];
}
}
}
}

// Update the sound map!
// We need to destructure here to trigger the update
soundMap.set({ ...soundDictionary });
}

async function aliasBankPath(path) {
const response = await fetch(path);
const aliasMap = await response.json();
aliasBankMap(aliasMap);
}

/**
* Register an alias for a bank of sounds.
* Optionally accepts a single argument map of bank aliases.
* Optionally accepts a single argument string of a path to a JSON file containing bank aliases.
* @param {string} bank - The bank to alias
* @param {string} alias - The alias to use for the bank
*/
export async function aliasBank(...args) {
switch (args.length) {
case 1:
if (typeof args[0] === 'string') {
return aliasBankPath(args[0]);
} else {
return aliasBankMap(args[0]);
}
case 2:
return aliasBankMap({ [args[0]]: args[1] });
default:
throw new Error('aliasMap expects 1 or 2 arguments, received ' + args.length);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if theres a better place for this function to live lemme know and i'll move it

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good

}

export function getSound(s) {
return soundMap.get()[s];
return soundMap.get()[s.toLowerCase()];
}

const defaultDefaultValues = {
Expand Down
68 changes: 68 additions & 0 deletions website/public/tidal-drum-machines-alias.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"AJKPercusyn": "Percysyn",
"AkaiLinn": "Linn",
"AkaiMPC60": "MPC60",
"AkaiXR10": "XR10",
"AlesisHR16": "HR16",
"AlesisSR16": "SR16",
"BossDR110": "DR110",
"BossDR220": "DR220",
"BossDR55": "DR55",
"BossDR550": "DR550",
"CasioRZ1": "RZ1",
"CasioSK1": "SK1",
"CasioVL1": "VL1",
"DoepferMS404": "MS404",
"EmuDrumulator": "Drumulator",
"EmuSP12": "SP12",
"KorgDDM110": "DDM110",
"KorgKPR77": "KPR77",
"KorgKR55": "KR55",
"KorgKRZ": "KRZ",
"KorgM1": "M1",
"KorgMinipops": "Minipops",
"KorgPoly800": "Poly800",
"KorgT3": "T3",
"Linn9000": "9000",
"LinnLM1": "LM1",
"LinnLM2": "LM2",
"MoogConcertMateMG1": "ConcertMateMG1",
"OberheimDMX": "DMX",
"RhodesPolaris": "Polaris",
"RhythmAce": "Ace",
"RolandCompurhythm1000": "Compurhythm1000",
"RolandCompurhythm78": "Compurhythm78",
"RolandCompurhythm8000": "Compurhythm8000",
"RolandD110": "D110",
"RolandD70": "D70",
"RolandDDR30": "DDR30",
"RolandJD990": "JD990",
"RolandMC202": "MC202",
"RolandMC303": "MC303",
"RolandMT32": "MT32",
"RolandR8": "R8",
"RolandS50": "S50",
"RolandSH09": "SH09",
"RolandSystem100": "System100",
"RolandTR505": "TR505",
"RolandTR606": "TR606",
"RolandTR626": "TR626",
"RolandTR707": "TR707",
"RolandTR727": "TR727",
"RolandTR808": "TR808",
"RolandTR909": "TR909",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kinda wanna add "909" as another alias but its a slippery slope

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah i guess 2 more or less characters doesnt make a lot of difference..

"SakataDPM48": "DPM48",
"SequentialCircuitsDrumtracks": "CircuitsDrumtracks",
"SequentialCircuitsTom": "CircuitsTom",
"SimmonsSDS400": "SDS400",
"SimmonsSDS5": "SDS5",
"SoundmastersR88": "R88",
"UnivoxMicroRhythmer12": "MicroRhythmer12",
"ViscoSpaceDrum": "SpaceDrum",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its real my neighbour told me

"XdrumLM8953": "LM8953",
"YamahaRM50": "RM50",
"YamahaRX21": "RX21",
"YamahaRX5": "RX5",
"YamahaRY30": "RY30",
"YamahaTG33": "TG33"
}
4 changes: 3 additions & 1 deletion website/src/repl/prebake.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Pattern, noteToMidi, valueToMidi } from '@strudel/core';
import { registerSynthSounds, registerZZFXSounds, samples } from '@strudel/webaudio';
import { aliasBank, registerSynthSounds, registerZZFXSounds, samples } from '@strudel/webaudio';
import { registerSamplesFromDB } from './idbutils.mjs';
import './piano.mjs';
import './files.mjs';
Expand Down Expand Up @@ -121,6 +121,8 @@ export async function prebake() {
},
),
]);

aliasBank(`${baseNoTrailing}/tidal-drum-machines-alias.json`);
}

const maxPan = noteToMidi('C8');
Expand Down
Loading