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.

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