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.

274 lines
8.7KB

  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_SINGLE_THREAD = 1 << 4,
  51. PLUGIN_USES_STATE = 1 << 5
  52. } PluginHints;
  53. typedef enum _ParameterHints {
  54. PARAMETER_IS_OUTPUT = 1 << 0,
  55. PARAMETER_IS_ENABLED = 1 << 1,
  56. PARAMETER_IS_AUTOMABLE = 1 << 2,
  57. PARAMETER_IS_BOOLEAN = 1 << 3,
  58. PARAMETER_IS_INTEGER = 1 << 4,
  59. PARAMETER_IS_LOGARITHMIC = 1 << 5,
  60. PARAMETER_USES_SAMPLE_RATE = 1 << 6,
  61. PARAMETER_USES_SCALEPOINTS = 1 << 7,
  62. PARAMETER_USES_CUSTOM_TEXT = 1 << 8
  63. } ParameterHints;
  64. typedef enum _PluginDispatcherOpcode {
  65. PLUGIN_OPCODE_NULL = 0, // nothing
  66. PLUGIN_OPCODE_BUFFER_SIZE_CHANGED = 1, // nothing
  67. PLUGIN_OPCODE_SAMPLE_RATE_CHANGED = 2, // nothing
  68. PLUGIN_OPCODE_UI_NAME_CHANGED = 3 // nothing
  69. } PluginDispatcherOpcode;
  70. typedef enum _HostDispatcherOpcode {
  71. HOST_OPCODE_NULL = 0, // nothing
  72. HOST_OPCODE_SET_PROCESS_PRECISION = 1, // uses value
  73. HOST_OPCODE_UI_UNAVAILABLE = 2 // nothing
  74. } HostDispatcherOpcode;
  75. typedef struct _ParameterScalePoint {
  76. const char* label;
  77. float value;
  78. } ParameterScalePoint;
  79. typedef struct _ParameterRanges {
  80. float def;
  81. float min;
  82. float max;
  83. float step;
  84. float stepSmall;
  85. float stepLarge;
  86. } ParameterRanges;
  87. #define PARAMETER_RANGES_DEFAULT_STEP 0.01f
  88. #define PARAMETER_RANGES_DEFAULT_STEP_SMALL 0.0001f
  89. #define PARAMETER_RANGES_DEFAULT_STEP_LARGE 0.1f
  90. typedef struct _Parameter {
  91. ParameterHints hints;
  92. const char* name;
  93. const char* unit;
  94. ParameterRanges ranges;
  95. uint32_t scalePointCount;
  96. ParameterScalePoint* scalePoints;
  97. } Parameter;
  98. typedef struct _MidiEvent {
  99. uint8_t port;
  100. uint32_t time;
  101. uint8_t data[4];
  102. uint8_t size;
  103. } MidiEvent;
  104. typedef struct _MidiProgram {
  105. uint32_t bank;
  106. uint32_t program;
  107. const char* name;
  108. } MidiProgram;
  109. typedef struct _TimeInfoBBT {
  110. bool valid;
  111. int32_t bar; //!< current bar
  112. int32_t beat; //!< current beat-within-bar
  113. int32_t tick; //!< current tick-within-beat
  114. double barStartTick;
  115. float beatsPerBar; //!< time signature "numerator"
  116. float beatType; //!< time signature "denominator"
  117. double ticksPerBeat;
  118. double beatsPerMinute;
  119. } TimeInfoBBT;
  120. typedef struct _TimeInfo {
  121. bool playing;
  122. uint64_t frame;
  123. uint64_t usecs;
  124. TimeInfoBBT bbt;
  125. } TimeInfo;
  126. typedef struct _HostDescriptor {
  127. HostHandle handle;
  128. const char* resource_dir;
  129. const char* ui_name;
  130. uint32_t (*get_buffer_size)(HostHandle handle);
  131. double (*get_sample_rate)(HostHandle handle);
  132. const TimeInfo* (*get_time_info)(HostHandle handle);
  133. bool (*write_midi_event)(HostHandle handle, const MidiEvent* event);
  134. void (*ui_parameter_changed)(HostHandle handle, uint32_t index, float value);
  135. void (*ui_midi_program_changed)(HostHandle handle, uint8_t channel, uint32_t bank, uint32_t program);
  136. void (*ui_custom_data_changed)(HostHandle handle, const char* key, const char* value);
  137. void (*ui_closed)(HostHandle handle);
  138. const char* (*ui_open_file)(HostHandle handle, bool isDir, const char* title, const char* filter);
  139. const char* (*ui_save_file)(HostHandle handle, bool isDir, const char* title, const char* filter);
  140. intptr_t (*dispatcher)(HostHandle handle, HostDispatcherOpcode opcode, int32_t index, intptr_t value, void* ptr);
  141. } HostDescriptor;
  142. typedef struct _PluginDescriptor {
  143. const PluginCategory category;
  144. const PluginHints hints;
  145. const uint32_t audioIns;
  146. const uint32_t audioOuts;
  147. const uint32_t midiIns;
  148. const uint32_t midiOuts;
  149. const uint32_t parameterIns;
  150. const uint32_t parameterOuts;
  151. const char* const name;
  152. const char* const label;
  153. const char* const maker;
  154. const char* const copyright;
  155. PluginHandle (*instantiate)(const struct _PluginDescriptor* _this_, HostDescriptor* host);
  156. void (*cleanup)(PluginHandle handle);
  157. uint32_t (*get_parameter_count)(PluginHandle handle);
  158. const Parameter* (*get_parameter_info)(PluginHandle handle, uint32_t index);
  159. float (*get_parameter_value)(PluginHandle handle, uint32_t index);
  160. const char* (*get_parameter_text)(PluginHandle handle, uint32_t index);
  161. uint32_t (*get_midi_program_count)(PluginHandle handle);
  162. const MidiProgram* (*get_midi_program_info)(PluginHandle handle, uint32_t index);
  163. void (*set_parameter_value)(PluginHandle handle, uint32_t index, float value);
  164. void (*set_midi_program)(PluginHandle handle, uint8_t channel, uint32_t bank, uint32_t program);
  165. void (*set_custom_data)(PluginHandle handle, const char* key, const char* value);
  166. void (*ui_show)(PluginHandle handle, bool show);
  167. void (*ui_idle)(PluginHandle handle);
  168. void (*ui_set_parameter_value)(PluginHandle handle, uint32_t index, float value);
  169. void (*ui_set_midi_program)(PluginHandle handle, uint8_t channel, uint32_t bank, uint32_t program);
  170. void (*ui_set_custom_data)(PluginHandle handle, const char* key, const char* value);
  171. void (*activate)(PluginHandle handle);
  172. void (*deactivate)(PluginHandle handle);
  173. void (*process)(PluginHandle handle, float** inBuffer, float** outBuffer, uint32_t frames, uint32_t midiEventCount, const MidiEvent* midiEvents);
  174. char* (*get_state)(PluginHandle handle);
  175. void (*set_state)(PluginHandle handle, const char* data);
  176. intptr_t (*dispatcher)(PluginHandle handle, PluginDispatcherOpcode opcode, int32_t index, intptr_t value, void* ptr);
  177. } PluginDescriptor;
  178. // -----------------------------------------------------------------------
  179. // Register plugin
  180. void carla_register_native_plugin(const PluginDescriptor* desc);
  181. // Simple plugins
  182. void carla_register_native_plugin_bypass();
  183. void carla_register_native_plugin_lfo();
  184. void carla_register_native_plugin_midiSequencer();
  185. void carla_register_native_plugin_midiSplit();
  186. void carla_register_native_plugin_midiThrough();
  187. void carla_register_native_plugin_midiTranspose();
  188. void carla_register_native_plugin_nekofilter();
  189. void carla_register_native_plugin_sunvoxfile();
  190. #ifndef BUILD_BRIDGE
  191. // Carla
  192. void carla_register_native_plugin_carla();
  193. #endif
  194. #ifdef WANT_AUDIOFILE
  195. // AudioFile
  196. void carla_register_native_plugin_audiofile();
  197. #endif
  198. #ifdef WANT_MIDIFILE
  199. // MidiFile
  200. void carla_register_native_plugin_midifile();
  201. #endif
  202. #ifdef WANT_OPENGL
  203. // DISTRHO plugins (OpenGL)
  204. void carla_register_native_plugin_3BandEQ();
  205. void carla_register_native_plugin_3BandSplitter();
  206. void carla_register_native_plugin_Nekobi();
  207. void carla_register_native_plugin_PingPongPan();
  208. void carla_register_native_plugin_StereoEnhancer();
  209. #endif
  210. // DISTRHO plugins (Qt)
  211. void carla_register_native_plugin_Notes();
  212. #ifdef WANT_ZYNADDSUBFX
  213. // ZynAddSubFX
  214. void carla_register_native_plugin_zynaddsubfx();
  215. #endif
  216. // -----------------------------------------------------------------------
  217. /**@}*/
  218. #ifdef __cplusplus
  219. } // extern "C"
  220. #endif
  221. #endif // __CARLA_NATIVE_H__