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.

1255 lines
34KB

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