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.

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