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