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.

1013 lines
28KB

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