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.

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