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.

1110 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. 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. // FIXME - this one should not be public
  638. /*!
  639. * Get a unique plugin name within the engine.\n
  640. * Returned variable must NOT be free'd.
  641. */
  642. const char* getNewUniquePluginName(const char* const name);
  643. // -------------------------------------------------------------------
  644. // Project management
  645. /*!
  646. * Load \a filename of any type.\n
  647. * This will try to load a generic file as a plugin,
  648. * either by direct handling (GIG, SF2 and SFZ) or by using an internal plugin (like Audio and MIDI).
  649. */
  650. bool loadFilename(const char* const filename);
  651. /*!
  652. * Load \a filename project file.\n
  653. * (project files have *.carxp extension)
  654. * \note Already loaded plugins are not removed; call removeAllPlugins() first if needed.
  655. */
  656. bool loadProject(const char* const filename);
  657. /*!
  658. * Save current project to \a filename.\n
  659. * (project files have *.carxp extension)
  660. */
  661. bool saveProject(const char* const filename);
  662. // -------------------------------------------------------------------
  663. // Information (base)
  664. /*!
  665. * Get current buffer size.
  666. */
  667. uint32_t getBufferSize() const
  668. {
  669. return fBufferSize;
  670. }
  671. /*!
  672. * Get current sample rate.
  673. */
  674. double getSampleRate() const
  675. {
  676. return fSampleRate;
  677. }
  678. /*!
  679. * Get engine name.
  680. */
  681. const char* getName() const
  682. {
  683. return (const char*)fName;
  684. }
  685. /*!
  686. * Get the engine options (read-only).
  687. */
  688. const EngineOptions& getOptions() const
  689. {
  690. return fOptions;
  691. }
  692. /*!
  693. * TODO.
  694. */
  695. ProcessMode getProccessMode() const
  696. {
  697. return fOptions.processMode;
  698. }
  699. /*!
  700. * Get current Time information (read-only).
  701. */
  702. const EngineTimeInfo& getTimeInfo() const
  703. {
  704. return fTimeInfo;
  705. }
  706. // -------------------------------------------------------------------
  707. // Information (peaks)
  708. /*!
  709. * TODO.
  710. * \a id must be either 1 or 2.
  711. */
  712. float getInputPeak(const unsigned int pluginId, const unsigned short id) const;
  713. /*!
  714. * TODO.
  715. * \a id must be either 1 or 2.
  716. */
  717. float getOutputPeak(const unsigned int pluginId, const unsigned short id) const;
  718. // -------------------------------------------------------------------
  719. // Callback
  720. // FIXME - this one should not be public
  721. /*!
  722. * TODO.
  723. */
  724. void callback(const CallbackType action, const unsigned int pluginId, const int value1, const int value2, const float value3, const char* const valueStr);
  725. /*!
  726. * TODO.
  727. */
  728. void setCallback(const CallbackFunc func, void* const ptr);
  729. // -------------------------------------------------------------------
  730. // Patchbay
  731. /*!
  732. * Connect patchbay ports \a portA and \a portB.
  733. */
  734. virtual bool patchbayConnect(int portA, int portB);
  735. /*!
  736. * Disconnect patchbay connection \a connectionId.
  737. */
  738. virtual bool patchbayDisconnect(int connectionId);
  739. /*!
  740. * Force the engine to resend all patchbay clients, ports and connections again.
  741. */
  742. virtual void patchbayRefresh();
  743. // -------------------------------------------------------------------
  744. // Transport
  745. /*!
  746. * Start playback of the engine transport.
  747. */
  748. virtual void transportPlay();
  749. /*!
  750. * Pause the engine transport.
  751. */
  752. virtual void transportPause();
  753. /*!
  754. * Relocate the engine transport to \a frames.
  755. */
  756. virtual void transportRelocate(const uint32_t frame);
  757. // -------------------------------------------------------------------
  758. // Error handling
  759. /*!
  760. * Get last error.
  761. */
  762. const char* getLastError() const;
  763. // FIXME - this one should not be public
  764. /*!
  765. * Set last error.
  766. */
  767. void setLastError(const char* const error);
  768. // -------------------------------------------------------------------
  769. // Misc
  770. /*!
  771. * Tell the engine it's about to close.\n
  772. * This is used to prevent the engine thread(s) from reactivating.
  773. */
  774. void setAboutToClose();
  775. // -------------------------------------------------------------------
  776. // Options
  777. /*!
  778. * Set the engine option \a option.
  779. */
  780. void setOption(const OptionsType option, const int value, const char* const valueStr);
  781. // -------------------------------------------------------------------
  782. // OSC Stuff
  783. #ifdef BUILD_BRIDGE
  784. /*!
  785. * Check if OSC bridge is registered.
  786. */
  787. bool isOscBridgeRegistered() const;
  788. #else
  789. /*!
  790. * Check if OSC controller is registered.
  791. */
  792. bool isOscControlRegistered() const;
  793. #endif
  794. // FIXME - this one should not be public
  795. /*!
  796. * Idle OSC.
  797. */
  798. void idleOsc();
  799. /*!
  800. * Get OSC TCP server path.
  801. */
  802. const char* getOscServerPathTCP() const;
  803. /*!
  804. * Get OSC UDP server path.
  805. */
  806. const char* getOscServerPathUDP() const;
  807. #ifdef BUILD_BRIDGE
  808. /*!
  809. * Set OSC bridge data.
  810. */
  811. void setOscBridgeData(const CarlaOscData* const oscData);
  812. #endif
  813. // -------------------------------------
  814. #ifndef DOXYGEN
  815. protected:
  816. uint32_t fBufferSize;
  817. double fSampleRate;
  818. CarlaString fName;
  819. EngineOptions fOptions;
  820. EngineTimeInfo fTimeInfo;
  821. friend struct CarlaEngineProtectedData;
  822. CarlaEngineProtectedData* const kData;
  823. /*!
  824. * Report to all plugins about buffer size change.
  825. */
  826. void bufferSizeChanged(const uint32_t newBufferSize);
  827. /*!
  828. * Report to all plugins about sample rate change.\n
  829. * This is not supported on all plugin types, on which case they will be re-initiated.\n
  830. * TODO: Not implemented yet.
  831. */
  832. void sampleRateChanged(const double newSampleRate);
  833. /*!
  834. * TODO.
  835. */
  836. void proccessPendingEvents();
  837. /*!
  838. * TODO.
  839. */
  840. void setPeaks(const unsigned int pluginId, float const inPeaks[MAX_PEAKS], float const outPeaks[MAX_PEAKS]);
  841. # ifndef BUILD_BRIDGE
  842. // Rack mode data
  843. EngineEvent* getRackEventBuffer(const bool isInput);
  844. /*!
  845. * Proccess audio buffer in rack mode.
  846. */
  847. void processRack(float* inBuf[2], float* outBuf[2], const uint32_t frames);
  848. /*!
  849. * Proccess audio buffer in patchbay mode.
  850. * In \a bufCount, [0]=inBufCount and [1]=outBufCount
  851. */
  852. void processPatchbay(float** inBuf, float** outBuf, const uint32_t bufCount[2], const uint32_t frames);
  853. # endif
  854. private:
  855. static CarlaEngine* newJack();
  856. # ifdef WANT_RTAUDIO
  857. enum RtAudioApi {
  858. RTAUDIO_DUMMY = 0,
  859. RTAUDIO_LINUX_ALSA = 1,
  860. RTAUDIO_LINUX_PULSE = 2,
  861. RTAUDIO_LINUX_OSS = 3,
  862. RTAUDIO_UNIX_JACK = 4,
  863. RTAUDIO_MACOSX_CORE = 5,
  864. RTAUDIO_WINDOWS_ASIO = 6,
  865. RTAUDIO_WINDOWS_DS = 7
  866. };
  867. static CarlaEngine* newRtAudio(const RtAudioApi api);
  868. static size_t getRtAudioApiCount();
  869. static const char* getRtAudioApiName(const unsigned int index);
  870. # endif
  871. public:
  872. # ifdef BUILD_BRIDGE
  873. static CarlaEngine* newBridge(const char* const audioBaseName, const char* const controlBaseName);
  874. void osc_send_bridge_audio_count(const int32_t ins, const int32_t outs, const int32_t total);
  875. void osc_send_bridge_midi_count(const int32_t ins, const int32_t outs, const int32_t total);
  876. void osc_send_bridge_parameter_count(const int32_t ins, const int32_t outs, const int32_t total);
  877. void osc_send_bridge_program_count(const int32_t count);
  878. void osc_send_bridge_midi_program_count(const int32_t count);
  879. 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);
  880. void osc_send_bridge_parameter_info(const int32_t index, const char* const name, const char* const unit);
  881. 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);
  882. 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);
  883. void osc_send_bridge_program_info(const int32_t index, const char* const name);
  884. void osc_send_bridge_midi_program_info(const int32_t index, const int32_t bank, const int32_t program, const char* const label);
  885. void osc_send_bridge_configure(const char* const key, const char* const value);
  886. void osc_send_bridge_set_parameter_value(const int32_t index, const float value);
  887. void osc_send_bridge_set_default_value(const int32_t index, const float value);
  888. void osc_send_bridge_set_program(const int32_t index);
  889. void osc_send_bridge_set_midi_program(const int32_t index);
  890. void osc_send_bridge_set_custom_data(const char* const type, const char* const key, const char* const value);
  891. void osc_send_bridge_set_chunk_data(const char* const chunkFile);
  892. void osc_send_bridge_set_peaks();
  893. # else
  894. void osc_send_control_add_plugin_start(const int32_t pluginId, const char* const pluginName);
  895. void osc_send_control_add_plugin_end(const int32_t pluginId);
  896. void osc_send_control_remove_plugin(const int32_t pluginId);
  897. 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);
  898. 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);
  899. 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);
  900. 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);
  901. void osc_send_control_set_parameter_midi_cc(const int32_t pluginId, const int32_t index, const int32_t cc);
  902. void osc_send_control_set_parameter_midi_channel(const int32_t pluginId, const int32_t index, const int32_t channel);
  903. void osc_send_control_set_parameter_value(const int32_t pluginId, const int32_t index, const float value);
  904. void osc_send_control_set_default_value(const int32_t pluginId, const int32_t index, const float value);
  905. void osc_send_control_set_program(const int32_t pluginId, const int32_t index);
  906. void osc_send_control_set_program_count(const int32_t pluginId, const int32_t count);
  907. void osc_send_control_set_program_name(const int32_t pluginId, const int32_t index, const char* const name);
  908. void osc_send_control_set_midi_program(const int32_t pluginId, const int32_t index);
  909. void osc_send_control_set_midi_program_count(const int32_t pluginId, const int32_t count);
  910. 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);
  911. void osc_send_control_note_on(const int32_t pluginId, const int32_t channel, const int32_t note, const int32_t velo);
  912. void osc_send_control_note_off(const int32_t pluginId, const int32_t channel, const int32_t note);
  913. void osc_send_control_set_peaks(const int32_t pluginId);
  914. void osc_send_control_exit();
  915. # endif
  916. private:
  917. friend class CarlaEngineEventPort;
  918. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaEngine)
  919. #endif
  920. };
  921. // -----------------------------------------------------------------------
  922. /**@}*/
  923. CARLA_BACKEND_END_NAMESPACE
  924. #endif // __CARLA_ENGINE_HPP__