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.

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