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.

272 lines
9.2KB

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