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.

CarlaEngine.hpp 30KB

11 years ago
12 years ago
11 years ago
11 years ago
11 years ago
12 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
12 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
12 years ago
11 years ago
12 years ago
11 years ago
11 years ago
12 years ago
11 years ago
12 years ago
12 years ago
11 years ago
12 years ago
11 years ago
12 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
12 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144
  1. /*
  2. * Carla Engine API
  3. * Copyright (C) 2012-2013 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 GPL.txt file
  16. */
  17. #ifndef __CARLA_ENGINE_HPP__
  18. #define __CARLA_ENGINE_HPP__
  19. #include "CarlaBackend.hpp"
  20. #include "CarlaString.hpp"
  21. #ifdef BUILD_BRIDGE
  22. struct CarlaOscData;
  23. #endif
  24. CARLA_BACKEND_START_NAMESPACE
  25. /*!
  26. * @defgroup CarlaEngineAPI Carla Engine API
  27. *
  28. * The Carla Engine API.
  29. *
  30. * @{
  31. */
  32. // -----------------------------------------------------------------------
  33. /*!
  34. * The type of an engine.
  35. */
  36. enum EngineType {
  37. /*!
  38. * Null engine type.
  39. */
  40. kEngineTypeNull = 0,
  41. /*!
  42. * JACK engine type.\n
  43. * Provides all processing modes.
  44. */
  45. kEngineTypeJack = 1,
  46. /*!
  47. * RtAudio engine type, used to provide Native Audio and MIDI support.
  48. */
  49. kEngineTypeRtAudio = 2,
  50. /*!
  51. * Plugin engine type, used to export the engine as a plugin.
  52. */
  53. kEngineTypePlugin = 3,
  54. /*!
  55. * Bridge engine type, used in BridgePlugin class.
  56. */
  57. kEngineTypeBridge = 4
  58. };
  59. /*!
  60. * The type of an engine port.
  61. */
  62. enum EnginePortType {
  63. /*!
  64. * Null port type.
  65. */
  66. kEnginePortTypeNull = 0,
  67. /*!
  68. * Audio port type.
  69. * \see CarlaEngineAudioPort
  70. */
  71. kEnginePortTypeAudio = 1,
  72. /*!
  73. * Event port type.
  74. ** \see CarlaEngineEventPort
  75. */
  76. kEnginePortTypeEvent = 2
  77. };
  78. /*!
  79. * The type of an engine event.
  80. */
  81. enum EngineEventType {
  82. /*!
  83. * Null port type.
  84. */
  85. kEngineEventTypeNull = 0,
  86. /*!
  87. * Control event type.
  88. * \see EngineControlEvent
  89. */
  90. kEngineEventTypeControl = 1,
  91. /*!
  92. * MIDI event type.
  93. * \see EngineMidiEvent
  94. */
  95. kEngineEventTypeMidi = 2
  96. };
  97. /*!
  98. * The type of an engine control event.
  99. */
  100. enum EngineControlEventType {
  101. /*!
  102. * Null event type.
  103. */
  104. kEngineControlEventTypeNull = 0,
  105. /*!
  106. * Parameter event type.\n
  107. * \note Value uses a normalized range of 0.0f<->1.0f.
  108. */
  109. kEngineControlEventTypeParameter = 1,
  110. /*!
  111. * MIDI Bank event type.
  112. */
  113. kEngineControlEventTypeMidiBank = 2,
  114. /*!
  115. * MIDI Program change event type.
  116. */
  117. kEngineControlEventTypeMidiProgram = 3,
  118. /*!
  119. * All sound off event type.
  120. */
  121. kEngineControlEventTypeAllSoundOff = 4,
  122. /*!
  123. * All notes off event type.
  124. */
  125. kEngineControlEventTypeAllNotesOff = 5
  126. };
  127. /*!
  128. * Engine control event.
  129. */
  130. struct EngineControlEvent {
  131. EngineControlEventType type; //!< Control-Event type.
  132. uint16_t param; //!< Parameter Id, midi bank or midi program.
  133. float value; //!< Parameter value, normalized to 0.0f<->1.0f.
  134. void clear()
  135. {
  136. type = kEngineControlEventTypeNull;
  137. param = 0;
  138. value = 0.0f;
  139. }
  140. CARLA_DECLARE_NON_COPY_STRUCT(EngineControlEvent)
  141. };
  142. /*!
  143. * Engine MIDI event.
  144. */
  145. struct EngineMidiEvent {
  146. uint8_t port; //!< Port offset (usually 0)
  147. uint8_t data[4]; //!< MIDI data, without channel bit
  148. uint8_t size; //!< Number of bytes used
  149. void clear()
  150. {
  151. port = 0;
  152. data[0] = 0;
  153. data[1] = 0;
  154. data[2] = 0;
  155. data[3] = 0;
  156. size = 0;
  157. }
  158. CARLA_DECLARE_NON_COPY_STRUCT(EngineMidiEvent)
  159. };
  160. /*!
  161. * Engine event.
  162. */
  163. struct EngineEvent {
  164. EngineEventType type; //!< Event Type; either Control or MIDI
  165. uint32_t time; //!< Time offset in frames
  166. uint8_t channel; //!< Channel, used for MIDI-related events
  167. union {
  168. EngineControlEvent ctrl;
  169. EngineMidiEvent midi;
  170. };
  171. #ifndef DOXYGEN
  172. EngineEvent()
  173. {
  174. clear();
  175. }
  176. #endif
  177. void clear()
  178. {
  179. type = kEngineEventTypeNull;
  180. time = 0;
  181. channel = 0;
  182. }
  183. CARLA_DECLARE_NON_COPY_STRUCT_WITH_LEAK_DETECTOR(EngineEvent)
  184. };
  185. /*!
  186. * Engine options.
  187. */
  188. struct EngineOptions {
  189. ProcessMode processMode;
  190. TransportMode transportMode;
  191. bool forceStereo;
  192. bool preferPluginBridges;
  193. bool preferUiBridges;
  194. #ifdef WANT_DSSI
  195. bool useDssiVstChunks;
  196. #endif
  197. unsigned int maxParameters;
  198. unsigned int oscUiTimeout;
  199. bool jackAutoConnect;
  200. bool jackTimeMaster;
  201. #ifdef WANT_RTAUDIO
  202. unsigned int rtaudioBufferSize;
  203. unsigned int rtaudioSampleRate;
  204. CarlaString rtaudioDevice;
  205. #endif
  206. #ifndef BUILD_BRIDGE
  207. CarlaString bridge_native;
  208. CarlaString bridge_posix32;
  209. CarlaString bridge_posix64;
  210. CarlaString bridge_win32;
  211. CarlaString bridge_win64;
  212. #endif
  213. #ifdef WANT_LV2
  214. CarlaString bridge_lv2Gtk2;
  215. CarlaString bridge_lv2Gtk3;
  216. CarlaString bridge_lv2Qt4;
  217. CarlaString bridge_lv2Qt5;
  218. CarlaString bridge_lv2Cocoa;
  219. CarlaString bridge_lv2Win;
  220. CarlaString bridge_lv2X11;
  221. #endif
  222. #ifdef WANT_VST
  223. CarlaString bridge_vstCocoa;
  224. CarlaString bridge_vstHWND;
  225. CarlaString bridge_vstX11;
  226. #endif
  227. int _d; //ignore
  228. #ifndef DOXYGEN
  229. EngineOptions()
  230. : processMode(PROCESS_MODE_CONTINUOUS_RACK),
  231. transportMode(TRANSPORT_MODE_INTERNAL),
  232. forceStereo(false),
  233. preferPluginBridges(false),
  234. preferUiBridges(true),
  235. # ifdef WANT_DSSI
  236. useDssiVstChunks(false),
  237. # endif
  238. maxParameters(MAX_DEFAULT_PARAMETERS),
  239. oscUiTimeout(4000),
  240. jackAutoConnect(false),
  241. jackTimeMaster(false),
  242. # ifdef WANT_RTAUDIO
  243. rtaudioBufferSize(512),
  244. rtaudioSampleRate(44100),
  245. # endif
  246. _d(0) {}
  247. CARLA_DECLARE_NON_COPY_STRUCT_WITH_LEAK_DETECTOR(EngineOptions)
  248. #endif
  249. };
  250. /*!
  251. * Engine BBT Time information.
  252. */
  253. struct EngineTimeInfoBBT {
  254. int32_t bar; //!< current bar
  255. int32_t beat; //!< current beat-within-bar
  256. int32_t tick; //!< current tick-within-beat
  257. double barStartTick;
  258. float beatsPerBar; //!< time signature "numerator"
  259. float beatType; //!< time signature "denominator"
  260. double ticksPerBeat;
  261. double beatsPerMinute;
  262. #ifndef DOXYGEN
  263. EngineTimeInfoBBT()
  264. : bar(0),
  265. beat(0),
  266. tick(0),
  267. barStartTick(0.0),
  268. beatsPerBar(0.0f),
  269. beatType(0.0f),
  270. ticksPerBeat(0.0),
  271. beatsPerMinute(0.0) {}
  272. CARLA_DECLARE_NON_COPY_STRUCT_WITH_LEAK_DETECTOR(EngineTimeInfoBBT)
  273. #endif
  274. };
  275. /*!
  276. * Engine Time information.
  277. */
  278. struct EngineTimeInfo {
  279. static const uint32_t ValidBBT = 0x1;
  280. bool playing;
  281. uint32_t frame;
  282. uint64_t usecs;
  283. uint32_t valid;
  284. EngineTimeInfoBBT bbt;
  285. #ifndef DOXYGEN
  286. EngineTimeInfo()
  287. {
  288. clear();
  289. }
  290. // quick operator, doesn't check all values
  291. bool operator==(const EngineTimeInfo& timeInfo) const
  292. {
  293. if (timeInfo.playing != playing || timeInfo.frame != frame)
  294. return false;
  295. if ((timeInfo.valid & ValidBBT) != (valid & ValidBBT))
  296. return false;
  297. if (timeInfo.bbt.beatsPerMinute != bbt.beatsPerMinute)
  298. return false;
  299. return true;
  300. }
  301. bool operator!=(const EngineTimeInfo& timeInfo) const
  302. {
  303. return !operator==(timeInfo);
  304. }
  305. #endif
  306. void clear()
  307. {
  308. playing = false;
  309. frame = 0;
  310. usecs = 0;
  311. valid = 0x0;
  312. }
  313. #ifndef DOXYGEN
  314. CARLA_DECLARE_NON_COPY_STRUCT_WITH_LEAK_DETECTOR(EngineTimeInfo)
  315. #endif
  316. };
  317. // -----------------------------------------------------------------------
  318. /*!
  319. * Carla Engine port (Abstract).\n
  320. * This is the base class for all Carla Engine ports.
  321. */
  322. class CarlaEnginePort
  323. {
  324. public:
  325. /*!
  326. * The contructor.\n
  327. * Param \a isInput defines wherever this is an input port or not (output otherwise).\n
  328. * Input/output state and process mode are constant for the lifetime of the port.
  329. */
  330. CarlaEnginePort(const bool isInput, const ProcessMode processMode);
  331. /*!
  332. * The destructor.
  333. */
  334. virtual ~CarlaEnginePort();
  335. /*!
  336. * Get the type of the port, as provided by the respective subclasses.
  337. */
  338. virtual EnginePortType type() const = 0;
  339. /*!
  340. * Initialize the port's internal buffer for \a engine.
  341. */
  342. virtual void initBuffer(CarlaEngine* const engine) = 0;
  343. #ifndef DOXYGEN
  344. protected:
  345. const bool kIsInput;
  346. const ProcessMode kProcessMode;
  347. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaEnginePort)
  348. #endif
  349. };
  350. // -----------------------------------------------------------------------
  351. /*!
  352. * Carla Engine Audio port.
  353. */
  354. class CarlaEngineAudioPort : public CarlaEnginePort
  355. {
  356. public:
  357. /*!
  358. * The contructor.\n
  359. * All constructor parameters are constant and will never change in the lifetime of the port.
  360. */
  361. CarlaEngineAudioPort(const bool isInput, const ProcessMode processMode);
  362. /*!
  363. * The destructor.
  364. */
  365. virtual ~CarlaEngineAudioPort() override;
  366. /*!
  367. * Get the type of the port, in this case CarlaEnginePortTypeAudio.
  368. */
  369. EnginePortType type() const override
  370. {
  371. return kEnginePortTypeAudio;
  372. }
  373. /*!
  374. * Initialize the port's internal buffer for \a engine.
  375. */
  376. virtual void initBuffer(CarlaEngine* const engine) override;
  377. /*!
  378. * Direct access to the port's audio buffer.
  379. */
  380. float* getBuffer() const
  381. {
  382. return fBuffer;
  383. }
  384. #ifndef DOXYGEN
  385. protected:
  386. float* fBuffer;
  387. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaEngineAudioPort)
  388. #endif
  389. };
  390. // -----------------------------------------------------------------------
  391. /*!
  392. * Carla Engine Event port.
  393. */
  394. class CarlaEngineEventPort : public CarlaEnginePort
  395. {
  396. public:
  397. /*!
  398. * The contructor.\n
  399. * All constructor parameters are constant and will never change in the lifetime of the port.
  400. */
  401. CarlaEngineEventPort(const bool isInput, const ProcessMode processMode);
  402. /*!
  403. * The destructor.
  404. */
  405. virtual ~CarlaEngineEventPort() override;
  406. /*!
  407. * Get the type of the port, in this case CarlaEnginePortTypeControl.
  408. */
  409. EnginePortType type() const override
  410. {
  411. return kEnginePortTypeEvent;
  412. }
  413. /*!
  414. * Initialize the port's internal buffer for \a engine.
  415. */
  416. virtual void initBuffer(CarlaEngine* const engine) override;
  417. /*!
  418. * Get the number of events present in the buffer.
  419. * \note You must only call this for input ports.
  420. */
  421. virtual uint32_t getEventCount();
  422. /*!
  423. * Get the event at \a index.
  424. * \note You must only call this for input ports.
  425. */
  426. virtual const EngineEvent& getEvent(const uint32_t index);
  427. /*!
  428. * Write a control event into the buffer.\n
  429. * Arguments are the same as in the EngineControlEvent struct.
  430. * \note You must only call this for output ports.
  431. */
  432. virtual void writeControlEvent(const uint32_t time, const uint8_t channel, const EngineControlEventType type, const uint16_t param, const float value = 0.0f);
  433. /*!
  434. * Write a control event into the buffer, overloaded call.
  435. */
  436. void writeControlEvent(const uint32_t time, const uint8_t channel, const EngineControlEvent& ctrl)
  437. {
  438. writeControlEvent(time, channel, ctrl.type, ctrl.param, ctrl.value);
  439. }
  440. /*!
  441. * Write a MIDI event into the buffer.\n
  442. * Arguments are the same as in the EngineMidiEvent struct.
  443. ** \note You must only call this for output ports.
  444. */
  445. virtual void writeMidiEvent(const uint32_t time, const uint8_t channel, const uint8_t port, const uint8_t* const data, const uint8_t size);
  446. /*!
  447. * Write a MIDI event into the buffer, overloaded call.
  448. */
  449. void writeMidiEvent(const uint32_t time, const uint8_t channel, const EngineMidiEvent& midi)
  450. {
  451. writeMidiEvent(time, channel, midi.port, midi.data, midi.size);
  452. }
  453. #ifndef DOXYGEN
  454. private:
  455. const uint32_t kMaxEventCount;
  456. EngineEvent* fBuffer;
  457. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaEngineEventPort)
  458. #endif
  459. };
  460. // -----------------------------------------------------------------------
  461. /*!
  462. * Carla Engine client.\n
  463. * Each plugin requires one client from the engine (created via CarlaEngine::addPort()).\n
  464. * \note This is a virtual class, each engine type provides its own funtionality.
  465. */
  466. class CarlaEngineClient
  467. {
  468. public:
  469. /*!
  470. * The constructor, protected.\n
  471. * All constructor parameters are constant and will never change in the lifetime of the client.\n
  472. * Client starts in deactivated state.
  473. */
  474. CarlaEngineClient(const CarlaBackend::EngineType engineType, const CarlaBackend::ProcessMode processMode);
  475. /*!
  476. * The destructor.
  477. */
  478. virtual ~CarlaEngineClient();
  479. /*!
  480. * Activate this client.\n
  481. * Client must be deactivated before calling this function.
  482. */
  483. virtual void activate();
  484. /*!
  485. * Deactivate this client.\n
  486. * Client must be activated before calling this function.
  487. */
  488. virtual void deactivate();
  489. /*!
  490. * Check if the client is activated.
  491. */
  492. virtual bool isActive() const;
  493. /*!
  494. * Check if the client is ok.\n
  495. * Plugins will refuse to instantiate if this returns false.
  496. * \note This is always true in rack and patchbay processing modes.
  497. */
  498. virtual bool isOk() const;
  499. /*!
  500. * Get the current latency, in samples.
  501. */
  502. virtual uint32_t getLatency() const;
  503. /*!
  504. * Change the client's latency.
  505. */
  506. virtual void setLatency(const uint32_t samples);
  507. /*!
  508. * Add a new port of type \a portType.
  509. * \note This function does nothing in rack processing mode since ports are static there (2 audio + 1 event for both input and output).
  510. */
  511. virtual CarlaEnginePort* addPort(const EnginePortType portType, const char* const name, const bool isInput);
  512. #ifndef DOXYGEN
  513. protected:
  514. const EngineType kEngineType;
  515. const ProcessMode kProcessMode;
  516. bool fActive;
  517. uint32_t fLatency;
  518. private:
  519. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaEngineClient)
  520. #endif
  521. };
  522. // -----------------------------------------------------------------------
  523. /*!
  524. * Protected data used in CarlaEngine.
  525. * Non-engine code MUST NEVER have direct access to this.
  526. */
  527. struct CarlaEngineProtectedData;
  528. /*!
  529. * Carla Engine.
  530. * \note This is a virtual class for all available engine types available in Carla.
  531. */
  532. class CarlaEngine
  533. {
  534. protected:
  535. /*!
  536. * The constructor, protected.\n
  537. * \note This only initializes engine data, it doesn't initialize the engine itself.
  538. */
  539. CarlaEngine();
  540. public:
  541. /*!
  542. * The decontructor.
  543. * The engine must have been closed before this happens.
  544. */
  545. virtual ~CarlaEngine();
  546. // -------------------------------------------------------------------
  547. // Static values and calls
  548. /*!
  549. * TODO.
  550. */
  551. static const unsigned short MAX_PEAKS = 2;
  552. /*!
  553. * Get the number of available engine drivers.
  554. */
  555. static unsigned int getDriverCount();
  556. /*!
  557. * Get the name of the engine driver at \a index.
  558. */
  559. static const char* getDriverName(unsigned int index);
  560. /*!
  561. * Get the device names of driver at \a index (for use in non-JACK drivers).\n
  562. * May return NULL.
  563. */
  564. static const char** getDriverDeviceNames(unsigned int index);
  565. /*!
  566. * Create a new engine, using driver \a driverName.\n
  567. * Returned variable must be deleted when no longer needed.
  568. */
  569. static CarlaEngine* newDriverByName(const char* const driverName);
  570. // -------------------------------------------------------------------
  571. // Constant values
  572. /*!
  573. * Maximum client name size.
  574. */
  575. virtual unsigned int maxClientNameSize() const;
  576. /*!
  577. * Maximum port name size.
  578. */
  579. virtual unsigned int maxPortNameSize() const;
  580. /*!
  581. * Current number of plugins loaded.
  582. */
  583. unsigned int currentPluginCount() const;
  584. /*!
  585. * Maximum number of loadable plugins allowed.
  586. * \note This function returns 0 if engine is not started.
  587. */
  588. unsigned int maxPluginNumber() const;
  589. // -------------------------------------------------------------------
  590. // Virtual, per-engine type calls
  591. /*!
  592. * Initialize engine, using \a clientName.
  593. */
  594. virtual bool init(const char* const clientName);
  595. /*!
  596. * Close engine.
  597. */
  598. virtual bool close();
  599. /*!
  600. * Idle engine.
  601. */
  602. virtual void idle();
  603. /*!
  604. * Check if engine is running.
  605. */
  606. virtual bool isRunning() const = 0;
  607. /*!
  608. * Check if engine is running offline (aka freewheel mode).
  609. */
  610. virtual bool isOffline() const = 0;
  611. /*!
  612. * Get engine type.
  613. */
  614. virtual EngineType type() const = 0;
  615. /*!
  616. * Add new engine client.
  617. * \note This must only be called within a plugin class.
  618. */
  619. virtual CarlaEngineClient* addClient(CarlaPlugin* const plugin);
  620. // -------------------------------------------------------------------
  621. // Plugin management
  622. /*!
  623. * Add new plugin.
  624. */
  625. bool addPlugin(const BinaryType btype, const PluginType ptype, const char* const filename, const char* const name, const char* const label, const void* const extra = nullptr);
  626. /*!
  627. * Add new plugin, using native binary type.
  628. */
  629. bool addPlugin(const PluginType ptype, const char* const filename, const char* const name, const char* const label, const void* const extra = nullptr)
  630. {
  631. return addPlugin(BINARY_NATIVE, ptype, filename, name, label, extra);
  632. }
  633. /*!
  634. * Remove plugin with id \a id.
  635. */
  636. bool removePlugin(const unsigned int id);
  637. /*!
  638. * Remove all plugins.
  639. */
  640. void removeAllPlugins();
  641. /*!
  642. * Rename plugin with id \a id to \a newName.\n
  643. * Returns the new name, or nullptr if the operation failed.
  644. */
  645. virtual const char* renamePlugin(const unsigned int id, const char* const newName);
  646. /*!
  647. * Clone plugin with id \a id.
  648. */
  649. bool clonePlugin(const unsigned int id);
  650. /*!
  651. * Prepare replace of plugin with id \a id.\n
  652. * The next call to addPlugin() will use this id, replacing the current plugin.
  653. * \note This function requires addPlugin() to be called afterwards as soon as possible.
  654. */
  655. bool replacePlugin(const unsigned int id);
  656. /*!
  657. * Switch plugins with id \a idA and \a idB.
  658. */
  659. bool switchPlugins(const unsigned int idA, const unsigned int idB);
  660. /*!
  661. * Get plugin with id \a id.
  662. */
  663. CarlaPlugin* getPlugin(const unsigned int id) const;
  664. /*!
  665. * Get plugin with id \a id, faster unchecked version.
  666. */
  667. CarlaPlugin* getPluginUnchecked(const unsigned int id) const;
  668. /*!
  669. * Get a unique plugin name within the engine.\n
  670. * Returned variable must NOT be free'd.
  671. */
  672. const char* getUniquePluginName(const char* const name);
  673. // -------------------------------------------------------------------
  674. // Project management
  675. /*!
  676. * Load \a filename of any type.\n
  677. * This will try to load a generic file as a plugin,
  678. * either by direct handling (GIG, SF2 and SFZ) or by using an internal plugin (like Audio and MIDI).
  679. */
  680. bool loadFilename(const char* const filename);
  681. /*!
  682. * Load \a filename project file.\n
  683. * (project files have *.carxp extension)
  684. * \note Already loaded plugins are not removed; call removeAllPlugins() first if needed.
  685. */
  686. bool loadProject(const char* const filename);
  687. /*!
  688. * Save current project to \a filename.\n
  689. * (project files have *.carxp extension)
  690. */
  691. bool saveProject(const char* const filename);
  692. // -------------------------------------------------------------------
  693. // Information (base)
  694. /*!
  695. * Get current buffer size.
  696. */
  697. uint32_t getBufferSize() const
  698. {
  699. return fBufferSize;
  700. }
  701. /*!
  702. * Get current sample rate.
  703. */
  704. double getSampleRate() const
  705. {
  706. return fSampleRate;
  707. }
  708. /*!
  709. * Get engine name.
  710. */
  711. const char* getName() const
  712. {
  713. return (const char*)fName;
  714. }
  715. /*!
  716. * Get the engine options (read-only).
  717. */
  718. const EngineOptions& getOptions() const
  719. {
  720. return fOptions;
  721. }
  722. /*!
  723. * Get the engine proccess mode.
  724. */
  725. ProcessMode getProccessMode() const
  726. {
  727. return fOptions.processMode;
  728. }
  729. /*!
  730. * Get current Time information (read-only).
  731. */
  732. const EngineTimeInfo& getTimeInfo() const
  733. {
  734. return fTimeInfo;
  735. }
  736. // -------------------------------------------------------------------
  737. // Information (peaks)
  738. /*!
  739. * TODO.
  740. * \a id must be either 1 or 2.
  741. */
  742. float getInputPeak(const unsigned int pluginId, const unsigned short id) const;
  743. /*!
  744. * TODO.
  745. * \a id must be either 1 or 2.
  746. */
  747. float getOutputPeak(const unsigned int pluginId, const unsigned short id) const;
  748. // -------------------------------------------------------------------
  749. // Callback
  750. /*!
  751. * TODO.
  752. */
  753. void callback(const CallbackType action, const unsigned int pluginId, const int value1, const int value2, const float value3, const char* const valueStr);
  754. /*!
  755. * TODO.
  756. */
  757. void setCallback(const CallbackFunc func, void* const ptr);
  758. // -------------------------------------------------------------------
  759. // Patchbay
  760. /*!
  761. * Connect patchbay ports \a portA and \a portB.
  762. */
  763. virtual bool patchbayConnect(int portA, int portB);
  764. /*!
  765. * Disconnect patchbay connection \a connectionId.
  766. */
  767. virtual bool patchbayDisconnect(int connectionId);
  768. /*!
  769. * Force the engine to resend all patchbay clients, ports and connections again.
  770. */
  771. virtual void patchbayRefresh();
  772. // -------------------------------------------------------------------
  773. // Transport
  774. /*!
  775. * Start playback of the engine transport.
  776. */
  777. virtual void transportPlay();
  778. /*!
  779. * Pause the engine transport.
  780. */
  781. virtual void transportPause();
  782. /*!
  783. * Relocate the engine transport to \a frames.
  784. */
  785. virtual void transportRelocate(const uint32_t frame);
  786. // -------------------------------------------------------------------
  787. // Error handling
  788. /*!
  789. * Get last error.
  790. */
  791. const char* getLastError() const;
  792. /*!
  793. * Set last error.
  794. */
  795. void setLastError(const char* const error);
  796. // -------------------------------------------------------------------
  797. // Misc
  798. /*!
  799. * Tell the engine it's about to close.\n
  800. * This is used to prevent the engine thread(s) from reactivating.
  801. */
  802. void setAboutToClose();
  803. // -------------------------------------------------------------------
  804. // Options
  805. /*!
  806. * Set the engine option \a option.
  807. */
  808. void setOption(const OptionsType option, const int value, const char* const valueStr);
  809. // -------------------------------------------------------------------
  810. // OSC Stuff
  811. #ifdef BUILD_BRIDGE
  812. /*!
  813. * Check if OSC bridge is registered.
  814. */
  815. bool isOscBridgeRegistered() const;
  816. #else
  817. /*!
  818. * Check if OSC controller is registered.
  819. */
  820. bool isOscControlRegistered() const;
  821. #endif
  822. /*!
  823. * Idle OSC.
  824. */
  825. void idleOsc();
  826. /*!
  827. * Get OSC TCP server path.
  828. */
  829. const char* getOscServerPathTCP() const;
  830. /*!
  831. * Get OSC UDP server path.
  832. */
  833. const char* getOscServerPathUDP() const;
  834. #ifdef BUILD_BRIDGE
  835. /*!
  836. * Set OSC bridge data.
  837. */
  838. void setOscBridgeData(const CarlaOscData* const oscData);
  839. #endif
  840. // -------------------------------------
  841. #ifndef DOXYGEN
  842. protected:
  843. uint32_t fBufferSize;
  844. double fSampleRate;
  845. CarlaString fName;
  846. EngineOptions fOptions;
  847. EngineTimeInfo fTimeInfo;
  848. friend struct CarlaEngineProtectedData;
  849. CarlaEngineProtectedData* const kData;
  850. /*!
  851. * Report to all plugins about buffer size change.
  852. */
  853. void bufferSizeChanged(const uint32_t newBufferSize);
  854. /*!
  855. * Report to all plugins about sample rate change.\n
  856. * This is not supported on all plugin types, on which case they will be re-initiated.\n
  857. * TODO: Not implemented yet.
  858. */
  859. void sampleRateChanged(const double newSampleRate);
  860. /*!
  861. * TODO.
  862. */
  863. void proccessPendingEvents();
  864. /*!
  865. * TODO.
  866. */
  867. void setPeaks(const unsigned int pluginId, float const inPeaks[MAX_PEAKS], float const outPeaks[MAX_PEAKS]);
  868. # ifndef BUILD_BRIDGE
  869. // Rack mode data
  870. EngineEvent* getRackEventBuffer(const bool isInput);
  871. /*!
  872. * Proccess audio buffer in rack mode.
  873. */
  874. void processRack(float* inBuf[2], float* outBuf[2], const uint32_t frames);
  875. /*!
  876. * Proccess audio buffer in patchbay mode.
  877. * In \a bufCount, [0]=inBufCount and [1]=outBufCount
  878. */
  879. void processPatchbay(float** inBuf, float** outBuf, const uint32_t bufCount[2], const uint32_t frames);
  880. # endif
  881. private:
  882. static CarlaEngine* newJack();
  883. # ifdef WANT_RTAUDIO
  884. enum RtAudioApi {
  885. RTAUDIO_DUMMY = 0,
  886. RTAUDIO_LINUX_ALSA = 1,
  887. RTAUDIO_LINUX_PULSE = 2,
  888. RTAUDIO_LINUX_OSS = 3,
  889. RTAUDIO_UNIX_JACK = 4,
  890. RTAUDIO_MACOSX_CORE = 5,
  891. RTAUDIO_WINDOWS_ASIO = 6,
  892. RTAUDIO_WINDOWS_DS = 7
  893. };
  894. static CarlaEngine* newRtAudio(const RtAudioApi api);
  895. static size_t getRtAudioApiCount();
  896. static const char* getRtAudioApiName(const unsigned int index);
  897. static const char** getRtAudioApiDeviceNames(const unsigned int index);
  898. # endif
  899. public:
  900. # ifdef BUILD_BRIDGE
  901. static CarlaEngine* newBridge(const char* const audioBaseName, const char* const controlBaseName);
  902. void osc_send_bridge_audio_count(const int32_t ins, const int32_t outs, const int32_t total);
  903. void osc_send_bridge_midi_count(const int32_t ins, const int32_t outs, const int32_t total);
  904. void osc_send_bridge_parameter_count(const int32_t ins, const int32_t outs, const int32_t total);
  905. void osc_send_bridge_program_count(const int32_t count);
  906. void osc_send_bridge_midi_program_count(const int32_t count);
  907. void osc_send_bridge_plugin_info(const int32_t category, const int32_t hints, const char* const name, const char* const label, const char* const maker, const char* const copyright, const int64_t uniqueId);
  908. void osc_send_bridge_parameter_info(const int32_t index, const char* const name, const char* const unit);
  909. void osc_send_bridge_parameter_data(const int32_t index, const int32_t type, const int32_t rindex, const int32_t hints, const int32_t midiChannel, const int32_t midiCC);
  910. void osc_send_bridge_parameter_ranges(const int32_t index, const float def, const float min, const float max, const float step, const float stepSmall, const float stepLarge);
  911. void osc_send_bridge_program_info(const int32_t index, const char* const name);
  912. void osc_send_bridge_midi_program_info(const int32_t index, const int32_t bank, const int32_t program, const char* const label);
  913. void osc_send_bridge_configure(const char* const key, const char* const value);
  914. void osc_send_bridge_set_parameter_value(const int32_t index, const float value);
  915. void osc_send_bridge_set_default_value(const int32_t index, const float value);
  916. void osc_send_bridge_set_program(const int32_t index);
  917. void osc_send_bridge_set_midi_program(const int32_t index);
  918. void osc_send_bridge_set_custom_data(const char* const type, const char* const key, const char* const value);
  919. void osc_send_bridge_set_chunk_data(const char* const chunkFile);
  920. void osc_send_bridge_set_peaks();
  921. # else
  922. void osc_send_control_add_plugin_start(const int32_t pluginId, const char* const pluginName);
  923. void osc_send_control_add_plugin_end(const int32_t pluginId);
  924. void osc_send_control_remove_plugin(const int32_t pluginId);
  925. void osc_send_control_set_plugin_data(const int32_t pluginId, const int32_t type, const int32_t category, const int32_t hints, const char* const realName, const char* const label, const char* const maker, const char* const copyright, const int64_t uniqueId);
  926. void osc_send_control_set_plugin_ports(const int32_t pluginId, const int32_t audioIns, const int32_t audioOuts, const int32_t midiIns, const int32_t midiOuts, const int32_t cIns, const int32_t cOuts, const int32_t cTotals);
  927. void osc_send_control_set_parameter_data(const int32_t pluginId, const int32_t index, const int32_t type, const int32_t hints, const char* const name, const char* const label, const float current);
  928. void osc_send_control_set_parameter_ranges(const int32_t pluginId, const int32_t index, const float min, const float max, const float def, const float step, const float stepSmall, const float stepLarge);
  929. void osc_send_control_set_parameter_midi_cc(const int32_t pluginId, const int32_t index, const int32_t cc);
  930. void osc_send_control_set_parameter_midi_channel(const int32_t pluginId, const int32_t index, const int32_t channel);
  931. void osc_send_control_set_parameter_value(const int32_t pluginId, const int32_t index, const float value);
  932. void osc_send_control_set_default_value(const int32_t pluginId, const int32_t index, const float value);
  933. void osc_send_control_set_program(const int32_t pluginId, const int32_t index);
  934. void osc_send_control_set_program_count(const int32_t pluginId, const int32_t count);
  935. void osc_send_control_set_program_name(const int32_t pluginId, const int32_t index, const char* const name);
  936. void osc_send_control_set_midi_program(const int32_t pluginId, const int32_t index);
  937. void osc_send_control_set_midi_program_count(const int32_t pluginId, const int32_t count);
  938. void osc_send_control_set_midi_program_data(const int32_t pluginId, const int32_t index, const int32_t bank, const int32_t program, const char* const name);
  939. void osc_send_control_note_on(const int32_t pluginId, const int32_t channel, const int32_t note, const int32_t velo);
  940. void osc_send_control_note_off(const int32_t pluginId, const int32_t channel, const int32_t note);
  941. void osc_send_control_set_peaks(const int32_t pluginId);
  942. void osc_send_control_exit();
  943. # endif
  944. private:
  945. friend class CarlaEngineEventPort;
  946. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaEngine)
  947. #endif
  948. };
  949. // -----------------------------------------------------------------------
  950. /**@}*/
  951. CARLA_BACKEND_END_NAMESPACE
  952. #endif // __CARLA_ENGINE_HPP__