Collection of tools useful for audio production
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.

470 lines
17KB

  1. /* -*- Mode: C ; c-basic-offset: 2 -*- */
  2. /*****************************************************************************
  3. *
  4. * This work is in public domain.
  5. *
  6. * This file is distributed in the hope that it will be useful,
  7. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. *
  10. * If you have questions, contact Nedko Arnaudov <nedko@arnaudov.name> or
  11. * ask in #lad channel, FreeNode IRC network.
  12. *
  13. *****************************************************************************/
  14. /**
  15. * @file lv2dynparam.h
  16. * @brief LV2 dynparam extension definition
  17. *
  18. * @par Purpose
  19. *
  20. * The purpose of this extension is to allow plugin parameters appear
  21. * and disappear as response of existing parameter changes (i.e. number
  22. * of voices) or executing commands (i.e. "add new voice"). It also
  23. * allows grouping of parameters and groups. Groups can be used for
  24. * things like ADSR abstraction, i.e. group of 4 float parameters.
  25. *
  26. * @par Architectural overview
  27. *
  28. * Plugin notifies host for changes through callbacks. During
  29. * initialization, plugin notifies host about initial groups,
  30. * parameters and commands through same callbacks used for later
  31. * notification. There are callbacks to notify host for group,
  32. * parameter and command disappears.
  33. *
  34. * Groups are containers of other groups, parameters and
  35. * commands. Parameters and groups have URIs. Parameter URIs are
  36. * used to describe type of parameter (i.e. boolean, integer,
  37. * string, etc.). Parameters are as simple as possible. There is one
  38. * predefined Group URI for "generic group" type, i.e. container
  39. * that is just that - a container of other groups, parameters and
  40. * commands. Other group types are just hints and ones that are
  41. * unknown to host, can be looked as generic ones. Only generic
  42. * groups can contain groups. Groups of other types can contain only
  43. * parameters. There is always one, root group. Name of the root
  44. * groop is expected to match name of the plugin.
  45. *
  46. * Groups, parameters and commands, have "name" containing short
  47. * human readble description of object purpose.
  48. *
  49. * Parameter ports, are bidirectional. Parameters have values, and
  50. * some of them (depending of type) - range. Data storage for
  51. * current, min and max values is in plugin memory. Host gets
  52. * pointers to that memory and accesses the data in type specific
  53. * way.
  54. *
  55. * When plugin decides to change parameter value or range (as
  56. * response to command execution or other parameter value change), it
  57. * notifies host through callback.
  58. *
  59. * When host decides to change parameter value or execute command (as
  60. * resoponse to user action, i.e. knob rotation/button press, or some
  61. * kind of automation), it calls plugin callback. In case of
  62. * parameter, it first changes the value in the plugin data storage
  63. * for particular parameter. Host ensures that values being set are
  64. * within current range (if range is defined for particular port
  65. * type).
  66. *
  67. * Apart from initialization (host_attach), plugin may call host
  68. * callbacks only as response to command execution or parameter
  69. * change notification (from host).
  70. *
  71. * Host serializes calls to plugin dynparam callbacks and the
  72. * run/connect_port lv2 callbacks. Thus plugin does not need to take
  73. * special measures for thread safety. in callbacks called by host.
  74. *
  75. * Plugin can assume that host will never call dynamic parameter
  76. * functions when lv2 plugin callbacks (like run and connect_port) are
  77. * being called. I.e. calls are serialized, no need for locks in
  78. * plugin. Plugin must not suspend execution (sleep/lock) while being
  79. * called by host. If it needs to sleep to implement action requested
  80. * by host, like allocation of data for new voice, the allocation
  81. * should be done in background thread and when ready, transfered to
  82. * the realtime code. During initialization (host_attach) plugin is
  83. * allowed to sleep. Thus conventional memory allocation is allowed
  84. * in host_attach.
  85. *
  86. * @par Intialization sequence
  87. *
  88. * -# Host discovers whether plugin supports the extension by
  89. * inspecting the RDF Turtle file.
  90. * -# Host calls lv2 extension_data callback, plugin returns pointer
  91. * to struct lv2dynparam_plugin_callbacks containing pointers to
  92. * several funtions, including host_attach.
  93. * -# For each instantiated plugin supporting this extension, host
  94. * calls host_attach function with parameters:
  95. * - a LV2_Handle, plugin instance handle
  96. * - pointer to struct lv2dynparam_host_callbacks, containing
  97. * pointers to several functions, to be called by plugin.
  98. * - instance host context, opaque pointer
  99. * -# During initialization (host_attach), initial groups and
  100. * parameters appear and host callbacks are called by plugin.
  101. *
  102. * @par Parameter types
  103. * - float, with range
  104. * - 32-bit 2's complement signed int, with range
  105. * - midi note, value stored as byte, with range
  106. * - string
  107. * - filename
  108. * - boolean, value stored as byte, non-zero means TRUE, zero means FALSE
  109. *
  110. * @par Notes:
  111. * - if function fails, variables where output parameters are normally
  112. * stored remain unmodified.
  113. * - If host callback, called by plugin, fails - plugin should try the
  114. * operation later.
  115. */
  116. #ifndef LV2DYNPARAM_H__31DEB371_3874_44A0_A9F2_AAFB0360D8C5__INCLUDED
  117. #define LV2DYNPARAM_H__31DEB371_3874_44A0_A9F2_AAFB0360D8C5__INCLUDED
  118. #ifdef __cplusplus
  119. extern "C" {
  120. #endif
  121. #if 0
  122. } /* Adjust editor indent */
  123. #endif
  124. /** base URI to be used for composing real URIs (internal use only) */
  125. #define LV2DYNPARAM_BASE_URI "http://home.gna.org/lv2dynparam/v1"
  126. /** URI of the LV2 extension defined in this file */
  127. #define LV2DYNPARAM_URI LV2DYNPARAM_BASE_URI
  128. /** max size of name and type_uri buffers, including terminating zero char */
  129. #define LV2DYNPARAM_MAX_STRING_SIZE 1024
  130. /** handle identifying parameter, supplied by plugin */
  131. typedef void * lv2dynparam_parameter_handle;
  132. /** handle identifying group, supplied by plugin */
  133. typedef void * lv2dynparam_group_handle;
  134. /** handle identifying command, supplied by plugin */
  135. typedef void * lv2dynparam_command_handle;
  136. /**
  137. * Structure containing set of hints.
  138. */
  139. struct lv2dynparam_hints
  140. {
  141. unsigned char count; /**< Number of hints in the set. Size of @c names and @c values arrays. */
  142. char ** names; /**< Hint names. Array of hint names with size @c count. */
  143. char ** values; /**< Hint values. Array of hint values with size @c count. Element can be NULL if hint has no value. */
  144. };
  145. /**
  146. * Structure containing poitners to functions called by
  147. * plugin and implemented by host.
  148. */
  149. struct lv2dynparam_host_callbacks
  150. {
  151. /**
  152. * This function is called by plugin to notify host about new
  153. * group.
  154. *
  155. * @param instance_host_context Host instance context, as supplied
  156. * during initialization (host_attach).
  157. * @param parent_group_host_context Host context of parent
  158. * group. For the root group, parent context is NULL.
  159. * @param group Plugin context for the group
  160. * @param hints_ptr Pointer to structure representing hints set
  161. * associated with appearing group.
  162. * @param group_host_context Pointer to variable where host context
  163. * for the new group will be stored.
  164. *
  165. * @return Success status
  166. * @retval Non-zero - success
  167. * @retval Zero - error, try later
  168. */
  169. unsigned char (*group_appear)(
  170. void * instance_host_context,
  171. void * parent_group_host_context,
  172. lv2dynparam_group_handle group,
  173. const struct lv2dynparam_hints * hints_ptr,
  174. void ** group_host_context);
  175. /**
  176. * This function is called by plugin to notify host about group
  177. * removal.
  178. *
  179. * @param instance_host_context Host instance context, as supplied
  180. * during initialization (host_attach).
  181. * @param group_host_context Host context of the group
  182. *
  183. * @return Success status
  184. * @retval Non-zero - success
  185. * @retval Zero - error, try later
  186. */
  187. unsigned char (*group_disappear)(
  188. void * instance_host_context,
  189. void * group_host_context);
  190. /**
  191. * This function is called by plugin to notify host about new
  192. * parameter.
  193. *
  194. * @param instance_host_context Host instance context, as supplied
  195. * during initialization (host_attach).
  196. * @param group_host_context Host context of parent group.
  197. * @param parameter Plugin context for the parameter
  198. * @param hints_ptr Pointer to structure representing hints set
  199. * associated with appearing parameter.
  200. * @param parameter_host_context Pointer to variable where host
  201. * context for the new parameter will be stored.
  202. *
  203. * @return Success status
  204. * @retval Non-zero - success
  205. * @retval Zero - error, try later
  206. */
  207. unsigned char (*parameter_appear)(
  208. void * instance_host_context,
  209. void * group_host_context,
  210. lv2dynparam_parameter_handle parameter,
  211. const struct lv2dynparam_hints * hints_ptr,
  212. void ** parameter_host_context);
  213. /**
  214. * This function is called by plugin to notify host about parameter
  215. * removal.
  216. *
  217. * @param instance_host_context Host instance context, as supplied
  218. * during initialization (host_attach).
  219. * @param parameter_host_context Host context of the parameter
  220. *
  221. * @return Success status
  222. * @retval Non-zero - success
  223. * @retval Zero - error, try later
  224. */
  225. unsigned char (*parameter_disappear)(
  226. void * instance_host_context,
  227. void * parameter_host_context);
  228. /**
  229. * This function is called by plugin to notify host about parameter
  230. * value or range change.
  231. *
  232. * @param instance_host_context Host instance context, as supplied
  233. * during initialization (host_attach).
  234. * @param parameter_host_context Host context of the parameter
  235. *
  236. * @return Success status
  237. * @retval Non-zero - success
  238. * @retval Zero - error, try later
  239. */
  240. unsigned char (*parameter_change)(
  241. void * instance_host_context,
  242. void * parameter_host_context);
  243. /**
  244. * This function is called by plugin to notify host about new commmand.
  245. *
  246. * @param instance_host_context Host instance context, as supplied
  247. * during initialization (host_attach).
  248. * @param group_host_context Host context of parent group.
  249. * @param command Plugin context for the command
  250. * @param hints_ptr Pointer to structure representing hints set
  251. * associated with appearing command.
  252. * @param command_host_context Pointer to variable where host
  253. * context for the new command will be stored.
  254. *
  255. * @return Success status
  256. * @retval Non-zero - success
  257. * @retval Zero - error, try later
  258. */
  259. unsigned char (*command_appear)(
  260. void * instance_host_context,
  261. void * group_host_context,
  262. lv2dynparam_command_handle command,
  263. const struct lv2dynparam_hints * hints_ptr,
  264. void ** command_host_context);
  265. /**
  266. * This function is called by plugin to notify host about command
  267. * removal.
  268. *
  269. * @param instance_host_context Host instance context, as supplied
  270. * during initialization (host_attach).
  271. * @param command_host_context Host context of the command
  272. *
  273. * @return Success status
  274. * @retval Non-zero - success
  275. * @retval Zero - error, try later
  276. */
  277. unsigned char (*command_disappear)(
  278. void * instance_host_context,
  279. void * command_host_context);
  280. };
  281. /**
  282. * Structure containing poitners to functions called by
  283. * host and implemented by plugin.
  284. * Pointer to this struct is returned by LV2 extension_data plugin callback
  285. */
  286. struct lv2dynparam_plugin_callbacks
  287. {
  288. /**
  289. * This callback is called by host during initialization.
  290. * Plugin is allowed to suspend execution (sleep/lock).
  291. * Thus conventional memory allocation is allowed.
  292. *
  293. * @param instance Handle of instantiated LV2 plugin
  294. * @param host_callbacks Pointer to struncture containing pointer to
  295. * functions implemented by host, to be called by plugin.
  296. * @param instance_host_context Context to be supplied as parameter
  297. * to callbacks implemented by host and called by plugin.
  298. *
  299. * @return Success status
  300. * @retval Non-zero - success
  301. * @retval Zero - error
  302. */
  303. unsigned char (*host_attach)(
  304. LV2_Handle instance,
  305. struct lv2dynparam_host_callbacks * host_callbacks,
  306. void * instance_host_context);
  307. /**
  308. * This function is called by host to retrieve name of group
  309. * Plugin implementation must not suspend execution (sleep/lock).
  310. *
  311. * @param group Group handle, as supplied by plugin
  312. * @param buffer Pointer to buffer with size of
  313. * LV2DYNPARAM_MAX_STRING_SIZE bytes, where ASCIIZ string containing
  314. * name of the group will be stored.
  315. */
  316. void (*group_get_name)(
  317. lv2dynparam_group_handle group,
  318. char * buffer);
  319. /**
  320. * This function is called by host to retrieve type URI of parameter
  321. * Plugin implementation must not suspend execution (sleep/lock).
  322. *
  323. * @param parameter Parameter handle, as supplied by plugin
  324. * @param buffer Pointer to buffer with size of
  325. * LV2DYNPARAM_MAX_STRING_SIZE bytes, where ASCIIZ string containing
  326. * type URI of the parameter will be stored.
  327. */
  328. void (*parameter_get_type_uri)(
  329. lv2dynparam_parameter_handle parameter,
  330. char * buffer);
  331. /**
  332. * This function is called by host to retrieve name of parameter
  333. * Plugin implementation must not suspend execution (sleep/lock).
  334. *
  335. * @param parameter Parameter handle, as supplied by plugin
  336. * @param buffer Pointer to buffer with size of
  337. * LV2DYNPARAM_MAX_STRING_SIZE bytes, where ASCIIZ string containing
  338. * name of the parameter will be stored.
  339. */
  340. void (*parameter_get_name)(
  341. lv2dynparam_parameter_handle parameter,
  342. char * buffer);
  343. /**
  344. * This funtion is called by host to retrieve pointer to memory
  345. * where value data for particular parameter is stored.
  346. * Plugin implementation must not suspend execution (sleep/lock).
  347. *
  348. * @param parameter Parameter handle, as supplied by plugin
  349. * @param value_buffer Pointer to variable where pointer to value
  350. * data will be stored.
  351. */
  352. void (*parameter_get_value)(
  353. lv2dynparam_parameter_handle parameter,
  354. void ** value_buffer);
  355. /**
  356. * This funtion is called by host to retrieve pointer to memory
  357. * where range min and max values data for particular parameter are
  358. * stored. Host calls this function only for parameter with types
  359. * that have range.
  360. * Plugin implementation must not suspend execution (sleep/lock).
  361. *
  362. * @param parameter Parameter handle, as supplied by plugin
  363. * @param value_min_buffer Pointer to variable where pointer to min
  364. * value data will be stored.
  365. * @param value_max_buffer Pointer to variable where pointer to max
  366. * value data will be stored.
  367. */
  368. void (*parameter_get_range)(
  369. lv2dynparam_parameter_handle parameter,
  370. void ** value_min_buffer,
  371. void ** value_max_buffer);
  372. /**
  373. * This function is called by host to notify plugin about value
  374. * change. For parameters with types that have range, value is
  375. * guaranteed to be with the range. Before calling this function,
  376. * host updates value data storage with the new value.
  377. * Plugin implementation must not suspend execution (sleep/lock).
  378. *
  379. * @param parameter Parameter handle, as supplied by plugin
  380. *
  381. * @return Success status
  382. * @retval Non-zero - success
  383. * @retval Zero - error, try later
  384. */
  385. unsigned char (*parameter_change)(
  386. lv2dynparam_parameter_handle parameter);
  387. /**
  388. * This function is called by host to retrieve name of command
  389. * Plugin implementation must not suspend execution (sleep/lock).
  390. *
  391. * @param command Command handle, as supplied by plugin
  392. * @param buffer Pointer to buffer with size of
  393. * LV2DYNPARAM_MAX_STRING_SIZE bytes, where ASCIIZ string containing
  394. * name of the command will be stored.
  395. */
  396. void (*command_get_name)(
  397. lv2dynparam_command_handle command,
  398. char * buffer);
  399. /**
  400. * This function is called by host to execute command defined by
  401. * plugin.
  402. * Plugin implementation must not suspend execution (sleep/lock).
  403. *
  404. * @param command Command handle, as supplied by plugin
  405. *
  406. * @return Success status
  407. * @retval Non-zero - success
  408. * @retval Zero - error, try later
  409. */
  410. unsigned char (*command_execute)(
  411. lv2dynparam_command_handle command);
  412. };
  413. /** URI for float parameter */
  414. #define LV2DYNPARAM_PARAMETER_TYPE_FLOAT_URI LV2DYNPARAM_BASE_URI "#parameter_float"
  415. /** URI for integer parameter */
  416. #define LV2DYNPARAM_PARAMETER_TYPE_INT_URI LV2DYNPARAM_BASE_URI "#parameter_int"
  417. /** URI for note parameter */
  418. #define LV2DYNPARAM_PARAMETER_TYPE_NOTE_URI LV2DYNPARAM_BASE_URI "#parameter_note"
  419. /** URI for string parameter */
  420. #define LV2DYNPARAM_PARAMETER_TYPE_STRING_URI LV2DYNPARAM_BASE_URI "#parameter_string"
  421. /** URI for filename parameter */
  422. #define LV2DYNPARAM_PARAMETER_TYPE_FILENAME_URI LV2DYNPARAM_BASE_URI "#parameter_filename"
  423. /** URI for boolean parameter */
  424. #define LV2DYNPARAM_PARAMETER_TYPE_BOOLEAN_URI LV2DYNPARAM_BASE_URI "#parameter_boolean"
  425. /** URI for enumeration parameter */
  426. #define LV2DYNPARAM_PARAMETER_TYPE_ENUM_URI LV2DYNPARAM_BASE_URI "#parameter_enum"
  427. #if 0
  428. { /* Adjust editor indent */
  429. #endif
  430. #ifdef __cplusplus
  431. } /* extern "C" */
  432. #endif
  433. #endif /* #ifndef LV2DYNPARAM_H__31DEB371_3874_44A0_A9F2_AAFB0360D8C5__INCLUDED */