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.

1036 lines
28KB

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