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.

1204 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. CARLA_DECLARE_NON_COPY_CLASS(CarlaEngineEventPort)
  441. #endif
  442. };
  443. // -----------------------------------------------------------------------
  444. /*!
  445. * Carla Engine client.
  446. * Each plugin requires one client from the engine (created via CarlaEngine::addClient()).
  447. * @note This is a virtual class, some engine types provide custom funtionality.
  448. */
  449. class CarlaEngineClient
  450. {
  451. public:
  452. /*!
  453. * The constructor, protected.
  454. * All constructor parameters are constant and will never change in the lifetime of the client.
  455. * Client starts in deactivated state.
  456. */
  457. CarlaEngineClient(const CarlaEngine& engine) noexcept;
  458. /*!
  459. * The destructor.
  460. */
  461. virtual ~CarlaEngineClient() noexcept;
  462. /*!
  463. * Activate this client.
  464. * Client must be deactivated before calling this function.
  465. */
  466. virtual void activate() noexcept;
  467. /*!
  468. * Deactivate this client.
  469. * Client must be activated before calling this function.
  470. */
  471. virtual void deactivate() noexcept;
  472. /*!
  473. * Check if the client is activated.
  474. */
  475. virtual bool isActive() const noexcept;
  476. /*!
  477. * Check if the client is ok.
  478. * Plugins will refuse to instantiate if this returns false.
  479. * @note This is always true in rack and patchbay processing modes.
  480. */
  481. virtual bool isOk() const noexcept;
  482. /*!
  483. * Get the current latency, in samples.
  484. */
  485. virtual uint32_t getLatency() const noexcept;
  486. /*!
  487. * Change the client's latency.
  488. */
  489. virtual void setLatency(const uint32_t samples) noexcept;
  490. /*!
  491. * Add a new port of type @a portType.
  492. * @note This function does nothing in rack processing mode since ports are static there.
  493. */
  494. virtual CarlaEnginePort* addPort(const EnginePortType portType, const char* const name, const bool isInput);
  495. /*!
  496. * Get this client's engine.
  497. */
  498. const CarlaEngine& getEngine() const noexcept
  499. {
  500. return fEngine;
  501. }
  502. #ifndef DOXYGEN
  503. protected:
  504. const CarlaEngine& fEngine;
  505. bool fActive;
  506. uint32_t fLatency;
  507. CARLA_DECLARE_NON_COPY_CLASS(CarlaEngineClient)
  508. #endif
  509. };
  510. // -----------------------------------------------------------------------
  511. /*!
  512. * Carla Engine.
  513. * @note This is a virtual class for all available engine types available in Carla.
  514. */
  515. class CarlaEngine
  516. {
  517. protected:
  518. /*!
  519. * The constructor, protected.
  520. * @note This only initializes engine data, it doesn't actually start the engine.
  521. */
  522. CarlaEngine();
  523. public:
  524. /*!
  525. * The destructor.
  526. * The engine must have been closed before this happens.
  527. */
  528. virtual ~CarlaEngine();
  529. // -------------------------------------------------------------------
  530. // Static calls
  531. /*!
  532. * Get the number of available engine drivers.
  533. */
  534. static uint getDriverCount();
  535. /*!
  536. * Get the name of the engine driver at @a index.
  537. */
  538. static const char* getDriverName(const uint index);
  539. /*!
  540. * Get the device names of the driver at @a index.
  541. */
  542. static const char* const* getDriverDeviceNames(const uint index);
  543. /*!
  544. * Get device information about the driver at @a index and name @a driverName.
  545. */
  546. static const EngineDriverDeviceInfo* getDriverDeviceInfo(const uint index, const char* const driverName);
  547. /*!
  548. * Create a new engine, using driver @a driverName.
  549. * Returned value must be deleted when no longer needed.
  550. * @note This only initializes engine data, it doesn't actually start the engine.
  551. */
  552. static CarlaEngine* newDriverByName(const char* const driverName);
  553. // -------------------------------------------------------------------
  554. // Constant values
  555. /*!
  556. * Maximum client name size.
  557. */
  558. virtual uint getMaxClientNameSize() const noexcept;
  559. /*!
  560. * Maximum port name size.
  561. */
  562. virtual uint getMaxPortNameSize() const noexcept;
  563. /*!
  564. * Current number of plugins loaded.
  565. */
  566. uint getCurrentPluginCount() const noexcept;
  567. /*!
  568. * Maximum number of loadable plugins allowed.
  569. * This function returns 0 if engine is not started.
  570. */
  571. uint getMaxPluginNumber() const noexcept;
  572. // -------------------------------------------------------------------
  573. // Virtual, per-engine type calls
  574. /*!
  575. * Initialize/start the engine, using @a clientName.
  576. * When the engine is intialized, you need to call idle() at regular intervals.
  577. */
  578. virtual bool init(const char* const clientName);
  579. /*!
  580. * Close engine.
  581. * This function always closes the engine even if it returns false.
  582. * In other words, even when something goes wrong when closing the engine it still be closed nonetheless.
  583. */
  584. virtual bool close();
  585. /*!
  586. * Idle engine.
  587. */
  588. virtual void idle() noexcept;
  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. * @see ENGINE_CALLBACK_PLUGIN_ADDED
  615. */
  616. 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);
  617. /*!
  618. * Add new plugin, using native binary type.
  619. * @see ENGINE_CALLBACK_PLUGIN_ADDED
  620. */
  621. 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);
  622. /*!
  623. * Remove plugin with id @a id.
  624. * @see ENGINE_CALLBACK_PLUGIN_REMOVED
  625. */
  626. bool removePlugin(const uint id);
  627. /*!
  628. * Remove all plugins.
  629. */
  630. bool removeAllPlugins();
  631. /*!
  632. * Rename plugin with id @a id to @a newName.
  633. * Returns the new name, or null if the operation failed.
  634. * Returned variable must be deleted if non-null.
  635. * @see ENGINE_CALLBACK_PLUGIN_RENAMED
  636. */
  637. virtual const char* renamePlugin(const uint id, const char* const newName);
  638. /*!
  639. * Clone plugin with id @a id.
  640. */
  641. bool clonePlugin(const uint id);
  642. /*!
  643. * Prepare replace of plugin with id @a id.
  644. * The next call to addPlugin() will use this id, replacing the selected plugin.
  645. * @note This function requires addPlugin() to be called afterwards, as soon as possible.
  646. */
  647. bool replacePlugin(const uint id);
  648. /*!
  649. * Switch plugins with id @a idA and @a idB.
  650. */
  651. bool switchPlugins(const uint idA, const uint idB);
  652. /*!
  653. * Get plugin with id @a id.
  654. */
  655. CarlaPlugin* getPlugin(const uint id) const;
  656. /*!
  657. * Get plugin with id @a id, faster unchecked version.
  658. */
  659. CarlaPlugin* getPluginUnchecked(const uint id) const noexcept;
  660. /*!
  661. * Get a unique plugin name within the engine.
  662. * Returned variable must be deleted if non-null.
  663. */
  664. const char* getUniquePluginName(const char* const name) const;
  665. // -------------------------------------------------------------------
  666. // Project management
  667. /*!
  668. * Load a file of any type.
  669. * This will try to load a generic file as a plugin,
  670. * either by direct handling (GIG, SF2 and SFZ) or by using an internal plugin (like Audio and MIDI).
  671. */
  672. bool loadFile(const char* const filename);
  673. /*!
  674. * Load a project file.
  675. * @note Already loaded plugins are not removed; call removeAllPlugins() first if needed.
  676. */
  677. bool loadProject(const char* const filename);
  678. /*!
  679. * Save current project to a file.
  680. */
  681. bool saveProject(const char* const filename);
  682. // -------------------------------------------------------------------
  683. // Information (base)
  684. /*!
  685. * Get the current engine driver hints.
  686. * @see EngineDriverHints
  687. */
  688. uint getHints() const noexcept;
  689. /*!
  690. * Get the current buffer size.
  691. */
  692. uint32_t getBufferSize() const noexcept;
  693. /*!
  694. * Get the current sample rate.
  695. */
  696. double getSampleRate() const noexcept;
  697. /*!
  698. * Get the current engine name.
  699. */
  700. const char* getName() const noexcept;
  701. /*!
  702. * Get the current engine proccess mode.
  703. */
  704. EngineProcessMode getProccessMode() const noexcept;
  705. /*!
  706. * Get the current engine options (read-only).
  707. */
  708. const EngineOptions& getOptions() const noexcept;
  709. /*!
  710. * Get the current Time information (read-only).
  711. */
  712. const EngineTimeInfo& getTimeInfo() const noexcept;
  713. // -------------------------------------------------------------------
  714. // Information (peaks)
  715. /*!
  716. * TODO.
  717. */
  718. float getInputPeak(const uint pluginId, const bool isLeft) const noexcept;
  719. /*!
  720. * TODO.
  721. */
  722. float getOutputPeak(const uint pluginId, const bool isLeft) const noexcept;
  723. // -------------------------------------------------------------------
  724. // Callback
  725. /*!
  726. * Call the main engine callback, if set.
  727. * May be called by plugins.
  728. */
  729. void callback(const EngineCallbackOpcode action, const uint pluginId, const int value1, const int value2, const float value3, const char* const valueStr) noexcept;
  730. /*!
  731. * Set the main engine callback to @a func.
  732. */
  733. void setCallback(const EngineCallbackFunc func, void* const ptr) noexcept;
  734. // -------------------------------------------------------------------
  735. // Callback
  736. /*!
  737. * Call the file callback, if set.
  738. * May be called by plugins.
  739. */
  740. const char* runFileCallback(const FileCallbackOpcode action, const bool isDir, const char* const title, const char* const filter) noexcept;
  741. /*!
  742. * Set the file callback to @a func.
  743. */
  744. void setFileCallback(const FileCallbackFunc func, void* const ptr) noexcept;
  745. #ifndef BUILD_BRIDGE
  746. // -------------------------------------------------------------------
  747. // Patchbay
  748. /*!
  749. * Connect two patchbay ports.
  750. */
  751. virtual bool patchbayConnect(const uint groupA, const uint portA, const uint groupB, const uint portB);
  752. /*!
  753. * Remove a patchbay connection.
  754. */
  755. virtual bool patchbayDisconnect(const uint connectionId);
  756. /*!
  757. * Force the engine to resend all patchbay clients, ports and connections again.
  758. */
  759. virtual bool patchbayRefresh();
  760. #endif
  761. // -------------------------------------------------------------------
  762. // Transport
  763. /*!
  764. * Start playback of the engine transport.
  765. */
  766. virtual void transportPlay() noexcept;
  767. /*!
  768. * Pause the engine transport.
  769. */
  770. virtual void transportPause() noexcept;
  771. /*!
  772. * Relocate the engine transport to @a frames.
  773. */
  774. virtual void transportRelocate(const uint64_t frame) noexcept;
  775. // -------------------------------------------------------------------
  776. // Error handling
  777. /*!
  778. * Get last error.
  779. */
  780. const char* getLastError() const noexcept;
  781. /*!
  782. * Set last error.
  783. */
  784. void setLastError(const char* const error) const noexcept;
  785. // -------------------------------------------------------------------
  786. // Misc
  787. /*!
  788. * Tell the engine it's about to close.
  789. * This is used to prevent the engine thread(s) from reactivating.
  790. */
  791. void setAboutToClose() noexcept;
  792. // -------------------------------------------------------------------
  793. // Options
  794. /*!
  795. * Set the engine option @a option to @a value or @a valueStr.
  796. */
  797. void setOption(const EngineOption option, const int value, const char* const valueStr);
  798. // -------------------------------------------------------------------
  799. // OSC Stuff
  800. #ifdef BUILD_BRIDGE
  801. /*!
  802. * Check if OSC bridge is registered.
  803. */
  804. bool isOscBridgeRegistered() const noexcept;
  805. #else
  806. /*!
  807. * Check if OSC controller is registered.
  808. */
  809. bool isOscControlRegistered() const noexcept;
  810. #endif
  811. /*!
  812. * Idle OSC.
  813. */
  814. void idleOsc() const noexcept;
  815. /*!
  816. * Get OSC TCP server path.
  817. */
  818. const char* getOscServerPathTCP() const noexcept;
  819. /*!
  820. * Get OSC UDP server path.
  821. */
  822. const char* getOscServerPathUDP() const noexcept;
  823. #ifdef BUILD_BRIDGE
  824. /*!
  825. * Set OSC bridge data.
  826. */
  827. void setOscBridgeData(const CarlaOscData* const oscData) const noexcept;
  828. #endif
  829. // -------------------------------------------------------------------
  830. // Helper functions
  831. /*!
  832. * Return internal data, needed for EventPorts when used in Rack and Bridge modes.
  833. * @note RT call
  834. */
  835. EngineEvent* getInternalEventBuffer(const bool isInput) const noexcept;
  836. /*!
  837. * Force register a plugin into slot @a id.
  838. * This is needed so we can receive OSC events for a plugin while it initializes.
  839. */
  840. void registerEnginePlugin(const uint id, CarlaPlugin* const plugin) noexcept;
  841. #ifndef BUILD_BRIDGE
  842. /*!
  843. * Virtual functions for handling MIDI ports in the rack graph.
  844. */
  845. virtual bool connectRackMidiInPort(const char* const) { return false; }
  846. virtual bool connectRackMidiOutPort(const char* const) { return false; }
  847. virtual bool disconnectRackMidiInPort(const char* const) { return false; }
  848. virtual bool disconnectRackMidiOutPort(const char* const) { return false; }
  849. #endif
  850. // -------------------------------------------------------------------
  851. protected:
  852. /*!
  853. * Internal data, for CarlaEngine subclasses only.
  854. */
  855. struct ProtectedData;
  856. ProtectedData* const pData;
  857. /*!
  858. * Some internal classes read directly from pData.
  859. */
  860. friend class EngineInternalGraph;
  861. friend class PatchbayGraph;
  862. friend class RackGraph;
  863. friend class ScopedActionLock;
  864. // -------------------------------------------------------------------
  865. // Internal stuff
  866. /*!
  867. * Report to all plugins about buffer size change.
  868. */
  869. void bufferSizeChanged(const uint32_t newBufferSize);
  870. /*!
  871. * Report to all plugins about sample rate change.
  872. * This is not supported on all plugin types, in which case they will have to be re-initiated.
  873. */
  874. void sampleRateChanged(const double newSampleRate);
  875. /*!
  876. * Report to all plugins about offline mode change.
  877. */
  878. void offlineModeChanged(const bool isOffline);
  879. /*!
  880. * Run any pending RT events.
  881. * Must always be called at the end of audio processing.
  882. * @note RT call
  883. */
  884. void runPendingRtEvents() noexcept;
  885. /*!
  886. * Set a plugin (stereo) peak values.
  887. * @note RT call
  888. */
  889. void setPluginPeaks(const uint pluginId, float const inPeaks[2], float const outPeaks[2]) noexcept;
  890. #ifndef BUILD_BRIDGE
  891. // -------------------------------------------------------------------
  892. // Patchbay stuff
  893. /*!
  894. * Virtual functions for handling patchbay state.
  895. */
  896. virtual const char* const* getPatchbayConnections() const;
  897. virtual void restorePatchbayConnection(const char* const sourcePort, const char* const targetPort);
  898. #endif
  899. // -------------------------------------------------------------------
  900. public:
  901. /*!
  902. * Native audio APIs.
  903. */
  904. enum AudioApi {
  905. AUDIO_API_NULL = 0,
  906. // common
  907. AUDIO_API_JACK = 1,
  908. // linux
  909. AUDIO_API_ALSA = 2,
  910. AUDIO_API_OSS = 3,
  911. AUDIO_API_PULSE = 4,
  912. // macos
  913. AUDIO_API_CORE = 5,
  914. // windows
  915. AUDIO_API_ASIO = 6,
  916. AUDIO_API_DS = 7
  917. };
  918. // -------------------------------------------------------------------
  919. // Engine initializers
  920. // JACK
  921. static CarlaEngine* newJack();
  922. #ifndef BUILD_BRIDGE
  923. // RtAudio
  924. static CarlaEngine* newRtAudio(const AudioApi api);
  925. static uint getRtAudioApiCount();
  926. static const char* getRtAudioApiName(const uint index);
  927. static const char* const* getRtAudioApiDeviceNames(const uint index);
  928. static const EngineDriverDeviceInfo* getRtAudioDeviceInfo(const uint index, const char* const deviceName);
  929. // Juce
  930. static CarlaEngine* newJuce(const AudioApi api);
  931. static uint getJuceApiCount();
  932. static const char* getJuceApiName(const uint index);
  933. static const char* const* getJuceApiDeviceNames(const uint index);
  934. static const EngineDriverDeviceInfo* getJuceDeviceInfo(const uint index, const char* const deviceName);
  935. #else
  936. // Bridge
  937. static CarlaEngine* newBridge(const char* const audioBaseName, const char* const controlBaseName, const char* const timeBaseName);
  938. #endif
  939. // -------------------------------------------------------------------
  940. // Bridge/Controller OSC stuff
  941. #ifdef BUILD_BRIDGE
  942. void oscSend_bridge_plugin_info1(const PluginCategory category, const uint hints, const int64_t uniqueId) const noexcept;
  943. void oscSend_bridge_plugin_info2(const char* const realName, const char* const label, const char* const maker, const char* const copyright) const noexcept;
  944. void oscSend_bridge_audio_count(const uint32_t ins, const uint32_t outs) const noexcept;
  945. void oscSend_bridge_midi_count(const uint32_t ins, const uint32_t outs) const noexcept;
  946. void oscSend_bridge_parameter_count(const uint32_t ins, const uint32_t outs) const noexcept;
  947. void oscSend_bridge_program_count(const uint32_t count) const noexcept;
  948. void oscSend_bridge_midi_program_count(const uint32_t count) const noexcept;
  949. 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;
  950. void oscSend_bridge_parameter_ranges1(const uint32_t index, const float def, const float min, const float max) const noexcept;
  951. void oscSend_bridge_parameter_ranges2(const uint32_t index, const float step, const float stepSmall, const float stepLarge) const noexcept;
  952. void oscSend_bridge_parameter_midi_cc(const uint32_t index, const int16_t cc) const noexcept;
  953. void oscSend_bridge_parameter_midi_channel(const uint32_t index, const uint8_t channel) const noexcept;
  954. void oscSend_bridge_parameter_value(const uint32_t index, const float value) const noexcept;
  955. void oscSend_bridge_default_value(const uint32_t index, const float value) const noexcept;
  956. void oscSend_bridge_current_program(const int32_t index) const noexcept;
  957. void oscSend_bridge_current_midi_program(const int32_t index) const noexcept;
  958. void oscSend_bridge_program_name(const uint32_t index, const char* const name) const noexcept;
  959. void oscSend_bridge_midi_program_data(const uint32_t index, const uint32_t bank, const uint32_t program, const char* const name) const noexcept;
  960. void oscSend_bridge_configure(const char* const key, const char* const value) const noexcept;
  961. void oscSend_bridge_set_custom_data(const char* const type, const char* const key, const char* const value) const noexcept;
  962. void oscSend_bridge_set_chunk_data(const char* const chunkFile) const noexcept;
  963. void oscSend_bridge_set_peaks() const noexcept;
  964. void oscSend_bridge_pong() const noexcept;
  965. #else
  966. void oscSend_control_add_plugin_start(const uint pluginId, const char* const pluginName) const noexcept;
  967. void oscSend_control_add_plugin_end(const uint pluginId) const noexcept;
  968. void oscSend_control_remove_plugin(const uint pluginId) const noexcept;
  969. void oscSend_control_set_plugin_info1(const uint pluginId, const PluginType type, const PluginCategory category, const uint hints, const int64_t uniqueId) const noexcept;
  970. 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;
  971. void oscSend_control_set_audio_count(const uint pluginId, const uint32_t ins, const uint32_t outs) const noexcept;
  972. void oscSend_control_set_midi_count(const uint pluginId, const uint32_t ins, const uint32_t outs) const noexcept;
  973. void oscSend_control_set_parameter_count(const uint pluginId, const uint32_t ins, const uint32_t outs) const noexcept;
  974. void oscSend_control_set_program_count(const uint pluginId, const uint32_t count) const noexcept;
  975. void oscSend_control_set_midi_program_count(const uint pluginId, const uint32_t count) const noexcept;
  976. 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;
  977. void oscSend_control_set_parameter_ranges1(const uint pluginId, const uint32_t index, const float def, const float min, const float max) const noexcept;
  978. void oscSend_control_set_parameter_ranges2(const uint pluginId, const uint32_t index, const float step, const float stepSmall, const float stepLarge) const noexcept;
  979. void oscSend_control_set_parameter_midi_cc(const uint pluginId, const uint32_t index, const int16_t cc) const noexcept;
  980. void oscSend_control_set_parameter_midi_channel(const uint pluginId, const uint32_t index, const uint8_t channel) const noexcept;
  981. 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)
  982. void oscSend_control_set_default_value(const uint pluginId, const uint32_t index, const float value) const noexcept;
  983. void oscSend_control_set_current_program(const uint pluginId, const int32_t index) const noexcept;
  984. void oscSend_control_set_current_midi_program(const uint pluginId, const int32_t index) const noexcept;
  985. void oscSend_control_set_program_name(const uint pluginId, const uint32_t index, const char* const name) const noexcept;
  986. 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;
  987. void oscSend_control_note_on(const uint pluginId, const uint8_t channel, const uint8_t note, const uint8_t velo) const noexcept;
  988. void oscSend_control_note_off(const uint pluginId, const uint8_t channel, const uint8_t note) const noexcept;
  989. void oscSend_control_set_peaks(const uint pluginId) const noexcept;
  990. void oscSend_control_exit() const noexcept;
  991. #endif
  992. CARLA_DECLARE_NON_COPY_CLASS(CarlaEngine)
  993. };
  994. /**@}*/
  995. // -----------------------------------------------------------------------
  996. CARLA_BACKEND_END_NAMESPACE
  997. #endif // CARLA_ENGINE_HPP_INCLUDED