Proxy host context menu items for VST3 plugins

This wasn't implemented yet because no plugin tried using the interface
in this way before this, but Surge XT incorporates the host's context
menu items into their own (much more elaborate) context menu. To
accommodate this, we now copy over all of the host's prepopulated
context menu items to the Wine plugin host, and calling the targets
associated with any of those items will cause the target on the
associated context menu item on the host to be called.

This is slightly more complicated than what would otherwise be necessary
because Bitwig does not assign tags to their context menu items and
instead always uses 0.
This commit is contained in:
Robbert van der Helm
2022-01-03 17:04:00 +01:00
parent 89cd1e9ee3
commit c625deadef
16 changed files with 219 additions and 107 deletions
+28 -13
View File
@@ -183,15 +183,6 @@ Vst3PluginBridge::Vst3PluginBridge()
request.type, request.dir,
request.index, request.state);
},
[&](const YaContextMenu::GetItemCount& request)
-> YaContextMenu::GetItemCount::Response {
const auto& [proxy_object, _] =
get_proxy(request.owner_instance_id);
return proxy_object.context_menus_
.at(request.context_menu_id)
.menu->getItemCount();
},
[&](YaContextMenu::AddItem& request)
-> YaContextMenu::AddItem::Response {
const auto& [proxy_object, _] =
@@ -201,13 +192,13 @@ Vst3PluginBridge::Vst3PluginBridge()
proxy_object.context_menus_.at(request.context_menu_id);
if (request.target) {
context_menu.targets[request.item.tag] =
context_menu.plugin_targets[request.item.tag] =
Steinberg::owned(new YaContextMenuTargetImpl(
*this, std::move(*request.target)));
return context_menu.menu->addItem(
request.item,
context_menu.targets[request.item.tag]);
context_menu.plugin_targets[request.item.tag]);
} else {
return context_menu.menu->addItem(request.item,
nullptr);
@@ -222,8 +213,8 @@ Vst3PluginBridge::Vst3PluginBridge()
proxy_object.context_menus_.at(request.context_menu_id);
if (const auto it =
context_menu.targets.find(request.item.tag);
it != context_menu.targets.end()) {
context_menu.plugin_targets.find(request.item.tag);
it != context_menu.plugin_targets.end()) {
return context_menu.menu->removeItem(request.item,
it->second);
} else {
@@ -245,6 +236,30 @@ Vst3PluginBridge::Vst3PluginBridge()
.menu->popup(request.x, request.y);
});
},
[&](YaContextMenuTarget::ExecuteMenuItem& request)
-> YaContextMenuTarget::ExecuteMenuItem::Response {
const auto& [proxy, _] =
get_proxy(request.owner_instance_id);
// This is of course only used for calling host defined
// targets from the plugin, this will never be called when
// the plugin calls their own targets for whatever reason
Steinberg::Vst::IContextMenuItem item;
Steinberg::Vst::IContextMenuTarget* target = nullptr;
Steinberg::IPtr<Steinberg::Vst::IContextMenu> menu =
proxy.context_menus_.at(request.context_menu_id).menu;
if (menu->getItem(request.item_id, item, &target) ==
Steinberg::kResultOk &&
target) {
return target->executeMenuItem(request.tag);
} else {
logger_.log(
"WARNING: A IContextMenuTarget::ExecuteMenuItem "
"from the plugin could not be handled");
return Steinberg::kInvalidArgument;
}
},
[&](YaConnectionPoint::Notify& request)
-> YaConnectionPoint::Notify::Response {
const auto& [proxy_object, _] =