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.

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