feat(web-audio): implement Class56 MIDI player with FluidSynth and TimGM6mb.sf2

Enables authentic General MIDI music playback in `2006Scape-Web` over both HTTP and HTTPS by implementing the missing `Class56_Sub1_Sub1` web adapter and wiring `js-synthesizer` (`libfluidsynth-2.3.0.js`) with the `TimGM6mb.sf2` SoundFont.

### Java MIDI Pipeline Bridge
- `Class56_Sub1_Sub1.java`:
  - Added `org.scape2006.web` implementation of `Class56` forwarding `method827`, `method828`, `method830`, `method831`, `method832`, and `method833` to `DesktopHooks.playMidiBytes`, `setSignlinkVolume`, and `stopSignlinkMidi`.
- `build.gradle`:
  - Patched `Game.constructMusic()` in `syncSharedSources` to instantiate `new Class56_Sub1_Sub1()` directly instead of `Class.forName("Class56_Sub1_Sub1").newInstance()`, preventing `musicIsntNull()` from returning `false`.

### FluidSynth Web Audio & Caching
- `src/main/webapp/libfluidsynth-2.3.0.js`, `js-synthesizer.min.js`, `TimGM6mb.sf2`:
  - Bundled FluidSynth WASM/JS synthesizer and General MIDI SoundFont (`5.8M`) locally for offline and plain-HTTP LAN compatibility.
- `src/main/webapp/index.html`:
  - Wired `window.scapeWebAudio` (`ensureFluidSynth`, `playMidi`, `setMidiVolume`, `stopMidi`) to load `TimGM6mb.sf2`, loop tracks via `setPlayerLoop(-1)`, and resume pending MIDI on first user gesture.
- `src/main/webapp/sw.js`:
  - Added `libfluidsynth-2.3.0.js`, `js-synthesizer.min.js`, and `TimGM6mb.sf2` to `SHELL_ASSETS` and bumped `CACHE_VERSION` to `2006scape-web-v5`.
This commit is contained in:
Dark98 committed 2026-12-01 14:53:04 +00:00
1 parent 4bcb91c3a2
commit 02c3d8fb10
7 files changed
+164 -15

No files matched your search

@@ -0,0 +1,44 @@
package org.scape2006.web;
/**
* Web MIDI player implementation of Class56, bridging Game's music pipeline
* to DesktopHooks / window.scapeWebAudio (WebAudioTinySynth).
*/
public final class Class56_Sub1_Sub1 extends Class56 {
@Override
void method827(int volume, byte[] midiBytes, int unused, boolean loop) {
if (midiBytes != null && midiBytes.length > 0) {
DesktopHooks.playMidiBytes(midiBytes, volume);
} else {
DesktopHooks.stopSignlinkMidi();
}
}
@Override
void method828() {
DesktopHooks.stopSignlinkMidi();
}
@Override
void method830(int volume, int fade) {
DesktopHooks.setSignlinkVolume(volume);
}
@Override
void method831(int volume) {
DesktopHooks.setSignlinkVolume(volume);
}
@Override
void method832(int i) {
if (i > -90) {
DesktopHooks.stopSignlinkMidi();
}
}
@Override
void method833() {
DesktopHooks.stopSignlinkMidi();
}
}