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.

833 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. // -------------------------------------------------------------------
  527. // Information (audio peaks)
  528. double getInputPeak(const unsigned short pluginId, const unsigned short id) const;
  529. double getOutputPeak(const unsigned short pluginId, const unsigned short id) const;
  530. void setInputPeak(const unsigned short pluginId, const unsigned short id, double value);
  531. void setOutputPeak(const unsigned short pluginId, const unsigned short id, double value);
  532. // -------------------------------------------------------------------
  533. // Callback
  534. void callback(const CallbackType action, const unsigned short pluginId, const int value1, const int value2, const double value3);
  535. void setCallback(const CallbackFunc func, void* const ptr);
  536. // -------------------------------------------------------------------
  537. // Error handling
  538. const char* getLastError() const;
  539. void setLastError(const char* const error);
  540. #ifndef BUILD_BRIDGE
  541. // -------------------------------------------------------------------
  542. // Options
  543. void setOption(const OptionsType option, const int value, const char* const valueStr);
  544. ProcessMode processMode() const
  545. {
  546. return options.processMode;
  547. }
  548. #endif
  549. // -------------------------------------------------------------------
  550. // Mutex locks
  551. void processLock();
  552. void processUnlock();
  553. void midiLock();
  554. void midiUnlock();
  555. // -------------------------------------------------------------------
  556. // OSC Stuff
  557. bool isOscControlRegisted() const;
  558. bool idleOsc();
  559. #ifndef BUILD_BRIDGE
  560. const char* getOscServerPathTCP() const;
  561. const char* getOscServerPathUDP() const;
  562. #else
  563. void setOscBridgeData(const CarlaOscData* const oscData);
  564. #endif
  565. #ifdef BUILD_BRIDGE
  566. void osc_send_bridge_audio_count(const int32_t ins, const int32_t outs, const int32_t total);
  567. void osc_send_bridge_midi_count(const int32_t ins, const int32_t outs, const int32_t total);
  568. void osc_send_bridge_parameter_count(const int32_t ins, const int32_t outs, const int32_t total);
  569. void osc_send_bridge_program_count(const int32_t count);
  570. void osc_send_bridge_midi_program_count(const int32_t count);
  571. 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);
  572. void osc_send_bridge_parameter_info(const int32_t index, const char* const name, const char* const unit);
  573. 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);
  574. 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);
  575. void osc_send_bridge_program_info(const int32_t index, const char* const name);
  576. void osc_send_bridge_midi_program_info(const int32_t index, const int32_t bank, const int32_t program, const char* const label);
  577. void osc_send_bridge_configure(const char* const key, const char* const value);
  578. void osc_send_bridge_set_parameter_value(const int32_t index, const double value);
  579. void osc_send_bridge_set_default_value(const int32_t index, const double value);
  580. void osc_send_bridge_set_program(const int32_t index);
  581. void osc_send_bridge_set_midi_program(const int32_t index);
  582. void osc_send_bridge_set_custom_data(const char* const stype, const char* const key, const char* const value);
  583. void osc_send_bridge_set_chunk_data(const char* const chunkFile);
  584. void osc_send_bridge_set_inpeak(const int32_t portId);
  585. void osc_send_bridge_set_outpeak(const int32_t portId);
  586. #else
  587. void osc_send_control_add_plugin_start(const int32_t pluginId, const char* const pluginName);
  588. void osc_send_control_add_plugin_end(const int32_t pluginId);
  589. void osc_send_control_remove_plugin(const int32_t pluginId);
  590. 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);
  591. 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);
  592. 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);
  593. 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);
  594. void osc_send_control_set_parameter_midi_cc(const int32_t pluginId, const int32_t index, const int32_t cc);
  595. void osc_send_control_set_parameter_midi_channel(const int32_t pluginId, const int32_t index, const int32_t channel);
  596. void osc_send_control_set_parameter_value(const int32_t pluginId, const int32_t index, const double value);
  597. void osc_send_control_set_default_value(const int32_t pluginId, const int32_t index, const double value);
  598. void osc_send_control_set_program(const int32_t pluginId, const int32_t index);
  599. void osc_send_control_set_program_count(const int32_t pluginId, const int32_t count);
  600. void osc_send_control_set_program_name(const int32_t pluginId, const int32_t index, const char* const name);
  601. void osc_send_control_set_midi_program(const int32_t pluginId, const int32_t index);
  602. void osc_send_control_set_midi_program_count(const int32_t pluginId, const int32_t count);
  603. 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);
  604. void osc_send_control_note_on(const int32_t pluginId, const int32_t channel, const int32_t note, const int32_t velo);
  605. void osc_send_control_note_off(const int32_t pluginId, const int32_t channel, const int32_t note);
  606. void osc_send_control_set_input_peak_value(const int32_t pluginId, const int32_t portId);
  607. void osc_send_control_set_output_peak_value(const int32_t pluginId, const int32_t portId);
  608. void osc_send_control_exit();
  609. #endif
  610. #ifndef BUILD_BRIDGE
  611. // -------------------------------------------------------------------
  612. // Rack mode
  613. static const unsigned short MAX_ENGINE_CONTROL_EVENTS = 512;
  614. static const unsigned short MAX_ENGINE_MIDI_EVENTS = 512;
  615. CarlaEngineControlEvent rackControlEventsIn[MAX_ENGINE_CONTROL_EVENTS];
  616. CarlaEngineControlEvent rackControlEventsOut[MAX_ENGINE_CONTROL_EVENTS];
  617. CarlaEngineMidiEvent rackMidiEventsIn[MAX_ENGINE_MIDI_EVENTS];
  618. CarlaEngineMidiEvent rackMidiEventsOut[MAX_ENGINE_MIDI_EVENTS];
  619. #endif
  620. // -------------------------------------
  621. /*!
  622. * \class ScopedLocker
  623. *
  624. * \brief Carla engine scoped locker
  625. *
  626. * This is a handy class that temporarily locks an engine during a function scope.
  627. */
  628. class ScopedLocker
  629. {
  630. public:
  631. /*!
  632. * Lock the engine \a engine if \a lock is true.
  633. * The engine is unlocked in the deconstructor of this class if \a lock is true.
  634. *
  635. * \param engine The engine to lock
  636. * \param lock Wherever to lock the engine or not, true by default
  637. */
  638. ScopedLocker(CarlaEngine* const engine, bool lock = true)
  639. : mutex(&engine->m_procLock),
  640. m_lock(lock)
  641. {
  642. if (m_lock)
  643. mutex->lock();
  644. }
  645. ~ScopedLocker()
  646. {
  647. if (m_lock)
  648. mutex->unlock();
  649. }
  650. private:
  651. QMutex* const mutex;
  652. const bool m_lock;
  653. };
  654. // -------------------------------------
  655. protected:
  656. CarlaEngineOptions options;
  657. CarlaString name;
  658. uint32_t bufferSize;
  659. double sampleRate;
  660. CarlaEngineTimeInfo timeInfo;
  661. void bufferSizeChanged(const uint32_t newBufferSize);
  662. private:
  663. CarlaEngineThread m_thread;
  664. #ifndef BUILD_BRIDGE
  665. CarlaEngineOsc m_osc;
  666. #endif
  667. const CarlaOscData* m_oscData;
  668. CallbackFunc m_callback;
  669. void* m_callbackPtr;
  670. CarlaString m_lastError;
  671. QMutex m_procLock;
  672. QMutex m_midiLock;
  673. CarlaPlugin* m_carlaPlugins[MAX_PLUGINS];
  674. const char* m_uniqueNames[MAX_PLUGINS];
  675. double m_insPeak[MAX_PLUGINS * MAX_PEAKS];
  676. double m_outsPeak[MAX_PLUGINS * MAX_PEAKS];
  677. unsigned short m_maxPluginNumber;
  678. #ifdef CARLA_ENGINE_JACK
  679. static CarlaEngine* newJack();
  680. #endif
  681. #ifdef CARLA_ENGINE_RTAUDIO
  682. enum RtAudioApi {
  683. RTAUDIO_DUMMY = 0,
  684. RTAUDIO_LINUX_ALSA = 1,
  685. RTAUDIO_LINUX_PULSE = 2,
  686. RTAUDIO_LINUX_OSS = 3,
  687. RTAUDIO_UNIX_JACK = 4,
  688. RTAUDIO_MACOSX_CORE = 5,
  689. RTAUDIO_WINDOWS_ASIO = 6,
  690. RTAUDIO_WINDOWS_DS = 7
  691. };
  692. static CarlaEngine* newRtAudio(RtAudioApi api);
  693. static unsigned int getRtAudioApiCount();
  694. static const char* getRtAudioApiName(unsigned int index);
  695. #endif
  696. };
  697. // -----------------------------------------------------------------------
  698. /**@}*/
  699. CARLA_BACKEND_END_NAMESPACE
  700. #endif // CARLA_ENGINE_HPP