From 3c44b75416fb8bc18d946cc0ca14f360be5e702a Mon Sep 17 00:00:00 2001 From: w1n5t0n Date: Fri, 3 Apr 2026 18:20:29 +0100 Subject: [PATCH] =?UTF-8?q?fix(playground):=20decouple=20MIDIInput=20from?= =?UTF-8?q?=20C15Bridge=20=E2=80=94=20use=20SynthEngine=20interface=20(mem?= =?UTF-8?q?l-se4)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- playground/js/a-app.js | 3 ++- playground/js/synth/midi-input.js | 15 +++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/playground/js/a-app.js b/playground/js/a-app.js index 5453317..1db3f47 100644 --- a/playground/js/a-app.js +++ b/playground/js/a-app.js @@ -810,6 +810,7 @@ async function setActiveEngine(engine) { activeEngine = engine; c15 = engine; // keep alias in sync arpeggiator.setEngine(engine); + if (midiInput) midiInput.setEngine(engine); const btn = document.getElementById('synth-mode-btn'); if (btn) btn.textContent = engine.displayName; const engineDockBtn = document.querySelector('[data-drawer="params"]'); @@ -916,7 +917,7 @@ async function init() { if (el) el.textContent = msg; }; arpeggiator = new Arpeggiator(activeEngine); - midiInput = new MIDIInput(activeEngine.bridge); // MIDIInput still talks to the C15 bridge directly + midiInput = new MIDIInput(activeEngine); initMIDIControls(); // MIDI Output diff --git a/playground/js/synth/midi-input.js b/playground/js/synth/midi-input.js index c441175..dfd0707 100644 --- a/playground/js/synth/midi-input.js +++ b/playground/js/synth/midi-input.js @@ -1,9 +1,9 @@ // MIDI Input — receives notes and CCs from external MIDI controllers -// Uses Web MIDI API, routes note on/off to C15 bridge +// Uses Web MIDI API, routes note on/off through a SynthEngine interface export class MIDIInput { - constructor(bridge) { - this.bridge = bridge; + constructor(engine) { + this.engine = engine; this.enabled = false; this.midiAccess = null; this.selectedInputId = null; @@ -19,6 +19,9 @@ export class MIDIInput { set onInputsChange(fn) { this._onInputsChange = fn; } set onCC(fn) { this._onCC = fn; } + /** Hot-swap the engine (e.g. when the user switches synth engines). */ + setEngine(engine) { this.engine = engine; } + _status(msg) { console.log('[MIDI]', msg); this._onStatusChange?.(msg); @@ -130,15 +133,15 @@ export class MIDIInput { switch (type) { case 0x90: // Note On if (data2 > 0) { - this.bridge.noteOn(data1, data2 / 127); + this.engine.noteOn(data1, data2 / 127); } else { // Velocity 0 = note off - this.bridge.noteOff(data1); + this.engine.noteOff(data1); } break; case 0x80: // Note Off - this.bridge.noteOff(data1); + this.engine.noteOff(data1); break; case 0xb0: // Control Change