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.

1290 lines
34KB

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