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.

408 lines
14KB

  1. /*
  2. LV2 UI Extension
  3. Copyright 2009-2012 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. @file ui.h
  18. C header for the LV2 UI extension <http://lv2plug.in/ns/extensions/ui>.
  19. */
  20. #ifndef LV2_UI_H
  21. #define LV2_UI_H
  22. #include <stdint.h>
  23. #include "lv2.h"
  24. #define LV2_UI_URI "http://lv2plug.in/ns/extensions/ui"
  25. #define LV2_UI_PREFIX LV2_UI_URI "#"
  26. #define LV2_UI__CocoaUI LV2_UI_PREFIX "CocoaUI"
  27. #define LV2_UI__Gtk3UI LV2_UI_PREFIX "Gtk3UI"
  28. #define LV2_UI__GtkUI LV2_UI_PREFIX "GtkUI"
  29. #define LV2_UI__PortNotification LV2_UI_PREFIX "PortNotification"
  30. #define LV2_UI__Qt4UI LV2_UI_PREFIX "Qt4UI"
  31. #define LV2_UI__UI LV2_UI_PREFIX "UI"
  32. #define LV2_UI__WindowsUI LV2_UI_PREFIX "WindowsUI"
  33. #define LV2_UI__X11UI LV2_UI_PREFIX "X11UI"
  34. #define LV2_UI__binary LV2_UI_PREFIX "binary"
  35. #define LV2_UI__fixedSize LV2_UI_PREFIX "fixedSize"
  36. #define LV2_UI__idleInterface LV2_UI_PREFIX "idleInterface"
  37. #define LV2_UI__noUserResize LV2_UI_PREFIX "noUserResize"
  38. #define LV2_UI__notifyType LV2_UI_PREFIX "notifyType"
  39. #define LV2_UI__parent LV2_UI_PREFIX "parent"
  40. #define LV2_UI__plugin LV2_UI_PREFIX "plugin"
  41. #define LV2_UI__portIndex LV2_UI_PREFIX "portIndex"
  42. #define LV2_UI__portMap LV2_UI_PREFIX "portMap"
  43. #define LV2_UI__portNotification LV2_UI_PREFIX "portNotification"
  44. #define LV2_UI__portSubscribe LV2_UI_PREFIX "portSubscribe"
  45. #define LV2_UI__resize LV2_UI_PREFIX "resize"
  46. #define LV2_UI__touch LV2_UI_PREFIX "touch"
  47. #define LV2_UI__ui LV2_UI_PREFIX "ui"
  48. /**
  49. The index returned by LV2_UI_Port_Port::port_index() for unknown ports.
  50. */
  51. #define LV2UI_INVALID_PORT_INDEX ((uint32_t)-1)
  52. #ifdef __cplusplus
  53. extern "C" {
  54. #else
  55. # include <stdbool.h>
  56. #endif
  57. /**
  58. A pointer to some widget or other type of UI handle.
  59. The actual type is defined by the type of the UI.
  60. */
  61. typedef void* LV2UI_Widget;
  62. /**
  63. A pointer to an instance of a UI.
  64. It is valid to compare this to NULL (0 for C++) but otherwise the host MUST
  65. not attempt to interpret it. The UI plugin may use it to reference internal
  66. instance data.
  67. */
  68. typedef void* LV2UI_Handle;
  69. /**
  70. A pointer to a controller provided by the host.
  71. It is valid to compare this to NULL (0 for C++) but otherwise the UI plugin
  72. MUST NOT attempt to interpret it. The host may use it to reference internal
  73. instance data.
  74. */
  75. typedef void* LV2UI_Controller;
  76. /**
  77. A pointer to opaque data for a feature.
  78. */
  79. typedef void* LV2UI_Feature_Handle;
  80. /**
  81. The type of the host-provided function that the UI can use to
  82. send data to a plugin's input ports.
  83. The @p buffer parameter must point to a block of data, @c buffer_size bytes
  84. large. The format of this data and how the host should use it is defined by
  85. the @p port_protocol. This buffer is owned by the UI and is only valid for
  86. the duration of this call.
  87. The @p port_protocol parameter should either be 0 or the URID for a
  88. ui:PortProtocol. If it is 0, the protocol is implicitly ui:floatProtocol,
  89. the port must be an lv2:ControlPort input, @c buffer must point to a single
  90. float value, and @c buffer_size must be sizeof(float).
  91. The UI SHOULD NOT use a PortProtocol not supported by the host (i.e. one not
  92. passed by the host as a feature), but the host MUST gracefully ignore any
  93. port_protocol it does not understand.
  94. */
  95. typedef void (*LV2UI_Write_Function)(LV2UI_Controller controller,
  96. uint32_t port_index,
  97. uint32_t buffer_size,
  98. uint32_t port_protocol,
  99. const void* buffer);
  100. /**
  101. The implementation of a UI.
  102. A pointer to an object of this type is returned by the lv2ui_descriptor()
  103. function.
  104. */
  105. typedef struct _LV2UI_Descriptor {
  106. /**
  107. The URI for this UI (not for the plugin it controls).
  108. */
  109. const char* URI;
  110. /**
  111. Create a new UI object and return a handle to it. This function works
  112. similarly to the instantiate() member in LV2_Descriptor.
  113. @param descriptor The descriptor for the UI that you want to instantiate.
  114. @param plugin_uri The URI of the plugin that this UI will control.
  115. @param bundle_path The path to the bundle containing the RDF data file
  116. that references this shared object file, including the trailing '/'.
  117. @param write_function A function provided by the host that the UI can use
  118. to send data to the plugin's input ports.
  119. @param controller A handle for the plugin instance that should be passed
  120. as the first parameter of @p write_function.
  121. @param widget A pointer to an LV2UI_Widget. The UI will write a widget
  122. pointer to this location (what type of widget depends on the RDF class of
  123. the UI) that will be the main UI widget.
  124. @param features An array of LV2_Feature pointers. The host must pass all
  125. feature URIs that it and the UI supports and any additional data, just
  126. like in the LV2 plugin instantiate() function. Note that UI features and
  127. plugin features are NOT necessarily the same, they just share the same
  128. data structure - this will probably not be the same array as the one the
  129. plugin host passes to a plugin.
  130. */
  131. LV2UI_Handle (*instantiate)(const struct _LV2UI_Descriptor* descriptor,
  132. const char* plugin_uri,
  133. const char* bundle_path,
  134. LV2UI_Write_Function write_function,
  135. LV2UI_Controller controller,
  136. LV2UI_Widget* widget,
  137. const LV2_Feature* const* features);
  138. /**
  139. Destroy the UI object and the associated widget. The host must not try
  140. to access the widget after calling this function.
  141. */
  142. void (*cleanup)(LV2UI_Handle ui);
  143. /**
  144. Tell the UI that something interesting has happened at a plugin port.
  145. What is interesting and how it is written to the buffer passed to this
  146. function is defined by the @p format parameter, which has the same
  147. meaning as in LV2UI_Write_Function. The only exception is ports of the
  148. class lv2:ControlPort, for which this function should be called when the
  149. port value changes (it does not have to be called for every single change
  150. if the host's UI thread has problems keeping up with the thread the
  151. plugin is running in), @p buffer_size should be 4, the buffer should
  152. contain a single IEEE-754 float, and @p format should be 0.
  153. By default, the host should only call this function for input ports of
  154. the lv2:ControlPort class. However, this can be modified by using
  155. ui:portNotification in the UI data, or the ui:portSubscribe feature.
  156. The @p buffer is only valid during the time of this function call, so if
  157. the UI wants to keep it for later use it has to copy the contents to an
  158. internal buffer.
  159. This member may be set to NULL if the UI is not interested in any
  160. port events.
  161. */
  162. void (*port_event)(LV2UI_Handle ui,
  163. uint32_t port_index,
  164. uint32_t buffer_size,
  165. uint32_t format,
  166. const void* buffer);
  167. /**
  168. Return a data structure associated with an extension URI, for example
  169. a struct containing additional function pointers.
  170. Avoid returning function pointers directly since standard C/C++ has no
  171. valid way of casting a void* to a function pointer. This member may be set
  172. to NULL if the UI is not interested in supporting any extensions. This is
  173. similar to the extension_data() member in LV2_Descriptor.
  174. */
  175. const void* (*extension_data)(const char* uri);
  176. } LV2UI_Descriptor;
  177. /**
  178. UI Resize Feature (LV2_UI__resize)
  179. This structure may be used in two ways: as a feature passed by the host via
  180. LV2UI_Descriptor::instantiate(), or as extension data provided by a UI via
  181. LV2UI_Descriptor::extension_data()).
  182. */
  183. typedef struct _LV2UI_Resize {
  184. /**
  185. Pointer to opaque data which must be passed to ui_resize().
  186. */
  187. LV2UI_Feature_Handle handle;
  188. /**
  189. Request or advertise a size change.
  190. When this struct is provided by the host, the UI may call this
  191. function to inform the host about the size of the UI.
  192. When this struct is provided by the UI, the host may call this
  193. function to notify the UI that it should change its size accordingly.
  194. @return 0 on success.
  195. */
  196. int (*ui_resize)(LV2UI_Feature_Handle handle, int width, int height);
  197. } LV2UI_Resize;
  198. /**
  199. Port Map Feature (LV2_UI__portMap).
  200. This feature can be used by the UI to get the index for a port with the
  201. given symbol. This makes it possible to implement and distribute a UI
  202. separately from the plugin (since symbol is a guaranteed stable port
  203. identifier while index is not).
  204. */
  205. typedef struct _LV2UI_Port_Map {
  206. /**
  207. Pointer to opaque data which must be passed to ui_resize().
  208. */
  209. LV2UI_Feature_Handle handle;
  210. /**
  211. Get the index for the port with the given @p symbol.
  212. @return The index of the port, or LV2_UI_INVALID_PORT_INDEX if no such
  213. port is found.
  214. */
  215. uint32_t (*port_index)(LV2UI_Feature_Handle handle, const char* symbol);
  216. } LV2UI_Port_Map;
  217. /**
  218. Port subscription feature (LV2_UI__portSubscribe);
  219. */
  220. typedef struct _LV2UI_Port_Subscribe {
  221. /**
  222. Pointer to opaque data which must be passed to ui_resize().
  223. */
  224. LV2UI_Feature_Handle handle;
  225. /**
  226. Subscribe to updates for a port.
  227. This means that the host will call the UI's port_event() function when
  228. the port value changes (as defined by protocol).
  229. Calling this function with the same @p port_index and @p port_protocol
  230. as an already active subscription has no effect.
  231. @param handle The handle field of this struct.
  232. @param port_index The index of the port.
  233. @param port_protocol The URID of the ui:PortProtocol.
  234. @param features Features for this subscription.
  235. @return 0 on success.
  236. */
  237. uint32_t (*subscribe)(LV2UI_Feature_Handle handle,
  238. uint32_t port_index,
  239. uint32_t port_protocol,
  240. const LV2_Feature* const* features);
  241. /**
  242. Unsubscribe from updates for a port.
  243. This means that the host will cease calling calling port_event() when
  244. the port value changes.
  245. Calling this function with a @p port_index and @p port_protocol that
  246. does not refer to an active port subscription has no effect.
  247. @param handle The handle field of this struct.
  248. @param port_index The index of the port.
  249. @param port_protocol The URID of the ui:PortProtocol.
  250. @param features Features for this subscription.
  251. @return 0 on success.
  252. */
  253. uint32_t (*unsubscribe)(LV2UI_Feature_Handle handle,
  254. uint32_t port_index,
  255. uint32_t port_protocol,
  256. const LV2_Feature* const* features);
  257. } LV2UI_Port_Subscribe;
  258. /**
  259. A feature to notify the host the user has grabbed a UI control.
  260. */
  261. typedef struct _LV2UI_Touch {
  262. /**
  263. Pointer to opaque data which must be passed to ui_resize().
  264. */
  265. LV2UI_Feature_Handle handle;
  266. /**
  267. Notify the host that a control has been grabbed or released.
  268. @param handle The handle field of this struct.
  269. @param port_index The index of the port associated with the control.
  270. @param grabbed If true, the control has been grabbed, otherwise the
  271. control has been released.
  272. */
  273. void (*touch)(LV2UI_Feature_Handle handle,
  274. uint32_t port_index,
  275. bool grabbed);
  276. } LV2UI_Touch;
  277. /**
  278. UI Idle Feature (LV2_UI__idle)
  279. This feature is an addition to the UI API that provides a callback for the
  280. host to call rapidly, e.g. to drive the idle callback of a toolkit.
  281. */
  282. typedef struct _LV2UI_Idle_Interface {
  283. /**
  284. Run a single iteration of the UI's idle loop.
  285. This will be called "frequently" in the UI thread at a rate appropriate
  286. for a toolkit main loop. There are no precise timing guarantees.
  287. @return 0 on success, or anything else to stop being called.
  288. */
  289. int (*idle)(LV2UI_Handle ui);
  290. } LV2UI_Idle_Interface;
  291. /**
  292. Peak data for a slice of time, the update format for ui:peakProtocol.
  293. */
  294. typedef struct _LV2UI_Peak_Data {
  295. /**
  296. The start of the measurement period. This is just a running counter
  297. that is only meaningful in comparison to previous values and must not be
  298. interpreted as an absolute time.
  299. */
  300. uint32_t period_start;
  301. /**
  302. The size of the measurement period, in the same units as period_start.
  303. */
  304. uint32_t period_size;
  305. /**
  306. The peak value for the measurement period. This should be the maximal
  307. value for abs(sample) over all the samples in the period.
  308. */
  309. float peak;
  310. } LV2UI_Peak_Data;
  311. /**
  312. A plugin UI programmer must include a function called "lv2ui_descriptor"
  313. with the following function prototype within the shared object file. This
  314. function will have C-style linkage (if you are using C++ this is taken care
  315. of by the 'extern "C"' clause at the top of the file). This function is
  316. loaded from the library by the UI host and called to get a
  317. LV2UI_Descriptor for the wanted plugin.
  318. Just like lv2_descriptor(), this function takes an index parameter. The
  319. index should only be used for enumeration and not as any sort of ID number -
  320. the host should just iterate from 0 and upwards until the function returns
  321. NULL or a descriptor with an URI matching the one the host is looking for.
  322. */
  323. LV2_SYMBOL_EXPORT
  324. const LV2UI_Descriptor* lv2ui_descriptor(uint32_t index);
  325. /**
  326. The type of the lv2ui_descriptor() function.
  327. */
  328. typedef const LV2UI_Descriptor* (*LV2UI_DescriptorFunction)(uint32_t index);
  329. #ifdef __cplusplus
  330. }
  331. #endif
  332. #endif /* LV2_UI_H */