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.

1095 lines
28KB

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