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

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
10 years ago
10 years ago
11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
11 years ago
10 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
10 years ago
10 years ago
11 years ago
10 years ago
11 years ago
11 years ago
10 years ago
10 years ago
11 years ago
10 years ago
11 years ago
10 years ago
11 years ago
10 years ago
10 years ago
11 years ago
10 years ago
11 years ago
10 years ago
10 years ago
10 years ago
11 years ago
11 years ago
11 years ago
10 years ago
10 years ago
10 years ago
11 years ago
10 years ago
10 years ago
10 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
10 years ago
11 years ago
11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
10 years ago
10 years ago
11 years ago
10 years ago
11 years ago
10 years ago
10 years ago
10 years ago
11 years ago
10 years ago
10 years ago
10 years ago
11 years ago
10 years ago
11 years ago
11 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207
  1. /*
  2. * Carla Plugin Host
  3. * Copyright (C) 2011-2014 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 doc/GPL.txt file.
  16. */
  17. #ifndef CARLA_ENGINE_HPP_INCLUDED
  18. #define CARLA_ENGINE_HPP_INCLUDED
  19. #include "CarlaBackend.h"
  20. #ifdef BUILD_BRIDGE
  21. struct CarlaOscData;
  22. #endif
  23. CARLA_BACKEND_START_NAMESPACE
  24. // -----------------------------------------------------------------------
  25. /*!
  26. * @defgroup CarlaEngineAPI Carla Engine API
  27. *
  28. * The Carla Engine API.
  29. * @{
  30. */
  31. /*!
  32. * The type of an engine.
  33. */
  34. enum EngineType {
  35. /*!
  36. * Null engine type.
  37. */
  38. kEngineTypeNull = 0,
  39. /*!
  40. * JACK engine type.
  41. * Provides all processing modes.
  42. */
  43. kEngineTypeJack = 1,
  44. /*!
  45. * Juce engine type, used to provide Native Audio and MIDI support.
  46. */
  47. kEngineTypeJuce = 2,
  48. /*!
  49. * RtAudio engine type, used to provide Native Audio and MIDI support.
  50. */
  51. kEngineTypeRtAudio = 3,
  52. /*!
  53. * Plugin engine type, used to export the engine as a plugin.
  54. */
  55. kEngineTypePlugin = 4,
  56. /*!
  57. * Bridge engine type, used in BridgePlugin class.
  58. */
  59. kEngineTypeBridge = 5
  60. };
  61. /*!
  62. * The type of an engine port.
  63. */
  64. enum EnginePortType {
  65. /*!
  66. * Null port type.
  67. */
  68. kEnginePortTypeNull = 0,
  69. /*!
  70. * Audio port type.
  71. * @see CarlaEngineAudioPort
  72. */
  73. kEnginePortTypeAudio = 1,
  74. /*!
  75. * CV port type.
  76. * @see CarlaEngineCVPort
  77. */
  78. kEnginePortTypeCV = 2,
  79. /*!
  80. * Event port type (Control or MIDI).
  81. * @see CarlaEngineEventPort
  82. */
  83. kEnginePortTypeEvent = 3
  84. };
  85. /*!
  86. * The type of an engine event.
  87. */
  88. enum EngineEventType {
  89. /*!
  90. * Null port type.
  91. */
  92. kEngineEventTypeNull = 0,
  93. /*!
  94. * Control event type.
  95. * @see EngineControlEvent
  96. */
  97. kEngineEventTypeControl = 1,
  98. /*!
  99. * MIDI event type.
  100. * @see EngineMidiEvent
  101. */
  102. kEngineEventTypeMidi = 2
  103. };
  104. /*!
  105. * The type of an engine control event.
  106. */
  107. enum EngineControlEventType {
  108. /*!
  109. * Null event type.
  110. */
  111. kEngineControlEventTypeNull = 0,
  112. /*!
  113. * Parameter event type.
  114. * @note Value uses a normalized range of 0.0f<->1.0f.
  115. */
  116. kEngineControlEventTypeParameter = 1,
  117. /*!
  118. * MIDI Bank event type.
  119. */
  120. kEngineControlEventTypeMidiBank = 2,
  121. /*!
  122. * MIDI Program change event type.
  123. */
  124. kEngineControlEventTypeMidiProgram = 3,
  125. /*!
  126. * All sound off event type.
  127. */
  128. kEngineControlEventTypeAllSoundOff = 4,
  129. /*!
  130. * All notes off event type.
  131. */
  132. kEngineControlEventTypeAllNotesOff = 5
  133. };
  134. // -----------------------------------------------------------------------
  135. /*!
  136. * Engine control event.
  137. */
  138. struct EngineControlEvent {
  139. EngineControlEventType type; //!< Control-Event type.
  140. uint16_t param; //!< Parameter Id, midi bank or midi program.
  141. float value; //!< Parameter value, normalized to 0.0f<->1.0f.
  142. /*!
  143. * Convert this control event into MIDI data.
  144. */
  145. void convertToMidiData(const uint8_t channel, uint8_t& size, uint8_t data[3]) const noexcept;
  146. };
  147. /*!
  148. * Engine MIDI event.
  149. */
  150. struct EngineMidiEvent {
  151. static const uint8_t kDataSize = 4; //!< Size of internal data
  152. uint8_t port; //!< Port offset (usually 0)
  153. uint8_t size; //!< Number of bytes used
  154. /*!
  155. * MIDI data, without channel bit.
  156. * If size > kDataSize, dataExt is used (otherwise NULL).
  157. */
  158. uint8_t data[kDataSize];
  159. const uint8_t* dataExt;
  160. };
  161. /*!
  162. * Engine event.
  163. */
  164. struct EngineEvent {
  165. EngineEventType type; //!< Event Type; either Control or MIDI
  166. uint32_t time; //!< Time offset in frames
  167. uint8_t channel; //!< Channel, used for MIDI-related events
  168. /*!
  169. * Event specific data.
  170. */
  171. union {
  172. EngineControlEvent ctrl;
  173. EngineMidiEvent midi;
  174. };
  175. /*!
  176. * Fill this event from MIDI data.
  177. */
  178. void fillFromMidiData(const uint8_t size, const uint8_t* const data) noexcept;
  179. };
  180. // -----------------------------------------------------------------------
  181. /*!
  182. * Engine options.
  183. */
  184. struct EngineOptions {
  185. EngineProcessMode processMode;
  186. EngineTransportMode transportMode;
  187. bool forceStereo;
  188. bool preferPluginBridges;
  189. bool preferUiBridges;
  190. bool uisAlwaysOnTop;
  191. uint maxParameters;
  192. uint uiBridgesTimeout;
  193. uint audioNumPeriods;
  194. uint audioBufferSize;
  195. uint audioSampleRate;
  196. const char* audioDevice;
  197. const char* binaryDir;
  198. const char* resourceDir;
  199. uintptr_t frontendWinId;
  200. #ifndef DOXYGEN
  201. EngineOptions() noexcept;
  202. ~EngineOptions() noexcept;
  203. #endif
  204. };
  205. /*!
  206. * Engine BBT Time information.
  207. */
  208. struct EngineTimeInfoBBT {
  209. int32_t bar; //!< current bar
  210. int32_t beat; //!< current beat-within-bar
  211. int32_t tick; //!< current tick-within-beat
  212. double barStartTick;
  213. float beatsPerBar; //!< time signature "numerator"
  214. float beatType; //!< time signature "denominator"
  215. double ticksPerBeat;
  216. double beatsPerMinute;
  217. #ifndef DOXYGEN
  218. EngineTimeInfoBBT() noexcept;
  219. #endif
  220. };
  221. /*!
  222. * Engine Time information.
  223. */
  224. struct EngineTimeInfo {
  225. static const uint kValidBBT = 0x1;
  226. bool playing;
  227. uint64_t frame;
  228. uint64_t usecs;
  229. uint valid;
  230. EngineTimeInfoBBT bbt;
  231. /*!
  232. * Clear.
  233. */
  234. void clear() noexcept;
  235. #ifndef DOXYGEN
  236. EngineTimeInfo() noexcept;
  237. // quick operator, doesn't check all values
  238. bool operator==(const EngineTimeInfo& timeInfo) const noexcept;
  239. bool operator!=(const EngineTimeInfo& timeInfo) const noexcept;
  240. #endif
  241. };
  242. // -----------------------------------------------------------------------
  243. /*!
  244. * Carla Engine port (Abstract).
  245. * This is the base class for all Carla Engine ports.
  246. */
  247. class CarlaEnginePort
  248. {
  249. protected:
  250. /*!
  251. * The constructor.
  252. * All constructor parameters are constant and will never change in the lifetime of the port.
  253. */
  254. CarlaEnginePort(const CarlaEngineClient& client, const bool isInputPort) noexcept;
  255. public:
  256. /*!
  257. * The destructor.
  258. */
  259. virtual ~CarlaEnginePort() noexcept;
  260. /*!
  261. * Get the type of the port, as provided by the respective subclasses.
  262. */
  263. virtual EnginePortType getType() const noexcept = 0;
  264. /*!
  265. * Initialize the port's internal buffer.
  266. */
  267. virtual void initBuffer() noexcept = 0;
  268. /*!
  269. * Check if this port is an input.
  270. */
  271. bool isInput() const noexcept
  272. {
  273. return kIsInput;
  274. }
  275. /*!
  276. * Get this ports' engine client.
  277. */
  278. const CarlaEngineClient& getEngineClient() const noexcept
  279. {
  280. return kClient;
  281. }
  282. #ifndef DOXYGEN
  283. protected:
  284. const CarlaEngineClient& kClient;
  285. const bool kIsInput;
  286. CARLA_DECLARE_NON_COPY_CLASS(CarlaEnginePort)
  287. #endif
  288. };
  289. /*!
  290. * Carla Engine Audio port.
  291. */
  292. class CarlaEngineAudioPort : public CarlaEnginePort
  293. {
  294. public:
  295. /*!
  296. * The constructor.
  297. * All constructor parameters are constant and will never change in the lifetime of the port.
  298. */
  299. CarlaEngineAudioPort(const CarlaEngineClient& client, const bool isInputPort) noexcept;
  300. /*!
  301. * The destructor.
  302. */
  303. ~CarlaEngineAudioPort() noexcept override;
  304. /*!
  305. * Get the type of the port, in this case kEnginePortTypeAudio.
  306. */
  307. EnginePortType getType() const noexcept final
  308. {
  309. return kEnginePortTypeAudio;
  310. }
  311. /*!
  312. * Initialize the port's internal buffer.
  313. */
  314. void initBuffer() noexcept override;
  315. /*!
  316. * Direct access to the port's audio buffer.
  317. * May be null.
  318. */
  319. float* getBuffer() const noexcept
  320. {
  321. return fBuffer;
  322. }
  323. #ifndef DOXYGEN
  324. protected:
  325. float* fBuffer;
  326. CARLA_DECLARE_NON_COPY_CLASS(CarlaEngineAudioPort)
  327. #endif
  328. };
  329. /*!
  330. * Carla Engine CV port.
  331. */
  332. class CarlaEngineCVPort : public CarlaEnginePort
  333. {
  334. public:
  335. /*!
  336. * The constructor.
  337. * All constructor parameters are constant and will never change in the lifetime of the port.
  338. */
  339. CarlaEngineCVPort(const CarlaEngineClient& client, const bool isInputPort) noexcept;
  340. /*!
  341. * The destructor.
  342. */
  343. ~CarlaEngineCVPort() noexcept override;
  344. /*!
  345. * Get the type of the port, in this case kEnginePortTypeCV.
  346. */
  347. EnginePortType getType() const noexcept final
  348. {
  349. return kEnginePortTypeCV;
  350. }
  351. /*!
  352. * Initialize the port's internal buffer.
  353. */
  354. void initBuffer() noexcept override;
  355. /*!
  356. * Direct access to the port's CV buffer.
  357. * May be null.
  358. */
  359. float* getBuffer() const noexcept
  360. {
  361. return fBuffer;
  362. }
  363. #ifndef DOXYGEN
  364. protected:
  365. float* fBuffer;
  366. CARLA_DECLARE_NON_COPY_CLASS(CarlaEngineCVPort)
  367. #endif
  368. };
  369. /*!
  370. * Carla Engine Event port.
  371. */
  372. class CarlaEngineEventPort : public CarlaEnginePort
  373. {
  374. public:
  375. /*!
  376. * The constructor.
  377. * All constructor parameters are constant and will never change in the lifetime of the port.
  378. */
  379. CarlaEngineEventPort(const CarlaEngineClient& client, const bool isInputPort) noexcept;
  380. /*!
  381. * The destructor.
  382. */
  383. ~CarlaEngineEventPort() noexcept override;
  384. /*!
  385. * Get the type of the port, in this case kEnginePortTypeEvent.
  386. */
  387. EnginePortType getType() const noexcept final
  388. {
  389. return kEnginePortTypeEvent;
  390. }
  391. /*!
  392. * Initialize the port's internal buffer for @a engine.
  393. */
  394. void initBuffer() noexcept override;
  395. /*!
  396. * Get the number of events present in the buffer.
  397. * @note You must only call this for input ports.
  398. */
  399. virtual uint32_t getEventCount() const noexcept;
  400. /*!
  401. * Get the event at @a index.
  402. * @note You must only call this for input ports.
  403. */
  404. virtual const EngineEvent& getEvent(const uint32_t index) const noexcept;
  405. /*!
  406. * Get the event at @a index, faster unchecked version.
  407. */
  408. virtual const EngineEvent& getEventUnchecked(const uint32_t index) const noexcept;
  409. /*!
  410. * Write a control event into the buffer.
  411. * @note You must only call this for output ports.
  412. */
  413. bool writeControlEvent(const uint32_t time, const uint8_t channel, const EngineControlEvent& ctrl) noexcept;
  414. /*!
  415. * Write a control event into the buffer.
  416. * Arguments are the same as in the EngineControlEvent struct.
  417. * @note You must only call this for output ports.
  418. */
  419. virtual bool writeControlEvent(const uint32_t time, const uint8_t channel, const EngineControlEventType type, const uint16_t param, const float value = 0.0f) noexcept;
  420. /*!
  421. * Write a MIDI event into the buffer.
  422. * @note You must only call this for output ports.
  423. */
  424. bool writeMidiEvent(const uint32_t time, const uint8_t size, const uint8_t* const data) noexcept;
  425. /*!
  426. * Write a MIDI event into the buffer.
  427. * @note You must only call this for output ports.
  428. */
  429. bool writeMidiEvent(const uint32_t time, const uint8_t channel, const EngineMidiEvent& midi) noexcept;
  430. /*!
  431. * Write a MIDI event into the buffer.
  432. * Arguments are the same as in the EngineMidiEvent struct.
  433. * @note You must only call this for output ports.
  434. */
  435. virtual bool writeMidiEvent(const uint32_t time, const uint8_t channel, const uint8_t port, const uint8_t size, const uint8_t* const data) noexcept;
  436. #ifndef DOXYGEN
  437. protected:
  438. EngineEvent* fBuffer;
  439. const EngineProcessMode kProcessMode;
  440. friend class CarlaPluginInstance;
  441. CARLA_DECLARE_NON_COPY_CLASS(CarlaEngineEventPort)
  442. #endif
  443. };
  444. // -----------------------------------------------------------------------
  445. /*!
  446. * Carla Engine client.
  447. * Each plugin requires one client from the engine (created via CarlaEngine::addClient()).
  448. * @note This is a virtual class, some engine types provide custom funtionality.
  449. */
  450. class CarlaEngineClient
  451. {
  452. public:
  453. /*!
  454. * The constructor, protected.
  455. * All constructor parameters are constant and will never change in the lifetime of the client.
  456. * Client starts in deactivated state.
  457. */
  458. CarlaEngineClient(const CarlaEngine& engine) noexcept;
  459. /*!
  460. * The destructor.
  461. */
  462. virtual ~CarlaEngineClient() noexcept;
  463. /*!
  464. * Activate this client.
  465. * Client must be deactivated before calling this function.
  466. */
  467. virtual void activate() noexcept;
  468. /*!
  469. * Deactivate this client.
  470. * Client must be activated before calling this function.
  471. */
  472. virtual void deactivate() noexcept;
  473. /*!
  474. * Check if the client is activated.
  475. */
  476. virtual bool isActive() const noexcept;
  477. /*!
  478. * Check if the client is ok.
  479. * Plugins will refuse to instantiate if this returns false.
  480. * @note This is always true in rack and patchbay processing modes.
  481. */
  482. virtual bool isOk() const noexcept;
  483. /*!
  484. * Get the current latency, in samples.
  485. */
  486. virtual uint32_t getLatency() const noexcept;
  487. /*!
  488. * Change the client's latency.
  489. */
  490. virtual void setLatency(const uint32_t samples) noexcept;
  491. /*!
  492. * Add a new port of type @a portType.
  493. * @note This function does nothing in rack processing mode since ports are static there.
  494. */
  495. virtual CarlaEnginePort* addPort(const EnginePortType portType, const char* const name, const bool isInput);
  496. /*!
  497. * Get this client's engine.
  498. */
  499. const CarlaEngine& getEngine() const noexcept
  500. {
  501. return kEngine;
  502. }
  503. #ifndef DOXYGEN
  504. protected:
  505. const CarlaEngine& kEngine;
  506. bool fActive;
  507. uint32_t fLatency;
  508. CARLA_DECLARE_NON_COPY_CLASS(CarlaEngineClient)
  509. #endif
  510. };
  511. // -----------------------------------------------------------------------
  512. /*!
  513. * Carla Engine.
  514. * @note This is a virtual class for all available engine types available in Carla.
  515. */
  516. class CarlaEngine
  517. {
  518. protected:
  519. /*!
  520. * The constructor, protected.
  521. * @note This only initializes engine data, it doesn't actually start the engine.
  522. */
  523. CarlaEngine();
  524. public:
  525. /*!
  526. * The destructor.
  527. * The engine must have been closed before this happens.
  528. */
  529. virtual ~CarlaEngine();
  530. // -------------------------------------------------------------------
  531. // Static calls
  532. /*!
  533. * Get the number of available engine drivers.
  534. */
  535. static uint getDriverCount();
  536. /*!
  537. * Get the name of the engine driver at @a index.
  538. */
  539. static const char* getDriverName(const uint index);
  540. /*!
  541. * Get the device names of the driver at @a index.
  542. */
  543. static const char* const* getDriverDeviceNames(const uint index);
  544. /*!
  545. * Get device information about the driver at @a index and name @a driverName.
  546. */
  547. static const EngineDriverDeviceInfo* getDriverDeviceInfo(const uint index, const char* const driverName);
  548. /*!
  549. * Create a new engine, using driver @a driverName.
  550. * Returned value must be deleted when no longer needed.
  551. * @note This only initializes engine data, it doesn't actually start the engine.
  552. */
  553. static CarlaEngine* newDriverByName(const char* const driverName);
  554. // -------------------------------------------------------------------
  555. // Constant values
  556. /*!
  557. * Maximum client name size.
  558. */
  559. virtual uint getMaxClientNameSize() const noexcept;
  560. /*!
  561. * Maximum port name size.
  562. */
  563. virtual uint getMaxPortNameSize() const noexcept;
  564. /*!
  565. * Current number of plugins loaded.
  566. */
  567. uint getCurrentPluginCount() const noexcept;
  568. /*!
  569. * Maximum number of loadable plugins allowed.
  570. * This function returns 0 if engine is not started.
  571. */
  572. uint getMaxPluginNumber() const noexcept;
  573. // -------------------------------------------------------------------
  574. // Virtual, per-engine type calls
  575. /*!
  576. * Initialize/start the engine, using @a clientName.
  577. * When the engine is intialized, you need to call idle() at regular intervals.
  578. */
  579. virtual bool init(const char* const clientName);
  580. /*!
  581. * Close engine.
  582. * This function always closes the engine even if it returns false.
  583. * In other words, even when something goes wrong when closing the engine it still be closed nonetheless.
  584. */
  585. virtual bool close();
  586. /*!
  587. * Idle engine.
  588. */
  589. virtual void idle() noexcept;
  590. /*!
  591. * Check if engine is running.
  592. */
  593. virtual bool isRunning() const noexcept = 0;
  594. /*!
  595. * Check if engine is running offline (aka freewheel mode).
  596. */
  597. virtual bool isOffline() const noexcept = 0;
  598. /*!
  599. * Get engine type.
  600. */
  601. virtual EngineType getType() const noexcept = 0;
  602. /*!
  603. * Get the currently used driver name.
  604. */
  605. virtual const char* getCurrentDriverName() const noexcept = 0;
  606. /*!
  607. * Add new engine client.
  608. * @note This function must only be called within a plugin class.
  609. */
  610. virtual CarlaEngineClient* addClient(CarlaPlugin* const plugin);
  611. // -------------------------------------------------------------------
  612. // Plugin management
  613. /*!
  614. * Add new plugin.
  615. * @see ENGINE_CALLBACK_PLUGIN_ADDED
  616. */
  617. bool addPlugin(const BinaryType btype, const PluginType ptype, const char* const filename, const char* const name, const char* const label, const int64_t uniqueId, const void* const extra);
  618. /*!
  619. * Add new plugin, using native binary type.
  620. * @see ENGINE_CALLBACK_PLUGIN_ADDED
  621. */
  622. bool addPlugin(const PluginType ptype, const char* const filename, const char* const name, const char* const label, const int64_t uniqueId, const void* const extra);
  623. /*!
  624. * Remove plugin with id @a id.
  625. * @see ENGINE_CALLBACK_PLUGIN_REMOVED
  626. */
  627. bool removePlugin(const uint id);
  628. /*!
  629. * Remove all plugins.
  630. */
  631. bool removeAllPlugins();
  632. #ifndef BUILD_BRIDGE
  633. /*!
  634. * Rename plugin with id @a id to @a newName.
  635. * Returns the new name, or null if the operation failed.
  636. * Returned variable must be deleted if non-null.
  637. * @see ENGINE_CALLBACK_PLUGIN_RENAMED
  638. */
  639. virtual const char* renamePlugin(const uint id, const char* const newName);
  640. /*!
  641. * Clone plugin with id @a id.
  642. */
  643. bool clonePlugin(const uint id);
  644. /*!
  645. * Prepare replace of plugin with id @a id.
  646. * The next call to addPlugin() will use this id, replacing the selected plugin.
  647. * @note This function requires addPlugin() to be called afterwards, as soon as possible.
  648. */
  649. bool replacePlugin(const uint id) noexcept;
  650. /*!
  651. * Switch plugins with id @a idA and @a idB.
  652. */
  653. bool switchPlugins(const uint idA, const uint idB) noexcept;
  654. #endif
  655. /*!
  656. * Get plugin with id @a id.
  657. */
  658. CarlaPlugin* getPlugin(const uint id) const noexcept;
  659. /*!
  660. * Get plugin with id @a id, faster unchecked version.
  661. */
  662. CarlaPlugin* getPluginUnchecked(const uint id) const noexcept;
  663. /*!
  664. * Get a unique plugin name within the engine.
  665. * Returned variable must be deleted if non-null.
  666. */
  667. const char* getUniquePluginName(const char* const name) const;
  668. // -------------------------------------------------------------------
  669. // Project management
  670. /*!
  671. * Load a file of any type.
  672. * This will try to load a generic file as a plugin,
  673. * either by direct handling (GIG, SF2 and SFZ) or by using an internal plugin (like Audio and MIDI).
  674. */
  675. bool loadFile(const char* const filename);
  676. /*!
  677. * Load a project file.
  678. * @note Already loaded plugins are not removed; call removeAllPlugins() first if needed.
  679. */
  680. bool loadProject(const char* const filename);
  681. /*!
  682. * Save current project to a file.
  683. */
  684. bool saveProject(const char* const filename);
  685. // -------------------------------------------------------------------
  686. // Information (base)
  687. /*!
  688. * Get the current engine driver hints.
  689. * @see EngineDriverHints
  690. */
  691. uint getHints() const noexcept;
  692. /*!
  693. * Get the current buffer size.
  694. */
  695. uint32_t getBufferSize() const noexcept;
  696. /*!
  697. * Get the current sample rate.
  698. */
  699. double getSampleRate() const noexcept;
  700. /*!
  701. * Get the current engine name.
  702. */
  703. const char* getName() const noexcept;
  704. /*!
  705. * Get the current engine proccess mode.
  706. */
  707. EngineProcessMode getProccessMode() const noexcept;
  708. /*!
  709. * Get the current engine options (read-only).
  710. */
  711. const EngineOptions& getOptions() const noexcept;
  712. /*!
  713. * Get the current Time information (read-only).
  714. */
  715. const EngineTimeInfo& getTimeInfo() const noexcept;
  716. // -------------------------------------------------------------------
  717. // Information (peaks)
  718. /*!
  719. * TODO.
  720. */
  721. float getInputPeak(const uint pluginId, const bool isLeft) const noexcept;
  722. /*!
  723. * TODO.
  724. */
  725. float getOutputPeak(const uint pluginId, const bool isLeft) const noexcept;
  726. // -------------------------------------------------------------------
  727. // Callback
  728. /*!
  729. * Call the main engine callback, if set.
  730. * May be called by plugins.
  731. */
  732. void callback(const EngineCallbackOpcode action, const uint pluginId, const int value1, const int value2, const float value3, const char* const valueStr) noexcept;
  733. /*!
  734. * Set the main engine callback to @a func.
  735. */
  736. void setCallback(const EngineCallbackFunc func, void* const ptr) noexcept;
  737. // -------------------------------------------------------------------
  738. // Callback
  739. /*!
  740. * Call the file callback, if set.
  741. * May be called by plugins.
  742. */
  743. const char* runFileCallback(const FileCallbackOpcode action, const bool isDir, const char* const title, const char* const filter) noexcept;
  744. /*!
  745. * Set the file callback to @a func.
  746. */
  747. void setFileCallback(const FileCallbackFunc func, void* const ptr) noexcept;
  748. #ifndef BUILD_BRIDGE
  749. // -------------------------------------------------------------------
  750. // Patchbay
  751. /*!
  752. * Connect two patchbay ports.
  753. */
  754. virtual bool patchbayConnect(const uint groupA, const uint portA, const uint groupB, const uint portB);
  755. /*!
  756. * Remove a patchbay connection.
  757. */
  758. virtual bool patchbayDisconnect(const uint connectionId);
  759. /*!
  760. * Force the engine to resend all patchbay clients, ports and connections again.
  761. */
  762. virtual bool patchbayRefresh();
  763. #endif
  764. // -------------------------------------------------------------------
  765. // Transport
  766. /*!
  767. * Start playback of the engine transport.
  768. */
  769. virtual void transportPlay() noexcept;
  770. /*!
  771. * Pause the engine transport.
  772. */
  773. virtual void transportPause() noexcept;
  774. /*!
  775. * Relocate the engine transport to @a frames.
  776. */
  777. virtual void transportRelocate(const uint64_t frame) noexcept;
  778. // -------------------------------------------------------------------
  779. // Error handling
  780. /*!
  781. * Get last error.
  782. */
  783. const char* getLastError() const noexcept;
  784. /*!
  785. * Set last error.
  786. */
  787. void setLastError(const char* const error) const noexcept;
  788. // -------------------------------------------------------------------
  789. // Misc
  790. /*!
  791. * Tell the engine it's about to close.
  792. * This is used to prevent the engine thread(s) from reactivating.
  793. */
  794. void setAboutToClose() noexcept;
  795. // -------------------------------------------------------------------
  796. // Options
  797. /*!
  798. * Set the engine option @a option to @a value or @a valueStr.
  799. */
  800. void setOption(const EngineOption option, const int value, const char* const valueStr) noexcept;
  801. // -------------------------------------------------------------------
  802. // OSC Stuff
  803. #ifdef BUILD_BRIDGE
  804. /*!
  805. * Check if OSC bridge is registered.
  806. */
  807. bool isOscBridgeRegistered() const noexcept;
  808. #else
  809. /*!
  810. * Check if OSC controller is registered.
  811. */
  812. bool isOscControlRegistered() const noexcept;
  813. #endif
  814. /*!
  815. * Idle OSC.
  816. */
  817. void idleOsc() const noexcept;
  818. /*!
  819. * Get OSC TCP server path.
  820. */
  821. const char* getOscServerPathTCP() const noexcept;
  822. /*!
  823. * Get OSC UDP server path.
  824. */
  825. const char* getOscServerPathUDP() const noexcept;
  826. #ifdef BUILD_BRIDGE
  827. /*!
  828. * Set OSC bridge data.
  829. */
  830. void setOscBridgeData(CarlaOscData* const oscData) const noexcept;
  831. #endif
  832. // -------------------------------------------------------------------
  833. // Helper functions
  834. /*!
  835. * Return internal data, needed for EventPorts when used in Rack and Bridge modes.
  836. * @note RT call
  837. */
  838. EngineEvent* getInternalEventBuffer(const bool isInput) const noexcept;
  839. /*!
  840. * Force register a plugin into slot @a id.
  841. * This is needed so we can receive OSC events for a plugin while it initializes.
  842. */
  843. void registerEnginePlugin(const uint id, CarlaPlugin* const plugin) noexcept;
  844. #ifndef BUILD_BRIDGE
  845. /*!
  846. * Virtual functions for handling MIDI ports in the rack graph.
  847. */
  848. virtual bool connectRackMidiInPort(const char* const) { return false; }
  849. virtual bool connectRackMidiOutPort(const char* const) { return false; }
  850. virtual bool disconnectRackMidiInPort(const char* const) { return false; }
  851. virtual bool disconnectRackMidiOutPort(const char* const) { return false; }
  852. #endif
  853. // -------------------------------------------------------------------
  854. protected:
  855. /*!
  856. * Internal data, for CarlaEngine subclasses only.
  857. */
  858. struct ProtectedData;
  859. ProtectedData* const pData;
  860. /*!
  861. * Some internal classes read directly from pData.
  862. */
  863. friend class EngineInternalGraph;
  864. friend class PatchbayGraph;
  865. friend class RackGraph;
  866. friend class ScopedActionLock;
  867. // -------------------------------------------------------------------
  868. // Internal stuff
  869. /*!
  870. * Report to all plugins about buffer size change.
  871. */
  872. void bufferSizeChanged(const uint32_t newBufferSize);
  873. /*!
  874. * Report to all plugins about sample rate change.
  875. * This is not supported on all plugin types, in which case they will have to be re-initiated.
  876. */
  877. void sampleRateChanged(const double newSampleRate);
  878. /*!
  879. * Report to all plugins about offline mode change.
  880. */
  881. void offlineModeChanged(const bool isOffline);
  882. /*!
  883. * Run any pending RT events.
  884. * Must always be called at the end of audio processing.
  885. * @note RT call
  886. */
  887. void runPendingRtEvents() noexcept;
  888. /*!
  889. * Set a plugin (stereo) peak values.
  890. * @note RT call
  891. */
  892. void setPluginPeaks(const uint pluginId, float const inPeaks[2], float const outPeaks[2]) noexcept;
  893. #ifndef BUILD_BRIDGE
  894. // -------------------------------------------------------------------
  895. // Patchbay stuff
  896. /*!
  897. * Virtual functions for handling patchbay state.
  898. */
  899. virtual const char* const* getPatchbayConnections() const;
  900. virtual void restorePatchbayConnection(const char* const sourcePort, const char* const targetPort);
  901. #endif
  902. // -------------------------------------------------------------------
  903. public:
  904. /*!
  905. * Native audio APIs.
  906. */
  907. enum AudioApi {
  908. AUDIO_API_NULL = 0,
  909. // common
  910. AUDIO_API_JACK = 1,
  911. // linux
  912. AUDIO_API_ALSA = 2,
  913. AUDIO_API_OSS = 3,
  914. AUDIO_API_PULSE = 4,
  915. // macos
  916. AUDIO_API_CORE = 5,
  917. // windows
  918. AUDIO_API_ASIO = 6,
  919. AUDIO_API_DS = 7
  920. };
  921. // -------------------------------------------------------------------
  922. // Engine initializers
  923. // JACK
  924. static CarlaEngine* newJack();
  925. #ifdef BUILD_BRIDGE
  926. // Bridge
  927. static CarlaEngine* newBridge(const char* const audioPoolBaseName, const char* const rtBaseName, const char* const nonRtBaseName);
  928. #else
  929. # if defined(CARLA_OS_MAC) || defined(CARLA_OS_WIN)
  930. // Juce
  931. static CarlaEngine* newJuce(const AudioApi api);
  932. static uint getJuceApiCount();
  933. static const char* getJuceApiName(const uint index);
  934. static const char* const* getJuceApiDeviceNames(const uint index);
  935. static const EngineDriverDeviceInfo* getJuceDeviceInfo(const uint index, const char* const deviceName);
  936. # else
  937. // RtAudio
  938. static CarlaEngine* newRtAudio(const AudioApi api);
  939. static uint getRtAudioApiCount();
  940. static const char* getRtAudioApiName(const uint index);
  941. static const char* const* getRtAudioApiDeviceNames(const uint index);
  942. static const EngineDriverDeviceInfo* getRtAudioDeviceInfo(const uint index, const char* const deviceName);
  943. # endif
  944. #endif
  945. // -------------------------------------------------------------------
  946. // Bridge/Controller OSC stuff
  947. #ifdef BUILD_BRIDGE
  948. void oscSend_bridge_plugin_info1(const PluginCategory category, const uint hints, const uint optionsAvailable, const uint optionsEnabled, const int64_t uniqueId) const noexcept;
  949. void oscSend_bridge_plugin_info2(const char* const realName, const char* const label, const char* const maker, const char* const copyright) const noexcept;
  950. void oscSend_bridge_audio_count(const uint32_t ins, const uint32_t outs) const noexcept;
  951. void oscSend_bridge_midi_count(const uint32_t ins, const uint32_t outs) const noexcept;
  952. void oscSend_bridge_parameter_count(const uint32_t ins, const uint32_t outs) const noexcept;
  953. void oscSend_bridge_program_count(const uint32_t count) const noexcept;
  954. void oscSend_bridge_midi_program_count(const uint32_t count) const noexcept;
  955. void oscSend_bridge_parameter_data1(const uint32_t index, const int32_t rindex, const ParameterType type, const uint hints, const int16_t cc) const noexcept;
  956. void oscSend_bridge_parameter_data2(const uint32_t index, const char* const name, const char* const unit) const noexcept;
  957. void oscSend_bridge_parameter_ranges1(const uint32_t index, const float def, const float min, const float max) const noexcept;
  958. void oscSend_bridge_parameter_ranges2(const uint32_t index, const float step, const float stepSmall, const float stepLarge) const noexcept;
  959. void oscSend_bridge_parameter_value(const uint32_t index, const float value) const noexcept;
  960. void oscSend_bridge_default_value(const uint32_t index, const float value) const noexcept;
  961. void oscSend_bridge_current_program(const int32_t index) const noexcept;
  962. void oscSend_bridge_current_midi_program(const int32_t index) const noexcept;
  963. void oscSend_bridge_program_name(const uint32_t index, const char* const name) const noexcept;
  964. void oscSend_bridge_midi_program_data(const uint32_t index, const uint32_t bank, const uint32_t program, const char* const name) const noexcept;
  965. void oscSend_bridge_configure(const char* const key, const char* const value) const noexcept;
  966. void oscSend_bridge_set_custom_data(const char* const type, const char* const key, const char* const value) const noexcept;
  967. void oscSend_bridge_set_chunk_data_file(const char* const chunkDataFile) const noexcept;
  968. void oscSend_bridge_set_peaks() const noexcept;
  969. void oscSend_bridge_pong() const noexcept;
  970. #else
  971. void oscSend_control_add_plugin_start(const uint pluginId, const char* const pluginName) const noexcept;
  972. void oscSend_control_add_plugin_end(const uint pluginId) const noexcept;
  973. void oscSend_control_remove_plugin(const uint pluginId) const noexcept;
  974. void oscSend_control_set_plugin_info1(const uint pluginId, const PluginType type, const PluginCategory category, const uint hints, const int64_t uniqueId) const noexcept;
  975. void oscSend_control_set_plugin_info2(const uint pluginId, const char* const realName, const char* const label, const char* const maker, const char* const copyright) const noexcept;
  976. void oscSend_control_set_audio_count(const uint pluginId, const uint32_t ins, const uint32_t outs) const noexcept;
  977. void oscSend_control_set_midi_count(const uint pluginId, const uint32_t ins, const uint32_t outs) const noexcept;
  978. void oscSend_control_set_parameter_count(const uint pluginId, const uint32_t ins, const uint32_t outs) const noexcept;
  979. void oscSend_control_set_program_count(const uint pluginId, const uint32_t count) const noexcept;
  980. void oscSend_control_set_midi_program_count(const uint pluginId, const uint32_t count) const noexcept;
  981. void oscSend_control_set_parameter_data(const uint pluginId, const uint32_t index, const ParameterType type, const uint hints, const char* const name, const char* const unit) const noexcept;
  982. void oscSend_control_set_parameter_ranges1(const uint pluginId, const uint32_t index, const float def, const float min, const float max) const noexcept;
  983. void oscSend_control_set_parameter_ranges2(const uint pluginId, const uint32_t index, const float step, const float stepSmall, const float stepLarge) const noexcept;
  984. void oscSend_control_set_parameter_midi_cc(const uint pluginId, const uint32_t index, const int16_t cc) const noexcept;
  985. void oscSend_control_set_parameter_midi_channel(const uint pluginId, const uint32_t index, const uint8_t channel) const noexcept;
  986. void oscSend_control_set_parameter_value(const uint pluginId, const int32_t index, const float value) const noexcept; // may be used for internal params (< 0)
  987. void oscSend_control_set_default_value(const uint pluginId, const uint32_t index, const float value) const noexcept;
  988. void oscSend_control_set_current_program(const uint pluginId, const int32_t index) const noexcept;
  989. void oscSend_control_set_current_midi_program(const uint pluginId, const int32_t index) const noexcept;
  990. void oscSend_control_set_program_name(const uint pluginId, const uint32_t index, const char* const name) const noexcept;
  991. void oscSend_control_set_midi_program_data(const uint pluginId, const uint32_t index, const uint32_t bank, const uint32_t program, const char* const name) const noexcept;
  992. void oscSend_control_note_on(const uint pluginId, const uint8_t channel, const uint8_t note, const uint8_t velo) const noexcept;
  993. void oscSend_control_note_off(const uint pluginId, const uint8_t channel, const uint8_t note) const noexcept;
  994. void oscSend_control_set_peaks(const uint pluginId) const noexcept;
  995. void oscSend_control_exit() const noexcept;
  996. #endif
  997. CARLA_DECLARE_NON_COPY_CLASS(CarlaEngine)
  998. };
  999. /**@}*/
  1000. // -----------------------------------------------------------------------
  1001. CARLA_BACKEND_END_NAMESPACE
  1002. #endif // CARLA_ENGINE_HPP_INCLUDED