(squash me) save setting in variable, not store

This commit is contained in:
fnordomat 2024-04-01 17:14:27 +02:00
parent e3b6884b86
commit b233c33f56

View File

@ -1,4 +1,3 @@
import { persistentMap } from '@nanostores/persistent';
import { noteToMidi, freqToMidi, getSoundIndex } from '@strudel/core'; import { noteToMidi, freqToMidi, getSoundIndex } from '@strudel/core';
import { import {
getAudioContext, getAudioContext,
@ -10,18 +9,11 @@ import {
} from '@strudel/webaudio'; } from '@strudel/webaudio';
import gm from './gm.mjs'; import gm from './gm.mjs';
export const defaultFontloaderConfig = { let defaultSoundfontUrl = 'https://felixroos.github.io/webaudiofontdata/sound';
soundfontUrl: 'https://felixroos.github.io/webaudiofontdata/sound' let soundfontUrl = defaultSoundfontUrl;
}
export const fontloaderConfigMap = persistentMap('strudel-config-fontloader', defaultFontloaderConfig); export function setSoundfontUrl(value) {
soundfontUrl = value;
export function setSoundfontUrl(obj) {
fontloaderConfigMap.setKey('soundfontUrl', JSON.stringify(obj));
}
export function getSoundfontUrl() {
return JSON.parse(fontloaderConfigMap.get().soundfontUrl);
} }
let loadCache = {}; let loadCache = {};
@ -31,7 +23,7 @@ async function loadFont(name) {
} }
const load = async () => { const load = async () => {
// TODO: make soundfont source configurable // TODO: make soundfont source configurable
const url = `${getSoundfontUrl()}/${name}.js`; const url = `${soundfontUrl}/${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);