cache loaded soundfonts

This commit is contained in:
Felix Roos 2022-08-07 23:53:14 +02:00
parent 8bd56d29d6
commit 3986c407ff
2 changed files with 13 additions and 5 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';
import { startPresetNote } from 'sfumato';
import { loadSoundfont } from './sfumato.mjs';
export { loadSoundfont, startPresetNote, getFontBufferSource, soundfontList };

View File

@ -1,7 +1,5 @@
import { Pattern } from '@strudel.cycles/core';
import { /* loadSoundfont, */ startPresetNote } from 'sfumato';
// TODO: find way to cache loadSoundfont
import { loadSoundfont as _loadSoundfont, startPresetNote } from 'sfumato';
Pattern.prototype.soundfont = function (sf, n = 0) {
return this.onTrigger((t, h, ct) => {
@ -14,3 +12,13 @@ Pattern.prototype.soundfont = function (sf, n = 0) {
stop(deadline + h.duration);
});
};
const soundfontCache = new Map();
export function loadSoundfont(url) {
if (soundfontCache.get(url)) {
return soundfontCache.get(url);
}
const sf = _loadSoundfont(url);
soundfontCache.set(url, sf);
return sf;
}