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 32KB

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