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.

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