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.

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