Audio plugin host https://kx.studio/carla
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.

995 lines
27KB

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