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.

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