fix cache + add cache reset

This commit is contained in:
Felix Roos 2022-05-29 22:44:26 +02:00
parent 7274a455a8
commit e27b8aeb66
3 changed files with 20 additions and 12 deletions

View File

@ -3740,15 +3740,15 @@
"___s": true
},
{
"comment": "/**\n *\n * Uses [webdirt](https://github.com/dktr0/WebDirt) as output.\n *\n * <details>\n * <summary>show supported Webdirt controls</summary>\n *\n * - s :: String, -- name of sample bank\n * - n :: Int, -- number of sample within a bank\n * - {@link gain} :: Number, -- clamped from 0 to 2; 1 is default and full-scale\n * - {@link overgain} :: Number, -- additional gain added to gain to go past clamp at 2\n * - {@link pan} :: Number, -- range: 0 to 1\n * - {@link nudge} :: Number, -- nudge the time of the sample forwards/backwards in seconds\n * - {@link speed} :: Number, -- speed / pitch of the sample\n * - {@link unit} :: String\n * - {@link note} :: Number, -- pitch offset in semitones\n * - {@link begin} :: Number, -- cut from sample start, normalized\n * - {@link end} :: Number, -- cut from sample end, normalized\n * - {@link cut} :: Int, -- samples with same cut number will interupt each other\n * - {@link shape} :: Number,\n * - {@link cutoff} :: Number, -- lowpass filter frequency\n * - {@link resonance} :: Number, -- lowpass filter resonance\n * - {@link hcutoff} :: Number, -- highpass filter frequency\n * - {@link hresonance} :: Number, -- highpass filter resonance\n * - {@link bandf} :: Number, -- bandpass filter frequency\n * - {@link bandq} :: Number, -- bandpass filter resonance\n * - {@link vowel} :: String, -- name of vowel ('a' | 'e' | 'i' | 'o' | 'u')\n * - {@link delay} :: Number, -- delay wet/dry mix\n * - {@link delaytime} :: Number, -- delay time in seconds\n * - {@link delayfeedback} :: Number, -- delay feedback\n * - {@link loop} :: Number, -- loop sample n times (relative to sample length)\n * - {@link crush} :: Number, -- bitcrusher (currently not working)\n * - {@link coarse} :: Number, -- coarse effect (currently not working)\n\n *\n * </details>\n *\n * @name webdirt\n * @memberof Pattern\n * @returns Pattern\n * @example\n * s(\"bd*2 hh sd hh\").n(\"<0 1>\").webdirt()\n */",
"comment": "/**\n *\n * Uses [webdirt](https://github.com/dktr0/WebDirt) as output.\n *\n * <details>\n * <summary>show supported Webdirt controls</summary>\n *\n * - s :: String, -- name of sample bank\n * - n :: Int, -- number of sample within a bank\n * - {@link gain} :: Number, -- clamped from 0 to 2; 1 is default and full-scale\n * - overgain :: Number, -- additional gain added to gain to go past clamp at 2\n * - {@link pan} :: Number, -- range: 0 to 1\n * - nudge :: Number, -- nudge the time of the sample forwards/backwards in seconds\n * - {@link speed} :: Number, -- speed / pitch of the sample\n * - {@link unit} :: String\n * - note :: Number, -- pitch offset in semitones\n * - {@link begin} :: Number, -- cut from sample start, normalized\n * - {@link end} :: Number, -- cut from sample end, normalized\n * - {@link cut} :: Int, -- samples with same cut number will interupt each other\n * - {@link cutoff} :: Number, -- lowpass filter frequency\n * - {@link resonance} :: Number, -- lowpass filter resonance\n * - {@link hcutoff} :: Number, -- highpass filter frequency\n * - {@link hresonance} :: Number, -- highpass filter resonance\n * - {@link bandf} :: Number, -- bandpass filter frequency\n * - {@link bandq} :: Number, -- bandpass filter resonance\n * - {@link vowel} :: String, -- name of vowel ('a' | 'e' | 'i' | 'o' | 'u')\n * - delay :: Number, -- delay wet/dry mix\n * - delaytime :: Number, -- delay time in seconds\n * - delayfeedback :: Number, -- delay feedback\n * - {@link loop} :: Number, -- loop sample n times (relative to sample length)\n * - {@link crush} :: Number, -- bitcrusher (currently not working)\n * - {@link coarse} :: Number, -- coarse effect (currently not working)\n * - {@link shape} :: Number, -- (currently not working)\n\n *\n * </details>\n *\n * @name webdirt\n * @memberof Pattern\n * @returns Pattern\n * @example\n * s(\"bd*2 hh sd hh\").n(\"<0 1>\").webdirt()\n */",
"meta": {
"filename": "webdirt.mjs",
"lineno": 19,
"lineno": 20,
"columnno": 0,
"path": "/home/felix/projects/strudel/packages/webdirt",
"code": {}
},
"description": "<p>Uses <a href=\"https://github.com/dktr0/WebDirt\">webdirt</a> as output.</p>\n<details>\n<summary>show supported Webdirt controls</summary>\n<ul>\n<li>s :: String, -- name of sample bank</li>\n<li>n :: Int, -- number of sample within a bank</li>\n<li>{@link gain} :: Number, -- clamped from 0 to 2; 1 is default and full-scale</li>\n<li>{@link overgain} :: Number, -- additional gain added to gain to go past clamp at 2</li>\n<li>{@link pan} :: Number, -- range: 0 to 1</li>\n<li>{@link nudge} :: Number, -- nudge the time of the sample forwards/backwards in seconds</li>\n<li>{@link speed} :: Number, -- speed / pitch of the sample</li>\n<li>{@link unit} :: String</li>\n<li>{@link note} :: Number, -- pitch offset in semitones</li>\n<li>{@link begin} :: Number, -- cut from sample start, normalized</li>\n<li>{@link end} :: Number, -- cut from sample end, normalized</li>\n<li>{@link cut} :: Int, -- samples with same cut number will interupt each other</li>\n<li>{@link shape} :: Number,</li>\n<li>{@link cutoff} :: Number, -- lowpass filter frequency</li>\n<li>{@link resonance} :: Number, -- lowpass filter resonance</li>\n<li>{@link hcutoff} :: Number, -- highpass filter frequency</li>\n<li>{@link hresonance} :: Number, -- highpass filter resonance</li>\n<li>{@link bandf} :: Number, -- bandpass filter frequency</li>\n<li>{@link bandq} :: Number, -- bandpass filter resonance</li>\n<li>{@link vowel} :: String, -- name of vowel ('a' | 'e' | 'i' | 'o' | 'u')</li>\n<li>{@link delay} :: Number, -- delay wet/dry mix</li>\n<li>{@link delaytime} :: Number, -- delay time in seconds</li>\n<li>{@link delayfeedback} :: Number, -- delay feedback</li>\n<li>{@link loop} :: Number, -- loop sample n times (relative to sample length)</li>\n<li>{@link crush} :: Number, -- bitcrusher (currently not working)</li>\n<li>{@link coarse} :: Number, -- coarse effect (currently not working)</li>\n</ul>\n</details>",
"description": "<p>Uses <a href=\"https://github.com/dktr0/WebDirt\">webdirt</a> as output.</p>\n<details>\n<summary>show supported Webdirt controls</summary>\n<ul>\n<li>s :: String, -- name of sample bank</li>\n<li>n :: Int, -- number of sample within a bank</li>\n<li>{@link gain} :: Number, -- clamped from 0 to 2; 1 is default and full-scale</li>\n<li>overgain :: Number, -- additional gain added to gain to go past clamp at 2</li>\n<li>{@link pan} :: Number, -- range: 0 to 1</li>\n<li>nudge :: Number, -- nudge the time of the sample forwards/backwards in seconds</li>\n<li>{@link speed} :: Number, -- speed / pitch of the sample</li>\n<li>{@link unit} :: String</li>\n<li>note :: Number, -- pitch offset in semitones</li>\n<li>{@link begin} :: Number, -- cut from sample start, normalized</li>\n<li>{@link end} :: Number, -- cut from sample end, normalized</li>\n<li>{@link cut} :: Int, -- samples with same cut number will interupt each other</li>\n<li>{@link cutoff} :: Number, -- lowpass filter frequency</li>\n<li>{@link resonance} :: Number, -- lowpass filter resonance</li>\n<li>{@link hcutoff} :: Number, -- highpass filter frequency</li>\n<li>{@link hresonance} :: Number, -- highpass filter resonance</li>\n<li>{@link bandf} :: Number, -- bandpass filter frequency</li>\n<li>{@link bandq} :: Number, -- bandpass filter resonance</li>\n<li>{@link vowel} :: String, -- name of vowel ('a' | 'e' | 'i' | 'o' | 'u')</li>\n<li>delay :: Number, -- delay wet/dry mix</li>\n<li>delaytime :: Number, -- delay time in seconds</li>\n<li>delayfeedback :: Number, -- delay feedback</li>\n<li>{@link loop} :: Number, -- loop sample n times (relative to sample length)</li>\n<li>{@link crush} :: Number, -- bitcrusher (currently not working)</li>\n<li>{@link coarse} :: Number, -- coarse effect (currently not working)</li>\n<li>{@link shape} :: Number, -- (currently not working)</li>\n</ul>\n</details>",
"name": "webdirt",
"memberof": "Pattern",
"returns": [
@ -3762,7 +3762,7 @@
"scope": "static",
"longname": "Pattern.webdirt",
"kind": "member",
"___id": "T000002R004015",
"___id": "T000002R004040",
"___s": true
},
{
@ -3839,6 +3839,7 @@
"/home/felix/projects/strudel/packages/webaudio/scheduler.mjs",
"/home/felix/projects/strudel/packages/webaudio/webaudio.mjs",
"/home/felix/projects/strudel/packages/webdirt/index.mjs",
"/home/felix/projects/strudel/packages/webdirt/sampler.mjs",
"/home/felix/projects/strudel/packages/webdirt/webdirt.mjs",
"/home/felix/projects/strudel/packages/xen/index.mjs",
"/home/felix/projects/strudel/packages/xen/test/xen.test.mjs",
@ -3846,7 +3847,7 @@
"/home/felix/projects/strudel/packages/xen/tunejs.js",
"/home/felix/projects/strudel/packages/xen/xen.mjs"
],
"___id": "T000002R014031",
"___id": "T000002R014063",
"___s": true
}
]

View File

@ -22,14 +22,16 @@ export const playSample = async (url) => playBuffer(await loadBuffer(url)); */
// Array<{ "url":string, "bank": string, "n": number}>
// ritchse/tidal-drum-machines/tree/main/machines/AkaiLinn
const githubCache = {};
let loaded;
let sampleCache = { current: undefined };
export const loadGithubSamples = async (path, nameFn) => {
const storageKey = 'loadGithubSamples ' + path;
const stored = localStorage.getItem(storageKey);
if (stored) {
return JSON.parse(stored);
console.log('[sampler]: loaded sample list from localstorage', path);
githubCache[path] = JSON.parse(stored);
}
if (githubCache[path]) {
sampleCache.current = githubCache[path];
return githubCache[path];
}
console.log('[sampler]: fetching sample list from github', path);
@ -62,10 +64,14 @@ export const loadGithubSamples = async (path, nameFn) => {
console.error('[sampler]: failed to fetch sample list from github', err);
return;
}
loaded = githubCache[path];
localStorage.setItem(storageKey, JSON.stringify(loaded));
console.log('[sampler]: loaded samples:', loaded);
sampleCache.current = githubCache[path];
localStorage.setItem(storageKey, JSON.stringify(sampleCache.current));
console.log('[sampler]: loaded samples:', sampleCache.current);
return githubCache[path];
};
export const getLoadedSamples = () => loaded;
export const resetLoadedSamples = () => {
sampleCache.current = undefined;
};
export const getLoadedSamples = () => sampleCache.current;

View File

@ -13,7 +13,7 @@ import './App.css';
import logo from './logo.svg';
import * as tunes from './tunes.mjs';
import * as WebDirt from 'WebDirt';
import { loadWebDirt } from '@strudel.cycles/webdirt';
import { loadWebDirt, resetLoadedSamples } from '@strudel.cycles/webdirt';
evalScope(
Tone,
@ -173,6 +173,7 @@ function App() {
setCode(_code);
cleanupDraw();
cleanupUi();
resetLoadedSamples();
const parsed = await evaluate(_code);
setPattern(parsed.pattern);
setActiveCode(_code);