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.

623 lines
18KB

  1. /*
  2. * Carla Backend API
  3. * Copyright (C) 2011-2013 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * 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 COPYING file
  16. */
  17. #ifndef __CARLA_BACKEND_HPP__
  18. #define __CARLA_BACKEND_HPP__
  19. // TODO - remove ifdef's when Carla stabilizes
  20. #include "carla_defines.hpp"
  21. #include <cstdint>
  22. #include <cstdlib>
  23. #define CARLA_BACKEND_START_NAMESPACE namespace CarlaBackend {
  24. #define CARLA_BACKEND_END_NAMESPACE }
  25. #define CARLA_BACKEND_USE_NAMESPACE using namespace CarlaBackend;
  26. #define STR_MAX 0xFF
  27. CARLA_BACKEND_START_NAMESPACE
  28. /*!
  29. * @defgroup CarlaBackendAPI Carla Backend API
  30. *
  31. * The Carla Backend API
  32. *
  33. * @{
  34. */
  35. const unsigned int MAX_DEFAULT_PLUGINS = 99; //!< Maximum default number of loadable plugins
  36. const unsigned int MAX_RACK_PLUGINS = 16; //!< Maximum number of loadable plugins in rack mode
  37. const unsigned int MAX_PATCHBAY_PLUGINS = 999; //!< Maximum number of loadable plugins in patchbay mode
  38. const unsigned int MAX_DEFAULT_PARAMETERS = 200; //!< Maximum default number of parameters allowed.\see OPTION_MAX_PARAMETERS
  39. /*!
  40. * @defgroup PluginHints Plugin Hints
  41. *
  42. * Various plugin hints.
  43. * \see CarlaPlugin::hints()
  44. * @{
  45. */
  46. #ifndef BUILD_BRIDGE
  47. const unsigned int PLUGIN_IS_BRIDGE = 0x001; //!< Plugin is a bridge (ie, BridgePlugin). This hint is required because "bridge" itself is not a plugin type.
  48. #endif
  49. const unsigned int PLUGIN_IS_RTSAFE = 0x002; //!< Plugin is hard real-time safe.
  50. const unsigned int PLUGIN_IS_SYNTH = 0x004; //!< Plugin is a synthesizer (produces sound).
  51. const unsigned int PLUGIN_HAS_GUI = 0x010; //!< Plugin has its own custom GUI.
  52. const unsigned int PLUGIN_USES_CHUNKS = 0x020; //!< Plugin uses chunks to save internal data.\see CarlaPlugin::chunkData()
  53. #ifndef BUILD_BRIDGE
  54. const unsigned int PLUGIN_USES_SINGLE_THREAD = 0x040; //!< Plugin needs a single thread for both DSP and UI events.
  55. #endif
  56. const unsigned int PLUGIN_CAN_DRYWET = 0x100; //!< Plugin can make use of Dry/Wet controls.
  57. const unsigned int PLUGIN_CAN_VOLUME = 0x200; //!< Plugin can make use of Volume controls.
  58. const unsigned int PLUGIN_CAN_BALANCE = 0x400; //!< Plugin can make use of Left & Right Balance controls.
  59. const unsigned int PLUGIN_CAN_FORCE_STEREO = 0x800; //!< Plugin can be used in forced-stereo mode.
  60. /**@}*/
  61. /*!
  62. * @defgroup ParameterHints Parameter Hints
  63. *
  64. * Various parameter hints.
  65. * \see CarlaPlugin::parameterData()
  66. * @{
  67. */
  68. const unsigned int PARAMETER_IS_BOOLEAN = 0x01; //!< Parameter value is always a boolean (always at minimum or maximum range).
  69. const unsigned int PARAMETER_IS_INTEGER = 0x02; //!< Parameter value is always an integer.
  70. const unsigned int PARAMETER_IS_LOGARITHMIC = 0x04; //!< Parameter is logarithmic.
  71. const unsigned int PARAMETER_IS_ENABLED = 0x08; //!< Parameter is enabled and will be shown in the host built-in editor.
  72. const unsigned int PARAMETER_IS_AUTOMABLE = 0x10; //!< Parameter is automable (realtime safe)
  73. const unsigned int PARAMETER_USES_SAMPLERATE = 0x20; //!< Parameter needs sample rate to work (value and ranges are multiplied by SR, and must be divided by SR on save).
  74. const unsigned int PARAMETER_USES_SCALEPOINTS = 0x40; //!< Parameter uses scalepoints to define internal values in a meaninful way.
  75. const unsigned int PARAMETER_USES_CUSTOM_TEXT = 0x80; //!< Parameter uses custom text for displaying its value.\see CarlaPlugin::getParameterText()
  76. /**@}*/
  77. #if 0
  78. /*!
  79. * @defgroup CustomDataTypes Custom Data types
  80. *
  81. * The type defines how the \param value in CustomData is stored.
  82. *
  83. * Types are valid URIs.\n
  84. * Any non-string, non-simple type (not integral) is saved in a base64 encoded format.
  85. */
  86. const char* const CUSTOM_DATA_INVALID = nullptr; //!< Null/Invalid data.
  87. const char* const CUSTOM_DATA_CHUNK = "http://kxstudio.sf.net/ns/carla/chunk"; //!< Carla Chunk
  88. const char* const CUSTOM_DATA_STRING = "http://kxstudio.sf.net/ns/carla/string"; //!< Carla String
  89. /**@}*/
  90. #endif
  91. #if 0
  92. /*!
  93. * @defgroup BridgeMessages Bridge Messages
  94. *
  95. * Various bridge related messages, used as configure(<message>, value).
  96. * \note This is for internal use only.
  97. *
  98. * TODO: Review these, may not be needed anymore
  99. * @{
  100. */
  101. const char* const CARLA_BRIDGE_MSG_HIDE_GUI = "CarlaBridgeHideGUI"; //!< Plugin -> Host call, tells host GUI is now hidden
  102. const char* const CARLA_BRIDGE_MSG_SAVED = "CarlaBridgeSaved"; //!< Plugin -> Host call, tells host state is saved
  103. const char* const CARLA_BRIDGE_MSG_SAVE_NOW = "CarlaBridgeSaveNow"; //!< Host -> Plugin call, tells plugin to save state now
  104. const char* const CARLA_BRIDGE_MSG_SET_CHUNK = "CarlaBridgeSetChunk"; //!< Host -> Plugin call, tells plugin to set chunk in file \a value
  105. const char* const CARLA_BRIDGE_MSG_SET_CUSTOM = "CarlaBridgeSetCustom"; //!< Host -> Plugin call, tells plugin to set a custom data set using \a value ("type·key·rvalue").\n If \a type is 'chunk' or 'binary' \a rvalue refers to chunk file.
  106. /**@}*/
  107. #endif
  108. /*!
  109. * The binary type of a plugin.
  110. */
  111. enum BinaryType {
  112. BINARY_NONE = 0, //!< Null binary type.
  113. BINARY_POSIX32 = 1, //!< POSIX 32bit.
  114. BINARY_POSIX64 = 2, //!< POSIX 64bit.
  115. BINARY_WIN32 = 3, //!< Windows 32bit.
  116. BINARY_WIN64 = 4, //!< Windows 64bit.
  117. BINARY_OTHER = 5 //!< Other.
  118. };
  119. /*!
  120. * All the available plugin types, as provided by subclasses of CarlaPlugin.\n
  121. * Some plugin classes might provide more than 1 plugin type.
  122. */
  123. enum PluginType {
  124. PLUGIN_NONE = 0, //!< Null plugin type.
  125. #ifndef BUILD_BRIDGE
  126. PLUGIN_INTERNAL = 1, //!< Internal plugin.\see NativePlugin
  127. #endif
  128. PLUGIN_LADSPA = 2, //!< LADSPA plugin.\see LadspaPlugin
  129. PLUGIN_DSSI = 3, //!< DSSI plugin.\see DssiPlugin
  130. PLUGIN_LV2 = 4, //!< LV2 plugin.\see Lv2Plugin
  131. PLUGIN_VST = 5, //!< VST plugin.\see VstPlugin
  132. #ifndef BUILD_BRIDGE
  133. PLUGIN_GIG = 6, //!< GIG sound kit, implemented via LinuxSampler.\see LinuxSamplerPlugin
  134. PLUGIN_SF2 = 7, //!< SF2 sound kit (aka SoundFont), implemented via FluidSynth.\see FluidSynthPlugin
  135. PLUGIN_SFZ = 8 //!< SFZ sound kit, implemented via LinuxSampler.\see LinuxSamplerPlugin
  136. #endif
  137. };
  138. /*!
  139. * Plugin category, describing the funtionality of a plugin.\n
  140. * When a plugin fails to tell his own category, one is atributted to it based on its name.
  141. */
  142. enum PluginCategory {
  143. PLUGIN_CATEGORY_NONE = 0, //!< Null plugin category.
  144. PLUGIN_CATEGORY_SYNTH = 1, //!< A synthesizer or generator.
  145. PLUGIN_CATEGORY_DELAY = 2, //!< A delay or reverberator.
  146. PLUGIN_CATEGORY_EQ = 3, //!< An equalizer.
  147. PLUGIN_CATEGORY_FILTER = 4, //!< A filter.
  148. PLUGIN_CATEGORY_DYNAMICS = 5, //!< A 'dynamic' plugin (amplifier, compressor, gate, etc).
  149. PLUGIN_CATEGORY_MODULATOR = 6, //!< A 'modulator' plugin (chorus, flanger, phaser, etc).
  150. PLUGIN_CATEGORY_UTILITY = 7, //!< An 'utility' plugin (analyzer, converter, mixer, etc).
  151. PLUGIN_CATEGORY_OTHER = 8 //!< Misc plugin (used to check if the plugin has a category).
  152. };
  153. /*!
  154. * Plugin parameter type.
  155. */
  156. enum ParameterType {
  157. PARAMETER_UNKNOWN = 0, //!< Null parameter type.
  158. PARAMETER_INPUT = 1, //!< Input parameter.
  159. PARAMETER_OUTPUT = 2, //!< Ouput parameter.
  160. PARAMETER_LATENCY = 3, //!< Special latency parameter, used in LADSPA, DSSI and LV2 plugins.
  161. PARAMETER_SAMPLE_RATE = 4, //!< Special sample-rate parameter, used in LADSPA, DSSI and LV2 plugins.
  162. #ifdef WANT_LV2
  163. PARAMETER_LV2_FREEWHEEL = 5, //!< Special LV2 Plugin parameter used to report freewheel (offline) mode.
  164. PARAMETER_LV2_TIME = 6 //!< Special LV2 Plugin parameter used to report time information.
  165. #endif
  166. };
  167. /*!
  168. * Internal parameter indexes.\n
  169. * These are special parameters used internally, plugins do not know about their existence.
  170. */
  171. enum InternalParametersIndex {
  172. PARAMETER_NULL = -1, //!< Null parameter.
  173. PARAMETER_ACTIVE = -2, //!< Active parameter, can only be 'true' or 'false'; default is 'false'.
  174. PARAMETER_DRYWET = -3, //!< Dry/Wet parameter, range 0.0...1.0; default is 1.0.
  175. PARAMETER_VOLUME = -4, //!< Volume parameter, range 0.0...1.27; default is 1.0.
  176. PARAMETER_BALANCE_LEFT = -5, //!< Stereo Balance-Left parameter, range -1.0...1.0; default is -1.0.
  177. PARAMETER_BALANCE_RIGHT = -6, //!< Stereo Balance-Right parameter, range -1.0...1.0; default is 1.0.
  178. PARAMETER_PANNING = -7 //!< Mono Panning parameter, range -1.0...1.0; default is 0.0.
  179. };
  180. /*!
  181. * Options used in the CarlaEngine::setOption() and set_option() calls.\n
  182. * These options must be set before initiliazing or after closing the engine.
  183. */
  184. enum OptionsType {
  185. /*!
  186. * Try to set the current process name.
  187. * \note Not available on all platforms.
  188. */
  189. OPTION_PROCESS_NAME = 0,
  190. /*!
  191. * Set the engine processing mode.\n
  192. * Default is PROCESS_MODE_CONTINUOUS_RACK.
  193. * \see ProcessMode
  194. */
  195. OPTION_PROCESS_MODE = 1,
  196. /*!
  197. * High-Precision processing mode.\n
  198. * When enabled, audio will be processed by blocks of 8 samples at a time, indenpendently of the buffer size.\n
  199. * Default is off.\n
  200. * EXPERIMENTAL AND INCOMPLETE!
  201. */
  202. OPTION_PROCESS_HIGH_PRECISION = 2,
  203. /*!
  204. * Force mono plugins as stereo, by running 2 instances at the same time.
  205. * \note Not supported by all plugins.
  206. */
  207. OPTION_FORCE_STEREO = 3,
  208. /*!
  209. * Use plugin bridges whenever possible.\n
  210. * Default is no, and not recommended at this point!.
  211. * EXPERIMENTAL AND INCOMPLETE!
  212. */
  213. OPTION_PREFER_PLUGIN_BRIDGES = 4,
  214. /*!
  215. * Use OSC-UI bridges whenever possible, otherwise UIs will be handled in the main thread.\n
  216. * Default is yes.
  217. */
  218. OPTION_PREFER_UI_BRIDGES = 5,
  219. #ifdef WANT_DSSI
  220. /*!
  221. * Use (unofficial) dssi-vst chunks feature.\n
  222. * Default is no.
  223. */
  224. OPTION_USE_DSSI_VST_CHUNKS = 6,
  225. #endif
  226. /*!
  227. * Maximum number of parameters allowed.\n
  228. * Default is MAX_DEFAULT_PARAMETERS.
  229. */
  230. OPTION_MAX_PARAMETERS = 7,
  231. /*!
  232. * Timeout value in ms for how much to wait for OSC-Bridges to respond.\n
  233. * Default is 4000 (4 secs).
  234. */
  235. OPTION_OSC_UI_TIMEOUT = 8,
  236. /*!
  237. * Prefered buffer size.
  238. */
  239. OPTION_PREFERRED_BUFFER_SIZE = 9,
  240. /*!
  241. * Prefered sample rate.
  242. */
  243. OPTION_PREFERRED_SAMPLE_RATE = 10,
  244. #ifndef BUILD_BRIDGE
  245. /*!
  246. * Set path to the native plugin bridge executable.\n
  247. * Default unset.
  248. */
  249. OPTION_PATH_BRIDGE_NATIVE = 11,
  250. /*!
  251. * Set path to the POSIX 32bit plugin bridge executable.\n
  252. * Default unset.
  253. */
  254. OPTION_PATH_BRIDGE_POSIX32 = 12,
  255. /*!
  256. * Set path to the POSIX 64bit plugin bridge executable.\n
  257. * Default unset.
  258. */
  259. OPTION_PATH_BRIDGE_POSIX64 = 13,
  260. /*!
  261. * Set path to the Windows 32bit plugin bridge executable.\n
  262. * Default unset.
  263. */
  264. OPTION_PATH_BRIDGE_WIN32 = 14,
  265. /*!
  266. * Set path to the Windows 64bit plugin bridge executable.\n
  267. * Default unset.
  268. */
  269. OPTION_PATH_BRIDGE_WIN64 = 15,
  270. #endif
  271. #ifdef WANT_LV2
  272. /*!
  273. * Set path to the LV2 Gtk2 UI bridge executable.\n
  274. * Default unset.
  275. */
  276. OPTION_PATH_BRIDGE_LV2_GTK2 = 16,
  277. /*!
  278. * Set path to the LV2 Gtk3 UI bridge executable.\n
  279. * Default unset.
  280. */
  281. OPTION_PATH_BRIDGE_LV2_GTK3 = 17,
  282. /*!
  283. * Set path to the LV2 Qt4 UI bridge executable.\n
  284. * Default unset.
  285. */
  286. OPTION_PATH_BRIDGE_LV2_QT4 = 18,
  287. /*!
  288. * Set path to the LV2 Qt5 UI bridge executable.\n
  289. * Default unset.
  290. */
  291. OPTION_PATH_BRIDGE_LV2_QT5 = 19,
  292. /*!
  293. * Set path to the LV2 Cocoa UI bridge executable.\n
  294. * Default unset.
  295. */
  296. OPTION_PATH_BRIDGE_LV2_COCOA = 20,
  297. /*!
  298. * Set path to the LV2 Windows UI bridge executable.\n
  299. * Default unset.
  300. */
  301. OPTION_PATH_BRIDGE_LV2_WINDOWS = 21,
  302. /*!
  303. * Set path to the LV2 X11 UI bridge executable.\n
  304. * Default unset.
  305. */
  306. OPTION_PATH_BRIDGE_LV2_X11 = 22,
  307. #endif
  308. #ifdef WANT_VST
  309. /*!
  310. * Set path to the VST Cocoa UI bridge executable.\n
  311. * Default unset.
  312. */
  313. OPTION_PATH_BRIDGE_VST_COCOA = 23,
  314. /*!
  315. * Set path to the VST HWND UI bridge executable.\n
  316. * Default unset.
  317. */
  318. OPTION_PATH_BRIDGE_VST_HWND = 24,
  319. /*!
  320. * Set path to the VST X11 UI bridge executable.\n
  321. * Default unset.
  322. */
  323. OPTION_PATH_BRIDGE_VST_X11 = 25
  324. #endif
  325. };
  326. /*!
  327. * Opcodes sent from the engine callback to the GUI, as defined by CallbackFunc.
  328. *
  329. * \see CarlaEngine::setCallback()
  330. * \see set_callback_function()
  331. */
  332. enum CallbackType {
  333. /*!
  334. * Debug.\n
  335. * This opcode is undefined and used only for testing purposes.
  336. */
  337. CALLBACK_DEBUG = 0,
  338. /*!
  339. * A parameter has been changed.
  340. *
  341. * \param value1 Parameter index
  342. * \param value3 Value
  343. */
  344. CALLBACK_PARAMETER_VALUE_CHANGED = 1,
  345. /*!
  346. * A parameter's MIDI channel has been changed.
  347. *
  348. * \param value1 Parameter index
  349. * \param value2 MIDI channel
  350. */
  351. CALLBACK_PARAMETER_MIDI_CHANNEL_CHANGED = 2,
  352. /*!
  353. * A parameter's MIDI CC has been changed.
  354. *
  355. * \param value1 Parameter index
  356. * \param value2 MIDI CC
  357. */
  358. CALLBACK_PARAMETER_MIDI_CC_CHANGED = 3,
  359. /*!
  360. * The current program has has been changed.
  361. *
  362. * \param value1 Program index
  363. */
  364. CALLBACK_PROGRAM_CHANGED = 4,
  365. /*!
  366. * The current MIDI program has been changed.
  367. *
  368. * \param value1 MIDI bank
  369. * \param value2 MIDI program
  370. */
  371. CALLBACK_MIDI_PROGRAM_CHANGED = 5,
  372. /*!
  373. * A note has been pressed.
  374. *
  375. * \param value1 Channel
  376. * \param value2 Note
  377. * \param value3 Velocity
  378. */
  379. CALLBACK_NOTE_ON = 6,
  380. /*!
  381. * A note has been released.
  382. *
  383. * \param value1 Channel
  384. * \param value2 Note
  385. */
  386. CALLBACK_NOTE_OFF = 7,
  387. /*!
  388. * The plugin's custom GUI state has changed.
  389. *
  390. * \param value1 State, as follows:.\n
  391. * 0: GUI has been closed or hidden\n
  392. * 1: GUI has been shown\n
  393. * -1: GUI has crashed and should not be shown again
  394. */
  395. CALLBACK_SHOW_GUI = 8,
  396. /*!
  397. * The plugin needs update.
  398. */
  399. CALLBACK_UPDATE = 9,
  400. /*!
  401. * The plugin's data/information has changed.
  402. */
  403. CALLBACK_RELOAD_INFO = 10,
  404. /*!
  405. * The plugin's parameters have changed.
  406. */
  407. CALLBACK_RELOAD_PARAMETERS = 11,
  408. /*!
  409. * The plugin's programs have changed.
  410. */
  411. CALLBACK_RELOAD_PROGRAMS = 12,
  412. /*!
  413. * The plugin's state has changed.
  414. */
  415. CALLBACK_RELOAD_ALL = 13,
  416. /*!
  417. * Non-Session-Manager Announce message.
  418. */
  419. CALLBACK_NSM_ANNOUNCE = 14,
  420. /*!
  421. * Non-Session-Manager Open message #1.
  422. */
  423. CALLBACK_NSM_OPEN1 = 15,
  424. /*!
  425. * Non-Session-Manager Open message #2.
  426. */
  427. CALLBACK_NSM_OPEN2 = 16,
  428. /*!
  429. * Non-Session-Manager Save message.
  430. */
  431. CALLBACK_NSM_SAVE = 17,
  432. /*!
  433. * An error occurred, show last error to user.
  434. */
  435. CALLBACK_ERROR = 18,
  436. /*!
  437. * The engine has crashed or malfunctioned and will no longer work.
  438. */
  439. CALLBACK_QUIT = 19
  440. };
  441. /*!
  442. * Engine process mode.
  443. *
  444. * \see OPTION_PROCESS_MODE
  445. */
  446. enum ProcessMode {
  447. PROCESS_MODE_SINGLE_CLIENT = 0, //!< Single client mode (dynamic input/outputs as needed by plugins)
  448. PROCESS_MODE_MULTIPLE_CLIENTS = 1, //!< Multiple client mode (1 master client + 1 client per plugin)
  449. PROCESS_MODE_CONTINUOUS_RACK = 2, //!< Single client, 'rack' mode. Processes plugins in order of id, with forced stereo.
  450. PROCESS_MODE_PATCHBAY = 3 //!< Single client, 'patchbay' mode.
  451. };
  452. /*!
  453. * Callback function the backend will call when something interesting happens.
  454. *
  455. * \see set_callback_function() and CallbackType
  456. */
  457. typedef void (*CallbackFunc)(void* ptr, CallbackType action, unsigned short pluginId, int value1, int value2, double value3, const char* valueStr);
  458. /*!
  459. * Parameter data
  460. */
  461. struct ParameterData {
  462. ParameterType type;
  463. int32_t index;
  464. int32_t rindex;
  465. int32_t hints;
  466. uint8_t midiChannel;
  467. int16_t midiCC;
  468. ParameterData()
  469. : type(PARAMETER_UNKNOWN),
  470. index(-1),
  471. rindex(-1),
  472. hints(0),
  473. midiChannel(0),
  474. midiCC(-1) {}
  475. };
  476. /*!
  477. * Parameter ranges
  478. */
  479. struct ParameterRanges {
  480. float def;
  481. float min;
  482. float max;
  483. float step;
  484. float stepSmall;
  485. float stepLarge;
  486. ParameterRanges()
  487. : def(0.0f),
  488. min(0.0f),
  489. max(1.0f),
  490. step(0.01f),
  491. stepSmall(0.0001f),
  492. stepLarge(0.1f) {}
  493. };
  494. /*!
  495. * MIDI Program data
  496. */
  497. struct MidiProgramData {
  498. uint32_t bank;
  499. uint32_t program;
  500. const char* name;
  501. MidiProgramData()
  502. : bank(0),
  503. program(0),
  504. name(nullptr) {}
  505. ~MidiProgramData()
  506. {
  507. if (name)
  508. free((void*)name);
  509. }
  510. };
  511. /*!
  512. * Custom data, saving key:value 'dictionaries'.
  513. * \a type is an URI which defines the \a value type.
  514. *
  515. * \see CustomDataTypes
  516. */
  517. struct CustomData {
  518. const char* type;
  519. const char* key;
  520. const char* value;
  521. CustomData()
  522. : type(nullptr),
  523. key(nullptr),
  524. value(nullptr) {}
  525. ~CustomData()
  526. {
  527. if (type)
  528. free((void*)type);
  529. if (key)
  530. free((void*)key);
  531. if (value)
  532. free((void*)value);
  533. }
  534. };
  535. /**@}*/
  536. // forward declarations of commonly used Carla classes
  537. class CarlaEngine;
  538. class CarlaPlugin;
  539. CARLA_BACKEND_END_NAMESPACE
  540. #endif // __CARLA_BACKEND_HPP__