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.

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