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.

277 lines
11KB

  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. NATIVE_PLUGIN_CATEGORY_NONE = 0, /** Null plugin category. */
  37. NATIVE_PLUGIN_CATEGORY_SYNTH = 1, /** A synthesizer or generator. */
  38. NATIVE_PLUGIN_CATEGORY_DELAY = 2, /** A delay or reverberator. */
  39. NATIVE_PLUGIN_CATEGORY_EQ = 3, /** An equalizer. */
  40. NATIVE_PLUGIN_CATEGORY_FILTER = 4, /** A filter. */
  41. NATIVE_PLUGIN_CATEGORY_DISTORTION = 5, /** A distortion plugin. */
  42. NATIVE_PLUGIN_CATEGORY_DYNAMICS = 6, /** A 'dynamic' plugin (amplifier, compressor, gate, etc). */
  43. NATIVE_PLUGIN_CATEGORY_MODULATOR = 7, /** A 'modulator' plugin (chorus, flanger, phaser, etc). */
  44. NATIVE_PLUGIN_CATEGORY_UTILITY = 8, /** An 'utility' plugin (analyzer, converter, mixer, etc). */
  45. NATIVE_PLUGIN_CATEGORY_OTHER = 9 /** Misc plugin (used to check if the plugin has a category). */
  46. } NativePluginCategory;
  47. typedef enum {
  48. NATIVE_PLUGIN_IS_RTSAFE = 1 << 0,
  49. NATIVE_PLUGIN_IS_SYNTH = 1 << 1,
  50. NATIVE_PLUGIN_HAS_UI = 1 << 2,
  51. NATIVE_PLUGIN_NEEDS_FIXED_BUFFERS = 1 << 3,
  52. NATIVE_PLUGIN_NEEDS_UI_MAIN_THREAD = 1 << 4,
  53. NATIVE_PLUGIN_NEEDS_UI_OPEN_SAVE = 1 << 6,
  54. NATIVE_PLUGIN_USES_MULTI_PROGS = 1 << 7, /** has 1 program per midi channel */
  55. NATIVE_PLUGIN_USES_PANNING = 1 << 8, /** uses stereo balance if unset (default) */
  56. NATIVE_PLUGIN_USES_STATE = 1 << 9,
  57. NATIVE_PLUGIN_USES_TIME = 1 << 10,
  58. NATIVE_PLUGIN_USES_PARENT_ID = 1 << 11 /** can set transient hint to parent */
  59. } NativePluginHints;
  60. typedef enum {
  61. NATIVE_PLUGIN_SUPPORTS_NOTHING = 0,
  62. NATIVE_PLUGIN_SUPPORTS_PROGRAM_CHANGES = 1 << 0, /** handles MIDI programs internally instead of host-exposed/exported */
  63. NATIVE_PLUGIN_SUPPORTS_CONTROL_CHANGES = 1 << 1,
  64. NATIVE_PLUGIN_SUPPORTS_CHANNEL_PRESSURE = 1 << 2,
  65. NATIVE_PLUGIN_SUPPORTS_NOTE_AFTERTOUCH = 1 << 3,
  66. NATIVE_PLUGIN_SUPPORTS_PITCHBEND = 1 << 4,
  67. NATIVE_PLUGIN_SUPPORTS_ALL_SOUND_OFF = 1 << 5,
  68. NATIVE_PLUGIN_SUPPORTS_EVERYTHING = (1 << 6)-1
  69. } NativePluginSupports;
  70. typedef enum {
  71. NATIVE_PARAMETER_IS_OUTPUT = 1 << 0,
  72. NATIVE_PARAMETER_IS_ENABLED = 1 << 1,
  73. NATIVE_PARAMETER_IS_AUTOMABLE = 1 << 2,
  74. NATIVE_PARAMETER_IS_BOOLEAN = 1 << 3,
  75. NATIVE_PARAMETER_IS_INTEGER = 1 << 4,
  76. NATIVE_PARAMETER_IS_LOGARITHMIC = 1 << 5,
  77. NATIVE_PARAMETER_USES_SAMPLE_RATE = 1 << 6,
  78. NATIVE_PARAMETER_USES_SCALEPOINTS = 1 << 7
  79. } NativeParameterHints;
  80. typedef enum {
  81. NATIVE_PLUGIN_OPCODE_NULL = 0, /** nothing */
  82. NATIVE_PLUGIN_OPCODE_BUFFER_SIZE_CHANGED = 1, /** uses value */
  83. NATIVE_PLUGIN_OPCODE_SAMPLE_RATE_CHANGED = 2, /** uses opt */
  84. NATIVE_PLUGIN_OPCODE_OFFLINE_CHANGED = 3, /** uses value (0=off, 1=on) */
  85. NATIVE_PLUGIN_OPCODE_UI_NAME_CHANGED = 4, /** uses ptr */
  86. NATIVE_PLUGIN_OPCODE_GET_INTERNAL_HANDLE = 5 /** nothing */
  87. } NativePluginDispatcherOpcode;
  88. typedef enum {
  89. NATIVE_HOST_OPCODE_NULL = 0, /** nothing */
  90. NATIVE_HOST_OPCODE_UPDATE_PARAMETER = 1, /** uses index, -1 for all */
  91. NATIVE_HOST_OPCODE_UPDATE_MIDI_PROGRAM = 2, /** uses index, -1 for all; may use value for channel */
  92. NATIVE_HOST_OPCODE_RELOAD_PARAMETERS = 3, /** nothing */
  93. NATIVE_HOST_OPCODE_RELOAD_MIDI_PROGRAMS = 4, /** nothing */
  94. NATIVE_HOST_OPCODE_RELOAD_ALL = 5, /** nothing */
  95. NATIVE_HOST_OPCODE_UI_UNAVAILABLE = 6, /** nothing */
  96. NATIVE_HOST_OPCODE_HOST_IDLE = 7, /** nothing */
  97. NATIVE_HOST_OPCODE_INTERNAL_PLUGIN = 8 /** nothing */
  98. } NativeHostDispatcherOpcode;
  99. /* ------------------------------------------------------------------------------------------------------------
  100. * base structs */
  101. typedef struct {
  102. const char* label;
  103. float value;
  104. } NativeParameterScalePoint;
  105. typedef struct {
  106. float def;
  107. float min;
  108. float max;
  109. float step;
  110. float stepSmall;
  111. float stepLarge;
  112. } NativeParameterRanges;
  113. #define PARAMETER_RANGES_DEFAULT_STEP 0.01f
  114. #define PARAMETER_RANGES_DEFAULT_STEP_SMALL 0.0001f
  115. #define PARAMETER_RANGES_DEFAULT_STEP_LARGE 0.1f
  116. typedef struct {
  117. NativeParameterHints hints;
  118. const char* name;
  119. const char* unit;
  120. NativeParameterRanges ranges;
  121. uint32_t scalePointCount;
  122. const NativeParameterScalePoint* scalePoints;
  123. } NativeParameter;
  124. typedef struct {
  125. uint32_t time;
  126. uint8_t port;
  127. uint8_t size;
  128. uint8_t data[4];
  129. } NativeMidiEvent;
  130. typedef struct {
  131. uint32_t bank;
  132. uint32_t program;
  133. const char* name;
  134. } NativeMidiProgram;
  135. typedef struct {
  136. bool valid;
  137. int32_t bar; /** current bar */
  138. int32_t beat; /** current beat-within-bar */
  139. double tick; /** current tick-within-beat */
  140. double barStartTick;
  141. float beatsPerBar; /** time signature "numerator" */
  142. float beatType; /** time signature "denominator" */
  143. double ticksPerBeat;
  144. double beatsPerMinute;
  145. } NativeTimeInfoBBT;
  146. typedef struct {
  147. bool playing;
  148. uint64_t frame;
  149. uint64_t usecs;
  150. NativeTimeInfoBBT bbt;
  151. } NativeTimeInfo;
  152. /* ------------------------------------------------------------------------------------------------------------
  153. * HostDescriptor */
  154. typedef struct {
  155. NativeHostHandle handle;
  156. const char* resourceDir;
  157. const char* uiName;
  158. uintptr_t uiParentId;
  159. uint32_t (*get_buffer_size)(NativeHostHandle handle);
  160. double (*get_sample_rate)(NativeHostHandle handle);
  161. bool (*is_offline)(NativeHostHandle handle);
  162. const NativeTimeInfo* (*get_time_info)(NativeHostHandle handle);
  163. bool (*write_midi_event)(NativeHostHandle handle, const NativeMidiEvent* event);
  164. void (*ui_parameter_changed)(NativeHostHandle handle, uint32_t index, float value);
  165. void (*ui_midi_program_changed)(NativeHostHandle handle, uint8_t channel, uint32_t bank, uint32_t program);
  166. void (*ui_custom_data_changed)(NativeHostHandle handle, const char* key, const char* value);
  167. void (*ui_closed)(NativeHostHandle handle);
  168. const char* (*ui_open_file)(NativeHostHandle handle, bool isDir, const char* title, const char* filter);
  169. const char* (*ui_save_file)(NativeHostHandle handle, bool isDir, const char* title, const char* filter);
  170. intptr_t (*dispatcher)(NativeHostHandle handle, NativeHostDispatcherOpcode opcode, int32_t index, intptr_t value, void* ptr, float opt);
  171. } NativeHostDescriptor;
  172. /* ------------------------------------------------------------------------------------------------------------
  173. * PluginDescriptor */
  174. typedef struct _NativePluginDescriptor {
  175. const NativePluginCategory category;
  176. const NativePluginHints hints;
  177. const NativePluginSupports supports;
  178. const uint32_t audioIns;
  179. const uint32_t audioOuts;
  180. const uint32_t midiIns;
  181. const uint32_t midiOuts;
  182. const uint32_t paramIns;
  183. const uint32_t paramOuts;
  184. const char* const name;
  185. const char* const label;
  186. const char* const maker;
  187. const char* const copyright;
  188. NativePluginHandle (*instantiate)(const NativeHostDescriptor* host);
  189. void (*cleanup)(NativePluginHandle handle);
  190. uint32_t (*get_parameter_count)(NativePluginHandle handle);
  191. const NativeParameter* (*get_parameter_info)(NativePluginHandle handle, uint32_t index);
  192. float (*get_parameter_value)(NativePluginHandle handle, uint32_t index);
  193. uint32_t (*get_midi_program_count)(NativePluginHandle handle);
  194. const NativeMidiProgram* (*get_midi_program_info)(NativePluginHandle handle, uint32_t index);
  195. void (*set_parameter_value)(NativePluginHandle handle, uint32_t index, float value);
  196. void (*set_midi_program)(NativePluginHandle handle, uint8_t channel, uint32_t bank, uint32_t program);
  197. void (*set_custom_data)(NativePluginHandle handle, const char* key, const char* value);
  198. void (*ui_show)(NativePluginHandle handle, bool show);
  199. void (*ui_idle)(NativePluginHandle handle);
  200. void (*ui_set_parameter_value)(NativePluginHandle handle, uint32_t index, float value);
  201. void (*ui_set_midi_program)(NativePluginHandle handle, uint8_t channel, uint32_t bank, uint32_t program);
  202. void (*ui_set_custom_data)(NativePluginHandle handle, const char* key, const char* value);
  203. void (*activate)(NativePluginHandle handle);
  204. void (*deactivate)(NativePluginHandle handle);
  205. void (*process)(NativePluginHandle handle, float** inBuffer, float** outBuffer, uint32_t frames, const NativeMidiEvent* midiEvents, uint32_t midiEventCount);
  206. char* (*get_state)(NativePluginHandle handle);
  207. void (*set_state)(NativePluginHandle handle, const char* data);
  208. intptr_t (*dispatcher)(NativePluginHandle handle, NativePluginDispatcherOpcode opcode, int32_t index, intptr_t value, void* ptr, float opt);
  209. } NativePluginDescriptor;
  210. /* ------------------------------------------------------------------------------------------------------------
  211. * Register plugin */
  212. /** Implemented by host */
  213. extern void carla_register_native_plugin(const NativePluginDescriptor* desc);
  214. /** Called once on host init */
  215. void carla_register_all_native_plugins(void);
  216. /** Get meta-data only */
  217. const NativePluginDescriptor* carla_get_native_plugins_data(uint32_t* count);
  218. /* ------------------------------------------------------------------------------------------------------------ */
  219. /**@}*/
  220. #ifdef __cplusplus
  221. } /* extern "C" */
  222. #endif
  223. #endif /* CARLA_NATIVE_H_INCLUDED */