G0.4: save/restore preset quanh reload khi close GUI (captureState/restoreState, memorystream link truc tiep)
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
#include "public.sdk/source/vst/hosting/processdata.h"
|
||||
#include "public.sdk/source/vst/hosting/eventlist.h"
|
||||
#include "public.sdk/source/vst/hosting/parameterchanges.h"
|
||||
#include "public.sdk/source/common/memorystream.h"
|
||||
|
||||
#include "pluginterfaces/vst/ivstaudioprocessor.h"
|
||||
#include "pluginterfaces/vst/ivstcomponent.h"
|
||||
@@ -525,6 +526,59 @@ bool Vst3Instrument::openGUI(void* parentWindowHandle) {
|
||||
#endif
|
||||
}
|
||||
|
||||
// G0.4: capture the plugin's full state (component + edit controller) into
|
||||
// buffers so a GUI reopen can restore the preset after reload().
|
||||
void Vst3Instrument::captureState() {
|
||||
#ifndef HAVE_VST3SDK
|
||||
return;
|
||||
#else
|
||||
auto* s = static_cast<Vst3HostState*>(state_);
|
||||
if (!s) return;
|
||||
savedComponentState_.clear();
|
||||
savedControllerState_.clear();
|
||||
Steinberg::MemoryStream stream;
|
||||
if (s->component && s->component->getState(&stream) == kResultOk && stream.getSize() > 0) {
|
||||
savedComponentState_.assign(stream.getData(), stream.getData() + stream.getSize());
|
||||
std::cout << "[Vst3Instrument] state captured ch=" << channel_
|
||||
<< " component=" << savedComponentState_.size() << "B" << std::endl;
|
||||
}
|
||||
if (s->controller && !s->controllerIsComponent &&
|
||||
s->controller->getState(&stream) == kResultOk && stream.getSize() > 0) {
|
||||
savedControllerState_.assign(stream.getData(), stream.getData() + stream.getSize());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// G0.4: restore the captured state onto the freshly loaded instance.
|
||||
void Vst3Instrument::restoreState() {
|
||||
#ifndef HAVE_VST3SDK
|
||||
return;
|
||||
#else
|
||||
auto* s = static_cast<Vst3HostState*>(state_);
|
||||
if (!s) return;
|
||||
if (!savedComponentState_.empty()) {
|
||||
Steinberg::MemoryStream stream;
|
||||
stream.write(savedComponentState_.data(), (int32)savedComponentState_.size(), nullptr);
|
||||
stream.seek(0, Steinberg::IBStream::kIBSeekSet, nullptr);
|
||||
bool okComp = s->component && s->component->setState(&stream) == kResultOk;
|
||||
if (!okComp) {
|
||||
std::cerr << "[Vst3Instrument] setState(component) failed ch=" << channel_ << std::endl;
|
||||
} else {
|
||||
std::cout << "[Vst3Instrument] state restored ch=" << channel_
|
||||
<< " component=" << savedComponentState_.size() << "B" << std::endl;
|
||||
}
|
||||
}
|
||||
if (!savedControllerState_.empty()) {
|
||||
Steinberg::MemoryStream stream;
|
||||
stream.write(savedControllerState_.data(), (int32)savedControllerState_.size(), nullptr);
|
||||
stream.seek(0, Steinberg::IBStream::kIBSeekSet, nullptr);
|
||||
if (s->controller && s->controller->setState(&stream) != kResultOk) {
|
||||
std::cerr << "[Vst3Instrument] setState(controller) failed ch=" << channel_ << std::endl;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool Vst3Instrument::reloadForGUI() {
|
||||
#ifndef HAVE_VST3SDK
|
||||
return false;
|
||||
@@ -539,9 +593,13 @@ bool Vst3Instrument::reloadForGUI() {
|
||||
// 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).
|
||||
// G0.4: reload() terminates + recreates the instance — capture the
|
||||
// preset first, restore it after, so the GUI reopen keeps the sound.
|
||||
captureState();
|
||||
if (!reload()) return false;
|
||||
s = static_cast<Vst3HostState*>(state_);
|
||||
if (!s || !s->controller) return false;
|
||||
restoreState();
|
||||
}
|
||||
return true;
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user