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
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
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
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
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
10 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
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
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
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
11 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398
  1. /*
  2. * Carla Plugin Host
  3. * Copyright (C) 2011-2020 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. #include "CarlaPluginPtr.hpp"
  21. namespace water {
  22. class MemoryOutputStream;
  23. class XmlDocument;
  24. }
  25. CARLA_BACKEND_START_NAMESPACE
  26. // -----------------------------------------------------------------------
  27. /*!
  28. * @defgroup CarlaEngineAPI Carla Engine API
  29. *
  30. * The Carla Engine API.
  31. * @{
  32. */
  33. /*!
  34. * The type of an engine.
  35. */
  36. enum EngineType {
  37. /*!
  38. * Null engine type.
  39. */
  40. kEngineTypeNull = 0,
  41. /*!
  42. * JACK engine type.
  43. * Provides all processing modes.
  44. */
  45. kEngineTypeJack = 1,
  46. /*!
  47. * JUCE engine type, used to provide Native Audio and MIDI support.
  48. */
  49. kEngineTypeJuce = 2,
  50. /*!
  51. * RtAudio engine type, used to provide Native Audio and MIDI support.
  52. */
  53. kEngineTypeRtAudio = 3,
  54. /*!
  55. * Plugin engine type, used to export the engine as a plugin.
  56. */
  57. kEngineTypePlugin = 4,
  58. /*!
  59. * Bridge engine type, used in BridgePlugin class.
  60. */
  61. kEngineTypeBridge = 5,
  62. /*!
  63. * Dummy engine type, does not send audio or MIDI anywhere.
  64. */
  65. kEngineTypeDummy = 6
  66. };
  67. /*!
  68. * The type of an engine port.
  69. */
  70. enum EnginePortType {
  71. /*!
  72. * Null port type.
  73. */
  74. kEnginePortTypeNull = 0,
  75. /*!
  76. * Audio port type.
  77. * @see CarlaEngineAudioPort
  78. */
  79. kEnginePortTypeAudio = 1,
  80. /*!
  81. * CV port type.
  82. * @see CarlaEngineCVPort
  83. */
  84. kEnginePortTypeCV = 2,
  85. /*!
  86. * Event port type (Control or MIDI).
  87. * @see CarlaEngineEventPort
  88. */
  89. kEnginePortTypeEvent = 3
  90. };
  91. /*!
  92. * The type of an engine event.
  93. */
  94. enum EngineEventType {
  95. /*!
  96. * Null port type.
  97. */
  98. kEngineEventTypeNull = 0,
  99. /*!
  100. * Control event type.
  101. * @see EngineControlEvent
  102. */
  103. kEngineEventTypeControl = 1,
  104. /*!
  105. * MIDI event type.
  106. * @see EngineMidiEvent
  107. */
  108. kEngineEventTypeMidi = 2
  109. };
  110. /*!
  111. * The type of an engine control event.
  112. */
  113. enum EngineControlEventType {
  114. /*!
  115. * Null event type.
  116. */
  117. kEngineControlEventTypeNull = 0,
  118. /*!
  119. * Parameter event type.
  120. * @note Value uses a normalized range of 0.0f<->1.0f.
  121. */
  122. kEngineControlEventTypeParameter = 1,
  123. /*!
  124. * MIDI Bank event type.
  125. */
  126. kEngineControlEventTypeMidiBank = 2,
  127. /*!
  128. * MIDI Program change event type.
  129. */
  130. kEngineControlEventTypeMidiProgram = 3,
  131. /*!
  132. * All sound off event type.
  133. */
  134. kEngineControlEventTypeAllSoundOff = 4,
  135. /*!
  136. * All notes off event type.
  137. */
  138. kEngineControlEventTypeAllNotesOff = 5
  139. };
  140. /*!
  141. * Special value for EngineEvent channel field, indicating a non-midi parameter event.
  142. */
  143. static const uint8_t kEngineEventNonMidiChannel = 0x30;
  144. // -----------------------------------------------------------------------
  145. /*!
  146. * Engine control event.
  147. */
  148. struct CARLA_API EngineControlEvent {
  149. EngineControlEventType type; //!< Control-Event type.
  150. uint16_t param; //!< Parameter Id, midi bank or midi program.
  151. int8_t midiValue; //!< Raw midi value, >= 0 if applicable, -1 otherwise.
  152. float normalizedValue; //!< Parameter value, normalized to 0.0f<->1.0f.
  153. bool handled; //!< Indicates that event was handled/received at least once.
  154. /*!
  155. * Convert this control event into MIDI data.
  156. * Returns size.
  157. */
  158. uint8_t convertToMidiData(uint8_t channel, uint8_t data[3]) const noexcept;
  159. };
  160. /*!
  161. * Engine MIDI event.
  162. */
  163. struct CARLA_API EngineMidiEvent {
  164. static const uint8_t kDataSize = 4; //!< Size of internal data
  165. uint8_t port; //!< Port offset (usually 0)
  166. uint8_t size; //!< Number of bytes used
  167. /*!
  168. * MIDI data, without channel bit.
  169. * If size > kDataSize, dataExt is used (otherwise NULL).
  170. */
  171. uint8_t data[kDataSize];
  172. const uint8_t* dataExt;
  173. };
  174. /*!
  175. * Engine event.
  176. */
  177. struct CARLA_API EngineEvent {
  178. EngineEventType type; //!< Event Type; either Control or MIDI
  179. uint32_t time; //!< Time offset in frames
  180. uint8_t channel; //!< Channel, used for MIDI-related events
  181. /*!
  182. * Event specific data.
  183. */
  184. union {
  185. EngineControlEvent ctrl;
  186. EngineMidiEvent midi;
  187. };
  188. /*!
  189. * Fill this event from MIDI data.
  190. */
  191. void fillFromMidiData(uint8_t size, const uint8_t* data, uint8_t midiPortOffset) noexcept;
  192. };
  193. // -----------------------------------------------------------------------
  194. /*!
  195. * Engine options.
  196. */
  197. struct CARLA_API EngineOptions {
  198. EngineProcessMode processMode;
  199. EngineTransportMode transportMode;
  200. const char* transportExtra;
  201. bool forceStereo;
  202. bool resetXruns;
  203. bool preferPluginBridges;
  204. bool preferUiBridges;
  205. bool uisAlwaysOnTop;
  206. bool pluginsAreStandalone;
  207. uint bgColor;
  208. uint fgColor;
  209. float uiScale;
  210. uint maxParameters;
  211. uint uiBridgesTimeout;
  212. uint audioBufferSize;
  213. uint audioSampleRate;
  214. bool audioTripleBuffer;
  215. const char* audioDriver;
  216. const char* audioDevice;
  217. #ifndef BUILD_BRIDGE
  218. bool oscEnabled;
  219. int oscPortTCP;
  220. int oscPortUDP;
  221. #endif
  222. const char* pathAudio;
  223. const char* pathMIDI;
  224. const char* pathLADSPA;
  225. const char* pathDSSI;
  226. const char* pathLV2;
  227. const char* pathVST2;
  228. const char* pathVST3;
  229. const char* pathSF2;
  230. const char* pathSFZ;
  231. const char* binaryDir;
  232. const char* resourceDir;
  233. const char* clientNamePrefix;
  234. bool preventBadBehaviour;
  235. uintptr_t frontendWinId;
  236. #ifndef CARLA_OS_WIN
  237. struct Wine {
  238. const char* executable;
  239. bool autoPrefix;
  240. const char* fallbackPrefix;
  241. bool rtPrio;
  242. int baseRtPrio;
  243. int serverRtPrio;
  244. Wine() noexcept;
  245. ~Wine() noexcept;
  246. CARLA_DECLARE_NON_COPY_STRUCT(Wine)
  247. } wine;
  248. #endif
  249. #ifndef DOXYGEN
  250. EngineOptions() noexcept;
  251. ~EngineOptions() noexcept;
  252. CARLA_DECLARE_NON_COPY_STRUCT(EngineOptions)
  253. #endif
  254. };
  255. /*!
  256. * Engine BBT Time information.
  257. */
  258. struct CARLA_API EngineTimeInfoBBT {
  259. bool valid;
  260. int32_t bar; //!< current bar
  261. int32_t beat; //!< current beat-within-bar
  262. double tick; //!< current tick-within-beat
  263. double barStartTick;
  264. float beatsPerBar; //!< time signature "numerator"
  265. float beatType; //!< time signature "denominator"
  266. double ticksPerBeat;
  267. double beatsPerMinute;
  268. /*!
  269. * Clear.
  270. */
  271. void clear() noexcept;
  272. #ifndef DOXYGEN
  273. EngineTimeInfoBBT() noexcept;
  274. EngineTimeInfoBBT(const EngineTimeInfoBBT&) noexcept;
  275. #endif
  276. };
  277. /*!
  278. * Engine Time information.
  279. */
  280. struct CARLA_API EngineTimeInfo {
  281. bool playing;
  282. uint64_t frame;
  283. uint64_t usecs;
  284. EngineTimeInfoBBT bbt;
  285. /*!
  286. * Clear.
  287. */
  288. void clear() noexcept;
  289. #ifndef DOXYGEN
  290. EngineTimeInfo() noexcept;
  291. EngineTimeInfo(const EngineTimeInfo&) noexcept;
  292. EngineTimeInfo& operator=(const EngineTimeInfo&) noexcept;
  293. // fast comparison, doesn't check all values
  294. bool compareIgnoringRollingFrames(const EngineTimeInfo& timeInfo, uint32_t maxFrames) const noexcept;
  295. // quick operator, doesn't check all values
  296. bool operator==(const EngineTimeInfo& timeInfo) const noexcept;
  297. bool operator!=(const EngineTimeInfo& timeInfo) const noexcept;
  298. #endif
  299. };
  300. // -----------------------------------------------------------------------
  301. /*!
  302. * Carla Engine port (Abstract).
  303. * This is the base class for all Carla Engine ports.
  304. */
  305. class CARLA_API CarlaEnginePort
  306. {
  307. protected:
  308. /*!
  309. * The constructor, protected.
  310. * All constructor parameters are constant and will never change in the lifetime of the port.
  311. */
  312. CarlaEnginePort(const CarlaEngineClient& client, bool isInputPort, uint32_t indexOffset) noexcept;
  313. public:
  314. /*!
  315. * The destructor.
  316. */
  317. virtual ~CarlaEnginePort() noexcept;
  318. /*!
  319. * Get the type of the port, as provided by the respective subclasses.
  320. */
  321. virtual EnginePortType getType() const noexcept = 0;
  322. /*!
  323. * Initialize the port's internal buffer.
  324. */
  325. virtual void initBuffer() noexcept = 0;
  326. /*!
  327. * Check if this port is an input.
  328. */
  329. inline bool isInput() const noexcept
  330. {
  331. return kIsInput;
  332. }
  333. /*!
  334. * Get the index offset as passed in the constructor.
  335. */
  336. inline uint32_t getIndexOffset() const noexcept
  337. {
  338. return kIndexOffset;
  339. }
  340. /*!
  341. * Get this ports' engine client.
  342. */
  343. inline const CarlaEngineClient& getEngineClient() const noexcept
  344. {
  345. return kClient;
  346. }
  347. /*!
  348. * Set a meta-data property on this port.
  349. */
  350. virtual void setMetaData(const char* key, const char* value, const char* type);
  351. #ifndef DOXYGEN
  352. protected:
  353. const CarlaEngineClient& kClient;
  354. const bool kIsInput;
  355. const uint32_t kIndexOffset;
  356. CARLA_DECLARE_NON_COPY_CLASS(CarlaEnginePort)
  357. #endif
  358. };
  359. /*!
  360. * Carla Engine Audio port.
  361. */
  362. class CARLA_API CarlaEngineAudioPort : public CarlaEnginePort
  363. {
  364. public:
  365. /*!
  366. * The constructor.
  367. * All constructor parameters are constant and will never change in the lifetime of the port.
  368. */
  369. CarlaEngineAudioPort(const CarlaEngineClient& client, bool isInputPort, uint32_t indexOffset) noexcept;
  370. /*!
  371. * The destructor.
  372. */
  373. ~CarlaEngineAudioPort() noexcept override;
  374. /*!
  375. * Get the type of the port, in this case kEnginePortTypeAudio.
  376. */
  377. inline EnginePortType getType() const noexcept final
  378. {
  379. return kEnginePortTypeAudio;
  380. }
  381. /*!
  382. * Initialize the port's internal buffer.
  383. */
  384. void initBuffer() noexcept override;
  385. /*!
  386. * Direct access to the port's audio buffer.
  387. * May be null.
  388. */
  389. inline float* getBuffer() const noexcept
  390. {
  391. return fBuffer;
  392. }
  393. #ifndef DOXYGEN
  394. protected:
  395. float* fBuffer;
  396. CARLA_DECLARE_NON_COPY_CLASS(CarlaEngineAudioPort)
  397. #endif
  398. };
  399. /*!
  400. * Carla Engine CV port.
  401. */
  402. class CARLA_API CarlaEngineCVPort : public CarlaEnginePort
  403. {
  404. public:
  405. /*!
  406. * The constructor.
  407. * All constructor parameters are constant and will never change in the lifetime of the port.
  408. */
  409. CarlaEngineCVPort(const CarlaEngineClient& client, bool isInputPort, uint32_t indexOffset) noexcept;
  410. /*!
  411. * The destructor.
  412. */
  413. ~CarlaEngineCVPort() noexcept override;
  414. /*!
  415. * Get the type of the port, in this case kEnginePortTypeCV.
  416. */
  417. inline EnginePortType getType() const noexcept final
  418. {
  419. return kEnginePortTypeCV;
  420. }
  421. /*!
  422. * Initialize the port's internal buffer.
  423. */
  424. void initBuffer() noexcept override;
  425. /*!
  426. * Direct access to the port's CV buffer.
  427. * May be null.
  428. */
  429. inline float* getBuffer() const noexcept
  430. {
  431. return fBuffer;
  432. }
  433. /*!
  434. * Get min/max range for this CV port.
  435. */
  436. inline void getRange(float& min, float& max) const noexcept
  437. {
  438. min = fMinimum;
  439. max = fMaximum;
  440. }
  441. /*!
  442. * Set min/max range for this CV port.
  443. */
  444. void setRange(float min, float max) noexcept;
  445. #ifndef DOXYGEN
  446. protected:
  447. float* fBuffer;
  448. float fMinimum, fMaximum;
  449. CARLA_DECLARE_NON_COPY_CLASS(CarlaEngineCVPort)
  450. #endif
  451. };
  452. /*!
  453. * Carla Engine Event port.
  454. */
  455. class CARLA_API CarlaEngineEventPort : public CarlaEnginePort
  456. {
  457. public:
  458. /*!
  459. * The constructor.
  460. * All constructor parameters are constant and will never change in the lifetime of the port.
  461. */
  462. CarlaEngineEventPort(const CarlaEngineClient& client, bool isInputPort, uint32_t indexOffset) noexcept;
  463. /*!
  464. * The destructor.
  465. */
  466. ~CarlaEngineEventPort() noexcept override;
  467. /*!
  468. * Get the type of the port, in this case kEnginePortTypeEvent.
  469. */
  470. inline EnginePortType getType() const noexcept final
  471. {
  472. return kEnginePortTypeEvent;
  473. }
  474. /*!
  475. * Initialize the port's internal buffer for @a engine.
  476. */
  477. void initBuffer() noexcept override;
  478. /*!
  479. * Get the number of events present in the buffer.
  480. * @note You must only call this for input ports.
  481. */
  482. virtual uint32_t getEventCount() const noexcept;
  483. /*!
  484. * Get the event at @a index.
  485. * @note You must only call this for input ports.
  486. */
  487. virtual EngineEvent& getEvent(uint32_t index) const noexcept;
  488. /*!
  489. * Get the event at @a index, faster unchecked version.
  490. */
  491. virtual EngineEvent& getEventUnchecked(uint32_t index) const noexcept;
  492. /*!
  493. * Write a control event into the buffer.
  494. * @note You must only call this for output ports.
  495. */
  496. bool writeControlEvent(uint32_t time, uint8_t channel, const EngineControlEvent& ctrl) noexcept;
  497. /*!
  498. * Write a control event into the buffer.
  499. * Arguments are the same as in the EngineControlEvent struct.
  500. * @note You must only call this for output ports.
  501. */
  502. virtual bool writeControlEvent(uint32_t time, uint8_t channel, EngineControlEventType type,
  503. uint16_t param, int8_t midiValue, float normalizedValue) noexcept;
  504. /*!
  505. * Write a MIDI event into the buffer.
  506. * @note You must only call this for output ports.
  507. */
  508. bool writeMidiEvent(uint32_t time, uint8_t size, const uint8_t* data) noexcept;
  509. /*!
  510. * Write a MIDI event into the buffer.
  511. * @note You must only call this for output ports.
  512. */
  513. bool writeMidiEvent(uint32_t time, uint8_t channel, const EngineMidiEvent& midi) noexcept;
  514. /*!
  515. * Write a MIDI event into the buffer.
  516. * Arguments are the same as in the EngineMidiEvent struct.
  517. * @note You must only call this for output ports.
  518. */
  519. virtual bool writeMidiEvent(uint32_t time, uint8_t channel, uint8_t size, const uint8_t* data) noexcept;
  520. #ifndef DOXYGEN
  521. protected:
  522. const EngineProcessMode kProcessMode;
  523. EngineEvent* fBuffer;
  524. friend class CarlaPluginInstance;
  525. friend class CarlaEngineCVSourcePorts;
  526. CARLA_DECLARE_NON_COPY_CLASS(CarlaEngineEventPort)
  527. #endif
  528. };
  529. // -----------------------------------------------------------------------
  530. /*!
  531. * Carla Engine Meta CV Port.
  532. * FIXME needs a better name...
  533. */
  534. class CARLA_API CarlaEngineCVSourcePorts
  535. {
  536. public:
  537. /*!
  538. * The destructor.
  539. */
  540. virtual ~CarlaEngineCVSourcePorts();
  541. /*!
  542. * Add a CV port as a source of events.
  543. */
  544. virtual bool addCVSource(CarlaEngineCVPort* port, uint32_t portIndexOffset, bool reconfigureNow);
  545. /*!
  546. * Remove a CV port as a source of events.
  547. */
  548. virtual bool removeCVSource(uint32_t portIndexOffset);
  549. /*!
  550. * Get events and add them to an event port.
  551. * FIXME needs a better name...
  552. */
  553. virtual void initPortBuffers(const float* const* buffers, uint32_t frames,
  554. bool sampleAccurate, CarlaEngineEventPort* eventPort);
  555. /*!
  556. * Set value range for a CV port.
  557. */
  558. bool setCVSourceRange(uint32_t portIndexOffset, float minimum, float maximum);
  559. /*!
  560. * Destroy all ports.
  561. */
  562. void cleanup();
  563. #ifndef DOXYGEN
  564. protected:
  565. /** @internal */
  566. struct ProtectedData;
  567. ProtectedData* const pData;
  568. /*!
  569. * The constructor, protected.
  570. */
  571. CarlaEngineCVSourcePorts();
  572. CARLA_DECLARE_NON_COPY_CLASS(CarlaEngineCVSourcePorts)
  573. #endif
  574. };
  575. // -----------------------------------------------------------------------
  576. /*!
  577. * Carla Engine Client.
  578. * Each plugin requires one client from the engine (created via CarlaEngine::addClient()).
  579. * @note This is a virtual class, some engine types provide custom functionality.
  580. */
  581. class CARLA_API CarlaEngineClient
  582. {
  583. public:
  584. /*!
  585. * The destructor.
  586. */
  587. virtual ~CarlaEngineClient() noexcept;
  588. /*!
  589. * Activate this client.
  590. * Client must be deactivated before calling this function.
  591. */
  592. virtual void activate() noexcept;
  593. /*!
  594. * Deactivate this client.
  595. * Client must be activated before calling this function.
  596. */
  597. virtual void deactivate(bool willClose) noexcept;
  598. /*!
  599. * Check if the client is activated.
  600. */
  601. virtual bool isActive() const noexcept;
  602. /*!
  603. * Check if the client is ok.
  604. * Plugins will refuse to instantiate if this returns false.
  605. * @note This is always true in rack and patchbay processing modes.
  606. */
  607. virtual bool isOk() const noexcept;
  608. /*!
  609. * Get the current latency, in samples.
  610. */
  611. virtual uint32_t getLatency() const noexcept;
  612. /*!
  613. * Change the client's latency.
  614. */
  615. virtual void setLatency(uint32_t samples) noexcept;
  616. /*!
  617. * Add a new port of type @a portType.
  618. * @note This function does nothing in rack processing mode since ports are static there.
  619. */
  620. virtual CarlaEnginePort* addPort(EnginePortType portType, const char* name, bool isInput, uint32_t indexOffset);
  621. /*!
  622. * Remove a previously added port via addPort().
  623. */
  624. virtual bool removePort(EnginePortType portType, const char* name, bool isInput);
  625. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  626. /*!
  627. * Create an instance of CV source ports.
  628. * Must be called only once per client.
  629. */
  630. virtual CarlaEngineCVSourcePorts* createCVSourcePorts();
  631. #endif
  632. /*!
  633. * Get this client's engine.
  634. */
  635. const CarlaEngine& getEngine() const noexcept;
  636. /*!
  637. * Get the engine's process mode.
  638. */
  639. EngineProcessMode getProcessMode() const noexcept;
  640. /*!
  641. * Get port count for a type and mode.
  642. */
  643. uint getPortCount(EnginePortType portType, bool isInput) const noexcept;
  644. /*!
  645. * Get an audio port name.
  646. */
  647. const char* getAudioPortName(bool isInput, uint index) const noexcept;
  648. /*!
  649. * Get a CV port name.
  650. */
  651. const char* getCVPortName(bool isInput, uint index) const noexcept;
  652. /*!
  653. * Get an event port name.
  654. */
  655. const char* getEventPortName(bool isInput, uint index) const noexcept;
  656. #ifndef DOXYGEN
  657. protected:
  658. /** @internal */
  659. struct ProtectedData;
  660. ProtectedData* const pData;
  661. /*!
  662. * The constructor, protected.
  663. */
  664. CarlaEngineClient(ProtectedData* pData);
  665. CARLA_DECLARE_NON_COPY_CLASS(CarlaEngineClient)
  666. #endif
  667. };
  668. // -----------------------------------------------------------------------
  669. /*!
  670. * Carla Engine.
  671. * @note This is a virtual class for all available engine types available in Carla.
  672. */
  673. class CARLA_API CarlaEngine
  674. {
  675. protected:
  676. /*!
  677. * The constructor, protected.
  678. * @note This only initializes engine data, it doesn't actually start the engine.
  679. */
  680. CarlaEngine();
  681. public:
  682. /*!
  683. * The destructor.
  684. * The engine must have been closed before this happens.
  685. */
  686. virtual ~CarlaEngine();
  687. // -------------------------------------------------------------------
  688. // Static calls
  689. /*!
  690. * Get the number of available engine drivers.
  691. */
  692. static uint getDriverCount();
  693. /*!
  694. * Get the name of the engine driver at @a index.
  695. */
  696. static const char* getDriverName(uint index);
  697. /*!
  698. * Get the device names of the driver at @a index.
  699. */
  700. static const char* const* getDriverDeviceNames(uint index);
  701. /*!
  702. * Get device information about the driver at @a index and name @a driverName.
  703. */
  704. static const EngineDriverDeviceInfo* getDriverDeviceInfo(uint index, const char* driverName);
  705. /*!
  706. * Show a device custom control panel.
  707. * @see ENGINE_DRIVER_DEVICE_HAS_CONTROL_PANEL
  708. */
  709. static bool showDriverDeviceControlPanel(uint index, const char* deviceName);
  710. /*!
  711. * Create a new engine, using driver @a driverName.
  712. * Returned value must be deleted when no longer needed.
  713. * @note This only initializes engine data, it doesn't actually start the engine.
  714. */
  715. static CarlaEngine* newDriverByName(const char* driverName);
  716. // -------------------------------------------------------------------
  717. // Constant values
  718. /*!
  719. * Maximum client name size.
  720. */
  721. virtual uint getMaxClientNameSize() const noexcept;
  722. /*!
  723. * Maximum port name size.
  724. */
  725. virtual uint getMaxPortNameSize() const noexcept;
  726. /*!
  727. * Current number of plugins loaded.
  728. */
  729. uint getCurrentPluginCount() const noexcept;
  730. /*!
  731. * Maximum number of loadable plugins allowed.
  732. * This function returns 0 if engine is not started.
  733. */
  734. uint getMaxPluginNumber() const noexcept;
  735. // -------------------------------------------------------------------
  736. // Virtual, per-engine type calls
  737. /*!
  738. * Initialize/start the engine, using @a clientName.
  739. * When the engine is initialized, you need to call idle() at regular intervals.
  740. */
  741. virtual bool init(const char* clientName) = 0;
  742. /*!
  743. * Close engine.
  744. * This function always closes the engine even if it returns false.
  745. * In other words, even when something goes wrong when closing the engine it still be closed nonetheless.
  746. */
  747. virtual bool close();
  748. /*!
  749. * Idle engine.
  750. */
  751. virtual void idle() noexcept;
  752. /*!
  753. * Check if engine is running.
  754. */
  755. virtual bool isRunning() const noexcept = 0;
  756. /*!
  757. * Check if engine is running offline (aka freewheel mode).
  758. */
  759. virtual bool isOffline() const noexcept = 0;
  760. /*!
  761. * Check if engine runs on a constant buffer size value.
  762. * Default implementation returns true.
  763. */
  764. virtual bool usesConstantBufferSize() const noexcept;
  765. /*!
  766. * Get engine type.
  767. */
  768. virtual EngineType getType() const noexcept = 0;
  769. /*!
  770. * Get the currently used driver name.
  771. */
  772. virtual const char* getCurrentDriverName() const noexcept = 0;
  773. /*!
  774. * Add new engine client.
  775. * @note This function must only be called within a plugin class.
  776. */
  777. virtual CarlaEngineClient* addClient(CarlaPluginPtr plugin);
  778. /*!
  779. * Get the current CPU load estimated by the engine.
  780. */
  781. virtual float getDSPLoad() const noexcept;
  782. /*!
  783. * Get the total number of xruns so far.
  784. */
  785. virtual uint32_t getTotalXruns() const noexcept;
  786. /*!
  787. * Clear the xrun count.
  788. */
  789. virtual void clearXruns() const noexcept;
  790. /*!
  791. * Dynamically change buffer size and/or sample rate while engine is running.
  792. * @see ENGINE_DRIVER_DEVICE_VARIABLE_BUFFER_SIZE
  793. * @see ENGINE_DRIVER_DEVICE_VARIABLE_SAMPLE_RATE
  794. */
  795. virtual bool setBufferSizeAndSampleRate(uint bufferSize, double sampleRate);
  796. /*!
  797. * Show the custom control panel for the current engine device.
  798. * @see ENGINE_DRIVER_DEVICE_HAS_CONTROL_PANEL
  799. */
  800. virtual bool showDeviceControlPanel() const noexcept;
  801. // -------------------------------------------------------------------
  802. // Plugin management
  803. /*!
  804. * Add new plugin.
  805. * @see ENGINE_CALLBACK_PLUGIN_ADDED
  806. */
  807. bool addPlugin(BinaryType btype, PluginType ptype,
  808. const char* filename, const char* name, const char* label, int64_t uniqueId,
  809. const void* extra, uint options = PLUGIN_OPTIONS_NULL);
  810. /*!
  811. * Add new plugin, using native binary type.
  812. * @see ENGINE_CALLBACK_PLUGIN_ADDED
  813. */
  814. bool addPlugin(PluginType ptype,
  815. const char* filename, const char* name, const char* label, int64_t uniqueId,
  816. const void* extra);
  817. /*!
  818. * Remove plugin with id @a id.
  819. * @see ENGINE_CALLBACK_PLUGIN_REMOVED
  820. */
  821. virtual bool removePlugin(uint id);
  822. /*!
  823. * Remove all plugins.
  824. */
  825. bool removeAllPlugins();
  826. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  827. /*!
  828. * Rename plugin with id @a id to @a newName.
  829. * Returns the new name, or null if the operation failed.
  830. * Returned variable must be deleted if non-null.
  831. * @see ENGINE_CALLBACK_PLUGIN_RENAMED
  832. */
  833. virtual bool renamePlugin(uint id, const char* newName);
  834. /*!
  835. * Clone plugin with id @a id.
  836. */
  837. bool clonePlugin(uint id);
  838. /*!
  839. * Prepare replace of plugin with id @a id.
  840. * The next call to addPlugin() will use this id, replacing the selected plugin.
  841. * @note This function requires addPlugin() to be called afterwards, as soon as possible.
  842. */
  843. bool replacePlugin(uint id) noexcept;
  844. /*!
  845. * Switch plugins with id @a idA and @a idB.
  846. */
  847. virtual bool switchPlugins(uint idA, uint idB) noexcept;
  848. #endif
  849. /*!
  850. * Set a plugin's parameter in drag/touch mode.
  851. * Usually happens from a UI when the user is moving a parameter with a mouse or similar input.
  852. *
  853. * @param parameterId The parameter to update
  854. * @param touch The new state for the parameter
  855. */
  856. virtual void touchPluginParameter(uint id, uint32_t parameterId, bool touch) noexcept;
  857. /*!
  858. * Get plugin with id @a id.
  859. */
  860. CarlaPluginPtr getPlugin(uint id) const noexcept;
  861. /*!
  862. * Get plugin with id @a id, faster unchecked version.
  863. */
  864. CarlaPluginPtr getPluginUnchecked(uint id) const noexcept;
  865. /*!
  866. * Get a unique plugin name within the engine.
  867. * Returned variable must be deleted if non-null.
  868. */
  869. const char* getUniquePluginName(const char* name) const;
  870. // -------------------------------------------------------------------
  871. // Project management
  872. /*!
  873. * Load a file of any type.
  874. * This will try to load a generic file as a plugin,
  875. * either by direct handling (SF2 and SFZ) or by using an internal plugin (like Audio and MIDI).
  876. */
  877. bool loadFile(const char* filename);
  878. /*!
  879. * Load a project file.
  880. * @note Already loaded plugins are not removed; call removeAllPlugins() first if needed.
  881. */
  882. bool loadProject(const char* filename, bool setAsCurrentProject);
  883. /*!
  884. * Save current project to a file.
  885. */
  886. bool saveProject(const char* filename, bool setAsCurrentProject);
  887. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  888. /*!
  889. * Get the currently set project folder.
  890. * @note Valid for both standalone and plugin versions.
  891. */
  892. virtual const char* getCurrentProjectFolder() const noexcept;
  893. /*!
  894. * Get the currently set project filename.
  895. * @note Valid only for both standalone version.
  896. */
  897. const char* getCurrentProjectFilename() const noexcept;
  898. /*!
  899. * Clear the currently set project filename.
  900. */
  901. void clearCurrentProjectFilename() noexcept;
  902. #endif
  903. // -------------------------------------------------------------------
  904. // Information (base)
  905. /*!
  906. * Get the current buffer size.
  907. */
  908. uint32_t getBufferSize() const noexcept;
  909. /*!
  910. * Get the current sample rate.
  911. */
  912. double getSampleRate() const noexcept;
  913. /*!
  914. * Get the current engine name.
  915. */
  916. const char* getName() const noexcept;
  917. /*!
  918. * Get the current engine process mode.
  919. */
  920. EngineProcessMode getProccessMode() const noexcept;
  921. /*!
  922. * Get the current engine options (read-only).
  923. */
  924. const EngineOptions& getOptions() const noexcept;
  925. /*!
  926. * Get the current Time information (read-only).
  927. */
  928. virtual EngineTimeInfo getTimeInfo() const noexcept;
  929. // -------------------------------------------------------------------
  930. // Information (peaks)
  931. /*!
  932. * Get a plugin's peak values.
  933. * @note not thread-safe if pluginId == MAIN_CARLA_PLUGIN_ID
  934. */
  935. const float* getPeaks(uint pluginId) const noexcept;
  936. /*!
  937. * Get a plugin's input peak value.
  938. */
  939. float getInputPeak(uint pluginId, bool isLeft) const noexcept;
  940. /*!
  941. * Get a plugin's output peak value.
  942. */
  943. float getOutputPeak(uint pluginId, bool isLeft) const noexcept;
  944. // -------------------------------------------------------------------
  945. // Callback
  946. /*!
  947. * Call the main engine callback, if set.
  948. * May be called by plugins.
  949. */
  950. virtual void callback(bool sendHost, bool sendOSC,
  951. EngineCallbackOpcode action, uint pluginId,
  952. int value1, int value2, int value3, float valuef, const char* valueStr) noexcept;
  953. /*!
  954. * Set the main engine callback to @a func.
  955. */
  956. void setCallback(EngineCallbackFunc func, void* ptr) noexcept;
  957. // -------------------------------------------------------------------
  958. // Callback
  959. /*!
  960. * Call the file callback, if set.
  961. * May be called by plugins.
  962. */
  963. virtual const char* runFileCallback(FileCallbackOpcode action,
  964. bool isDir, const char* title, const char* filter) noexcept;
  965. /*!
  966. * Set the file callback to @a func.
  967. */
  968. void setFileCallback(FileCallbackFunc func, void* ptr) noexcept;
  969. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  970. // -------------------------------------------------------------------
  971. // Patchbay
  972. /*!
  973. * Connect two patchbay ports.
  974. */
  975. virtual bool patchbayConnect(bool external,
  976. uint groupA, uint portA,
  977. uint groupB, uint portB);
  978. /*!
  979. * Remove a patchbay connection.
  980. */
  981. virtual bool patchbayDisconnect(bool external, uint connectionId);
  982. /*!
  983. * Set the position of a group.
  984. */
  985. virtual bool patchbaySetGroupPos(bool sendHost, bool sendOSC, bool external,
  986. uint groupId, int x1, int y1, int x2, int y2);
  987. /*!
  988. * Force the engine to resend all patchbay clients, ports and connections again.
  989. */
  990. virtual bool patchbayRefresh(bool sendHost, bool sendOSC, bool external);
  991. #endif
  992. // -------------------------------------------------------------------
  993. // Transport
  994. /*!
  995. * Start playback of the engine transport.
  996. */
  997. virtual void transportPlay() noexcept;
  998. /*!
  999. * Pause the engine transport.
  1000. */
  1001. virtual void transportPause() noexcept;
  1002. /*!
  1003. * Set the engine transport bpm to @a bpm.
  1004. */
  1005. virtual void transportBPM(double bpm) noexcept;
  1006. /*!
  1007. * Relocate the engine transport to @a frames.
  1008. */
  1009. virtual void transportRelocate(uint64_t frame) noexcept;
  1010. // -------------------------------------------------------------------
  1011. // Error handling
  1012. /*!
  1013. * Get last error.
  1014. */
  1015. const char* getLastError() const noexcept;
  1016. /*!
  1017. * Set last error.
  1018. */
  1019. void setLastError(const char* error) const noexcept;
  1020. // -------------------------------------------------------------------
  1021. // Misc
  1022. /*!
  1023. * Check if the engine is about to close.
  1024. */
  1025. bool isAboutToClose() const noexcept;
  1026. /*!
  1027. * Tell the engine it's about to close.
  1028. * This is used to prevent the engine thread(s) from reactivating.
  1029. * Returns true if there's no pending engine events.
  1030. */
  1031. bool setAboutToClose() noexcept;
  1032. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  1033. /*!
  1034. * TODO.
  1035. */
  1036. bool isLoadingProject() const noexcept;
  1037. #endif
  1038. /*!
  1039. * Tell the engine to stop the current cancelable action.
  1040. * @see ENGINE_CALLBACK_CANCELABLE_ACTION
  1041. */
  1042. void setActionCanceled(bool canceled) noexcept;
  1043. /*!
  1044. * Check wherever the last cancelable action was indeed canceled or not.
  1045. */
  1046. bool wasActionCanceled() const noexcept;
  1047. // -------------------------------------------------------------------
  1048. // Options
  1049. /*!
  1050. * Set the engine option @a option to @a value or @a valueStr.
  1051. */
  1052. virtual void setOption(EngineOption option, int value, const char* valueStr) noexcept;
  1053. // -------------------------------------------------------------------
  1054. // OSC Stuff
  1055. #ifndef BUILD_BRIDGE
  1056. /*!
  1057. * Check if OSC controller is registered.
  1058. */
  1059. bool isOscControlRegistered() const noexcept;
  1060. /*!
  1061. * Get OSC TCP server path.
  1062. */
  1063. const char* getOscServerPathTCP() const noexcept;
  1064. /*!
  1065. * Get OSC UDP server path.
  1066. */
  1067. const char* getOscServerPathUDP() const noexcept;
  1068. #endif
  1069. // -------------------------------------------------------------------
  1070. protected:
  1071. /*!
  1072. * Internal data, for CarlaEngine subclasses and friends.
  1073. */
  1074. struct ProtectedData;
  1075. ProtectedData* const pData;
  1076. /*!
  1077. * Some internal classes read directly from pData or call protected functions.
  1078. */
  1079. friend class CarlaEngineEventPort;
  1080. friend class CarlaEngineOsc;
  1081. friend class CarlaEngineThread;
  1082. friend class CarlaPluginInstance;
  1083. friend class EngineInternalGraph;
  1084. friend class PendingRtEventsRunner;
  1085. friend class ScopedActionLock;
  1086. friend class ScopedEngineEnvironmentLocker;
  1087. friend class ScopedThreadStopper;
  1088. friend class PatchbayGraph;
  1089. friend struct ExternalGraph;
  1090. friend struct RackGraph;
  1091. // -------------------------------------------------------------------
  1092. // Internal stuff
  1093. /*!
  1094. * Report to all plugins about buffer size change.
  1095. */
  1096. void bufferSizeChanged(uint32_t newBufferSize);
  1097. /*!
  1098. * Report to all plugins about sample rate change.
  1099. * This is not supported on all plugin types, in which case they will have to be re-initiated.
  1100. */
  1101. void sampleRateChanged(double newSampleRate);
  1102. /*!
  1103. * Report to all plugins about offline mode change.
  1104. */
  1105. void offlineModeChanged(bool isOffline);
  1106. /*!
  1107. * Set a plugin (stereo) peak values.
  1108. * @note RT call
  1109. */
  1110. void setPluginPeaksRT(uint pluginId, float const inPeaks[2], float const outPeaks[2]) noexcept;
  1111. public:
  1112. /*!
  1113. * Common save project function for main engine and plugin.
  1114. */
  1115. void saveProjectInternal(water::MemoryOutputStream& outStrm) const;
  1116. /*!
  1117. * Common load project function for main engine and plugin.
  1118. */
  1119. bool loadProjectInternal(water::XmlDocument& xmlDoc, bool alwaysLoadConnections);
  1120. protected:
  1121. // -------------------------------------------------------------------
  1122. // Helper functions
  1123. /*!
  1124. * Return internal data, needed for EventPorts when used in Rack, Patchbay and Bridge modes.
  1125. * @note RT call
  1126. */
  1127. EngineEvent* getInternalEventBuffer(bool isInput) const noexcept;
  1128. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  1129. // -------------------------------------------------------------------
  1130. // Patchbay stuff
  1131. /*!
  1132. * Virtual functions for handling patchbay state.
  1133. * Do not free returned data.
  1134. */
  1135. struct PatchbayPosition { const char* name; int x1, y1, x2, y2, pluginId; bool dealloc; };
  1136. virtual const char* const* getPatchbayConnections(bool external) const;
  1137. virtual const PatchbayPosition* getPatchbayPositions(bool external, uint& count) const;
  1138. virtual void restorePatchbayConnection(bool external, const char* sourcePort, const char* targetPort);
  1139. // returns true if plugin name mapping found, ppos.name updated to its converted name
  1140. virtual bool restorePatchbayGroupPosition(bool external, PatchbayPosition& ppos);
  1141. /*!
  1142. * Virtual functions for handling external graph ports.
  1143. */
  1144. virtual bool connectExternalGraphPort(uint, uint, const char*);
  1145. virtual bool disconnectExternalGraphPort(uint, uint, const char*);
  1146. #endif
  1147. // -------------------------------------------------------------------
  1148. CARLA_DECLARE_NON_COPY_CLASS(CarlaEngine)
  1149. };
  1150. /**@}*/
  1151. // -----------------------------------------------------------------------
  1152. CARLA_BACKEND_END_NAMESPACE
  1153. #endif // CARLA_ENGINE_HPP_INCLUDED