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.

1106 lines
29KB

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