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.

284 lines
11KB

  1. //-----------------------------------------------------------------------------
  2. // Project : SDK Core
  3. //
  4. // Category : SDK GUI Interfaces
  5. // Filename : pluginterfaces/gui/iplugview.h
  6. // Created by : Steinberg, 12/2007
  7. // Description : Plug-in User Interface
  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/base/typesizecheck.h"
  19. namespace Steinberg {
  20. class IPlugFrame;
  21. //------------------------------------------------------------------------
  22. /*! \defgroup pluginGUI Graphical User Interface
  23. */
  24. //------------------------------------------------------------------------
  25. /** Graphical rectangle structure. Used with IPlugView.
  26. \ingroup pluginGUI
  27. */
  28. struct ViewRect
  29. {
  30. ViewRect (int32 l = 0, int32 t = 0, int32 r = 0, int32 b = 0)
  31. : left (l), top (t), right (r), bottom (b)
  32. {
  33. }
  34. int32 left;
  35. int32 top;
  36. int32 right;
  37. int32 bottom;
  38. //--- ---------------------------------------------------------------------
  39. int32 getWidth () const { return right - left; }
  40. int32 getHeight () const { return bottom - top; }
  41. };
  42. SMTG_TYPE_SIZE_CHECK (ViewRect, 16, 16, 16, 16)
  43. //------------------------------------------------------------------------
  44. /** \defgroup platformUIType Platform UI Types
  45. \ingroup pluginGUI
  46. List of Platform UI types for IPlugView. This list is used to match the GUI-System between
  47. the host and a plug-in in case that an OS provides multiple GUI-APIs.
  48. */
  49. /*@{*/
  50. /** The parent parameter in IPlugView::attached() is a HWND handle.
  51. * You should attach a child window to it. */
  52. const FIDString kPlatformTypeHWND = "HWND"; ///< HWND handle. (Microsoft Windows)
  53. /** The parent parameter in IPlugView::attached() is a WindowRef.
  54. * You should attach a HIViewRef to the content view of the window. */
  55. const FIDString kPlatformTypeHIView = "HIView"; ///< HIViewRef. (Mac OS X)
  56. /** The parent parameter in IPlugView::attached() is a NSView pointer.
  57. * You should attach a NSView to it. */
  58. const FIDString kPlatformTypeNSView = "NSView"; ///< NSView pointer. (Mac OS X)
  59. /** The parent parameter in IPlugView::attached() is a UIView pointer.
  60. * You should attach an UIView to it. */
  61. const FIDString kPlatformTypeUIView = "UIView"; ///< UIView pointer. (iOS)
  62. /** The parent parameter in IPlugView::attached() is a X11 Window supporting XEmbed.
  63. * You should attach a Window to it that supports the XEmbed extension.
  64. * See https://standards.freedesktop.org/xembed-spec/xembed-spec-latest.html */
  65. const FIDString kPlatformTypeX11EmbedWindowID = "X11EmbedWindowID"; ///< X11 Window ID. (X11)
  66. /*@}*/
  67. //------------------------------------------------------------------------
  68. //------------------------------------------------------------------------
  69. /** Plug-in definition of a view.
  70. \ingroup pluginGUI vstIPlug vst300
  71. - [plug imp]
  72. - [released: 3.0.0]
  73. \par Sizing of a view
  74. Usually, the size of a plug-in view is fixed. But both the host and the plug-in can cause
  75. a view to be resized:
  76. \n
  77. - \b Host: If IPlugView::canResize () returns kResultTrue the host will set up the window
  78. so that the user can resize it. While the user resizes the window,
  79. IPlugView::checkSizeConstraint () is called, allowing the plug-in to change the size to a valid
  80. a valid supported rectangle size. The host then resizes the window to this rect and has to call IPlugView::onSize ().
  81. \n
  82. \n
  83. - \b Plug-in: The plug-in can call IPlugFrame::resizeView () and cause the host to resize the
  84. window.\n\n
  85. Afterwards, in the same callstack, the host has to call IPlugView::onSize () if a resize is needed (size was changed).
  86. Note that if the host calls IPlugView::getSize () before calling IPlugView::onSize () (if needed),
  87. it will get the current (old) size not the wanted one!!\n
  88. Here the calling sequence:\n
  89. - plug-in->host: IPlugFrame::resizeView (newSize)
  90. - host->plug-in (optional): IPlugView::getSize () returns the currentSize (not the newSize!)
  91. - host->plug-in: if newSize is different from the current size: IPlugView::onSize (newSize)
  92. - host->plug-in (optional): IPlugView::getSize () returns the newSize
  93. \n
  94. <b>Please only resize the platform representation of the view when IPlugView::onSize () is
  95. called.</b>
  96. \par Keyboard handling
  97. The plug-in view receives keyboard events from the host. A view implementation must not handle
  98. keyboard events by the means of platform callbacks, but let the host pass them to the view. The host
  99. depends on a proper return value when IPlugView::onKeyDown is called, otherwise the plug-in view may
  100. cause a malfunction of the host's key command handling.
  101. \see IPlugFrame, \ref platformUIType
  102. */
  103. class IPlugView : public FUnknown
  104. {
  105. public:
  106. //------------------------------------------------------------------------
  107. /** Is Platform UI Type supported
  108. \param type : IDString of \ref platformUIType */
  109. virtual tresult PLUGIN_API isPlatformTypeSupported (FIDString type) = 0;
  110. /** The parent window of the view has been created, the (platform) representation of the view
  111. should now be created as well.
  112. Note that the parent is owned by the caller and you are not allowed to alter it in any way
  113. other than adding your own views.
  114. Note that in this call the plug-in could call a IPlugFrame::resizeView ()!
  115. \param parent : platform handle of the parent window or view
  116. \param type : \ref platformUIType which should be created */
  117. virtual tresult PLUGIN_API attached (void* parent, FIDString type) = 0;
  118. /** The parent window of the view is about to be destroyed.
  119. You have to remove all your own views from the parent window or view. */
  120. virtual tresult PLUGIN_API removed () = 0;
  121. /** Handling of mouse wheel. */
  122. virtual tresult PLUGIN_API onWheel (float distance) = 0;
  123. /** Handling of keyboard events : Key Down.
  124. \param key : unicode code of key
  125. \param keyCode : virtual keycode for non ascii keys - see \ref VirtualKeyCodes in keycodes.h
  126. \param modifiers : any combination of modifiers - see \ref KeyModifier in keycodes.h
  127. \return kResultTrue if the key is handled, otherwise kResultFalse. \n
  128. <b> Please note that kResultTrue must only be returned if the key has really been
  129. handled. </b> Otherwise key command handling of the host might be blocked! */
  130. virtual tresult PLUGIN_API onKeyDown (char16 key, int16 keyCode, int16 modifiers) = 0;
  131. /** Handling of keyboard events : Key Up.
  132. \param key : unicode code of key
  133. \param keyCode : virtual keycode for non ascii keys - see \ref VirtualKeyCodes in keycodes.h
  134. \param modifiers : any combination of KeyModifier - see \ref KeyModifier in keycodes.h
  135. \return kResultTrue if the key is handled, otherwise return kResultFalse. */
  136. virtual tresult PLUGIN_API onKeyUp (char16 key, int16 keyCode, int16 modifiers) = 0;
  137. /** Returns the size of the platform representation of the view. */
  138. virtual tresult PLUGIN_API getSize (ViewRect* size) = 0;
  139. /** Resizes the platform representation of the view to the given rect. Note that if the plug-in
  140. * requests a resize (IPlugFrame::resizeView ()) onSize has to be called afterward. */
  141. virtual tresult PLUGIN_API onSize (ViewRect* newSize) = 0;
  142. /** Focus changed message. */
  143. virtual tresult PLUGIN_API onFocus (TBool state) = 0;
  144. /** Sets IPlugFrame object to allow the plug-in to inform the host about resizing. */
  145. virtual tresult PLUGIN_API setFrame (IPlugFrame* frame) = 0;
  146. /** Is view sizable by user. */
  147. virtual tresult PLUGIN_API canResize () = 0;
  148. /** On live resize this is called to check if the view can be resized to the given rect, if not
  149. * adjust the rect to the allowed size. */
  150. virtual tresult PLUGIN_API checkSizeConstraint (ViewRect* rect) = 0;
  151. //------------------------------------------------------------------------
  152. static const FUID iid;
  153. };
  154. DECLARE_CLASS_IID (IPlugView, 0x5BC32507, 0xD06049EA, 0xA6151B52, 0x2B755B29)
  155. //------------------------------------------------------------------------
  156. /** Callback interface passed to IPlugView.
  157. \ingroup pluginGUI vstIHost vst300
  158. - [host imp]
  159. - [released: 3.0.0]
  160. - [mandatory]
  161. Enables a plug-in to resize the view and cause the host to resize the window.
  162. */
  163. class IPlugFrame : public FUnknown
  164. {
  165. public:
  166. //------------------------------------------------------------------------
  167. /** Called to inform the host about the resize of a given view.
  168. * Afterwards the host has to call IPlugView::onSize (). */
  169. virtual tresult PLUGIN_API resizeView (IPlugView* view, ViewRect* newSize) = 0;
  170. //------------------------------------------------------------------------
  171. static const FUID iid;
  172. };
  173. DECLARE_CLASS_IID (IPlugFrame, 0x367FAF01, 0xAFA94693, 0x8D4DA2A0, 0xED0882A3)
  174. #if SMTG_OS_LINUX
  175. //------------------------------------------------------------------------
  176. namespace Linux {
  177. using TimerInterval = uint64;
  178. using FileDescriptor = int;
  179. //------------------------------------------------------------------------
  180. /** Linux event handler interface
  181. \ingroup pluginGUI vst368
  182. - [plug imp]
  183. - [released: 3.6.8]
  184. \see IRunLoop
  185. */
  186. class IEventHandler : public FUnknown
  187. {
  188. public:
  189. virtual void PLUGIN_API onFDIsSet (FileDescriptor fd) = 0;
  190. //------------------------------------------------------------------------
  191. static const FUID iid;
  192. };
  193. DECLARE_CLASS_IID (IEventHandler, 0x561E65C9, 0x13A0496F, 0x813A2C35, 0x654D7983)
  194. //------------------------------------------------------------------------
  195. /** Linux timer handler interface
  196. \ingroup pluginGUI vst368
  197. - [plug imp]
  198. - [released: 3.6.8]
  199. \see IRunLoop
  200. */
  201. class ITimerHandler : public FUnknown
  202. {
  203. public:
  204. virtual void PLUGIN_API onTimer () = 0;
  205. //------------------------------------------------------------------------
  206. static const FUID iid;
  207. };
  208. DECLARE_CLASS_IID (ITimerHandler, 0x10BDD94F, 0x41424774, 0x821FAD8F, 0xECA72CA9)
  209. //------------------------------------------------------------------------
  210. /** Linux host run loop interface
  211. \ingroup pluginGUI vst368
  212. - [host imp]
  213. - [extends IPlugFrame]
  214. - [released: 3.6.8]
  215. On Linux the host has to provide this interface to the plug-in as there's no global event run loop
  216. defined as on other platforms.
  217. A plug-in can register an event handler for a file descriptor. The host has to call the event
  218. handler when the file descriptor is marked readable.
  219. A plug-in also can register a timer which will be called repeatedly until it is unregistered.
  220. */
  221. class IRunLoop : public FUnknown
  222. {
  223. public:
  224. virtual tresult PLUGIN_API registerEventHandler (IEventHandler* handler, FileDescriptor fd) = 0;
  225. virtual tresult PLUGIN_API unregisterEventHandler (IEventHandler* handler) = 0;
  226. virtual tresult PLUGIN_API registerTimer (ITimerHandler* handler,
  227. TimerInterval milliseconds) = 0;
  228. virtual tresult PLUGIN_API unregisterTimer (ITimerHandler* handler) = 0;
  229. //------------------------------------------------------------------------
  230. static const FUID iid;
  231. };
  232. DECLARE_CLASS_IID (IRunLoop, 0x18C35366, 0x97764F1A, 0x9C5B8385, 0x7A871389)
  233. //------------------------------------------------------------------------
  234. } // namespace Linux
  235. #endif
  236. //------------------------------------------------------------------------
  237. } // namespace Steinberg