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.

315 lines
12KB

  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. typedef int32_t AtomXYZ;
  32. typedef void* HostHandle;
  33. typedef void* PluginHandle;
  34. // -----------------------------------------------------------------------
  35. // enums
  36. #define PLUGIN_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_GUI "gui" //!< Provides custom UI.
  68. #define PLUGIN_FEATURE_STATE "state" //!< Supports get_state() and set_state().
  69. #define PLUGIN_FEATURE_TIME "time" //!< Uses get_time_info().
  70. #define PLUGIN_FEATURE_WRITE_EVENT "writeevent" //!< Uses write_event().
  71. #define PLUGIN_FEATURE_FIXED_BUFFERS "fixedbuffers" //!< Needs fixed-size audio buffers.
  72. #define PLUGIN_FEATURE_MONO_PANNING "monopanning" //!< Prefers mono-style panning.
  73. #define PLUGIN_FEATURE_STEREO_BALANCE "stereobalance" //!< Prefers stereo balance.
  74. #define PLUGIN_FEATURE_OPENSAVE "uiopensave" //!< UI uses ui_open_file() and/or ui_save_file() functions.
  75. #define PLUGIN_FEATURE_SINGLE_THREAD "uisinglethread" //!< UI needs paramter, midi-program and custom-data changes in the main thread.
  76. /**@}*/
  77. /*!
  78. * @defgroup PluginSupports Plugin Supports
  79. *
  80. * A list of plugin supported MIDI events.
  81. * @{
  82. */
  83. #define PLUGIN_SUPPORTS_PROGRAM_CHANGES "program" //!< Handles MIDI programs internally instead of host-exposed/exported
  84. #define PLUGIN_SUPPORTS_CONTROL_CHANGES "control" //!< Supports control changes (0xB0)
  85. #define PLUGIN_SUPPORTS_CHANNEL_PRESSURE "pressure" //!< Supports channel pressure (0xD0)
  86. #define PLUGIN_SUPPORTS_NOTE_AFTERTOUCH "aftertouch" //!< Supports note aftertouch (0xA0)
  87. #define PLUGIN_SUPPORTS_PITCHBEND "pitchbend" //!< Supports pitchbend (0xE0)
  88. #define PLUGIN_SUPPORTS_ALL_SOUND_OFF "allsoundoff" //!< Supporta all-sound-off and all-notes-off events
  89. #define PLUGIN_SUPPORTS_EVERYTHING "program:control:pressure:aftertouch:pitchbend:allsoundoff" //!< Supports everything
  90. /**@}*/
  91. /*!
  92. * @defgroup ParameterHints Parameter Hints
  93. *
  94. * List of parameter hints.
  95. * @{
  96. */
  97. #define PARAMETER_IS_OUTPUT "output" //!< Is output; input if unset.
  98. #define PARAMETER_IS_ENABLED "enabled" //!< Is enabled and shown by the host; can be changed if not output.
  99. #define PARAMETER_IS_AUTOMABLE "automable" //!< Is automable; get_parameter_value() and set_parameter_value() MUST be realtime safe for this parameter.
  100. #define PARAMETER_IS_BOOLEAN "boolean" //!< Values are boolean (always at minimum or maximum values).
  101. #define PARAMETER_IS_INTEGER "integer" //!< Values are integer.
  102. #define PARAMETER_IS_LOGARITHMIC "logarithmic" //!< Values are logarithmic.
  103. #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).
  104. #define PARAMETER_USES_SCALEPOINTS "scalepoints" //!< Uses scalepoints to define internal values in a meaningful way.
  105. #define PARAMETER_USES_CUSTOM_TEXT "customtext" //!< Uses custom text for displaying its value. @see get_parameter_text()
  106. /**@}*/
  107. typedef enum {
  108. PLUGIN_OPCODE_NULL = 0, // nothing
  109. PLUGIN_OPCODE_BUFFER_SIZE_CHANGED = 1, // uses value
  110. PLUGIN_OPCODE_SAMPLE_RATE_CHANGED = 2, // uses opt
  111. PLUGIN_OPCODE_OFFLINE_CHANGED = 3, // uses value (0=off, 1=on)
  112. PLUGIN_OPCODE_UI_NAME_CHANGED = 4 // uses ptr
  113. } PluginDispatcherOpcode;
  114. typedef enum {
  115. HOST_OPCODE_NULL = 0, // nothing
  116. HOST_OPCODE_SET_VOLUME = 1, // uses opt
  117. HOST_OPCODE_SET_DRYWET = 2, // uses opt
  118. HOST_OPCODE_SET_BALANCE_LEFT = 3, // uses opt
  119. HOST_OPCODE_SET_BALANCE_RIGHT = 4, // uses opt
  120. HOST_OPCODE_SET_PANNING = 5, // uses opt
  121. HOST_OPCODE_GET_PARAMETER_MIDI_CC = 6, // uses index; return answer
  122. HOST_OPCODE_SET_PARAMETER_MIDI_CC = 7, // uses index and value
  123. HOST_OPCODE_SET_PROCESS_PRECISION = 8, // uses value
  124. HOST_OPCODE_UPDATE_PARAMETER = 9, // uses index, -1 for all
  125. HOST_OPCODE_UPDATE_MIDI_PROGRAM = 10, // uses index, -1 for all; may use value for channel
  126. HOST_OPCODE_RELOAD_PARAMETERS = 11, // nothing
  127. HOST_OPCODE_RELOAD_MIDI_PROGRAMS = 12, // nothing
  128. HOST_OPCODE_RELOAD_ALL = 13, // nothing
  129. HOST_OPCODE_UI_UNAVAILABLE = 14 // nothing
  130. } HostDispatcherOpcode;
  131. // -----------------------------------------------------------------------
  132. // base structs
  133. typedef struct {
  134. const char* label;
  135. float value;
  136. } ParameterScalePoint;
  137. typedef struct {
  138. float def;
  139. float min;
  140. float max;
  141. float step;
  142. float stepSmall;
  143. float stepLarge;
  144. } ParameterRanges;
  145. #define PARAMETER_RANGES_DEFAULT_STEP 0.01f
  146. #define PARAMETER_RANGES_DEFAULT_STEP_SMALL 0.0001f
  147. #define PARAMETER_RANGES_DEFAULT_STEP_LARGE 0.1f
  148. typedef struct {
  149. const char* hints;
  150. const char* name;
  151. const char* unit;
  152. ParameterRanges ranges;
  153. uint32_t scalePointCount;
  154. ParameterScalePoint* scalePoints;
  155. } Parameter;
  156. typedef struct {
  157. AtomXYZ type;
  158. uint32_t frame;
  159. } Event;
  160. typedef struct {
  161. Event e;
  162. uint8_t port;
  163. uint8_t size;
  164. uint8_t data[4];
  165. } MidiEvent;
  166. typedef struct {
  167. Event e;
  168. uint32_t index;
  169. float value;
  170. } ParameterEvent;
  171. typedef struct {
  172. uint32_t bank;
  173. uint32_t program;
  174. const char* name;
  175. } MidiProgram;
  176. typedef struct {
  177. bool valid;
  178. int32_t bar; //!< current bar
  179. int32_t beat; //!< current beat-within-bar
  180. int32_t tick; //!< current tick-within-beat
  181. double barStartTick;
  182. float beatsPerBar; //!< time signature "numerator"
  183. float beatType; //!< time signature "denominator"
  184. double ticksPerBeat;
  185. double beatsPerMinute;
  186. } TimeInfoBBT;
  187. typedef struct {
  188. bool playing;
  189. uint64_t frame;
  190. uint64_t usecs;
  191. TimeInfoBBT bbt;
  192. } TimeInfo;
  193. // -----------------------------------------------------------------------
  194. // HostDescriptor
  195. typedef struct {
  196. HostHandle handle;
  197. const char* resourceDir;
  198. const char* uiName;
  199. uint32_t (*get_buffer_size)(HostHandle handle);
  200. double (*get_sample_rate)(HostHandle handle);
  201. bool (*is_offline)(HostHandle handle);
  202. const TimeInfo* (*get_time_info)(HostHandle handle);
  203. bool (*write_event)(HostHandle handle, const Event* event);
  204. void (*ui_parameter_changed)(HostHandle handle, uint32_t index, float value);
  205. void (*ui_midi_program_changed)(HostHandle handle, uint8_t channel, uint32_t bank, uint32_t program);
  206. void (*ui_custom_data_changed)(HostHandle handle, const char* key, const char* value);
  207. void (*ui_closed)(HostHandle handle);
  208. // TODO: add some msgbox call
  209. const char* (*ui_open_file)(HostHandle handle, bool isDir, const char* title, const char* filter);
  210. const char* (*ui_save_file)(HostHandle handle, bool isDir, const char* title, const char* filter);
  211. intptr_t (*dispatcher)(HostHandle handle, HostDispatcherOpcode opcode, int32_t index, intptr_t value, void* ptr, float opt);
  212. } HostDescriptor;
  213. // -----------------------------------------------------------------------
  214. // PluginDescriptor
  215. typedef struct _PluginDescriptor {
  216. const char* const category;
  217. const char* const hints;
  218. const char* const supports;
  219. const uint32_t audioIns;
  220. const uint32_t audioOuts;
  221. const uint32_t midiIns;
  222. const uint32_t midiOuts;
  223. const uint32_t parameterIns;
  224. const uint32_t parameterOuts;
  225. const char* const name;
  226. const char* const label;
  227. const char* const maker;
  228. const char* const copyright;
  229. PluginHandle (*instantiate)(const HostDescriptor* host);
  230. void (*cleanup)(PluginHandle handle);
  231. uint32_t (*get_parameter_count)(PluginHandle handle);
  232. const Parameter* (*get_parameter_info)(PluginHandle handle, uint32_t index);
  233. float (*get_parameter_value)(PluginHandle handle, uint32_t index);
  234. const char* (*get_parameter_text)(PluginHandle handle, uint32_t index, float value);
  235. uint32_t (*get_midi_program_count)(PluginHandle handle);
  236. const MidiProgram* (*get_midi_program_info)(PluginHandle handle, uint32_t index);
  237. void (*set_parameter_value)(PluginHandle handle, uint32_t index, float value);
  238. void (*set_midi_program)(PluginHandle handle, uint8_t channel, uint32_t bank, uint32_t program);
  239. void (*set_custom_data)(PluginHandle handle, const char* key, const char* value);
  240. void (*ui_show)(PluginHandle handle, bool show);
  241. void (*ui_idle)(PluginHandle handle);
  242. void (*ui_set_parameter_value)(PluginHandle handle, uint32_t index, float value);
  243. void (*ui_set_midi_program)(PluginHandle handle, uint8_t channel, uint32_t bank, uint32_t program);
  244. void (*ui_set_custom_data)(PluginHandle handle, const char* key, const char* value);
  245. void (*activate)(PluginHandle handle);
  246. void (*deactivate)(PluginHandle handle);
  247. void (*process)(PluginHandle handle, float** inBuffer, float** outBuffer, uint32_t frames, const Event* events, uint32_t eventCount);
  248. char* (*get_state)(PluginHandle handle);
  249. void (*set_state)(PluginHandle handle, const char* data);
  250. intptr_t (*dispatcher)(PluginHandle handle, PluginDispatcherOpcode opcode, int32_t index, intptr_t value, void* ptr, float opt);
  251. } PluginDescriptor;
  252. // -----------------------------------------------------------------------
  253. // Register plugin
  254. extern void carla_register_native_plugin(const PluginDescriptor* desc);
  255. // -----------------------------------------------------------------------
  256. /**@}*/
  257. #ifdef __cplusplus
  258. } // extern "C"
  259. #endif
  260. #endif // CARLA_NATIVE_H_INCLUDED