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.

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