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.

1154 lines
30KB

  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. * Get the number of events present in the buffer.
  420. * \note You must only call this for input ports.
  421. */
  422. virtual uint32_t getEventCount();
  423. /*!
  424. * Get the event at \a index.
  425. * \note You must only call this for input ports.
  426. */
  427. virtual const EngineEvent& getEvent(const uint32_t index);
  428. /*!
  429. * Write a control event into the buffer.\n
  430. * Arguments are the same as in the EngineControlEvent struct.
  431. * \note You must only call this for output ports.
  432. */
  433. virtual void writeControlEvent(const uint32_t time, const uint8_t channel, const EngineControlEventType type, const uint16_t param, const float value = 0.0f);
  434. /*!
  435. * Write a control event into the buffer, overloaded call.
  436. */
  437. void writeControlEvent(const uint32_t time, const uint8_t channel, const EngineControlEvent& ctrl)
  438. {
  439. writeControlEvent(time, channel, ctrl.type, ctrl.param, ctrl.value);
  440. }
  441. /*!
  442. * Write a MIDI event into the buffer.\n
  443. * Arguments are the same as in the EngineMidiEvent struct.
  444. ** \note You must only call this for output ports.
  445. */
  446. virtual void writeMidiEvent(const uint32_t time, const uint8_t channel, const uint8_t port, const uint8_t* const data, const uint8_t size);
  447. /*!
  448. * Write a MIDI event into the buffer, overloaded call.
  449. */
  450. void writeMidiEvent(const uint32_t time, const uint8_t* const data, const uint8_t size)
  451. {
  452. writeMidiEvent(time, MIDI_GET_CHANNEL_FROM_DATA(data), 0, data, size);
  453. }
  454. /*!
  455. * Write a MIDI event into the buffer, overloaded call.
  456. */
  457. void writeMidiEvent(const uint32_t time, const uint8_t channel, const EngineMidiEvent& midi)
  458. {
  459. writeMidiEvent(time, channel, midi.port, midi.data, midi.size);
  460. }
  461. #ifndef DOXYGEN
  462. private:
  463. const uint32_t kMaxEventCount;
  464. EngineEvent* fBuffer;
  465. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaEngineEventPort)
  466. #endif
  467. };
  468. // -----------------------------------------------------------------------
  469. /*!
  470. * Carla Engine client.\n
  471. * Each plugin requires one client from the engine (created via CarlaEngine::addPort()).\n
  472. * \note This is a virtual class, each engine type provides its own funtionality.
  473. */
  474. class CarlaEngineClient
  475. {
  476. public:
  477. /*!
  478. * The constructor, protected.\n
  479. * All constructor parameters are constant and will never change in the lifetime of the client.\n
  480. * Client starts in deactivated state.
  481. */
  482. CarlaEngineClient(const CarlaBackend::EngineType engineType, const CarlaBackend::ProcessMode processMode);
  483. /*!
  484. * The destructor.
  485. */
  486. virtual ~CarlaEngineClient();
  487. /*!
  488. * Activate this client.\n
  489. * Client must be deactivated before calling this function.
  490. */
  491. virtual void activate();
  492. /*!
  493. * Deactivate this client.\n
  494. * Client must be activated before calling this function.
  495. */
  496. virtual void deactivate();
  497. /*!
  498. * Check if the client is activated.
  499. */
  500. virtual bool isActive() const;
  501. /*!
  502. * Check if the client is ok.\n
  503. * Plugins will refuse to instantiate if this returns false.
  504. * \note This is always true in rack and patchbay processing modes.
  505. */
  506. virtual bool isOk() const;
  507. /*!
  508. * Get the current latency, in samples.
  509. */
  510. virtual uint32_t getLatency() const;
  511. /*!
  512. * Change the client's latency.
  513. */
  514. virtual void setLatency(const uint32_t samples);
  515. /*!
  516. * Add a new port of type \a portType.
  517. * \note This function does nothing in rack processing mode since ports are static there (2 audio + 1 event for both input and output).
  518. */
  519. virtual CarlaEnginePort* addPort(const EnginePortType portType, const char* const name, const bool isInput);
  520. #ifndef DOXYGEN
  521. protected:
  522. const EngineType kEngineType;
  523. const ProcessMode kProcessMode;
  524. bool fActive;
  525. uint32_t fLatency;
  526. private:
  527. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaEngineClient)
  528. #endif
  529. };
  530. // -----------------------------------------------------------------------
  531. /*!
  532. * Protected data used in CarlaEngine.
  533. * Non-engine code MUST NEVER have direct access to this.
  534. */
  535. struct CarlaEngineProtectedData;
  536. /*!
  537. * Carla Engine.
  538. * \note This is a virtual class for all available engine types available in Carla.
  539. */
  540. class CarlaEngine
  541. {
  542. protected:
  543. /*!
  544. * The constructor, protected.\n
  545. * \note This only initializes engine data, it doesn't initialize the engine itself.
  546. */
  547. CarlaEngine();
  548. public:
  549. /*!
  550. * The decontructor.
  551. * The engine must have been closed before this happens.
  552. */
  553. virtual ~CarlaEngine();
  554. // -------------------------------------------------------------------
  555. // Static values and calls
  556. /*!
  557. * TODO.
  558. */
  559. static const unsigned short MAX_PEAKS = 2;
  560. /*!
  561. * Get the number of available engine drivers.
  562. */
  563. static unsigned int getDriverCount();
  564. /*!
  565. * Get the name of the engine driver at \a index.
  566. */
  567. static const char* getDriverName(unsigned int index);
  568. /*!
  569. * Get the device names of driver at \a index (for use in non-JACK drivers).\n
  570. * May return NULL.
  571. */
  572. static const char** getDriverDeviceNames(unsigned int index);
  573. /*!
  574. * Create a new engine, using driver \a driverName.\n
  575. * Returned variable must be deleted when no longer needed.
  576. */
  577. static CarlaEngine* newDriverByName(const char* const driverName);
  578. // -------------------------------------------------------------------
  579. // Constant values
  580. /*!
  581. * Maximum client name size.
  582. */
  583. virtual unsigned int maxClientNameSize() const;
  584. /*!
  585. * Maximum port name size.
  586. */
  587. virtual unsigned int maxPortNameSize() const;
  588. /*!
  589. * Current number of plugins loaded.
  590. */
  591. unsigned int currentPluginCount() const;
  592. /*!
  593. * Maximum number of loadable plugins allowed.
  594. * \note This function returns 0 if engine is not started.
  595. */
  596. unsigned int maxPluginNumber() const;
  597. // -------------------------------------------------------------------
  598. // Virtual, per-engine type calls
  599. /*!
  600. * Initialize engine, using \a clientName.
  601. */
  602. virtual bool init(const char* const clientName);
  603. /*!
  604. * Close engine.
  605. */
  606. virtual bool close();
  607. /*!
  608. * Idle engine.
  609. */
  610. virtual void idle();
  611. /*!
  612. * Check if engine is running.
  613. */
  614. virtual bool isRunning() const = 0;
  615. /*!
  616. * Check if engine is running offline (aka freewheel mode).
  617. */
  618. virtual bool isOffline() const = 0;
  619. /*!
  620. * Get engine type.
  621. */
  622. virtual EngineType type() const = 0;
  623. /*!
  624. * Add new engine client.
  625. * \note This must only be called within a plugin class.
  626. */
  627. virtual CarlaEngineClient* addClient(CarlaPlugin* const plugin);
  628. // -------------------------------------------------------------------
  629. // Plugin management
  630. /*!
  631. * Add new plugin.
  632. */
  633. 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);
  634. /*!
  635. * Add new plugin, using native binary type.
  636. */
  637. bool addPlugin(const PluginType ptype, const char* const filename, const char* const name, const char* const label, const void* const extra = nullptr)
  638. {
  639. return addPlugin(BINARY_NATIVE, ptype, filename, name, label, extra);
  640. }
  641. /*!
  642. * Remove plugin with id \a id.
  643. */
  644. bool removePlugin(const unsigned int id);
  645. /*!
  646. * Remove all plugins.
  647. */
  648. void removeAllPlugins();
  649. /*!
  650. * Rename plugin with id \a id to \a newName.\n
  651. * Returns the new name, or nullptr if the operation failed.
  652. */
  653. virtual const char* renamePlugin(const unsigned int id, const char* const newName);
  654. /*!
  655. * Clone plugin with id \a id.
  656. */
  657. bool clonePlugin(const unsigned int id);
  658. /*!
  659. * Prepare replace of plugin with id \a id.\n
  660. * The next call to addPlugin() will use this id, replacing the current plugin.
  661. * \note This function requires addPlugin() to be called afterwards as soon as possible.
  662. */
  663. bool replacePlugin(const unsigned int id);
  664. /*!
  665. * Switch plugins with id \a idA and \a idB.
  666. */
  667. bool switchPlugins(const unsigned int idA, const unsigned int idB);
  668. /*!
  669. * Get plugin with id \a id.
  670. */
  671. CarlaPlugin* getPlugin(const unsigned int id) const;
  672. /*!
  673. * Get plugin with id \a id, faster unchecked version.
  674. */
  675. CarlaPlugin* getPluginUnchecked(const unsigned int id) const;
  676. /*!
  677. * Get a unique plugin name within the engine.\n
  678. * Returned variable must NOT be free'd.
  679. */
  680. const char* getUniquePluginName(const char* const name);
  681. // -------------------------------------------------------------------
  682. // Project management
  683. /*!
  684. * Load \a filename of any type.\n
  685. * This will try to load a generic file as a plugin,
  686. * either by direct handling (GIG, SF2 and SFZ) or by using an internal plugin (like Audio and MIDI).
  687. */
  688. bool loadFilename(const char* const filename);
  689. /*!
  690. * Load \a filename project file.\n
  691. * (project files have *.carxp extension)
  692. * \note Already loaded plugins are not removed; call removeAllPlugins() first if needed.
  693. */
  694. bool loadProject(const char* const filename);
  695. /*!
  696. * Save current project to \a filename.\n
  697. * (project files have *.carxp extension)
  698. */
  699. bool saveProject(const char* const filename);
  700. // -------------------------------------------------------------------
  701. // Information (base)
  702. /*!
  703. * Get current buffer size.
  704. */
  705. uint32_t getBufferSize() const
  706. {
  707. return fBufferSize;
  708. }
  709. /*!
  710. * Get current sample rate.
  711. */
  712. double getSampleRate() const
  713. {
  714. return fSampleRate;
  715. }
  716. /*!
  717. * Get engine name.
  718. */
  719. const char* getName() const
  720. {
  721. return (const char*)fName;
  722. }
  723. /*!
  724. * Get the engine options (read-only).
  725. */
  726. const EngineOptions& getOptions() const
  727. {
  728. return fOptions;
  729. }
  730. /*!
  731. * Get the engine proccess mode.
  732. */
  733. ProcessMode getProccessMode() const
  734. {
  735. return fOptions.processMode;
  736. }
  737. /*!
  738. * Get current Time information (read-only).
  739. */
  740. const EngineTimeInfo& getTimeInfo() const
  741. {
  742. return fTimeInfo;
  743. }
  744. // -------------------------------------------------------------------
  745. // Information (peaks)
  746. /*!
  747. * TODO.
  748. * \a id must be either 1 or 2.
  749. */
  750. float getInputPeak(const unsigned int pluginId, const unsigned short id) const;
  751. /*!
  752. * TODO.
  753. * \a id must be either 1 or 2.
  754. */
  755. float getOutputPeak(const unsigned int pluginId, const unsigned short id) const;
  756. // -------------------------------------------------------------------
  757. // Callback
  758. /*!
  759. * TODO.
  760. */
  761. void callback(const CallbackType action, const unsigned int pluginId, const int value1, const int value2, const float value3, const char* const valueStr);
  762. /*!
  763. * TODO.
  764. */
  765. void setCallback(const CallbackFunc func, void* const ptr);
  766. // -------------------------------------------------------------------
  767. // Patchbay
  768. /*!
  769. * Connect patchbay ports \a portA and \a portB.
  770. */
  771. virtual bool patchbayConnect(int portA, int portB);
  772. /*!
  773. * Disconnect patchbay connection \a connectionId.
  774. */
  775. virtual bool patchbayDisconnect(int connectionId);
  776. /*!
  777. * Force the engine to resend all patchbay clients, ports and connections again.
  778. */
  779. virtual void patchbayRefresh();
  780. // -------------------------------------------------------------------
  781. // Transport
  782. /*!
  783. * Start playback of the engine transport.
  784. */
  785. virtual void transportPlay();
  786. /*!
  787. * Pause the engine transport.
  788. */
  789. virtual void transportPause();
  790. /*!
  791. * Relocate the engine transport to \a frames.
  792. */
  793. virtual void transportRelocate(const uint32_t frame);
  794. // -------------------------------------------------------------------
  795. // Error handling
  796. /*!
  797. * Get last error.
  798. */
  799. const char* getLastError() const;
  800. /*!
  801. * Set last error.
  802. */
  803. void setLastError(const char* const error);
  804. // -------------------------------------------------------------------
  805. // Misc
  806. /*!
  807. * Tell the engine it's about to close.\n
  808. * This is used to prevent the engine thread(s) from reactivating.
  809. */
  810. void setAboutToClose();
  811. // -------------------------------------------------------------------
  812. // Options
  813. /*!
  814. * Set the engine option \a option.
  815. */
  816. void setOption(const OptionsType option, const int value, const char* const valueStr);
  817. // -------------------------------------------------------------------
  818. // OSC Stuff
  819. #ifdef BUILD_BRIDGE
  820. /*!
  821. * Check if OSC bridge is registered.
  822. */
  823. bool isOscBridgeRegistered() const;
  824. #else
  825. /*!
  826. * Check if OSC controller is registered.
  827. */
  828. bool isOscControlRegistered() const;
  829. #endif
  830. /*!
  831. * Idle OSC.
  832. */
  833. void idleOsc();
  834. /*!
  835. * Get OSC TCP server path.
  836. */
  837. const char* getOscServerPathTCP() const;
  838. /*!
  839. * Get OSC UDP server path.
  840. */
  841. const char* getOscServerPathUDP() const;
  842. #ifdef BUILD_BRIDGE
  843. /*!
  844. * Set OSC bridge data.
  845. */
  846. void setOscBridgeData(const CarlaOscData* const oscData);
  847. #endif
  848. // -------------------------------------
  849. #ifndef DOXYGEN
  850. protected:
  851. uint32_t fBufferSize;
  852. double fSampleRate;
  853. CarlaString fName;
  854. EngineOptions fOptions;
  855. EngineTimeInfo fTimeInfo;
  856. friend struct CarlaEngineProtectedData;
  857. CarlaEngineProtectedData* const kData;
  858. /*!
  859. * Report to all plugins about buffer size change.
  860. */
  861. void bufferSizeChanged(const uint32_t newBufferSize);
  862. /*!
  863. * Report to all plugins about sample rate change.\n
  864. * This is not supported on all plugin types, on which case they will be re-initiated.\n
  865. * TODO: Not implemented yet.
  866. */
  867. void sampleRateChanged(const double newSampleRate);
  868. /*!
  869. * TODO.
  870. */
  871. void proccessPendingEvents();
  872. /*!
  873. * TODO.
  874. */
  875. void setPeaks(const unsigned int pluginId, float const inPeaks[MAX_PEAKS], float const outPeaks[MAX_PEAKS]);
  876. # ifndef BUILD_BRIDGE
  877. // Rack mode data
  878. EngineEvent* getRackEventBuffer(const bool isInput);
  879. /*!
  880. * Proccess audio buffer in rack mode.
  881. */
  882. void processRack(float* inBuf[2], float* outBuf[2], const uint32_t frames);
  883. /*!
  884. * Proccess audio buffer in patchbay mode.
  885. * In \a bufCount, [0]=inBufCount and [1]=outBufCount
  886. */
  887. void processPatchbay(float** inBuf, float** outBuf, const uint32_t bufCount[2], const uint32_t frames);
  888. # endif
  889. private:
  890. static CarlaEngine* newJack();
  891. # ifdef WANT_RTAUDIO
  892. enum RtAudioApi {
  893. RTAUDIO_DUMMY = 0,
  894. RTAUDIO_LINUX_ALSA = 1,
  895. RTAUDIO_LINUX_PULSE = 2,
  896. RTAUDIO_LINUX_OSS = 3,
  897. RTAUDIO_UNIX_JACK = 4,
  898. RTAUDIO_MACOSX_CORE = 5,
  899. RTAUDIO_WINDOWS_ASIO = 6,
  900. RTAUDIO_WINDOWS_DS = 7
  901. };
  902. static CarlaEngine* newRtAudio(const RtAudioApi api);
  903. static size_t getRtAudioApiCount();
  904. static const char* getRtAudioApiName(const unsigned int index);
  905. static const char** getRtAudioApiDeviceNames(const unsigned int index);
  906. # endif
  907. public:
  908. # ifdef BUILD_BRIDGE
  909. static CarlaEngine* newBridge(const char* const audioBaseName, const char* const controlBaseName);
  910. void osc_send_bridge_audio_count(const int32_t ins, const int32_t outs, const int32_t total);
  911. void osc_send_bridge_midi_count(const int32_t ins, const int32_t outs, const int32_t total);
  912. void osc_send_bridge_parameter_count(const int32_t ins, const int32_t outs, const int32_t total);
  913. void osc_send_bridge_program_count(const int32_t count);
  914. void osc_send_bridge_midi_program_count(const int32_t count);
  915. 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);
  916. void osc_send_bridge_parameter_info(const int32_t index, const char* const name, const char* const unit);
  917. 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);
  918. 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);
  919. void osc_send_bridge_program_info(const int32_t index, const char* const name);
  920. void osc_send_bridge_midi_program_info(const int32_t index, const int32_t bank, const int32_t program, const char* const label);
  921. void osc_send_bridge_configure(const char* const key, const char* const value);
  922. void osc_send_bridge_set_parameter_value(const int32_t index, const float value);
  923. void osc_send_bridge_set_default_value(const int32_t index, const float value);
  924. void osc_send_bridge_set_program(const int32_t index);
  925. void osc_send_bridge_set_midi_program(const int32_t index);
  926. void osc_send_bridge_set_custom_data(const char* const type, const char* const key, const char* const value);
  927. void osc_send_bridge_set_chunk_data(const char* const chunkFile);
  928. void osc_send_bridge_set_peaks();
  929. # else
  930. void osc_send_control_add_plugin_start(const int32_t pluginId, const char* const pluginName);
  931. void osc_send_control_add_plugin_end(const int32_t pluginId);
  932. void osc_send_control_remove_plugin(const int32_t pluginId);
  933. 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);
  934. 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);
  935. 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);
  936. 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);
  937. void osc_send_control_set_parameter_midi_cc(const int32_t pluginId, const int32_t index, const int32_t cc);
  938. void osc_send_control_set_parameter_midi_channel(const int32_t pluginId, const int32_t index, const int32_t channel);
  939. void osc_send_control_set_parameter_value(const int32_t pluginId, const int32_t index, const float value);
  940. void osc_send_control_set_default_value(const int32_t pluginId, const int32_t index, const float value);
  941. void osc_send_control_set_program(const int32_t pluginId, const int32_t index);
  942. void osc_send_control_set_program_count(const int32_t pluginId, const int32_t count);
  943. void osc_send_control_set_program_name(const int32_t pluginId, const int32_t index, const char* const name);
  944. void osc_send_control_set_midi_program(const int32_t pluginId, const int32_t index);
  945. void osc_send_control_set_midi_program_count(const int32_t pluginId, const int32_t count);
  946. 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);
  947. void osc_send_control_note_on(const int32_t pluginId, const int32_t channel, const int32_t note, const int32_t velo);
  948. void osc_send_control_note_off(const int32_t pluginId, const int32_t channel, const int32_t note);
  949. void osc_send_control_set_peaks(const int32_t pluginId);
  950. void osc_send_control_exit();
  951. # endif
  952. private:
  953. friend class CarlaEngineEventPort;
  954. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaEngine)
  955. #endif
  956. };
  957. // -----------------------------------------------------------------------
  958. /**@}*/
  959. CARLA_BACKEND_END_NAMESPACE
  960. #endif // __CARLA_ENGINE_HPP__