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.

300 lines
10KB

  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 GPL.txt file
  16. */
  17. #ifndef __CARLA_NATIVE_H__
  18. #define __CARLA_NATIVE_H__
  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. typedef void* HostHandle;
  33. typedef void* PluginHandle;
  34. typedef enum _PluginCategory {
  35. PLUGIN_CATEGORY_NONE = 0, //!< Null plugin category.
  36. PLUGIN_CATEGORY_SYNTH = 1, //!< A synthesizer or generator.
  37. PLUGIN_CATEGORY_DELAY = 2, //!< A delay or reverberator.
  38. PLUGIN_CATEGORY_EQ = 3, //!< An equalizer.
  39. PLUGIN_CATEGORY_FILTER = 4, //!< A filter.
  40. PLUGIN_CATEGORY_DYNAMICS = 5, //!< A 'dynamic' plugin (amplifier, compressor, gate, etc).
  41. PLUGIN_CATEGORY_MODULATOR = 6, //!< A 'modulator' plugin (chorus, flanger, phaser, etc).
  42. PLUGIN_CATEGORY_UTILITY = 7, //!< An 'utility' plugin (analyzer, converter, mixer, etc).
  43. PLUGIN_CATEGORY_OTHER = 8 //!< Misc plugin (used to check if the plugin has a category).
  44. } PluginCategory;
  45. typedef enum _PluginHints {
  46. PLUGIN_IS_RTSAFE = 1 << 0,
  47. PLUGIN_IS_SYNTH = 1 << 1,
  48. PLUGIN_HAS_GUI = 1 << 2,
  49. PLUGIN_USES_GUI_AS_FILE = 1 << 3,
  50. PLUGIN_USES_PANNING = 1 << 4, // uses stereo balance if unset (default)
  51. PLUGIN_USES_SINGLE_THREAD = 1 << 5,
  52. PLUGIN_USES_STATE = 1 << 6,
  53. PLUGIN_USES_STATIC_BUFFERS = 1 << 7
  54. } PluginHints;
  55. typedef enum _PluginSupports {
  56. PLUGIN_SUPPORTS_PROGRAM_CHANGES = 1 << 0, // handles MIDI programs internally instead of host-exposed/exported
  57. PLUGIN_SUPPORTS_CONTROL_CHANGES = 1 << 1,
  58. PLUGIN_SUPPORTS_CHANNEL_PRESSURE = 1 << 2,
  59. PLUGIN_SUPPORTS_NOTE_AFTERTOUCH = 1 << 3,
  60. PLUGIN_SUPPORTS_PITCHBEND = 1 << 4,
  61. PLUGIN_SUPPORTS_ALL_SOUND_OFF = 1 << 5,
  62. PLUGIN_SUPPORTS_EVERYTHING = PLUGIN_SUPPORTS_ALL_SOUND_OFF*2-1
  63. } PluginSupports;
  64. typedef enum _ParameterHints {
  65. PARAMETER_IS_OUTPUT = 1 << 0,
  66. PARAMETER_IS_ENABLED = 1 << 1,
  67. PARAMETER_IS_AUTOMABLE = 1 << 2,
  68. PARAMETER_IS_BOOLEAN = 1 << 3,
  69. PARAMETER_IS_INTEGER = 1 << 4,
  70. PARAMETER_IS_LOGARITHMIC = 1 << 5,
  71. PARAMETER_USES_SAMPLE_RATE = 1 << 6,
  72. PARAMETER_USES_SCALEPOINTS = 1 << 7,
  73. PARAMETER_USES_CUSTOM_TEXT = 1 << 8
  74. } ParameterHints;
  75. typedef enum _PluginDispatcherOpcode {
  76. PLUGIN_OPCODE_NULL = 0, // nothing
  77. PLUGIN_OPCODE_BUFFER_SIZE_CHANGED = 1, // uses value
  78. PLUGIN_OPCODE_SAMPLE_RATE_CHANGED = 2, // uses opt
  79. PLUGIN_OPCODE_OFFLINE_CHANGED = 3, // uses value
  80. PLUGIN_OPCODE_UI_NAME_CHANGED = 4 // uses ptr
  81. } PluginDispatcherOpcode;
  82. typedef enum _HostDispatcherOpcode {
  83. HOST_OPCODE_NULL = 0, // nothing
  84. HOST_OPCODE_SET_VOLUME = 1, // uses opt
  85. HOST_OPCODE_SET_DRYWET = 2, // uses opt
  86. HOST_OPCODE_SET_BALANCE_LEFT = 3, // uses opt
  87. HOST_OPCODE_SET_BALANCE_RIGHT = 4, // uses opt
  88. HOST_OPCODE_SET_PANNING = 5, // uses opt
  89. HOST_OPCODE_SET_PROCESS_PRECISION = 6, // uses value
  90. HOST_OPCODE_UPDATE_PARAMETER = 7, // uses value, -1 for all
  91. HOST_OPCODE_UPDATE_MIDI_PROGRAM = 8, // uses value, -1 for all; may use index for channel
  92. HOST_OPCODE_RELOAD_PARAMETERS = 9, // nothing
  93. HOST_OPCODE_RELOAD_MIDI_PROGRAMS = 10, // nothing
  94. HOST_OPCODE_RELOAD_ALL = 11, // nothing
  95. HOST_OPCODE_UI_UNAVAILABLE = 12 // nothing
  96. } HostDispatcherOpcode;
  97. typedef struct _ParameterScalePoint {
  98. const char* label;
  99. float value;
  100. } ParameterScalePoint;
  101. typedef struct _ParameterRanges {
  102. float def;
  103. float min;
  104. float max;
  105. float step;
  106. float stepSmall;
  107. float stepLarge;
  108. } ParameterRanges;
  109. #define PARAMETER_RANGES_DEFAULT_STEP 0.01f
  110. #define PARAMETER_RANGES_DEFAULT_STEP_SMALL 0.0001f
  111. #define PARAMETER_RANGES_DEFAULT_STEP_LARGE 0.1f
  112. typedef struct _Parameter {
  113. ParameterHints hints;
  114. const char* name;
  115. const char* unit;
  116. ParameterRanges ranges;
  117. uint32_t scalePointCount;
  118. ParameterScalePoint* scalePoints;
  119. } Parameter;
  120. typedef struct _MidiEvent {
  121. uint8_t port;
  122. uint32_t time;
  123. uint8_t data[4];
  124. uint8_t size;
  125. } MidiEvent;
  126. typedef struct _MidiProgram {
  127. uint32_t bank;
  128. uint32_t program;
  129. const char* name;
  130. } MidiProgram;
  131. typedef struct _TimeInfoBBT {
  132. bool valid;
  133. int32_t bar; //!< current bar
  134. int32_t beat; //!< current beat-within-bar
  135. int32_t tick; //!< current tick-within-beat
  136. double barStartTick;
  137. float beatsPerBar; //!< time signature "numerator"
  138. float beatType; //!< time signature "denominator"
  139. double ticksPerBeat;
  140. double beatsPerMinute;
  141. } TimeInfoBBT;
  142. typedef struct _TimeInfo {
  143. bool playing;
  144. uint64_t frame;
  145. uint64_t usecs;
  146. TimeInfoBBT bbt;
  147. } TimeInfo;
  148. typedef struct _HostDescriptor {
  149. HostHandle handle;
  150. const char* resource_dir;
  151. const char* ui_name;
  152. uint32_t (*get_buffer_size)(HostHandle handle);
  153. double (*get_sample_rate)(HostHandle handle);
  154. bool (*is_offline)(HostHandle handle);
  155. const TimeInfo* (*get_time_info)(HostHandle handle);
  156. bool (*write_midi_event)(HostHandle handle, const MidiEvent* event);
  157. void (*ui_parameter_changed)(HostHandle handle, uint32_t index, float value);
  158. void (*ui_midi_program_changed)(HostHandle handle, uint8_t channel, uint32_t bank, uint32_t program);
  159. void (*ui_custom_data_changed)(HostHandle handle, const char* key, const char* value);
  160. void (*ui_closed)(HostHandle handle);
  161. const char* (*ui_open_file)(HostHandle handle, bool isDir, const char* title, const char* filter);
  162. const char* (*ui_save_file)(HostHandle handle, bool isDir, const char* title, const char* filter);
  163. intptr_t (*dispatcher)(HostHandle handle, HostDispatcherOpcode opcode, int32_t index, intptr_t value, void* ptr, float opt);
  164. } HostDescriptor;
  165. typedef struct _PluginDescriptor {
  166. const PluginCategory category;
  167. const PluginHints hints;
  168. const PluginSupports supports;
  169. const uint32_t audioIns;
  170. const uint32_t audioOuts;
  171. const uint32_t midiIns;
  172. const uint32_t midiOuts;
  173. const uint32_t parameterIns;
  174. const uint32_t parameterOuts;
  175. const char* const name;
  176. const char* const label;
  177. const char* const maker;
  178. const char* const copyright;
  179. PluginHandle (*instantiate)(const struct _PluginDescriptor* _this_, HostDescriptor* host);
  180. void (*cleanup)(PluginHandle handle);
  181. uint32_t (*get_parameter_count)(PluginHandle handle);
  182. const Parameter* (*get_parameter_info)(PluginHandle handle, uint32_t index);
  183. float (*get_parameter_value)(PluginHandle handle, uint32_t index);
  184. const char* (*get_parameter_text)(PluginHandle handle, uint32_t index, float value);
  185. uint32_t (*get_midi_program_count)(PluginHandle handle);
  186. const MidiProgram* (*get_midi_program_info)(PluginHandle handle, uint32_t index);
  187. void (*set_parameter_value)(PluginHandle handle, uint32_t index, float value);
  188. void (*set_midi_program)(PluginHandle handle, uint8_t channel, uint32_t bank, uint32_t program);
  189. void (*set_custom_data)(PluginHandle handle, const char* key, const char* value);
  190. void (*ui_show)(PluginHandle handle, bool show);
  191. void (*ui_idle)(PluginHandle handle);
  192. void (*ui_set_parameter_value)(PluginHandle handle, uint32_t index, float value);
  193. void (*ui_set_midi_program)(PluginHandle handle, uint8_t channel, uint32_t bank, uint32_t program);
  194. void (*ui_set_custom_data)(PluginHandle handle, const char* key, const char* value);
  195. void (*activate)(PluginHandle handle);
  196. void (*deactivate)(PluginHandle handle);
  197. void (*process)(PluginHandle handle, float** inBuffer, float** outBuffer, uint32_t frames, uint32_t midiEventCount, const MidiEvent* midiEvents);
  198. char* (*get_state)(PluginHandle handle);
  199. void (*set_state)(PluginHandle handle, const char* data);
  200. intptr_t (*dispatcher)(PluginHandle handle, PluginDispatcherOpcode opcode, int32_t index, intptr_t value, void* ptr, float opt);
  201. } PluginDescriptor;
  202. // -----------------------------------------------------------------------
  203. // Register plugin
  204. void carla_register_native_plugin(const PluginDescriptor* desc);
  205. // Simple plugins
  206. void carla_register_native_plugin_bypass();
  207. void carla_register_native_plugin_lfo();
  208. void carla_register_native_plugin_midiSequencer();
  209. void carla_register_native_plugin_midiSplit();
  210. void carla_register_native_plugin_midiThrough();
  211. void carla_register_native_plugin_midiTranspose();
  212. void carla_register_native_plugin_nekofilter();
  213. void carla_register_native_plugin_sunvoxfile();
  214. #ifndef BUILD_BRIDGE
  215. // Carla
  216. void carla_register_native_plugin_carla();
  217. #endif
  218. #ifdef WANT_AUDIOFILE
  219. // AudioFile
  220. void carla_register_native_plugin_audiofile();
  221. #endif
  222. #ifdef WANT_MIDIFILE
  223. // MidiFile
  224. void carla_register_native_plugin_midifile();
  225. #endif
  226. #ifdef WANT_OPENGL
  227. // DISTRHO plugins (OpenGL)
  228. void carla_register_native_plugin_3BandEQ();
  229. void carla_register_native_plugin_3BandSplitter();
  230. void carla_register_native_plugin_Nekobi();
  231. void carla_register_native_plugin_PingPongPan();
  232. // void carla_register_native_plugin_StereoEnhancer();
  233. #endif
  234. // DISTRHO plugins (Qt)
  235. // void carla_register_native_plugin_Notes();
  236. #ifdef WANT_ZYNADDSUBFX
  237. // ZynAddSubFX
  238. void carla_register_native_plugin_zynaddsubfx();
  239. #endif
  240. // -----------------------------------------------------------------------
  241. /**@}*/
  242. #ifdef __cplusplus
  243. } // extern "C"
  244. #endif
  245. #endif // __CARLA_NATIVE_H__