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.

1236 lines
34KB

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