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.

1088 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. * Check if engine is running.
  588. */
  589. virtual bool isRunning() const = 0;
  590. /*!
  591. * Check if engine is running offline (aka freewheel mode).
  592. */
  593. virtual bool isOffline() const = 0;
  594. /*!
  595. * Get engine type.
  596. */
  597. virtual EngineType type() const = 0;
  598. /*!
  599. * Add new engine client.
  600. * \note This must only be called within a plugin class.
  601. */
  602. virtual CarlaEngineClient* addClient(CarlaPlugin* const plugin);
  603. // -------------------------------------------------------------------
  604. // Plugin management
  605. /*!
  606. * Add new plugin.
  607. */
  608. 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);
  609. /*!
  610. * Add new plugin, using native binary type.
  611. */
  612. bool addPlugin(const PluginType ptype, const char* const filename, const char* const name, const char* const label, const void* const extra = nullptr)
  613. {
  614. return addPlugin(BINARY_NATIVE, ptype, filename, name, label, extra);
  615. }
  616. /*!
  617. * Remove plugin with id \a id.
  618. */
  619. bool removePlugin(const unsigned int id);
  620. /*!
  621. * Remove all plugins.
  622. */
  623. void removeAllPlugins();
  624. /*!
  625. * Get plugin with id \a id.
  626. */
  627. CarlaPlugin* getPlugin(const unsigned int id) const;
  628. /*!
  629. * Get plugin with id \a id, faster unchecked version.
  630. */
  631. CarlaPlugin* getPluginUnchecked(const unsigned int id) const;
  632. /*!
  633. * Get a unique plugin name within the engine.\n
  634. * Returned variable must NOT be free'd.
  635. */
  636. const char* getNewUniquePluginName(const char* const name);
  637. // -------------------------------------------------------------------
  638. // Project management
  639. /*!
  640. * Load \a filename session.
  641. * \note Already loaded plugins are not removed; call removeAllPlugins() first if needed.
  642. */
  643. bool loadProject(const char* const filename);
  644. /*!
  645. * Save current session to \a filename.
  646. */
  647. bool saveProject(const char* const filename);
  648. // -------------------------------------------------------------------
  649. // Information (base)
  650. /*!
  651. * Get current buffer size.
  652. */
  653. uint32_t getBufferSize() const
  654. {
  655. return fBufferSize;
  656. }
  657. /*!
  658. * Get current sample rate.
  659. */
  660. double getSampleRate() const
  661. {
  662. return fSampleRate;
  663. }
  664. /*!
  665. * Get engine name.
  666. */
  667. const char* getName() const
  668. {
  669. return (const char*)fName;
  670. }
  671. /*!
  672. * Get the engine options (read-only).
  673. */
  674. const EngineOptions& getOptions() const
  675. {
  676. return fOptions;
  677. }
  678. /*!
  679. * TODO.
  680. */
  681. ProcessMode getProccessMode() const
  682. {
  683. return fOptions.processMode;
  684. }
  685. /*!
  686. * Get current Time information (read-only).
  687. */
  688. const EngineTimeInfo& getTimeInfo() const
  689. {
  690. return fTimeInfo;
  691. }
  692. // -------------------------------------------------------------------
  693. // Information (peaks)
  694. /*!
  695. * TODO.
  696. * \a id must be either 1 or 2.
  697. */
  698. float getInputPeak(const unsigned int pluginId, const unsigned short id) const;
  699. /*!
  700. * TODO.
  701. * \a id must be either 1 or 2.
  702. */
  703. float getOutputPeak(const unsigned int pluginId, const unsigned short id) const;
  704. // FIXME - remove once IPC audio is implemented
  705. void setPeaks(const unsigned int pluginId, float const inPeaks[MAX_PEAKS], float const outPeaks[MAX_PEAKS]);
  706. // -------------------------------------------------------------------
  707. // Callback
  708. /*!
  709. * TODO.
  710. */
  711. void callback(const CallbackType action, const unsigned int pluginId, const int value1, const int value2, const float value3, const char* const valueStr);
  712. /*!
  713. * TODO.
  714. */
  715. void setCallback(const CallbackFunc func, void* const ptr);
  716. // -------------------------------------------------------------------
  717. // Patchbay
  718. /*!
  719. * TODO.
  720. */
  721. virtual void patchbayConnect(int portA, int portB);
  722. /*!
  723. * TODO.
  724. */
  725. virtual void patchbayDisconnect(int connectionId);
  726. // -------------------------------------------------------------------
  727. // Transport
  728. /*!
  729. * TODO.
  730. */
  731. virtual void transportPlay();
  732. /*!
  733. * TODO.
  734. */
  735. virtual void transportPause();
  736. /*!
  737. * TODO.
  738. */
  739. virtual void transportRelocate(const uint32_t frame);
  740. // -------------------------------------------------------------------
  741. // Error handling
  742. /*!
  743. * Get last error.
  744. */
  745. const char* getLastError() const;
  746. /*!
  747. * Set last error.
  748. */
  749. void setLastError(const char* const error);
  750. // -------------------------------------------------------------------
  751. // Misc
  752. /*!
  753. * Tell the engine it's about to close.\n
  754. * This is used to prevent the engine thread(s) from reactivating.
  755. */
  756. void setAboutToClose();
  757. #ifndef BUILD_BRIDGE
  758. // -------------------------------------------------------------------
  759. // Options
  760. /*!
  761. * Get the engine options as process environment.
  762. */
  763. const QProcessEnvironment& getOptionsAsProcessEnvironment() const;
  764. /*!
  765. * Set the engine option \a option.
  766. */
  767. void setOption(const OptionsType option, const int value, const char* const valueStr);
  768. #endif
  769. // -------------------------------------------------------------------
  770. // OSC Stuff
  771. #ifdef BUILD_BRIDGE
  772. /*!
  773. * Check if OSC bridge is registered.
  774. */
  775. bool isOscBridgeRegistered() const;
  776. #else
  777. /*!
  778. * Check if OSC controller is registered.
  779. */
  780. bool isOscControlRegistered() const;
  781. #endif
  782. /*!
  783. * Idle OSC.
  784. */
  785. void idleOsc();
  786. /*!
  787. * Get OSC TCP server path.
  788. */
  789. const char* getOscServerPathTCP() const;
  790. /*!
  791. * Get OSC UDP server path.
  792. */
  793. const char* getOscServerPathUDP() const;
  794. #ifdef BUILD_BRIDGE
  795. /*!
  796. * Set OSC bridge data.
  797. */
  798. void setOscBridgeData(const CarlaOscData* const oscData);
  799. #endif
  800. // -------------------------------------
  801. protected:
  802. uint32_t fBufferSize;
  803. double fSampleRate;
  804. CarlaString fName;
  805. EngineOptions fOptions;
  806. EngineTimeInfo fTimeInfo;
  807. friend struct CarlaEngineProtectedData;
  808. CarlaEngineProtectedData* const kData;
  809. /*!
  810. * Report to all plugins about buffer size change.
  811. */
  812. void bufferSizeChanged(const uint32_t newBufferSize);
  813. /*!
  814. * Report to all plugins about sample rate change.\n
  815. * This is not supported on all plugin types, on which case they will be re-initiated.\n
  816. * TODO: Not implemented yet.
  817. */
  818. void sampleRateChanged(const double newSampleRate);
  819. /*!
  820. * TODO.
  821. */
  822. void proccessPendingEvents();
  823. #ifndef BUILD_BRIDGE
  824. // Rack mode data
  825. EngineEvent* getRackEventBuffer(const bool isInput);
  826. /*!
  827. * Proccess audio buffer in rack mode.
  828. */
  829. void processRack(float* inBuf[2], float* outBuf[2], const uint32_t frames);
  830. /*!
  831. * Proccess audio buffer in patchbay mode.
  832. * In \a bufCount, [0]=inBufCount and [1]=outBufCount
  833. */
  834. void processPatchbay(float** inBuf, float** outBuf, const uint32_t bufCount[2], const uint32_t frames);
  835. #endif
  836. private:
  837. #ifdef WANT_JACK
  838. static CarlaEngine* newJack();
  839. #endif
  840. #ifdef WANT_RTAUDIO
  841. enum RtAudioApi {
  842. RTAUDIO_DUMMY = 0,
  843. RTAUDIO_LINUX_ALSA = 1,
  844. RTAUDIO_LINUX_PULSE = 2,
  845. RTAUDIO_LINUX_OSS = 3,
  846. RTAUDIO_UNIX_JACK = 4,
  847. RTAUDIO_MACOSX_CORE = 5,
  848. RTAUDIO_WINDOWS_ASIO = 6,
  849. RTAUDIO_WINDOWS_DS = 7
  850. };
  851. static CarlaEngine* newRtAudio(const RtAudioApi api);
  852. static size_t getRtAudioApiCount();
  853. static const char* getRtAudioApiName(const unsigned int index);
  854. #endif
  855. public:
  856. #ifdef BUILD_BRIDGE
  857. void osc_send_bridge_audio_count(const int32_t ins, const int32_t outs, const int32_t total);
  858. void osc_send_bridge_midi_count(const int32_t ins, const int32_t outs, const int32_t total);
  859. void osc_send_bridge_parameter_count(const int32_t ins, const int32_t outs, const int32_t total);
  860. void osc_send_bridge_program_count(const int32_t count);
  861. void osc_send_bridge_midi_program_count(const int32_t count);
  862. 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);
  863. void osc_send_bridge_parameter_info(const int32_t index, const char* const name, const char* const unit);
  864. 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);
  865. 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);
  866. void osc_send_bridge_program_info(const int32_t index, const char* const name);
  867. void osc_send_bridge_midi_program_info(const int32_t index, const int32_t bank, const int32_t program, const char* const label);
  868. void osc_send_bridge_configure(const char* const key, const char* const value);
  869. void osc_send_bridge_set_parameter_value(const int32_t index, const float value);
  870. void osc_send_bridge_set_default_value(const int32_t index, const float value);
  871. void osc_send_bridge_set_program(const int32_t index);
  872. void osc_send_bridge_set_midi_program(const int32_t index);
  873. void osc_send_bridge_set_custom_data(const char* const type, const char* const key, const char* const value);
  874. void osc_send_bridge_set_chunk_data(const char* const chunkFile);
  875. void osc_send_bridge_set_peaks();
  876. #else
  877. void osc_send_control_add_plugin_start(const int32_t pluginId, const char* const pluginName);
  878. void osc_send_control_add_plugin_end(const int32_t pluginId);
  879. void osc_send_control_remove_plugin(const int32_t pluginId);
  880. 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);
  881. 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);
  882. 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);
  883. 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);
  884. void osc_send_control_set_parameter_midi_cc(const int32_t pluginId, const int32_t index, const int32_t cc);
  885. void osc_send_control_set_parameter_midi_channel(const int32_t pluginId, const int32_t index, const int32_t channel);
  886. void osc_send_control_set_parameter_value(const int32_t pluginId, const int32_t index, const float value);
  887. void osc_send_control_set_default_value(const int32_t pluginId, const int32_t index, const float value);
  888. void osc_send_control_set_program(const int32_t pluginId, const int32_t index);
  889. void osc_send_control_set_program_count(const int32_t pluginId, const int32_t count);
  890. void osc_send_control_set_program_name(const int32_t pluginId, const int32_t index, const char* const name);
  891. void osc_send_control_set_midi_program(const int32_t pluginId, const int32_t index);
  892. void osc_send_control_set_midi_program_count(const int32_t pluginId, const int32_t count);
  893. 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);
  894. void osc_send_control_note_on(const int32_t pluginId, const int32_t channel, const int32_t note, const int32_t velo);
  895. void osc_send_control_note_off(const int32_t pluginId, const int32_t channel, const int32_t note);
  896. void osc_send_control_set_peaks(const int32_t pluginId);
  897. void osc_send_control_exit();
  898. #endif
  899. private:
  900. friend class CarlaEngineEventPort;
  901. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaEngine)
  902. };
  903. // -----------------------------------------------------------------------
  904. /**@}*/
  905. CARLA_BACKEND_END_NAMESPACE
  906. #endif // __CARLA_ENGINE_HPP__