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.

1127 lines
30KB

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