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
35KB

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