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.

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