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

@ -1,6 +1,6 @@
import { getFontBufferSource } from './fontloader.mjs';
import * as soundfontList from './list.mjs';
import { loadSoundfont, startPresetNote } from 'sfumato';
import './sfumato.mjs';
globalThis.getFontBufferSource = getFontBufferSource;
globalThis.soundfontList = soundfontList;
globalThis.soundfontList = soundfontList;
export { loadSoundfont, startPresetNote, getFontBufferSource, soundfontList };

View file

@ -23,7 +23,8 @@
"homepage": "https://github.com/tidalcycles/strudel#readme",
"dependencies": {
"@strudel.cycles/core": "*",
"@strudel.cycles/webaudio": "^0.1.4"
"@strudel.cycles/webaudio": "^0.1.4",
"sfumato": "^0.1.2"
},
"devDependencies": {
"node-fetch": "^3.2.6"

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);
});
};