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.

444 lines
19KB

  1. /* -*- c-basic-offset: 4 -*- */
  2. /* dssi.h
  3. DSSI version 1.0
  4. Copyright (c) 2004, 2009 Chris Cannam, Steve Harris and Sean Bolton
  5. This library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public License
  7. as published by the Free Software Foundation; either version 2.1 of
  8. the License, or (at your option) any later version.
  9. This library is distributed in the hope that it will be useful, but
  10. WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with this library; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  16. MA 02110-1301 USA
  17. */
  18. #ifndef DSSI_INCLUDED
  19. #define DSSI_INCLUDED
  20. #include "../ladspa/ladspa.h"
  21. #include "seq_event-compat.h"
  22. #define DSSI_VERSION "1.0"
  23. #define DSSI_VERSION_MAJOR 1
  24. #define DSSI_VERSION_MINOR 0
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. /*
  29. There is a need for an API that supports hosted MIDI soft synths
  30. with GUIs in Linux audio applications. In time the GMPI initiative
  31. should comprehensively address this need, but the requirement for
  32. Linux applications to be able to support simple hosted synths is
  33. here now, and GMPI is not. This proposal (the "DSSI Soft Synth
  34. Interface" or DSSI, pronounced "dizzy") aims to provide a simple
  35. solution in a way that we hope will prove complete and compelling
  36. enough to support now, yet not so compelling as to supplant GMPI or
  37. any other comprehensive future proposal.
  38. For simplicity and familiarity, this API is based as far as
  39. possible on existing work -- the LADSPA plugin API for control
  40. values and audio processing, and the ALSA sequencer event types for
  41. MIDI event communication. The GUI part of the proposal is quite
  42. new, but may also be applicable retroactively to LADSPA plugins
  43. that do not otherwise support this synth interface.
  44. */
  45. typedef struct _DSSI_Program_Descriptor {
  46. /** Bank number for this program. Note that DSSI does not support
  47. MIDI-style separation of bank LSB and MSB values. There is no
  48. restriction on the set of available banks: the numbers do not
  49. need to be contiguous, there does not need to be a bank 0, etc. */
  50. unsigned long Bank;
  51. /** Program number (unique within its bank) for this program.
  52. There is no restriction on the set of available programs: the
  53. numbers do not need to be contiguous, there does not need to
  54. be a program 0, etc. */
  55. unsigned long Program;
  56. /** Name of the program. */
  57. const char * Name;
  58. } DSSI_Program_Descriptor;
  59. typedef struct _DSSI_Descriptor {
  60. /**
  61. * DSSI_API_Version
  62. *
  63. * This member indicates the DSSI API level used by this plugin.
  64. * If we're lucky, this will never be needed. For now all plugins
  65. * must set it to 1.
  66. */
  67. int DSSI_API_Version;
  68. /**
  69. * LADSPA_Plugin
  70. *
  71. * A DSSI synth plugin consists of a LADSPA plugin plus an
  72. * additional framework for controlling program settings and
  73. * transmitting MIDI events. A plugin must fully implement the
  74. * LADSPA descriptor fields as well as the required LADSPA
  75. * functions including instantiate() and (de)activate(). It
  76. * should also implement run(), with the same behaviour as if
  77. * run_synth() (below) were called with no synth events.
  78. *
  79. * In order to instantiate a synth the host calls the LADSPA
  80. * instantiate function, passing in this LADSPA_Descriptor
  81. * pointer. The returned LADSPA_Handle is used as the argument
  82. * for the DSSI functions below as well as for the LADSPA ones.
  83. */
  84. const LADSPA_Descriptor *LADSPA_Plugin;
  85. /**
  86. * configure()
  87. *
  88. * This member is a function pointer that sends a piece of
  89. * configuration data to the plugin. The key argument specifies
  90. * some aspect of the synth's configuration that is to be changed,
  91. * and the value argument specifies a new value for it. A plugin
  92. * that does not require this facility at all may set this member
  93. * to NULL.
  94. *
  95. * This call is intended to set some session-scoped aspect of a
  96. * plugin's behaviour, for example to tell the plugin to load
  97. * sample data from a particular file. The plugin should act
  98. * immediately on the request. The call should return NULL on
  99. * success, or an error string that may be shown to the user. The
  100. * host will free the returned value after use if it is non-NULL.
  101. *
  102. * Calls to configure() are not automated as timed events.
  103. * Instead, a host should remember the last value associated with
  104. * each key passed to configure() during a given session for a
  105. * given plugin instance, and should call configure() with the
  106. * correct value for each key the next time it instantiates the
  107. * "same" plugin instance, for example on reloading a project in
  108. * which the plugin was used before. Plugins should note that a
  109. * host may typically instantiate a plugin multiple times with the
  110. * same configuration values, and should share data between
  111. * instances where practical.
  112. *
  113. * Calling configure() completely invalidates the program and bank
  114. * information last obtained from the plugin.
  115. *
  116. * Reserved and special key prefixes
  117. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  118. * The DSSI: prefix
  119. * ----------------
  120. * Configure keys starting with DSSI: are reserved for particular
  121. * purposes documented in the DSSI specification. At the moment,
  122. * there is one such key: DSSI:PROJECT_DIRECTORY. A host may call
  123. * configure() passing this key and a directory path value. This
  124. * indicates to the plugin and its UI that a directory at that
  125. * path exists and may be used for project-local data. Plugins
  126. * may wish to use the project directory as a fallback location
  127. * when looking for other file data, or as a base for relative
  128. * paths in other configuration values.
  129. *
  130. * The GLOBAL: prefix
  131. * ------------------
  132. * Configure keys starting with GLOBAL: may be used by the plugin
  133. * and its UI for any purpose, but are treated specially by the
  134. * host. When one of these keys is used in a configure OSC call
  135. * from the plugin UI, the host makes the corresponding configure
  136. * call (preserving the GLOBAL: prefix) not only to the target
  137. * plugin but also to all other plugins in the same instance
  138. * group, as well as their UIs. Note that if any instance
  139. * returns non-NULL from configure to indicate error, the host
  140. * may stop there (and the set of plugins on which configure has
  141. * been called will thus depend on the host implementation).
  142. * See also the configure OSC call documentation in RFC.txt.
  143. */
  144. char *(*configure)(LADSPA_Handle Instance,
  145. const char *Key,
  146. const char *Value);
  147. #define DSSI_RESERVED_CONFIGURE_PREFIX "DSSI:"
  148. #define DSSI_GLOBAL_CONFIGURE_PREFIX "GLOBAL:"
  149. #define DSSI_PROJECT_DIRECTORY_KEY \
  150. DSSI_RESERVED_CONFIGURE_PREFIX "PROJECT_DIRECTORY"
  151. #define DSSI_CUSTOMDATA_EXTENSION_KEY \
  152. DSSI_RESERVED_CONFIGURE_PREFIX "SUPPORTS_CUSTOMDATA"
  153. /**
  154. * get_program()
  155. *
  156. * This member is a function pointer that provides a description
  157. * of a program (named preset sound) available on this synth. A
  158. * plugin that does not support programs at all should set this
  159. * member to NULL.
  160. *
  161. * The Index argument is an index into the plugin's list of
  162. * programs, not a program number as represented by the Program
  163. * field of the DSSI_Program_Descriptor. (This distinction is
  164. * needed to support synths that use non-contiguous program or
  165. * bank numbers.)
  166. *
  167. * This function returns a DSSI_Program_Descriptor pointer that is
  168. * guaranteed to be valid only until the next call to get_program,
  169. * deactivate, or configure, on the same plugin instance. This
  170. * function must return NULL if passed an Index argument out of
  171. * range, so that the host can use it to query the number of
  172. * programs as well as their properties.
  173. */
  174. const DSSI_Program_Descriptor *(*get_program)(LADSPA_Handle Instance,
  175. unsigned long Index);
  176. /**
  177. * select_program()
  178. *
  179. * This member is a function pointer that selects a new program
  180. * for this synth. The program change should take effect
  181. * immediately at the start of the next run_synth() call. (This
  182. * means that a host providing the capability of changing programs
  183. * between any two notes on a track must vary the block size so as
  184. * to place the program change at the right place. A host that
  185. * wanted to avoid this would probably just instantiate a plugin
  186. * for each program.)
  187. *
  188. * A plugin that does not support programs at all should set this
  189. * member NULL. Plugins should ignore a select_program() call
  190. * with an invalid bank or program.
  191. *
  192. * A plugin is not required to select any particular default
  193. * program on activate(): it's the host's duty to set a program
  194. * explicitly. The current program is invalidated by any call to
  195. * configure().
  196. *
  197. * A plugin is permitted to re-write the values of its input
  198. * control ports when select_program is called. The host should
  199. * re-read the input control port values and update its own
  200. * records appropriately. (This is the only circumstance in
  201. * which a DSSI plugin is allowed to modify its own input ports.)
  202. */
  203. void (*select_program)(LADSPA_Handle Instance,
  204. unsigned long Bank,
  205. unsigned long Program);
  206. /**
  207. * get_midi_controller_for_port()
  208. *
  209. * This member is a function pointer that returns the MIDI
  210. * controller number or NRPN that should be mapped to the given
  211. * input control port. If the given port should not have any MIDI
  212. * controller mapped to it, the function should return DSSI_NONE.
  213. * The behaviour of this function is undefined if the given port
  214. * number does not correspond to an input control port. A plugin
  215. * that does not want MIDI controllers mapped to ports at all may
  216. * set this member NULL.
  217. *
  218. * Correct values can be got using the macros DSSI_CC(num) and
  219. * DSSI_NRPN(num) as appropriate, and values can be combined using
  220. * bitwise OR: e.g. DSSI_CC(23) | DSSI_NRPN(1069) means the port
  221. * should respond to CC #23 and NRPN #1069.
  222. *
  223. * The host is responsible for doing proper scaling from MIDI
  224. * controller and NRPN value ranges to port ranges according to
  225. * the plugin's LADSPA port hints. Hosts should not deliver
  226. * through run_synth any MIDI controller events that have already
  227. * been mapped to control port values.
  228. *
  229. * A plugin should not attempt to request mappings from
  230. * controllers 0 or 32 (MIDI Bank Select MSB and LSB).
  231. */
  232. int (*get_midi_controller_for_port)(LADSPA_Handle Instance,
  233. unsigned long Port);
  234. /**
  235. * run_synth()
  236. *
  237. * This member is a function pointer that runs a synth for a
  238. * block. This is identical in function to the LADSPA run()
  239. * function, except that it also supplies events to the synth.
  240. *
  241. * A plugin may provide this function, run_multiple_synths() (see
  242. * below), both, or neither (if it is not in fact a synth). A
  243. * plugin that does not provide this function must set this member
  244. * to NULL. Authors of synth plugins are encouraged to provide
  245. * this function if at all possible.
  246. *
  247. * The Events pointer points to a block of EventCount ALSA
  248. * sequencer events, which is used to communicate MIDI and related
  249. * events to the synth. Each event is timestamped relative to the
  250. * start of the block, (mis)using the ALSA "tick time" field as a
  251. * frame count. The host is responsible for ensuring that events
  252. * with differing timestamps are already ordered by time.
  253. *
  254. * See also the notes on activation, port connection etc in
  255. * ladpsa.h, in the context of the LADSPA run() function.
  256. *
  257. * Note Events
  258. * ~~~~~~~~~~~
  259. * There are two minor requirements aimed at making the plugin
  260. * writer's life as simple as possible:
  261. *
  262. * 1. A host must never send events of type SND_SEQ_EVENT_NOTE.
  263. * Notes should always be sent as separate SND_SEQ_EVENT_NOTE_ON
  264. * and NOTE_OFF events. A plugin should discard any one-point
  265. * NOTE events it sees.
  266. *
  267. * 2. A host must not attempt to switch notes off by sending
  268. * zero-velocity NOTE_ON events. It should always send true
  269. * NOTE_OFFs. It is the host's responsibility to remap events in
  270. * cases where an external MIDI source has sent it zero-velocity
  271. * NOTE_ONs.
  272. *
  273. * Bank and Program Events
  274. * ~~~~~~~~~~~~~~~~~~~~~~~
  275. * Hosts must map MIDI Bank Select MSB and LSB (0 and 32)
  276. * controllers and MIDI Program Change events onto the banks and
  277. * programs specified by the plugin, using the DSSI select_program
  278. * call. No host should ever deliver a program change or bank
  279. * select controller to a plugin via run_synth.
  280. */
  281. void (*run_synth)(LADSPA_Handle Instance,
  282. unsigned long SampleCount,
  283. snd_seq_event_t *Events,
  284. unsigned long EventCount);
  285. /**
  286. * run_synth_adding()
  287. *
  288. * This member is a function pointer that runs an instance of a
  289. * synth for a block, adding its outputs to the values already
  290. * present at the output ports. This is provided for symmetry
  291. * with LADSPA run_adding(), and is equally optional. A plugin
  292. * that does not provide it must set this member to NULL.
  293. */
  294. void (*run_synth_adding)(LADSPA_Handle Instance,
  295. unsigned long SampleCount,
  296. snd_seq_event_t *Events,
  297. unsigned long EventCount);
  298. /**
  299. * run_multiple_synths()
  300. *
  301. * This member is a function pointer that runs multiple synth
  302. * instances for a block. This is very similar to run_synth(),
  303. * except that Instances, Events, and EventCounts each point to
  304. * arrays that hold the LADSPA handles, event buffers, and
  305. * event counts for each of InstanceCount instances. That is,
  306. * Instances points to an array of InstanceCount pointers to
  307. * DSSI plugin instantiations, Events points to an array of
  308. * pointers to each instantiation's respective event list, and
  309. * EventCounts points to an array containing each instantiation's
  310. * respective event count.
  311. *
  312. * A host using this function must guarantee that ALL active
  313. * instances of the plugin are represented in each call to the
  314. * function -- that is, a host may not call run_multiple_synths()
  315. * for some instances of a given plugin and then call run_synth()
  316. * as well for others. 'All .. instances of the plugin' means
  317. * every instance sharing the same LADSPA label and shared object
  318. * (*.so) file (rather than every instance sharing the same *.so).
  319. * 'Active' means any instance for which activate() has been called
  320. * but deactivate() has not.
  321. *
  322. * A plugin may provide this function, run_synths() (see above),
  323. * both, or neither (if it not in fact a synth). A plugin that
  324. * does not provide this function must set this member to NULL.
  325. * Plugin authors implementing run_multiple_synths are strongly
  326. * encouraged to implement run_synth as well if at all possible,
  327. * to aid simplistic hosts, even where it would be less efficient
  328. * to use it.
  329. */
  330. void (*run_multiple_synths)(unsigned long InstanceCount,
  331. LADSPA_Handle *Instances,
  332. unsigned long SampleCount,
  333. snd_seq_event_t **Events,
  334. unsigned long *EventCounts);
  335. /**
  336. * run_multiple_synths_adding()
  337. *
  338. * This member is a function pointer that runs multiple synth
  339. * instances for a block, adding each synth's outputs to the
  340. * values already present at the output ports. This is provided
  341. * for symmetry with both the DSSI run_multiple_synths() and LADSPA
  342. * run_adding() functions, and is equally optional. A plugin
  343. * that does not provide it must set this member to NULL.
  344. */
  345. void (*run_multiple_synths_adding)(unsigned long InstanceCount,
  346. LADSPA_Handle *Instances,
  347. unsigned long SampleCount,
  348. snd_seq_event_t **Events,
  349. unsigned long *EventCounts);
  350. /**
  351. * set_custom_data()
  352. */
  353. int (*set_custom_data)(LADSPA_Handle Instance,
  354. void *Data,
  355. unsigned long DataLength);
  356. /**
  357. * get_custom_data()
  358. */
  359. int (*get_custom_data)(LADSPA_Handle Instance,
  360. void **Data,
  361. unsigned long *DataLength);
  362. } DSSI_Descriptor;
  363. /**
  364. * DSSI supports a plugin discovery method similar to that of LADSPA:
  365. *
  366. * - DSSI hosts may wish to locate DSSI plugin shared object files by
  367. * searching the paths contained in the DSSI_PATH and LADSPA_PATH
  368. * environment variables, if they are present. Both are expected
  369. * to be colon-separated lists of directories to be searched (in
  370. * order), and DSSI_PATH should be searched first if both variables
  371. * are set.
  372. *
  373. * - Each shared object file containing DSSI plugins must include a
  374. * function dssi_descriptor(), with the following function prototype
  375. * and C-style linkage. Hosts may enumerate the plugin types
  376. * available in the shared object file by repeatedly calling
  377. * this function with successive Index values (beginning from 0),
  378. * until a return value of NULL indicates no more plugin types are
  379. * available. Each non-NULL return is the DSSI_Descriptor
  380. * of a distinct plugin type.
  381. */
  382. const DSSI_Descriptor *dssi_descriptor(unsigned long Index);
  383. typedef const DSSI_Descriptor *(*DSSI_Descriptor_Function)(unsigned long Index);
  384. /*
  385. * Macros to specify particular MIDI controllers in return values from
  386. * get_midi_controller_for_port()
  387. */
  388. #define DSSI_CC_BITS 0x20000000
  389. #define DSSI_NRPN_BITS 0x40000000
  390. #define DSSI_NONE -1
  391. #define DSSI_CONTROLLER_IS_SET(n) (DSSI_NONE != (n))
  392. #define DSSI_CC(n) (DSSI_CC_BITS | (n))
  393. #define DSSI_IS_CC(n) (DSSI_CC_BITS & (n))
  394. #define DSSI_CC_NUMBER(n) ((n) & 0x7f)
  395. #define DSSI_NRPN(n) (DSSI_NRPN_BITS | ((n) << 7))
  396. #define DSSI_IS_NRPN(n) (DSSI_NRPN_BITS & (n))
  397. #define DSSI_NRPN_NUMBER(n) (((n) >> 7) & 0x3fff)
  398. #ifdef __cplusplus
  399. }
  400. #endif
  401. #endif /* DSSI_INCLUDED */