1// The sample map songs load (`samples('jev-samples/strudel.json')`), from the 2// repo's samples/ folder, one folder per sound. One builder for both of its 3// makers: the site's route (pages/jev-samples/strudel.json.js, from Vite's 4// glob) and the headless tools measuring a worktree's own samples 5// (tools/worktree-samples/, from the disk), so the two cannot drift. 6 7// The files a sound is made of. The site's glob names the same list (a glob 8// pattern must be a literal there); sampleMap.test.mjs holds the two together. 9export const SAMPLE_EXTENSIONS = ['mp3', 'wav', 'ogg']; 10 11// `files`: [path, url] pairs, `path` ending in `samples/<sound>/<file>`, 12// `url` where the page fetches it. Strudel prefixes every entry with 13// `_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}