fix: GUI VST native window qua bridge + audio path bridge (SF2 preview/play câm)

- open_vst_gui: bo WebviewWindowBuilder/thread, chi push_control type=4 (hwnd=0 -> bridge tao window)
- main.cpp: create_native_vst_window (class SonicForge_Native_VST3_Class, 800x600, khong TOPMOST),
  tao trong ChannelWorker job, map guiWindows, capture arg2 by value (fix dangling)
- app.jsx: guard isBridgeActive() 8 cho -> bridge active thi moi note di router -> pushEvent -> bridge
  (truoc day SF2 cam vi HAS_PYFLUIDSYNTH=FALSE -> /soundfont-render 501; VST3 path cu dung nativeSf/Carla)
- E2E: SF2 NOTE_ON qua dispatchMidiEvent -> SHM peak 0.029745; Nexus GUI native hwnd OK (license/preset)
- docs: TASKS.md + TEST_NOTES.md ghi batch fix + ket qua; gitignore vendor/junk
This commit is contained in:
2026-08-12 22:12:43 +07:00
parent c3368d0a91
commit d8f8506077
37 changed files with 2170 additions and 419 deletions
+4 -4
View File
@@ -1,5 +1,5 @@
// SonicForge Studio API Service
window.API_BASE_URL = window.API_BASE_URL || window.location.origin;
window.API_BASE_URL = (window.API_BASE_URL || window.location.origin).replace(/\/+$/, '');
(function() {
function getAuthToken() {
@@ -115,9 +115,9 @@ window.API_BASE_URL = window.API_BASE_URL || window.location.origin;
listSoundfontInstruments: (sfId) => apiRequest(`/api/v1/plugins/soundfont-instruments/${sfId}`, { method: 'GET' }),
// Native Host Bridge (daw_vst_bridge C++): trạng thái + load asset +
// tail bridge.log (E1/E2/E5).
bridgeStatus: () => apiRequest('/api/v1/bridge/status', { method: 'GET' }),
bridgeLoad: (payload) => apiRequest('/api/v1/bridge/load', { method: 'POST', body: JSON.stringify(payload) }),
bridgeLog: (lines = 100) => apiRequest(`/api/v1/bridge/log?lines=${lines}`, { method: 'GET' }),
bridgeStatus: () => apiRequest('/api/v1/plugins/bridge/status', { method: 'GET' }),
bridgeLoad: (payload) => apiRequest('/api/v1/plugins/bridge/load', { method: 'POST', body: JSON.stringify(payload) }),
bridgeLog: (lines = 100) => apiRequest(`/api/v1/plugins/bridge/log?lines=${lines}`, { method: 'GET' }),
getAIPresets: () => apiRequest('/api/v1/ai/presets', { method: 'GET' }),
saveAIPreset: (preset) => apiRequest('/api/v1/ai/presets', { method: 'POST', body: JSON.stringify(preset) }),
deleteAIPreset: (presetId) => apiRequest(`/api/v1/ai/presets/${presetId}`, { method: 'DELETE' }),
@@ -20,6 +20,30 @@
if (this._statusCb) this._statusCb({ connected: !!connected });
},
/** Fix C: re-establish bridge routing once audio frames arrive again
* after bridge-down. Same wiring as the bootstrap block in app.jsx
* (getAudioContext -> BridgeAudioNode.init -> AudioRoutingEngine.connect). */
_reconnectInFlight: false,
_reconnectIfNeeded: function () {
if (this._reconnectInFlight) return;
this._reconnectInFlight = true;
var self = this;
var finish = function () { self._reconnectInFlight = false; };
try {
var ctx = (typeof getAudioContext === 'function') ? getAudioContext() : (window.__sharedAudioCtx || null);
if (ctx && window.BridgeAudioNode && window.AudioRoutingEngine) {
window.BridgeAudioNode.init(ctx);
window.AudioRoutingEngine.connect(window.BridgeAudioNode, null, null);
}
if (window.SonicMidiRouter) window.SonicMidiRouter.setBridgeConnected(true);
this._notifyStatus(true);
console.warn('[BridgeService] bridge recovered — routing re-established.');
} catch (e) {
console.warn('[BridgeService] reconnect failed:', e);
}
finish();
},
_init: function () {
if (!this._tauri()) {
// Dev mode (Linux / plain browser): no Tauri -> log-only, app uses SonicSF.
@@ -29,6 +53,9 @@
var self = this;
try {
window.__TAURI__.event.listen('bridge-audio', function (e) {
// Bridge recovered after bridge-down (or never bootstrapped):
// audio frames flow again -> re-establish routing (Fix C).
if (!self.isBridgeConnected) self._reconnectIfNeeded();
if (self._audioCb) self._audioCb(e.payload.l, e.payload.r);
});
window.__TAURI__.event.listen('bridge-down', function () {
+4 -18
View File
@@ -73,28 +73,14 @@ window.SonicRuntime = window.SonicRuntime || { loaded: false, capabilities: null
// (Carla standalone bật OSC UDP mặc định cổng 22752).
window.SonicCarlaMidi = window.SonicCarlaMidi || {
shouldRoute: function (synthEngine, isArmed) {
try {
// D4: bridge active → VSTi do native bridge host, KHÔNG route Carla
// (tránh kép âm).
if (window.NativeBridgeService && window.NativeBridgeService.isBridgeConnected) return false;
var c = window.SonicRuntime && window.SonicRuntime.capabilities;
if (!c || !c.features || !c.features.carla_local) return false;
if (!isArmed) return false;
var se = synthEngine || {};
return String(se.type || '').indexOf('vst') !== -1 && !!se.plugin_id;
} catch (e) { return false; }
// Carla bridge removed - all instruments hosted by Native Bridge.
return false;
},
// Playback MIDI items: route khi track VSTi + Carla local (không cần ARM —
// user đã chủ động bấm Play trên item đó).
shouldRoutePlayback: function (synthEngine) {
try {
// D4: bridge active → KHÔNG route Carla (bridge host VSTi).
if (window.NativeBridgeService && window.NativeBridgeService.isBridgeConnected) return false;
var c = window.SonicRuntime && window.SonicRuntime.capabilities;
if (!c || !c.features || !c.features.carla_local) return false;
var se = synthEngine || {};
return String(se.type || '').indexOf('vst') !== -1 && !!se.plugin_id;
} catch (e) { return false; }
// Carla bridge removed - all instruments hosted by Native Bridge.
return false;
},
noteOn: function (channel, note, velocity) {
if (!window.SonicAPI || !window.SonicAPI.carlaMidi) return;