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.

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