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.

dssi.h 19KB

12 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  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. /**
  152. * get_program()
  153. *
  154. * This member is a function pointer that provides a description
  155. * of a program (named preset sound) available on this synth. A
  156. * plugin that does not support programs at all should set this
  157. * member to NULL.
  158. *
  159. * The Index argument is an index into the plugin's list of
  160. * programs, not a program number as represented by the Program
  161. * field of the DSSI_Program_Descriptor. (This distinction is
  162. * needed to support synths that use non-contiguous program or
  163. * bank numbers.)
  164. *
  165. * This function returns a DSSI_Program_Descriptor pointer that is
  166. * guaranteed to be valid only until the next call to get_program,
  167. * deactivate, or configure, on the same plugin instance. This
  168. * function must return NULL if passed an Index argument out of
  169. * range, so that the host can use it to query the number of
  170. * programs as well as their properties.
  171. */
  172. const DSSI_Program_Descriptor *(*get_program)(LADSPA_Handle Instance,
  173. unsigned long Index);
  174. /**
  175. * select_program()
  176. *
  177. * This member is a function pointer that selects a new program
  178. * for this synth. The program change should take effect
  179. * immediately at the start of the next run_synth() call. (This
  180. * means that a host providing the capability of changing programs
  181. * between any two notes on a track must vary the block size so as
  182. * to place the program change at the right place. A host that
  183. * wanted to avoid this would probably just instantiate a plugin
  184. * for each program.)
  185. *
  186. * A plugin that does not support programs at all should set this
  187. * member NULL. Plugins should ignore a select_program() call
  188. * with an invalid bank or program.
  189. *
  190. * A plugin is not required to select any particular default
  191. * program on activate(): it's the host's duty to set a program
  192. * explicitly. The current program is invalidated by any call to
  193. * configure().
  194. *
  195. * A plugin is permitted to re-write the values of its input
  196. * control ports when select_program is called. The host should
  197. * re-read the input control port values and update its own
  198. * records appropriately. (This is the only circumstance in
  199. * which a DSSI plugin is allowed to modify its own input ports.)
  200. */
  201. void (*select_program)(LADSPA_Handle Instance,
  202. unsigned long Bank,
  203. unsigned long Program);
  204. /**
  205. * get_midi_controller_for_port()
  206. *
  207. * This member is a function pointer that returns the MIDI
  208. * controller number or NRPN that should be mapped to the given
  209. * input control port. If the given port should not have any MIDI
  210. * controller mapped to it, the function should return DSSI_NONE.
  211. * The behaviour of this function is undefined if the given port
  212. * number does not correspond to an input control port. A plugin
  213. * that does not want MIDI controllers mapped to ports at all may
  214. * set this member NULL.
  215. *
  216. * Correct values can be got using the macros DSSI_CC(num) and
  217. * DSSI_NRPN(num) as appropriate, and values can be combined using
  218. * bitwise OR: e.g. DSSI_CC(23) | DSSI_NRPN(1069) means the port
  219. * should respond to CC #23 and NRPN #1069.
  220. *
  221. * The host is responsible for doing proper scaling from MIDI
  222. * controller and NRPN value ranges to port ranges according to
  223. * the plugin's LADSPA port hints. Hosts should not deliver
  224. * through run_synth any MIDI controller events that have already
  225. * been mapped to control port values.
  226. *
  227. * A plugin should not attempt to request mappings from
  228. * controllers 0 or 32 (MIDI Bank Select MSB and LSB).
  229. */
  230. int (*get_midi_controller_for_port)(LADSPA_Handle Instance,
  231. unsigned long Port);
  232. /**
  233. * run_synth()
  234. *
  235. * This member is a function pointer that runs a synth for a
  236. * block. This is identical in function to the LADSPA run()
  237. * function, except that it also supplies events to the synth.
  238. *
  239. * A plugin may provide this function, run_multiple_synths() (see
  240. * below), both, or neither (if it is not in fact a synth). A
  241. * plugin that does not provide this function must set this member
  242. * to NULL. Authors of synth plugins are encouraged to provide
  243. * this function if at all possible.
  244. *
  245. * The Events pointer points to a block of EventCount ALSA
  246. * sequencer events, which is used to communicate MIDI and related
  247. * events to the synth. Each event is timestamped relative to the
  248. * start of the block, (mis)using the ALSA "tick time" field as a
  249. * frame count. The host is responsible for ensuring that events
  250. * with differing timestamps are already ordered by time.
  251. *
  252. * See also the notes on activation, port connection etc in
  253. * ladpsa.h, in the context of the LADSPA run() function.
  254. *
  255. * Note Events
  256. * ~~~~~~~~~~~
  257. * There are two minor requirements aimed at making the plugin
  258. * writer's life as simple as possible:
  259. *
  260. * 1. A host must never send events of type SND_SEQ_EVENT_NOTE.
  261. * Notes should always be sent as separate SND_SEQ_EVENT_NOTE_ON
  262. * and NOTE_OFF events. A plugin should discard any one-point
  263. * NOTE events it sees.
  264. *
  265. * 2. A host must not attempt to switch notes off by sending
  266. * zero-velocity NOTE_ON events. It should always send true
  267. * NOTE_OFFs. It is the host's responsibility to remap events in
  268. * cases where an external MIDI source has sent it zero-velocity
  269. * NOTE_ONs.
  270. *
  271. * Bank and Program Events
  272. * ~~~~~~~~~~~~~~~~~~~~~~~
  273. * Hosts must map MIDI Bank Select MSB and LSB (0 and 32)
  274. * controllers and MIDI Program Change events onto the banks and
  275. * programs specified by the plugin, using the DSSI select_program
  276. * call. No host should ever deliver a program change or bank
  277. * select controller to a plugin via run_synth.
  278. */
  279. void (*run_synth)(LADSPA_Handle Instance,
  280. unsigned long SampleCount,
  281. snd_seq_event_t *Events,
  282. unsigned long EventCount);
  283. /**
  284. * run_synth_adding()
  285. *
  286. * This member is a function pointer that runs an instance of a
  287. * synth for a block, adding its outputs to the values already
  288. * present at the output ports. This is provided for symmetry
  289. * with LADSPA run_adding(), and is equally optional. A plugin
  290. * that does not provide it must set this member to NULL.
  291. */
  292. void (*run_synth_adding)(LADSPA_Handle Instance,
  293. unsigned long SampleCount,
  294. snd_seq_event_t *Events,
  295. unsigned long EventCount);
  296. /**
  297. * run_multiple_synths()
  298. *
  299. * This member is a function pointer that runs multiple synth
  300. * instances for a block. This is very similar to run_synth(),
  301. * except that Instances, Events, and EventCounts each point to
  302. * arrays that hold the LADSPA handles, event buffers, and
  303. * event counts for each of InstanceCount instances. That is,
  304. * Instances points to an array of InstanceCount pointers to
  305. * DSSI plugin instantiations, Events points to an array of
  306. * pointers to each instantiation's respective event list, and
  307. * EventCounts points to an array containing each instantiation's
  308. * respective event count.
  309. *
  310. * A host using this function must guarantee that ALL active
  311. * instances of the plugin are represented in each call to the
  312. * function -- that is, a host may not call run_multiple_synths()
  313. * for some instances of a given plugin and then call run_synth()
  314. * as well for others. 'All .. instances of the plugin' means
  315. * every instance sharing the same LADSPA label and shared object
  316. * (*.so) file (rather than every instance sharing the same *.so).
  317. * 'Active' means any instance for which activate() has been called
  318. * but deactivate() has not.
  319. *
  320. * A plugin may provide this function, run_synths() (see above),
  321. * both, or neither (if it not in fact a synth). A plugin that
  322. * does not provide this function must set this member to NULL.
  323. * Plugin authors implementing run_multiple_synths are strongly
  324. * encouraged to implement run_synth as well if at all possible,
  325. * to aid simplistic hosts, even where it would be less efficient
  326. * to use it.
  327. */
  328. void (*run_multiple_synths)(unsigned long InstanceCount,
  329. LADSPA_Handle *Instances,
  330. unsigned long SampleCount,
  331. snd_seq_event_t **Events,
  332. unsigned long *EventCounts);
  333. /**
  334. * run_multiple_synths_adding()
  335. *
  336. * This member is a function pointer that runs multiple synth
  337. * instances for a block, adding each synth's outputs to the
  338. * values already present at the output ports. This is provided
  339. * for symmetry with both the DSSI run_multiple_synths() and LADSPA
  340. * run_adding() functions, and is equally optional. A plugin
  341. * that does not provide it must set this member to NULL.
  342. */
  343. void (*run_multiple_synths_adding)(unsigned long InstanceCount,
  344. LADSPA_Handle *Instances,
  345. unsigned long SampleCount,
  346. snd_seq_event_t **Events,
  347. unsigned long *EventCounts);
  348. /**
  349. * set_custom_data()
  350. */
  351. int (*set_custom_data)(LADSPA_Handle Instance,
  352. void *Data,
  353. unsigned long DataLength);
  354. /**
  355. * get_custom_data()
  356. */
  357. int (*get_custom_data)(LADSPA_Handle Instance,
  358. void **Data,
  359. unsigned long *DataLength);
  360. } DSSI_Descriptor;
  361. /**
  362. * DSSI supports a plugin discovery method similar to that of LADSPA:
  363. *
  364. * - DSSI hosts may wish to locate DSSI plugin shared object files by
  365. * searching the paths contained in the DSSI_PATH and LADSPA_PATH
  366. * environment variables, if they are present. Both are expected
  367. * to be colon-separated lists of directories to be searched (in
  368. * order), and DSSI_PATH should be searched first if both variables
  369. * are set.
  370. *
  371. * - Each shared object file containing DSSI plugins must include a
  372. * function dssi_descriptor(), with the following function prototype
  373. * and C-style linkage. Hosts may enumerate the plugin types
  374. * available in the shared object file by repeatedly calling
  375. * this function with successive Index values (beginning from 0),
  376. * until a return value of NULL indicates no more plugin types are
  377. * available. Each non-NULL return is the DSSI_Descriptor
  378. * of a distinct plugin type.
  379. */
  380. const DSSI_Descriptor *dssi_descriptor(unsigned long Index);
  381. typedef const DSSI_Descriptor *(*DSSI_Descriptor_Function)(unsigned long Index);
  382. /*
  383. * Macros to specify particular MIDI controllers in return values from
  384. * get_midi_controller_for_port()
  385. */
  386. #define DSSI_CC_BITS 0x20000000
  387. #define DSSI_NRPN_BITS 0x40000000
  388. #define DSSI_NONE -1
  389. #define DSSI_CONTROLLER_IS_SET(n) (DSSI_NONE != (n))
  390. #define DSSI_CC(n) (DSSI_CC_BITS | (n))
  391. #define DSSI_IS_CC(n) (DSSI_CC_BITS & (n))
  392. #define DSSI_CC_NUMBER(n) ((n) & 0x7f)
  393. #define DSSI_NRPN(n) (DSSI_NRPN_BITS | ((n) << 7))
  394. #define DSSI_IS_NRPN(n) (DSSI_NRPN_BITS & (n))
  395. #define DSSI_NRPN_NUMBER(n) (((n) >> 7) & 0x3fff)
  396. #ifdef __cplusplus
  397. }
  398. #endif
  399. #endif /* DSSI_INCLUDED */