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.

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