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.

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