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.

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