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.

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