fix(bridge): noteId match noteOn (0) for noteOff; create VST GUI window on main thread, attach on worker

This commit is contained in:
2026-08-13 16:33:46 +07:00
parent 05e4244cc8
commit 2c890aef54
5 changed files with 226 additions and 103 deletions
+30 -4
View File
@@ -424,7 +424,10 @@ void Vst3Instrument::noteOff(uint32_t channel, uint32_t pitch, uint32_t sampleOf
e.noteOff.channel = 0; // Force to MIDI Channel 1 (0) for VSTi compatibility
e.noteOff.pitch = (int16)pitch;
e.noteOff.velocity = 0.f;
e.noteOff.noteId = -1;
// noteId phai MATCH noteOn (0): Nexus/DUNE3 track notes bang id, -1
// khong khop voi note-on -> plugin giu note vo han (am thanh khong dung
// cho den khi kill bridge).
e.noteOff.noteId = 0;
e.noteOff.tuning = 0.f;
s->eventList.addEvent(e);
#endif
@@ -485,21 +488,44 @@ bool Vst3Instrument::openGUI(void* parentWindowHandle) {
#ifndef HAVE_VST3SDK
(void)parentWindowHandle;
return false;
#else
if (!reloadForGUI()) return false;
return attachView(parentWindowHandle);
#endif
}
bool Vst3Instrument::reloadForGUI() {
#ifndef HAVE_VST3SDK
return false;
#else
auto* s = static_cast<Vst3HostState*>(state_);
std::cerr << "[dbg] openGUI hwnd=" << (void*)(uintptr_t)parentWindowHandle
<< " controller=" << (s ? (s->controller ? 1 : 0) : -1) << std::endl;
if (!s || !s->controller || !parentWindowHandle) return false;
if (!s || !s->controller) return false;
if (s->view && guiAttached_) return true;
if (hasAttachedOnce_ && !guiAttached_) {
// Reopen GUI sau khi dong: mot so plugin (Nexus...) hang o
// view->attached() LAN 2 tren cung component instance. Tao lai inst
// moi tren CUNG worker thread (COM STA con song) roi attach lai.
// PHAN NAY PHAI chay tren worker thread — apartment cua channel song
// o day; chay tren thread tam thi apartment moi chet ngay sau do
// (reopen lan sau -> treo nhu bridge_like).
std::cerr << "[dbg] openGUI: re-attach - reloading fresh plugin instance" << std::endl;
if (!reload()) return false;
s = static_cast<Vst3HostState*>(state_);
if (!s || !s->controller) return false;
}
return true;
#endif
}
bool Vst3Instrument::attachView(void* parentWindowHandle) {
#ifndef HAVE_VST3SDK
(void)parentWindowHandle;
return false;
#else
auto* s = static_cast<Vst3HostState*>(state_);
std::cerr << "[dbg] openGUI hwnd=" << (void*)(uintptr_t)parentWindowHandle
<< " controller=" << (s ? (s->controller ? 1 : 0) : -1) << std::endl;
if (!s || !s->controller || !parentWindowHandle) return false;
IPlugView* rawView = nullptr;
tresult qi = s->controller->queryInterface(IPlugView::iid, (void**)&rawView);
{