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.

1253 lines
36KB

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