Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

220 lines
7.7KB

  1. //------------------------------------------------------------------------
  2. // Project : VST SDK
  3. //
  4. // Category : Interfaces
  5. // Filename : pluginterfaces/vst/ivstcontextmenu.h
  6. // Created by : Steinberg, 10/2010
  7. // Description : VST Context Menu Interfaces
  8. //
  9. //-----------------------------------------------------------------------------
  10. // This file is part of a Steinberg SDK. It is subject to the license terms
  11. // in the LICENSE file found in the top-level directory of this distribution
  12. // and at www.steinberg.net/sdklicenses.
  13. // No part of the SDK, including this file, may be copied, modified, propagated,
  14. // or distributed except according to the terms contained in the LICENSE file.
  15. //-----------------------------------------------------------------------------
  16. #pragma once
  17. #include "pluginterfaces/base/funknown.h"
  18. #include "pluginterfaces/vst/vsttypes.h"
  19. //------------------------------------------------------------------------
  20. #include "pluginterfaces/base/falignpush.h"
  21. //------------------------------------------------------------------------
  22. namespace Steinberg {
  23. class IPlugView;
  24. namespace Vst {
  25. class IContextMenu;
  26. //------------------------------------------------------------------------
  27. /** Extended host callback interface Vst::IComponentHandler3 for an edit controller.
  28. \ingroup vstIHost vst350
  29. - [host imp]
  30. - [extends IComponentHandler]
  31. - [released: 3.5.0]
  32. - [optional]
  33. A plug-in can ask the host to create a context menu for a given exported parameter ID or a generic context menu.\n
  34. The host may pre-fill this context menu with specific items regarding the parameter ID like "Show automation for parameter",
  35. "MIDI learn" etc...\n
  36. The plug-in can use the context menu in two ways :
  37. - add its own items to the menu via the IContextMenu interface and call IContextMenu::popup(..) to create the pop-up. See the \ref IContextMenuExample.
  38. - extract the host menu items and add them to a context menu created by the plug-in.
  39. \b Note: You can and should use this even if you do not add your own items to the menu as this is considered to be a big user value.
  40. \sa IContextMenu
  41. \sa IContextMenuTarget
  42. \section IContextMenuExample Examples
  43. - For example, Cubase adds its owned entries in the context menu opened with right-click on an exported parameter when the plug-in uses createContextMenu.
  44. \image html "contextmenuexample.png"
  45. \n
  46. - Adding plug-in specific items to the context menu:
  47. \code{.cpp}
  48. //------------------------------------------------------------------------
  49. class PluginContextMenuTarget : public IContextMenuTarget, public FObject
  50. {
  51. public:
  52. PluginContextMenuTarget () {}
  53. virtual tresult PLUGIN_API executeMenuItem (int32 tag)
  54. {
  55. // this will be called if the user has executed one of the menu items of the plug-in.
  56. // It will not be called for items of the host.
  57. switch (tag)
  58. {
  59. case 1: break;
  60. case 2: break;
  61. }
  62. return kResultTrue;
  63. }
  64. OBJ_METHODS(PluginContextMenuTarget, FObject)
  65. DEFINE_INTERFACES
  66. DEF_INTERFACE (IContextMenuTarget)
  67. END_DEFINE_INTERFACES (FObject)
  68. REFCOUNT_METHODS(FObject)
  69. };
  70. // The following is the code to create the context menu
  71. void popupContextMenu (IComponentHandler* componentHandler, IPlugView* view, const ParamID* paramID, UCoord x, UCoord y)
  72. {
  73. if (componentHandler == 0 || view == 0)
  74. return;
  75. FUnknownPtr<IComponentHandler3> handler (componentHandler);
  76. if (handler == 0)
  77. return;
  78. IContextMenu* menu = handler->createContextMenu (view, paramID);
  79. if (menu)
  80. {
  81. // here you can add your entries (optional)
  82. PluginContextMenuTarget* target = new PluginContextMenuTarget ();
  83. IContextMenu::Item item = {0};
  84. UString128 ("My Item 1").copyTo (item.name, 128);
  85. item.tag = 1;
  86. menu->addItem (item, target);
  87. UString128 ("My Item 2").copyTo (item.name, 128);
  88. item.tag = 2;
  89. menu->addItem (item, target);
  90. target->release ();
  91. //--end of adding new entries
  92. // here the the context menu will be pop-up (and it waits a user interaction)
  93. menu->popup (x, y);
  94. menu->release ();
  95. }
  96. }
  97. \endcode
  98. */
  99. class IComponentHandler3 : public FUnknown
  100. {
  101. public:
  102. /** Creates a host context menu for a plug-in:
  103. - If paramID is zero, the host may create a generic context menu.
  104. - The IPlugView object must be valid.
  105. - The return IContextMenu object needs to be released afterwards by the plug-in.
  106. */
  107. virtual IContextMenu* PLUGIN_API createContextMenu (IPlugView* plugView, const ParamID* paramID) = 0;
  108. //------------------------------------------------------------------------
  109. static const FUID iid;
  110. };
  111. DECLARE_CLASS_IID (IComponentHandler3, 0x69F11617, 0xD26B400D, 0xA4B6B964, 0x7B6EBBAB)
  112. //------------------------------------------------------------------------
  113. /** Context Menu Item Target interface: Vst::IContextMenuTarget
  114. \ingroup vstIHost vstIPlug vst350
  115. - [host imp]
  116. - [plug imp]
  117. - [released: 3.5.0]
  118. - [optional]
  119. A receiver of a menu item should implement this interface, which will be called after the user has selected
  120. this menu item.
  121. \see IComponentHandler3 for more information.
  122. */
  123. class IContextMenuTarget : public FUnknown
  124. {
  125. public:
  126. /** Called when an menu item was executed. */
  127. virtual tresult PLUGIN_API executeMenuItem (int32 tag) = 0;
  128. //------------------------------------------------------------------------
  129. static const FUID iid;
  130. };
  131. DECLARE_CLASS_IID (IContextMenuTarget, 0x3CDF2E75, 0x85D34144, 0xBF86D36B, 0xD7C4894D)
  132. //------------------------------------------------------------------------
  133. /** IContextMenuItem is an entry element of the context menu. */
  134. struct IContextMenuItem
  135. {
  136. String128 name; ///< Name of the item
  137. int32 tag; ///< Identifier tag of the item
  138. int32 flags; ///< Flags of the item
  139. enum Flags {
  140. kIsSeparator = 1 << 0, ///< Item is a separator
  141. kIsDisabled = 1 << 1, ///< Item is disabled
  142. kIsChecked = 1 << 2, ///< Item is checked
  143. kIsGroupStart = 1 << 3 | kIsDisabled, ///< Item is a group start (like sub folder)
  144. kIsGroupEnd = 1 << 4 | kIsSeparator, ///< Item is a group end
  145. };
  146. };
  147. //------------------------------------------------------------------------
  148. /** Context Menu interface: Vst::IContextMenu
  149. \ingroup vstIHost vst350
  150. - [host imp]
  151. - [create with IComponentHandler3::createContextMenu(..)]
  152. - [released: 3.5.0]
  153. - [optional]
  154. A context menu is composed of Item (entry). A Item is defined by a name, a tag, a flag
  155. and a associated target (called when this item will be selected/executed).
  156. With IContextMenu the plug-in can retrieve a Item, add a Item, remove a Item and pop-up the menu.
  157. \see IComponentHandler3 for more information.
  158. */
  159. class IContextMenu : public FUnknown
  160. {
  161. public:
  162. typedef IContextMenuItem Item;
  163. /** Gets the number of menu items. */
  164. virtual int32 PLUGIN_API getItemCount () = 0;
  165. /** Gets a menu item and its target (target could be not assigned). */
  166. virtual tresult PLUGIN_API getItem (int32 index, Item& item /*out*/, IContextMenuTarget** target /*out*/) = 0;
  167. /** Adds a menu item and its target. */
  168. virtual tresult PLUGIN_API addItem (const Item& item, IContextMenuTarget* target) = 0;
  169. /** Removes a menu item. */
  170. virtual tresult PLUGIN_API removeItem (const Item& item, IContextMenuTarget* target) = 0;
  171. /** Pop-ups the menu. Coordinates are relative to the top-left position of the plug-ins view. */
  172. virtual tresult PLUGIN_API popup (UCoord x, UCoord y) = 0;
  173. //------------------------------------------------------------------------
  174. static const FUID iid;
  175. };
  176. DECLARE_CLASS_IID (IContextMenu, 0x2E93C863, 0x0C9C4588, 0x97DBECF5, 0xAD17817D)
  177. //------------------------------------------------------------------------
  178. } // namespace Vst
  179. } // namespace Steinberg
  180. //------------------------------------------------------------------------
  181. #include "pluginterfaces/base/falignpop.h"
  182. //------------------------------------------------------------------------