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.
This commit is contained in:
Robbert van der Helm
2021-04-14 21:33:20 +02:00
parent d97e699db1
commit e0094979bf
+34 -20
View File
@@ -219,29 +219,43 @@ void Vst3Bridge::run() {
}, },
[&](Vst3PluginProxy::SetState& request) [&](Vst3PluginProxy::SetState& request)
-> Vst3PluginProxy::SetState::Response { -> Vst3PluginProxy::SetState::Response {
// This same function is defined in both `IComponent` and // We need to run `getState()` from the main thread, so we might
// `IEditController`, so the host is calling one or the other // as well do the same thing with `setState()`. See below.
if (object_instances[request.instance_id].component) { return main_context
return object_instances[request.instance_id] .run_in_context<tresult>([&]() {
.component->setState(&request.state); // This same function is defined in both `IComponent`
} else { // and `IEditController`, so the host is calling one or
return object_instances[request.instance_id] // the other
.edit_controller->setState(&request.state); 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& request)
-> Vst3PluginProxy::GetState::Response { -> Vst3PluginProxy::GetState::Response {
tresult result; // NOTE: The VST3 version of Algonaut Atlas doesn't restore
// state unless this function is run from the GUI thread
// This same function is defined in both `IComponent` and tresult result =
// `IEditController`, so the host is calling one or the other main_context
if (object_instances[request.instance_id].component) { .run_in_context<tresult>([&]() {
result = object_instances[request.instance_id] // This same function is defined in both
.component->getState(&request.state); // `IComponent` and `IEditController`, so the host
} else { // is calling one or the other
result = object_instances[request.instance_id] if (object_instances[request.instance_id]
.edit_controller->getState(&request.state); .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{ return Vst3PluginProxy::GetStateResponse{
.result = result, .state = std::move(request.state)}; .result = result, .state = std::move(request.state)};