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.

1203 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.
  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.
  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. * Convert this control event into MIDI data.
  148. */
  149. void convertToMidiData(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 (otherwise NULL).
  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 this 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. uint maxParameters;
  196. uint uiBridgesTimeout;
  197. uint audioNumPeriods;
  198. uint audioBufferSize;
  199. uint 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() noexcept;
  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).
  249. * This is the base class for all Carla Engine ports.
  250. */
  251. class CarlaEnginePort
  252. {
  253. protected:
  254. /*!
  255. * The constructor.
  256. * All constructor parameters are constant and will never change in the lifetime of the port.
  257. */
  258. CarlaEnginePort(const CarlaEngineClient& client, const bool isInputPort) noexcept;
  259. public:
  260. /*!
  261. * The destructor.
  262. */
  263. virtual ~CarlaEnginePort() noexcept;
  264. /*!
  265. * Get the type of the port, as provided by the respective subclasses.
  266. */
  267. virtual EnginePortType getType() const noexcept = 0;
  268. /*!
  269. * Initialize the port's internal buffer.
  270. */
  271. virtual void initBuffer() noexcept = 0;
  272. /*!
  273. * Check if this port is an input.
  274. */
  275. bool isInput() const noexcept
  276. {
  277. return fIsInput;
  278. }
  279. /*!
  280. * Get this ports' engine client.
  281. */
  282. const CarlaEngineClient& getEngineClient() const noexcept
  283. {
  284. return fClient;
  285. }
  286. #ifndef DOXYGEN
  287. protected:
  288. const CarlaEngineClient& fClient;
  289. const bool fIsInput;
  290. CARLA_DECLARE_NON_COPY_CLASS(CarlaEnginePort)
  291. #endif
  292. };
  293. /*!
  294. * Carla Engine Audio port.
  295. */
  296. class CarlaEngineAudioPort : public CarlaEnginePort
  297. {
  298. public:
  299. /*!
  300. * The constructor.
  301. * All constructor parameters are constant and will never change in the lifetime of the port.
  302. */
  303. CarlaEngineAudioPort(const CarlaEngineClient& client, const bool isInputPort) noexcept;
  304. /*!
  305. * The destructor.
  306. */
  307. ~CarlaEngineAudioPort() noexcept override;
  308. /*!
  309. * Get the type of the port, in this case kEnginePortTypeAudio.
  310. */
  311. EnginePortType getType() const noexcept final
  312. {
  313. return kEnginePortTypeAudio;
  314. }
  315. /*!
  316. * Initialize the port's internal buffer.
  317. */
  318. void initBuffer() noexcept override;
  319. /*!
  320. * Direct access to the port's audio buffer.
  321. * May be null.
  322. */
  323. float* getBuffer() const noexcept
  324. {
  325. return fBuffer;
  326. }
  327. #ifndef DOXYGEN
  328. protected:
  329. float* fBuffer;
  330. CARLA_DECLARE_NON_COPY_CLASS(CarlaEngineAudioPort)
  331. #endif
  332. };
  333. /*!
  334. * Carla Engine CV port.
  335. */
  336. class CarlaEngineCVPort : public CarlaEnginePort
  337. {
  338. public:
  339. /*!
  340. * The constructor.
  341. * All constructor parameters are constant and will never change in the lifetime of the port.
  342. */
  343. CarlaEngineCVPort(const CarlaEngineClient& client, const bool isInputPort) noexcept;
  344. /*!
  345. * The destructor.
  346. */
  347. ~CarlaEngineCVPort() noexcept override;
  348. /*!
  349. * Get the type of the port, in this case kEnginePortTypeCV.
  350. */
  351. EnginePortType getType() const noexcept final
  352. {
  353. return kEnginePortTypeCV;
  354. }
  355. /*!
  356. * Initialize the port's internal buffer.
  357. */
  358. void initBuffer() noexcept override;
  359. /*!
  360. * Direct access to the port's CV buffer.
  361. * May be null.
  362. */
  363. float* getBuffer() const noexcept
  364. {
  365. return fBuffer;
  366. }
  367. #ifndef DOXYGEN
  368. protected:
  369. float* fBuffer;
  370. CARLA_DECLARE_NON_COPY_CLASS(CarlaEngineCVPort)
  371. #endif
  372. };
  373. /*!
  374. * Carla Engine Event port.
  375. */
  376. class CarlaEngineEventPort : public CarlaEnginePort
  377. {
  378. public:
  379. /*!
  380. * The constructor.
  381. * All constructor parameters are constant and will never change in the lifetime of the port.
  382. */
  383. CarlaEngineEventPort(const CarlaEngineClient& client, const bool isInputPort) noexcept;
  384. /*!
  385. * The destructor.
  386. */
  387. ~CarlaEngineEventPort() noexcept override;
  388. /*!
  389. * Get the type of the port, in this case kEnginePortTypeEvent.
  390. */
  391. EnginePortType getType() const noexcept final
  392. {
  393. return kEnginePortTypeEvent;
  394. }
  395. /*!
  396. * Initialize the port's internal buffer for @a engine.
  397. */
  398. void initBuffer() noexcept override;
  399. /*!
  400. * Get the number of events present in the buffer.
  401. * @note You must only call this for input ports.
  402. */
  403. virtual uint32_t getEventCount() const noexcept;
  404. /*!
  405. * Get the event at @a index.
  406. * @note You must only call this for input ports.
  407. */
  408. virtual const EngineEvent& getEvent(const uint32_t index) const noexcept;
  409. /*!
  410. * Get the event at @a index, faster unchecked version.
  411. */
  412. virtual const EngineEvent& getEventUnchecked(const uint32_t index) const noexcept;
  413. /*!
  414. * Write a control event into the buffer.
  415. * @note You must only call this for output ports.
  416. */
  417. bool writeControlEvent(const uint32_t time, const uint8_t channel, const EngineControlEvent& ctrl) noexcept;
  418. /*!
  419. * Write a control event into the buffer.
  420. * Arguments are the same as in the EngineControlEvent struct.
  421. * @note You must only call this for output ports.
  422. */
  423. virtual bool writeControlEvent(const uint32_t time, const uint8_t channel, const EngineControlEventType type, const uint16_t param, const float value = 0.0f) noexcept;
  424. /*!
  425. * Write a MIDI event into the buffer.
  426. * @note You must only call this for output ports.
  427. */
  428. bool writeMidiEvent(const uint32_t time, const uint8_t size, const uint8_t* const data) noexcept;
  429. /*!
  430. * Write a MIDI event into the buffer.
  431. * @note You must only call this for output ports.
  432. */
  433. bool writeMidiEvent(const uint32_t time, const uint8_t channel, const EngineMidiEvent& midi) noexcept;
  434. /*!
  435. * Write a MIDI event into the buffer.
  436. * Arguments are the same as in the EngineMidiEvent struct.
  437. * @note You must only call this for output ports.
  438. */
  439. 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;
  440. #ifndef DOXYGEN
  441. protected:
  442. EngineEvent* fBuffer;
  443. const EngineProcessMode fProcessMode;
  444. CARLA_DECLARE_NON_COPY_CLASS(CarlaEngineEventPort)
  445. #endif
  446. };
  447. // -----------------------------------------------------------------------
  448. /*!
  449. * Carla Engine client.
  450. * Each plugin requires one client from the engine (created via CarlaEngine::addClient()).
  451. * @note This is a virtual class, some engine types provide custom funtionality.
  452. */
  453. class CarlaEngineClient
  454. {
  455. public:
  456. /*!
  457. * The constructor, protected.
  458. * All constructor parameters are constant and will never change in the lifetime of the client.
  459. * Client starts in deactivated state.
  460. */
  461. CarlaEngineClient(const CarlaEngine& engine) noexcept;
  462. /*!
  463. * The destructor.
  464. */
  465. virtual ~CarlaEngineClient() noexcept;
  466. /*!
  467. * Activate this client.
  468. * Client must be deactivated before calling this function.
  469. */
  470. virtual void activate() noexcept;
  471. /*!
  472. * Deactivate this client.
  473. * Client must be activated before calling this function.
  474. */
  475. virtual void deactivate() noexcept;
  476. /*!
  477. * Check if the client is activated.
  478. */
  479. virtual bool isActive() const noexcept;
  480. /*!
  481. * Check if the client is ok.
  482. * Plugins will refuse to instantiate if this returns false.
  483. * @note This is always true in rack and patchbay processing modes.
  484. */
  485. virtual bool isOk() const noexcept;
  486. /*!
  487. * Get the current latency, in samples.
  488. */
  489. virtual uint32_t getLatency() const noexcept;
  490. /*!
  491. * Change the client's latency.
  492. */
  493. virtual void setLatency(const uint32_t samples) noexcept;
  494. /*!
  495. * Add a new port of type @a portType.
  496. * @note This function does nothing in rack processing mode since ports are static there.
  497. */
  498. virtual CarlaEnginePort* addPort(const EnginePortType portType, const char* const name, const bool isInput);
  499. /*!
  500. * Get this client's engine.
  501. */
  502. const CarlaEngine& getEngine() const noexcept
  503. {
  504. return fEngine;
  505. }
  506. #ifndef DOXYGEN
  507. protected:
  508. const CarlaEngine& fEngine;
  509. bool fActive;
  510. uint32_t fLatency;
  511. CARLA_DECLARE_NON_COPY_CLASS(CarlaEngineClient)
  512. #endif
  513. };
  514. // -----------------------------------------------------------------------
  515. /*!
  516. * Carla Engine.
  517. * @note This is a virtual class for all available engine types available in Carla.
  518. */
  519. class CarlaEngine
  520. {
  521. protected:
  522. /*!
  523. * The constructor, protected.
  524. * @note This only initializes engine data, it doesn't actually start the engine.
  525. */
  526. CarlaEngine();
  527. public:
  528. /*!
  529. * The destructor.
  530. * The engine must have been closed before this happens.
  531. */
  532. virtual ~CarlaEngine();
  533. // -------------------------------------------------------------------
  534. // Static calls
  535. /*!
  536. * Get the number of available engine drivers.
  537. */
  538. static uint getDriverCount();
  539. /*!
  540. * Get the name of the engine driver at @a index.
  541. */
  542. static const char* getDriverName(const uint index);
  543. /*!
  544. * Get the device names of the driver at @a index.
  545. */
  546. static const char* const* getDriverDeviceNames(const uint index);
  547. /*!
  548. * Get device information about the driver at @a index and name @a driverName.
  549. */
  550. static const EngineDriverDeviceInfo* getDriverDeviceInfo(const uint index, const char* const driverName);
  551. /*!
  552. * Create a new engine, using driver @a driverName.
  553. * Returned value must be deleted when no longer needed.
  554. * @note This only initializes engine data, it doesn't actually start the engine.
  555. */
  556. static CarlaEngine* newDriverByName(const char* const driverName);
  557. // -------------------------------------------------------------------
  558. // Constant values
  559. /*!
  560. * Maximum client name size.
  561. */
  562. virtual uint getMaxClientNameSize() const noexcept;
  563. /*!
  564. * Maximum port name size.
  565. */
  566. virtual uint getMaxPortNameSize() const noexcept;
  567. /*!
  568. * Current number of plugins loaded.
  569. */
  570. uint getCurrentPluginCount() const noexcept;
  571. /*!
  572. * Maximum number of loadable plugins allowed.
  573. * This function returns 0 if engine is not started.
  574. */
  575. uint getMaxPluginNumber() const noexcept;
  576. // -------------------------------------------------------------------
  577. // Virtual, per-engine type calls
  578. /*!
  579. * Initialize/start the engine, using @a clientName.
  580. * When the engine is intialized, you need to call idle() at regular intervals.
  581. */
  582. virtual bool init(const char* const clientName);
  583. /*!
  584. * Close engine.
  585. * This function always closes the engine even if it returns false.
  586. * In other words, even when something goes wrong when closing the engine it still be closed nonetheless.
  587. */
  588. virtual bool close();
  589. /*!
  590. * Idle engine.
  591. */
  592. virtual void idle() noexcept;
  593. /*!
  594. * Check if engine is running.
  595. */
  596. virtual bool isRunning() const noexcept = 0;
  597. /*!
  598. * Check if engine is running offline (aka freewheel mode).
  599. */
  600. virtual bool isOffline() const noexcept = 0;
  601. /*!
  602. * Get engine type.
  603. */
  604. virtual EngineType getType() const noexcept = 0;
  605. /*!
  606. * Get the currently used driver name.
  607. */
  608. virtual const char* getCurrentDriverName() const noexcept = 0;
  609. /*!
  610. * Add new engine client.
  611. * @note This function must only be called within a plugin class.
  612. */
  613. virtual CarlaEngineClient* addClient(CarlaPlugin* const plugin);
  614. // -------------------------------------------------------------------
  615. // Plugin management
  616. /*!
  617. * Add new plugin.
  618. * @see ENGINE_CALLBACK_PLUGIN_ADDED
  619. */
  620. bool addPlugin(const BinaryType btype, const PluginType ptype, const char* const filename, const char* const name, const char* const label, const int64_t uniqueId, const void* const extra);
  621. /*!
  622. * Add new plugin, using native binary type.
  623. * @see ENGINE_CALLBACK_PLUGIN_ADDED
  624. */
  625. bool addPlugin(const PluginType ptype, const char* const filename, const char* const name, const char* const label, const int64_t uniqueId, const void* const extra);
  626. /*!
  627. * Remove plugin with id @a id.
  628. * @see ENGINE_CALLBACK_PLUGIN_REMOVED
  629. */
  630. bool removePlugin(const uint id);
  631. /*!
  632. * Remove all plugins.
  633. */
  634. bool removeAllPlugins();
  635. /*!
  636. * Rename plugin with id @a id to @a newName.
  637. * Returns the new name, or null if the operation failed.
  638. * Returned variable must be deleted if non-null.
  639. * @see ENGINE_CALLBACK_PLUGIN_RENAMED
  640. */
  641. virtual const char* renamePlugin(const uint id, const char* const newName);
  642. /*!
  643. * Clone plugin with id @a id.
  644. */
  645. bool clonePlugin(const uint id);
  646. /*!
  647. * Prepare replace of plugin with id @a id.
  648. * The next call to addPlugin() will use this id, replacing the selected plugin.
  649. * @note This function requires addPlugin() to be called afterwards, as soon as possible.
  650. */
  651. bool replacePlugin(const uint id);
  652. /*!
  653. * Switch plugins with id @a idA and @a idB.
  654. */
  655. bool switchPlugins(const uint idA, const uint idB);
  656. /*!
  657. * Get plugin with id @a id.
  658. */
  659. CarlaPlugin* getPlugin(const uint id) const;
  660. /*!
  661. * Get plugin with id @a id, faster unchecked version.
  662. */
  663. CarlaPlugin* getPluginUnchecked(const uint id) const noexcept;
  664. /*!
  665. * Get a unique plugin name within the engine.
  666. * Returned variable must be deleted if non-null.
  667. */
  668. const char* getUniquePluginName(const char* const name) const;
  669. // -------------------------------------------------------------------
  670. // Project management
  671. /*!
  672. * Load a file of any type.
  673. * This will try to load a generic file as a plugin,
  674. * either by direct handling (GIG, SF2 and SFZ) or by using an internal plugin (like Audio and MIDI).
  675. */
  676. bool loadFile(const char* const filename);
  677. /*!
  678. * Load a project file.
  679. * @note Already loaded plugins are not removed; call removeAllPlugins() first if needed.
  680. */
  681. bool loadProject(const char* const filename);
  682. /*!
  683. * Save current project to a file.
  684. */
  685. bool saveProject(const char* const filename);
  686. // -------------------------------------------------------------------
  687. // Information (base)
  688. /*!
  689. * Get the current engine driver hints.
  690. * @see EngineDriverHints
  691. */
  692. uint getHints() const noexcept;
  693. /*!
  694. * Get the current buffer size.
  695. */
  696. uint32_t getBufferSize() const noexcept;
  697. /*!
  698. * Get the current sample rate.
  699. */
  700. double getSampleRate() const noexcept;
  701. /*!
  702. * Get the current engine name.
  703. */
  704. const char* getName() const noexcept;
  705. /*!
  706. * Get the current engine proccess mode.
  707. */
  708. EngineProcessMode getProccessMode() const noexcept;
  709. /*!
  710. * Get the current engine options (read-only).
  711. */
  712. const EngineOptions& getOptions() const noexcept;
  713. /*!
  714. * Get the current Time information (read-only).
  715. */
  716. const EngineTimeInfo& getTimeInfo() const noexcept;
  717. // -------------------------------------------------------------------
  718. // Information (peaks)
  719. /*!
  720. * TODO.
  721. */
  722. float getInputPeak(const uint pluginId, const bool isLeft) const noexcept;
  723. /*!
  724. * TODO.
  725. */
  726. float getOutputPeak(const uint pluginId, const bool isLeft) const noexcept;
  727. // -------------------------------------------------------------------
  728. // Callback
  729. /*!
  730. * Call the main engine callback, if set.
  731. * May be called by plugins.
  732. */
  733. void callback(const EngineCallbackOpcode action, const uint pluginId, const int value1, const int value2, const float value3, const char* const valueStr) noexcept;
  734. /*!
  735. * Set the main engine callback to @a func.
  736. */
  737. void setCallback(const EngineCallbackFunc func, void* const ptr) noexcept;
  738. // -------------------------------------------------------------------
  739. // Callback
  740. /*!
  741. * Call the file callback, if set.
  742. * May be called by plugins.
  743. */
  744. const char* runFileCallback(const FileCallbackOpcode action, const bool isDir, const char* const title, const char* const filter) noexcept;
  745. /*!
  746. * Set the file callback to @a func.
  747. */
  748. void setFileCallback(const FileCallbackFunc func, void* const ptr) noexcept;
  749. #ifndef BUILD_BRIDGE
  750. // -------------------------------------------------------------------
  751. // Patchbay
  752. /*!
  753. * Connect two patchbay ports.
  754. */
  755. virtual bool patchbayConnect(const uint groupA, const uint portA, const uint groupB, const uint portB);
  756. /*!
  757. * Remove a patchbay connection.
  758. */
  759. virtual bool patchbayDisconnect(const uint connectionId);
  760. /*!
  761. * Force the engine to resend all patchbay clients, ports and connections again.
  762. */
  763. virtual bool patchbayRefresh();
  764. #endif
  765. // -------------------------------------------------------------------
  766. // Transport
  767. /*!
  768. * Start playback of the engine transport.
  769. */
  770. virtual void transportPlay() noexcept;
  771. /*!
  772. * Pause the engine transport.
  773. */
  774. virtual void transportPause() noexcept;
  775. /*!
  776. * Relocate the engine transport to @a frames.
  777. */
  778. virtual void transportRelocate(const uint64_t frame) noexcept;
  779. // -------------------------------------------------------------------
  780. // Error handling
  781. /*!
  782. * Get last error.
  783. */
  784. const char* getLastError() const noexcept;
  785. /*!
  786. * Set last error.
  787. */
  788. void setLastError(const char* const error) const noexcept;
  789. // -------------------------------------------------------------------
  790. // Misc
  791. /*!
  792. * Tell the engine it's about to close.
  793. * This is used to prevent the engine thread(s) from reactivating.
  794. */
  795. void setAboutToClose() noexcept;
  796. // -------------------------------------------------------------------
  797. // Options
  798. /*!
  799. * Set the engine option @a option to @a value or @a valueStr.
  800. */
  801. void setOption(const EngineOption option, const int value, const char* const valueStr);
  802. // -------------------------------------------------------------------
  803. // OSC Stuff
  804. #ifdef BUILD_BRIDGE
  805. /*!
  806. * Check if OSC bridge is registered.
  807. */
  808. bool isOscBridgeRegistered() const noexcept;
  809. #else
  810. /*!
  811. * Check if OSC controller is registered.
  812. */
  813. bool isOscControlRegistered() const noexcept;
  814. #endif
  815. /*!
  816. * Idle OSC.
  817. */
  818. void idleOsc() const noexcept;
  819. /*!
  820. * Get OSC TCP server path.
  821. */
  822. const char* getOscServerPathTCP() const noexcept;
  823. /*!
  824. * Get OSC UDP server path.
  825. */
  826. const char* getOscServerPathUDP() const noexcept;
  827. #ifdef BUILD_BRIDGE
  828. /*!
  829. * Set OSC bridge data.
  830. */
  831. void setOscBridgeData(const CarlaOscData* const oscData) const noexcept;
  832. #endif
  833. // -------------------------------------------------------------------
  834. // Helper functions
  835. /*!
  836. * Return internal data, needed for EventPorts when used in Rack and Bridge modes.
  837. * @note RT call
  838. */
  839. EngineEvent* getInternalEventBuffer(const bool isInput) const noexcept;
  840. /*!
  841. * Force register a plugin into slot @a id.
  842. * This is needed so we can receive OSC events for a plugin while it initializes.
  843. */
  844. void registerEnginePlugin(const uint id, CarlaPlugin* const plugin) noexcept;
  845. #ifndef BUILD_BRIDGE
  846. /*!
  847. * Virtual functions for handling MIDI ports in the rack graph.
  848. */
  849. virtual bool connectRackMidiInPort(const char* const) { return false; }
  850. virtual bool connectRackMidiOutPort(const char* const) { return false; }
  851. virtual bool disconnectRackMidiInPort(const char* const) { return false; }
  852. virtual bool disconnectRackMidiOutPort(const char* const) { return false; }
  853. #endif
  854. // -------------------------------------------------------------------
  855. protected:
  856. /*!
  857. * Internal data, for CarlaEngine subclasses only.
  858. */
  859. struct ProtectedData;
  860. ProtectedData* const pData;
  861. friend class ScopedActionLock;
  862. // -------------------------------------------------------------------
  863. // Internal stuff
  864. /*!
  865. * Report to all plugins about buffer size change.
  866. */
  867. void bufferSizeChanged(const uint32_t newBufferSize);
  868. /*!
  869. * Report to all plugins about sample rate change.
  870. * This is not supported on all plugin types, in which case they will have to be re-initiated.
  871. */
  872. void sampleRateChanged(const double newSampleRate);
  873. /*!
  874. * Report to all plugins about offline mode change.
  875. */
  876. void offlineModeChanged(const bool isOffline);
  877. /*!
  878. * Run any pending RT events.
  879. * Must always be called at the end of audio processing.
  880. * @note RT call
  881. */
  882. void runPendingRtEvents() noexcept;
  883. /*!
  884. * Set a plugin (stereo) peak values.
  885. * @note RT call
  886. */
  887. void setPluginPeaks(const uint pluginId, float const inPeaks[2], float const outPeaks[2]) noexcept;
  888. #ifndef BUILD_BRIDGE
  889. // -------------------------------------------------------------------
  890. // Patchbay stuff
  891. /*!
  892. * Virtual functions for handling patchbay state.
  893. */
  894. virtual const char* const* getPatchbayConnections() const;
  895. virtual void restorePatchbayConnection(const char* const sourcePort, const char* const targetPort);
  896. #endif
  897. // -------------------------------------------------------------------
  898. public:
  899. /*!
  900. * Native audio APIs.
  901. */
  902. enum AudioApi {
  903. AUDIO_API_NULL = 0,
  904. // common
  905. AUDIO_API_JACK = 1,
  906. // linux
  907. AUDIO_API_ALSA = 2,
  908. AUDIO_API_OSS = 3,
  909. AUDIO_API_PULSE = 4,
  910. // macos
  911. AUDIO_API_CORE = 5,
  912. // windows
  913. AUDIO_API_ASIO = 6,
  914. AUDIO_API_DS = 7
  915. };
  916. // -------------------------------------------------------------------
  917. // Engine initializers
  918. // JACK
  919. static CarlaEngine* newJack();
  920. #ifndef BUILD_BRIDGE
  921. // RtAudio
  922. static CarlaEngine* newRtAudio(const AudioApi api);
  923. static uint getRtAudioApiCount();
  924. static const char* getRtAudioApiName(const uint index);
  925. static const char* const* getRtAudioApiDeviceNames(const uint index);
  926. static const EngineDriverDeviceInfo* getRtAudioDeviceInfo(const uint index, const char* const deviceName);
  927. // Juce
  928. static CarlaEngine* newJuce(const AudioApi api);
  929. static uint getJuceApiCount();
  930. static const char* getJuceApiName(const uint index);
  931. static const char* const* getJuceApiDeviceNames(const uint index);
  932. static const EngineDriverDeviceInfo* getJuceDeviceInfo(const uint index, const char* const deviceName);
  933. #else
  934. // Bridge
  935. static CarlaEngine* newBridge(const char* const audioBaseName, const char* const controlBaseName, const char* const timeBaseName);
  936. #endif
  937. // -------------------------------------------------------------------
  938. // Bridge/Controller OSC stuff
  939. #ifdef BUILD_BRIDGE
  940. void oscSend_bridge_plugin_info1(const PluginCategory category, const uint hints, const int64_t uniqueId) const noexcept;
  941. void oscSend_bridge_plugin_info2(const char* const realName, const char* const label, const char* const maker, const char* const copyright) const noexcept;
  942. void oscSend_bridge_audio_count(const uint32_t ins, const uint32_t outs) const noexcept;
  943. void oscSend_bridge_midi_count(const uint32_t ins, const uint32_t outs) const noexcept;
  944. void oscSend_bridge_parameter_count(const uint32_t ins, const uint32_t outs) const noexcept;
  945. void oscSend_bridge_program_count(const uint32_t count) const noexcept;
  946. void oscSend_bridge_midi_program_count(const uint32_t count) const noexcept;
  947. 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;
  948. void oscSend_bridge_parameter_ranges1(const uint32_t index, const float def, const float min, const float max) const noexcept;
  949. void oscSend_bridge_parameter_ranges2(const uint32_t index, const float step, const float stepSmall, const float stepLarge) const noexcept;
  950. void oscSend_bridge_parameter_midi_cc(const uint32_t index, const int16_t cc) const noexcept;
  951. void oscSend_bridge_parameter_midi_channel(const uint32_t index, const uint8_t channel) const noexcept;
  952. void oscSend_bridge_parameter_value(const uint32_t index, const float value) const noexcept;
  953. void oscSend_bridge_default_value(const uint32_t index, const float value) const noexcept;
  954. void oscSend_bridge_current_program(const int32_t index) const noexcept;
  955. void oscSend_bridge_current_midi_program(const int32_t index) const noexcept;
  956. void oscSend_bridge_program_name(const uint32_t index, const char* const name) const noexcept;
  957. void oscSend_bridge_midi_program_data(const uint32_t index, const uint32_t bank, const uint32_t program, const char* const name) const noexcept;
  958. void oscSend_bridge_configure(const char* const key, const char* const value) const noexcept;
  959. void oscSend_bridge_set_custom_data(const char* const type, const char* const key, const char* const value) const noexcept;
  960. void oscSend_bridge_set_chunk_data(const char* const chunkFile) const noexcept;
  961. void oscSend_bridge_set_peaks() const noexcept;
  962. void oscSend_bridge_pong() const noexcept;
  963. #else
  964. void oscSend_control_add_plugin_start(const uint pluginId, const char* const pluginName) const noexcept;
  965. void oscSend_control_add_plugin_end(const uint pluginId) const noexcept;
  966. void oscSend_control_remove_plugin(const uint pluginId) const noexcept;
  967. void oscSend_control_set_plugin_info1(const uint pluginId, const PluginType type, const PluginCategory category, const uint hints, const int64_t uniqueId) const noexcept;
  968. 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;
  969. void oscSend_control_set_audio_count(const uint pluginId, const uint32_t ins, const uint32_t outs) const noexcept;
  970. void oscSend_control_set_midi_count(const uint pluginId, const uint32_t ins, const uint32_t outs) const noexcept;
  971. void oscSend_control_set_parameter_count(const uint pluginId, const uint32_t ins, const uint32_t outs) const noexcept;
  972. void oscSend_control_set_program_count(const uint pluginId, const uint32_t count) const noexcept;
  973. void oscSend_control_set_midi_program_count(const uint pluginId, const uint32_t count) const noexcept;
  974. 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;
  975. void oscSend_control_set_parameter_ranges1(const uint pluginId, const uint32_t index, const float def, const float min, const float max) const noexcept;
  976. void oscSend_control_set_parameter_ranges2(const uint pluginId, const uint32_t index, const float step, const float stepSmall, const float stepLarge) const noexcept;
  977. void oscSend_control_set_parameter_midi_cc(const uint pluginId, const uint32_t index, const int16_t cc) const noexcept;
  978. void oscSend_control_set_parameter_midi_channel(const uint pluginId, const uint32_t index, const uint8_t channel) const noexcept;
  979. 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)
  980. void oscSend_control_set_default_value(const uint pluginId, const uint32_t index, const float value) const noexcept;
  981. void oscSend_control_set_current_program(const uint pluginId, const int32_t index) const noexcept;
  982. void oscSend_control_set_current_midi_program(const uint pluginId, const int32_t index) const noexcept;
  983. void oscSend_control_set_program_name(const uint pluginId, const uint32_t index, const char* const name) const noexcept;
  984. 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;
  985. void oscSend_control_note_on(const uint pluginId, const uint8_t channel, const uint8_t note, const uint8_t velo) const noexcept;
  986. void oscSend_control_note_off(const uint pluginId, const uint8_t channel, const uint8_t note) const noexcept;
  987. void oscSend_control_set_peaks(const uint pluginId) const noexcept;
  988. void oscSend_control_exit() const noexcept;
  989. #endif
  990. CARLA_DECLARE_NON_COPY_CLASS(CarlaEngine)
  991. };
  992. /**@}*/
  993. // -----------------------------------------------------------------------
  994. CARLA_BACKEND_END_NAMESPACE
  995. #endif // CARLA_ENGINE_HPP_INCLUDED