mirror of
https://github.com/eliasstepanik/strudel.git
synced 2026-01-11 13:48:40 +00:00
make soundfont base url configurable
This commit is contained in:
parent
7839d6b4bf
commit
e3b6884b86
@ -1,3 +1,4 @@
|
|||||||
|
import { persistentMap } from '@nanostores/persistent';
|
||||||
import { noteToMidi, freqToMidi, getSoundIndex } from '@strudel/core';
|
import { noteToMidi, freqToMidi, getSoundIndex } from '@strudel/core';
|
||||||
import {
|
import {
|
||||||
getAudioContext,
|
getAudioContext,
|
||||||
@ -9,6 +10,20 @@ import {
|
|||||||
} from '@strudel/webaudio';
|
} from '@strudel/webaudio';
|
||||||
import gm from './gm.mjs';
|
import gm from './gm.mjs';
|
||||||
|
|
||||||
|
export const defaultFontloaderConfig = {
|
||||||
|
soundfontUrl: 'https://felixroos.github.io/webaudiofontdata/sound'
|
||||||
|
}
|
||||||
|
|
||||||
|
export const fontloaderConfigMap = persistentMap('strudel-config-fontloader', defaultFontloaderConfig);
|
||||||
|
|
||||||
|
export function setSoundfontUrl(obj) {
|
||||||
|
fontloaderConfigMap.setKey('soundfontUrl', JSON.stringify(obj));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getSoundfontUrl() {
|
||||||
|
return JSON.parse(fontloaderConfigMap.get().soundfontUrl);
|
||||||
|
}
|
||||||
|
|
||||||
let loadCache = {};
|
let loadCache = {};
|
||||||
async function loadFont(name) {
|
async function loadFont(name) {
|
||||||
if (loadCache[name]) {
|
if (loadCache[name]) {
|
||||||
@ -16,7 +31,7 @@ async function loadFont(name) {
|
|||||||
}
|
}
|
||||||
const load = async () => {
|
const load = async () => {
|
||||||
// TODO: make soundfont source configurable
|
// TODO: make soundfont source configurable
|
||||||
const url = `https://felixroos.github.io/webaudiofontdata/sound/${name}.js`;
|
const url = `${getSoundfontUrl()}/${name}.js`;
|
||||||
const preset = await fetch(url).then((res) => res.text());
|
const preset = await fetch(url).then((res) => res.text());
|
||||||
let [_, data] = preset.split('={');
|
let [_, data] = preset.split('={');
|
||||||
return eval('{' + data);
|
return eval('{' + data);
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { getFontBufferSource, registerSoundfonts } from './fontloader.mjs';
|
import { getFontBufferSource, registerSoundfonts, setSoundfontUrl } from './fontloader.mjs';
|
||||||
import * as soundfontList from './list.mjs';
|
import * as soundfontList from './list.mjs';
|
||||||
import { startPresetNote } from 'sfumato';
|
import { startPresetNote } from 'sfumato';
|
||||||
import { loadSoundfont } from './sfumato.mjs';
|
import { loadSoundfont } from './sfumato.mjs';
|
||||||
|
|
||||||
export { loadSoundfont, startPresetNote, getFontBufferSource, soundfontList, registerSoundfonts };
|
export { loadSoundfont, startPresetNote, getFontBufferSource, soundfontList, registerSoundfonts, setSoundfontUrl };
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user