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.

894 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 GPL.txt file
  16. */
  17. #ifndef __CARLA_PLUGIN_HPP__
  18. #define __CARLA_PLUGIN_HPP__
  19. #include "CarlaBackend.hpp"
  20. #include "CarlaString.hpp"
  21. #ifndef DOXYGEN
  22. // Avoid including extra libs here
  23. struct LADSPA_RDF_Descriptor;
  24. typedef void* lo_address;
  25. typedef struct _PluginDescriptor PluginDescriptor;
  26. #endif
  27. CARLA_BACKEND_START_NAMESPACE
  28. #ifndef DOXYGEN
  29. class CarlaEngineEventPort;
  30. #endif
  31. /*!
  32. * @defgroup CarlaPluginAPI Carla Plugin API
  33. *
  34. * The Carla Plugin API.
  35. *
  36. * @{
  37. */
  38. /*!
  39. * TODO.
  40. */
  41. enum PluginPostRtEventType {
  42. kPluginPostRtEventNull,
  43. kPluginPostRtEventDebug,
  44. kPluginPostRtEventParameterChange, // param, SP*, value (SP: if 1, don't report change to Callback and OSC)
  45. kPluginPostRtEventProgramChange, // index
  46. kPluginPostRtEventMidiProgramChange, // index
  47. kPluginPostRtEventNoteOn, // channel, note, velo
  48. kPluginPostRtEventNoteOff // channel, note
  49. };
  50. // -----------------------------------------------------------------------
  51. /*!
  52. * Save state data.
  53. */
  54. struct SaveState;
  55. /*!
  56. * Protected data used in CarlaPlugin and subclasses.\n
  57. * Non-plugin code MUST NEVER have direct access to this.
  58. */
  59. struct CarlaPluginProtectedData;
  60. /*!
  61. * \class CarlaPlugin
  62. *
  63. * \brief Carla Backend base plugin class
  64. *
  65. * This is the base class for all available plugin types available in Carla Backend.\n
  66. * All virtual calls are implemented in this class as fallback, so it's safe to only override needed calls.
  67. *
  68. * \see PluginType
  69. */
  70. class CarlaPlugin
  71. {
  72. protected:
  73. /*!
  74. * This is the constructor of the base plugin class.
  75. *
  76. * \param engine The engine which this plugin belongs to, must not be null
  77. * \param id The 'id' of this plugin, must be between 0 and CarlaEngine::maxPluginNumber()
  78. */
  79. CarlaPlugin(CarlaEngine* const engine, const unsigned int id);
  80. public:
  81. /*!
  82. * This is the destructor of the base plugin class.
  83. */
  84. virtual ~CarlaPlugin();
  85. // -------------------------------------------------------------------
  86. // Information (base)
  87. /*!
  88. * Get the plugin's type (ie, a subclass of CarlaPlugin).
  89. *
  90. * \note Plugin bridges will return their respective plugin type, there is no plugin type such as "bridge".\n
  91. * To check if a plugin is a bridge use:
  92. * \code
  93. * if (hints() & PLUGIN_IS_BRIDGE)
  94. * ...
  95. * \endcode
  96. */
  97. virtual PluginType type() const = 0;
  98. /*!
  99. * Get the plugin's id (as passed in the constructor).
  100. *
  101. * \see setId()
  102. */
  103. unsigned int id() const
  104. {
  105. return fId;
  106. }
  107. /*!
  108. * Get the plugin's hints.
  109. *
  110. * \see PluginHints
  111. */
  112. unsigned int hints() const
  113. {
  114. return fHints;
  115. }
  116. /*!
  117. * Get the plugin's options.
  118. *
  119. * \see PluginOptions, availableOptions() and setOption()
  120. */
  121. unsigned int options() const
  122. {
  123. return fOptions;
  124. }
  125. /*!
  126. * Check if the plugin is enabled.\n
  127. * When a plugin is disabled, it will never be processed or managed in any way.\n
  128. * To 'bypass' a plugin use setActive() instead.
  129. *
  130. * \see setEnabled()
  131. */
  132. bool enabled() const
  133. {
  134. return fEnabled;
  135. }
  136. /*!
  137. * Get the plugin's internal name.\n
  138. * This name is unique within all plugins in an engine.
  139. *
  140. * \see getRealName()
  141. */
  142. const char* name() const
  143. {
  144. return (const char*)fName;
  145. }
  146. /*!
  147. * Get the currently loaded DLL filename for this plugin.\n
  148. * (Sound kits return their exact filename).
  149. */
  150. const char* filename() const
  151. {
  152. return (const char*)fFilename;
  153. }
  154. /*!
  155. * Get the plugin's category (delay, filter, synth, etc).
  156. */
  157. virtual PluginCategory category()
  158. {
  159. return PLUGIN_CATEGORY_NONE;
  160. }
  161. /*!
  162. * Get the plugin's native unique Id.\n
  163. * May return 0 on plugin types that don't support Ids.
  164. */
  165. virtual long uniqueId() const
  166. {
  167. return 0;
  168. }
  169. /*!
  170. * Get the plugin's latency, in sample frames.
  171. */
  172. uint32_t latency() const;
  173. // -------------------------------------------------------------------
  174. // Information (count)
  175. /*!
  176. * Get the number of audio inputs.
  177. */
  178. uint32_t audioInCount() const;
  179. /*!
  180. * Get the number of audio outputs.
  181. */
  182. uint32_t audioOutCount() const;
  183. /*!
  184. * Get the number of MIDI inputs.
  185. */
  186. virtual uint32_t midiInCount() const;
  187. /*!
  188. * Get the number of MIDI outputs.
  189. */
  190. virtual uint32_t midiOutCount() const;
  191. /*!
  192. * Get the number of parameters.\n
  193. * To know the number of parameter inputs and outputs separately use getParameterCountInfo() instead.
  194. */
  195. uint32_t parameterCount() const;
  196. /*!
  197. * Get the number of scalepoints for parameter \a parameterId.
  198. */
  199. virtual uint32_t parameterScalePointCount(const uint32_t parameterId) const;
  200. /*!
  201. * Get the number of programs.
  202. */
  203. uint32_t programCount() const;
  204. /*!
  205. * Get the number of MIDI programs.
  206. */
  207. uint32_t midiProgramCount() const;
  208. /*!
  209. * Get the number of custom data sets.
  210. */
  211. uint32_t customDataCount() const;
  212. // -------------------------------------------------------------------
  213. // Information (current data)
  214. /*!
  215. * Get the current program number (-1 if unset).
  216. *
  217. * \see setProgram()
  218. */
  219. int32_t currentProgram() const;
  220. /*!
  221. * Get the current MIDI program number (-1 if unset).
  222. *
  223. * \see setMidiProgram()
  224. * \see setMidiProgramById()
  225. */
  226. int32_t currentMidiProgram() const;
  227. /*!
  228. * Get the parameter data of \a parameterId.
  229. */
  230. const ParameterData& parameterData(const uint32_t parameterId) const;
  231. /*!
  232. * Get the parameter ranges of \a parameterId.
  233. */
  234. const ParameterRanges& parameterRanges(const uint32_t parameterId) const;
  235. /*!
  236. * Check if parameter \a parameterId is of output type.
  237. */
  238. bool parameterIsOutput(const uint32_t parameterId) const;
  239. /*!
  240. * Get the MIDI program at \a index.
  241. *
  242. * \see getMidiProgramName()
  243. */
  244. const MidiProgramData& midiProgramData(const uint32_t index) const;
  245. /*!
  246. * Get the custom data set at \a index.
  247. *
  248. * \see setCustomData()
  249. */
  250. const CustomData& customData(const uint32_t index) const;
  251. /*!
  252. * Get the complete plugin chunk data into \a dataPtr.
  253. *
  254. * \note Make sure to verify the plugin supports chunks before calling this function!
  255. * \return The size of the chunk or 0 if invalid.
  256. *
  257. * \see setChunkData()
  258. */
  259. virtual int32_t chunkData(void** const dataPtr);
  260. // -------------------------------------------------------------------
  261. // Information (per-plugin data)
  262. /*!
  263. * Get the plugin available options.
  264. *
  265. * \see PluginOptions
  266. */
  267. virtual unsigned int availableOptions();
  268. /*!
  269. * Get the current parameter value of \a parameterId.
  270. */
  271. virtual float getParameterValue(const uint32_t parameterId);
  272. /*!
  273. * Get the scalepoint \a scalePointId value of the parameter \a parameterId.
  274. */
  275. virtual float getParameterScalePointValue(const uint32_t parameterId, const uint32_t scalePointId);
  276. /*!
  277. * Get the plugin's label (URI for PLUGIN_LV2).
  278. */
  279. virtual void getLabel(char* const strBuf);
  280. /*!
  281. * Get the plugin's maker.
  282. */
  283. virtual void getMaker(char* const strBuf);
  284. /*!
  285. * Get the plugin's copyright/license.
  286. */
  287. virtual void getCopyright(char* const strBuf);
  288. /*!
  289. * Get the plugin's (real) name.
  290. *
  291. * \see name()
  292. */
  293. virtual void getRealName(char* const strBuf);
  294. /*!
  295. * Get the name of the parameter \a parameterId.
  296. */
  297. virtual void getParameterName(const uint32_t parameterId, char* const strBuf);
  298. /*!
  299. * Get the symbol of the parameter \a parameterId.
  300. */
  301. virtual void getParameterSymbol(const uint32_t parameterId, char* const strBuf);
  302. /*!
  303. * Get the custom text of the parameter \a parameterId.
  304. */
  305. virtual void getParameterText(const uint32_t parameterId, char* const strBuf);
  306. /*!
  307. * Get the unit of the parameter \a parameterId.
  308. */
  309. virtual void getParameterUnit(const uint32_t parameterId, char* const strBuf);
  310. /*!
  311. * Get the scalepoint \a scalePointId label of the parameter \a parameterId.
  312. */
  313. virtual void getParameterScalePointLabel(const uint32_t parameterId, const uint32_t scalePointId, char* const strBuf);
  314. /*!
  315. * Get the name of the program at \a index.
  316. */
  317. void getProgramName(const uint32_t index, char* const strBuf);
  318. /*!
  319. * Get the name of the MIDI program at \a index.
  320. *
  321. * \see getMidiProgramInfo()
  322. */
  323. void getMidiProgramName(const uint32_t index, char* const strBuf);
  324. /*!
  325. * Get information about the plugin's parameter count.\n
  326. * This is used to check how many input, output and total parameters are available.\n
  327. *
  328. * \note Some parameters might not be input or output (ie, invalid).
  329. *
  330. * \see parameterCount()
  331. */
  332. void getParameterCountInfo(uint32_t* const ins, uint32_t* const outs, uint32_t* const total);
  333. // -------------------------------------------------------------------
  334. // Set data (state)
  335. /*!
  336. * Tell the plugin to prepare for save.
  337. */
  338. virtual void prepareForSave();
  339. /*!
  340. * Get the plugin's save state.\n
  341. * The plugin will automatically call prepareForSave() as needed.
  342. *
  343. * \see loadSaveState()
  344. */
  345. const SaveState& getSaveState();
  346. /*!
  347. * Get the plugin's save state.
  348. *
  349. * \see getSaveState()
  350. */
  351. void loadSaveState(const SaveState& saveState);
  352. /*!
  353. * Save the current plugin state to \a filename.
  354. */
  355. bool saveStateToFile(const char* const filename);
  356. /*!
  357. * Save the plugin state from \a filename.
  358. */
  359. bool loadStateFromFile(const char* const filename);
  360. // -------------------------------------------------------------------
  361. // Set data (internal stuff)
  362. /*!
  363. * Set the plugin's id to \a newId.
  364. *
  365. * \see id()
  366. */
  367. void setId(const unsigned int newId);
  368. /*!
  369. * Set the plugin's name to \a newName.
  370. *
  371. * \see name()
  372. */
  373. virtual void setName(const char* const newName);
  374. /*!
  375. * Set a plugin's option.
  376. *
  377. * \see options()
  378. */
  379. void setOption(const unsigned int option, const bool yesNo);
  380. /*!
  381. * Enable or disable the plugin according to \a yesNo.
  382. *
  383. * When a plugin is disabled, it will never be processed or managed in any way.\n
  384. * To 'bypass' a plugin use setActive() instead.
  385. *
  386. * \see enabled()
  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. #ifndef BUILD_BRIDGE
  478. /*!
  479. * Set parameter's \a parameterId MIDI channel to \a channel.\n
  480. * \a channel must be between 0 and 15.
  481. */
  482. void setParameterMidiChannel(const uint32_t parameterId, uint8_t channel, const bool sendOsc, const bool sendCallback);
  483. /*!
  484. * Set parameter's \a parameterId MIDI CC to \a cc.\n
  485. * \a cc must be between 0 and 95 (0x5F), or -1 for invalid.
  486. */
  487. void setParameterMidiCC(const uint32_t parameterId, int16_t cc, const bool sendOsc, const bool sendCallback);
  488. #endif
  489. /*!
  490. * Add a custom data set.\n
  491. * If \a key already exists, its current value will be swapped with \a value.
  492. *
  493. * \param type Type of data used in \a value.
  494. * \param key A key identifing this data set.
  495. * \param value The value of the data set, of type \a type.
  496. * \param sendGui Send message change to plugin's custom GUI, if any
  497. *
  498. * \see customData()
  499. */
  500. virtual void setCustomData(const char* const type, const char* const key, const char* const value, const bool sendGui);
  501. /*!
  502. * Set the complete chunk data as \a stringData.\n
  503. * \a stringData must a base64 encoded string of binary data.
  504. *
  505. * \see chunkData()
  506. *
  507. * \note Make sure to verify the plugin supports chunks before calling this function!
  508. */
  509. virtual void setChunkData(const char* const stringData);
  510. /*!
  511. * Change the current plugin program to \a index.
  512. *
  513. * If \a index is negative the plugin's program will be considered unset.\n
  514. * The plugin's default parameter values will be updated when this function is called.
  515. *
  516. * \param index New program index to use
  517. * \param sendGui Send message change to plugin's custom GUI, if any
  518. * \param sendOsc Send message change over OSC
  519. * \param sendCallback Send message change to registered callback
  520. * \param block Block the audio callback
  521. */
  522. virtual void setProgram(int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback);
  523. /*!
  524. * Change the current MIDI plugin program to \a index.
  525. *
  526. * If \a index is negative the plugin's program will be considered unset.\n
  527. * The plugin's default parameter values will be updated when this function is called.
  528. *
  529. * \param index New program index to use
  530. * \param sendGui Send message change to plugin's custom GUI, if any
  531. * \param sendOsc Send message change over OSC
  532. * \param sendCallback Send message change to registered callback
  533. * \param block Block the audio callback
  534. */
  535. virtual void setMidiProgram(int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback);
  536. /*!
  537. * This is an overloaded call to setMidiProgram().\n
  538. * It changes the current MIDI program using \a bank and \a program values instead of index.
  539. */
  540. void setMidiProgramById(const uint32_t bank, const uint32_t program, const bool sendGui, const bool sendOsc, const bool sendCallback);
  541. // -------------------------------------------------------------------
  542. // Set gui stuff
  543. /*!
  544. * Show (or hide) the plugin's custom GUI according to \a yesNo.
  545. *
  546. * \note This function must be always called from the main thread.
  547. */
  548. virtual void showGui(const bool yesNo);
  549. /*!
  550. * Idle the plugin's custom GUI.
  551. *
  552. * \note This function must be always called from the main thread.
  553. */
  554. virtual void idleGui();
  555. // -------------------------------------------------------------------
  556. // Plugin state
  557. /*!
  558. * Reload the plugin's entire state (including programs).\n
  559. * The plugin will be disabled during this call.
  560. */
  561. virtual void reload();
  562. /*!
  563. * Reload the plugin's programs state.
  564. */
  565. virtual void reloadPrograms(const bool init);
  566. // -------------------------------------------------------------------
  567. // Plugin processing
  568. /*!
  569. * Plugin activate call.
  570. */
  571. virtual void activate();
  572. /*!
  573. * Plugin activate call.
  574. */
  575. virtual void deactivate();
  576. /*!
  577. * Plugin process call.
  578. */
  579. virtual void process(float** const inBuffer, float** const outBuffer, const uint32_t frames);
  580. /*!
  581. * Tell the plugin the current buffer size has changed.
  582. */
  583. virtual void bufferSizeChanged(const uint32_t newBufferSize);
  584. /*!
  585. * Tell the plugin the current sample rate has changed.
  586. */
  587. virtual void sampleRateChanged(const double newSampleRate);
  588. /*!
  589. * TODO.
  590. */
  591. bool tryLock();
  592. /*!
  593. * TODO.
  594. */
  595. void unlock();
  596. // -------------------------------------------------------------------
  597. // Plugin buffers
  598. /*!
  599. * Initialize all RT buffers of the plugin.
  600. */
  601. virtual void initBuffers();
  602. /*!
  603. * Delete and clear all RT buffers.
  604. */
  605. virtual void clearBuffers();
  606. // -------------------------------------------------------------------
  607. // OSC stuff
  608. /*!
  609. * Register this plugin to the engine's OSC client (controller or bridge).
  610. */
  611. void registerToOscClient();
  612. /*!
  613. * Update the plugin's internal OSC data according to \a source and \a url.\n
  614. * This is used for OSC-GUI bridges.
  615. */
  616. void updateOscData(const lo_address& source, const char* const url);
  617. /*!
  618. * Free the plugin's internal OSC memory data.
  619. */
  620. void freeOscData();
  621. /*!
  622. * Show the plugin's OSC based GUI.\n
  623. * This is a handy function that waits for the GUI to respond and automatically asks it to show itself.
  624. */
  625. bool waitForOscGuiShow();
  626. // -------------------------------------------------------------------
  627. // MIDI events
  628. #ifndef BUILD_BRIDGE
  629. /*!
  630. * Send a single midi note to be processed in the next audio callback.\n
  631. * A note with 0 velocity means note-off.
  632. * \note Non-RT call
  633. */
  634. void sendMidiSingleNote(const uint8_t channel, const uint8_t note, const uint8_t velo, const bool sendGui, const bool sendOsc, const bool sendCallback);
  635. #endif
  636. /*!
  637. * Send all midi notes off to the host callback.\n
  638. * This doesn't send the actual MIDI All-Notes-Off event, but 128 note-offs instead (if ctrlChannel is valid).
  639. * \note RT call
  640. */
  641. void sendMidiAllNotesOffToCallback();
  642. // -------------------------------------------------------------------
  643. // Post-poned events
  644. /*!
  645. * Post pone an event of type \a type.\n
  646. * The event will be processed later, but as soon as possible.
  647. * \note RT call
  648. */
  649. void postponeRtEvent(const PluginPostRtEventType type, const int32_t value1, const int32_t value2, const float value3);
  650. /*!
  651. * Process all the post-poned events.
  652. * This function must be called from the main thread (ie, idleGui()) if PLUGIN_USES_SINGLE_THREAD is set.
  653. */
  654. void postRtEventsRun();
  655. // -------------------------------------------------------------------
  656. // Post-poned UI Stuff
  657. /*!
  658. * Tell the UI a parameter has changed.
  659. */
  660. virtual void uiParameterChange(const uint32_t index, const float value);
  661. /*!
  662. * Tell the UI the current program has changed.
  663. */
  664. virtual void uiProgramChange(const uint32_t index);
  665. /*!
  666. * Tell the UI the current midi program has changed.
  667. */
  668. virtual void uiMidiProgramChange(const uint32_t index);
  669. /*!
  670. * Tell the UI a note has been pressed.
  671. */
  672. virtual void uiNoteOn(const uint8_t channel, const uint8_t note, const uint8_t velo);
  673. /*!
  674. * Tell the UI a note has been released.
  675. */
  676. virtual void uiNoteOff(const uint8_t channel, const uint8_t note);
  677. #ifndef DOXYGEN
  678. // -------------------------------------------------------------------
  679. // Plugin initializers
  680. struct Initializer {
  681. CarlaEngine* const engine;
  682. const unsigned int id;
  683. const char* const filename;
  684. const char* const name;
  685. const char* const label;
  686. };
  687. // used in CarlaEngine::clonePlugin()
  688. virtual const void* getExtraStuff()
  689. {
  690. return nullptr;
  691. }
  692. # ifdef WANT_NATIVE
  693. static size_t getNativePluginCount();
  694. static const PluginDescriptor* getNativePluginDescriptor(const size_t index);
  695. # endif
  696. static CarlaPlugin* newNative(const Initializer& init);
  697. static CarlaPlugin* newBridge(const Initializer& init, const BinaryType btype, const PluginType ptype, const char* const bridgeBinary);
  698. static CarlaPlugin* newLADSPA(const Initializer& init, const LADSPA_RDF_Descriptor* const rdfDescriptor);
  699. static CarlaPlugin* newDSSI(const Initializer& init, const char* const guiFilename);
  700. static CarlaPlugin* newLV2(const Initializer& init);
  701. static CarlaPlugin* newVST(const Initializer& init);
  702. static CarlaPlugin* newVST3(const Initializer& init);
  703. static CarlaPlugin* newGIG(const Initializer& init, const bool use16Outs);
  704. static CarlaPlugin* newSF2(const Initializer& init, const bool use16Outs);
  705. static CarlaPlugin* newSFZ(const Initializer& init, const bool use16Outs);
  706. // -------------------------------------------------------------------
  707. protected:
  708. unsigned int fId; //!< Plugin Id, as passed in the constructor, returned in id(). \see setId()
  709. unsigned int fHints; //!< Hints, as returned in hints().
  710. unsigned int fOptions; //!< Defined and currently in-use options, returned in options(). \see availableOptions()
  711. bool fEnabled; //!< Wherever the plugin is ready for usage
  712. CarlaString fName; //!< Plugin name
  713. CarlaString fFilename; //!< Plugin filename, if applicable
  714. friend class CarlaEngineBridge;
  715. friend struct CarlaPluginProtectedData;
  716. CarlaPluginProtectedData* const kData; //!< Internal data, for CarlaPlugin subclasses only.
  717. // -------------------------------------------------------------------
  718. // Helper classes
  719. // Fully disable plugin in scope and also its engine client
  720. // May wait-block on constructor for plugin process to end
  721. class ScopedDisabler
  722. {
  723. public:
  724. ScopedDisabler(CarlaPlugin* const plugin);
  725. ~ScopedDisabler();
  726. private:
  727. CarlaPlugin* const kPlugin;
  728. CARLA_PREVENT_HEAP_ALLOCATION
  729. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ScopedDisabler)
  730. };
  731. // Lock the plugin's own run/process call
  732. // Plugin will still work as normal, but output only silence
  733. // On destructor needsReset flag might be set if the plugin might have missed some events
  734. class ScopedSingleProcessLocker
  735. {
  736. public:
  737. ScopedSingleProcessLocker(CarlaPlugin* const plugin, const bool block);
  738. ~ScopedSingleProcessLocker();
  739. private:
  740. CarlaPlugin* const kPlugin;
  741. const bool kBlock;
  742. CARLA_PREVENT_HEAP_ALLOCATION
  743. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ScopedSingleProcessLocker)
  744. };
  745. private:
  746. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaPlugin)
  747. #endif
  748. };
  749. /**@}*/
  750. CARLA_BACKEND_END_NAMESPACE
  751. #endif // __CARLA_PLUGIN_HPP__