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.

486 lines
18KB

  1. /*
  2. * Carla Native Plugin API
  3. * Copyright (C) 2012-2013 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the doc/GPL.txt file.
  16. */
  17. #ifndef CARLA_NATIVE_H_INCLUDED
  18. #define CARLA_NATIVE_H_INCLUDED
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. #include <stdbool.h>
  23. #include <stddef.h>
  24. #include <stdint.h>
  25. /*!
  26. * @defgroup CarlaNativeAPI Carla Native API
  27. *
  28. * The Carla Native API
  29. * @{
  30. */
  31. // -----------------------------------------------------------------------
  32. // Macros
  33. /*!
  34. * Current API version.
  35. */
  36. #define CARLA_NATIVE_API_VERSION 1
  37. /*!
  38. * @defgroup PluginCategories Plugin Categories
  39. *
  40. * A small list of pre-defined plugin categories.
  41. *
  42. * Plugins can use their own custom categories as well, as long as they are lowercase and contain ASCII characters only.
  43. * Many categories can be set by using ":" in between them.
  44. * @{
  45. */
  46. #define PLUGIN_CATEGORY_SYNTH "synth" //!< A synthesizer or generator.
  47. #define PLUGIN_CATEGORY_DELAY "delay" //!< A delay or reverberator.
  48. #define PLUGIN_CATEGORY_EQ "eq" //!< An equalizer.
  49. #define PLUGIN_CATEGORY_FILTER "filter" //!< A filter.
  50. #define PLUGIN_CATEGORY_DYNAMICS "dynamics" //!< A 'dynamic' plugin (amplifier, compressor, gate, etc).
  51. #define PLUGIN_CATEGORY_MODULATOR "modulator" //!< A 'modulator' plugin (chorus, flanger, phaser, etc).
  52. #define PLUGIN_CATEGORY_UTILITY "utility" //!< An 'utility' plugin (analyzer, converter, mixer, etc).
  53. #define PLUGIN_CATEGORY_OTHER "other" //!< Misc plugin (used to check if the plugin has a category).
  54. /**@}*/
  55. /*!
  56. * @defgroup PluginFeatures Plugin Features
  57. *
  58. * A list of plugin features or hints.
  59. *
  60. * Custom features are allowed, as long as they are lowercase and contain ASCII characters only.
  61. * The host can decide if it can load the plugin or not based on this information.
  62. *
  63. * Multiple features can be set by using ":" in between them.
  64. * @{
  65. */
  66. #define PLUGIN_FEATURE_RTSAFE "rtsafe" //!< Is hard-realtime safe.
  67. #define PLUGIN_FEATURE_IDLE "idle" //!< Needs non-realtime idle regularly. @see HOST_OPCODE_NEEDS_IDLE
  68. #define PLUGIN_FEATURE_STATE "state" //!< Supports get_state() and set_state() functions.
  69. #define PLUGIN_FEATURE_TIME "time" //!< Uses get_time_info() function.
  70. #define PLUGIN_FEATURE_SEND_MSG "sendmsg" //!< Uses send_ui_msg() function.
  71. #define PLUGIN_FEATURE_WRITE_EVENT "writeevent" //!< Uses write_event() function.
  72. #define PLUGIN_FEATURE_FIXED_BUFFERS "fixedbuffers" //!< Needs fixed-size audio buffers.
  73. #define PLUGIN_FEATURE_MONO_PANNING "monopanning" //!< Prefers mono-style panning.
  74. #define PLUGIN_FEATURE_STEREO_BALANCE "stereobalance" //!< Prefers stereo balance.
  75. /**@}*/
  76. /*!
  77. * @defgroup UiFeatures UI Features
  78. *
  79. * A list of UI features or hints.
  80. *
  81. * Custom features are allowed, as long as they are lowercase and contain ASCII characters only.
  82. * The host can decide if it can load the plugin or not based on this information.
  83. *
  84. * Multiple features can be set by using ":" in between them.
  85. * @{
  86. */
  87. #define UI_FEATURE_OPEN_SAVE "opensave" //!< Uses ui_open_file() and/or ui_save_file() functions.
  88. #define UI_FEATURE_SEND_MSG "sendmsg" //!< Uses send_plugin_msg() function.
  89. #define UI_FEATURE_SINGLE_THREAD "singlethread" //!< Needs parameter, midi-program and custom-data changes in the main thread.
  90. /**@}*/
  91. /*!
  92. * TODO - this needs a better name...
  93. *
  94. * @defgroup PluginSupports Plugin Supports
  95. *
  96. * A list of plugin supported MIDI events.
  97. *
  98. * Multiple (supports) can be set by using ":" in between them.
  99. * @{
  100. */
  101. #define PLUGIN_SUPPORTS_PROGRAM_CHANGES "program" //!< Handles MIDI programs internally instead of host-exposed/exported
  102. #define PLUGIN_SUPPORTS_CONTROL_CHANGES "control" //!< Supports control changes (0xB0)
  103. #define PLUGIN_SUPPORTS_CHANNEL_PRESSURE "pressure" //!< Supports channel pressure (0xD0)
  104. #define PLUGIN_SUPPORTS_NOTE_AFTERTOUCH "aftertouch" //!< Supports note aftertouch (0xA0)
  105. #define PLUGIN_SUPPORTS_PITCHBEND "pitchbend" //!< Supports pitchbend (0xE0)
  106. #define PLUGIN_SUPPORTS_ALL_SOUND_OFF "allsoundoff" //!< Supports all-sound-off and all-notes-off events
  107. #define PLUGIN_SUPPORTS_EVERYTHING "program:control:pressure:aftertouch:pitchbend:allsoundoff" //!< Supports everything
  108. /**@}*/
  109. /*!
  110. * @defgroup ParameterHints Parameter Hints
  111. *
  112. * List of parameter hints.
  113. *
  114. * Multiple hints can be set by using ":" in between them.
  115. * @{
  116. */
  117. #define PARAMETER_IS_OUTPUT "output" //!< Is output; input if unset.
  118. #define PARAMETER_IS_ENABLED "enabled" //!< Is enabled and shown by the host; can be changed if not output.
  119. #define PARAMETER_IS_AUTOMABLE "automable" //!< Is automable; get_parameter_value() and set_parameter_value() MUST be realtime safe for this parameter.
  120. #define PARAMETER_IS_BOOLEAN "boolean" //!< Values are boolean (always at minimum or maximum values).
  121. #define PARAMETER_IS_INTEGER "integer" //!< Values are integer.
  122. #define PARAMETER_IS_LOGARITHMIC "logarithmic" //!< Values are logarithmic.
  123. #define PARAMETER_USES_SAMPLE_RATE "samplerate" //!< Needs sample-rate to work (value and ranges are multiplied by SR on usage, divided by SR on save).
  124. #define PARAMETER_USES_SCALEPOINTS "scalepoints" //!< Uses scalepoints to define internal values in a meaningful way.
  125. #define PARAMETER_USES_CUSTOM_TEXT "customtext" //!< Uses custom text for displaying its value. @see get_parameter_text()
  126. /**@}*/
  127. /*!
  128. * @defgroup DefaultParameterRanges Default Parameter Ranges
  129. *
  130. * Default ParameterRanges values.
  131. * @{
  132. */
  133. #define PARAMETER_RANGE_DEFAULT_STEP 0.01f
  134. #define PARAMETER_RANGE_DEFAULT_STEP_SMALL 0.0001f
  135. #define PARAMETER_RANGE_DEFAULT_STEP_LARGE 0.1f
  136. /**@}*/
  137. /*!
  138. * @defgroup EventTypes EventTypes
  139. *
  140. * List of supported event types.
  141. *
  142. * The types are mapped into MappedValue by the host.
  143. * @see HostDescriptor::map_value()
  144. * @{
  145. */
  146. #define EVENT_TYPE_MIDI "midi" //!< @see MidiEvent
  147. #define EVENT_TYPE_PARAMETER "parameter" //!< @see ParameterEvent
  148. /**@}*/
  149. /*!
  150. * @defgroup PluginDispatcherOpcodes Plugin Dispatcher Opcodes
  151. *
  152. * Opcodes dispatched by the host to report changes to the plugin or UI.
  153. *
  154. * The opcodes are mapped into MappedValue by the host.
  155. * @see PluginDescriptor::dispatcher()
  156. * @{
  157. */
  158. #define PLUGIN_OPCODE_MSG_RECEIVED "msgReceived" //!< Message received, uses ptr as char*.
  159. #define PLUGIN_OPCODE_BUFFER_SIZE_CHANGED "bufferSizeChanged" //!< Audio buffer size changed, uses value. @see PluginHostDescriptor::get_buffer_size()
  160. #define PLUGIN_OPCODE_SAMPLE_RATE_CHANGED "sampleRateChanged" //!< Audio sample rate changed, uses opt. @see Plugin/UiHostDescriptor::get_sample_rate()
  161. #define PLUGIN_OPCODE_OFFLINE_CHANGED "offlineChanged" //!< Offline mode changed, uses value (0=off, 1=on). @see Plugin/UiHostDescriptor::is_offline()
  162. #define PLUGIN_OPCODE_UI_TITLE_CHANGED "uiTitleChanged" //!< UI title changed, uses ptr. @see UiHostDescriptor::is_offline()
  163. /**@}*/
  164. /*!
  165. * @defgroup HostDispatcherOpcodes Host Dispatcher Opcodes
  166. *
  167. * Opcodes dispatched by the plugin or UI to report and request information from the host.
  168. *
  169. * The opcodes are mapped into MappedValue by the host.
  170. * @see HostDescriptor::dispatcher()
  171. * @{
  172. */
  173. #define HOST_OPCODE_NEEDS_IDLE "needsIdle" //!< Tell the host to call idle() as soon as possible (once), uses nothing.
  174. #define HOST_OPCODE_SET_VOLUME "setVolume" //!< Set host's volume, uses opt. MUST ONLY be called within PluginDescriptor::set_midi_program().
  175. #define HOST_OPCODE_SET_DRYWET "setDryWet" //!< Set host's dry-wet, uses opt. MUST ONLY be called within PluginDescriptor::set_midi_program().
  176. #define HOST_OPCODE_SET_BALANCE_LEFT "setBalanceLeft" //!< Set host's balance-left, uses opt. MUST ONLY be called within PluginDescriptor::set_midi_program().
  177. #define HOST_OPCODE_SET_BALANCE_RIGHT "setBalanceRight" //!< Set host's balance-right, uses opt. MUST ONLY be called within PluginDescriptor::set_midi_program().
  178. #define HOST_OPCODE_SET_PANNING "setPanning" //!< Set host's panning, uses opt. MUST ONLY be called within PluginDescriptor::set_midi_program().
  179. #define HOST_OPCODE_GET_PARAMETER_MIDI_CC "getParameterMidiCC" //!< Get the parameter @a index currently mapped MIDI control, uses index, return answer.
  180. #define HOST_OPCODE_SET_PARAMETER_MIDI_CC "setParameterMidiCC" //!< Set the parameter @a index mapped MIDI control, uses index and value.
  181. #define HOST_OPCODE_UPDATE_PARAMETER "updateParameter" //!< Tell the host to update parameter @a index, uses index with -1 for all.
  182. #define HOST_OPCODE_UPDATE_MIDI_PROGRAM "updateMidiProgram" //!< Tell the host to update midi-program @index, uses index with -1 for all; may also use value for channel.
  183. #define HOST_OPCODE_RELOAD_PARAMETERS "reloadParameters" //!< Tell the host to reload all parameters data, uses nothing.
  184. #define HOST_OPCODE_RELOAD_MIDI_PROGRAMS "reloadMidiPrograms" //!< Tell the host to reload all midi-programs data, uses nothing.
  185. #define HOST_OPCODE_RELOAD_ALL "reloadAll" //!< Tell the host to reload everything all the plugin, uses nothing.
  186. #define HOST_OPCODE_UI_UNAVAILABLE "uiUnavailable" //!< Tell the host the UI can't be shown, uses nothing.
  187. /**@}*/
  188. // -----------------------------------------------------------------------
  189. // Base types
  190. /*!
  191. * Host mapped value of a string.
  192. * @see Plugin/UiHostDescriptor::map_value()
  193. */
  194. typedef int32_t MappedValue;
  195. /*!
  196. * Opaque plugin handle.
  197. */
  198. typedef void* PluginHandle;
  199. /*!
  200. * Opaque UI handle.
  201. */
  202. typedef void* UiHandle;
  203. /*!
  204. * Opaque plugin host handle.
  205. */
  206. typedef void* PluginHostHandle;
  207. /*!
  208. * Opaque UI host handle.
  209. */
  210. typedef void* UiHostHandle;
  211. // -----------------------------------------------------------------------
  212. // Base structs
  213. /*!
  214. * Parameter scale point.
  215. */
  216. typedef struct {
  217. const char* label;
  218. float value;
  219. } ParameterScalePoint;
  220. /*!
  221. * Paraneter ranges.
  222. */
  223. typedef struct {
  224. float def;
  225. float min;
  226. float max;
  227. float step;
  228. float stepSmall;
  229. float stepLarge;
  230. } ParameterRanges;
  231. /*!
  232. * Parameter.
  233. */
  234. typedef struct {
  235. const char* hints; //!< @see ParameterHints
  236. const char* name;
  237. const char* unit;
  238. ParameterRanges ranges;
  239. uint32_t scalePointCount;
  240. ParameterScalePoint* scalePoints;
  241. } Parameter;
  242. /*!
  243. * MIDI Program.
  244. */
  245. typedef struct {
  246. uint32_t bank;
  247. uint32_t program;
  248. const char* name;
  249. } MidiProgram;
  250. /*!
  251. * Bar-Beat-Tick information.
  252. *
  253. * @note this is the same data provided by JACK
  254. */
  255. typedef struct {
  256. bool valid;
  257. int32_t bar; //!< current bar
  258. int32_t beat; //!< current beat-within-bar
  259. int32_t tick; //!< current tick-within-beat
  260. double barStartTick;
  261. float beatsPerBar; //!< time signature "numerator"
  262. float beatType; //!< time signature "denominator"
  263. double ticksPerBeat;
  264. double beatsPerMinute;
  265. } TimeInfoBBT;
  266. /*!
  267. * Time information.
  268. */
  269. typedef struct {
  270. bool playing;
  271. uint64_t frame;
  272. uint64_t usecs;
  273. TimeInfoBBT bbt;
  274. } TimeInfo;
  275. /*!
  276. * Generic event.
  277. */
  278. typedef struct {
  279. MappedValue type; //!< Type of event. @see EventTypes
  280. uint32_t frame; //!< Frame offset since the beginning of process()
  281. } Event;
  282. /*!
  283. * MIDI event.
  284. */
  285. typedef struct {
  286. Event e;
  287. uint8_t port;
  288. uint8_t size;
  289. uint8_t data[4];
  290. } MidiEvent;
  291. /*!
  292. * Parameter event.
  293. */
  294. typedef struct {
  295. Event e;
  296. uint32_t index;
  297. float value;
  298. } ParameterEvent;
  299. // -----------------------------------------------------------------------
  300. // PluginHostDescriptor
  301. typedef struct {
  302. PluginHostHandle handle;
  303. /*!
  304. * Previously used plugin version, may be 0.
  305. * Plugins might want to check this value during set_parameter_value(), set_midi_program() and set_state().
  306. */
  307. int pluginVersion;
  308. MappedValue (*map_value)(PluginHostHandle handle, const char* valueStr);
  309. const char* (*unmap_value)(PluginHostHandle handle, MappedValue value);
  310. uint32_t (*get_buffer_size)(PluginHostHandle handle);
  311. double (*get_sample_rate)(PluginHostHandle handle);
  312. bool (*is_offline)(PluginHostHandle handle);
  313. // plugin must set "time" feature to use this
  314. const TimeInfo* (*get_time_info)(PluginHostHandle handle);
  315. // plugin must set "sendmsg" feature to use this
  316. bool (*send_ui_msg)(const char* msg);
  317. // plugin must set "writeevent" feature to use this
  318. bool (*write_event)(PluginHostHandle handle, const Event* event);
  319. // uses HostDispatcherOpcodes
  320. intptr_t (*dispatcher)(PluginHostHandle handle, MappedValue opcode, int32_t index, intptr_t value, void* ptr, float opt);
  321. } PluginHostDescriptor;
  322. // -----------------------------------------------------------------------
  323. // UiHostDescriptor
  324. typedef struct {
  325. UiHostHandle handle;
  326. const char* resourceDir;
  327. const char* uiTitle;
  328. MappedValue (*map_value)(UiHostHandle handle, const char* valueStr);
  329. const char* (*unmap_value)(UiHostHandle handle, MappedValue value);
  330. double (*get_sample_rate)(UiHostHandle handle);
  331. bool (*is_offline)(UiHostHandle handle);
  332. void (*parameter_changed)(UiHostHandle handle, uint32_t index, float value);
  333. void (*midi_program_changed)(UiHostHandle handle, uint8_t channel, uint32_t bank, uint32_t program);
  334. void (*closed)(UiHostHandle handle);
  335. // TODO: add some msgbox call
  336. // ui must set "opensave" feature to use these
  337. const char* (*open_file)(UiHostHandle handle, bool isDir, const char* title, const char* filter);
  338. const char* (*save_file)(UiHostHandle handle, bool isDir, const char* title, const char* filter);
  339. // ui must set "sendmsg" feature to use this
  340. bool (*send_plugin_msg)(const char* msg);
  341. // uses HostDispatcherOpcodes
  342. intptr_t (*dispatcher)(PluginHostHandle handle, MappedValue opcode, int32_t index, intptr_t value, void* ptr, float opt);
  343. } UiHostDescriptor;
  344. // -----------------------------------------------------------------------
  345. // PluginDescriptor
  346. typedef struct _PluginDescriptor {
  347. const int api_version; //!< Must be set to CARLA_NATIVE_API_VERSION
  348. const char* const categories; //!< Categories. @see PluginCategories
  349. const char* const features; //!< Features. @see PluginFeatures
  350. const char* const supports; //!< MIDI supported events. @see PluginSupports
  351. const uint32_t audioIns; //!< Default number of audio inputs.
  352. const uint32_t audioOuts; //!< Default number of audio outputs.
  353. const uint32_t midiIns; //!< Default number of MIDI inputs.
  354. const uint32_t midiOuts; //!< Default number of MIDI inputs.
  355. const uint32_t parameterIns; //!< Default number of input parameters, may be 0.
  356. const uint32_t parameterOuts; //!< Default number of output parameters, may be 0.
  357. const char* const author; //!< Author.
  358. const char* const name; //!< Name.
  359. const char* const label; //!< Label, can only contain letters, numbers and "_".
  360. const char* const copyright; //!< Copyright.
  361. const int version; //!< Version.
  362. PluginHandle (*instantiate)(const PluginHostDescriptor* host);
  363. void (*cleanup)(PluginHandle handle);
  364. uint32_t (*get_parameter_count)(PluginHandle handle);
  365. const Parameter* (*get_parameter_info)(PluginHandle handle, uint32_t index);
  366. float (*get_parameter_value)(PluginHandle handle, uint32_t index);
  367. const char* (*get_parameter_text)(PluginHandle handle, uint32_t index, float value); // only used if parameter hint "customtext" is set
  368. void (*set_parameter_value)(PluginHandle handle, uint32_t index, float value);
  369. uint32_t (*get_midi_program_count)(PluginHandle handle);
  370. const MidiProgram* (*get_midi_program_info)(PluginHandle handle, uint32_t index);
  371. void (*set_midi_program)(PluginHandle handle, uint8_t channel, uint32_t bank, uint32_t program); // channel used only in synths
  372. // only used if "state" feature is set
  373. char* (*get_state)(PluginHandle handle);
  374. void (*set_state)(PluginHandle handle, const char* data);
  375. // only used if "idle" feature is set, or HOST_OPCODE_NEEDS_IDLE was triggered (for one-shot).
  376. // NOTE: although it's a non-realtime function, it will probably still not be called from the host main thread
  377. void (*idle)();
  378. void (*activate)(PluginHandle handle);
  379. void (*deactivate)(PluginHandle handle);
  380. void (*process)(PluginHandle handle, float** inBuffer, float** outBuffer, uint32_t frames, const Event* events, uint32_t eventCount);
  381. // uses PluginDispatcherOpcodes
  382. intptr_t (*dispatcher)(PluginHandle handle, MappedValue opcode, int32_t index, intptr_t value, void* ptr, float opt);
  383. } PluginDescriptor;
  384. // -----------------------------------------------------------------------
  385. // UiDescriptor
  386. typedef struct {
  387. const int api_version; //!< Must be set to CARLA_NATIVE_API_VERSION
  388. const char* const features; //!< Features. @see UiFeatures
  389. const char* const author; //!< Author this UI matches to.
  390. const char* const label; //!< Label this UI matches to, can only contain letters, numbers and "_". May be null, in which case represents all UIs for @a maker.
  391. UiHandle (*instantiate)(const UiHostDescriptor* host);
  392. void (*cleanup)(UiHandle handle);
  393. void (*show)(UiHandle handle, bool show);
  394. void (*idle)(UiHandle handle);
  395. void (*set_parameter_value)(UiHandle handle, uint32_t index, float value);
  396. void (*set_midi_program)(UiHandle handle, uint8_t channel, uint32_t bank, uint32_t program); // channel used only in synths
  397. intptr_t (*dispatcher)(UiHandle handle, MappedValue opcode, int32_t index, intptr_t value, void* ptr, float opt);
  398. } UiDescriptor;
  399. // -----------------------------------------------------------------------
  400. // Register plugin
  401. extern void carla_register_native_plugin(const PluginDescriptor* desc);
  402. // -----------------------------------------------------------------------
  403. /**@}*/
  404. #ifdef __cplusplus
  405. } // extern "C"
  406. #endif
  407. #endif // CARLA_NATIVE_H_INCLUDED