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.

970 lines
27KB

  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 decontructor.
  442. * The engine must have been closed before this happens.
  443. */
  444. virtual ~CarlaEngine();
  445. // -------------------------------------------------------------------
  446. // Static values and calls
  447. /*!
  448. * Maximum number of peaks per plugin.\n
  449. * \note There are both input and output peaks.
  450. */
  451. static const unsigned short MAX_PEAKS = 2;
  452. /*!
  453. * Get the number of available engine drivers.
  454. */
  455. static unsigned int getDriverCount();
  456. /*!
  457. * Get the name of the engine driver at \a index.
  458. */
  459. static const char* getDriverName(unsigned int index);
  460. /*!
  461. * Create a new engine, using driver \a driverName.\n
  462. * Returned variable must be deleted when no longer needed.
  463. */
  464. static CarlaEngine* newDriverByName(const char* const driverName);
  465. // -------------------------------------------------------------------
  466. // Maximum values
  467. /*!
  468. * Maximum client name size.
  469. */
  470. virtual int maxClientNameSize();
  471. /*!
  472. * Maximum port name size.
  473. */
  474. virtual int maxPortNameSize();
  475. /*!
  476. * Maximum number of loadable plugins.
  477. * \note This function returns 0 if no engine is not started.
  478. */
  479. unsigned short maxPluginNumber() const;
  480. // -------------------------------------------------------------------
  481. // Virtual, per-engine type calls
  482. /*!
  483. * Initialize engine, using \a clientName.
  484. */
  485. virtual bool init(const char* const clientName);
  486. /*!
  487. * Close engine.
  488. */
  489. virtual bool close();
  490. /*!
  491. * Check if engine is running.
  492. */
  493. virtual bool isRunning() const = 0;
  494. /*!
  495. * Check if engine is running offline (aka freewheel mode).
  496. */
  497. virtual bool isOffline() const = 0;
  498. /*!
  499. * Get engine type.
  500. */
  501. virtual CarlaEngineType type() const = 0;
  502. /*!
  503. * Add new engine client.
  504. * \note This must only be called within a plugin class.
  505. */
  506. virtual CarlaEngineClient* addClient(CarlaPlugin* const plugin) = 0;
  507. // -------------------------------------------------------------------
  508. // Plugin management
  509. /*!
  510. * Get next available plugin id.\n
  511. * Returns -1 if no more plugins can be loaded.
  512. */
  513. short getNewPluginId() const;
  514. /*!
  515. * Get plugin with id \a id.
  516. */
  517. CarlaPlugin* getPlugin(const unsigned short id) const;
  518. /*!
  519. * Get plugin with id \a id, faster unchecked version.
  520. */
  521. CarlaPlugin* getPluginUnchecked(const unsigned short id) const;
  522. /*!
  523. * Get a unique plugin name within the engine.\n
  524. * Returned variable must be free'd when no longer needed.
  525. */
  526. const char* getUniquePluginName(const char* const name);
  527. /*!
  528. * Add new plugin.\n
  529. * Returns the id of the plugin, or -1 if the operation failed.
  530. */
  531. short addPlugin(const BinaryType btype, const PluginType ptype, const char* const filename, const char* const name, const char* const label, void* const extra = nullptr);
  532. /*!
  533. * Add new plugin, using native binary type.\n
  534. * Returns the id of the plugin, or -1 if the operation failed.
  535. */
  536. short addPlugin(const PluginType ptype, const char* const filename, const char* const name, const char* const label, void* const extra = nullptr);
  537. /*!
  538. * Remove plugin with id \a id.
  539. */
  540. bool removePlugin(const unsigned short id);
  541. /*!
  542. * Remove all plugins.
  543. */
  544. void removeAllPlugins();
  545. /*!
  546. * Idle all plugins GUIs.
  547. */
  548. void idlePluginGuis();
  549. // bridge, internal use only
  550. // TODO - find a better way for this
  551. void __bridgePluginRegister(const unsigned short id, CarlaPlugin* const plugin)
  552. {
  553. m_carlaPlugins[id] = plugin;
  554. }
  555. // -------------------------------------------------------------------
  556. // Information (base)
  557. /*!
  558. * Get engine name.
  559. */
  560. const char* getName() const;
  561. /*!
  562. * Get current sample rate.
  563. */
  564. double getSampleRate() const;
  565. /*!
  566. * Get current buffer size.
  567. */
  568. uint32_t getBufferSize() const;
  569. /*!
  570. * Get current Time information.
  571. */
  572. const CarlaEngineTimeInfo* getTimeInfo() const;
  573. /*!
  574. * Tell the engine it's about to close.\n
  575. * This is used to prevent the engine thread from reactivating.
  576. */
  577. void aboutToClose();
  578. // -------------------------------------------------------------------
  579. // Information (audio peaks)
  580. double getInputPeak(const unsigned short pluginId, const unsigned short id) const;
  581. double getOutputPeak(const unsigned short pluginId, const unsigned short id) const;
  582. void setInputPeak(const unsigned short pluginId, const unsigned short id, double value);
  583. void setOutputPeak(const unsigned short pluginId, const unsigned short id, double value);
  584. // -------------------------------------------------------------------
  585. // Callback
  586. void callback(const CallbackType action, const unsigned short pluginId, const int value1, const int value2, const double value3, const char* const valueStr);
  587. void setCallback(const CallbackFunc func, void* const ptr);
  588. // -------------------------------------------------------------------
  589. // Error handling
  590. /*!
  591. * Get last error.
  592. */
  593. const char* getLastError() const;
  594. /*!
  595. * Set last error.
  596. */
  597. void setLastError(const char* const error);
  598. #ifndef BUILD_BRIDGE
  599. // -------------------------------------------------------------------
  600. // Options
  601. /*!
  602. * Get the engine options (read-only).
  603. */
  604. const CarlaEngineOptions& getOptions() const
  605. {
  606. return options;
  607. }
  608. /*!
  609. * Set the engine option \a option.
  610. */
  611. void setOption(const OptionsType option, const int value, const char* const valueStr);
  612. #endif
  613. // -------------------------------------------------------------------
  614. // Mutex locks
  615. /*!
  616. * Lock processing.
  617. */
  618. void processLock();
  619. /*!
  620. * Unlock processing.
  621. */
  622. void processUnlock();
  623. /*!
  624. * Lock MIDI.
  625. */
  626. void midiLock();
  627. /*!
  628. * Unlock MIDI.
  629. */
  630. void midiUnlock();
  631. // -------------------------------------------------------------------
  632. // OSC Stuff
  633. #ifndef BUILD_BRIDGE
  634. /*!
  635. * Check if OSC controller is registered.
  636. */
  637. bool isOscControlRegistered() const;
  638. #else
  639. /*!
  640. * Check if OSC bridge is registered.
  641. */
  642. bool isOscBridgeRegistered() const;
  643. #endif
  644. /*!
  645. * Idle OSC.
  646. */
  647. void idleOsc();
  648. /*!
  649. * Get OSC TCP server path.
  650. */
  651. const char* getOscServerPathTCP() const;
  652. /*!
  653. * Get OSC UDP server path.
  654. */
  655. const char* getOscServerPathUDP() const;
  656. #ifdef BUILD_BRIDGE
  657. /*!
  658. * Set OSC bridge data.
  659. */
  660. void setOscBridgeData(const CarlaOscData* const oscData);
  661. #endif
  662. #ifdef BUILD_BRIDGE
  663. void osc_send_peaks(CarlaPlugin* const plugin);
  664. #else
  665. void osc_send_peaks(CarlaPlugin* const plugin, const unsigned short& id);
  666. #endif
  667. #ifdef BUILD_BRIDGE
  668. void osc_send_bridge_audio_count(const int32_t ins, const int32_t outs, const int32_t total);
  669. void osc_send_bridge_midi_count(const int32_t ins, const int32_t outs, const int32_t total);
  670. void osc_send_bridge_parameter_count(const int32_t ins, const int32_t outs, const int32_t total);
  671. void osc_send_bridge_program_count(const int32_t count);
  672. void osc_send_bridge_midi_program_count(const int32_t count);
  673. 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);
  674. void osc_send_bridge_parameter_info(const int32_t index, const char* const name, const char* const unit);
  675. 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);
  676. 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);
  677. void osc_send_bridge_program_info(const int32_t index, const char* const name);
  678. void osc_send_bridge_midi_program_info(const int32_t index, const int32_t bank, const int32_t program, const char* const label);
  679. void osc_send_bridge_configure(const char* const key, const char* const value);
  680. void osc_send_bridge_set_parameter_value(const int32_t index, const double value);
  681. void osc_send_bridge_set_default_value(const int32_t index, const double value);
  682. void osc_send_bridge_set_program(const int32_t index);
  683. void osc_send_bridge_set_midi_program(const int32_t index);
  684. void osc_send_bridge_set_custom_data(const char* const type, const char* const key, const char* const value);
  685. void osc_send_bridge_set_chunk_data(const char* const chunkFile);
  686. void osc_send_bridge_set_inpeak(const int32_t portId);
  687. void osc_send_bridge_set_outpeak(const int32_t portId);
  688. #else
  689. void osc_send_control_add_plugin_start(const int32_t pluginId, const char* const pluginName);
  690. void osc_send_control_add_plugin_end(const int32_t pluginId);
  691. void osc_send_control_remove_plugin(const int32_t pluginId);
  692. 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);
  693. 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);
  694. 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);
  695. 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);
  696. void osc_send_control_set_parameter_midi_cc(const int32_t pluginId, const int32_t index, const int32_t cc);
  697. void osc_send_control_set_parameter_midi_channel(const int32_t pluginId, const int32_t index, const int32_t channel);
  698. void osc_send_control_set_parameter_value(const int32_t pluginId, const int32_t index, const double value);
  699. void osc_send_control_set_default_value(const int32_t pluginId, const int32_t index, const double value);
  700. void osc_send_control_set_program(const int32_t pluginId, const int32_t index);
  701. void osc_send_control_set_program_count(const int32_t pluginId, const int32_t count);
  702. void osc_send_control_set_program_name(const int32_t pluginId, const int32_t index, const char* const name);
  703. void osc_send_control_set_midi_program(const int32_t pluginId, const int32_t index);
  704. void osc_send_control_set_midi_program_count(const int32_t pluginId, const int32_t count);
  705. 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);
  706. void osc_send_control_note_on(const int32_t pluginId, const int32_t channel, const int32_t note, const int32_t velo);
  707. void osc_send_control_note_off(const int32_t pluginId, const int32_t channel, const int32_t note);
  708. void osc_send_control_set_input_peak_value(const int32_t pluginId, const int32_t portId);
  709. void osc_send_control_set_output_peak_value(const int32_t pluginId, const int32_t portId);
  710. void osc_send_control_exit();
  711. #endif
  712. #ifndef BUILD_BRIDGE
  713. // -------------------------------------------------------------------
  714. // Rack mode
  715. static const unsigned short MAX_CONTROL_EVENTS = 512;
  716. static const unsigned short MAX_MIDI_EVENTS = 512;
  717. CarlaEngineControlEvent rackControlEventsIn[MAX_CONTROL_EVENTS];
  718. CarlaEngineControlEvent rackControlEventsOut[MAX_CONTROL_EVENTS];
  719. CarlaEngineMidiEvent rackMidiEventsIn[MAX_MIDI_EVENTS];
  720. CarlaEngineMidiEvent rackMidiEventsOut[MAX_MIDI_EVENTS];
  721. #endif
  722. // -------------------------------------
  723. /*!
  724. * \class ScopedLocker
  725. *
  726. * \brief Carla engine scoped locker
  727. *
  728. * This is a handy class that temporarily locks an engine during a function scope.
  729. */
  730. class ScopedLocker
  731. {
  732. public:
  733. /*!
  734. * Lock the engine \a engine if \a lock is true.
  735. * The engine is unlocked in the deconstructor of this class if \a lock is true.
  736. *
  737. * \param engine The engine to lock
  738. * \param lock Wherever to lock the engine or not, true by default
  739. */
  740. ScopedLocker(CarlaEngine* const engine, bool lock = true)
  741. : mutex(&engine->m_procLock),
  742. m_lock(lock)
  743. {
  744. if (m_lock)
  745. mutex->lock();
  746. }
  747. ~ScopedLocker()
  748. {
  749. if (m_lock)
  750. mutex->unlock();
  751. }
  752. private:
  753. QMutex* const mutex;
  754. const bool m_lock;
  755. };
  756. // -------------------------------------
  757. protected:
  758. /*!
  759. * The contructor, protected.\n
  760. * \note This only initializes engine data, it doesn't initialize the engine itself.
  761. */
  762. CarlaEngine();
  763. #ifndef BUILD_BRIDGE
  764. /*!
  765. * Proccess audio buffer in rack mode, protected.
  766. */
  767. void processRack(float* inBuf[2], float* outBuf[2], const uint32_t frames);
  768. #endif
  769. #ifndef BUILD_BRIDGE
  770. CarlaEngineOptions options;
  771. #endif
  772. CarlaString name;
  773. uint32_t bufferSize;
  774. double sampleRate;
  775. CarlaEngineTimeInfo timeInfo;
  776. void bufferSizeChanged(const uint32_t newBufferSize);
  777. private:
  778. CarlaEngineOsc m_osc;
  779. CarlaEngineThread m_thread;
  780. const CarlaOscData* m_oscData;
  781. CallbackFunc m_callback;
  782. void* m_callbackPtr;
  783. CarlaString m_lastError;
  784. QMutex m_procLock;
  785. QMutex m_midiLock;
  786. CarlaPlugin* m_carlaPlugins[MAX_PLUGINS];
  787. const char* m_uniqueNames[MAX_PLUGINS];
  788. double m_insPeak[MAX_PLUGINS * MAX_PEAKS];
  789. double m_outsPeak[MAX_PLUGINS * MAX_PEAKS];
  790. bool m_aboutToClose;
  791. unsigned short m_maxPluginNumber;
  792. #ifdef CARLA_ENGINE_JACK
  793. static CarlaEngine* newJack();
  794. #endif
  795. #ifdef CARLA_ENGINE_RTAUDIO
  796. enum RtAudioApi {
  797. RTAUDIO_DUMMY = 0,
  798. RTAUDIO_LINUX_ALSA = 1,
  799. RTAUDIO_LINUX_PULSE = 2,
  800. RTAUDIO_LINUX_OSS = 3,
  801. RTAUDIO_UNIX_JACK = 4,
  802. RTAUDIO_MACOSX_CORE = 5,
  803. RTAUDIO_WINDOWS_ASIO = 6,
  804. RTAUDIO_WINDOWS_DS = 7
  805. };
  806. static CarlaEngine* newRtAudio(RtAudioApi api);
  807. static unsigned int getRtAudioApiCount();
  808. static const char* getRtAudioApiName(unsigned int index);
  809. #endif
  810. };
  811. // -----------------------------------------------------------------------
  812. /**@}*/
  813. CARLA_BACKEND_END_NAMESPACE
  814. #endif // CARLA_ENGINE_HPP