Handle mutual recursion in context menus

REAPER will call `getState()` while the context menu is open, and that
also has to be handled from the GUI thread.
This commit is contained in:
Robbert van der Helm
2021-04-30 02:49:54 +02:00
parent 52428c8749
commit 36b3636072
3 changed files with 20 additions and 16 deletions
@@ -114,7 +114,10 @@ tresult PLUGIN_API Vst3ContextMenuProxyImpl::removeItem(
tresult PLUGIN_API Vst3ContextMenuProxyImpl::popup(Steinberg::UCoord x,
Steinberg::UCoord y) {
return bridge.send_message(
// NOTE: This requires mutual recursion, because REAPER will call
// `getState()` whle the context menu is open, and `getState()` also
// has to be handled from the GUi thread
return bridge.send_mutually_recursive_message(
YaContextMenu::Popup{.owner_instance_id = owner_instance_id(),
.context_menu_id = context_menu_id(),
.x = x,
+14 -15
View File
@@ -253,22 +253,21 @@ void Vst3Bridge::run() {
-> Vst3PluginProxy::GetState::Response {
// NOTE: The VST3 version of Algonaut Atlas doesn't restore
// state unless this function is run from the GUI thread
// NOTE: This also requires mutual recursion because REAPER will
// call `getState()` while opening a popup menu
const tresult result =
main_context
.run_in_context<tresult>([&]() {
// 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();
do_mutual_recursion_on_gui_thread<tresult>([&]() {
// 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);
}
});
return Vst3PluginProxy::GetStateResponse{
.result = result, .state = std::move(request.state)};