pass all value props to webdirt + list available

This commit is contained in:
Felix Roos 2022-05-29 09:55:58 +02:00
parent f9f1b55185
commit e1fb0acff7

View File

@ -16,6 +16,42 @@ export function loadWebDirt(config) {
webDirt.initializeWebAudio();
}
/**
* Uses [webdirt](https://github.com/dktr0/WebDirt) as output.
*
* Supported Webdirt controls:
*
* - s :: String, -- name of sample bank (ie. old-style with sampleMap)
* - n :: Int, -- number of sample within a bank (ie. old-style with sampleMap)
* - whenPosix :: Number, -- when to play the sample, in POSIX/epoch-1970 time
* - when :: Number, -- when to play the sample, in audio context time
* - gain :: Number, -- clamped from 0 to 2; 1 is default and full-scale
* - overgain :: Number, -- additional gain added to gain to go past clamp at 2
* - pan :: Number, -- range: 0 to 1
* - nudge :: Number, -- nudge the time of the sample forwards/backwards in seconds
* - speed :: Number,
* - note :: Number,
* - begin :: Number,
* - end :: Number,
* - cut :: Int,
* - shape :: Number,
* - cutoff :: Number,
* - resonance :: Number,
* - hcutoff :: Number,
* - hresonance :: Number,
* - bandf :: Number,
* - bandq :: Number,
* - vowel :: String,
* - delay :: Number,
* - delaytime :: Number,
* - delayfeedback :: Number,
* - loop :: Number,
* - crush :: Number,
* - coarse :: Number,
* - unit :: String
*
* @returns Pattern
*/
Pattern.prototype.webdirt = function () {
// create a WebDirt object and initialize Web Audio context
return this._withHap((hap) => {
@ -24,8 +60,11 @@ Pattern.prototype.webdirt = function () {
throw new Error('WebDirt not initialized!');
}
const deadline = time - currentTime;
const { s, n = 0 } = e.value;
webDirt.playSample({ s, n }, deadline);
const { s, n = 0, ...rest } = e.value || {};
if (!s) {
console.warn('webdirt: no "s" was set!');
}
webDirt.playSample({ s, n, ...rest }, deadline);
};
return hap.setContext({ ...hap.context, onTrigger });
});