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.

334 lines
14KB

  1. /*
  2. * Carla Native Plugin API
  3. * Copyright (C) 2012-2023 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. #include "CarlaDefines.h"
  20. #include <stddef.h>
  21. #include <stdint.h>
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  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. NATIVE_PLUGIN_HAS_INLINE_DISPLAY = 1 << 12,
  60. NATIVE_PLUGIN_USES_CONTROL_VOLTAGE = 1 << 13,
  61. NATIVE_PLUGIN_REQUESTS_IDLE = 1 << 15,
  62. NATIVE_PLUGIN_USES_UI_SIZE = 1 << 16
  63. } NativePluginHints;
  64. typedef enum {
  65. NATIVE_PLUGIN_SUPPORTS_NOTHING = 0,
  66. NATIVE_PLUGIN_SUPPORTS_PROGRAM_CHANGES = 1 << 0, /** handles MIDI programs internally instead of host-exposed/exported */
  67. NATIVE_PLUGIN_SUPPORTS_CONTROL_CHANGES = 1 << 1,
  68. NATIVE_PLUGIN_SUPPORTS_CHANNEL_PRESSURE = 1 << 2,
  69. NATIVE_PLUGIN_SUPPORTS_NOTE_AFTERTOUCH = 1 << 3,
  70. NATIVE_PLUGIN_SUPPORTS_PITCHBEND = 1 << 4,
  71. NATIVE_PLUGIN_SUPPORTS_ALL_SOUND_OFF = 1 << 5,
  72. NATIVE_PLUGIN_SUPPORTS_EVERYTHING = (1 << 6)-1
  73. } NativePluginSupports;
  74. typedef enum {
  75. NATIVE_PARAMETER_DESIGNATION_NONE = 0,
  76. NATIVE_PARAMETER_DESIGNATION_ENABLED
  77. } NativeParameterDesignations;
  78. typedef enum {
  79. NATIVE_PARAMETER_IS_OUTPUT = 1 << 0,
  80. NATIVE_PARAMETER_IS_ENABLED = 1 << 1,
  81. NATIVE_PARAMETER_IS_AUTOMATABLE = 1 << 2,
  82. NATIVE_PARAMETER_IS_AUTOMABLE = NATIVE_PARAMETER_IS_AUTOMATABLE, // there was a typo..
  83. NATIVE_PARAMETER_IS_BOOLEAN = 1 << 3,
  84. NATIVE_PARAMETER_IS_INTEGER = 1 << 4,
  85. NATIVE_PARAMETER_IS_LOGARITHMIC = 1 << 5,
  86. NATIVE_PARAMETER_USES_SAMPLE_RATE = 1 << 6,
  87. NATIVE_PARAMETER_USES_SCALEPOINTS = 1 << 7,
  88. NATIVE_PARAMETER_USES_DESIGNATION = 1 << 8
  89. } NativeParameterHints;
  90. typedef enum {
  91. NATIVE_PLUGIN_OPCODE_NULL = 0, /** nothing */
  92. NATIVE_PLUGIN_OPCODE_BUFFER_SIZE_CHANGED = 1, /** uses value */
  93. NATIVE_PLUGIN_OPCODE_SAMPLE_RATE_CHANGED = 2, /** uses opt */
  94. NATIVE_PLUGIN_OPCODE_OFFLINE_CHANGED = 3, /** uses value (0=off, 1=on) */
  95. NATIVE_PLUGIN_OPCODE_UI_NAME_CHANGED = 4, /** uses ptr */
  96. NATIVE_PLUGIN_OPCODE_GET_INTERNAL_HANDLE = 5, /** nothing */
  97. NATIVE_PLUGIN_OPCODE_IDLE = 6, /** nothing */
  98. NATIVE_PLUGIN_OPCODE_UI_MIDI_EVENT = 7, /** uses ptr */
  99. NATIVE_PLUGIN_OPCODE_HOST_USES_EMBED = 8, /** nothing */
  100. NATIVE_PLUGIN_OPCODE_HOST_OPTION = 9 /** uses index, value and ptr */
  101. } NativePluginDispatcherOpcode;
  102. typedef enum {
  103. NATIVE_HOST_OPCODE_NULL = 0, /** nothing */
  104. NATIVE_HOST_OPCODE_UPDATE_PARAMETER = 1, /** uses index, -1 for all */
  105. NATIVE_HOST_OPCODE_UPDATE_MIDI_PROGRAM = 2, /** uses index, -1 for all; may use value for channel */
  106. NATIVE_HOST_OPCODE_RELOAD_PARAMETERS = 3, /** nothing */
  107. NATIVE_HOST_OPCODE_RELOAD_MIDI_PROGRAMS = 4, /** nothing */
  108. NATIVE_HOST_OPCODE_RELOAD_ALL = 5, /** nothing */
  109. NATIVE_HOST_OPCODE_UI_UNAVAILABLE = 6, /** nothing */
  110. NATIVE_HOST_OPCODE_HOST_IDLE = 7, /** nothing */
  111. NATIVE_HOST_OPCODE_INTERNAL_PLUGIN = 8, /** nothing */
  112. NATIVE_HOST_OPCODE_QUEUE_INLINE_DISPLAY = 9, /** nothing */
  113. NATIVE_HOST_OPCODE_UI_TOUCH_PARAMETER = 10, /** uses index, value as bool */
  114. NATIVE_HOST_OPCODE_REQUEST_IDLE = 11, /** nothing */
  115. NATIVE_HOST_OPCODE_GET_FILE_PATH = 12, /** uses ptr as string for file type */
  116. NATIVE_HOST_OPCODE_UI_RESIZE = 13, /** uses index and value */
  117. NATIVE_HOST_OPCODE_PREVIEW_BUFFER_DATA = 14 /** uses index as type, value as size, and ptr */
  118. } NativeHostDispatcherOpcode;
  119. /* ------------------------------------------------------------------------------------------------------------
  120. * base structs */
  121. typedef struct {
  122. const char* label;
  123. float value;
  124. } NativeParameterScalePoint;
  125. typedef struct {
  126. float def;
  127. float min;
  128. float max;
  129. float step;
  130. float stepSmall;
  131. float stepLarge;
  132. } NativeParameterRanges;
  133. #define PARAMETER_RANGES_DEFAULT_STEP 0.01f
  134. #define PARAMETER_RANGES_DEFAULT_STEP_SMALL 0.0001f
  135. #define PARAMETER_RANGES_DEFAULT_STEP_LARGE 0.1f
  136. typedef struct {
  137. NativeParameterHints hints;
  138. const char* name;
  139. const char* unit;
  140. NativeParameterRanges ranges;
  141. uint32_t scalePointCount;
  142. const NativeParameterScalePoint* scalePoints;
  143. const char* comment;
  144. const char* groupName;
  145. uint designation;
  146. } NativeParameter;
  147. typedef struct {
  148. uint32_t time;
  149. uint8_t port;
  150. uint8_t size;
  151. uint8_t data[4];
  152. } NativeMidiEvent;
  153. typedef struct {
  154. uint32_t bank;
  155. uint32_t program;
  156. const char* name;
  157. } NativeMidiProgram;
  158. typedef struct {
  159. bool valid;
  160. int32_t bar; /** current bar */
  161. int32_t beat; /** current beat-within-bar */
  162. double tick; /** current tick-within-beat */
  163. double barStartTick;
  164. float beatsPerBar; /** time signature "numerator" */
  165. float beatType; /** time signature "denominator" */
  166. double ticksPerBeat;
  167. double beatsPerMinute;
  168. } NativeTimeInfoBBT;
  169. typedef struct {
  170. bool playing;
  171. uint64_t frame;
  172. uint64_t usecs;
  173. NativeTimeInfoBBT bbt;
  174. } NativeTimeInfo;
  175. typedef struct {
  176. unsigned char* data;
  177. int width;
  178. int height;
  179. int stride;
  180. } NativeInlineDisplayImageSurface;
  181. typedef struct {
  182. float minimum, maximum;
  183. } NativePortRange;
  184. /* ------------------------------------------------------------------------------------------------------------
  185. * HostDescriptor */
  186. typedef struct {
  187. NativeHostHandle handle;
  188. const char* resourceDir;
  189. const char* uiName;
  190. uintptr_t uiParentId;
  191. uint32_t (*get_buffer_size)(NativeHostHandle handle);
  192. double (*get_sample_rate)(NativeHostHandle handle);
  193. bool (*is_offline)(NativeHostHandle handle);
  194. const NativeTimeInfo* (*get_time_info)(NativeHostHandle handle);
  195. bool (*write_midi_event)(NativeHostHandle handle, const NativeMidiEvent* event);
  196. void (*ui_parameter_changed)(NativeHostHandle handle, uint32_t index, float value);
  197. void (*ui_midi_program_changed)(NativeHostHandle handle, uint8_t channel, uint32_t bank, uint32_t program);
  198. void (*ui_custom_data_changed)(NativeHostHandle handle, const char* key, const char* value);
  199. void (*ui_closed)(NativeHostHandle handle);
  200. const char* (*ui_open_file)(NativeHostHandle handle, bool isDir, const char* title, const char* filter);
  201. const char* (*ui_save_file)(NativeHostHandle handle, bool isDir, const char* title, const char* filter);
  202. intptr_t (*dispatcher)(NativeHostHandle handle,
  203. NativeHostDispatcherOpcode opcode, int32_t index, intptr_t value, void* ptr, float opt);
  204. } NativeHostDescriptor;
  205. /* ------------------------------------------------------------------------------------------------------------
  206. * PluginDescriptor */
  207. typedef struct _NativePluginDescriptor {
  208. const NativePluginCategory category;
  209. const NativePluginHints hints;
  210. const NativePluginSupports supports;
  211. const uint32_t audioIns;
  212. const uint32_t audioOuts;
  213. const uint32_t midiIns;
  214. const uint32_t midiOuts;
  215. const uint32_t paramIns;
  216. const uint32_t paramOuts;
  217. const char* const name;
  218. const char* const label;
  219. const char* const maker;
  220. const char* const copyright;
  221. NativePluginHandle (*instantiate)(const NativeHostDescriptor* host);
  222. void (*cleanup)(NativePluginHandle handle);
  223. uint32_t (*get_parameter_count)(NativePluginHandle handle);
  224. const NativeParameter* (*get_parameter_info)(NativePluginHandle handle, uint32_t index);
  225. float (*get_parameter_value)(NativePluginHandle handle, uint32_t index);
  226. uint32_t (*get_midi_program_count)(NativePluginHandle handle);
  227. const NativeMidiProgram* (*get_midi_program_info)(NativePluginHandle handle, uint32_t index);
  228. void (*set_parameter_value)(NativePluginHandle handle, uint32_t index, float value);
  229. void (*set_midi_program)(NativePluginHandle handle, uint8_t channel, uint32_t bank, uint32_t program);
  230. void (*set_custom_data)(NativePluginHandle handle, const char* key, const char* value);
  231. void (*ui_show)(NativePluginHandle handle, bool show);
  232. void (*ui_idle)(NativePluginHandle handle);
  233. void (*ui_set_parameter_value)(NativePluginHandle handle, uint32_t index, float value);
  234. void (*ui_set_midi_program)(NativePluginHandle handle, uint8_t channel, uint32_t bank, uint32_t program);
  235. void (*ui_set_custom_data)(NativePluginHandle handle, const char* key, const char* value);
  236. void (*activate)(NativePluginHandle handle);
  237. void (*deactivate)(NativePluginHandle handle);
  238. /* FIXME for v3.0, use const for the input buffer */
  239. void (*process)(NativePluginHandle handle,
  240. float** inBuffer, float** outBuffer, uint32_t frames,
  241. const NativeMidiEvent* midiEvents, uint32_t midiEventCount);
  242. char* (*get_state)(NativePluginHandle handle);
  243. void (*set_state)(NativePluginHandle handle, const char* data);
  244. intptr_t (*dispatcher)(NativePluginHandle handle,
  245. NativePluginDispatcherOpcode opcode, int32_t index, intptr_t value, void* ptr, float opt);
  246. /* placed at the end for backwards compatibility. only valid if NATIVE_PLUGIN_HAS_INLINE_DISPLAY is set */
  247. const NativeInlineDisplayImageSurface* (*render_inline_display)(NativePluginHandle handle,
  248. uint32_t width, uint32_t height);
  249. /* placed at the end for backwards compatibility. only valid if NATIVE_PLUGIN_USES_CONTROL_VOLTAGE is set */
  250. const uint32_t cvIns;
  251. const uint32_t cvOuts;
  252. const char* (*get_buffer_port_name)(NativePluginHandle handle, uint32_t index, bool isOutput);
  253. const NativePortRange* (*get_buffer_port_range)(NativePluginHandle handle, uint32_t index, bool isOutput);
  254. /* placed at the end for backwards compatibility. only valid if NATIVE_PLUGIN_USES_UI_SIZE is set */
  255. uint16_t ui_width, ui_height;
  256. } NativePluginDescriptor;
  257. /* ------------------------------------------------------------------------------------------------------------
  258. * Register plugin */
  259. /** Implemented by host */
  260. extern void carla_register_native_plugin(const NativePluginDescriptor* desc);
  261. /** Called once on host init */
  262. void carla_register_all_native_plugins(void);
  263. /** Get meta-data only */
  264. CARLA_API_EXPORT
  265. const NativePluginDescriptor* carla_get_native_plugins_data(uint32_t* count);
  266. /* ------------------------------------------------------------------------------------------------------------ */
  267. /**@}*/
  268. #ifdef __cplusplus
  269. } /* extern "C" */
  270. #endif
  271. #endif /* CARLA_NATIVE_H_INCLUDED */