Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CarlaEngine.hpp 34KB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
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
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
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
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
11 years ago
11 years ago
12 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
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
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
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
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
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
10 years ago
10 years ago
11 years ago
10 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
10 years ago
11 years ago
10 years ago
11 years ago
11 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196
  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. // -----------------------------------------------------------------------
  24. CARLA_BACKEND_START_NAMESPACE
  25. #if 0
  26. } /* Fix editor indentation */
  27. #endif
  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.\n
  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.\n
  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 to 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* binaryDir;
  202. const char* resourceDir;
  203. uintptr_t frontendWinId;
  204. #ifndef DOXYGEN
  205. EngineOptions() noexcept;
  206. ~EngineOptions() noexcept;
  207. #endif
  208. };
  209. /*!
  210. * Engine BBT Time information.
  211. */
  212. struct EngineTimeInfoBBT {
  213. int32_t bar; //!< current bar
  214. int32_t beat; //!< current beat-within-bar
  215. int32_t tick; //!< current tick-within-beat
  216. double barStartTick;
  217. float beatsPerBar; //!< time signature "numerator"
  218. float beatType; //!< time signature "denominator"
  219. double ticksPerBeat;
  220. double beatsPerMinute;
  221. #ifndef DOXYGEN
  222. EngineTimeInfoBBT() noexcept;
  223. #endif
  224. };
  225. /*!
  226. * Engine Time information.
  227. */
  228. struct EngineTimeInfo {
  229. static const uint kValidBBT = 0x1;
  230. bool playing;
  231. uint64_t frame;
  232. uint64_t usecs;
  233. uint valid;
  234. EngineTimeInfoBBT bbt;
  235. /*!
  236. * Clear.
  237. */
  238. void clear() noexcept;
  239. #ifndef DOXYGEN
  240. EngineTimeInfo() noexcept;
  241. // quick operator, doesn't check all values
  242. bool operator==(const EngineTimeInfo& timeInfo) const noexcept;
  243. bool operator!=(const EngineTimeInfo& timeInfo) const noexcept;
  244. #endif
  245. };
  246. // -----------------------------------------------------------------------
  247. /*!
  248. * Carla Engine port (Abstract).\n
  249. * This is the base class for all Carla Engine ports.
  250. */
  251. class CarlaEnginePort
  252. {
  253. protected:
  254. /*!
  255. * The constructor.\n
  256. * Param \a isInputPort defines wherever this is an input port or not (output otherwise).\n
  257. * Input/output and process mode are constant for the lifetime of the port.
  258. */
  259. CarlaEnginePort(const CarlaEngineClient& client, const bool isInputPort) noexcept;
  260. public:
  261. /*!
  262. * The destructor.
  263. */
  264. virtual ~CarlaEnginePort() noexcept;
  265. /*!
  266. * Get the type of the port, as provided by the respective subclasses.
  267. */
  268. virtual EnginePortType getType() const noexcept = 0;
  269. /*!
  270. * Initialize the port's internal buffer.
  271. */
  272. virtual void initBuffer() noexcept = 0;
  273. /*!
  274. * Check if this port is an input.
  275. */
  276. bool isInput() const noexcept
  277. {
  278. return fIsInput;
  279. }
  280. /*!
  281. * Get this ports' engine client.
  282. */
  283. const CarlaEngineClient& getEngineClient() const noexcept
  284. {
  285. return fClient;
  286. }
  287. #ifndef DOXYGEN
  288. protected:
  289. const CarlaEngineClient& fClient;
  290. const bool fIsInput;
  291. CARLA_DECLARE_NON_COPY_CLASS(CarlaEnginePort)
  292. #endif
  293. };
  294. /*!
  295. * Carla Engine Audio port.
  296. */
  297. class CarlaEngineAudioPort : public CarlaEnginePort
  298. {
  299. public:
  300. /*!
  301. * The constructor.\n
  302. * All constructor parameters are constant and will never change in the lifetime of the port.
  303. */
  304. CarlaEngineAudioPort(const CarlaEngineClient& client, const bool isInputPort) noexcept;
  305. /*!
  306. * The destructor.
  307. */
  308. ~CarlaEngineAudioPort() noexcept override;
  309. /*!
  310. * Get the type of the port, in this case kEnginePortTypeAudio.
  311. */
  312. EnginePortType getType() const noexcept override
  313. {
  314. return kEnginePortTypeAudio;
  315. }
  316. /*!
  317. * Initialize the port's internal buffer.
  318. */
  319. virtual void initBuffer() noexcept override;
  320. /*!
  321. * Direct access to the port's audio buffer.
  322. * May return null.
  323. */
  324. float* getBuffer() const noexcept
  325. {
  326. return fBuffer;
  327. }
  328. #ifndef DOXYGEN
  329. protected:
  330. float* fBuffer;
  331. CARLA_DECLARE_NON_COPY_CLASS(CarlaEngineAudioPort)
  332. #endif
  333. };
  334. /*!
  335. * Carla Engine CV port.
  336. */
  337. class CarlaEngineCVPort : public CarlaEnginePort
  338. {
  339. public:
  340. /*!
  341. * The constructor.\n
  342. * All constructor parameters are constant and will never change in the lifetime of the port.
  343. */
  344. CarlaEngineCVPort(const CarlaEngineClient& client, const bool isInputPort) noexcept;
  345. /*!
  346. * The destructor.
  347. */
  348. ~CarlaEngineCVPort() noexcept override;
  349. /*!
  350. * Get the type of the port, in this case kEnginePortTypeCV.
  351. */
  352. EnginePortType getType() const noexcept override
  353. {
  354. return kEnginePortTypeCV;
  355. }
  356. /*!
  357. * Initialize the port's internal buffer for \a engine.
  358. */
  359. void initBuffer() noexcept override;
  360. /*!
  361. * Direct access to the port's CV buffer.
  362. * May return null.
  363. */
  364. float* getBuffer() const noexcept
  365. {
  366. return fBuffer;
  367. }
  368. #ifndef DOXYGEN
  369. protected:
  370. float* fBuffer;
  371. CARLA_DECLARE_NON_COPY_CLASS(CarlaEngineCVPort)
  372. #endif
  373. };
  374. /*!
  375. * Carla Engine Event port.
  376. */
  377. class CarlaEngineEventPort : public CarlaEnginePort
  378. {
  379. public:
  380. /*!
  381. * The constructor.\n
  382. * All constructor parameters are constant and will never change in the lifetime of the port.
  383. */
  384. CarlaEngineEventPort(const CarlaEngineClient& client, const bool isInputPort) noexcept;
  385. /*!
  386. * The destructor.
  387. */
  388. ~CarlaEngineEventPort() noexcept override;
  389. /*!
  390. * Get the type of the port, in this case kEnginePortTypeEvent.
  391. */
  392. EnginePortType getType() const noexcept override
  393. {
  394. return kEnginePortTypeEvent;
  395. }
  396. /*!
  397. * Initialize the port's internal buffer for \a engine.
  398. */
  399. void initBuffer() noexcept override;
  400. /*!
  401. * Get the number of events present in the buffer.
  402. * \note You must only call this for input ports.
  403. */
  404. virtual uint32_t getEventCount() const noexcept;
  405. /*!
  406. * Get the event at \a index.
  407. * \note You must only call this for input ports.
  408. */
  409. virtual const EngineEvent& getEvent(const uint32_t index) const noexcept;
  410. /*!
  411. * Get the event at \a index, faster unchecked version.
  412. */
  413. virtual const EngineEvent& getEventUnchecked(const uint32_t index) const noexcept;
  414. /*!
  415. * Write a control event into the buffer.\n
  416. * Arguments are the same as in the EngineControlEvent struct.
  417. * \note You must only call this for output ports.
  418. */
  419. virtual bool writeControlEvent(const uint32_t time, const uint8_t channel, const EngineControlEventType type, const uint16_t param, const float value = 0.0f) noexcept;
  420. /*!
  421. * Write a control event into the buffer, overloaded call.
  422. */
  423. bool writeControlEvent(const uint32_t time, const uint8_t channel, const EngineControlEvent& ctrl) noexcept;
  424. /*!
  425. * Write a MIDI event into the buffer.\n
  426. * Arguments are the same as in the EngineMidiEvent struct.
  427. * \note You must only call this for output ports.
  428. */
  429. 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;
  430. /*!
  431. * Write a MIDI event into the buffer, overloaded call.
  432. */
  433. bool writeMidiEvent(const uint32_t time, const uint8_t size, const uint8_t* const data) noexcept;
  434. /*!
  435. * Write a MIDI event into the buffer, overloaded call.
  436. */
  437. bool writeMidiEvent(const uint32_t time, const uint8_t channel, const EngineMidiEvent& midi) noexcept;
  438. #ifndef DOXYGEN
  439. protected:
  440. EngineEvent* fBuffer;
  441. const EngineProcessMode fProcessMode;
  442. CARLA_DECLARE_NON_COPY_CLASS(CarlaEngineEventPort)
  443. #endif
  444. };
  445. // -----------------------------------------------------------------------
  446. /*!
  447. * Carla Engine client.\n
  448. * Each plugin requires one client from the engine (created via CarlaEngine::addClient()).\n
  449. * \note This is a virtual class, some engine types provide custom funtionality.
  450. */
  451. class CarlaEngineClient
  452. {
  453. public:
  454. /*!
  455. * The constructor, protected.\n
  456. * All constructor parameters are constant and will never change in the lifetime of the client.\n
  457. * Client starts in deactivated state.
  458. */
  459. CarlaEngineClient(const CarlaEngine& engine);
  460. /*!
  461. * The destructor.
  462. */
  463. virtual ~CarlaEngineClient();
  464. /*!
  465. * Activate this client.\n
  466. * Client must be deactivated before calling this function.
  467. */
  468. virtual void activate() noexcept;
  469. /*!
  470. * Deactivate this client.\n
  471. * Client must be activated before calling this function.
  472. */
  473. virtual void deactivate() noexcept;
  474. /*!
  475. * Check if the client is activated.
  476. */
  477. virtual bool isActive() const noexcept;
  478. /*!
  479. * Check if the client is ok.\n
  480. * Plugins will refuse to instantiate if this returns false.
  481. * \note This is always true in rack and patchbay processing modes.
  482. */
  483. virtual bool isOk() const noexcept;
  484. /*!
  485. * Get the current latency, in samples.
  486. */
  487. virtual uint32_t getLatency() const noexcept;
  488. /*!
  489. * Change the client's latency.
  490. */
  491. virtual void setLatency(const uint32_t samples) noexcept;
  492. /*!
  493. * Add a new port of type \a portType.
  494. * \note This function does nothing in rack processing mode since ports are static there (2 audio + 1 event for both input and output).
  495. */
  496. virtual CarlaEnginePort* addPort(const EnginePortType portType, const char* const name, const bool isInput);
  497. /*!
  498. * Get this client's engine.
  499. */
  500. const CarlaEngine& getEngine() const noexcept
  501. {
  502. return fEngine;
  503. }
  504. #ifndef DOXYGEN
  505. protected:
  506. const CarlaEngine& fEngine;
  507. bool fActive;
  508. uint32_t fLatency;
  509. CARLA_DECLARE_NON_COPY_CLASS(CarlaEngineClient)
  510. #endif
  511. };
  512. // -----------------------------------------------------------------------
  513. /*!
  514. * Protected data used in CarlaEngine and subclasses.\n
  515. * Non-engine code MUST NEVER have direct access to this.
  516. */
  517. struct CarlaEngineProtectedData;
  518. /*!
  519. * Carla Engine.
  520. * \note This is a virtual class for all available engine types available in Carla.
  521. */
  522. class CarlaEngine
  523. {
  524. protected:
  525. /*!
  526. * The constructor, protected.\n
  527. * \note This only initializes engine data, it doesn't start the engine (audio).
  528. */
  529. CarlaEngine();
  530. public:
  531. /*!
  532. * The decontructor.
  533. * The engine must have been closed before this happens.
  534. */
  535. virtual ~CarlaEngine();
  536. // -------------------------------------------------------------------
  537. // Static calls
  538. /*!
  539. * Get the number of available engine drivers.
  540. */
  541. static uint getDriverCount();
  542. /*!
  543. * Get the name of the engine driver at \a index.
  544. */
  545. static const char* getDriverName(const uint index);
  546. /*!
  547. * Get the device names of driver at \a index.
  548. */
  549. static const char* const* getDriverDeviceNames(const uint index);
  550. /*!
  551. * Get the device names of driver at \a index.
  552. */
  553. static const EngineDriverDeviceInfo* getDriverDeviceInfo(const uint index, const char* const driverName);
  554. /*!
  555. * Create a new engine, using driver \a driverName. \n
  556. * Returned variable must be deleted when no longer needed.
  557. * \note This only initializes engine data, it doesn't initialize the engine itself.
  558. */
  559. static CarlaEngine* newDriverByName(const char* const driverName);
  560. // -------------------------------------------------------------------
  561. // Constant values
  562. /*!
  563. * Maximum client name size.
  564. */
  565. virtual uint getMaxClientNameSize() const noexcept;
  566. /*!
  567. * Maximum port name size.
  568. */
  569. virtual uint getMaxPortNameSize() const noexcept;
  570. /*!
  571. * Current number of plugins loaded.
  572. */
  573. uint getCurrentPluginCount() const noexcept;
  574. /*!
  575. * Maximum number of loadable plugins allowed.
  576. * \note This function returns 0 if engine is not started.
  577. */
  578. uint getMaxPluginNumber() const noexcept;
  579. // -------------------------------------------------------------------
  580. // Virtual, per-engine type calls
  581. /*!
  582. * Initialize engine, using \a clientName.
  583. */
  584. virtual bool init(const char* const clientName);
  585. /*!
  586. * Close engine.
  587. */
  588. virtual bool close();
  589. /*!
  590. * Idle engine.
  591. */
  592. virtual void idle();
  593. /*!
  594. * Check if engine is running.
  595. */
  596. virtual bool isRunning() const noexcept = 0;
  597. /*!
  598. * Check if engine is running offline (aka freewheel mode).
  599. */
  600. virtual bool isOffline() const noexcept = 0;
  601. /*!
  602. * Get engine type.
  603. */
  604. virtual EngineType getType() const noexcept = 0;
  605. /*!
  606. * Get the currently used driver name.
  607. */
  608. virtual const char* getCurrentDriverName() const noexcept = 0;
  609. /*!
  610. * Add new engine client.
  611. * \note This function must only be called within a plugin class.
  612. */
  613. virtual CarlaEngineClient* addClient(CarlaPlugin* const plugin);
  614. // -------------------------------------------------------------------
  615. // Plugin management
  616. /*!
  617. * Add new plugin.
  618. */
  619. 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);
  620. /*!
  621. * Add new plugin, using native binary type.
  622. */
  623. 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);
  624. /*!
  625. * Remove plugin with id \a id.
  626. */
  627. bool removePlugin(const uint id);
  628. /*!
  629. * Remove all plugins.
  630. */
  631. bool removeAllPlugins();
  632. /*!
  633. * Rename plugin with id \a id to \a newName.\n
  634. * Returns the new name, or nullptr if the operation failed.
  635. */
  636. virtual const char* renamePlugin(const uint id, const char* const newName);
  637. /*!
  638. * Clone plugin with id \a id.
  639. */
  640. bool clonePlugin(const uint id);
  641. /*!
  642. * Prepare replace of plugin with id \a id.\n
  643. * The next call to addPlugin() will use this id, replacing the selected plugin.
  644. * \note This function requires addPlugin() to be called afterwards, as soon as possible.
  645. */
  646. bool replacePlugin(const uint id);
  647. /*!
  648. * Switch plugins with id \a idA and \a idB.
  649. */
  650. bool switchPlugins(const uint idA, const uint idB);
  651. /*!
  652. * Get plugin with id \a id.
  653. */
  654. CarlaPlugin* getPlugin(const uint id) const;
  655. /*!
  656. * Get plugin with id \a id, faster unchecked version.
  657. */
  658. CarlaPlugin* getPluginUnchecked(const uint id) const noexcept;
  659. /*!
  660. * Get a unique plugin name within the engine.\n
  661. * Returned variable must be deleted if non-NULL.
  662. */
  663. const char* getUniquePluginName(const char* const name) const;
  664. // -------------------------------------------------------------------
  665. // Project management
  666. /*!
  667. * Load a file of any type.\n
  668. * This will try to load a generic file as a plugin,
  669. * either by direct handling (GIG, SF2 and SFZ) or by using an internal plugin (like Audio and MIDI).
  670. */
  671. bool loadFile(const char* const filename);
  672. /*!
  673. * Load a project file.
  674. * @note Already loaded plugins are not removed; call removeAllPlugins() first if needed.
  675. */
  676. bool loadProject(const char* const filename);
  677. /*!
  678. * Save current project to a file.
  679. */
  680. bool saveProject(const char* const filename);
  681. // -------------------------------------------------------------------
  682. // Information (base)
  683. /*!
  684. * Get the current engine driver hints.
  685. */
  686. uint getHints() const noexcept;
  687. /*!
  688. * Get the current buffer size.
  689. */
  690. uint32_t getBufferSize() const noexcept;
  691. /*!
  692. * Get the current sample rate.
  693. */
  694. double getSampleRate() const noexcept;
  695. /*!
  696. * Get the current engine name.
  697. */
  698. const char* getName() const noexcept;
  699. /*!
  700. * Get the current engine proccess mode.
  701. */
  702. EngineProcessMode getProccessMode() const noexcept;
  703. /*!
  704. * Get the current engine options (read-only).
  705. */
  706. const EngineOptions& getOptions() const noexcept;
  707. /*!
  708. * Get the current Time information (read-only).
  709. */
  710. const EngineTimeInfo& getTimeInfo() const noexcept;
  711. // -------------------------------------------------------------------
  712. // Information (peaks)
  713. /*!
  714. * TODO.
  715. */
  716. float getInputPeak(const uint pluginId, const bool isLeft) const noexcept;
  717. /*!
  718. * TODO.
  719. */
  720. float getOutputPeak(const uint pluginId, const bool isLeft) const noexcept;
  721. // -------------------------------------------------------------------
  722. // Callback
  723. /*!
  724. * Run the main engine callback, if set.
  725. * May be called by plugins.
  726. */
  727. void callback(const EngineCallbackOpcode action, const uint pluginId, const int value1, const int value2, const float value3, const char* const valueStr) noexcept;
  728. /*!
  729. * Set the main engine callback.
  730. */
  731. void setCallback(const EngineCallbackFunc func, void* const ptr) noexcept;
  732. // -------------------------------------------------------------------
  733. // Callback
  734. /*!
  735. * Run the file callback, if set.
  736. * May be called by plugins.
  737. */
  738. const char* runFileCallback(const FileCallbackOpcode action, const bool isDir, const char* const title, const char* const filter) noexcept;
  739. /*!
  740. * Set the file callback.
  741. */
  742. void setFileCallback(const FileCallbackFunc func, void* const ptr) noexcept;
  743. #ifndef BUILD_BRIDGE
  744. // -------------------------------------------------------------------
  745. // Patchbay
  746. /*!
  747. * Connect patchbay ports \a portA and \a portB.
  748. */
  749. virtual bool patchbayConnect(const int groupA, const int portA, const int groupB, const int portB);
  750. /*!
  751. * Disconnect patchbay connection \a connectionId.
  752. */
  753. virtual bool patchbayDisconnect(const uint connectionId);
  754. /*!
  755. * Force the engine to resend all patchbay clients, ports and connections again.
  756. */
  757. virtual bool patchbayRefresh();
  758. #endif
  759. // -------------------------------------------------------------------
  760. // Transport
  761. /*!
  762. * Start playback of the engine transport.
  763. */
  764. virtual void transportPlay() noexcept;
  765. /*!
  766. * Pause the engine transport.
  767. */
  768. virtual void transportPause() noexcept;
  769. /*!
  770. * Relocate the engine transport to \a frames.
  771. */
  772. virtual void transportRelocate(const uint64_t frame) noexcept;
  773. // -------------------------------------------------------------------
  774. // Error handling
  775. /*!
  776. * Get last error.
  777. */
  778. const char* getLastError() const noexcept;
  779. /*!
  780. * Set last error.
  781. */
  782. void setLastError(const char* const error) const noexcept;
  783. // -------------------------------------------------------------------
  784. // Misc
  785. /*!
  786. * Tell the engine it's about to close.\n
  787. * This is used to prevent the engine thread(s) from reactivating.
  788. */
  789. void setAboutToClose() noexcept;
  790. // -------------------------------------------------------------------
  791. // Options
  792. /*!
  793. * Set the engine option \a option.
  794. */
  795. void setOption(const EngineOption option, const int value, const char* const valueStr);
  796. // -------------------------------------------------------------------
  797. // OSC Stuff
  798. #ifdef BUILD_BRIDGE
  799. /*!
  800. * Check if OSC bridge is registered.
  801. */
  802. bool isOscBridgeRegistered() const noexcept;
  803. #else
  804. /*!
  805. * Check if OSC controller is registered.
  806. */
  807. bool isOscControlRegistered() const noexcept;
  808. #endif
  809. /*!
  810. * Idle OSC.
  811. */
  812. void idleOsc() const noexcept;
  813. /*!
  814. * Get OSC TCP server path.
  815. */
  816. const char* getOscServerPathTCP() const noexcept;
  817. /*!
  818. * Get OSC UDP server path.
  819. */
  820. const char* getOscServerPathUDP() const noexcept;
  821. #ifdef BUILD_BRIDGE
  822. /*!
  823. * Set OSC bridge data.
  824. */
  825. void setOscBridgeData(const CarlaOscData* const oscData) const noexcept;
  826. #endif
  827. // -------------------------------------------------------------------
  828. // Helper functions
  829. /*!
  830. * Return internal data, needed for EventPorts when used in Rack and Bridge modes.
  831. * \note RT call
  832. */
  833. EngineEvent* getInternalEventBuffer(const bool isInput) const noexcept;
  834. /*!
  835. * Force register a plugin into slot \a id. \n
  836. * This is needed so we can receive OSC events for a plugin while it initializes.
  837. */
  838. void registerEnginePlugin(const uint id, CarlaPlugin* const plugin) noexcept;
  839. #ifndef BUILD_BRIDGE
  840. /*!
  841. * Virtual functions for handling MIDI ports in the rack graph.
  842. */
  843. virtual bool connectRackMidiInPort(const int) { return false; }
  844. virtual bool connectRackMidiOutPort(const int) { return false; }
  845. virtual bool disconnectRackMidiInPort(const int) { return false; }
  846. virtual bool disconnectRackMidiOutPort(const int) { return false; }
  847. #endif
  848. // -------------------------------------------------------------------
  849. protected:
  850. /*!
  851. * Internal data, for CarlaEngine subclasses only.
  852. */
  853. CarlaEngineProtectedData* const pData;
  854. friend struct CarlaEngineProtectedData;
  855. // -------------------------------------------------------------------
  856. // Internal stuff
  857. /*!
  858. * Report to all plugins about buffer size change.
  859. */
  860. void bufferSizeChanged(const uint32_t newBufferSize);
  861. /*!
  862. * Report to all plugins about sample rate change.\n
  863. * This is not supported on all plugin types, in which case they will have to be re-initiated.
  864. */
  865. void sampleRateChanged(const double newSampleRate);
  866. /*!
  867. * Report to all plugins about offline mode change.
  868. */
  869. void offlineModeChanged(const bool isOffline);
  870. /*!
  871. * Run any pending RT events.\n
  872. * Must always be called at the end of audio processing.
  873. * \note RT call
  874. */
  875. void runPendingRtEvents() noexcept;
  876. /*!
  877. * Set a plugin (stereo) peak values.
  878. * \note RT call
  879. */
  880. void setPluginPeaks(const uint pluginId, float const inPeaks[2], float const outPeaks[2]) noexcept;
  881. #ifndef BUILD_BRIDGE
  882. // -------------------------------------------------------------------
  883. // Patchbay stuff
  884. /*!
  885. * Virtual functions for handling patchbay state.
  886. */
  887. virtual const char* const* getPatchbayConnections() const;
  888. virtual void restorePatchbayConnection(const char* const sourcePort, const char* const targetPort);
  889. #endif
  890. // -------------------------------------------------------------------
  891. public:
  892. /*!
  893. * Native audio APIs.
  894. */
  895. enum AudioApi {
  896. AUDIO_API_NULL = 0,
  897. // common
  898. AUDIO_API_JACK = 1,
  899. // linux
  900. AUDIO_API_ALSA = 2,
  901. AUDIO_API_OSS = 3,
  902. AUDIO_API_PULSE = 4,
  903. // macos
  904. AUDIO_API_CORE = 5,
  905. // windows
  906. AUDIO_API_ASIO = 6,
  907. AUDIO_API_DS = 7
  908. };
  909. // -------------------------------------------------------------------
  910. // Engine initializers
  911. // JACK
  912. static CarlaEngine* newJack();
  913. #ifndef BUILD_BRIDGE
  914. // RtAudio
  915. static CarlaEngine* newRtAudio(const AudioApi api);
  916. static uint getRtAudioApiCount();
  917. static const char* getRtAudioApiName(const uint index);
  918. static const char* const* getRtAudioApiDeviceNames(const uint index);
  919. static const EngineDriverDeviceInfo* getRtAudioDeviceInfo(const uint index, const char* const deviceName);
  920. // Juce
  921. static CarlaEngine* newJuce(const AudioApi api);
  922. static uint getJuceApiCount();
  923. static const char* getJuceApiName(const uint index);
  924. static const char* const* getJuceApiDeviceNames(const uint index);
  925. static const EngineDriverDeviceInfo* getJuceDeviceInfo(const uint index, const char* const deviceName);
  926. #else
  927. // Bridge
  928. static CarlaEngine* newBridge(const char* const audioBaseName, const char* const controlBaseName, const char* const timeBaseName);
  929. #endif
  930. // -------------------------------------------------------------------
  931. // Bridge/Controller OSC stuff
  932. #ifdef BUILD_BRIDGE
  933. void oscSend_bridge_plugin_info1(const PluginCategory category, const uint hints, const int64_t uniqueId) const noexcept;
  934. void oscSend_bridge_plugin_info2(const char* const realName, const char* const label, const char* const maker, const char* const copyright) const noexcept;
  935. void oscSend_bridge_audio_count(const uint32_t ins, const uint32_t outs) const noexcept;
  936. void oscSend_bridge_midi_count(const uint32_t ins, const uint32_t outs) const noexcept;
  937. void oscSend_bridge_parameter_count(const uint32_t ins, const uint32_t outs) const noexcept;
  938. void oscSend_bridge_program_count(const uint32_t count) const noexcept;
  939. void oscSend_bridge_midi_program_count(const uint32_t count) const noexcept;
  940. void oscSend_bridge_parameter_data(const uint32_t index, const int32_t rindex, const ParameterType type, const uint hints, const char* const name, const char* const unit) const noexcept;
  941. void oscSend_bridge_parameter_ranges1(const uint32_t index, const float def, const float min, const float max) const noexcept;
  942. void oscSend_bridge_parameter_ranges2(const uint32_t index, const float step, const float stepSmall, const float stepLarge) const noexcept;
  943. void oscSend_bridge_parameter_midi_cc(const uint32_t index, const int16_t cc) const noexcept;
  944. void oscSend_bridge_parameter_midi_channel(const uint32_t index, const uint8_t channel) const noexcept;
  945. void oscSend_bridge_parameter_value(const uint32_t index, const float value) const noexcept;
  946. void oscSend_bridge_default_value(const uint32_t index, const float value) const noexcept;
  947. void oscSend_bridge_current_program(const int32_t index) const noexcept;
  948. void oscSend_bridge_current_midi_program(const int32_t index) const noexcept;
  949. void oscSend_bridge_program_name(const uint32_t index, const char* const name) const noexcept;
  950. void oscSend_bridge_midi_program_data(const uint32_t index, const uint32_t bank, const uint32_t program, const char* const name) const noexcept;
  951. void oscSend_bridge_configure(const char* const key, const char* const value) const noexcept;
  952. void oscSend_bridge_set_custom_data(const char* const type, const char* const key, const char* const value) const noexcept;
  953. void oscSend_bridge_set_chunk_data(const char* const chunkFile) const noexcept;
  954. void oscSend_bridge_set_peaks() const noexcept;
  955. void oscSend_bridge_pong() const noexcept;
  956. #else
  957. void oscSend_control_add_plugin_start(const uint pluginId, const char* const pluginName) const noexcept;
  958. void oscSend_control_add_plugin_end(const uint pluginId) const noexcept;
  959. void oscSend_control_remove_plugin(const uint pluginId) const noexcept;
  960. void oscSend_control_set_plugin_info1(const uint pluginId, const PluginType type, const PluginCategory category, const uint hints, const int64_t uniqueId) const noexcept;
  961. 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;
  962. void oscSend_control_set_audio_count(const uint pluginId, const uint32_t ins, const uint32_t outs) const noexcept;
  963. void oscSend_control_set_midi_count(const uint pluginId, const uint32_t ins, const uint32_t outs) const noexcept;
  964. void oscSend_control_set_parameter_count(const uint pluginId, const uint32_t ins, const uint32_t outs) const noexcept;
  965. void oscSend_control_set_program_count(const uint pluginId, const uint32_t count) const noexcept;
  966. void oscSend_control_set_midi_program_count(const uint pluginId, const uint32_t count) const noexcept;
  967. 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;
  968. void oscSend_control_set_parameter_ranges1(const uint pluginId, const uint32_t index, const float def, const float min, const float max) const noexcept;
  969. void oscSend_control_set_parameter_ranges2(const uint pluginId, const uint32_t index, const float step, const float stepSmall, const float stepLarge) const noexcept;
  970. void oscSend_control_set_parameter_midi_cc(const uint pluginId, const uint32_t index, const int16_t cc) const noexcept;
  971. void oscSend_control_set_parameter_midi_channel(const uint pluginId, const uint32_t index, const uint8_t channel) const noexcept;
  972. 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)
  973. void oscSend_control_set_default_value(const uint pluginId, const uint32_t index, const float value) const noexcept;
  974. void oscSend_control_set_current_program(const uint pluginId, const int32_t index) const noexcept;
  975. void oscSend_control_set_current_midi_program(const uint pluginId, const int32_t index) const noexcept;
  976. void oscSend_control_set_program_name(const uint pluginId, const uint32_t index, const char* const name) const noexcept;
  977. 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;
  978. void oscSend_control_note_on(const uint pluginId, const uint8_t channel, const uint8_t note, const uint8_t velo) const noexcept;
  979. void oscSend_control_note_off(const uint pluginId, const uint8_t channel, const uint8_t note) const noexcept;
  980. void oscSend_control_set_peaks(const uint pluginId) const noexcept;
  981. void oscSend_control_exit() const noexcept;
  982. #endif
  983. CARLA_DECLARE_NON_COPY_CLASS(CarlaEngine)
  984. };
  985. /**@}*/
  986. // -----------------------------------------------------------------------
  987. CARLA_BACKEND_END_NAMESPACE
  988. #endif // CARLA_ENGINE_HPP_INCLUDED