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.

1394 lines
35KB

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