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.

913 lines
27KB

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