diff --git a/classes/Drums.js b/classes/Drums.js index fe0fec0..df883f4 100644 --- a/classes/Drums.js +++ b/classes/Drums.js @@ -6,30 +6,41 @@ import { parseArgument } from '../helpers/parseArguments'; import BufferLoader from '../helpers/BufferLoader'; import drumMap from '../helpers/drumMap'; +const typeMap = { + 0: 'acoustic', + 1: '808' +} + // Taking the easy route here: let's store the drums in // global variables here so each instance of the `Drums` // class has access to them. -let loadingDrums = false; -let drumBuffers = []; +let loadingDrums = { + acousting: false, + 808: false, +} + +let drumBuffers = { + acoustic: [], + 808: [], +} class Drums extends Block { constructor(...args) { super(...args); - // In the future we can support different drum sets - // using a simple integer argument. + // this.arguments will be used to set the type this.type = this.arguments[0] || parseArgument(0); + this.drumType = typeMap[this.type.next()]; - // Super basic lazy loading of drum sounds. - // If the buffers don't already exist and we're - // not trying to load them... do that. - if (!drumBuffers.length && !loadingDrums) { + // if we don't have buffers for this specific type and we're + // not already loading them, go ahead and load them. + if (!drumBuffers[this.drumType].length || !loadingDrums[this.drumType]) { this.loadDrumSounds(); } } schedule(start, stop, note, envelopeMode) { - if (!drumBuffers.length || loadingDrums) return; + if (!drumBuffers[this.drumType].length || loadingDrums[this.drumType]) return; // we only have 12 samples available but we shouldn't // burden the user with that knowledge so let's use // mod 12, which allows them to use chords, scales, @@ -37,7 +48,7 @@ class Drums extends Block { const drumSound = note % 12; const sample = context.createBufferSource(); - sample.buffer = drumBuffers[drumSound]; + sample.buffer = drumBuffers[this.drumType][drumSound]; sample.start(start); sample.stop(stop); @@ -57,14 +68,15 @@ class Drums extends Block { sample.connect(this.getOutput()); } loadDrumSounds() { - loadingDrums = true; + loadingDrums[this.drumType] = true; + // Decide which map to use based on type // Get a list of files - const files = Object.keys(drumMap).map(key => drumMap[key].file); + const files = Object.keys(drumMap[this.drumType]).map(key => drumMap[this.drumType][key].file); // Load the files! const loader = new BufferLoader(context, files, list => { // set our global variable to the list of buffers. Done. - drumBuffers = list; - loadingDrums = false; + drumBuffers[this.drumType] = list; + loadingDrums[this.drumType] = false; }); loader.load(); } diff --git a/helpers/drumMap.js b/helpers/drumMap.js index 74f8d7c..0f819b2 100644 --- a/helpers/drumMap.js +++ b/helpers/drumMap.js @@ -1,52 +1,105 @@ const drumMap = { - 0: { - file: '/audio/acoustic/kick1.mp3', - label: 'acoustic kick 1' + acoustic: { + 0: { + file: '/audio/acoustic/kick1.mp3', + label: 'acoustic kick 1' + }, + 1: { + file: '/audio/acoustic/kick2.mp3', + label: 'acoustic kick 2' + }, + 2: { + file: '/audio/acoustic/kick3.mp3', + label: 'acoustic kick 3' + }, + 3: { + file: '/audio/acoustic/snare1.mp3', + label: 'acoustic snare 1' + }, + 4: { + file: '/audio/acoustic/snare2.mp3', + label: 'acoustic snare 2' + }, + 5: { + file: '/audio/acoustic/snare3.mp3', + label: 'acoustic snare 3' + }, + 6: { + file: '/audio/acoustic/hihat1.mp3', + label: 'acoustic hat 1' + }, + 7: { + file: '/audio/acoustic/hihat2.mp3', + label: 'acoustic hat 2' + }, + 8: { + file: '/audio/acoustic/hihat_open1.mp3', + label: 'acoustic hat (open) 1' + }, + 9: { + file: '/audio/acoustic/hihat_open2.mp3', + label: 'acoustic hat (open) 2' + }, + 10: { + file: '/audio/acoustic/hihat_open3.mp3', + label: 'acoustic hat (open) 3' + }, + 11: { + file: '/audio/acoustic/rim1.mp3', + label: 'acoustic rim' + }, }, - 1: { - file: '/audio/acoustic/kick2.mp3', - label: 'acoustic kick 2' - }, - 2: { - file: '/audio/acoustic/kick3.mp3', - label: 'acoustic kick 3' - }, - 3: { - file: '/audio/acoustic/snare1.mp3', - label: 'acoustic snare 1' - }, - 4: { - file: '/audio/acoustic/snare2.mp3', - label: 'acoustic snare 2' - }, - 5: { - file: '/audio/acoustic/snare3.mp3', - label: 'acoustic snare 3' - }, - 6: { - file: '/audio/acoustic/hihat1.mp3', - label: 'acoustic hat 1' - }, - 7: { - file: '/audio/acoustic/hihat2.mp3', - label: 'acoustic hat 2' - }, - 8: { - file: '/audio/acoustic/hihat_open1.mp3', - label: 'acoustic hat (open) 1' - }, - 9: { - file: '/audio/acoustic/hihat_open2.mp3', - label: 'acoustic hat (open) 2' - }, - 10: { - file: '/audio/acoustic/hihat_open3.mp3', - label: 'acoustic hat (open) 3' - }, - 11: { - file: '/audio/acoustic/rim1.mp3', - label: 'acoustic rim' + 808: { + 0: { + file: '/audio/808/kick1.mp3', + label: '808 kick 1' + }, + 1: { + file: '/audio/808/kick2.mp3', + label: '808 kick 2' + }, + 2: { + file: '/audio/808/kick3.mp3', + label: '808 kick 3' + }, + 3: { + file: '/audio/808/snare1.mp3', + label: '808 snare 1' + }, + 4: { + file: '/audio/808/snare2.mp3', + label: '808 snare 2' + }, + 5: { + file: '/audio/808/snare3.mp3', + label: '808 snare 3' + }, + 6: { + file: '/audio/808/hihat1.mp3', + label: '808 hat 1' + }, + 7: { + file: '/audio/808/hihat2.mp3', + label: '808 hat 2' + }, + 8: { + file: '/audio/808/hihat_open1.mp3', + label: '808 hat (open) 1' + }, + 9: { + file: '/audio/808/hihat_open2.mp3', + label: '808 hat (open) 2' + }, + 10: { + file: '/audio/808/hihat_open3.mp3', + label: '808 hat (open) 3' + }, + 11: { + file: '/audio/808/rim1.mp3', + label: '808 rim' + }, }, }; + export default drumMap; diff --git a/public/audio/808/hihat1.mp3 b/public/audio/808/hihat1.mp3 new file mode 100644 index 0000000..a38e220 Binary files /dev/null and b/public/audio/808/hihat1.mp3 differ diff --git a/public/audio/808/hihat2.mp3 b/public/audio/808/hihat2.mp3 new file mode 100644 index 0000000..e7ceeda Binary files /dev/null and b/public/audio/808/hihat2.mp3 differ diff --git a/public/audio/808/hihat_open1.mp3 b/public/audio/808/hihat_open1.mp3 new file mode 100644 index 0000000..5024cf8 Binary files /dev/null and b/public/audio/808/hihat_open1.mp3 differ diff --git a/public/audio/808/hihat_open2.mp3 b/public/audio/808/hihat_open2.mp3 new file mode 100644 index 0000000..5024cf8 Binary files /dev/null and b/public/audio/808/hihat_open2.mp3 differ diff --git a/public/audio/808/hihat_open3.mp3 b/public/audio/808/hihat_open3.mp3 new file mode 100644 index 0000000..97c3068 Binary files /dev/null and b/public/audio/808/hihat_open3.mp3 differ diff --git a/public/audio/808/kick1.mp3 b/public/audio/808/kick1.mp3 new file mode 100644 index 0000000..9056fa8 Binary files /dev/null and b/public/audio/808/kick1.mp3 differ diff --git a/public/audio/808/kick2.mp3 b/public/audio/808/kick2.mp3 new file mode 100644 index 0000000..dfb7eeb Binary files /dev/null and b/public/audio/808/kick2.mp3 differ diff --git a/public/audio/808/kick3.mp3 b/public/audio/808/kick3.mp3 new file mode 100644 index 0000000..5ecd36d Binary files /dev/null and b/public/audio/808/kick3.mp3 differ diff --git a/public/audio/808/rim1.mp3 b/public/audio/808/rim1.mp3 new file mode 100644 index 0000000..60049f3 Binary files /dev/null and b/public/audio/808/rim1.mp3 differ diff --git a/public/audio/808/snare1.mp3 b/public/audio/808/snare1.mp3 new file mode 100644 index 0000000..56f1472 Binary files /dev/null and b/public/audio/808/snare1.mp3 differ diff --git a/public/audio/808/snare2.mp3 b/public/audio/808/snare2.mp3 new file mode 100644 index 0000000..1fa019b Binary files /dev/null and b/public/audio/808/snare2.mp3 differ diff --git a/public/audio/808/snare3.mp3 b/public/audio/808/snare3.mp3 new file mode 100644 index 0000000..de08c36 Binary files /dev/null and b/public/audio/808/snare3.mp3 differ