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.

1168 lines
33KB

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