add webdirt with some default samples
This commit is contained in:
parent
15b32abadf
commit
f9f1b55185
76 changed files with 178 additions and 20 deletions
32
packages/webdirt/webdirt.mjs
Normal file
32
packages/webdirt/webdirt.mjs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import * as strudel from '@strudel.cycles/core';
|
||||
const { Pattern } = strudel;
|
||||
import * as WebDirt from 'WebDirt';
|
||||
|
||||
let webDirt;
|
||||
|
||||
/*
|
||||
example config:
|
||||
{
|
||||
sampleMapUrl: 'EmuSP12.json',
|
||||
sampleFolder: 'EmuSP12',
|
||||
}
|
||||
*/
|
||||
export function loadWebDirt(config) {
|
||||
webDirt = new WebDirt.WebDirt(config);
|
||||
webDirt.initializeWebAudio();
|
||||
}
|
||||
|
||||
Pattern.prototype.webdirt = function () {
|
||||
// create a WebDirt object and initialize Web Audio context
|
||||
return this._withHap((hap) => {
|
||||
const onTrigger = (time, e, currentTime) => {
|
||||
if (!webDirt) {
|
||||
throw new Error('WebDirt not initialized!');
|
||||
}
|
||||
const deadline = time - currentTime;
|
||||
const { s, n = 0 } = e.value;
|
||||
webDirt.playSample({ s, n }, deadline);
|
||||
};
|
||||
return hap.setContext({ ...hap.context, onTrigger });
|
||||
});
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue