(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 {
getAudioContext,
@ -10,18 +9,11 @@ import {
} from '@strudel/webaudio';
import gm from './gm.mjs';
export const defaultFontloaderConfig = {
soundfontUrl: 'https://felixroos.github.io/webaudiofontdata/sound'
}
let defaultSoundfontUrl = 'https://felixroos.github.io/webaudiofontdata/sound';
let soundfontUrl = defaultSoundfontUrl;
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);
export function setSoundfontUrl(value) {
soundfontUrl = value;
}
let loadCache = {};
@ -31,7 +23,7 @@ async function loadFont(name) {
}
const load = async () => {
// TODO: make soundfont source configurable
const url = `${getSoundfontUrl()}/${name}.js`;
const url = `${soundfontUrl}/${name}.js`;
const preset = await fetch(url).then((res) => res.text());
let [_, data] = preset.split('={');
return eval('{' + data);