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.

447 lines
17KB

  1. /*
  2. LV2 UI Extension
  3. Copyright 2009-2016 David Robillard <d@drobilla.net>
  4. Copyright 2006-2011 Lars Luthman <lars.luthman@gmail.com>
  5. Permission to use, copy, modify, and/or distribute this software for any
  6. purpose with or without fee is hereby granted, provided that the above
  7. copyright notice and this permission notice appear in all copies.
  8. THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. /**
  17. @defgroup ui User Interfaces
  18. User interfaces of any type for plugins,
  19. <http://lv2plug.in/ns/extensions/ui> for details.
  20. @{
  21. */
  22. #ifndef LV2_UI_H
  23. #define LV2_UI_H
  24. #include <stdint.h>
  25. #include "lv2.h"
  26. #define LV2_UI_URI "http://lv2plug.in/ns/extensions/ui" ///< http://lv2plug.in/ns/extensions/ui
  27. #define LV2_UI_PREFIX LV2_UI_URI "#" ///< http://lv2plug.in/ns/extensions/ui#
  28. #define LV2_UI__CocoaUI LV2_UI_PREFIX "CocoaUI" ///< http://lv2plug.in/ns/extensions/ui#CocoaUI
  29. #define LV2_UI__Gtk3UI LV2_UI_PREFIX "Gtk3UI" ///< http://lv2plug.in/ns/extensions/ui#Gtk3UI
  30. #define LV2_UI__GtkUI LV2_UI_PREFIX "GtkUI" ///< http://lv2plug.in/ns/extensions/ui#GtkUI
  31. #define LV2_UI__PortNotification LV2_UI_PREFIX "PortNotification" ///< http://lv2plug.in/ns/extensions/ui#PortNotification
  32. #define LV2_UI__PortProtocol LV2_UI_PREFIX "PortProtocol" ///< http://lv2plug.in/ns/extensions/ui#PortProtocol
  33. #define LV2_UI__Qt4UI LV2_UI_PREFIX "Qt4UI" ///< http://lv2plug.in/ns/extensions/ui#Qt4UI
  34. #define LV2_UI__Qt5UI LV2_UI_PREFIX "Qt5UI" ///< http://lv2plug.in/ns/extensions/ui#Qt5UI
  35. #define LV2_UI__UI LV2_UI_PREFIX "UI" ///< http://lv2plug.in/ns/extensions/ui#UI
  36. #define LV2_UI__WindowsUI LV2_UI_PREFIX "WindowsUI" ///< http://lv2plug.in/ns/extensions/ui#WindowsUI
  37. #define LV2_UI__X11UI LV2_UI_PREFIX "X11UI" ///< http://lv2plug.in/ns/extensions/ui#X11UI
  38. #define LV2_UI__binary LV2_UI_PREFIX "binary" ///< http://lv2plug.in/ns/extensions/ui#binary
  39. #define LV2_UI__fixedSize LV2_UI_PREFIX "fixedSize" ///< http://lv2plug.in/ns/extensions/ui#fixedSize
  40. #define LV2_UI__idleInterface LV2_UI_PREFIX "idleInterface" ///< http://lv2plug.in/ns/extensions/ui#idleInterface
  41. #define LV2_UI__noUserResize LV2_UI_PREFIX "noUserResize" ///< http://lv2plug.in/ns/extensions/ui#noUserResize
  42. #define LV2_UI__notifyType LV2_UI_PREFIX "notifyType" ///< http://lv2plug.in/ns/extensions/ui#notifyType
  43. #define LV2_UI__parent LV2_UI_PREFIX "parent" ///< http://lv2plug.in/ns/extensions/ui#parent
  44. #define LV2_UI__plugin LV2_UI_PREFIX "plugin" ///< http://lv2plug.in/ns/extensions/ui#plugin
  45. #define LV2_UI__portIndex LV2_UI_PREFIX "portIndex" ///< http://lv2plug.in/ns/extensions/ui#portIndex
  46. #define LV2_UI__portMap LV2_UI_PREFIX "portMap" ///< http://lv2plug.in/ns/extensions/ui#portMap
  47. #define LV2_UI__portNotification LV2_UI_PREFIX "portNotification" ///< http://lv2plug.in/ns/extensions/ui#portNotification
  48. #define LV2_UI__portSubscribe LV2_UI_PREFIX "portSubscribe" ///< http://lv2plug.in/ns/extensions/ui#portSubscribe
  49. #define LV2_UI__protocol LV2_UI_PREFIX "protocol" ///< http://lv2plug.in/ns/extensions/ui#protocol
  50. #define LV2_UI__floatProtocol LV2_UI_PREFIX "floatProtocol" ///< http://lv2plug.in/ns/extensions/ui#floatProtocol
  51. #define LV2_UI__peakProtocol LV2_UI_PREFIX "peakProtocol" ///< http://lv2plug.in/ns/extensions/ui#peakProtocol
  52. #define LV2_UI__resize LV2_UI_PREFIX "resize" ///< http://lv2plug.in/ns/extensions/ui#resize
  53. #define LV2_UI__showInterface LV2_UI_PREFIX "showInterface" ///< http://lv2plug.in/ns/extensions/ui#showInterface
  54. #define LV2_UI__touch LV2_UI_PREFIX "touch" ///< http://lv2plug.in/ns/extensions/ui#touch
  55. #define LV2_UI__ui LV2_UI_PREFIX "ui" ///< http://lv2plug.in/ns/extensions/ui#ui
  56. #define LV2_UI__updateRate LV2_UI_PREFIX "updateRate" ///< http://lv2plug.in/ns/extensions/ui#updateRate
  57. #define LV2_UI__windowTitle LV2_UI_PREFIX "windowTitle" ///< http://lv2plug.in/ns/extensions/ui#windowTitle
  58. /**
  59. The index returned by LV2UI_Port_Map::port_index() for unknown ports.
  60. */
  61. #define LV2UI_INVALID_PORT_INDEX ((uint32_t)-1)
  62. #ifdef __cplusplus
  63. extern "C" {
  64. #else
  65. # include <stdbool.h>
  66. #endif
  67. /**
  68. A pointer to some widget or other type of UI handle.
  69. The actual type is defined by the type of the UI.
  70. */
  71. typedef void* LV2UI_Widget;
  72. /**
  73. A pointer to UI instance internals.
  74. The host may compare this to NULL, but otherwise MUST NOT interpret it.
  75. */
  76. typedef void* LV2UI_Handle;
  77. /**
  78. A pointer to a controller provided by the host.
  79. The UI may compare this to NULL, but otherwise MUST NOT interpret it.
  80. */
  81. typedef void* LV2UI_Controller;
  82. /**
  83. A pointer to opaque data for a feature.
  84. */
  85. typedef void* LV2UI_Feature_Handle;
  86. /**
  87. A host-provided function that sends data to a plugin's input ports.
  88. @param controller The opaque controller pointer passed to
  89. LV2UI_Descriptor::instantiate().
  90. @param port_index Index of the port to update.
  91. @param buffer Buffer containing `buffer_size` bytes of data.
  92. @param buffer_size Size of `buffer` in bytes.
  93. @param port_protocol Either 0 or the URID for a ui:PortProtocol. If 0, the
  94. protocol is implicitly ui:floatProtocol, the port MUST be an lv2:ControlPort
  95. input, `buffer` MUST point to a single float value, and `buffer_size` MUST
  96. be sizeof(float). The UI SHOULD NOT use a protocol not supported by the
  97. host, but the host MUST gracefully ignore any protocol it does not
  98. understand.
  99. */
  100. typedef void (*LV2UI_Write_Function)(LV2UI_Controller controller,
  101. uint32_t port_index,
  102. uint32_t buffer_size,
  103. uint32_t port_protocol,
  104. const void* buffer);
  105. /**
  106. A plugin UI.
  107. A pointer to an object of this type is returned by the lv2ui_descriptor()
  108. function.
  109. */
  110. typedef struct _LV2UI_Descriptor {
  111. /**
  112. The URI for this UI (not for the plugin it controls).
  113. */
  114. const char* URI;
  115. /**
  116. Create a new UI and return a handle to it. This function works
  117. similarly to LV2_Descriptor::instantiate().
  118. @param descriptor The descriptor for the UI to instantiate.
  119. @param plugin_uri The URI of the plugin that this UI will control.
  120. @param bundle_path The path to the bundle containing this UI, including
  121. the trailing directory separator.
  122. @param write_function A function that the UI can use to send data to the
  123. plugin's input ports.
  124. @param controller A handle for the UI instance to be passed as the
  125. first parameter of UI methods.
  126. @param widget (output) widget pointer. The UI points this at its main
  127. widget, which has the type defined by the UI type in the data file.
  128. @param features An array of LV2_Feature pointers. The host must pass
  129. all feature URIs that it and the UI supports and any additional data, as
  130. in LV2_Descriptor::instantiate(). Note that UI features and plugin
  131. features are not necessarily the same.
  132. */
  133. LV2UI_Handle (*instantiate)(const struct _LV2UI_Descriptor* descriptor,
  134. const char* plugin_uri,
  135. const char* bundle_path,
  136. LV2UI_Write_Function write_function,
  137. LV2UI_Controller controller,
  138. LV2UI_Widget* widget,
  139. const LV2_Feature* const* features);
  140. /**
  141. Destroy the UI. The host must not try to access the widget after
  142. calling this function.
  143. */
  144. void (*cleanup)(LV2UI_Handle ui);
  145. /**
  146. Tell the UI that something interesting has happened at a plugin port.
  147. What is "interesting" and how it is written to `buffer` is defined by
  148. `format`, which has the same meaning as in LV2UI_Write_Function().
  149. Format 0 is a special case for lv2:ControlPort, where this function
  150. should be called when the port value changes (but not necessarily for
  151. every change), `buffer_size` must be sizeof(float), and `buffer`
  152. points to a single IEEE-754 float.
  153. By default, the host should only call this function for lv2:ControlPort
  154. inputs. However, the UI can request updates for other ports statically
  155. with ui:portNotification or dynamicaly with ui:portSubscribe.
  156. The UI MUST NOT retain any reference to `buffer` after this function
  157. returns, it is only valid for the duration of the call.
  158. This member may be NULL if the UI is not interested in any port events.
  159. */
  160. void (*port_event)(LV2UI_Handle ui,
  161. uint32_t port_index,
  162. uint32_t buffer_size,
  163. uint32_t format,
  164. const void* buffer);
  165. /**
  166. Return a data structure associated with an extension URI, typically an
  167. interface struct with additional function pointers
  168. This member may be set to NULL if the UI is not interested in supporting
  169. any extensions. This is similar to LV2_Descriptor::extension_data().
  170. */
  171. const void* (*extension_data)(const char* uri);
  172. } LV2UI_Descriptor;
  173. /**
  174. Feature/interface for resizable UIs (LV2_UI__resize).
  175. This structure is used in two ways: as a feature passed by the host via
  176. LV2UI_Descriptor::instantiate(), or as an interface provided by a UI via
  177. LV2UI_Descriptor::extension_data()).
  178. */
  179. typedef struct _LV2UI_Resize {
  180. /**
  181. Pointer to opaque data which must be passed to ui_resize().
  182. */
  183. LV2UI_Feature_Handle handle;
  184. /**
  185. Request/advertise a size change.
  186. When provided by the host, the UI may call this function to inform the
  187. host about the size of the UI.
  188. When provided by the UI, the host may call this function to notify the
  189. UI that it should change its size accordingly. In this case, the host
  190. must pass the LV2UI_Handle to provide access to the UI instance.
  191. @return 0 on success.
  192. */
  193. int (*ui_resize)(LV2UI_Feature_Handle handle, int width, int height);
  194. } LV2UI_Resize;
  195. /**
  196. Feature to map port symbols to UIs.
  197. This can be used by the UI to get the index for a port with the given
  198. symbol. This makes it possible to implement and distribute a UI separately
  199. from the plugin (since symbol, unlike index, is a stable port identifier).
  200. */
  201. typedef struct _LV2UI_Port_Map {
  202. /**
  203. Pointer to opaque data which must be passed to port_index().
  204. */
  205. LV2UI_Feature_Handle handle;
  206. /**
  207. Get the index for the port with the given `symbol`.
  208. @return The index of the port, or LV2UI_INVALID_PORT_INDEX if no such
  209. port is found.
  210. */
  211. uint32_t (*port_index)(LV2UI_Feature_Handle handle, const char* symbol);
  212. } LV2UI_Port_Map;
  213. /**
  214. Feature to subscribe to port updates (LV2_UI__portSubscribe).
  215. */
  216. typedef struct _LV2UI_Port_Subscribe {
  217. /**
  218. Pointer to opaque data which must be passed to subscribe() and
  219. unsubscribe().
  220. */
  221. LV2UI_Feature_Handle handle;
  222. /**
  223. Subscribe to updates for a port.
  224. This means that the host will call the UI's port_event() function when
  225. the port value changes (as defined by protocol).
  226. Calling this function with the same `port_index` and `port_protocol`
  227. as an already active subscription has no effect.
  228. @param handle The handle field of this struct.
  229. @param port_index The index of the port.
  230. @param port_protocol The URID of the ui:PortProtocol.
  231. @param features Features for this subscription.
  232. @return 0 on success.
  233. */
  234. uint32_t (*subscribe)(LV2UI_Feature_Handle handle,
  235. uint32_t port_index,
  236. uint32_t port_protocol,
  237. const LV2_Feature* const* features);
  238. /**
  239. Unsubscribe from updates for a port.
  240. This means that the host will cease calling calling port_event() when
  241. the port value changes.
  242. Calling this function with a `port_index` and `port_protocol` that
  243. does not refer to an active port subscription has no effect.
  244. @param handle The handle field of this struct.
  245. @param port_index The index of the port.
  246. @param port_protocol The URID of the ui:PortProtocol.
  247. @param features Features for this subscription.
  248. @return 0 on success.
  249. */
  250. uint32_t (*unsubscribe)(LV2UI_Feature_Handle handle,
  251. uint32_t port_index,
  252. uint32_t port_protocol,
  253. const LV2_Feature* const* features);
  254. } LV2UI_Port_Subscribe;
  255. /**
  256. A feature to notify the host that the user has grabbed a UI control.
  257. */
  258. typedef struct _LV2UI_Touch {
  259. /**
  260. Pointer to opaque data which must be passed to ui_resize().
  261. */
  262. LV2UI_Feature_Handle handle;
  263. /**
  264. Notify the host that a control has been grabbed or released.
  265. The host should cease automating the port or otherwise manipulating the
  266. port value until the control has been ungrabbed.
  267. @param handle The handle field of this struct.
  268. @param port_index The index of the port associated with the control.
  269. @param grabbed If true, the control has been grabbed, otherwise the
  270. control has been released.
  271. */
  272. void (*touch)(LV2UI_Feature_Handle handle,
  273. uint32_t port_index,
  274. bool grabbed);
  275. } LV2UI_Touch;
  276. /**
  277. UI Idle Interface (LV2_UI__idleInterface)
  278. UIs can provide this interface to have an idle() callback called by the host
  279. rapidly to update the UI.
  280. */
  281. typedef struct _LV2UI_Idle_Interface {
  282. /**
  283. Run a single iteration of the UI's idle loop.
  284. This will be called rapidly in the UI thread at a rate appropriate
  285. for a toolkit main loop. There are no precise timing guarantees, but
  286. the host should attempt to call idle() at a high enough rate for smooth
  287. animation, at least 30Hz.
  288. @return non-zero if the UI has been closed, in which case the host
  289. should stop calling idle(), and can either completely destroy the UI, or
  290. re-show it and resume calling idle().
  291. */
  292. int (*idle)(LV2UI_Handle ui);
  293. } LV2UI_Idle_Interface;
  294. /**
  295. UI Show Interface (LV2_UI__showInterface)
  296. UIs can provide this interface to show and hide a window, which allows them
  297. to function in hosts unable to embed their widget. This allows any UI to
  298. provide a fallback for embedding that works in any host.
  299. If used:
  300. - The host MUST use LV2UI_Idle_Interface to drive the UI.
  301. - The UI MUST return non-zero from LV2UI_Idle_Interface::idle() when it has been closed.
  302. - If idle() returns non-zero, the host MUST call hide() and stop calling
  303. idle(). It MAY later call show() then resume calling idle().
  304. */
  305. typedef struct _LV2UI_Show_Interface {
  306. /**
  307. Show a window for this UI.
  308. The window title MAY have been passed by the host to
  309. LV2UI_Descriptor::instantiate() as an LV2_Options_Option with key
  310. LV2_UI__windowTitle.
  311. @return 0 on success, or anything else to stop being called.
  312. */
  313. int (*show)(LV2UI_Handle ui);
  314. /**
  315. Hide the window for this UI.
  316. @return 0 on success, or anything else to stop being called.
  317. */
  318. int (*hide)(LV2UI_Handle ui);
  319. } LV2UI_Show_Interface;
  320. /**
  321. Peak data for a slice of time, the update format for ui:peakProtocol.
  322. */
  323. typedef struct _LV2UI_Peak_Data {
  324. /**
  325. The start of the measurement period. This is just a running counter
  326. that is only meaningful in comparison to previous values and must not be
  327. interpreted as an absolute time.
  328. */
  329. uint32_t period_start;
  330. /**
  331. The size of the measurement period, in the same units as period_start.
  332. */
  333. uint32_t period_size;
  334. /**
  335. The peak value for the measurement period. This should be the maximal
  336. value for abs(sample) over all the samples in the period.
  337. */
  338. float peak;
  339. } LV2UI_Peak_Data;
  340. /**
  341. Prototype for UI accessor function.
  342. This is the entry point to a UI library, which works in the same way as
  343. lv2_descriptor() but for UIs rather than plugins.
  344. */
  345. LV2_SYMBOL_EXPORT
  346. const LV2UI_Descriptor* lv2ui_descriptor(uint32_t index);
  347. /**
  348. The type of the lv2ui_descriptor() function.
  349. */
  350. typedef const LV2UI_Descriptor* (*LV2UI_DescriptorFunction)(uint32_t index);
  351. #ifdef __cplusplus
  352. }
  353. #endif
  354. #endif /* LV2_UI_H */
  355. /**
  356. @}
  357. */