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.

ui.h 15KB

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