Skip to content

Commit

Permalink
(squash me) save setting in variable, not store
Browse files Browse the repository at this point in the history
  • Loading branch information
fnordomat authored and fnordomat committed Apr 1, 2024
1 parent e3b6884 commit e27f9ca
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions packages/soundfonts/fontloader.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { persistentMap } from '@nanostores/persistent';
import { noteToMidi, freqToMidi, getSoundIndex } from '@strudel/core';
import {
getAudioContext,
Expand All @@ -10,18 +9,11 @@ import {
} from '@strudel/webaudio';
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));
}
let defaultSoundfontUrl = 'https://felixroos.github.io/webaudiofontdata/sound'
let soundfontUrl = defaultSoundfontUrl

export function getSoundfontUrl() {
return JSON.parse(fontloaderConfigMap.get().soundfontUrl);
export function setSoundfontUrl(value) {
soundfontUrl = value
}

let loadCache = {};
Expand All @@ -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);
Expand Down

0 comments on commit e27f9ca

Please sign in to comment.