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.

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