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.

1188 lines
34KB

  1. /*
  2. * Carla Plugin Host
  3. * Copyright (C) 2011-2014 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or 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 doc/GPL.txt file.
  16. */
  17. #ifndef CARLA_ENGINE_HPP_INCLUDED
  18. #define CARLA_ENGINE_HPP_INCLUDED
  19. #include "CarlaBackend.h"
  20. #ifdef BUILD_BRIDGE
  21. struct CarlaOscData;
  22. #endif
  23. // -----------------------------------------------------------------------
  24. CARLA_BACKEND_START_NAMESPACE
  25. #if 0
  26. } /* Fix editor indentation */
  27. #endif
  28. // -----------------------------------------------------------------------
  29. /*!
  30. * @defgroup CarlaEngineAPI Carla Engine API
  31. *
  32. * The Carla Engine API.
  33. * @{
  34. */
  35. /*!
  36. * The type of an engine.
  37. */
  38. enum EngineType {
  39. /*!
  40. * Null engine type.
  41. */
  42. kEngineTypeNull = 0,
  43. /*!
  44. * JACK engine type.\n
  45. * Provides all processing modes.
  46. */
  47. kEngineTypeJack = 1,
  48. /*!
  49. * Juce engine type, used to provide Native Audio and MIDI support.
  50. */
  51. kEngineTypeJuce = 2,
  52. /*!
  53. * RtAudio engine type, used to provide Native Audio and MIDI support.
  54. */
  55. kEngineTypeRtAudio = 3,
  56. /*!
  57. * Plugin engine type, used to export the engine as a plugin.
  58. */
  59. kEngineTypePlugin = 4,
  60. /*!
  61. * Bridge engine type, used in BridgePlugin class.
  62. */
  63. kEngineTypeBridge = 5
  64. };
  65. /*!
  66. * The type of an engine port.
  67. */
  68. enum EnginePortType {
  69. /*!
  70. * Null port type.
  71. */
  72. kEnginePortTypeNull = 0,
  73. /*!
  74. * Audio port type.
  75. * \see CarlaEngineAudioPort
  76. */
  77. kEnginePortTypeAudio = 1,
  78. /*!
  79. * CV port type.
  80. * \see CarlaEngineCVPort
  81. */
  82. kEnginePortTypeCV = 2,
  83. /*!
  84. * Event port type (Control or MIDI).
  85. ** \see CarlaEngineEventPort
  86. */
  87. kEnginePortTypeEvent = 3
  88. };
  89. /*!
  90. * The type of an engine event.
  91. */
  92. enum EngineEventType {
  93. /*!
  94. * Null port type.
  95. */
  96. kEngineEventTypeNull = 0,
  97. /*!
  98. * Control event type.
  99. * \see EngineControlEvent
  100. */
  101. kEngineEventTypeControl = 1,
  102. /*!
  103. * MIDI event type.
  104. * \see EngineMidiEvent
  105. */
  106. kEngineEventTypeMidi = 2
  107. };
  108. /*!
  109. * The type of an engine control event.
  110. */
  111. enum EngineControlEventType {
  112. /*!
  113. * Null event type.
  114. */
  115. kEngineControlEventTypeNull = 0,
  116. /*!
  117. * Parameter event type.\n
  118. * \note Value uses a normalized range of 0.0f<->1.0f.
  119. */
  120. kEngineControlEventTypeParameter = 1,
  121. /*!
  122. * MIDI Bank event type.
  123. */
  124. kEngineControlEventTypeMidiBank = 2,
  125. /*!
  126. * MIDI Program change event type.
  127. */
  128. kEngineControlEventTypeMidiProgram = 3,
  129. /*!
  130. * All sound off event type.
  131. */
  132. kEngineControlEventTypeAllSoundOff = 4,
  133. /*!
  134. * All notes off event type.
  135. */
  136. kEngineControlEventTypeAllNotesOff = 5
  137. };
  138. // -----------------------------------------------------------------------
  139. /*!
  140. * Engine control event.
  141. */
  142. struct EngineControlEvent {
  143. EngineControlEventType type; //!< Control-Event type.
  144. uint16_t param; //!< Parameter Id, midi bank or midi program.
  145. float value; //!< Parameter value, normalized to 0.0f<->1.0f.
  146. /*!
  147. * Dump control event as MIDI data.
  148. */
  149. void dumpToMidiData(const uint8_t channel, uint8_t& size, uint8_t data[3]) const noexcept;
  150. };
  151. /*!
  152. * Engine MIDI event.
  153. */
  154. struct EngineMidiEvent {
  155. static const uint8_t kDataSize = 4; //!< Size of internal data
  156. uint8_t port; //!< Port offset (usually 0)
  157. uint8_t size; //!< Number of bytes used
  158. /*!
  159. * MIDI data, without channel bit.
  160. * If size > kDataSize, dataExt is used.
  161. */
  162. uint8_t data[kDataSize];
  163. const uint8_t* dataExt;
  164. };
  165. /*!
  166. * Engine event.
  167. */
  168. struct EngineEvent {
  169. EngineEventType type; //!< Event Type; either Control or MIDI
  170. uint32_t time; //!< Time offset in frames
  171. uint8_t channel; //!< Channel, used for MIDI-related events
  172. /*!
  173. * Event specific data.
  174. */
  175. union {
  176. EngineControlEvent ctrl;
  177. EngineMidiEvent midi;
  178. };
  179. /*!
  180. * Fill event from MIDI data.
  181. */
  182. void fillFromMidiData(const uint8_t size, const uint8_t* const data) noexcept;
  183. };
  184. // -----------------------------------------------------------------------
  185. /*!
  186. * Engine options.
  187. */
  188. struct EngineOptions {
  189. EngineProcessMode processMode;
  190. EngineTransportMode transportMode;
  191. bool forceStereo;
  192. bool preferPluginBridges;
  193. bool preferUiBridges;
  194. bool uisAlwaysOnTop;
  195. unsigned int maxParameters;
  196. unsigned int uiBridgesTimeout;
  197. unsigned int audioNumPeriods;
  198. unsigned int audioBufferSize;
  199. unsigned int audioSampleRate;
  200. const char* audioDevice;
  201. const char* binaryDir;
  202. const char* resourceDir;
  203. uintptr_t frontendWinId;
  204. #ifndef DOXYGEN
  205. EngineOptions() noexcept;
  206. ~EngineOptions();
  207. #endif
  208. };
  209. /*!
  210. * Engine BBT Time information.
  211. */
  212. struct EngineTimeInfoBBT {
  213. int32_t bar; //!< current bar
  214. int32_t beat; //!< current beat-within-bar
  215. int32_t tick; //!< current tick-within-beat
  216. double barStartTick;
  217. float beatsPerBar; //!< time signature "numerator"
  218. float beatType; //!< time signature "denominator"
  219. double ticksPerBeat;
  220. double beatsPerMinute;
  221. #ifndef DOXYGEN
  222. EngineTimeInfoBBT() noexcept;
  223. #endif
  224. };
  225. /*!
  226. * Engine Time information.
  227. */
  228. struct EngineTimeInfo {
  229. static const uint kValidBBT = 0x1;
  230. bool playing;
  231. uint64_t frame;
  232. uint64_t usecs;
  233. uint valid;
  234. EngineTimeInfoBBT bbt;
  235. /*!
  236. * Clear.
  237. */
  238. void clear() noexcept;
  239. #ifndef DOXYGEN
  240. EngineTimeInfo() noexcept;
  241. // quick operator, doesn't check all values
  242. bool operator==(const EngineTimeInfo& timeInfo) const noexcept;
  243. bool operator!=(const EngineTimeInfo& timeInfo) const noexcept;
  244. #endif
  245. };
  246. // -----------------------------------------------------------------------
  247. /*!
  248. * Carla Engine port (Abstract).\n
  249. * This is the base class for all Carla Engine ports.
  250. */
  251. class CarlaEnginePort
  252. {
  253. protected:
  254. /*!
  255. * The constructor.\n
  256. * Param \a isInputPort defines wherever this is an input port or not (output otherwise).\n
  257. * Input/output and process mode are constant for the lifetime of the port.
  258. */
  259. CarlaEnginePort(const CarlaEngine& engine, const bool isInputPort);
  260. public:
  261. /*!
  262. * The destructor.
  263. */
  264. virtual ~CarlaEnginePort();
  265. /*!
  266. * Get the type of the port, as provided by the respective subclasses.
  267. */
  268. virtual EnginePortType getType() const noexcept = 0;
  269. /*!
  270. * Initialize the port's internal buffer.
  271. */
  272. virtual void initBuffer() noexcept = 0;
  273. /*!
  274. * Check if this port is an input.
  275. */
  276. bool isInput() const noexcept
  277. {
  278. return fIsInput;
  279. }
  280. #ifndef DOXYGEN
  281. protected:
  282. const CarlaEngine& fEngine;
  283. const bool fIsInput;
  284. CARLA_DECLARE_NON_COPY_CLASS(CarlaEnginePort)
  285. #endif
  286. };
  287. /*!
  288. * Carla Engine Audio port.
  289. */
  290. class CarlaEngineAudioPort : public CarlaEnginePort
  291. {
  292. public:
  293. /*!
  294. * The constructor.\n
  295. * All constructor parameters are constant and will never change in the lifetime of the port.
  296. */
  297. CarlaEngineAudioPort(const CarlaEngine& engine, const bool isInputPort);
  298. /*!
  299. * The destructor.
  300. */
  301. virtual ~CarlaEngineAudioPort() override;
  302. /*!
  303. * Get the type of the port, in this case kEnginePortTypeAudio.
  304. */
  305. EnginePortType getType() const noexcept override
  306. {
  307. return kEnginePortTypeAudio;
  308. }
  309. /*!
  310. * Initialize the port's internal buffer.
  311. */
  312. virtual void initBuffer() noexcept override;
  313. /*!
  314. * Direct access to the port's audio buffer.
  315. */
  316. float* getBuffer() const noexcept
  317. {
  318. return fBuffer;
  319. }
  320. #ifndef DOXYGEN
  321. protected:
  322. float* fBuffer;
  323. CARLA_DECLARE_NON_COPY_CLASS(CarlaEngineAudioPort)
  324. #endif
  325. };
  326. /*!
  327. * Carla Engine CV port.
  328. */
  329. class CarlaEngineCVPort : public CarlaEnginePort
  330. {
  331. public:
  332. /*!
  333. * The constructor.\n
  334. * All constructor parameters are constant and will never change in the lifetime of the port.
  335. */
  336. CarlaEngineCVPort(const CarlaEngine& engine, const bool isInputPort);
  337. /*!
  338. * The destructor.
  339. */
  340. virtual ~CarlaEngineCVPort() override;
  341. /*!
  342. * Get the type of the port, in this case kEnginePortTypeCV.
  343. */
  344. EnginePortType getType() const noexcept override
  345. {
  346. return kEnginePortTypeCV;
  347. }
  348. /*!
  349. * Initialize the port's internal buffer for \a engine.
  350. */
  351. virtual void initBuffer() noexcept override;
  352. /*!
  353. * Set a new buffer size.
  354. */
  355. void setBufferSize(const uint32_t bufferSize);
  356. #if 0
  357. // TESTING: I should remove this
  358. /*!
  359. * Write buffer back into the engine.
  360. */
  361. virtual void writeBuffer(const uint32_t frames, const uint32_t timeOffset);
  362. #endif
  363. /*!
  364. * Direct access to the port's buffer.
  365. */
  366. float* getBuffer() const noexcept
  367. {
  368. return fBuffer;
  369. }
  370. #ifndef DOXYGEN
  371. protected:
  372. float* fBuffer;
  373. const EngineProcessMode fProcessMode;
  374. CARLA_DECLARE_NON_COPY_CLASS(CarlaEngineCVPort)
  375. #endif
  376. };
  377. /*!
  378. * Carla Engine Event port.
  379. */
  380. class CarlaEngineEventPort : public CarlaEnginePort
  381. {
  382. public:
  383. /*!
  384. * The constructor.\n
  385. * All constructor parameters are constant and will never change in the lifetime of the port.
  386. */
  387. CarlaEngineEventPort(const CarlaEngine& engine, const bool isInputPort);
  388. /*!
  389. * The destructor.
  390. */
  391. virtual ~CarlaEngineEventPort() override;
  392. /*!
  393. * Get the type of the port, in this case kEnginePortTypeEvent.
  394. */
  395. EnginePortType getType() const noexcept override
  396. {
  397. return kEnginePortTypeEvent;
  398. }
  399. /*!
  400. * Initialize the port's internal buffer for \a engine.
  401. */
  402. virtual void initBuffer() noexcept override;
  403. /*!
  404. * Get the number of events present in the buffer.
  405. * \note You must only call this for input ports.
  406. */
  407. virtual uint32_t getEventCount() const noexcept;
  408. /*!
  409. * Get the event at \a index.
  410. * \note You must only call this for input ports.
  411. */
  412. virtual const EngineEvent& getEvent(const uint32_t index) const noexcept;
  413. /*!
  414. * Get the event at \a index, faster unchecked version.
  415. */
  416. virtual const EngineEvent& getEventUnchecked(const uint32_t index) const noexcept;
  417. /*!
  418. * Write a control event into the buffer.\n
  419. * Arguments are the same as in the EngineControlEvent struct.
  420. * \note You must only call this for output ports.
  421. */
  422. virtual bool writeControlEvent(const uint32_t time, const uint8_t channel, const EngineControlEventType type, const uint16_t param, const float value = 0.0f) noexcept;
  423. /*!
  424. * Write a control event into the buffer, overloaded call.
  425. */
  426. bool writeControlEvent(const uint32_t time, const uint8_t channel, const EngineControlEvent& ctrl) noexcept;
  427. /*!
  428. * Write a MIDI event into the buffer.\n
  429. * Arguments are the same as in the EngineMidiEvent struct.
  430. * \note You must only call this for output ports.
  431. */
  432. virtual bool writeMidiEvent(const uint32_t time, const uint8_t channel, const uint8_t port, const uint8_t size, const uint8_t* const data) noexcept;
  433. /*!
  434. * Write a MIDI event into the buffer, overloaded call.
  435. */
  436. bool writeMidiEvent(const uint32_t time, const uint8_t size, const uint8_t* const data) noexcept;
  437. /*!
  438. * Write a MIDI event into the buffer, overloaded call.
  439. */
  440. bool writeMidiEvent(const uint32_t time, const uint8_t channel, const EngineMidiEvent& midi) noexcept;
  441. #ifndef DOXYGEN
  442. protected:
  443. EngineEvent* fBuffer;
  444. const EngineProcessMode fProcessMode;
  445. CARLA_DECLARE_NON_COPY_CLASS(CarlaEngineEventPort)
  446. #endif
  447. };
  448. // -----------------------------------------------------------------------
  449. /*!
  450. * Carla Engine client.\n
  451. * Each plugin requires one client from the engine (created via CarlaEngine::addClient()).\n
  452. * \note This is a virtual class, some engine types provide custom funtionality.
  453. */
  454. class CarlaEngineClient
  455. {
  456. public:
  457. /*!
  458. * The constructor, protected.\n
  459. * All constructor parameters are constant and will never change in the lifetime of the client.\n
  460. * Client starts in deactivated state.
  461. */
  462. CarlaEngineClient(const CarlaEngine& engine);
  463. /*!
  464. * The destructor.
  465. */
  466. virtual ~CarlaEngineClient();
  467. /*!
  468. * Activate this client.\n
  469. * Client must be deactivated before calling this function.
  470. */
  471. virtual void activate() noexcept;
  472. /*!
  473. * Deactivate this client.\n
  474. * Client must be activated before calling this function.
  475. */
  476. virtual void deactivate() noexcept;
  477. /*!
  478. * Check if the client is activated.
  479. */
  480. virtual bool isActive() const noexcept;
  481. /*!
  482. * Check if the client is ok.\n
  483. * Plugins will refuse to instantiate if this returns false.
  484. * \note This is always true in rack and patchbay processing modes.
  485. */
  486. virtual bool isOk() const noexcept;
  487. /*!
  488. * Get the current latency, in samples.
  489. */
  490. virtual uint32_t getLatency() const noexcept;
  491. /*!
  492. * Change the client's latency.
  493. */
  494. virtual void setLatency(const uint32_t samples) noexcept;
  495. /*!
  496. * Add a new port of type \a portType.
  497. * \note This function does nothing in rack processing mode since ports are static there (2 audio + 1 event for both input and output).
  498. */
  499. virtual CarlaEnginePort* addPort(const EnginePortType portType, const char* const name, const bool isInput);
  500. #ifndef DOXYGEN
  501. protected:
  502. const CarlaEngine& fEngine;
  503. bool fActive;
  504. uint32_t fLatency;
  505. CARLA_DECLARE_NON_COPY_CLASS(CarlaEngineClient)
  506. #endif
  507. };
  508. // -----------------------------------------------------------------------
  509. /*!
  510. * Protected data used in CarlaEngine and subclasses.\n
  511. * Non-engine code MUST NEVER have direct access to this.
  512. */
  513. struct CarlaEngineProtectedData;
  514. /*!
  515. * Carla Engine.
  516. * \note This is a virtual class for all available engine types available in Carla.
  517. */
  518. class CarlaEngine
  519. {
  520. protected:
  521. /*!
  522. * The constructor, protected.\n
  523. * \note This only initializes engine data, it doesn't start the engine (audio).
  524. */
  525. CarlaEngine();
  526. public:
  527. /*!
  528. * The decontructor.
  529. * The engine must have been closed before this happens.
  530. */
  531. virtual ~CarlaEngine();
  532. // -------------------------------------------------------------------
  533. // Static calls
  534. /*!
  535. * Get the number of available engine drivers.
  536. */
  537. static unsigned int getDriverCount();
  538. /*!
  539. * Get the name of the engine driver at \a index.
  540. */
  541. static const char* getDriverName(const unsigned int index);
  542. /*!
  543. * Get the device names of driver at \a index.
  544. */
  545. static const char* const* getDriverDeviceNames(const unsigned int index);
  546. /*!
  547. * Get the device names of driver at \a index.
  548. */
  549. static const EngineDriverDeviceInfo* getDriverDeviceInfo(const unsigned int index, const char* const driverName);
  550. /*!
  551. * Create a new engine, using driver \a driverName. \n
  552. * Returned variable must be deleted when no longer needed.
  553. * \note This only initializes engine data, it doesn't initialize the engine itself.
  554. */
  555. static CarlaEngine* newDriverByName(const char* const driverName);
  556. // -------------------------------------------------------------------
  557. // Constant values
  558. /*!
  559. * Maximum client name size.
  560. */
  561. virtual unsigned int getMaxClientNameSize() const noexcept;
  562. /*!
  563. * Maximum port name size.
  564. */
  565. virtual unsigned int getMaxPortNameSize() const noexcept;
  566. /*!
  567. * Current number of plugins loaded.
  568. */
  569. unsigned int getCurrentPluginCount() const noexcept;
  570. /*!
  571. * Maximum number of loadable plugins allowed.
  572. * \note This function returns 0 if engine is not started.
  573. */
  574. unsigned int getMaxPluginNumber() const noexcept;
  575. // -------------------------------------------------------------------
  576. // Virtual, per-engine type calls
  577. /*!
  578. * Initialize engine, using \a clientName.
  579. */
  580. virtual bool init(const char* const clientName);
  581. /*!
  582. * Close engine.
  583. */
  584. virtual bool close();
  585. /*!
  586. * Idle engine.
  587. */
  588. virtual void idle();
  589. /*!
  590. * Check if engine is running.
  591. */
  592. virtual bool isRunning() const noexcept = 0;
  593. /*!
  594. * Check if engine is running offline (aka freewheel mode).
  595. */
  596. virtual bool isOffline() const noexcept = 0;
  597. /*!
  598. * Get engine type.
  599. */
  600. virtual EngineType getType() const noexcept = 0;
  601. /*!
  602. * Get the currently used driver name.
  603. */
  604. virtual const char* getCurrentDriverName() const noexcept = 0;
  605. /*!
  606. * Add new engine client.
  607. * \note This function must only be called within a plugin class.
  608. */
  609. virtual CarlaEngineClient* addClient(CarlaPlugin* const plugin);
  610. // -------------------------------------------------------------------
  611. // Plugin management
  612. /*!
  613. * Add new plugin.
  614. */
  615. bool addPlugin(const BinaryType btype, const PluginType ptype, const char* const filename, const char* const name, const char* const label, const void* const extra = nullptr);
  616. /*!
  617. * Add new plugin, using native binary type.
  618. */
  619. bool addPlugin(const PluginType ptype, const char* const filename, const char* const name, const char* const label, const void* const extra = nullptr)
  620. {
  621. return addPlugin(BINARY_NATIVE, ptype, filename, name, label, extra);
  622. }
  623. /*!
  624. * Remove plugin with id \a id.
  625. */
  626. bool removePlugin(const unsigned int id);
  627. /*!
  628. * Remove all plugins.
  629. */
  630. bool removeAllPlugins();
  631. /*!
  632. * Rename plugin with id \a id to \a newName.\n
  633. * Returns the new name, or nullptr if the operation failed.
  634. */
  635. virtual const char* renamePlugin(const unsigned int id, const char* const newName);
  636. /*!
  637. * Clone plugin with id \a id.
  638. */
  639. bool clonePlugin(const unsigned int id);
  640. /*!
  641. * Prepare replace of plugin with id \a id.\n
  642. * The next call to addPlugin() will use this id, replacing the selected plugin.
  643. * \note This function requires addPlugin() to be called afterwards, as soon as possible.
  644. */
  645. bool replacePlugin(const unsigned int id);
  646. /*!
  647. * Switch plugins with id \a idA and \a idB.
  648. */
  649. bool switchPlugins(const unsigned int idA, const unsigned int idB);
  650. /*!
  651. * Get plugin with id \a id.
  652. */
  653. CarlaPlugin* getPlugin(const unsigned int id) const;
  654. /*!
  655. * Get plugin with id \a id, faster unchecked version.
  656. */
  657. CarlaPlugin* getPluginUnchecked(const unsigned int id) const noexcept;
  658. /*!
  659. * Get a unique plugin name within the engine.\n
  660. * Returned variable must be deleted if non-NULL.
  661. */
  662. const char* getUniquePluginName(const char* const name) const;
  663. // -------------------------------------------------------------------
  664. // Project management
  665. /*!
  666. * Load a file of any type.\n
  667. * This will try to load a generic file as a plugin,
  668. * either by direct handling (GIG, SF2 and SFZ) or by using an internal plugin (like Audio and MIDI).
  669. */
  670. bool loadFile(const char* const filename);
  671. /*!
  672. * Load a project file.
  673. * @note Already loaded plugins are not removed; call removeAllPlugins() first if needed.
  674. */
  675. bool loadProject(const char* const filename);
  676. /*!
  677. * Save current project to a file.
  678. */
  679. bool saveProject(const char* const filename);
  680. // -------------------------------------------------------------------
  681. // Information (base)
  682. /*!
  683. * Get the current engine driver hints.
  684. */
  685. unsigned int getHints() const noexcept;
  686. /*!
  687. * Get the current buffer size.
  688. */
  689. uint32_t getBufferSize() const noexcept;
  690. /*!
  691. * Get the current sample rate.
  692. */
  693. double getSampleRate() const noexcept;
  694. /*!
  695. * Get the current engine name.
  696. */
  697. const char* getName() const noexcept;
  698. /*!
  699. * Get the current engine proccess mode.
  700. */
  701. EngineProcessMode getProccessMode() const noexcept;
  702. /*!
  703. * Get the current engine options (read-only).
  704. */
  705. const EngineOptions& getOptions() const noexcept;
  706. /*!
  707. * Get the current Time information (read-only).
  708. */
  709. const EngineTimeInfo& getTimeInfo() const noexcept;
  710. // -------------------------------------------------------------------
  711. // Information (peaks)
  712. /*!
  713. * TODO.
  714. */
  715. float getInputPeak(const unsigned int pluginId, const bool isLeft) const noexcept;
  716. /*!
  717. * TODO.
  718. */
  719. float getOutputPeak(const unsigned int pluginId, const bool isLeft) const noexcept;
  720. // -------------------------------------------------------------------
  721. // Callback
  722. /*!
  723. * Run the main engine callback, if set.
  724. * May be called by plugins.
  725. */
  726. void callback(const EngineCallbackOpcode action, const unsigned int pluginId, const int value1, const int value2, const float value3, const char* const valueStr) noexcept;
  727. /*!
  728. * Set the main engine callback.
  729. */
  730. void setCallback(const EngineCallbackFunc func, void* const ptr) noexcept;
  731. // -------------------------------------------------------------------
  732. // Callback
  733. /*!
  734. * Run the file callback, if set.
  735. * May be called by plugins.
  736. */
  737. const char* runFileCallback(const FileCallbackOpcode action, const bool isDir, const char* const title, const char* const filter) noexcept;
  738. /*!
  739. * Set the file callback.
  740. */
  741. void setFileCallback(const FileCallbackFunc func, void* const ptr) noexcept;
  742. #ifndef BUILD_BRIDGE
  743. // -------------------------------------------------------------------
  744. // Patchbay
  745. /*!
  746. * Connect patchbay ports \a portA and \a portB.
  747. */
  748. virtual bool patchbayConnect(const int portA, const int portB);
  749. /*!
  750. * Disconnect patchbay connection \a connectionId.
  751. */
  752. virtual bool patchbayDisconnect(const uint connectionId);
  753. /*!
  754. * Force the engine to resend all patchbay clients, ports and connections again.
  755. */
  756. virtual bool patchbayRefresh();
  757. #endif
  758. // -------------------------------------------------------------------
  759. // Transport
  760. /*!
  761. * Start playback of the engine transport.
  762. */
  763. virtual void transportPlay() noexcept;
  764. /*!
  765. * Pause the engine transport.
  766. */
  767. virtual void transportPause() noexcept;
  768. /*!
  769. * Relocate the engine transport to \a frames.
  770. */
  771. virtual void transportRelocate(const uint64_t frame) noexcept;
  772. // -------------------------------------------------------------------
  773. // Error handling
  774. /*!
  775. * Get last error.
  776. */
  777. const char* getLastError() const noexcept;
  778. /*!
  779. * Set last error.
  780. */
  781. void setLastError(const char* const error) const;
  782. // -------------------------------------------------------------------
  783. // Misc
  784. /*!
  785. * Tell the engine it's about to close.\n
  786. * This is used to prevent the engine thread(s) from reactivating.
  787. */
  788. void setAboutToClose() noexcept;
  789. // -------------------------------------------------------------------
  790. // Options
  791. /*!
  792. * Set the engine option \a option.
  793. */
  794. void setOption(const EngineOption option, const int value, const char* const valueStr);
  795. // -------------------------------------------------------------------
  796. // OSC Stuff
  797. #ifdef BUILD_BRIDGE
  798. /*!
  799. * Check if OSC bridge is registered.
  800. */
  801. bool isOscBridgeRegistered() const noexcept;
  802. #else
  803. /*!
  804. * Check if OSC controller is registered.
  805. */
  806. bool isOscControlRegistered() const noexcept;
  807. #endif
  808. /*!
  809. * Get OSC TCP server path.
  810. */
  811. const char* getOscServerPathTCP() const noexcept;
  812. /*!
  813. * Get OSC UDP server path.
  814. */
  815. const char* getOscServerPathUDP() const noexcept;
  816. #ifdef BUILD_BRIDGE
  817. /*!
  818. * Set OSC bridge data.
  819. */
  820. void setOscBridgeData(const CarlaOscData* const oscData) const noexcept;
  821. #endif
  822. // -------------------------------------------------------------------
  823. // Helper functions
  824. /*!
  825. * Return internal data, needed for EventPorts when used in Rack and Bridge modes.
  826. * \note RT call
  827. */
  828. EngineEvent* getInternalEventBuffer(const bool isInput) const noexcept;
  829. /*!
  830. * Force register a plugin into slot \a id. \n
  831. * This is needed so we can receive OSC events for a plugin while it initializes.
  832. */
  833. void registerEnginePlugin(const unsigned int id, CarlaPlugin* const plugin) noexcept;
  834. // -------------------------------------------------------------------
  835. protected:
  836. /*!
  837. * Internal data, for CarlaEngine subclasses only.
  838. */
  839. CarlaEngineProtectedData* const pData;
  840. friend struct CarlaEngineProtectedData;
  841. // -------------------------------------------------------------------
  842. // Internal stuff
  843. /*!
  844. * Report to all plugins about buffer size change.
  845. */
  846. void bufferSizeChanged(const uint32_t newBufferSize);
  847. /*!
  848. * Report to all plugins about sample rate change.\n
  849. * This is not supported on all plugin types, in which case they will have to be re-initiated.
  850. */
  851. void sampleRateChanged(const double newSampleRate);
  852. /*!
  853. * Report to all plugins about offline mode change.
  854. */
  855. void offlineModeChanged(const bool isOffline);
  856. /*!
  857. * Run any pending RT events.\n
  858. * Must always be called at the end of audio processing.
  859. * \note RT call
  860. */
  861. void runPendingRtEvents() noexcept;
  862. /*!
  863. * Set a plugin (stereo) peak values.
  864. * \note RT call
  865. */
  866. void setPluginPeaks(const unsigned int pluginId, float const inPeaks[2], float const outPeaks[2]) noexcept;
  867. #ifndef BUILD_BRIDGE
  868. // -------------------------------------------------------------------
  869. // Patchbay stuff
  870. /*!
  871. * Virtual functions for handling MIDI ports in the rack patchbay.
  872. */
  873. virtual bool connectRackMidiInPort(const int) { return false; }
  874. virtual bool connectRackMidiOutPort(const int) { return false; }
  875. virtual bool disconnectRackMidiInPort(const int) { return false; }
  876. virtual bool disconnectRackMidiOutPort(const int) { return false; }
  877. /*!
  878. * Virtual functions for handling patchbay state.
  879. */
  880. virtual const char* const* getPatchbayConnections() const;
  881. virtual void restorePatchbayConnection(const char* const sourcePort, const char* const targetPort);
  882. #endif
  883. // -------------------------------------------------------------------
  884. private:
  885. /*!
  886. * Native audio APIs.
  887. */
  888. enum AudioApi {
  889. AUDIO_API_NULL = 0,
  890. // common
  891. AUDIO_API_JACK = 1,
  892. // linux
  893. AUDIO_API_ALSA = 2,
  894. AUDIO_API_OSS = 3,
  895. AUDIO_API_PULSE = 4,
  896. // macos
  897. AUDIO_API_CORE = 5,
  898. // windows
  899. AUDIO_API_ASIO = 6,
  900. AUDIO_API_DS = 7
  901. };
  902. // -------------------------------------------------------------------
  903. // Engine initializers
  904. // JACK
  905. static CarlaEngine* newJack();
  906. // RtAudio
  907. static CarlaEngine* newRtAudio(const AudioApi api);
  908. static unsigned int getRtAudioApiCount();
  909. static const char* getRtAudioApiName(const unsigned int index);
  910. static const char* const* getRtAudioApiDeviceNames(const unsigned int index);
  911. static const EngineDriverDeviceInfo* getRtAudioDeviceInfo(const unsigned int index, const char* const deviceName);
  912. // Juce
  913. static CarlaEngine* newJuce(const AudioApi api);
  914. static unsigned int getJuceApiCount();
  915. static const char* getJuceApiName(const unsigned int index);
  916. static const char* const* getJuceApiDeviceNames(const unsigned int index);
  917. static const EngineDriverDeviceInfo* getJuceDeviceInfo(const unsigned int index, const char* const deviceName);
  918. #ifdef BUILD_BRIDGE
  919. public:
  920. // Bridge
  921. static CarlaEngine* newBridge(const char* const audioBaseName, const char* const controlBaseName);
  922. // -------------------------------------------------------------------
  923. // Bridge/Controller OSC stuff
  924. void oscSend_bridge_plugin_info1(const PluginCategory category, const uint hints, const long uniqueId) const noexcept;
  925. void oscSend_bridge_plugin_info2(const char* const realName, const char* const label, const char* const maker, const char* const copyright) const noexcept;
  926. void oscSend_bridge_audio_count(const uint32_t ins, const uint32_t outs) const noexcept;
  927. void oscSend_bridge_midi_count(const uint32_t ins, const uint32_t outs) const noexcept;
  928. void oscSend_bridge_parameter_count(const uint32_t ins, const uint32_t outs) const noexcept;
  929. void oscSend_bridge_program_count(const uint32_t count) const noexcept;
  930. void oscSend_bridge_midi_program_count(const uint32_t count) const noexcept;
  931. void oscSend_bridge_parameter_data(const uint32_t index, const int32_t rindex, const ParameterType type, const uint hints, const char* const name, const char* const unit) const noexcept;
  932. void oscSend_bridge_parameter_ranges1(const uint32_t index, const float def, const float min, const float max) const noexcept;
  933. void oscSend_bridge_parameter_ranges2(const uint32_t index, const float step, const float stepSmall, const float stepLarge) const noexcept;
  934. void oscSend_bridge_parameter_midi_cc(const uint32_t index, const int16_t cc) const noexcept;
  935. void oscSend_bridge_parameter_midi_channel(const uint32_t index, const uint8_t channel) const noexcept;
  936. void oscSend_bridge_parameter_value(const uint32_t index, const float value) const noexcept;
  937. void oscSend_bridge_default_value(const uint32_t index, const float value) const noexcept;
  938. void oscSend_bridge_current_program(const int32_t index) const noexcept;
  939. void oscSend_bridge_current_midi_program(const int32_t index) const noexcept;
  940. void oscSend_bridge_program_name(const uint32_t index, const char* const name) const noexcept;
  941. void oscSend_bridge_midi_program_data(const uint32_t index, const uint32_t bank, const uint32_t program, const char* const name) const noexcept;
  942. void oscSend_bridge_configure(const char* const key, const char* const value) const noexcept;
  943. void oscSend_bridge_set_custom_data(const char* const type, const char* const key, const char* const value) const noexcept;
  944. void oscSend_bridge_set_chunk_data(const char* const chunkFile) const noexcept;
  945. void oscSend_bridge_set_peaks() const noexcept;
  946. #else
  947. public:
  948. void oscSend_control_add_plugin_start(const uint pluginId, const char* const pluginName) const noexcept;
  949. void oscSend_control_add_plugin_end(const uint pluginId) const noexcept;
  950. void oscSend_control_remove_plugin(const uint pluginId) const noexcept;
  951. void oscSend_control_set_plugin_info1(const uint pluginId, const PluginType type, const PluginCategory category, const uint hints, const long uniqueId) const noexcept;
  952. void oscSend_control_set_plugin_info2(const uint pluginId, const char* const realName, const char* const label, const char* const maker, const char* const copyright) const noexcept;
  953. void oscSend_control_set_audio_count(const uint pluginId, const uint32_t ins, const uint32_t outs) const noexcept;
  954. void oscSend_control_set_midi_count(const uint pluginId, const uint32_t ins, const uint32_t outs) const noexcept;
  955. void oscSend_control_set_parameter_count(const uint pluginId, const uint32_t ins, const uint32_t outs) const noexcept;
  956. void oscSend_control_set_program_count(const uint pluginId, const uint32_t count) const noexcept;
  957. void oscSend_control_set_midi_program_count(const uint pluginId, const uint32_t count) const noexcept;
  958. void oscSend_control_set_parameter_data(const uint pluginId, const uint32_t index, const ParameterType type, const uint hints, const char* const name, const char* const unit) const noexcept;
  959. void oscSend_control_set_parameter_ranges1(const uint pluginId, const uint32_t index, const float def, const float min, const float max) const noexcept;
  960. void oscSend_control_set_parameter_ranges2(const uint pluginId, const uint32_t index, const float step, const float stepSmall, const float stepLarge) const noexcept;
  961. void oscSend_control_set_parameter_midi_cc(const uint pluginId, const uint32_t index, const int16_t cc) const noexcept;
  962. void oscSend_control_set_parameter_midi_channel(const uint pluginId, const uint32_t index, const uint8_t channel) const noexcept;
  963. void oscSend_control_set_parameter_value(const uint pluginId, const int32_t index, const float value) const noexcept; // may be used for internal params (< 0)
  964. void oscSend_control_set_default_value(const uint pluginId, const uint32_t index, const float value) const noexcept;
  965. void oscSend_control_set_current_program(const uint pluginId, const int32_t index) const noexcept;
  966. void oscSend_control_set_current_midi_program(const uint pluginId, const int32_t index) const noexcept;
  967. void oscSend_control_set_program_name(const uint pluginId, const uint32_t index, const char* const name) const noexcept;
  968. void oscSend_control_set_midi_program_data(const uint pluginId, const uint32_t index, const uint32_t bank, const uint32_t program, const char* const name) const noexcept;
  969. void oscSend_control_note_on(const uint pluginId, const uint8_t channel, const uint8_t note, const uint8_t velo) const noexcept;
  970. void oscSend_control_note_off(const uint pluginId, const uint8_t channel, const uint8_t note) const noexcept;
  971. void oscSend_control_set_peaks(const uint pluginId) const noexcept;
  972. void oscSend_control_exit() const noexcept;
  973. #endif
  974. CARLA_DECLARE_NON_COPY_CLASS(CarlaEngine)
  975. };
  976. /**@}*/
  977. // -----------------------------------------------------------------------
  978. CARLA_BACKEND_END_NAMESPACE
  979. #endif // CARLA_ENGINE_HPP_INCLUDED