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.

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