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.

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