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.

540 lines
20KB

  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. #include "urid.h"
  27. #define LV2_UI_URI "http://lv2plug.in/ns/extensions/ui" ///< http://lv2plug.in/ns/extensions/ui
  28. #define LV2_UI_PREFIX LV2_UI_URI "#" ///< http://lv2plug.in/ns/extensions/ui#
  29. #define LV2_UI__CocoaUI LV2_UI_PREFIX "CocoaUI" ///< http://lv2plug.in/ns/extensions/ui#CocoaUI
  30. #define LV2_UI__Gtk3UI LV2_UI_PREFIX "Gtk3UI" ///< http://lv2plug.in/ns/extensions/ui#Gtk3UI
  31. #define LV2_UI__GtkUI LV2_UI_PREFIX "GtkUI" ///< http://lv2plug.in/ns/extensions/ui#GtkUI
  32. #define LV2_UI__PortNotification LV2_UI_PREFIX "PortNotification" ///< http://lv2plug.in/ns/extensions/ui#PortNotification
  33. #define LV2_UI__PortProtocol LV2_UI_PREFIX "PortProtocol" ///< http://lv2plug.in/ns/extensions/ui#PortProtocol
  34. #define LV2_UI__Qt4UI LV2_UI_PREFIX "Qt4UI" ///< http://lv2plug.in/ns/extensions/ui#Qt4UI
  35. #define LV2_UI__Qt5UI LV2_UI_PREFIX "Qt5UI" ///< http://lv2plug.in/ns/extensions/ui#Qt5UI
  36. #define LV2_UI__UI LV2_UI_PREFIX "UI" ///< http://lv2plug.in/ns/extensions/ui#UI
  37. #define LV2_UI__WindowsUI LV2_UI_PREFIX "WindowsUI" ///< http://lv2plug.in/ns/extensions/ui#WindowsUI
  38. #define LV2_UI__X11UI LV2_UI_PREFIX "X11UI" ///< http://lv2plug.in/ns/extensions/ui#X11UI
  39. #define LV2_UI__backgroundColor LV2_UI_PREFIX "backgroundColor" ///< http://lv2plug.in/ns/extensions/ui#backgroundColor
  40. #define LV2_UI__binary LV2_UI_PREFIX "binary" ///< http://lv2plug.in/ns/extensions/ui#binary
  41. #define LV2_UI__fixedSize LV2_UI_PREFIX "fixedSize" ///< http://lv2plug.in/ns/extensions/ui#fixedSize
  42. #define LV2_UI__foregroundColor LV2_UI_PREFIX "foregroundColor" ///< http://lv2plug.in/ns/extensions/ui#foregroundColor
  43. #define LV2_UI__idleInterface LV2_UI_PREFIX "idleInterface" ///< http://lv2plug.in/ns/extensions/ui#idleInterface
  44. #define LV2_UI__noUserResize LV2_UI_PREFIX "noUserResize" ///< http://lv2plug.in/ns/extensions/ui#noUserResize
  45. #define LV2_UI__notifyType LV2_UI_PREFIX "notifyType" ///< http://lv2plug.in/ns/extensions/ui#notifyType
  46. #define LV2_UI__parent LV2_UI_PREFIX "parent" ///< http://lv2plug.in/ns/extensions/ui#parent
  47. #define LV2_UI__plugin LV2_UI_PREFIX "plugin" ///< http://lv2plug.in/ns/extensions/ui#plugin
  48. #define LV2_UI__portIndex LV2_UI_PREFIX "portIndex" ///< http://lv2plug.in/ns/extensions/ui#portIndex
  49. #define LV2_UI__portMap LV2_UI_PREFIX "portMap" ///< http://lv2plug.in/ns/extensions/ui#portMap
  50. #define LV2_UI__portNotification LV2_UI_PREFIX "portNotification" ///< http://lv2plug.in/ns/extensions/ui#portNotification
  51. #define LV2_UI__portSubscribe LV2_UI_PREFIX "portSubscribe" ///< http://lv2plug.in/ns/extensions/ui#portSubscribe
  52. #define LV2_UI__protocol LV2_UI_PREFIX "protocol" ///< http://lv2plug.in/ns/extensions/ui#protocol
  53. #define LV2_UI__floatProtocol LV2_UI_PREFIX "floatProtocol" ///< http://lv2plug.in/ns/extensions/ui#floatProtocol
  54. #define LV2_UI__peakProtocol LV2_UI_PREFIX "peakProtocol" ///< http://lv2plug.in/ns/extensions/ui#peakProtocol
  55. #define LV2_UI__requestValue LV2_UI_PREFIX "requestValue" ///< http://lv2plug.in/ns/extensions/ui#requestValue
  56. #define LV2_UI__resize LV2_UI_PREFIX "resize" ///< http://lv2plug.in/ns/extensions/ui#resize
  57. #define LV2_UI__scaleFactor LV2_UI_PREFIX "scaleFactor" ///< http://lv2plug.in/ns/extensions/ui#scaleFactor
  58. #define LV2_UI__showInterface LV2_UI_PREFIX "showInterface" ///< http://lv2plug.in/ns/extensions/ui#showInterface
  59. #define LV2_UI__touch LV2_UI_PREFIX "touch" ///< http://lv2plug.in/ns/extensions/ui#touch
  60. #define LV2_UI__ui LV2_UI_PREFIX "ui" ///< http://lv2plug.in/ns/extensions/ui#ui
  61. #define LV2_UI__updateRate LV2_UI_PREFIX "updateRate" ///< http://lv2plug.in/ns/extensions/ui#updateRate
  62. #define LV2_UI__windowTitle LV2_UI_PREFIX "windowTitle" ///< http://lv2plug.in/ns/extensions/ui#windowTitle
  63. /**
  64. The index returned by LV2UI_Port_Map::port_index() for unknown ports.
  65. */
  66. #define LV2UI_INVALID_PORT_INDEX ((uint32_t)-1)
  67. #ifdef __cplusplus
  68. extern "C" {
  69. #else
  70. # include <stdbool.h>
  71. #endif
  72. /**
  73. A pointer to some widget or other type of UI handle.
  74. The actual type is defined by the type of the UI.
  75. */
  76. typedef void* LV2UI_Widget;
  77. /**
  78. A pointer to UI instance internals.
  79. The host may compare this to NULL, but otherwise MUST NOT interpret it.
  80. */
  81. typedef void* LV2UI_Handle;
  82. /**
  83. A pointer to a controller provided by the host.
  84. The UI may compare this to NULL, but otherwise MUST NOT interpret it.
  85. */
  86. typedef void* LV2UI_Controller;
  87. /**
  88. A pointer to opaque data for a feature.
  89. */
  90. typedef void* LV2UI_Feature_Handle;
  91. /**
  92. A host-provided function that sends data to a plugin's input ports.
  93. @param controller The opaque controller pointer passed to
  94. LV2UI_Descriptor::instantiate().
  95. @param port_index Index of the port to update.
  96. @param buffer Buffer containing `buffer_size` bytes of data.
  97. @param buffer_size Size of `buffer` in bytes.
  98. @param port_protocol Either 0 or the URID for a ui:PortProtocol. If 0, the
  99. protocol is implicitly ui:floatProtocol, the port MUST be an lv2:ControlPort
  100. input, `buffer` MUST point to a single float value, and `buffer_size` MUST
  101. be sizeof(float). The UI SHOULD NOT use a protocol not supported by the
  102. host, but the host MUST gracefully ignore any protocol it does not
  103. understand.
  104. */
  105. typedef void (*LV2UI_Write_Function)(LV2UI_Controller controller,
  106. uint32_t port_index,
  107. uint32_t buffer_size,
  108. uint32_t port_protocol,
  109. const void* buffer);
  110. /**
  111. A plugin UI.
  112. A pointer to an object of this type is returned by the lv2ui_descriptor()
  113. function.
  114. */
  115. typedef struct _LV2UI_Descriptor {
  116. /**
  117. The URI for this UI (not for the plugin it controls).
  118. */
  119. const char* URI;
  120. /**
  121. Create a new UI and return a handle to it. This function works
  122. similarly to LV2_Descriptor::instantiate().
  123. @param descriptor The descriptor for the UI to instantiate.
  124. @param plugin_uri The URI of the plugin that this UI will control.
  125. @param bundle_path The path to the bundle containing this UI, including
  126. the trailing directory separator.
  127. @param write_function A function that the UI can use to send data to the
  128. plugin's input ports.
  129. @param controller A handle for the UI instance to be passed as the
  130. first parameter of UI methods.
  131. @param widget (output) widget pointer. The UI points this at its main
  132. widget, which has the type defined by the UI type in the data file.
  133. @param features An array of LV2_Feature pointers. The host must pass
  134. all feature URIs that it and the UI supports and any additional data, as
  135. in LV2_Descriptor::instantiate(). Note that UI features and plugin
  136. features are not necessarily the same.
  137. */
  138. LV2UI_Handle (*instantiate)(const struct _LV2UI_Descriptor* descriptor,
  139. const char* plugin_uri,
  140. const char* bundle_path,
  141. LV2UI_Write_Function write_function,
  142. LV2UI_Controller controller,
  143. LV2UI_Widget* widget,
  144. const LV2_Feature* const* features);
  145. /**
  146. Destroy the UI. The host must not try to access the widget after
  147. calling this function.
  148. */
  149. void (*cleanup)(LV2UI_Handle ui);
  150. /**
  151. Tell the UI that something interesting has happened at a plugin port.
  152. What is "interesting" and how it is written to `buffer` is defined by
  153. `format`, which has the same meaning as in LV2UI_Write_Function().
  154. Format 0 is a special case for lv2:ControlPort, where this function
  155. should be called when the port value changes (but not necessarily for
  156. every change), `buffer_size` must be sizeof(float), and `buffer`
  157. points to a single IEEE-754 float.
  158. By default, the host should only call this function for lv2:ControlPort
  159. inputs. However, the UI can request updates for other ports statically
  160. with ui:portNotification or dynamicaly with ui:portSubscribe.
  161. The UI MUST NOT retain any reference to `buffer` after this function
  162. returns, it is only valid for the duration of the call.
  163. This member may be NULL if the UI is not interested in any port events.
  164. */
  165. void (*port_event)(LV2UI_Handle ui,
  166. uint32_t port_index,
  167. uint32_t buffer_size,
  168. uint32_t format,
  169. const void* buffer);
  170. /**
  171. Return a data structure associated with an extension URI, typically an
  172. interface struct with additional function pointers
  173. This member may be set to NULL if the UI is not interested in supporting
  174. any extensions. This is similar to LV2_Descriptor::extension_data().
  175. */
  176. const void* (*extension_data)(const char* uri);
  177. } LV2UI_Descriptor;
  178. /**
  179. Feature/interface for resizable UIs (LV2_UI__resize).
  180. This structure is used in two ways: as a feature passed by the host via
  181. LV2UI_Descriptor::instantiate(), or as an interface 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/advertise a size change.
  191. When provided by the host, the UI may call this function to inform the
  192. host about the size of the UI.
  193. When provided by the UI, the host may call this function to notify the
  194. UI that it should change its size accordingly. In this case, the host
  195. must pass the LV2UI_Handle to provide access to the UI instance.
  196. @return 0 on success.
  197. */
  198. int (*ui_resize)(LV2UI_Feature_Handle handle, int width, int height);
  199. } LV2UI_Resize;
  200. /**
  201. Feature to map port symbols to UIs.
  202. This can be used by the UI to get the index for a port with the given
  203. symbol. This makes it possible to implement and distribute a UI separately
  204. from the plugin (since symbol, unlike index, is a stable port identifier).
  205. */
  206. typedef struct _LV2UI_Port_Map {
  207. /**
  208. Pointer to opaque data which must be passed to port_index().
  209. */
  210. LV2UI_Feature_Handle handle;
  211. /**
  212. Get the index for the port with the given `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. Feature to subscribe to port updates (LV2_UI__portSubscribe).
  220. */
  221. typedef struct _LV2UI_Port_Subscribe {
  222. /**
  223. Pointer to opaque data which must be passed to subscribe() and
  224. unsubscribe().
  225. */
  226. LV2UI_Feature_Handle handle;
  227. /**
  228. Subscribe to updates for a port.
  229. This means that the host will call the UI's port_event() function when
  230. the port value changes (as defined by protocol).
  231. Calling this function with the same `port_index` and `port_protocol`
  232. as an already active subscription has no effect.
  233. @param handle The handle field of this struct.
  234. @param port_index The index of the port.
  235. @param port_protocol The URID of the ui:PortProtocol.
  236. @param features Features for this subscription.
  237. @return 0 on success.
  238. */
  239. uint32_t (*subscribe)(LV2UI_Feature_Handle handle,
  240. uint32_t port_index,
  241. uint32_t port_protocol,
  242. const LV2_Feature* const* features);
  243. /**
  244. Unsubscribe from updates for a port.
  245. This means that the host will cease calling calling port_event() when
  246. the port value changes.
  247. Calling this function with a `port_index` and `port_protocol` that
  248. does not refer to an active port subscription has no effect.
  249. @param handle The handle field of this struct.
  250. @param port_index The index of the port.
  251. @param port_protocol The URID of the ui:PortProtocol.
  252. @param features Features for this subscription.
  253. @return 0 on success.
  254. */
  255. uint32_t (*unsubscribe)(LV2UI_Feature_Handle handle,
  256. uint32_t port_index,
  257. uint32_t port_protocol,
  258. const LV2_Feature* const* features);
  259. } LV2UI_Port_Subscribe;
  260. /**
  261. A feature to notify the host that the user has grabbed a UI control.
  262. */
  263. typedef struct _LV2UI_Touch {
  264. /**
  265. Pointer to opaque data which must be passed to ui_resize().
  266. */
  267. LV2UI_Feature_Handle handle;
  268. /**
  269. Notify the host that a control has been grabbed or released.
  270. The host should cease automating the port or otherwise manipulating the
  271. port value until the control has been ungrabbed.
  272. @param handle The handle field of this struct.
  273. @param port_index The index of the port associated with the control.
  274. @param grabbed If true, the control has been grabbed, otherwise the
  275. control has been released.
  276. */
  277. void (*touch)(LV2UI_Feature_Handle handle,
  278. uint32_t port_index,
  279. bool grabbed);
  280. } LV2UI_Touch;
  281. /**
  282. A status code for LV2UI_Request_Value::request.
  283. */
  284. typedef enum {
  285. /**
  286. Completed successfully.
  287. The host will set the parameter later if the user choses a new value.
  288. */
  289. LV2UI_REQUEST_VALUE_SUCCESS,
  290. /**
  291. Parameter already being requested.
  292. The host is already requesting a parameter from the user (for example, a
  293. dialog is visible), or the UI is otherwise busy and can not make this
  294. request.
  295. */
  296. LV2UI_REQUEST_VALUE_BUSY,
  297. /**
  298. Unknown parameter.
  299. The host is not aware of this parameter, and is not able to set a new
  300. value for it.
  301. */
  302. LV2UI_REQUEST_VALUE_ERR_UNKNOWN,
  303. /**
  304. Unsupported parameter.
  305. The host knows about this parameter, but does not support requesting a
  306. new value for it from the user. This is likely because the host does
  307. not have UI support for choosing a value with the appropriate type.
  308. */
  309. LV2UI_REQUEST_VALUE_ERR_UNSUPPORTED
  310. } LV2UI_Request_Value_Status;
  311. /**
  312. A feature to request a new parameter value from the host.
  313. */
  314. typedef struct {
  315. /**
  316. Pointer to opaque data which must be passed to request().
  317. */
  318. LV2UI_Feature_Handle handle;
  319. /**
  320. Request a value for a parameter from the host.
  321. This is mainly used by UIs to request values for complex parameters that
  322. don't change often, such as file paths, but it may be used to request
  323. any parameter value.
  324. This function returns immediately, and the return value indicates
  325. whether the host can fulfill the request. The host may notify the
  326. plugin about the new parameter value, for example when a file is
  327. selected by the user, via the usual mechanism. Typically, the host will
  328. send a message to the plugin that sets the new parameter value, and the
  329. plugin will notify the UI via a message as usual for any other parameter
  330. change.
  331. To provide an appropriate UI, the host can determine details about the
  332. parameter from the plugin data as usual. The additional parameters of
  333. this function provide support for more advanced use cases, but in the
  334. simple common case, the plugin will simply pass the key of the desired
  335. parameter and zero for everything else.
  336. @param handle The handle field of this struct.
  337. @param key The URID of the parameter.
  338. @param type The optional type of the value to request. This can be used
  339. to request a specific value type for parameters that support several.
  340. If non-zero, it must be the URID of an instance of rdfs:Class or
  341. rdfs:Datatype.
  342. @param features Additional features for this request, or NULL.
  343. @return A status code which is 0 on success.
  344. */
  345. LV2UI_Request_Value_Status (*request)(LV2UI_Feature_Handle handle,
  346. LV2_URID key,
  347. LV2_URID type,
  348. const LV2_Feature* const* features);
  349. } LV2UI_Request_Value;
  350. /**
  351. UI Idle Interface (LV2_UI__idleInterface)
  352. UIs can provide this interface to have an idle() callback called by the host
  353. rapidly to update the UI.
  354. */
  355. typedef struct _LV2UI_Idle_Interface {
  356. /**
  357. Run a single iteration of the UI's idle loop.
  358. This will be called rapidly in the UI thread at a rate appropriate
  359. for a toolkit main loop. There are no precise timing guarantees, but
  360. the host should attempt to call idle() at a high enough rate for smooth
  361. animation, at least 30Hz.
  362. @return non-zero if the UI has been closed, in which case the host
  363. should stop calling idle(), and can either completely destroy the UI, or
  364. re-show it and resume calling idle().
  365. */
  366. int (*idle)(LV2UI_Handle ui);
  367. } LV2UI_Idle_Interface;
  368. /**
  369. UI Show Interface (LV2_UI__showInterface)
  370. UIs can provide this interface to show and hide a window, which allows them
  371. to function in hosts unable to embed their widget. This allows any UI to
  372. provide a fallback for embedding that works in any host.
  373. If used:
  374. - The host MUST use LV2UI_Idle_Interface to drive the UI.
  375. - The UI MUST return non-zero from LV2UI_Idle_Interface::idle() when it has been closed.
  376. - If idle() returns non-zero, the host MUST call hide() and stop calling
  377. idle(). It MAY later call show() then resume calling idle().
  378. */
  379. typedef struct _LV2UI_Show_Interface {
  380. /**
  381. Show a window for this UI.
  382. The window title MAY have been passed by the host to
  383. LV2UI_Descriptor::instantiate() as an LV2_Options_Option with key
  384. LV2_UI__windowTitle.
  385. @return 0 on success, or anything else to stop being called.
  386. */
  387. int (*show)(LV2UI_Handle ui);
  388. /**
  389. Hide the window for this UI.
  390. @return 0 on success, or anything else to stop being called.
  391. */
  392. int (*hide)(LV2UI_Handle ui);
  393. } LV2UI_Show_Interface;
  394. /**
  395. Peak data for a slice of time, the update format for ui:peakProtocol.
  396. */
  397. typedef struct _LV2UI_Peak_Data {
  398. /**
  399. The start of the measurement period. This is just a running counter
  400. that is only meaningful in comparison to previous values and must not be
  401. interpreted as an absolute time.
  402. */
  403. uint32_t period_start;
  404. /**
  405. The size of the measurement period, in the same units as period_start.
  406. */
  407. uint32_t period_size;
  408. /**
  409. The peak value for the measurement period. This should be the maximal
  410. value for abs(sample) over all the samples in the period.
  411. */
  412. float peak;
  413. } LV2UI_Peak_Data;
  414. /**
  415. Prototype for UI accessor function.
  416. This is the entry point to a UI library, which works in the same way as
  417. lv2_descriptor() but for UIs rather than plugins.
  418. */
  419. LV2_SYMBOL_EXPORT
  420. const LV2UI_Descriptor* lv2ui_descriptor(uint32_t index);
  421. /**
  422. The type of the lv2ui_descriptor() function.
  423. */
  424. typedef const LV2UI_Descriptor* (*LV2UI_DescriptorFunction)(uint32_t index);
  425. #ifdef __cplusplus
  426. }
  427. #endif
  428. #endif /* LV2_UI_H */
  429. /**
  430. @}
  431. */