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.

1226 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. union {
  158. uint8_t data[kDataSize];
  159. uint8_t* dataExt;
  160. };
  161. };
  162. /*!
  163. * Engine event.
  164. */
  165. struct EngineEvent {
  166. EngineEventType type; //!< Event Type; either Control or MIDI
  167. uint32_t time; //!< Time offset in frames
  168. uint8_t channel; //!< Channel, used for MIDI-related events
  169. /*!
  170. * Event specific data.
  171. */
  172. union {
  173. EngineControlEvent ctrl;
  174. EngineMidiEvent midi;
  175. };
  176. void fillFromMidiData(const uint8_t size, uint8_t* const data);
  177. };
  178. /*!
  179. * Engine options.
  180. */
  181. struct EngineOptions {
  182. EngineProcessMode processMode;
  183. EngineTransportMode transportMode;
  184. bool forceStereo;
  185. bool preferPluginBridges;
  186. bool preferUiBridges;
  187. bool uisAlwaysOnTop;
  188. unsigned int maxParameters;
  189. unsigned int uiBridgesTimeout;
  190. unsigned int audioNumPeriods;
  191. unsigned int audioBufferSize;
  192. unsigned int audioSampleRate;
  193. const char* audioDevice;
  194. const char* binaryDir;
  195. const char* resourceDir;
  196. EngineOptions()
  197. #ifdef CARLA_OS_LINUX
  198. : processMode(ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS),
  199. transportMode(ENGINE_TRANSPORT_MODE_JACK),
  200. #else
  201. : processMode(ENGINE_PROCESS_MODE_CONTINUOUS_RACK),
  202. transportMode(ENGINE_TRANSPORT_MODE_INTERNAL),
  203. #endif
  204. forceStereo(false),
  205. preferPluginBridges(false),
  206. preferUiBridges(true),
  207. uisAlwaysOnTop(true),
  208. maxParameters(MAX_DEFAULT_PARAMETERS),
  209. uiBridgesTimeout(4000),
  210. audioNumPeriods(2),
  211. audioBufferSize(512),
  212. audioSampleRate(44100),
  213. audioDevice(nullptr),
  214. binaryDir(nullptr),
  215. resourceDir(nullptr) {}
  216. ~EngineOptions()
  217. {
  218. if (audioDevice != nullptr)
  219. {
  220. delete[] audioDevice;
  221. audioDevice = nullptr;
  222. }
  223. if (binaryDir != nullptr)
  224. {
  225. delete[] binaryDir;
  226. binaryDir = nullptr;
  227. }
  228. if (resourceDir != nullptr)
  229. {
  230. delete[] resourceDir;
  231. resourceDir = nullptr;
  232. }
  233. }
  234. };
  235. /*!
  236. * Engine BBT Time information.
  237. */
  238. struct EngineTimeInfoBBT {
  239. int32_t bar; //!< current bar
  240. int32_t beat; //!< current beat-within-bar
  241. int32_t tick; //!< current tick-within-beat
  242. double barStartTick;
  243. float beatsPerBar; //!< time signature "numerator"
  244. float beatType; //!< time signature "denominator"
  245. double ticksPerBeat;
  246. double beatsPerMinute;
  247. EngineTimeInfoBBT() noexcept
  248. : bar(0),
  249. beat(0),
  250. tick(0),
  251. barStartTick(0.0),
  252. beatsPerBar(0.0f),
  253. beatType(0.0f),
  254. ticksPerBeat(0.0),
  255. beatsPerMinute(0.0) {}
  256. };
  257. /*!
  258. * Engine Time information.
  259. */
  260. struct EngineTimeInfo {
  261. static const uint kValidBBT = 0x1;
  262. bool playing;
  263. uint64_t frame;
  264. uint64_t usecs;
  265. uint valid;
  266. EngineTimeInfoBBT bbt;
  267. EngineTimeInfo() noexcept
  268. : playing(false),
  269. frame(0),
  270. usecs(0),
  271. valid(0x0) {}
  272. void clear() noexcept
  273. {
  274. playing = false;
  275. frame = 0;
  276. usecs = 0;
  277. valid = 0x0;
  278. }
  279. // quick operator, doesn't check all values
  280. bool operator==(const EngineTimeInfo& timeInfo) const noexcept
  281. {
  282. if (timeInfo.playing != playing || timeInfo.frame != frame || timeInfo.valid != valid)
  283. return false;
  284. if ((valid & kValidBBT) == 0)
  285. return true;
  286. if (timeInfo.bbt.beatsPerMinute != bbt.beatsPerMinute)
  287. return false;
  288. return true;
  289. }
  290. bool operator!=(const EngineTimeInfo& timeInfo) const noexcept
  291. {
  292. return !operator==(timeInfo);
  293. }
  294. };
  295. // -----------------------------------------------------------------------
  296. /*!
  297. * Carla Engine port (Abstract).\n
  298. * This is the base class for all Carla Engine ports.
  299. */
  300. class CarlaEnginePort
  301. {
  302. protected:
  303. /*!
  304. * The constructor.\n
  305. * Param \a isInput defines wherever this is an input port or not (output otherwise).\n
  306. * Input/output and process mode are constant for the lifetime of the port.
  307. */
  308. CarlaEnginePort(const CarlaEngine& engine, const bool isInput);
  309. public:
  310. /*!
  311. * The destructor.
  312. */
  313. virtual ~CarlaEnginePort();
  314. /*!
  315. * Get the type of the port, as provided by the respective subclasses.
  316. */
  317. virtual EnginePortType getType() const noexcept = 0;
  318. /*!
  319. * Initialize the port's internal buffer.
  320. */
  321. virtual void initBuffer() = 0;
  322. /*!
  323. * Check if this port is an input.
  324. */
  325. bool isInput() const noexcept
  326. {
  327. return fIsInput;
  328. }
  329. #ifndef DOXYGEN
  330. protected:
  331. const CarlaEngine& fEngine;
  332. const bool fIsInput;
  333. CARLA_DECLARE_NON_COPY_CLASS(CarlaEnginePort)
  334. #endif
  335. };
  336. /*!
  337. * Carla Engine Audio port.
  338. */
  339. class CarlaEngineAudioPort : public CarlaEnginePort
  340. {
  341. public:
  342. /*!
  343. * The constructor.\n
  344. * All constructor parameters are constant and will never change in the lifetime of the port.
  345. */
  346. CarlaEngineAudioPort(const CarlaEngine& engine, const bool isInput);
  347. /*!
  348. * The destructor.
  349. */
  350. virtual ~CarlaEngineAudioPort() override;
  351. /*!
  352. * Get the type of the port, in this case kEnginePortTypeAudio.
  353. */
  354. EnginePortType getType() const noexcept override
  355. {
  356. return kEnginePortTypeAudio;
  357. }
  358. /*!
  359. * Initialize the port's internal buffer.
  360. */
  361. virtual void initBuffer() override;
  362. /*!
  363. * Direct access to the port's audio buffer.
  364. */
  365. float* getBuffer() const noexcept
  366. {
  367. return fBuffer;
  368. }
  369. #ifndef DOXYGEN
  370. protected:
  371. float* fBuffer;
  372. CARLA_DECLARE_NON_COPY_CLASS(CarlaEngineAudioPort)
  373. #endif
  374. };
  375. /*!
  376. * Carla Engine CV port.
  377. */
  378. class CarlaEngineCVPort : public CarlaEnginePort
  379. {
  380. public:
  381. /*!
  382. * The constructor.\n
  383. * All constructor parameters are constant and will never change in the lifetime of the port.
  384. */
  385. CarlaEngineCVPort(const CarlaEngine& engine, const bool isInput);
  386. /*!
  387. * The destructor.
  388. */
  389. virtual ~CarlaEngineCVPort() override;
  390. /*!
  391. * Get the type of the port, in this case kEnginePortTypeCV.
  392. */
  393. EnginePortType getType() const noexcept override
  394. {
  395. return kEnginePortTypeCV;
  396. }
  397. /*!
  398. * Initialize the port's internal buffer for \a engine.
  399. */
  400. virtual void initBuffer() override;
  401. /*!
  402. * Set a new buffer size.
  403. */
  404. void setBufferSize(const uint32_t bufferSize);
  405. #if 0
  406. // TESTING: I should remove this
  407. /*!
  408. * Write buffer back into the engine.
  409. */
  410. virtual void writeBuffer(const uint32_t frames, const uint32_t timeOffset);
  411. #endif
  412. /*!
  413. * Direct access to the port's buffer.
  414. */
  415. float* getBuffer() const noexcept
  416. {
  417. return fBuffer;
  418. }
  419. #ifndef DOXYGEN
  420. protected:
  421. float* fBuffer;
  422. const EngineProcessMode fProcessMode;
  423. CARLA_DECLARE_NON_COPY_CLASS(CarlaEngineCVPort)
  424. #endif
  425. };
  426. /*!
  427. * Carla Engine Event port.
  428. */
  429. class CarlaEngineEventPort : public CarlaEnginePort
  430. {
  431. public:
  432. /*!
  433. * The constructor.\n
  434. * All constructor parameters are constant and will never change in the lifetime of the port.
  435. */
  436. CarlaEngineEventPort(const CarlaEngine& engine, const bool isInput);
  437. /*!
  438. * The destructor.
  439. */
  440. virtual ~CarlaEngineEventPort() override;
  441. /*!
  442. * Get the type of the port, in this case kEnginePortTypeEvent.
  443. */
  444. EnginePortType getType() const noexcept override
  445. {
  446. return kEnginePortTypeEvent;
  447. }
  448. /*!
  449. * Initialize the port's internal buffer for \a engine.
  450. */
  451. virtual void initBuffer() override;
  452. /*!
  453. * Get the number of events present in the buffer.
  454. * \note You must only call this for input ports.
  455. */
  456. virtual uint32_t getEventCount() const;
  457. /*!
  458. * Get the event at \a index.
  459. * \note You must only call this for input ports.
  460. */
  461. virtual const EngineEvent& getEvent(const uint32_t index);
  462. /*!
  463. * Get the event at \a index, faster unchecked version.
  464. */
  465. virtual const EngineEvent& getEventUnchecked(const uint32_t index);
  466. /*!
  467. * Write a control event into the buffer.\n
  468. * Arguments are the same as in the EngineControlEvent struct.
  469. * \note You must only call this for output ports.
  470. */
  471. virtual bool writeControlEvent(const uint32_t time, const uint8_t channel, const EngineControlEventType type, const uint16_t param, const float value = 0.0f);
  472. /*!
  473. * Write a control event into the buffer, overloaded call.
  474. */
  475. bool writeControlEvent(const uint32_t time, const uint8_t channel, const EngineControlEvent& ctrl)
  476. {
  477. return writeControlEvent(time, channel, ctrl.type, ctrl.param, ctrl.value);
  478. }
  479. /*!
  480. * Write a MIDI event into the buffer.\n
  481. * Arguments are the same as in the EngineMidiEvent struct.
  482. * \note You must only call this for output ports.
  483. */
  484. virtual bool writeMidiEvent(const uint32_t time, const uint8_t channel, const uint8_t port, const uint8_t size, const uint8_t* const data);
  485. /*!
  486. * Write a MIDI event into the buffer, overloaded call.
  487. */
  488. bool writeMidiEvent(const uint32_t time, const uint8_t size, const uint8_t* const data)
  489. {
  490. return writeMidiEvent(time, MIDI_GET_CHANNEL_FROM_DATA(data), 0, size, data);
  491. }
  492. /*!
  493. * Write a MIDI event into the buffer, overloaded call.
  494. */
  495. bool writeMidiEvent(const uint32_t time, const uint8_t channel, const EngineMidiEvent& midi)
  496. {
  497. return writeMidiEvent(time, channel, midi.port, midi.size, midi.data);
  498. }
  499. #ifndef DOXYGEN
  500. protected:
  501. EngineEvent* fBuffer;
  502. const EngineProcessMode fProcessMode;
  503. CARLA_DECLARE_NON_COPY_CLASS(CarlaEngineEventPort)
  504. #endif
  505. };
  506. // -----------------------------------------------------------------------
  507. /*!
  508. * Carla Engine client.\n
  509. * Each plugin requires one client from the engine (created via CarlaEngine::addClient()).\n
  510. * \note This is a virtual class, some engine types provide custom funtionality.
  511. */
  512. class CarlaEngineClient
  513. {
  514. public:
  515. /*!
  516. * The constructor, protected.\n
  517. * All constructor parameters are constant and will never change in the lifetime of the client.\n
  518. * Client starts in deactivated state.
  519. */
  520. CarlaEngineClient(const CarlaEngine& engine);
  521. /*!
  522. * The destructor.
  523. */
  524. virtual ~CarlaEngineClient();
  525. /*!
  526. * Activate this client.\n
  527. * Client must be deactivated before calling this function.
  528. */
  529. virtual void activate();
  530. /*!
  531. * Deactivate this client.\n
  532. * Client must be activated before calling this function.
  533. */
  534. virtual void deactivate();
  535. /*!
  536. * Check if the client is activated.
  537. */
  538. virtual bool isActive() const noexcept;
  539. /*!
  540. * Check if the client is ok.\n
  541. * Plugins will refuse to instantiate if this returns false.
  542. * \note This is always true in rack and patchbay processing modes.
  543. */
  544. virtual bool isOk() const noexcept;
  545. /*!
  546. * Get the current latency, in samples.
  547. */
  548. virtual uint32_t getLatency() const noexcept;
  549. /*!
  550. * Change the client's latency.
  551. */
  552. virtual void setLatency(const uint32_t samples) noexcept;
  553. /*!
  554. * Add a new port of type \a portType.
  555. * \note This function does nothing in rack processing mode since ports are static there (2 audio + 1 event for both input and output).
  556. */
  557. virtual CarlaEnginePort* addPort(const EnginePortType portType, const char* const name, const bool isInput);
  558. #ifndef DOXYGEN
  559. protected:
  560. const CarlaEngine& fEngine;
  561. bool fActive;
  562. uint32_t fLatency;
  563. CARLA_DECLARE_NON_COPY_CLASS(CarlaEngineClient)
  564. #endif
  565. };
  566. // -----------------------------------------------------------------------
  567. /*!
  568. * Protected data used in CarlaEngine and subclasses.\n
  569. * Non-engine code MUST NEVER have direct access to this.
  570. */
  571. struct CarlaEngineProtectedData;
  572. /*!
  573. * Carla Engine.
  574. * \note This is a virtual class for all available engine types available in Carla.
  575. */
  576. class CarlaEngine
  577. {
  578. protected:
  579. /*!
  580. * The constructor, protected.\n
  581. * \note This only initializes engine data, it doesn't start the engine (audio).
  582. */
  583. CarlaEngine();
  584. public:
  585. /*!
  586. * The decontructor.
  587. * The engine must have been closed before this happens.
  588. */
  589. virtual ~CarlaEngine();
  590. // -------------------------------------------------------------------
  591. // Static calls
  592. /*!
  593. * Get the number of available engine drivers.
  594. */
  595. static unsigned int getDriverCount();
  596. /*!
  597. * Get the name of the engine driver at \a index.
  598. */
  599. static const char* getDriverName(const unsigned int index);
  600. /*!
  601. * Get the device names of driver at \a index.
  602. */
  603. static const char* const* getDriverDeviceNames(const unsigned int index);
  604. /*!
  605. * Get the device names of driver at \a index.
  606. */
  607. static const EngineDriverDeviceInfo* getDriverDeviceInfo(const unsigned int index, const char* const driverName);
  608. /*!
  609. * Create a new engine, using driver \a driverName. \n
  610. * Returned variable must be deleted when no longer needed.
  611. * \note This only initializes engine data, it doesn't initialize the engine itself.
  612. */
  613. static CarlaEngine* newDriverByName(const char* const driverName);
  614. // -------------------------------------------------------------------
  615. // Constant values
  616. /*!
  617. * Maximum client name size.
  618. */
  619. virtual unsigned int getMaxClientNameSize() const noexcept;
  620. /*!
  621. * Maximum port name size.
  622. */
  623. virtual unsigned int getMaxPortNameSize() const noexcept;
  624. /*!
  625. * Current number of plugins loaded.
  626. */
  627. unsigned int getCurrentPluginCount() const noexcept;
  628. /*!
  629. * Maximum number of loadable plugins allowed.
  630. * \note This function returns 0 if engine is not started.
  631. */
  632. unsigned int getMaxPluginNumber() const noexcept;
  633. // -------------------------------------------------------------------
  634. // Virtual, per-engine type calls
  635. /*!
  636. * Initialize engine, using \a clientName.
  637. */
  638. virtual bool init(const char* const clientName);
  639. /*!
  640. * Close engine.
  641. */
  642. virtual bool close();
  643. /*!
  644. * Idle engine.
  645. */
  646. virtual void idle();
  647. /*!
  648. * Check if engine is running.
  649. */
  650. virtual bool isRunning() const noexcept = 0;
  651. /*!
  652. * Check if engine is running offline (aka freewheel mode).
  653. */
  654. virtual bool isOffline() const noexcept = 0;
  655. /*!
  656. * Get engine type.
  657. */
  658. virtual EngineType getType() const noexcept = 0;
  659. /*!
  660. * Get the currently used driver name.
  661. */
  662. virtual const char* getCurrentDriverName() const noexcept = 0;
  663. /*!
  664. * Add new engine client.
  665. * \note This function must only be called within a plugin class.
  666. */
  667. virtual CarlaEngineClient* addClient(CarlaPlugin* const plugin);
  668. // -------------------------------------------------------------------
  669. // Plugin management
  670. /*!
  671. * Add new plugin.
  672. */
  673. 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);
  674. /*!
  675. * Add new plugin, using native binary type.
  676. */
  677. bool addPlugin(const PluginType ptype, const char* const filename, const char* const name, const char* const label, const void* const extra = nullptr)
  678. {
  679. return addPlugin(BINARY_NATIVE, ptype, filename, name, label, extra);
  680. }
  681. /*!
  682. * Remove plugin with id \a id.
  683. */
  684. bool removePlugin(const unsigned int id);
  685. /*!
  686. * Remove all plugins.
  687. */
  688. bool removeAllPlugins();
  689. /*!
  690. * Rename plugin with id \a id to \a newName.\n
  691. * Returns the new name, or nullptr if the operation failed.
  692. */
  693. virtual const char* renamePlugin(const unsigned int id, const char* const newName);
  694. /*!
  695. * Clone plugin with id \a id.
  696. */
  697. bool clonePlugin(const unsigned int id);
  698. /*!
  699. * Prepare replace of plugin with id \a id.\n
  700. * The next call to addPlugin() will use this id, replacing the selected plugin.
  701. * \note This function requires addPlugin() to be called afterwards, as soon as possible.
  702. */
  703. bool replacePlugin(const unsigned int id);
  704. /*!
  705. * Switch plugins with id \a idA and \a idB.
  706. */
  707. bool switchPlugins(const unsigned int idA, const unsigned int idB);
  708. /*!
  709. * Get plugin with id \a id.
  710. */
  711. CarlaPlugin* getPlugin(const unsigned int id) const;
  712. /*!
  713. * Get plugin with id \a id, faster unchecked version.
  714. */
  715. CarlaPlugin* getPluginUnchecked(const unsigned int id) const noexcept;
  716. /*!
  717. * Get a unique plugin name within the engine.\n
  718. * Returned variable must be deleted if non-NULL.
  719. */
  720. const char* getUniquePluginName(const char* const name) const;
  721. // -------------------------------------------------------------------
  722. // Project management
  723. /*!
  724. * Load a file of any type.\n
  725. * This will try to load a generic file as a plugin,
  726. * either by direct handling (GIG, SF2 and SFZ) or by using an internal plugin (like Audio and MIDI).
  727. */
  728. bool loadFile(const char* const filename);
  729. /*!
  730. * Load a project file.
  731. * @note Already loaded plugins are not removed; call removeAllPlugins() first if needed.
  732. */
  733. bool loadProject(const char* const filename);
  734. /*!
  735. * Save current project to a file.
  736. */
  737. bool saveProject(const char* const filename);
  738. // -------------------------------------------------------------------
  739. // Information (base)
  740. /*!
  741. * Get the current engine driver hints.
  742. */
  743. unsigned int getHints() const noexcept;
  744. /*!
  745. * Get the current buffer size.
  746. */
  747. uint32_t getBufferSize() const noexcept;
  748. /*!
  749. * Get the current sample rate.
  750. */
  751. double getSampleRate() const noexcept;
  752. /*!
  753. * Get the current engine name.
  754. */
  755. const char* getName() const noexcept;
  756. /*!
  757. * Get the current engine proccess mode.
  758. */
  759. EngineProcessMode getProccessMode() const noexcept;
  760. /*!
  761. * Get the current engine options (read-only).
  762. */
  763. const EngineOptions& getOptions() const noexcept;
  764. /*!
  765. * Get the current Time information (read-only).
  766. */
  767. const EngineTimeInfo& getTimeInfo() const noexcept;
  768. // -------------------------------------------------------------------
  769. // Information (peaks)
  770. /*!
  771. * TODO.
  772. * \a id must be either 1 or 2.
  773. */
  774. float getInputPeak(const unsigned int pluginId, const bool isLeft) const;
  775. /*!
  776. * TODO.
  777. * \a id must be either 1 or 2.
  778. */
  779. float getOutputPeak(const unsigned int pluginId, const bool isLeft) const;
  780. // -------------------------------------------------------------------
  781. // Callback
  782. /*!
  783. * TODO.
  784. */
  785. void callback(const EngineCallbackOpcode action, const unsigned int pluginId, const int value1, const int value2, const float value3, const char* const valueStr);
  786. /*!
  787. * TODO.
  788. */
  789. void setCallback(const EngineCallbackFunc func, void* const ptr);
  790. // -------------------------------------------------------------------
  791. // Patchbay
  792. /*!
  793. * Connect patchbay ports \a portA and \a portB.
  794. */
  795. virtual bool patchbayConnect(int portA, int portB);
  796. /*!
  797. * Disconnect patchbay connection \a connectionId.
  798. */
  799. virtual bool patchbayDisconnect(int connectionId);
  800. /*!
  801. * Force the engine to resend all patchbay clients, ports and connections again.
  802. */
  803. virtual bool patchbayRefresh();
  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. #ifndef BUILD_BRIDGE
  918. /*!
  919. * Proccess audio buffer in rack mode.
  920. * \note RT call
  921. */
  922. void processRack(float* inBuf[2], float* outBuf[2], const uint32_t frames);
  923. /*!
  924. * Proccess audio buffer in patchbay mode.
  925. * In \a bufCount, [0]=inBufCount and [1]=outBufCount
  926. * \note RT call
  927. */
  928. void processPatchbay(float** inBuf, float** outBuf, const uint32_t bufCount[2], const uint32_t frames);
  929. #endif
  930. // -------------------------------------------------------------------
  931. // Engine initializers
  932. #ifdef BUILD_BRIDGE
  933. public:
  934. static CarlaEngine* newBridge(const char* const audioBaseName, const char* const controlBaseName);
  935. #endif
  936. private:
  937. static CarlaEngine* newJack();
  938. #ifndef BUILD_BRIDGE
  939. enum AudioApi {
  940. AUDIO_API_NULL = 0,
  941. // common
  942. AUDIO_API_JACK = 1,
  943. // linux
  944. AUDIO_API_ALSA = 2,
  945. AUDIO_API_OSS = 3,
  946. AUDIO_API_PULSE = 4,
  947. // macos
  948. AUDIO_API_CORE = 5,
  949. // windows
  950. AUDIO_API_ASIO = 6,
  951. AUDIO_API_DS = 7
  952. };
  953. static CarlaEngine* newRtAudio(const AudioApi api);
  954. static unsigned int getRtAudioApiCount();
  955. static const char* getRtAudioApiName(const unsigned int index);
  956. static const char* const* getRtAudioApiDeviceNames(const unsigned int index);
  957. static const EngineDriverDeviceInfo* getRtAudioDeviceInfo(const unsigned int index, const char* const deviceName);
  958. # ifdef HAVE_JUCE
  959. static CarlaEngine* newJuce(const AudioApi api);
  960. static unsigned int getJuceApiCount();
  961. static const char* getJuceApiName(const unsigned int index);
  962. static const char* const* getJuceApiDeviceNames(const unsigned int index);
  963. static const EngineDriverDeviceInfo* getJuceDeviceInfo(const unsigned int index, const char* const deviceName);
  964. # endif
  965. #endif
  966. // -------------------------------------------------------------------
  967. // Bridge/Controller OSC stuff
  968. public:
  969. #ifdef BUILD_BRIDGE
  970. void oscSend_bridge_plugin_info1(const PluginCategory category, const uint hints, const long uniqueId) const;
  971. void oscSend_bridge_plugin_info2(const char* const realName, const char* const label, const char* const maker, const char* const copyright) const;
  972. void oscSend_bridge_audio_count(const uint32_t ins, const uint32_t outs) const;
  973. void oscSend_bridge_midi_count(const uint32_t ins, const uint32_t outs) const;
  974. void oscSend_bridge_parameter_count(const uint32_t ins, const uint32_t outs) const;
  975. void oscSend_bridge_program_count(const uint32_t count) const;
  976. void oscSend_bridge_midi_program_count(const uint32_t count) const;
  977. 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;
  978. void oscSend_bridge_parameter_ranges1(const uint32_t index, const float def, const float min, const float max) const;
  979. void oscSend_bridge_parameter_ranges2(const uint32_t index, const float step, const float stepSmall, const float stepLarge) const;
  980. void oscSend_bridge_parameter_midi_cc(const uint32_t index, const int16_t cc) const;
  981. void oscSend_bridge_parameter_midi_channel(const uint32_t index, const uint8_t channel) const;
  982. void oscSend_bridge_parameter_value(const int32_t index, const float value) const; // may be used for internal params (< 0)
  983. void oscSend_bridge_default_value(const uint32_t index, const float value) const;
  984. void oscSend_bridge_current_program(const int32_t index) const;
  985. void oscSend_bridge_current_midi_program(const int32_t index) const;
  986. void oscSend_bridge_program_name(const uint32_t index, const char* const name) const;
  987. void oscSend_bridge_midi_program_data(const uint32_t index, const uint32_t bank, const uint32_t program, const char* const name) const;
  988. void oscSend_bridge_configure(const char* const key, const char* const value) const;
  989. void oscSend_bridge_set_custom_data(const char* const type, const char* const key, const char* const value) const;
  990. void oscSend_bridge_set_chunk_data(const char* const chunkFile) const;
  991. void oscSend_bridge_set_peaks() const;
  992. #else
  993. void oscSend_control_add_plugin_start(const uint pluginId, const char* const pluginName) const;
  994. void oscSend_control_add_plugin_end(const uint pluginId) const;
  995. void oscSend_control_remove_plugin(const uint pluginId) const;
  996. void oscSend_control_set_plugin_info1(const uint pluginId, const PluginType type, const PluginCategory category, const uint hints, const long uniqueId) const;
  997. 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;
  998. void oscSend_control_set_audio_count(const uint pluginId, const uint32_t ins, const uint32_t outs) const;
  999. void oscSend_control_set_midi_count(const uint pluginId, const uint32_t ins, const uint32_t outs) const;
  1000. void oscSend_control_set_parameter_count(const uint pluginId, const uint32_t ins, const uint32_t outs) const;
  1001. void oscSend_control_set_program_count(const uint pluginId, const uint32_t count) const;
  1002. void oscSend_control_set_midi_program_count(const uint pluginId, const uint32_t count) const;
  1003. 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;
  1004. void oscSend_control_set_parameter_ranges1(const uint pluginId, const uint32_t index, const float def, const float min, const float max) const;
  1005. void oscSend_control_set_parameter_ranges2(const uint pluginId, const uint32_t index, const float step, const float stepSmall, const float stepLarge) const;
  1006. void oscSend_control_set_parameter_midi_cc(const uint pluginId, const uint32_t index, const int16_t cc) const;
  1007. void oscSend_control_set_parameter_midi_channel(const uint pluginId, const uint32_t index, const uint8_t channel) const;
  1008. void oscSend_control_set_parameter_value(const uint pluginId, const int32_t index, const float value) const; // may be used for internal params (< 0)
  1009. void oscSend_control_set_default_value(const uint pluginId, const uint32_t index, const float value) const;
  1010. void oscSend_control_set_current_program(const uint pluginId, const int32_t index) const;
  1011. void oscSend_control_set_current_midi_program(const uint pluginId, const int32_t index) const;
  1012. void oscSend_control_set_program_name(const uint pluginId, const uint32_t index, const char* const name) const;
  1013. 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;
  1014. void oscSend_control_note_on(const uint pluginId, const uint8_t channel, const uint8_t note, const uint8_t velo) const;
  1015. void oscSend_control_note_off(const uint pluginId, const uint8_t channel, const uint8_t note) const;
  1016. void oscSend_control_set_peaks(const uint pluginId) const;
  1017. void oscSend_control_exit() const;
  1018. #endif
  1019. CARLA_DECLARE_NON_COPY_CLASS(CarlaEngine)
  1020. };
  1021. /**@}*/
  1022. CARLA_BACKEND_END_NAMESPACE
  1023. #endif // CARLA_ENGINE_HPP_INCLUDED