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.

1293 lines
33KB

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