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.

1009 lines
28KB

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