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.

281 lines
10KB

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