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.

1239 lines
33KB

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