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.

974 lines
27KB

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