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

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