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.

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