-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsynth_manager.js
More file actions
46 lines (42 loc) · 1.55 KB
/
Copy pathsynth_manager.js
File metadata and controls
46 lines (42 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
* SynthManager - Dynamic synth loader for multiple WASM synth engines
*/
class SynthManager {
static synths = {
oxisynth_sf3: { label: 'OxiSynth SF3', module: './oxisynth_piano_sf3.js', global: 'OxiSynthPianoSF3', esm: true },
oxisynth: { label: 'OxiSynth', module: './oxisynth_piano.js', global: 'OxiSynthPiano', esm: false },
spessasynth: { label: 'SpessaSynth', module: './spessasynth_piano.js', global: 'SpessaSynthPiano', esm: false },
fluidweb: { label: 'RustySynth', module: './fluidweb_piano.js', global: 'FluidWebPiano', esm: false }
};
static loaded = {};
static async load(name) {
const synth = this.synths[name];
if (!synth) return null;
if (!this.loaded[name]) {
// Check if already globally available
if (window[synth.global]) {
this.loaded[name] = window[synth.global];
} else {
if (synth.esm) {
await import(synth.module);
} else {
await new Promise((resolve, reject) => {
const script = document.createElement('script');
script.src = synth.module.replace('./', '');
script.onload = resolve;
script.onerror = reject;
document.head.appendChild(script);
});
}
this.loaded[name] = window[synth.global];
}
console.log('Loaded', name, ':', this.loaded[name]);
}
return this.loaded[name];
}
static async create(name) {
const SynthClass = await this.load(name);
return SynthClass ? new SynthClass() : null;
}
}
window.SynthManager = SynthManager;