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.

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