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.

916 lines
27KB

  1. /*
  2. * Carla Plugin Host
  3. * Copyright (C) 2011-2014 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_PLUGIN_HPP_INCLUDED
  18. #define CARLA_PLUGIN_HPP_INCLUDED
  19. #include "CarlaBackend.h"
  20. // -----------------------------------------------------------------------
  21. // Avoid including extra libs here
  22. typedef void* lo_address;
  23. typedef struct _NativePluginDescriptor NativePluginDescriptor;
  24. struct LADSPA_RDF_Descriptor;
  25. // -----------------------------------------------------------------------
  26. CARLA_BACKEND_START_NAMESPACE
  27. #if 0
  28. } /* Fix editor indentation */
  29. #endif
  30. // -----------------------------------------------------------------------
  31. /*!
  32. * @defgroup CarlaPluginAPI Carla Plugin API
  33. *
  34. * The Carla Plugin API.
  35. * @{
  36. */
  37. class CarlaEngineAudioPort;
  38. /*!
  39. * Save state data.
  40. */
  41. struct SaveState;
  42. /*!
  43. * Protected data used in CarlaPlugin and subclasses.\n
  44. * Non-plugin code MUST NEVER have direct access to this.
  45. */
  46. struct CarlaPluginProtectedData;
  47. // -----------------------------------------------------------------------
  48. /*!
  49. * Carla Backend base plugin class
  50. *
  51. * This is the base class for all available plugin types available in Carla Backend.\n
  52. * All virtual calls are implemented in this class as fallback (except reload and process),\n
  53. * so it's safe to only override needed calls.
  54. *
  55. * \see PluginType
  56. */
  57. class CarlaPlugin
  58. {
  59. protected:
  60. /*!
  61. * This is the constructor of the base plugin class.
  62. *
  63. * \param engine The engine which this plugin belongs to, must not be null
  64. * \param id The 'id' of this plugin, must be between 0 and CarlaEngine::maxPluginNumber()
  65. */
  66. CarlaPlugin(CarlaEngine* const engine, const unsigned int id);
  67. public:
  68. /*!
  69. * This is the destructor of the base plugin class.
  70. */
  71. virtual ~CarlaPlugin();
  72. // -------------------------------------------------------------------
  73. // Information (base)
  74. /*!
  75. * Get the plugin's type (a subclass of CarlaPlugin).
  76. *
  77. * \note Plugin bridges will return their respective plugin type, there is no plugin type such as "bridge".\n
  78. * To check if a plugin is a bridge use:
  79. * \code
  80. * if (getHints() & PLUGIN_IS_BRIDGE)
  81. * ...
  82. * \endcode
  83. */
  84. virtual PluginType getType() const noexcept = 0;
  85. /*!
  86. * Get the plugin's id (as passed in the constructor).
  87. *
  88. * \see setId()
  89. */
  90. unsigned int getId() const noexcept;
  91. /*!
  92. * Get the plugin's hints.
  93. *
  94. * \see PluginHints
  95. */
  96. unsigned int getHints() const noexcept;
  97. /*!
  98. * Get the plugin's options (currently in use).
  99. *
  100. * \see PluginOptions, getAvailableOptions() and setOption()
  101. */
  102. unsigned int getOptionsEnabled() const noexcept;
  103. /*!
  104. * Check if the plugin is enabled.\n
  105. * When a plugin is disabled, it will never be processed or managed in any way.
  106. *
  107. * \see setEnabled()
  108. */
  109. bool isEnabled() const noexcept;
  110. /*!
  111. * Get the plugin's internal name.\n
  112. * This name is unique within all plugins in an engine.
  113. *
  114. * \see getRealName() and setName()
  115. */
  116. const char* getName() const noexcept;
  117. /*!
  118. * Get the currently loaded DLL filename for this plugin.\n
  119. * (Sound kits return their exact filename).
  120. */
  121. const char* getFilename() const noexcept;
  122. /*!
  123. * Get the plugins's icon name.
  124. */
  125. const char* getIconName() const noexcept;
  126. /*!
  127. * Get the plugin's category (delay, filter, synth, etc).
  128. */
  129. virtual PluginCategory getCategory() const noexcept;
  130. /*!
  131. * Get the plugin's native unique Id.\n
  132. * May return 0 on plugin types that don't support Ids.
  133. */
  134. virtual int64_t getUniqueId() const noexcept;
  135. /*!
  136. * Get the plugin's latency, in sample frames.
  137. */
  138. uint32_t getLatencyInFrames() const noexcept;
  139. // -------------------------------------------------------------------
  140. // Information (count)
  141. /*!
  142. * Get the number of audio inputs.
  143. */
  144. uint32_t getAudioInCount() const noexcept;
  145. /*!
  146. * Get the number of audio outputs.
  147. */
  148. uint32_t getAudioOutCount() const noexcept;
  149. /*!
  150. * Get the number of MIDI inputs.
  151. */
  152. virtual uint32_t getMidiInCount() const noexcept;
  153. /*!
  154. * Get the number of MIDI outputs.
  155. */
  156. virtual uint32_t getMidiOutCount() const noexcept;
  157. /*!
  158. * Get the number of parameters.\n
  159. * To know the number of parameter inputs and outputs separately use getParameterCountInfo() instead.
  160. */
  161. uint32_t getParameterCount() const noexcept;
  162. /*!
  163. * Get the number of scalepoints for parameter \a parameterId.
  164. */
  165. virtual uint32_t getParameterScalePointCount(const uint32_t parameterId) const noexcept;
  166. /*!
  167. * Get the number of programs.
  168. */
  169. uint32_t getProgramCount() const noexcept;
  170. /*!
  171. * Get the number of MIDI programs.
  172. */
  173. uint32_t getMidiProgramCount() const noexcept;
  174. /*!
  175. * Get the number of custom data sets.
  176. */
  177. uint32_t getCustomDataCount() const noexcept;
  178. // -------------------------------------------------------------------
  179. // Information (current data)
  180. /*!
  181. * Get the current program number (-1 if unset).
  182. *
  183. * \see setProgram()
  184. */
  185. int32_t getCurrentProgram() const noexcept;
  186. /*!
  187. * Get the current MIDI program number (-1 if unset).
  188. *
  189. * \see setMidiProgram()
  190. * \see setMidiProgramById()
  191. */
  192. int32_t getCurrentMidiProgram() const noexcept;
  193. /*!
  194. * Get the parameter data of \a parameterId.
  195. */
  196. const ParameterData& getParameterData(const uint32_t parameterId) const noexcept;
  197. /*!
  198. * Get the parameter ranges of \a parameterId.
  199. */
  200. const ParameterRanges& getParameterRanges(const uint32_t parameterId) const noexcept;
  201. /*!
  202. * Check if parameter \a parameterId is of output type.
  203. */
  204. bool isParameterOutput(const uint32_t parameterId) const noexcept;
  205. /*!
  206. * Get the MIDI program at \a index.
  207. *
  208. * \see getMidiProgramName()
  209. */
  210. const MidiProgramData& getMidiProgramData(const uint32_t index) const noexcept;
  211. /*!
  212. * Get the custom data set at \a index.
  213. *
  214. * \see getCustomDataCount() and setCustomData()
  215. */
  216. const CustomData& getCustomData(const uint32_t index) const noexcept;
  217. /*!
  218. * Get the complete plugin chunk data into \a dataPtr.
  219. *
  220. * \note Make sure to verify the plugin supports chunks before calling this function!
  221. * \return The size of the chunk or 0 if invalid.
  222. *
  223. * \see setChunkData()
  224. */
  225. virtual int32_t getChunkData(void** const dataPtr) const noexcept;
  226. // -------------------------------------------------------------------
  227. // Information (per-plugin data)
  228. /*!
  229. * Get the plugin available options.
  230. *
  231. * \see PluginOptions, getOptions() and setOption()
  232. */
  233. virtual unsigned int getOptionsAvailable() const noexcept;
  234. /*!
  235. * Get the current parameter value of \a parameterId.
  236. */
  237. virtual float getParameterValue(const uint32_t parameterId) const noexcept;
  238. /*!
  239. * Get the scalepoint \a scalePointId value of the parameter \a parameterId.
  240. */
  241. virtual float getParameterScalePointValue(const uint32_t parameterId, const uint32_t scalePointId) const noexcept;
  242. /*!
  243. * Get the plugin's label (URI for LV2 plugins).
  244. */
  245. virtual void getLabel(char* const strBuf) const noexcept;
  246. /*!
  247. * Get the plugin's maker.
  248. */
  249. virtual void getMaker(char* const strBuf) const noexcept;
  250. /*!
  251. * Get the plugin's copyright/license.
  252. */
  253. virtual void getCopyright(char* const strBuf) const noexcept;
  254. /*!
  255. * Get the plugin's (real) name.
  256. *
  257. * \see getName() and setName()
  258. */
  259. virtual void getRealName(char* const strBuf) const noexcept;
  260. /*!
  261. * Get the name of the parameter \a parameterId.
  262. */
  263. virtual void getParameterName(const uint32_t parameterId, char* const strBuf) const noexcept;
  264. /*!
  265. * Get the symbol of the parameter \a parameterId.
  266. */
  267. virtual void getParameterSymbol(const uint32_t parameterId, char* const strBuf) const noexcept;
  268. /*!
  269. * Get the custom text of the parameter \a parameterId.
  270. */
  271. virtual void getParameterText(const uint32_t parameterId, char* const strBuf) const noexcept;
  272. /*!
  273. * Get the unit of the parameter \a parameterId.
  274. */
  275. virtual void getParameterUnit(const uint32_t parameterId, char* const strBuf) const noexcept;
  276. /*!
  277. * Get the scalepoint \a scalePointId label of the parameter \a parameterId.
  278. */
  279. virtual void getParameterScalePointLabel(const uint32_t parameterId, const uint32_t scalePointId, char* const strBuf) const noexcept;
  280. /*!
  281. * Get the name of the program at \a index.
  282. */
  283. void getProgramName(const uint32_t index, char* const strBuf) const noexcept;
  284. /*!
  285. * Get the name of the MIDI program at \a index.
  286. *
  287. * \see getMidiProgramInfo()
  288. */
  289. void getMidiProgramName(const uint32_t index, char* const strBuf) const noexcept;
  290. /*!
  291. * Get information about the plugin's parameter count.\n
  292. * This is used to check how many input, output and total parameters are available.\n
  293. *
  294. * \note Some parameters might not be input or output (ie, invalid).
  295. *
  296. * \see getParameterCount()
  297. */
  298. void getParameterCountInfo(uint32_t& ins, uint32_t& outs) const noexcept;
  299. // -------------------------------------------------------------------
  300. // Set data (state)
  301. /*!
  302. * Tell the plugin to prepare for save.
  303. */
  304. virtual void prepareForSave();
  305. /*!
  306. * Get the plugin's save state.\n
  307. * The plugin will automatically call prepareForSave() as needed.
  308. *
  309. * \see loadSaveState()
  310. */
  311. const SaveState& getSaveState();
  312. /*!
  313. * Get the plugin's save state.
  314. *
  315. * \see getSaveState()
  316. */
  317. void loadSaveState(const SaveState& saveState);
  318. /*!
  319. * Save the current plugin state to \a filename.
  320. *
  321. * \see loadStateFromFile()
  322. */
  323. bool saveStateToFile(const char* const filename);
  324. /*!
  325. * Save the plugin state from \a filename.
  326. *
  327. * \see saveStateToFile()
  328. */
  329. bool loadStateFromFile(const char* const filename);
  330. // -------------------------------------------------------------------
  331. // Set data (internal stuff)
  332. /*!
  333. * Set the plugin's id to \a newId.
  334. *
  335. * \see getId()
  336. */
  337. void setId(const unsigned int newId) noexcept;
  338. /*!
  339. * Set the plugin's name to \a newName.
  340. *
  341. * \see getName() and getRealName()
  342. */
  343. virtual void setName(const char* const newName);
  344. /*!
  345. * Set a plugin's option.
  346. *
  347. * \see getOptions() and getAvailableOptions()
  348. */
  349. void setOption(const unsigned int option, const bool yesNo);
  350. /*!
  351. * Enable or disable the plugin according to \a yesNo. \n
  352. * When a plugin is disabled, it will never be processed or managed in any way.
  353. *
  354. * \see isEnabled()
  355. */
  356. void setEnabled(const bool yesNo) noexcept;
  357. /*!
  358. * Set plugin as active according to \a active.
  359. *
  360. * \param sendOsc Send message change over OSC
  361. * \param sendCallback Send message change to registered callback
  362. */
  363. void setActive(const bool active, const bool sendOsc, const bool sendCallback) noexcept;
  364. #ifndef BUILD_BRIDGE
  365. /*!
  366. * Set the plugin's dry/wet signal value to \a value.\n
  367. * \a value must be between 0.0 and 1.0.
  368. *
  369. * \param sendOsc Send message change over OSC
  370. * \param sendCallback Send message change to registered callback
  371. */
  372. void setDryWet(const float value, const bool sendOsc, const bool sendCallback) noexcept;
  373. /*!
  374. * Set the plugin's output volume to \a value.\n
  375. * \a value must be between 0.0 and 1.27.
  376. *
  377. * \param sendOsc Send message change over OSC
  378. * \param sendCallback Send message change to registered callback
  379. */
  380. void setVolume(const float value, const bool sendOsc, const bool sendCallback) noexcept;
  381. /*!
  382. * Set the plugin's output left balance value to \a value.\n
  383. * \a value must be between -1.0 and 1.0.
  384. *
  385. * \param sendOsc Send message change over OSC
  386. * \param sendCallback Send message change to registered callback
  387. *
  388. * \note Pure-Stereo plugins only!
  389. */
  390. void setBalanceLeft(const float value, const bool sendOsc, const bool sendCallback) noexcept;
  391. /*!
  392. * Set the plugin's output right balance value to \a value.\n
  393. * \a value must be between -1.0 and 1.0.
  394. *
  395. * \param sendOsc Send message change over OSC
  396. * \param sendCallback Send message change to registered callback
  397. *
  398. * \note Pure-Stereo plugins only!
  399. */
  400. void setBalanceRight(const float value, const bool sendOsc, const bool sendCallback) noexcept;
  401. /*!
  402. * Set the plugin's output panning value to \a value.\n
  403. * \a value must be between -1.0 and 1.0.
  404. *
  405. * \param sendOsc Send message change over OSC
  406. * \param sendCallback Send message change to registered callback
  407. *
  408. * \note Force-Stereo plugins only!
  409. */
  410. void setPanning(const float value, const bool sendOsc, const bool sendCallback) noexcept;
  411. #endif
  412. /*!
  413. * Set the plugin's midi control channel.
  414. *
  415. * \param sendOsc Send message change over OSC
  416. * \param sendCallback Send message change to registered callback
  417. */
  418. virtual void setCtrlChannel(const int8_t channel, const bool sendOsc, const bool sendCallback) noexcept;
  419. // -------------------------------------------------------------------
  420. // Set data (plugin-specific stuff)
  421. /*!
  422. * Set a plugin's parameter value.
  423. *
  424. * \param parameterId The parameter to change
  425. * \param value The new parameter value, must be within the parameter's range
  426. * \param sendGui Send message change to plugin's custom GUI, if any
  427. * \param sendOsc Send message change over OSC
  428. * \param sendCallback Send message change to registered callback
  429. *
  430. * \see getParameterValue()
  431. */
  432. virtual void setParameterValue(const uint32_t parameterId, const float value, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept;
  433. /*!
  434. * Set a plugin's parameter value, including internal parameters.\n
  435. * \a rindex can be negative to allow internal parameters change (as defined in InternalParametersIndex).
  436. *
  437. * \see setParameterValue()
  438. * \see setActive()
  439. * \see setDryWet()
  440. * \see setVolume()
  441. * \see setBalanceLeft()
  442. * \see setBalanceRight()
  443. */
  444. void setParameterValueByRealIndex(const int32_t rindex, const float value, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept;
  445. /*!
  446. * Set parameter's \a parameterId MIDI channel to \a channel.\n
  447. * \a channel must be between 0 and 15.
  448. */
  449. void setParameterMidiChannel(const uint32_t parameterId, uint8_t channel, const bool sendOsc, const bool sendCallback) noexcept;
  450. /*!
  451. * Set parameter's \a parameterId MIDI CC to \a cc.\n
  452. * \a cc must be between 0 and 95 (0x5F), or -1 for invalid.
  453. */
  454. void setParameterMidiCC(const uint32_t parameterId, int16_t cc, const bool sendOsc, const bool sendCallback) noexcept;
  455. /*!
  456. * Add a custom data set.\n
  457. * If \a key already exists, its current value will be swapped with \a value.
  458. *
  459. * \param type Type of data used in \a value.
  460. * \param key A key identifing this data set.
  461. * \param value The value of the data set, of type \a type.
  462. * \param sendGui Send message change to plugin's custom GUI, if any
  463. *
  464. * \see getCustomDataCount() and getCustomData()
  465. */
  466. virtual void setCustomData(const char* const type, const char* const key, const char* const value, const bool sendGui);
  467. /*!
  468. * Set the complete chunk data as \a stringData.\n
  469. * \a stringData must a base64 encoded string of binary data.
  470. *
  471. * \see getChunkData()
  472. *
  473. * \note Make sure to verify the plugin supports chunks before calling this function!
  474. */
  475. virtual void setChunkData(const char* const stringData);
  476. /*!
  477. * Change the current plugin program to \a index.
  478. *
  479. * If \a index is negative the plugin's program will be considered unset.\n
  480. * The plugin's default parameter values will be updated when this function is called.
  481. *
  482. * \param index New program index to use
  483. * \param sendGui Send message change to plugin's custom GUI, if any
  484. * \param sendOsc Send message change over OSC
  485. * \param sendCallback Send message change to registered callback
  486. * \param block Block the audio callback
  487. */
  488. virtual void setProgram(const int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept;
  489. /*!
  490. * Change the current MIDI plugin program to \a index.
  491. *
  492. * If \a index is negative the plugin's program will be considered unset.\n
  493. * The plugin's default parameter values will be updated when this function is called.
  494. *
  495. * \param index New program index to use
  496. * \param sendGui Send message change to plugin's custom GUI, if any
  497. * \param sendOsc Send message change over OSC
  498. * \param sendCallback Send message change to registered callback
  499. * \param block Block the audio callback
  500. */
  501. virtual void setMidiProgram(const int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept;
  502. /*!
  503. * This is an overloaded call to setMidiProgram().\n
  504. * It changes the current MIDI program using \a bank and \a program values instead of index.
  505. */
  506. void setMidiProgramById(const uint32_t bank, const uint32_t program, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept;
  507. // -------------------------------------------------------------------
  508. // Set gui stuff
  509. /*!
  510. * Idle function.
  511. *
  512. * \note This function must be always called from the main thread.
  513. */
  514. virtual void idle();
  515. /*!
  516. * Show (or hide) the plugin's custom UI according to \a yesNo.
  517. *
  518. * \note This function must be always called from the main thread.
  519. */
  520. virtual void showCustomUI(const bool yesNo);
  521. // -------------------------------------------------------------------
  522. // Plugin state
  523. /*!
  524. * Reload the plugin's entire state (including programs).\n
  525. * The plugin will be disabled during this call.
  526. */
  527. virtual void reload() = 0;
  528. /*!
  529. * Reload the plugin's programs state.
  530. */
  531. virtual void reloadPrograms(const bool doInit);
  532. // -------------------------------------------------------------------
  533. // Plugin processing
  534. /*!
  535. * Plugin activate call.
  536. */
  537. virtual void activate() noexcept;
  538. /*!
  539. * Plugin activate call.
  540. */
  541. virtual void deactivate() noexcept;
  542. /*!
  543. * Plugin process call.
  544. */
  545. virtual void process(float** const inBuffer, float** const outBuffer, const uint32_t frames) = 0;
  546. /*!
  547. * Tell the plugin the current buffer size changed.
  548. */
  549. virtual void bufferSizeChanged(const uint32_t newBufferSize);
  550. /*!
  551. * Tell the plugin the current sample rate changed.
  552. */
  553. virtual void sampleRateChanged(const double newSampleRate);
  554. /*!
  555. * Tell the plugin the current offline mode changed.
  556. */
  557. virtual void offlineModeChanged(const bool isOffline);
  558. #if 0
  559. /*!
  560. * Lock the plugin's master mutex.
  561. */
  562. void lock();
  563. #endif
  564. /*!
  565. * Try to lock the plugin's master mutex.
  566. * @param forcedOffline When true, always locks and returns true
  567. */
  568. bool tryLock(const bool forcedOffline) noexcept;
  569. /*!
  570. * Unlock the plugin's master mutex.
  571. */
  572. void unlock() noexcept;
  573. // -------------------------------------------------------------------
  574. // Plugin buffers
  575. /*!
  576. * Initialize all RT buffers of the plugin.
  577. */
  578. virtual void initBuffers();
  579. /*!
  580. * Delete and clear all RT buffers.
  581. */
  582. virtual void clearBuffers();
  583. // -------------------------------------------------------------------
  584. // OSC stuff
  585. /*!
  586. * Register this plugin to the engine's OSC client (controller or bridge).
  587. */
  588. void registerToOscClient() noexcept;
  589. /*!
  590. * Update the plugin's internal OSC data according to \a source and \a url.\n
  591. * This is used for OSC-GUI bridges.
  592. */
  593. virtual void updateOscData(const lo_address& source, const char* const url);
  594. /*!
  595. * Free the plugin's internal OSC memory data.
  596. */
  597. //void freeOscData();
  598. /*!
  599. * Show the plugin's OSC based GUI.\n
  600. * This is a handy function that waits for the GUI to respond and automatically asks it to show itself.
  601. */
  602. bool waitForOscGuiShow();
  603. // -------------------------------------------------------------------
  604. // MIDI events
  605. #ifndef BUILD_BRIDGE
  606. /*!
  607. * Send a single midi note to be processed in the next audio callback.\n
  608. * A note with 0 velocity means note-off.
  609. * \note Non-RT call
  610. */
  611. void sendMidiSingleNote(const uint8_t channel, const uint8_t note, const uint8_t velo, const bool sendGui, const bool sendOsc, const bool sendCallback);
  612. #endif
  613. /*!
  614. * Send all midi notes off to the host callback.\n
  615. * This doesn't send the actual MIDI All-Notes-Off event, but 128 note-offs instead (IFF ctrlChannel is valid).
  616. * \note RT call
  617. */
  618. void sendMidiAllNotesOffToCallback();
  619. // -------------------------------------------------------------------
  620. // Post-poned events
  621. /*!
  622. * Process all the post-poned events.
  623. * This function must be called from the main thread (ie, idle()) if PLUGIN_USES_SINGLE_THREAD is set.
  624. */
  625. void postRtEventsRun();
  626. // -------------------------------------------------------------------
  627. // Post-poned UI Stuff
  628. /*!
  629. * Tell the UI a parameter has changed.
  630. */
  631. virtual void uiParameterChange(const uint32_t index, const float value) noexcept;
  632. /*!
  633. * Tell the UI the current program has changed.
  634. */
  635. virtual void uiProgramChange(const uint32_t index) noexcept;
  636. /*!
  637. * Tell the UI the current midi program has changed.
  638. */
  639. virtual void uiMidiProgramChange(const uint32_t index) noexcept;
  640. /*!
  641. * Tell the UI a note has been pressed.
  642. */
  643. virtual void uiNoteOn(const uint8_t channel, const uint8_t note, const uint8_t velo) noexcept;
  644. /*!
  645. * Tell the UI a note has been released.
  646. */
  647. virtual void uiNoteOff(const uint8_t channel, const uint8_t note) noexcept;
  648. // -------------------------------------------------------------------
  649. // Helper functions
  650. /*!
  651. * Check if the plugin can run in rack mode.
  652. */
  653. bool canRunInRack() const noexcept;
  654. /*!
  655. * Get the plugin's engine, as passed in the constructor.
  656. */
  657. CarlaEngine* getEngine() const noexcept;
  658. /*!
  659. * Get the plugin's engine client.
  660. */
  661. CarlaEngineClient* getEngineClient() const noexcept;
  662. /*!
  663. * Get a plugin's audio input port.
  664. */
  665. CarlaEngineAudioPort* getAudioInPort(const uint32_t index) const noexcept;
  666. /*!
  667. * Get a plugin's audio output port.
  668. */
  669. CarlaEngineAudioPort* getAudioOutPort(const uint32_t index) const noexcept;
  670. // -------------------------------------------------------------------
  671. // Plugin initializers
  672. /*!
  673. * Get a plugin's binary type.\n
  674. * This is always BINARY_NATIVE unless the plugin is a bridge.
  675. */
  676. virtual BinaryType getBinaryType() const noexcept
  677. {
  678. return BINARY_NATIVE;
  679. }
  680. /*!
  681. * Handy function required by CarlaEngine::clonePlugin().
  682. */
  683. virtual const void* getExtraStuff() const noexcept
  684. {
  685. return nullptr;
  686. }
  687. #ifndef DOXYGEN
  688. struct Initializer {
  689. CarlaEngine* const engine;
  690. const unsigned int id;
  691. const char* const filename;
  692. const char* const name;
  693. const char* const label;
  694. const int64_t uniqueId;
  695. };
  696. static size_t getNativePluginCount() noexcept;
  697. static const NativePluginDescriptor* getNativePluginDescriptor(const size_t index) noexcept;
  698. static CarlaPlugin* newNative(const Initializer& init);
  699. static CarlaPlugin* newBridge(const Initializer& init, const BinaryType btype, const PluginType ptype, const char* const bridgeBinary);
  700. static CarlaPlugin* newLADSPA(const Initializer& init, const LADSPA_RDF_Descriptor* const rdfDescriptor);
  701. static CarlaPlugin* newDSSI(const Initializer& init);
  702. static CarlaPlugin* newLV2(const Initializer& init);
  703. static CarlaPlugin* newVST(const Initializer& init);
  704. static CarlaPlugin* newVST3(const Initializer& init);
  705. static CarlaPlugin* newAU(const Initializer& init);
  706. static CarlaPlugin* newJACK(const Initializer& init);
  707. static CarlaPlugin* newReWire(const Initializer& init);
  708. static CarlaPlugin* newCsound(const Initializer& init);
  709. static CarlaPlugin* newJuce(const Initializer& init, const char* const format);
  710. static CarlaPlugin* newFluidSynth(const Initializer& init, const bool use16Outs);
  711. static CarlaPlugin* newLinuxSampler(const Initializer& init, const char* const format, const bool use16Outs);
  712. static CarlaPlugin* newFileCSD(const Initializer& init);
  713. static CarlaPlugin* newFileGIG(const Initializer& init, const bool use16Outs);
  714. static CarlaPlugin* newFileSF2(const Initializer& init, const bool use16Outs);
  715. static CarlaPlugin* newFileSFZ(const Initializer& init);
  716. #endif
  717. // -------------------------------------------------------------------
  718. protected:
  719. /*!
  720. * Internal data, for CarlaPlugin subclasses only.
  721. */
  722. CarlaPluginProtectedData* const pData;
  723. friend struct CarlaPluginProtectedData;
  724. // -------------------------------------------------------------------
  725. // Helper classes
  726. /*!
  727. * Fully disable plugin in scope and also its engine client.\n
  728. * May wait-block on constructor for plugin process to end.
  729. */
  730. class ScopedDisabler
  731. {
  732. public:
  733. ScopedDisabler(CarlaPlugin* const plugin) noexcept;
  734. ~ScopedDisabler() noexcept;
  735. private:
  736. CarlaPlugin* const fPlugin;
  737. CARLA_PREVENT_HEAP_ALLOCATION
  738. CARLA_DECLARE_NON_COPY_CLASS(ScopedDisabler)
  739. };
  740. /*!
  741. * Lock the plugin's own run/process call.\n
  742. * Plugin will still work as normal, but output only silence.\n
  743. * On destructor needsReset flag might be set if the plugin might have missed some events.
  744. */
  745. class ScopedSingleProcessLocker
  746. {
  747. public:
  748. ScopedSingleProcessLocker(CarlaPlugin* const plugin, const bool block) noexcept;
  749. ~ScopedSingleProcessLocker() noexcept;
  750. private:
  751. CarlaPlugin* const fPlugin;
  752. const bool fBlock;
  753. CARLA_PREVENT_HEAP_ALLOCATION
  754. CARLA_DECLARE_NON_COPY_CLASS(ScopedSingleProcessLocker)
  755. };
  756. CARLA_DECLARE_NON_COPY_CLASS(CarlaPlugin)
  757. };
  758. /**@}*/
  759. // -----------------------------------------------------------------------
  760. CARLA_BACKEND_END_NAMESPACE
  761. #endif // CARLA_PLUGIN_HPP_INCLUDED