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

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