Collection of tools useful for audio production
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.

592 lines
17KB

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