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.

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