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.

1303 lines
34KB

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