Collection of tools useful for audio production
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.

861 lines
25KB

  1. /*
  2. * Carla Engine
  3. * Copyright (C) 2012 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_engine_thread.hpp"
  20. #ifdef BUILD_BRIDGE
  21. # include "carla_osc_utils.hpp"
  22. #else
  23. # include "carla_engine_osc.hpp"
  24. #endif
  25. CARLA_BACKEND_START_NAMESPACE
  26. #ifdef BUILD_BRIDGE
  27. class CarlaPlugin;
  28. #endif
  29. /*!
  30. * @defgroup CarlaBackendEngine Carla Backend Engine
  31. *
  32. * The Carla Backend Engine
  33. * @{
  34. */
  35. /*!
  36. * @defgroup TimeInfoValidHints TimeInfo Valid Hints
  37. *
  38. * Various hints used for CarlaTimeInfo::valid.
  39. * @{
  40. */
  41. const uint32_t CarlaEngineTimeBBT = 0x1;
  42. /**@}*/
  43. /*!
  44. * The type of an engine.
  45. */
  46. enum CarlaEngineType {
  47. /*!
  48. * Null engine type.
  49. */
  50. CarlaEngineTypeNull = 0,
  51. /*!
  52. * Jack engine type.\n
  53. * Provides single, multi-client, and rack processing modes.
  54. */
  55. CarlaEngineTypeJack = 1,
  56. /*!
  57. * RtAudio engine type, used to provide ALSA, PulseAudio, DirectSound, ASIO and CoreAudio/Midi support.\n
  58. * Provides rack mode processing only.
  59. */
  60. CarlaEngineTypeRtAudio = 2,
  61. /*!
  62. * Plugin engine type, used to export the engine as a plugin (DSSI, LV2 and VST) via the DISTRHO Plugin Toolkit.\n
  63. * Works in rack mode only.
  64. */
  65. CarlaEngineTypePlugin = 3
  66. };
  67. /*!
  68. * The type of an engine port.
  69. */
  70. enum CarlaEnginePortType {
  71. /*!
  72. * Null engine port type.
  73. */
  74. CarlaEnginePortTypeNull = 0,
  75. /*!
  76. * Audio port.
  77. */
  78. CarlaEnginePortTypeAudio = 1,
  79. /*!
  80. * Control port.\n
  81. * These are MIDI ports on some engine types, by handling MIDI-CC as control.
  82. */
  83. CarlaEnginePortTypeControl = 2,
  84. /*!
  85. * MIDI port.
  86. */
  87. CarlaEnginePortTypeMIDI = 3
  88. };
  89. /*!
  90. * The type of a control event.
  91. */
  92. enum CarlaEngineControlEventType {
  93. /*!
  94. * Null event type.
  95. */
  96. CarlaEngineNullEvent = 0,
  97. /*!
  98. * Parameter change event.\n
  99. * \note Value uses a range of 0.0<->1.0.
  100. */
  101. CarlaEngineParameterChangeEvent = 1,
  102. /*!
  103. * MIDI Bank change event.
  104. */
  105. CarlaEngineMidiBankChangeEvent = 2,
  106. /*!
  107. * MIDI Program change event.
  108. */
  109. CarlaEngineMidiProgramChangeEvent = 3,
  110. /*!
  111. * All sound off event.
  112. */
  113. CarlaEngineAllSoundOffEvent = 4,
  114. /*!
  115. * All notes off event.
  116. */
  117. CarlaEngineAllNotesOffEvent = 5
  118. };
  119. /*!
  120. * Engine control event.
  121. */
  122. struct CarlaEngineControlEvent {
  123. CarlaEngineControlEventType type;
  124. uint32_t time;
  125. uint8_t channel;
  126. uint16_t parameter;
  127. double value;
  128. CarlaEngineControlEvent()
  129. : type(CarlaEngineNullEvent),
  130. time(0),
  131. channel(0),
  132. parameter(0),
  133. value(0.0) {}
  134. };
  135. /*!
  136. * Engine MIDI event.
  137. */
  138. struct CarlaEngineMidiEvent {
  139. uint32_t time;
  140. uint8_t size;
  141. uint8_t data[3];
  142. CarlaEngineMidiEvent()
  143. : time(0),
  144. #ifdef Q_COMPILER_INITIALIZER_LISTS
  145. size(0),
  146. data{0} {}
  147. #else
  148. size(0) { data[0] = data[1] = data[2] = 0; }
  149. #endif
  150. };
  151. /*!
  152. * Engine BBT Time information.
  153. */
  154. struct CarlaEngineTimeInfoBBT {
  155. int32_t bar;
  156. int32_t beat;
  157. int32_t tick;
  158. double bar_start_tick;
  159. float beats_per_bar;
  160. float beat_type;
  161. double ticks_per_beat;
  162. double beats_per_minute;
  163. CarlaEngineTimeInfoBBT()
  164. : bar(0),
  165. beat(0),
  166. tick(0),
  167. bar_start_tick(0.0),
  168. beats_per_bar(0.0f),
  169. beat_type(0.0f),
  170. ticks_per_beat(0.0),
  171. beats_per_minute(0.0) {}
  172. };
  173. /*!
  174. * Engine Time information.
  175. */
  176. struct CarlaEngineTimeInfo {
  177. bool playing;
  178. uint32_t frame;
  179. uint32_t time;
  180. uint32_t valid;
  181. CarlaEngineTimeInfoBBT bbt;
  182. CarlaEngineTimeInfo()
  183. : playing(false),
  184. frame(0),
  185. time(0),
  186. valid(0) {}
  187. };
  188. #ifndef BUILD_BRIDGE
  189. /*!
  190. * Engine options.
  191. */
  192. struct CarlaEngineOptions {
  193. ProcessMode processMode;
  194. bool processHighPrecision;
  195. uint maxParameters;
  196. uint preferredBufferSize;
  197. uint preferredSampleRate;
  198. bool forceStereo;
  199. bool useDssiVstChunks;
  200. bool preferPluginBridges;
  201. bool preferUiBridges;
  202. uint oscUiTimeout;
  203. CarlaString bridge_posix32;
  204. CarlaString bridge_posix64;
  205. CarlaString bridge_win32;
  206. CarlaString bridge_win64;
  207. CarlaString bridge_lv2gtk2;
  208. CarlaString bridge_lv2gtk3;
  209. CarlaString bridge_lv2qt4;
  210. CarlaString bridge_lv2qt5;
  211. CarlaString bridge_lv2cocoa;
  212. CarlaString bridge_lv2win;
  213. CarlaString bridge_lv2x11;
  214. CarlaString bridge_vstcocoa;
  215. CarlaString bridge_vsthwnd;
  216. CarlaString bridge_vstx11;
  217. CarlaEngineOptions()
  218. : processMode(PROCESS_MODE_CONTINUOUS_RACK),
  219. processHighPrecision(false),
  220. maxParameters(MAX_PARAMETERS),
  221. preferredBufferSize(512),
  222. preferredSampleRate(44100),
  223. forceStereo(false),
  224. useDssiVstChunks(false),
  225. preferPluginBridges(false),
  226. preferUiBridges(true),
  227. oscUiTimeout(4000/100) {}
  228. };
  229. #endif
  230. // -----------------------------------------------------------------------
  231. /*!
  232. * Engine port (Base).\n
  233. * This is the base class for all Carla engine ports.
  234. */
  235. class CarlaEngineBasePort
  236. {
  237. public:
  238. /*!
  239. * The contructor.\n
  240. * Param \a isInput defines wherever this is an input port or not (output otherwise).\n
  241. * Input/output state is constant for the lifetime of the port.
  242. */
  243. CarlaEngineBasePort(const bool isInput, const ProcessMode processMode);
  244. /*!
  245. * The decontructor.
  246. */
  247. virtual ~CarlaEngineBasePort();
  248. /*!
  249. * Get the type of the port, as provided by the respective subclasses.
  250. */
  251. virtual CarlaEnginePortType type() const = 0;
  252. /*!
  253. * Initialize the port's internal buffer for \a engine.
  254. */
  255. virtual void initBuffer(CarlaEngine* const engine) = 0;
  256. protected:
  257. const bool isInput;
  258. const ProcessMode processMode;
  259. void* buffer;
  260. };
  261. // -----------------------------------------------------------------------
  262. /*!
  263. * Engine port (Audio).
  264. */
  265. class CarlaEngineAudioPort : public CarlaEngineBasePort
  266. {
  267. public:
  268. /*!
  269. * The contructor.\n
  270. * Param \a isInput defines wherever this is an input port or not (output otherwise).\n
  271. * Input/output state is constant for the lifetime of the port.
  272. */
  273. CarlaEngineAudioPort(const bool isInput, const ProcessMode processMode);
  274. /*!
  275. * The decontructor.
  276. */
  277. virtual ~CarlaEngineAudioPort();
  278. /*!
  279. * Get the type of the port, in this case CarlaEnginePortTypeAudio.
  280. */
  281. CarlaEnginePortType type() const
  282. {
  283. return CarlaEnginePortTypeAudio;
  284. }
  285. /*!
  286. * Initialize the port's internal buffer for \a engine.
  287. */
  288. virtual void initBuffer(CarlaEngine* const engine);
  289. };
  290. // -----------------------------------------------------------------------
  291. /*!
  292. * Engine port (Control).
  293. */
  294. class CarlaEngineControlPort : public CarlaEngineBasePort
  295. {
  296. public:
  297. /*!
  298. * The contructor.\n
  299. * Param \a isInput defines wherever this is an input port or not (output otherwise).\n
  300. * Input/output state is constant for the lifetime of the port.
  301. */
  302. CarlaEngineControlPort(const bool isInput, const ProcessMode processMode);
  303. /*!
  304. * The decontructor.
  305. */
  306. virtual ~CarlaEngineControlPort();
  307. /*!
  308. * Get the type of the port, in this case CarlaEnginePortTypeControl.
  309. */
  310. CarlaEnginePortType type() const
  311. {
  312. return CarlaEnginePortTypeControl;
  313. }
  314. /*!
  315. * Initialize the port's internal buffer for \a engine.
  316. */
  317. virtual void initBuffer(CarlaEngine* const engine);
  318. /*!
  319. * Get the number of control events present in the buffer.
  320. * \note You must only call this for input ports.
  321. */
  322. virtual uint32_t getEventCount();
  323. /*!
  324. * Get the control event at \a index.
  325. ** \note You must only call this for input ports.
  326. */
  327. virtual const CarlaEngineControlEvent* getEvent(const uint32_t index);
  328. /*!
  329. * Write a control event to the buffer.\n
  330. * Arguments are the same as in the CarlaEngineControlEvent struct.
  331. ** \note You must only call this for output ports.
  332. */
  333. virtual void writeEvent(const CarlaEngineControlEventType type, const uint32_t time, const uint8_t channel, const uint16_t parameter, const double value);
  334. };
  335. // -----------------------------------------------------------------------
  336. /*!
  337. * Engine port (MIDI).
  338. */
  339. class CarlaEngineMidiPort : public CarlaEngineBasePort
  340. {
  341. public:
  342. /*!
  343. * The contructor.\n
  344. * Param \a isInput defines wherever this is an input port or not (output otherwise).\n
  345. * Input/output state is constant for the lifetime of the port.
  346. */
  347. CarlaEngineMidiPort(const bool isInput, const ProcessMode processMode);
  348. /*!
  349. * The decontructor.
  350. */
  351. virtual ~CarlaEngineMidiPort();
  352. /*!
  353. * Get the type of the port, in this case CarlaEnginePortTypeMIDI.
  354. */
  355. CarlaEnginePortType type() const
  356. {
  357. return CarlaEnginePortTypeMIDI;
  358. }
  359. /*!
  360. * Initialize the port's internal buffer for \a engine.
  361. */
  362. virtual void initBuffer(CarlaEngine* const engine);
  363. /*!
  364. * Get the number of MIDI events present in the buffer.
  365. * \note You must only call this for input ports.
  366. */
  367. virtual uint32_t getEventCount();
  368. /*!
  369. * Get the MIDI event at \a index.
  370. ** \note You must only call this for input ports.
  371. */
  372. virtual const CarlaEngineMidiEvent* getEvent(const uint32_t index);
  373. /*!
  374. * Write a MIDI event to the buffer.\n
  375. * Arguments are the same as in the CarlaEngineMidiEvent struct.
  376. ** \note You must only call this for output ports.
  377. */
  378. virtual void writeEvent(const uint32_t time, const uint8_t* const data, const uint8_t size);
  379. };
  380. // -----------------------------------------------------------------------
  381. /*!
  382. * Engine client.\n
  383. * Each plugin requires one client from the engine (created via CarlaEngine::addPort()).\n
  384. * \note This is a virtual class, each engine type provides its own funtionality.
  385. */
  386. class CarlaEngineClient
  387. {
  388. public:
  389. /*!
  390. * The contructor.\n
  391. * All constructor parameters are constant and will never change in the lifetime of the client.\n
  392. * Client starts in deactivated state.
  393. */
  394. CarlaEngineClient(const CarlaEngineType engineType, const ProcessMode processMode);
  395. /*!
  396. * The decontructor.
  397. */
  398. virtual ~CarlaEngineClient();
  399. /*!
  400. * Activate this client.\n
  401. * \note Client must be deactivated before calling this function.
  402. */
  403. virtual void activate();
  404. /*!
  405. * Deactivate this client.\n
  406. * \note Client must be activated before calling this function.
  407. */
  408. virtual void deactivate();
  409. /*!
  410. * Check if the client is activated.
  411. */
  412. virtual bool isActive() const;
  413. /*!
  414. * Check if the client is ok.\n
  415. * Plugins will refuse to instantiate if this returns false.
  416. * \note This is always true in rack and patchbay processing modes.
  417. */
  418. virtual bool isOk() const;
  419. /*!
  420. * Get the current latency, in samples.
  421. */
  422. virtual uint32_t getLatency() const;
  423. /*!
  424. * Change the client's latency.
  425. */
  426. virtual void setLatency(const uint32_t samples);
  427. /*!
  428. * Add a new port of type \a portType.
  429. * \note This function does nothing in rack processing mode since its ports are static (2 audio, 1 midi and 1 control for both input and output).
  430. */
  431. virtual const CarlaEngineBasePort* addPort(const CarlaEnginePortType portType, const char* const name, const bool isInput) = 0;
  432. protected:
  433. const CarlaEngineType engineType;
  434. const ProcessMode processMode;
  435. private:
  436. bool m_active;
  437. uint32_t m_latency;
  438. };
  439. // -----------------------------------------------------------------------
  440. /*!
  441. * Carla Engine.
  442. * \note This is a virtual class for all available engine types available in Carla.
  443. */
  444. class CarlaEngine
  445. {
  446. public:
  447. /*!
  448. * The contructor.\n
  449. * \note This only initializes engine data, it doesn't initialize the engine itself.
  450. */
  451. CarlaEngine();
  452. /*!
  453. * The decontructor.
  454. * The engine must have been closed before this happens.
  455. */
  456. virtual ~CarlaEngine();
  457. // -------------------------------------------------------------------
  458. // Static values and calls
  459. /*!
  460. * Maximum number of peaks per plugin.\n
  461. * \note There are both input and output peaks.
  462. */
  463. static const unsigned short MAX_PEAKS = 2;
  464. /*!
  465. * Get the number of available engine drivers.
  466. */
  467. static unsigned int getDriverCount();
  468. /*!
  469. * Get the name of the engine driver at \a index.
  470. */
  471. static const char* getDriverName(unsigned int index);
  472. /*!
  473. * Create a new engine, using driver \a driverName.
  474. */
  475. static CarlaEngine* newDriverByName(const char* const driverName);
  476. // -------------------------------------------------------------------
  477. // Maximum values
  478. virtual int maxClientNameSize();
  479. virtual int maxPortNameSize();
  480. unsigned short maxPluginNumber();
  481. // -------------------------------------------------------------------
  482. // Virtual, per-engine type calls
  483. virtual bool init(const char* const clientName);
  484. virtual bool close();
  485. virtual bool isOffline() const = 0;
  486. virtual bool isRunning() const = 0;
  487. virtual CarlaEngineType type() const = 0;
  488. virtual CarlaEngineClient* addClient(CarlaPlugin* const plugin) = 0;
  489. // -------------------------------------------------------------------
  490. // Plugin management
  491. short getNewPluginId() const;
  492. CarlaPlugin* getPlugin(const unsigned short id) const;
  493. CarlaPlugin* getPluginUnchecked(const unsigned short id) const;
  494. const char* getUniquePluginName(const char* const name);
  495. short addPlugin(const BinaryType btype, const PluginType ptype, const char* const filename, const char* const name, const char* const label, void* const extra = nullptr);
  496. short addPlugin(const PluginType ptype, const char* const filename, const char* const name, const char* const label, void* const extra = nullptr);
  497. bool removePlugin(const unsigned short id);
  498. void removeAllPlugins();
  499. void idlePluginGuis();
  500. #ifndef BUILD_BRIDGE
  501. void processRack(float* inBuf[2], float* outBuf[2], const uint32_t frames);
  502. #endif
  503. // bridge, internal use only
  504. void __bridgePluginRegister(const unsigned short id, CarlaPlugin* const plugin)
  505. {
  506. m_carlaPlugins[id] = plugin;
  507. }
  508. // -------------------------------------------------------------------
  509. // Information (base)
  510. const char* getName() const;
  511. double getSampleRate() const;
  512. uint32_t getBufferSize() const;
  513. const CarlaEngineTimeInfo* getTimeInfo() const;
  514. void aboutToClose();
  515. // -------------------------------------------------------------------
  516. // Information (audio peaks)
  517. double getInputPeak(const unsigned short pluginId, const unsigned short id) const;
  518. double getOutputPeak(const unsigned short pluginId, const unsigned short id) const;
  519. void setInputPeak(const unsigned short pluginId, const unsigned short id, double value);
  520. void setOutputPeak(const unsigned short pluginId, const unsigned short id, double value);
  521. // -------------------------------------------------------------------
  522. // Callback
  523. void callback(const CallbackType action, const unsigned short pluginId, const int value1, const int value2, const double value3, const char* const valueStr);
  524. void setCallback(const CallbackFunc func, void* const ptr);
  525. // -------------------------------------------------------------------
  526. // Error handling
  527. const char* getLastError() const;
  528. void setLastError(const char* const error);
  529. #ifndef BUILD_BRIDGE
  530. // -------------------------------------------------------------------
  531. // Options
  532. void setOption(const OptionsType option, const int value, const char* const valueStr);
  533. const CarlaEngineOptions& getOptions() const
  534. {
  535. return options;
  536. }
  537. ProcessMode processMode() const
  538. {
  539. return options.processMode;
  540. }
  541. bool processHighPrecision() const
  542. {
  543. return options.processHighPrecision;
  544. }
  545. uint maxParameters() const
  546. {
  547. return options.maxParameters;
  548. }
  549. bool forceStereo() const
  550. {
  551. return options.forceStereo;
  552. }
  553. bool useDssiVstChunks() const
  554. {
  555. return options.useDssiVstChunks;
  556. }
  557. bool preferUiBridges() const
  558. {
  559. return options.preferUiBridges;
  560. }
  561. uint oscUiTimeout() const
  562. {
  563. return options.oscUiTimeout;
  564. }
  565. #endif
  566. // -------------------------------------------------------------------
  567. // Mutex locks
  568. void processLock();
  569. void processUnlock();
  570. void midiLock();
  571. void midiUnlock();
  572. // -------------------------------------------------------------------
  573. // OSC Stuff
  574. bool isOscControlRegisted() const;
  575. #ifndef BUILD_BRIDGE
  576. bool idleOsc();
  577. const char* getOscServerPathTCP() const;
  578. const char* getOscServerPathUDP() const;
  579. #else
  580. void setOscBridgeData(const CarlaOscData* const oscData);
  581. #endif
  582. #ifdef BUILD_BRIDGE
  583. void osc_send_bridge_audio_count(const int32_t ins, const int32_t outs, const int32_t total);
  584. void osc_send_bridge_midi_count(const int32_t ins, const int32_t outs, const int32_t total);
  585. void osc_send_bridge_parameter_count(const int32_t ins, const int32_t outs, const int32_t total);
  586. void osc_send_bridge_program_count(const int32_t count);
  587. void osc_send_bridge_midi_program_count(const int32_t count);
  588. 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);
  589. void osc_send_bridge_parameter_info(const int32_t index, const char* const name, const char* const unit);
  590. 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);
  591. 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);
  592. void osc_send_bridge_program_info(const int32_t index, const char* const name);
  593. void osc_send_bridge_midi_program_info(const int32_t index, const int32_t bank, const int32_t program, const char* const label);
  594. void osc_send_bridge_configure(const char* const key, const char* const value);
  595. void osc_send_bridge_set_parameter_value(const int32_t index, const double value);
  596. void osc_send_bridge_set_default_value(const int32_t index, const double value);
  597. void osc_send_bridge_set_program(const int32_t index);
  598. void osc_send_bridge_set_midi_program(const int32_t index);
  599. void osc_send_bridge_set_custom_data(const char* const type, const char* const key, const char* const value);
  600. void osc_send_bridge_set_chunk_data(const char* const chunkFile);
  601. void osc_send_bridge_set_inpeak(const int32_t portId);
  602. void osc_send_bridge_set_outpeak(const int32_t portId);
  603. #else
  604. void osc_send_control_add_plugin_start(const int32_t pluginId, const char* const pluginName);
  605. void osc_send_control_add_plugin_end(const int32_t pluginId);
  606. void osc_send_control_remove_plugin(const int32_t pluginId);
  607. 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);
  608. 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);
  609. 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);
  610. 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);
  611. void osc_send_control_set_parameter_midi_cc(const int32_t pluginId, const int32_t index, const int32_t cc);
  612. void osc_send_control_set_parameter_midi_channel(const int32_t pluginId, const int32_t index, const int32_t channel);
  613. void osc_send_control_set_parameter_value(const int32_t pluginId, const int32_t index, const double value);
  614. void osc_send_control_set_default_value(const int32_t pluginId, const int32_t index, const double value);
  615. void osc_send_control_set_program(const int32_t pluginId, const int32_t index);
  616. void osc_send_control_set_program_count(const int32_t pluginId, const int32_t count);
  617. void osc_send_control_set_program_name(const int32_t pluginId, const int32_t index, const char* const name);
  618. void osc_send_control_set_midi_program(const int32_t pluginId, const int32_t index);
  619. void osc_send_control_set_midi_program_count(const int32_t pluginId, const int32_t count);
  620. 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);
  621. void osc_send_control_note_on(const int32_t pluginId, const int32_t channel, const int32_t note, const int32_t velo);
  622. void osc_send_control_note_off(const int32_t pluginId, const int32_t channel, const int32_t note);
  623. void osc_send_control_set_input_peak_value(const int32_t pluginId, const int32_t portId);
  624. void osc_send_control_set_output_peak_value(const int32_t pluginId, const int32_t portId);
  625. void osc_send_control_exit();
  626. #endif
  627. #ifndef BUILD_BRIDGE
  628. // -------------------------------------------------------------------
  629. // Rack mode
  630. static const unsigned short MAX_CONTROL_EVENTS = 512;
  631. static const unsigned short MAX_MIDI_EVENTS = 512;
  632. CarlaEngineControlEvent rackControlEventsIn[MAX_CONTROL_EVENTS];
  633. CarlaEngineControlEvent rackControlEventsOut[MAX_CONTROL_EVENTS];
  634. CarlaEngineMidiEvent rackMidiEventsIn[MAX_MIDI_EVENTS];
  635. CarlaEngineMidiEvent rackMidiEventsOut[MAX_MIDI_EVENTS];
  636. #endif
  637. // -------------------------------------
  638. /*!
  639. * \class ScopedLocker
  640. *
  641. * \brief Carla engine scoped locker
  642. *
  643. * This is a handy class that temporarily locks an engine during a function scope.
  644. */
  645. class ScopedLocker
  646. {
  647. public:
  648. /*!
  649. * Lock the engine \a engine if \a lock is true.
  650. * The engine is unlocked in the deconstructor of this class if \a lock is true.
  651. *
  652. * \param engine The engine to lock
  653. * \param lock Wherever to lock the engine or not, true by default
  654. */
  655. ScopedLocker(CarlaEngine* const engine, bool lock = true)
  656. : mutex(&engine->m_procLock),
  657. m_lock(lock)
  658. {
  659. if (m_lock)
  660. mutex->lock();
  661. }
  662. ~ScopedLocker()
  663. {
  664. if (m_lock)
  665. mutex->unlock();
  666. }
  667. private:
  668. QMutex* const mutex;
  669. const bool m_lock;
  670. };
  671. // -------------------------------------
  672. protected:
  673. #ifndef BUILD_BRIDGE
  674. CarlaEngineOptions options;
  675. #endif
  676. CarlaString name;
  677. uint32_t bufferSize;
  678. double sampleRate;
  679. CarlaEngineTimeInfo timeInfo;
  680. void bufferSizeChanged(const uint32_t newBufferSize);
  681. private:
  682. CarlaEngineThread m_thread;
  683. #ifndef BUILD_BRIDGE
  684. CarlaEngineOsc m_osc;
  685. #endif
  686. const CarlaOscData* m_oscData;
  687. CallbackFunc m_callback;
  688. void* m_callbackPtr;
  689. CarlaString m_lastError;
  690. QMutex m_procLock;
  691. QMutex m_midiLock;
  692. CarlaPlugin* m_carlaPlugins[MAX_PLUGINS];
  693. const char* m_uniqueNames[MAX_PLUGINS];
  694. double m_insPeak[MAX_PLUGINS * MAX_PEAKS];
  695. double m_outsPeak[MAX_PLUGINS * MAX_PEAKS];
  696. bool m_aboutToClose;
  697. unsigned short m_maxPluginNumber;
  698. #ifdef CARLA_ENGINE_JACK
  699. static CarlaEngine* newJack();
  700. #endif
  701. #ifdef CARLA_ENGINE_RTAUDIO
  702. enum RtAudioApi {
  703. RTAUDIO_DUMMY = 0,
  704. RTAUDIO_LINUX_ALSA = 1,
  705. RTAUDIO_LINUX_PULSE = 2,
  706. RTAUDIO_LINUX_OSS = 3,
  707. RTAUDIO_UNIX_JACK = 4,
  708. RTAUDIO_MACOSX_CORE = 5,
  709. RTAUDIO_WINDOWS_ASIO = 6,
  710. RTAUDIO_WINDOWS_DS = 7
  711. };
  712. static CarlaEngine* newRtAudio(RtAudioApi api);
  713. static unsigned int getRtAudioApiCount();
  714. static const char* getRtAudioApiName(unsigned int index);
  715. #endif
  716. };
  717. // -----------------------------------------------------------------------
  718. /**@}*/
  719. CARLA_BACKEND_END_NAMESPACE
  720. #endif // CARLA_ENGINE_HPP