Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: make soundfont base url configurable #1040

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion packages/soundfonts/fontloader.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,21 @@ import {
} from '@strudel/webaudio';
import gm from './gm.mjs';

let defaultSoundfontUrl = 'https://felixroos.github.io/webaudiofontdata/sound';
let soundfontUrl = defaultSoundfontUrl;

export function setSoundfontUrl(value) {
soundfontUrl = value;
}

let loadCache = {};
async function loadFont(name) {
if (loadCache[name]) {
return loadCache[name];
}
const load = async () => {
// TODO: make soundfont source configurable
const url = `https://felixroos.github.io/webaudiofontdata/sound/${name}.js`;
const url = `${soundfontUrl}/${name}.js`;
const preset = await fetch(url).then((res) => res.text());
let [_, data] = preset.split('={');
return eval('{' + data);
Expand Down
4 changes: 2 additions & 2 deletions packages/soundfonts/index.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getFontBufferSource, registerSoundfonts } from './fontloader.mjs';
import { getFontBufferSource, registerSoundfonts, setSoundfontUrl } from './fontloader.mjs';
import * as soundfontList from './list.mjs';
import { startPresetNote } from 'sfumato';
import { loadSoundfont } from './sfumato.mjs';

export { loadSoundfont, startPresetNote, getFontBufferSource, soundfontList, registerSoundfonts };
export { loadSoundfont, startPresetNote, getFontBufferSource, soundfontList, registerSoundfonts, setSoundfontUrl };
Loading