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.

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