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.

1248 lines
33KB

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