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.

1221 lines
34KB

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