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.

847 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 parameter;
  120. double value;
  121. CarlaEngineControlEvent()
  122. : type(CarlaEngineNullEvent),
  123. time(0),
  124. channel(0),
  125. parameter(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_lv2qt5;
  204. CarlaString bridge_lv2cocoa;
  205. CarlaString bridge_lv2win;
  206. CarlaString bridge_lv2x11;
  207. CarlaString bridge_vstcocoa;
  208. CarlaString bridge_vsthwnd;
  209. CarlaString bridge_vstx11;
  210. CarlaEngineOptions()
  211. : processMode(PROCESS_MODE_CONTINUOUS_RACK),
  212. processHighPrecision(false),
  213. maxParameters(MAX_PARAMETERS),
  214. preferredBufferSize(512),
  215. preferredSampleRate(44100),
  216. forceStereo(false),
  217. useDssiVstChunks(false),
  218. preferPluginBridges(false),
  219. preferUiBridges(true),
  220. oscUiTimeout(4000/100) {}
  221. };
  222. #endif
  223. // -----------------------------------------------------------------------
  224. /*!
  225. * Engine port (Base).\n
  226. * This is the base class for all Carla engine ports.
  227. */
  228. class CarlaEngineBasePort
  229. {
  230. public:
  231. /*!
  232. * The contructor.\n
  233. * Param \a isInput defines wherever this is an input port or not (output otherwise).\n
  234. * Input/output state is constant for the lifetime of the port.
  235. */
  236. CarlaEngineBasePort(const bool isInput, const ProcessMode processMode);
  237. /*!
  238. * The decontructor.
  239. */
  240. virtual ~CarlaEngineBasePort();
  241. /*!
  242. * Get the type of the port, as provided by the respective subclasses.
  243. */
  244. virtual CarlaEnginePortType type() const = 0;
  245. /*!
  246. * Initialize the port's internal buffer for \a engine.
  247. */
  248. virtual void initBuffer(CarlaEngine* const engine) = 0;
  249. protected:
  250. const bool isInput;
  251. const ProcessMode processMode;
  252. void* buffer;
  253. };
  254. // -----------------------------------------------------------------------
  255. /*!
  256. * Engine port (Audio).
  257. */
  258. class CarlaEngineAudioPort : public CarlaEngineBasePort
  259. {
  260. public:
  261. /*!
  262. * The contructor.\n
  263. * Param \a isInput defines wherever this is an input port or not (output otherwise).\n
  264. * Input/output state is constant for the lifetime of the port.
  265. */
  266. CarlaEngineAudioPort(const bool isInput, const ProcessMode processMode);
  267. /*!
  268. * The decontructor.
  269. */
  270. virtual ~CarlaEngineAudioPort();
  271. /*!
  272. * Get the type of the port, in this case CarlaEnginePortTypeAudio.
  273. */
  274. CarlaEnginePortType type() const
  275. {
  276. return CarlaEnginePortTypeAudio;
  277. }
  278. /*!
  279. * Initialize the port's internal buffer for \a engine.
  280. */
  281. virtual void initBuffer(CarlaEngine* const engine);
  282. };
  283. // -----------------------------------------------------------------------
  284. /*!
  285. * Engine port (Control).
  286. */
  287. class CarlaEngineControlPort : public CarlaEngineBasePort
  288. {
  289. public:
  290. /*!
  291. * The contructor.\n
  292. * Param \a isInput defines wherever this is an input port or not (output otherwise).\n
  293. * Input/output state is constant for the lifetime of the port.
  294. */
  295. CarlaEngineControlPort(const bool isInput, const ProcessMode processMode);
  296. /*!
  297. * The decontructor.
  298. */
  299. virtual ~CarlaEngineControlPort();
  300. /*!
  301. * Get the type of the port, in this case CarlaEnginePortTypeControl.
  302. */
  303. CarlaEnginePortType type() const
  304. {
  305. return CarlaEnginePortTypeControl;
  306. }
  307. /*!
  308. * Initialize the port's internal buffer for \a engine.
  309. */
  310. virtual void initBuffer(CarlaEngine* const engine);
  311. /*!
  312. * Get the number of control events present in the buffer.
  313. * \note You must only call this for input ports.
  314. */
  315. virtual uint32_t getEventCount();
  316. /*!
  317. * Get the control event at \a index.
  318. ** \note You must only call this for input ports.
  319. */
  320. virtual const CarlaEngineControlEvent* getEvent(const uint32_t index);
  321. /*!
  322. * Write a control event to the buffer.\n
  323. * Arguments are the same as in the CarlaEngineControlEvent struct.
  324. ** \note You must only call this for output ports.
  325. */
  326. virtual void writeEvent(const CarlaEngineControlEventType type, const uint32_t time, const uint8_t channel, const uint16_t parameter, const double value);
  327. };
  328. // -----------------------------------------------------------------------
  329. /*!
  330. * Engine port (MIDI).
  331. */
  332. class CarlaEngineMidiPort : public CarlaEngineBasePort
  333. {
  334. public:
  335. /*!
  336. * The contructor.\n
  337. * Param \a isInput defines wherever this is an input port or not (output otherwise).\n
  338. * Input/output state is constant for the lifetime of the port.
  339. */
  340. CarlaEngineMidiPort(const bool isInput, const ProcessMode processMode);
  341. /*!
  342. * The decontructor.
  343. */
  344. virtual ~CarlaEngineMidiPort();
  345. /*!
  346. * Get the type of the port, in this case CarlaEnginePortTypeMIDI.
  347. */
  348. CarlaEnginePortType type() const
  349. {
  350. return CarlaEnginePortTypeMIDI;
  351. }
  352. /*!
  353. * Initialize the port's internal buffer for \a engine.
  354. */
  355. virtual void initBuffer(CarlaEngine* const engine);
  356. /*!
  357. * Get the number of MIDI events present in the buffer.
  358. * \note You must only call this for input ports.
  359. */
  360. virtual uint32_t getEventCount();
  361. /*!
  362. * Get the MIDI event at \a index.
  363. ** \note You must only call this for input ports.
  364. */
  365. virtual const CarlaEngineMidiEvent* getEvent(const uint32_t index);
  366. /*!
  367. * Write a MIDI event to the buffer.\n
  368. * Arguments are the same as in the CarlaEngineMidiEvent struct.
  369. ** \note You must only call this for output ports.
  370. */
  371. virtual void writeEvent(const uint32_t time, const uint8_t* const data, const uint8_t size);
  372. };
  373. // -----------------------------------------------------------------------
  374. /*!
  375. * Engine client.\n
  376. * Each plugin requires one client from the engine (created via CarlaEngine::addPort()).\n
  377. * \note This is a virtual class, each engine type provides its own funtionality.
  378. */
  379. class CarlaEngineClient
  380. {
  381. public:
  382. /*!
  383. * The contructor.\n
  384. * All constructor parameters are constant and will never change in the lifetime of the client.\n
  385. * Client starts in deactivated state.
  386. */
  387. CarlaEngineClient(const CarlaEngineType engineType, const ProcessMode processMode);
  388. /*!
  389. * The decontructor.
  390. */
  391. virtual ~CarlaEngineClient();
  392. /*!
  393. * Activate this client.\n
  394. * \note Client must be deactivated before calling this function.
  395. */
  396. virtual void activate();
  397. /*!
  398. * Deactivate this client.\n
  399. * \note Client must be activated before calling this function.
  400. */
  401. virtual void deactivate();
  402. /*!
  403. * Check if the client is activated.
  404. */
  405. virtual bool isActive() const;
  406. /*!
  407. * Check if the client is ok.\n
  408. * Plugins will refuse to instantiate if this returns false.
  409. * \note This is always true in rack and patchbay processing modes.
  410. */
  411. virtual bool isOk() const;
  412. /*!
  413. * Get the current latency, in samples.
  414. */
  415. virtual uint32_t getLatency() const;
  416. /*!
  417. * Change the client's latency.
  418. */
  419. virtual void setLatency(const uint32_t samples);
  420. /*!
  421. * Add a new port of type \a portType.
  422. * \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).
  423. */
  424. virtual const CarlaEngineBasePort* addPort(const CarlaEnginePortType portType, const char* const name, const bool isInput) = 0;
  425. protected:
  426. const CarlaEngineType engineType;
  427. const ProcessMode processMode;
  428. private:
  429. bool m_active;
  430. uint32_t m_latency;
  431. };
  432. // -----------------------------------------------------------------------
  433. /*!
  434. * Carla Engine.
  435. * \note This is a virtual class for all available engine types available in Carla.
  436. */
  437. class CarlaEngine
  438. {
  439. public:
  440. /*!
  441. * The contructor.\n
  442. * \note This only initializes engine data, it doesn't initialize the engine itself.
  443. */
  444. CarlaEngine();
  445. /*!
  446. * The decontructor.
  447. * The engine must have been closed before this happens.
  448. */
  449. virtual ~CarlaEngine();
  450. // -------------------------------------------------------------------
  451. // Static values and calls
  452. /*!
  453. * Maximum number of peaks per plugin.\n
  454. * \note There are both input and output peaks.
  455. */
  456. static const unsigned short MAX_PEAKS = 2;
  457. /*!
  458. * Get the number of available engine drivers.
  459. */
  460. static unsigned int getDriverCount();
  461. /*!
  462. * Get the name of the engine driver at \a index.
  463. */
  464. static const char* getDriverName(unsigned int index);
  465. /*!
  466. * Create a new engine, using driver \a driverName.
  467. */
  468. static CarlaEngine* newDriverByName(const char* const driverName);
  469. // -------------------------------------------------------------------
  470. // Maximum values
  471. virtual int maxClientNameSize();
  472. virtual int maxPortNameSize();
  473. unsigned short maxPluginNumber();
  474. // -------------------------------------------------------------------
  475. // Virtual, per-engine type calls
  476. virtual bool init(const char* const clientName);
  477. virtual bool close();
  478. virtual bool isOffline() const = 0;
  479. virtual bool isRunning() const = 0;
  480. virtual CarlaEngineType type() const = 0;
  481. virtual CarlaEngineClient* addClient(CarlaPlugin* const plugin) = 0;
  482. // -------------------------------------------------------------------
  483. // Plugin management
  484. short getNewPluginId() const;
  485. CarlaPlugin* getPlugin(const unsigned short id) const;
  486. CarlaPlugin* getPluginUnchecked(const unsigned short id) const;
  487. const char* getUniquePluginName(const char* const name);
  488. short addPlugin(const BinaryType btype, const PluginType ptype, const char* const filename, const char* const name, const char* const label, void* const extra = nullptr);
  489. short addPlugin(const PluginType ptype, const char* const filename, const char* const name, const char* const label, void* const extra = nullptr);
  490. bool removePlugin(const unsigned short id);
  491. void removeAllPlugins();
  492. void idlePluginGuis();
  493. #ifndef BUILD_BRIDGE
  494. void processRack(float* inBuf[2], float* outBuf[2], const uint32_t frames);
  495. #endif
  496. // bridge, internal use only
  497. void __bridgePluginRegister(const unsigned short id, CarlaPlugin* const plugin)
  498. {
  499. m_carlaPlugins[id] = plugin;
  500. }
  501. // -------------------------------------------------------------------
  502. // Information (base)
  503. const char* getName() const;
  504. double getSampleRate() const;
  505. uint32_t getBufferSize() const;
  506. const CarlaEngineTimeInfo* getTimeInfo() const;
  507. void aboutToClose();
  508. // -------------------------------------------------------------------
  509. // Information (audio peaks)
  510. double getInputPeak(const unsigned short pluginId, const unsigned short id) const;
  511. double getOutputPeak(const unsigned short pluginId, const unsigned short id) const;
  512. void setInputPeak(const unsigned short pluginId, const unsigned short id, double value);
  513. void setOutputPeak(const unsigned short pluginId, const unsigned short id, double value);
  514. // -------------------------------------------------------------------
  515. // Callback
  516. void callback(const CallbackType action, const unsigned short pluginId, const int value1, const int value2, const double value3);
  517. void setCallback(const CallbackFunc func, void* const ptr);
  518. // -------------------------------------------------------------------
  519. // Error handling
  520. const char* getLastError() const;
  521. void setLastError(const char* const error);
  522. #ifndef BUILD_BRIDGE
  523. // -------------------------------------------------------------------
  524. // Options
  525. void setOption(const OptionsType option, const int value, const char* const valueStr);
  526. ProcessMode processMode() const
  527. {
  528. return options.processMode;
  529. }
  530. bool processHighPrecision() const
  531. {
  532. return options.processHighPrecision;
  533. }
  534. uint maxParameters() const
  535. {
  536. return options.maxParameters;
  537. }
  538. bool forceStereo() const
  539. {
  540. return options.forceStereo;
  541. }
  542. bool useDssiVstChunks() const
  543. {
  544. return options.useDssiVstChunks;
  545. }
  546. bool preferUiBridges() const
  547. {
  548. return options.preferUiBridges;
  549. }
  550. uint oscUiTimeout() const
  551. {
  552. return options.oscUiTimeout;
  553. }
  554. #endif
  555. // -------------------------------------------------------------------
  556. // Mutex locks
  557. void processLock();
  558. void processUnlock();
  559. void midiLock();
  560. void midiUnlock();
  561. // -------------------------------------------------------------------
  562. // OSC Stuff
  563. bool isOscControlRegisted() const;
  564. #ifndef BUILD_BRIDGE
  565. bool idleOsc();
  566. const char* getOscServerPathTCP() const;
  567. const char* getOscServerPathUDP() const;
  568. #else
  569. void setOscBridgeData(const CarlaOscData* const oscData);
  570. #endif
  571. #ifdef BUILD_BRIDGE
  572. void osc_send_bridge_audio_count(const int32_t ins, const int32_t outs, const int32_t total);
  573. void osc_send_bridge_midi_count(const int32_t ins, const int32_t outs, const int32_t total);
  574. void osc_send_bridge_parameter_count(const int32_t ins, const int32_t outs, const int32_t total);
  575. void osc_send_bridge_program_count(const int32_t count);
  576. void osc_send_bridge_midi_program_count(const int32_t count);
  577. 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);
  578. void osc_send_bridge_parameter_info(const int32_t index, const char* const name, const char* const unit);
  579. 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);
  580. 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);
  581. void osc_send_bridge_program_info(const int32_t index, const char* const name);
  582. void osc_send_bridge_midi_program_info(const int32_t index, const int32_t bank, const int32_t program, const char* const label);
  583. void osc_send_bridge_configure(const char* const key, const char* const value);
  584. void osc_send_bridge_set_parameter_value(const int32_t index, const double value);
  585. void osc_send_bridge_set_default_value(const int32_t index, const double value);
  586. void osc_send_bridge_set_program(const int32_t index);
  587. void osc_send_bridge_set_midi_program(const int32_t index);
  588. void osc_send_bridge_set_custom_data(const char* const stype, const char* const key, const char* const value);
  589. void osc_send_bridge_set_chunk_data(const char* const chunkFile);
  590. void osc_send_bridge_set_inpeak(const int32_t portId);
  591. void osc_send_bridge_set_outpeak(const int32_t portId);
  592. #else
  593. void osc_send_control_add_plugin_start(const int32_t pluginId, const char* const pluginName);
  594. void osc_send_control_add_plugin_end(const int32_t pluginId);
  595. void osc_send_control_remove_plugin(const int32_t pluginId);
  596. 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);
  597. 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);
  598. 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);
  599. 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);
  600. void osc_send_control_set_parameter_midi_cc(const int32_t pluginId, const int32_t index, const int32_t cc);
  601. void osc_send_control_set_parameter_midi_channel(const int32_t pluginId, const int32_t index, const int32_t channel);
  602. void osc_send_control_set_parameter_value(const int32_t pluginId, const int32_t index, const double value);
  603. void osc_send_control_set_default_value(const int32_t pluginId, const int32_t index, const double value);
  604. void osc_send_control_set_program(const int32_t pluginId, const int32_t index);
  605. void osc_send_control_set_program_count(const int32_t pluginId, const int32_t count);
  606. void osc_send_control_set_program_name(const int32_t pluginId, const int32_t index, const char* const name);
  607. void osc_send_control_set_midi_program(const int32_t pluginId, const int32_t index);
  608. void osc_send_control_set_midi_program_count(const int32_t pluginId, const int32_t count);
  609. 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);
  610. void osc_send_control_note_on(const int32_t pluginId, const int32_t channel, const int32_t note, const int32_t velo);
  611. void osc_send_control_note_off(const int32_t pluginId, const int32_t channel, const int32_t note);
  612. void osc_send_control_set_input_peak_value(const int32_t pluginId, const int32_t portId);
  613. void osc_send_control_set_output_peak_value(const int32_t pluginId, const int32_t portId);
  614. void osc_send_control_exit();
  615. #endif
  616. #ifndef BUILD_BRIDGE
  617. // -------------------------------------------------------------------
  618. // Rack mode
  619. static const unsigned short MAX_CONTROL_EVENTS = 512;
  620. static const unsigned short MAX_MIDI_EVENTS = 512;
  621. CarlaEngineControlEvent rackControlEventsIn[MAX_CONTROL_EVENTS];
  622. CarlaEngineControlEvent rackControlEventsOut[MAX_CONTROL_EVENTS];
  623. CarlaEngineMidiEvent rackMidiEventsIn[MAX_MIDI_EVENTS];
  624. CarlaEngineMidiEvent rackMidiEventsOut[MAX_MIDI_EVENTS];
  625. #endif
  626. // -------------------------------------
  627. /*!
  628. * \class ScopedLocker
  629. *
  630. * \brief Carla engine scoped locker
  631. *
  632. * This is a handy class that temporarily locks an engine during a function scope.
  633. */
  634. class ScopedLocker
  635. {
  636. public:
  637. /*!
  638. * Lock the engine \a engine if \a lock is true.
  639. * The engine is unlocked in the deconstructor of this class if \a lock is true.
  640. *
  641. * \param engine The engine to lock
  642. * \param lock Wherever to lock the engine or not, true by default
  643. */
  644. ScopedLocker(CarlaEngine* const engine, bool lock = true)
  645. : mutex(&engine->m_procLock),
  646. m_lock(lock)
  647. {
  648. if (m_lock)
  649. mutex->lock();
  650. }
  651. ~ScopedLocker()
  652. {
  653. if (m_lock)
  654. mutex->unlock();
  655. }
  656. private:
  657. QMutex* const mutex;
  658. const bool m_lock;
  659. };
  660. // -------------------------------------
  661. protected:
  662. #ifndef BUILD_BRIDGE
  663. CarlaEngineOptions options;
  664. #endif
  665. CarlaString name;
  666. uint32_t bufferSize;
  667. double sampleRate;
  668. CarlaEngineTimeInfo timeInfo;
  669. void bufferSizeChanged(const uint32_t newBufferSize);
  670. private:
  671. CarlaEngineThread m_thread;
  672. #ifndef BUILD_BRIDGE
  673. CarlaEngineOsc m_osc;
  674. #endif
  675. const CarlaOscData* m_oscData;
  676. CallbackFunc m_callback;
  677. void* m_callbackPtr;
  678. CarlaString m_lastError;
  679. QMutex m_procLock;
  680. QMutex m_midiLock;
  681. CarlaPlugin* m_carlaPlugins[MAX_PLUGINS];
  682. const char* m_uniqueNames[MAX_PLUGINS];
  683. double m_insPeak[MAX_PLUGINS * MAX_PEAKS];
  684. double m_outsPeak[MAX_PLUGINS * MAX_PEAKS];
  685. bool m_aboutToClose;
  686. unsigned short m_maxPluginNumber;
  687. #ifdef CARLA_ENGINE_JACK
  688. static CarlaEngine* newJack();
  689. #endif
  690. #ifdef CARLA_ENGINE_RTAUDIO
  691. enum RtAudioApi {
  692. RTAUDIO_DUMMY = 0,
  693. RTAUDIO_LINUX_ALSA = 1,
  694. RTAUDIO_LINUX_PULSE = 2,
  695. RTAUDIO_LINUX_OSS = 3,
  696. RTAUDIO_UNIX_JACK = 4,
  697. RTAUDIO_MACOSX_CORE = 5,
  698. RTAUDIO_WINDOWS_ASIO = 6,
  699. RTAUDIO_WINDOWS_DS = 7
  700. };
  701. static CarlaEngine* newRtAudio(RtAudioApi api);
  702. static unsigned int getRtAudioApiCount();
  703. static const char* getRtAudioApiName(unsigned int index);
  704. #endif
  705. };
  706. // -----------------------------------------------------------------------
  707. /**@}*/
  708. CARLA_BACKEND_END_NAMESPACE
  709. #endif // CARLA_ENGINE_HPP