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.

287 lines
12KB

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