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.

1066 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 "carla_backend.hpp"
  20. #include "carla_utils.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 (Abstract).\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. * Get the number of available engine drivers.
  532. */
  533. static unsigned int getDriverCount();
  534. /*!
  535. * Get the name of the engine driver at \a index.
  536. */
  537. static const char* getDriverName(unsigned int index);
  538. /*!
  539. * Create a new engine, using driver \a driverName.\n
  540. * Returned variable must be deleted when no longer needed.
  541. */
  542. static CarlaEngine* newDriverByName(const char* const driverName);
  543. // -------------------------------------------------------------------
  544. // Constant values
  545. /*!
  546. * Maximum client name size.
  547. */
  548. virtual unsigned int maxClientNameSize() const;
  549. /*!
  550. * Maximum port name size.
  551. */
  552. virtual unsigned int maxPortNameSize() const;
  553. /*!
  554. * Current number of plugins loaded.
  555. */
  556. unsigned int currentPluginCount() const;
  557. /*!
  558. * Maximum number of loadable plugins allowed.
  559. * \note This function returns 0 if engine is not started.
  560. */
  561. unsigned int maxPluginNumber() const;
  562. // -------------------------------------------------------------------
  563. // Virtual, per-engine type calls
  564. /*!
  565. * Initialize engine, using \a clientName.
  566. */
  567. virtual bool init(const char* const clientName);
  568. /*!
  569. * Close engine.
  570. */
  571. virtual bool close();
  572. /*!
  573. * Idle engine.
  574. */
  575. virtual void idle();
  576. /*!
  577. * Check if engine is running.
  578. */
  579. virtual bool isRunning() const = 0;
  580. /*!
  581. * Check if engine is running offline (aka freewheel mode).
  582. */
  583. virtual bool isOffline() const = 0;
  584. /*!
  585. * Get engine type.
  586. */
  587. virtual EngineType type() const = 0;
  588. /*!
  589. * Add new engine client.
  590. * \note This must only be called within a plugin class.
  591. */
  592. virtual CarlaEngineClient* addClient(CarlaPlugin* const plugin);
  593. // -------------------------------------------------------------------
  594. // Plugin management
  595. /*!
  596. * Add new plugin.
  597. */
  598. 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);
  599. /*!
  600. * Add new plugin, using native binary type.
  601. */
  602. bool addPlugin(const PluginType ptype, const char* const filename, const char* const name, const char* const label, const void* const extra = nullptr)
  603. {
  604. return addPlugin(BINARY_NATIVE, ptype, filename, name, label, extra);
  605. }
  606. /*!
  607. * Remove plugin with id \a id.
  608. */
  609. bool removePlugin(const unsigned int id);
  610. /*!
  611. * Remove all plugins.
  612. */
  613. void removeAllPlugins();
  614. /*!
  615. * Get plugin with id \a id.
  616. */
  617. CarlaPlugin* getPlugin(const unsigned int id) const;
  618. /*!
  619. * Get plugin with id \a id, faster unchecked version.
  620. */
  621. CarlaPlugin* getPluginUnchecked(const unsigned int id) const;
  622. /*!
  623. * Get a unique plugin name within the engine.\n
  624. * Returned variable must NOT be free'd.
  625. */
  626. const char* getNewUniquePluginName(const char* const name);
  627. // bridge, internal use only
  628. // TODO - find a better way for this
  629. //void __bridgePluginRegister(const unsigned short id, CarlaPlugin* const plugin);
  630. //{
  631. // m_carlaPlugins[id] = plugin;
  632. //}
  633. // -------------------------------------------------------------------
  634. // Project management
  635. /*!
  636. * Load \a filename session.
  637. * \note Already loaded plugins are not removed; call removeAllPlugins() first if needed.
  638. */
  639. void loadProject(const char* const filename);
  640. /*!
  641. * Save current session to \a filename.
  642. */
  643. void saveProject(const char* const filename);
  644. // -------------------------------------------------------------------
  645. // Information (base)
  646. /*!
  647. * Get engine name.
  648. */
  649. const char* getName() const
  650. {
  651. return (const char*)fName;
  652. }
  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 the engine options (read-only).
  669. */
  670. const EngineOptions& getOptions() const
  671. {
  672. return fOptions;
  673. }
  674. ProcessMode getProccessMode() const
  675. {
  676. return fOptions.processMode;
  677. }
  678. /*!
  679. * Get current Time information (read-only).
  680. */
  681. const EngineTimeInfo& getTimeInfo() const
  682. {
  683. return fTimeInfo;
  684. }
  685. // -------------------------------------------------------------------
  686. // Information (peaks)
  687. /*!
  688. * TODO.
  689. */
  690. float getInputPeak(const unsigned int pluginId, const unsigned short id) const;
  691. /*!
  692. * TODO.
  693. */
  694. float getOutputPeak(const unsigned int pluginId, const unsigned short id) const;
  695. // -------------------------------------------------------------------
  696. // Callback
  697. /*!
  698. * TODO.
  699. */
  700. void callback(const CallbackType action, const unsigned int pluginId, const int value1, const int value2, const float value3, const char* const valueStr);
  701. /*!
  702. * TODO.
  703. */
  704. void setCallback(const CallbackFunc func, void* const ptr);
  705. // -------------------------------------------------------------------
  706. // Error handling
  707. /*!
  708. * Get last error.
  709. */
  710. const char* getLastError() const;
  711. /*!
  712. * Set last error.
  713. */
  714. void setLastError(const char* const error);
  715. // -------------------------------------------------------------------
  716. // Misc
  717. /*!
  718. * Tell the engine it's about to close.\n
  719. * This is used to prevent the engine thread(s) from reactivating.
  720. */
  721. void setAboutToClose();
  722. /*!
  723. * Safely block wait until the current proccessing callback ends.
  724. */
  725. void waitForProccessEnd();
  726. // -------------------------------------------------------------------
  727. // Options
  728. #ifndef BUILD_BRIDGE
  729. /*!
  730. * Get the engine options as process environment.
  731. */
  732. const QProcessEnvironment& getOptionsAsProcessEnvironment() const;
  733. /*!
  734. * Set the engine option \a option.
  735. */
  736. void setOption(const OptionsType option, const int value, const char* const valueStr);
  737. #endif
  738. // -------------------------------------------------------------------
  739. // OSC Stuff
  740. #ifdef BUILD_BRIDGE
  741. /*!
  742. * Check if OSC bridge is registered.
  743. */
  744. bool isOscBridgeRegistered() const;
  745. #else
  746. /*!
  747. * Check if OSC controller is registered.
  748. */
  749. bool isOscControlRegistered() const;
  750. #endif
  751. /*!
  752. * Idle OSC.
  753. */
  754. void idleOsc();
  755. /*!
  756. * Get OSC TCP server path.
  757. */
  758. const char* getOscServerPathTCP() const;
  759. /*!
  760. * Get OSC UDP server path.
  761. */
  762. const char* getOscServerPathUDP() const;
  763. #ifdef BUILD_BRIDGE
  764. /*!
  765. * Set OSC bridge data.
  766. */
  767. void setOscBridgeData(const CarlaOscData* const oscData);
  768. #endif
  769. // -------------------------------------
  770. protected:
  771. uint32_t fBufferSize;
  772. double fSampleRate;
  773. CarlaString fName;
  774. EngineOptions fOptions;
  775. EngineTimeInfo fTimeInfo;
  776. CarlaEngineProtectedData* const fData;
  777. /*!
  778. * Report to all plugins about buffer size change.
  779. */
  780. void bufferSizeChanged(const uint32_t newBufferSize);
  781. /*!
  782. * Report to all plugins about sample rate change.\n
  783. * This is not supported on all plugin types, on which case they will be re-initiated.\n
  784. * TODO: Not implemented yet.
  785. */
  786. void sampleRateChanged(const double newSampleRate);
  787. /*!
  788. * TODO.
  789. */
  790. void proccessPendingEvents();
  791. /*!
  792. * TODO.
  793. */
  794. void setPeaks(const unsigned int pluginId, float* inPeaks, float* outPeaks);
  795. #ifndef BUILD_BRIDGE
  796. //static const unsigned short MAX_EVENTS = 1024;
  797. //EngineEvent fRackEventsIn[MAX_EVENTS];
  798. //EngineEvent fRackEventsOut[MAX_EVENTS];
  799. // Rack mode data
  800. EngineEvent* getRackEventBuffer(const bool isInput);
  801. /*!
  802. * Proccess audio buffer in rack mode.
  803. */
  804. void processRack(float* inBuf[2], float* outBuf[2], const uint32_t frames);
  805. /*!
  806. * Proccess audio buffer in patchbay mode.
  807. * In \a bufCount, [0]=inBufCount and [1]=outBufCount
  808. */
  809. void processPatchbay(float** inBuf, float** outBuf, const uint32_t bufCount[2], const uint32_t frames);
  810. #endif
  811. private:
  812. #ifdef WANT_JACK
  813. static CarlaEngine* newJack();
  814. #endif
  815. #ifdef WANT_RTAUDIO
  816. enum RtAudioApi {
  817. RTAUDIO_DUMMY = 0,
  818. RTAUDIO_LINUX_ALSA = 1,
  819. RTAUDIO_LINUX_PULSE = 2,
  820. RTAUDIO_LINUX_OSS = 3,
  821. RTAUDIO_UNIX_JACK = 4,
  822. RTAUDIO_MACOSX_CORE = 5,
  823. RTAUDIO_WINDOWS_ASIO = 6,
  824. RTAUDIO_WINDOWS_DS = 7
  825. };
  826. static CarlaEngine* newRtAudio(const RtAudioApi api);
  827. static unsigned int getRtAudioApiCount();
  828. static const char* getRtAudioApiName(unsigned int index);
  829. #endif
  830. public:
  831. #ifdef BUILD_BRIDGE
  832. void osc_send_peaks(CarlaPlugin* const plugin);
  833. #else
  834. void osc_send_peaks(CarlaPlugin* const plugin, const unsigned short& id);
  835. #endif
  836. #ifdef BUILD_BRIDGE
  837. void osc_send_bridge_audio_count(const int32_t ins, const int32_t outs, const int32_t total);
  838. void osc_send_bridge_midi_count(const int32_t ins, const int32_t outs, const int32_t total);
  839. void osc_send_bridge_parameter_count(const int32_t ins, const int32_t outs, const int32_t total);
  840. void osc_send_bridge_program_count(const int32_t count);
  841. void osc_send_bridge_midi_program_count(const int32_t count);
  842. 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);
  843. void osc_send_bridge_parameter_info(const int32_t index, const char* const name, const char* const unit);
  844. 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);
  845. 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);
  846. void osc_send_bridge_program_info(const int32_t index, const char* const name);
  847. void osc_send_bridge_midi_program_info(const int32_t index, const int32_t bank, const int32_t program, const char* const label);
  848. void osc_send_bridge_configure(const char* const key, const char* const value);
  849. void osc_send_bridge_set_parameter_value(const int32_t index, const double value);
  850. void osc_send_bridge_set_default_value(const int32_t index, const double value);
  851. void osc_send_bridge_set_program(const int32_t index);
  852. void osc_send_bridge_set_midi_program(const int32_t index);
  853. void osc_send_bridge_set_custom_data(const char* const type, const char* const key, const char* const value);
  854. void osc_send_bridge_set_chunk_data(const char* const chunkFile);
  855. void osc_send_bridge_set_inpeak(const int32_t portId);
  856. void osc_send_bridge_set_outpeak(const int32_t portId);
  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 double current);
  864. 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);
  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 double value);
  868. void osc_send_control_set_default_value(const int32_t pluginId, const int32_t index, const double 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_input_peak_value(const int32_t pluginId, const int32_t portId);
  878. void osc_send_control_set_output_peak_value(const int32_t pluginId, const int32_t portId);
  879. void osc_send_control_exit();
  880. #endif
  881. private:
  882. friend class CarlaEngineEventPort;
  883. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaEngine)
  884. };
  885. // -----------------------------------------------------------------------
  886. /**@}*/
  887. CARLA_BACKEND_END_NAMESPACE
  888. #endif // __CARLA_ENGINE_HPP__