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.

1059 lines
28KB

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