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.

1234 lines
32KB

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