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.

908 lines
26KB

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