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.

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