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.

1165 lines
31KB

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