/ simulated_instruments / bass
Sign in
simulated_instruments / bass
bass / webapp / src / mfiles.ts
44 lines · 1.3 KBCodeBlameHistory
0e92d35Pizzicato standup bass: coupled string-body modal model, numbl MATLAB reference, and interactive web appJeremy Magland 1// The MATLAB implementation, loaded from ../matlab at build time. The app
2// keeps an editable in-memory copy of these sources (see App.tsx); edits feed
3// straight into the render worker and are deliberately not persisted, so a
4// reload restores the shipped code.
6export interface MFile {
7 name: string;
8 source: string;
9}
11const modules = import.meta.glob('../../matlab/*.m', {
12 eager: true,
13 query: '?raw',
14 import: 'default',
15}) as Record<string, string>;
17export const DEFAULT_MFILES: MFile[] = Object.entries(modules)
18 .map(([path, source]) => ({ name: path.split('/').pop()!, source }))
19 .sort((a, b) => a.name.localeCompare(b.name));
21// Files the app itself executes. The others are entry points for running the
22// model from the numbl CLI, and editing them changes nothing in the browser.
23export const EXECUTED_BY_APP = new Set([
24 'bass_notes.m',
25 'bass_rng.m',
26 'bass_body.m',
27 'bass_assemble.m',
28 'bass_basis.m',
29 'bass_radiate.m',
30 'bass_output.m',
31]);
33// Cheap content hash (FNV-1a) so the worker can key its caches on the code.
34export function hashMFiles(files: MFile[]): string {
35 let h = 0x811c9dc5;
36 for (const f of files) {
37 const s = f.name + ' ' + f.source + '';
38 for (let i = 0; i < s.length; i++) {
39 h ^= s.charCodeAt(i);
40 h = Math.imul(h, 0x01000193);
41 }
42 }
43 return (h >>> 0).toString(36);
↑↓ move↵openescclose