add sfumato soundfont player

This commit is contained in:
Felix Roos 2022-08-07 21:30:02 +02:00
parent 467b3db824
commit 8bd56d29d6
4 changed files with 51 additions and 6 deletions

View file

@ -0,0 +1,16 @@
import { Pattern } from '@strudel.cycles/core';
import { /* loadSoundfont, */ startPresetNote } from 'sfumato';
// TODO: find way to cache loadSoundfont
Pattern.prototype.soundfont = function (sf, n = 0) {
return this.onTrigger((t, h, ct) => {
const ctx = getAudioContext();
const note = getPlayableNoteValue(h);
const preset = sf.presets[n % sf.presets.length];
const deadline = ctx.currentTime + t - ct;
const args = [ctx, preset, toMidi(note), deadline];
const stop = startPresetNote(...args);
stop(deadline + h.duration);
});
};