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.

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