From e0094979bf63814401ae26bc5662d25904ff9611 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Wed, 14 Apr 2021 21:33:20 +0200 Subject: [PATCH] Also run {get,set}State() for VST3 on GUI thread This fixes the same issue with the VST3 version of Algonaut Atlas as the last commit did for the VST2 version. --- src/wine-host/bridges/vst3.cpp | 54 +++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/src/wine-host/bridges/vst3.cpp b/src/wine-host/bridges/vst3.cpp index 9dd2cc98..e9464859 100644 --- a/src/wine-host/bridges/vst3.cpp +++ b/src/wine-host/bridges/vst3.cpp @@ -219,29 +219,43 @@ void Vst3Bridge::run() { }, [&](Vst3PluginProxy::SetState& request) -> Vst3PluginProxy::SetState::Response { - // This same function is defined in both `IComponent` and - // `IEditController`, so the host is calling one or the other - if (object_instances[request.instance_id].component) { - return object_instances[request.instance_id] - .component->setState(&request.state); - } else { - return object_instances[request.instance_id] - .edit_controller->setState(&request.state); - } + // We need to run `getState()` from the main thread, so we might + // as well do the same thing with `setState()`. See below. + return main_context + .run_in_context([&]() { + // This same function is defined in both `IComponent` + // and `IEditController`, so the host is calling one or + // the other + if (object_instances[request.instance_id].component) { + return object_instances[request.instance_id] + .component->setState(&request.state); + } else { + return object_instances[request.instance_id] + .edit_controller->setState(&request.state); + } + }) + .get(); }, [&](Vst3PluginProxy::GetState& request) -> Vst3PluginProxy::GetState::Response { - tresult result; - - // This same function is defined in both `IComponent` and - // `IEditController`, so the host is calling one or the other - if (object_instances[request.instance_id].component) { - result = object_instances[request.instance_id] - .component->getState(&request.state); - } else { - result = object_instances[request.instance_id] - .edit_controller->getState(&request.state); - } + // NOTE: The VST3 version of Algonaut Atlas doesn't restore + // state unless this function is run from the GUI thread + tresult result = + main_context + .run_in_context([&]() { + // This same function is defined in both + // `IComponent` and `IEditController`, so the host + // is calling one or the other + if (object_instances[request.instance_id] + .component) { + return object_instances[request.instance_id] + .component->getState(&request.state); + } else { + return object_instances[request.instance_id] + .edit_controller->getState(&request.state); + } + }) + .get(); return Vst3PluginProxy::GetStateResponse{ .result = result, .state = std::move(request.state)};