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.

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