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.

1237 lines
34KB

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