jevstrudel.git / website / src / jev / sampleMap.mjs

The sample map songs load (samples('jev-samples/strudel.json')), from the repo's samples/ folder, one folder per sound. One builder for both of its makers: the site's route (pages/jev-samples/strudel.json.js, from Vite's glob) and the headless tools measuring a worktree's own samples (tools/worktree-samples/, from the disk), so the two cannot drift.

The files a sound is made of. The site's glob names the same list (a glob pattern must be a literal there); sampleMap.test.mjs holds the two together.

9export const SAMPLE_EXTENSIONS = ['mp3', 'wav', 'ogg'];

files: [path, url] pairs, path ending in samples/<sound>/<file>, url where the page fetches it. Strudel prefixes every entry with _base, so a url's leading slash and query are dropped.

14export function sampleMap(files) {
15  const map = { _base: '/' };
16  for (const [path, url] of [...files].sort(([a], [b]) => a.localeCompare(b))) {
17    const sound = path.split('/').at(-2);
18    (map[sound] ??= []).push(url.replace(/^\//, '').replace(/\?.*$/, ''));
19  }
20  return map;
21}