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.

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