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.

431 lines
14KB

  1. /*
  2. LV2 UI Extension
  3. Copyright 2009-2014 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 User Interface API.
  18. For high-level documentation, see <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__showInterface LV2_UI_PREFIX "showInterface"
  47. #define LV2_UI__touch LV2_UI_PREFIX "touch"
  48. #define LV2_UI__ui LV2_UI_PREFIX "ui"
  49. #define LV2_UI__updateRate LV2_UI_PREFIX "updateRate"
  50. #define LV2_UI__windowTitle LV2_UI_PREFIX "windowTitle"
  51. /**
  52. The index returned by LV2_UI_Port_Port::port_index() for unknown ports.
  53. */
  54. #define LV2UI_INVALID_PORT_INDEX ((uint32_t)-1)
  55. #ifdef __cplusplus
  56. extern "C" {
  57. #else
  58. # include <stdbool.h>
  59. #endif
  60. /**
  61. A pointer to some widget or other type of UI handle.
  62. The actual type is defined by the type of the UI.
  63. */
  64. typedef void* LV2UI_Widget;
  65. /**
  66. A pointer to UI instance internals.
  67. The host may compare this to NULL, but otherwise MUST NOT interpret it.
  68. */
  69. typedef void* LV2UI_Handle;
  70. /**
  71. A pointer to a controller provided by the host.
  72. The UI may compare this to NULL, but otherwise MUST NOT interpret it.
  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. A host-provided function that sends data to a plugin's input ports.
  81. The @p buffer parameter must point to a block of data, @p buffer_size bytes
  82. large. The format of this data and how the host should use it is defined by
  83. the @p port_protocol. This buffer is owned by the UI and is only valid for
  84. the duration of this call.
  85. The @p port_protocol parameter should either be 0 or the URID for a
  86. ui:PortProtocol. If it is 0, the protocol is implicitly ui:floatProtocol,
  87. the port MUST be an lv2:ControlPort input, @p buffer MUST point to a single
  88. float value, and @p buffer_size MUST be sizeof(float).
  89. The UI SHOULD NOT use a protocol not supported by the host, but the host
  90. MUST gracefully ignore any protocol it does not understand.
  91. */
  92. typedef void (*LV2UI_Write_Function)(LV2UI_Controller controller,
  93. uint32_t port_index,
  94. uint32_t buffer_size,
  95. uint32_t port_protocol,
  96. const void* buffer);
  97. /**
  98. A plugin UI.
  99. A pointer to an object of this type is returned by the lv2ui_descriptor()
  100. function.
  101. */
  102. typedef struct _LV2UI_Descriptor {
  103. /**
  104. The URI for this UI (not for the plugin it controls).
  105. */
  106. const char* URI;
  107. /**
  108. Create a new UI and return a handle to it. This function works
  109. similarly to LV2_Descriptor::instantiate().
  110. @param descriptor The descriptor for the UI to instantiate.
  111. @param plugin_uri The URI of the plugin that this UI will control.
  112. @param bundle_path The path to the bundle containing this UI, including
  113. the trailing directory separator.
  114. @param write_function A function that the UI can use to send data to the
  115. plugin's input ports.
  116. @param controller A handle for the plugin instance to be passed as the
  117. first parameter of UI methods.
  118. @param widget (output) widget pointer. The UI points this at its main
  119. widget, which has the type defined by the UI type in the data file.
  120. @param features An array of LV2_Feature pointers. The host must pass
  121. all feature URIs that it and the UI supports and any additional data, as
  122. in LV2_Descriptor::instantiate(). Note that UI features and plugin
  123. features are not necessarily the same.
  124. */
  125. LV2UI_Handle (*instantiate)(const struct _LV2UI_Descriptor* descriptor,
  126. const char* plugin_uri,
  127. const char* bundle_path,
  128. LV2UI_Write_Function write_function,
  129. LV2UI_Controller controller,
  130. LV2UI_Widget* widget,
  131. const LV2_Feature* const* features);
  132. /**
  133. Destroy the UI. The host must not try to access the widget after
  134. calling this function.
  135. */
  136. void (*cleanup)(LV2UI_Handle ui);
  137. /**
  138. Tell the UI that something interesting has happened at a plugin port.
  139. What is "interesting" and how it is written to @p buffer is defined by
  140. @p format, which has the same meaning as in LV2UI_Write_Function().
  141. Format 0 is a special case for lv2:ControlPort, where this function
  142. should be called when the port value changes (but not necessarily for
  143. every change), @p buffer_size must be sizeof(float), and @p buffer
  144. points to a single IEEE-754 float.
  145. By default, the host should only call this function for lv2:ControlPort
  146. inputs. However, the UI can request updates for other ports statically
  147. with ui:portNotification or dynamicaly with ui:portSubscribe.
  148. The UI MUST NOT retain any reference to @p buffer after this function
  149. returns, it is only valid for the duration of the call.
  150. This member may be NULL if the UI is not interested in any port events.
  151. */
  152. void (*port_event)(LV2UI_Handle ui,
  153. uint32_t port_index,
  154. uint32_t buffer_size,
  155. uint32_t format,
  156. const void* buffer);
  157. /**
  158. Return a data structure associated with an extension URI, typically an
  159. interface struct with additional function pointers
  160. This member may be set to NULL if the UI is not interested in supporting
  161. any extensions. This is similar to LV2_Descriptor::extension_data().
  162. */
  163. const void* (*extension_data)(const char* uri);
  164. } LV2UI_Descriptor;
  165. /**
  166. Feature/interface for resizable UIs (LV2_UI__resize).
  167. This structure is used in two ways: as a feature passed by the host via
  168. LV2UI_Descriptor::instantiate(), or as an interface provided by a UI via
  169. LV2UI_Descriptor::extension_data()).
  170. */
  171. typedef struct _LV2UI_Resize {
  172. /**
  173. Pointer to opaque data which must be passed to ui_resize().
  174. */
  175. LV2UI_Feature_Handle handle;
  176. /**
  177. Request/advertise a size change.
  178. When provided by the host, the UI may call this function to inform the
  179. host about the size of the UI.
  180. When provided by the UI, the host may call this function to notify the
  181. UI that it should change its size accordingly.
  182. @return 0 on success.
  183. */
  184. int (*ui_resize)(LV2UI_Feature_Handle handle, int width, int height);
  185. } LV2UI_Resize;
  186. /**
  187. Feature to map port symbols to UIs.
  188. This can be used by the UI to get the index for a port with the given
  189. symbol. This makes it possible to implement and distribute a UI separately
  190. from the plugin (since symbol, unlike index, is a stable port identifier).
  191. */
  192. typedef struct _LV2UI_Port_Map {
  193. /**
  194. Pointer to opaque data which must be passed to port_index().
  195. */
  196. LV2UI_Feature_Handle handle;
  197. /**
  198. Get the index for the port with the given @p symbol.
  199. @return The index of the port, or LV2UI_INVALID_PORT_INDEX if no such
  200. port is found.
  201. */
  202. uint32_t (*port_index)(LV2UI_Feature_Handle handle, const char* symbol);
  203. } LV2UI_Port_Map;
  204. /**
  205. Feature to subscribe to port updates (LV2_UI__portSubscribe).
  206. */
  207. typedef struct _LV2UI_Port_Subscribe {
  208. /**
  209. Pointer to opaque data which must be passed to subscribe() and
  210. unsubscribe().
  211. */
  212. LV2UI_Feature_Handle handle;
  213. /**
  214. Subscribe to updates for a port.
  215. This means that the host will call the UI's port_event() function when
  216. the port value changes (as defined by protocol).
  217. Calling this function with the same @p port_index and @p port_protocol
  218. as an already active subscription has no effect.
  219. @param handle The handle field of this struct.
  220. @param port_index The index of the port.
  221. @param port_protocol The URID of the ui:PortProtocol.
  222. @param features Features for this subscription.
  223. @return 0 on success.
  224. */
  225. uint32_t (*subscribe)(LV2UI_Feature_Handle handle,
  226. uint32_t port_index,
  227. uint32_t port_protocol,
  228. const LV2_Feature* const* features);
  229. /**
  230. Unsubscribe from updates for a port.
  231. This means that the host will cease calling calling port_event() when
  232. the port value changes.
  233. Calling this function with a @p port_index and @p port_protocol that
  234. does not refer to an active port subscription has no effect.
  235. @param handle The handle field of this struct.
  236. @param port_index The index of the port.
  237. @param port_protocol The URID of the ui:PortProtocol.
  238. @param features Features for this subscription.
  239. @return 0 on success.
  240. */
  241. uint32_t (*unsubscribe)(LV2UI_Feature_Handle handle,
  242. uint32_t port_index,
  243. uint32_t port_protocol,
  244. const LV2_Feature* const* features);
  245. } LV2UI_Port_Subscribe;
  246. /**
  247. A feature to notify the host that the user has grabbed a UI control.
  248. */
  249. typedef struct _LV2UI_Touch {
  250. /**
  251. Pointer to opaque data which must be passed to ui_resize().
  252. */
  253. LV2UI_Feature_Handle handle;
  254. /**
  255. Notify the host that a control has been grabbed or released.
  256. The host should cease automating the port or otherwise manipulating the
  257. port value until the control has been ungrabbed.
  258. @param handle The handle field of this struct.
  259. @param port_index The index of the port associated with the control.
  260. @param grabbed If true, the control has been grabbed, otherwise the
  261. control has been released.
  262. */
  263. void (*touch)(LV2UI_Feature_Handle handle,
  264. uint32_t port_index,
  265. bool grabbed);
  266. } LV2UI_Touch;
  267. /**
  268. UI Idle Interface (LV2_UI__idleInterface)
  269. UIs can provide this interface to have an idle() callback called by the host
  270. rapidly to update the UI.
  271. */
  272. typedef struct _LV2UI_Idle_Interface {
  273. /**
  274. Run a single iteration of the UI's idle loop.
  275. This will be called rapidly in the UI thread at a rate appropriate
  276. for a toolkit main loop. There are no precise timing guarantees, but
  277. the host should attempt to call idle() at a high enough rate for smooth
  278. animation, at least 30Hz.
  279. @return non-zero if the UI has been closed, in which case the host
  280. should stop calling idle(), and can either completely destroy the UI, or
  281. re-show it and resume calling idle().
  282. */
  283. int (*idle)(LV2UI_Handle ui);
  284. } LV2UI_Idle_Interface;
  285. /**
  286. UI Show Interface (LV2_UI__showInterface)
  287. UIs can provide this interface to show and hide a window, which allows them
  288. to function in hosts unable to embed their widget. This allows any UI to
  289. provide a fallback for embedding that works in any host.
  290. If used:
  291. - The host MUST use LV2UI_Idle_Interface to drive the UI.
  292. - The UI MUST return non-zero from LV2UI_Idle_Interface::idle() when it has been closed.
  293. - If idle() returns non-zero, the host MUST call hide() and stop calling
  294. idle(). It MAY later call show() then resume calling idle().
  295. */
  296. typedef struct _LV2UI_Show_Interface {
  297. /**
  298. Show a window for this UI.
  299. The window title MAY have been passed by the host to
  300. LV2UI_Descriptor::instantiate() as an LV2_Options_Option with key
  301. LV2_UI__windowTitle.
  302. @return 0 on success, or anything else to stop being called.
  303. */
  304. int (*show)(LV2UI_Handle ui);
  305. /**
  306. Hide the window for this UI.
  307. @return 0 on success, or anything else to stop being called.
  308. */
  309. int (*hide)(LV2UI_Handle ui);
  310. } LV2UI_Show_Interface;
  311. /**
  312. Peak data for a slice of time, the update format for ui:peakProtocol.
  313. */
  314. typedef struct _LV2UI_Peak_Data {
  315. /**
  316. The start of the measurement period. This is just a running counter
  317. that is only meaningful in comparison to previous values and must not be
  318. interpreted as an absolute time.
  319. */
  320. uint32_t period_start;
  321. /**
  322. The size of the measurement period, in the same units as period_start.
  323. */
  324. uint32_t period_size;
  325. /**
  326. The peak value for the measurement period. This should be the maximal
  327. value for abs(sample) over all the samples in the period.
  328. */
  329. float peak;
  330. } LV2UI_Peak_Data;
  331. /**
  332. Prototype for UI accessor function.
  333. This is the entry point to a UI library, which works in the same way as
  334. lv2_descriptor() but for UIs rather than plugins.
  335. */
  336. LV2_SYMBOL_EXPORT
  337. const LV2UI_Descriptor* lv2ui_descriptor(uint32_t index);
  338. /**
  339. The type of the lv2ui_descriptor() function.
  340. */
  341. typedef const LV2UI_Descriptor* (*LV2UI_DescriptorFunction)(uint32_t index);
  342. #ifdef __cplusplus
  343. }
  344. #endif
  345. #endif /* LV2_UI_H */