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.

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