/ simulated_instruments / maraca
Sign in
simulated_instruments / maraca
maraca / webapp / src / mfiles.ts
43 lines · 1.3 KBCodeBlameHistory
aa03146Maraca shake simulator: MATLAB model and interactive web appmagland 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 'maraca_basis.m',
25 'maraca_hankel.m',
26 'maraca_impacts.m',
27 'maraca_radiate.m',
28 'maraca_rng.m',
29 'maraca_output.m',
30]);
32// Cheap content hash (FNV-1a) so the worker can key its caches on the code.
33export function hashMFiles(files: MFile[]): string {
34 let h = 0x811c9dc5;
35 for (const f of files) {
36 const s = f.name + ' ' + f.source + '';
37 for (let i = 0; i < s.length; i++) {
38 h ^= s.charCodeAt(i);
39 h = Math.imul(h, 0x01000193);
40 }
41 }
42 return (h >>> 0).toString(36);
↑↓ move↵openescclose