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.

923 lines
28KB

  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 CarlaEngineAudioPort;
  38. /*!
  39. * Save state data.
  40. */
  41. struct SaveState;
  42. /*!
  43. * Protected data used in CarlaPlugin and subclasses.\n
  44. * Non-plugin code MUST NEVER have direct access to this.
  45. */
  46. struct CarlaPluginProtectedData;
  47. // -----------------------------------------------------------------------
  48. /*!
  49. * Carla Backend base plugin class
  50. *
  51. * This is the base class for all available plugin types available in Carla Backend.\n
  52. * All virtual calls are implemented in this class as fallback (except reload and process),\n
  53. * so it's safe to only override needed calls.
  54. *
  55. * \see PluginType
  56. */
  57. class CarlaPlugin
  58. {
  59. protected:
  60. /*!
  61. * This is the constructor of the base plugin class.
  62. *
  63. * \param engine The engine which this plugin belongs to, must not be null
  64. * \param id The 'id' of this plugin, must be between 0 and CarlaEngine::maxPluginNumber()
  65. */
  66. CarlaPlugin(CarlaEngine* const engine, const unsigned int id);
  67. public:
  68. /*!
  69. * This is the destructor of the base plugin class.
  70. */
  71. virtual ~CarlaPlugin();
  72. // -------------------------------------------------------------------
  73. // Information (base)
  74. /*!
  75. * Get the plugin's type (a subclass of CarlaPlugin).
  76. *
  77. * \note Plugin bridges will return their respective plugin type, there is no plugin type such as "bridge".\n
  78. * To check if a plugin is a bridge use:
  79. * \code
  80. * if (getHints() & PLUGIN_IS_BRIDGE)
  81. * ...
  82. * \endcode
  83. */
  84. virtual PluginType getType() const noexcept = 0;
  85. /*!
  86. * Get the plugin's id (as passed in the constructor).
  87. *
  88. * \see setId()
  89. */
  90. unsigned int getId() const noexcept;
  91. /*!
  92. * Get the plugin's hints.
  93. *
  94. * \see PluginHints
  95. */
  96. unsigned int getHints() const noexcept;
  97. /*!
  98. * Get the plugin's options (currently in use).
  99. *
  100. * \see PluginOptions, getAvailableOptions() and setOption()
  101. */
  102. unsigned int getOptionsEnabled() const noexcept;
  103. /*!
  104. * Check if the plugin is enabled.\n
  105. * When a plugin is disabled, it will never be processed or managed in any way.
  106. *
  107. * \see setEnabled()
  108. */
  109. bool isEnabled() const noexcept;
  110. /*!
  111. * Get the plugin's internal name.\n
  112. * This name is unique within all plugins in an engine.
  113. *
  114. * \see getRealName() and setName()
  115. */
  116. const char* getName() const noexcept;
  117. /*!
  118. * Get the currently loaded DLL filename for this plugin.\n
  119. * (Sound kits return their exact filename).
  120. */
  121. const char* getFilename() const noexcept;
  122. /*!
  123. * Get the plugins's icon name.
  124. */
  125. const char* getIconName() const noexcept;
  126. /*!
  127. * Get the plugin's category (delay, filter, synth, etc).
  128. */
  129. virtual PluginCategory getCategory() const noexcept;
  130. /*!
  131. * Get the plugin's native unique Id.\n
  132. * May return 0 on plugin types that don't support Ids.
  133. */
  134. virtual int64_t getUniqueId() const noexcept;
  135. /*!
  136. * Get the plugin's latency, in sample frames.
  137. */
  138. uint32_t getLatencyInFrames() const noexcept;
  139. // -------------------------------------------------------------------
  140. // Information (count)
  141. /*!
  142. * Get the number of audio inputs.
  143. */
  144. uint32_t getAudioInCount() const noexcept;
  145. /*!
  146. * Get the number of audio outputs.
  147. */
  148. uint32_t getAudioOutCount() const noexcept;
  149. /*!
  150. * Get the number of MIDI inputs.
  151. */
  152. virtual uint32_t getMidiInCount() const noexcept;
  153. /*!
  154. * Get the number of MIDI outputs.
  155. */
  156. virtual uint32_t getMidiOutCount() const noexcept;
  157. /*!
  158. * Get the number of parameters.\n
  159. * To know the number of parameter inputs and outputs separately use getParameterCountInfo() instead.
  160. */
  161. uint32_t getParameterCount() const noexcept;
  162. /*!
  163. * Get the number of scalepoints for parameter \a parameterId.
  164. */
  165. virtual uint32_t getParameterScalePointCount(const uint32_t parameterId) const noexcept;
  166. /*!
  167. * Get the number of programs.
  168. */
  169. uint32_t getProgramCount() const noexcept;
  170. /*!
  171. * Get the number of MIDI programs.
  172. */
  173. uint32_t getMidiProgramCount() const noexcept;
  174. /*!
  175. * Get the number of custom data sets.
  176. */
  177. uint32_t getCustomDataCount() const noexcept;
  178. // -------------------------------------------------------------------
  179. // Information (current data)
  180. /*!
  181. * Get the current program number (-1 if unset).
  182. *
  183. * \see setProgram()
  184. */
  185. int32_t getCurrentProgram() const noexcept;
  186. /*!
  187. * Get the current MIDI program number (-1 if unset).
  188. *
  189. * \see setMidiProgram()
  190. * \see setMidiProgramById()
  191. */
  192. int32_t getCurrentMidiProgram() const noexcept;
  193. /*!
  194. * Get the parameter data of \a parameterId.
  195. */
  196. const ParameterData& getParameterData(const uint32_t parameterId) const noexcept;
  197. /*!
  198. * Get the parameter ranges of \a parameterId.
  199. */
  200. const ParameterRanges& getParameterRanges(const uint32_t parameterId) const noexcept;
  201. /*!
  202. * Check if parameter \a parameterId is of output type.
  203. */
  204. bool isParameterOutput(const uint32_t parameterId) const noexcept;
  205. /*!
  206. * Get the MIDI program at \a index.
  207. *
  208. * \see getMidiProgramName()
  209. */
  210. const MidiProgramData& getMidiProgramData(const uint32_t index) const noexcept;
  211. /*!
  212. * Get the custom data set at \a index.
  213. *
  214. * \see getCustomDataCount() and setCustomData()
  215. */
  216. const CustomData& getCustomData(const uint32_t index) const noexcept;
  217. /*!
  218. * Get the complete plugin chunk data into \a dataPtr.
  219. *
  220. * \note Make sure to verify the plugin supports chunks before calling this function!
  221. * \return The size of the chunk or 0 if invalid.
  222. *
  223. * \see setChunkData()
  224. */
  225. virtual int32_t getChunkData(void** const dataPtr) const noexcept;
  226. // -------------------------------------------------------------------
  227. // Information (per-plugin data)
  228. /*!
  229. * Get the plugin available options.
  230. *
  231. * \see PluginOptions, getOptions() and setOption()
  232. */
  233. virtual unsigned int getOptionsAvailable() const noexcept;
  234. /*!
  235. * Get the current parameter value of \a parameterId.
  236. */
  237. virtual float getParameterValue(const uint32_t parameterId) const noexcept;
  238. /*!
  239. * Get the scalepoint \a scalePointId value of the parameter \a parameterId.
  240. */
  241. virtual float getParameterScalePointValue(const uint32_t parameterId, const uint32_t scalePointId) const noexcept;
  242. /*!
  243. * Get the plugin's label (URI for LV2 plugins).
  244. */
  245. virtual void getLabel(char* const strBuf) const noexcept;
  246. /*!
  247. * Get the plugin's maker.
  248. */
  249. virtual void getMaker(char* const strBuf) const noexcept;
  250. /*!
  251. * Get the plugin's copyright/license.
  252. */
  253. virtual void getCopyright(char* const strBuf) const noexcept;
  254. /*!
  255. * Get the plugin's (real) name.
  256. *
  257. * \see getName() and setName()
  258. */
  259. virtual void getRealName(char* const strBuf) const noexcept;
  260. /*!
  261. * Get the name of the parameter \a parameterId.
  262. */
  263. virtual void getParameterName(const uint32_t parameterId, char* const strBuf) const noexcept;
  264. /*!
  265. * Get the symbol of the parameter \a parameterId.
  266. */
  267. virtual void getParameterSymbol(const uint32_t parameterId, char* const strBuf) const noexcept;
  268. /*!
  269. * Get the custom text of the parameter \a parameterId.
  270. */
  271. virtual void getParameterText(const uint32_t parameterId, char* const strBuf) const noexcept;
  272. /*!
  273. * Get the unit of the parameter \a parameterId.
  274. */
  275. virtual void getParameterUnit(const uint32_t parameterId, char* const strBuf) const noexcept;
  276. /*!
  277. * Get the scalepoint \a scalePointId label of the parameter \a parameterId.
  278. */
  279. virtual void getParameterScalePointLabel(const uint32_t parameterId, const uint32_t scalePointId, char* const strBuf) const noexcept;
  280. /*!
  281. * Get the current parameter value of \a parameterId.
  282. * \a parameterId can be negative to allow internal parameters.
  283. * \see InternalParametersIndex
  284. */
  285. float getInternalParameterValue(const int32_t parameterId) const noexcept;
  286. /*!
  287. * Get the name of the program at \a index.
  288. */
  289. void getProgramName(const uint32_t index, char* const strBuf) const noexcept;
  290. /*!
  291. * Get the name of the MIDI program at \a index.
  292. *
  293. * \see getMidiProgramInfo()
  294. */
  295. void getMidiProgramName(const uint32_t index, char* const strBuf) const noexcept;
  296. /*!
  297. * Get information about the plugin's parameter count.\n
  298. * This is used to check how many input, output and total parameters are available.\n
  299. *
  300. * \note Some parameters might not be input or output (ie, invalid).
  301. *
  302. * \see getParameterCount()
  303. */
  304. void getParameterCountInfo(uint32_t& ins, uint32_t& outs) const noexcept;
  305. // -------------------------------------------------------------------
  306. // Set data (state)
  307. /*!
  308. * Tell the plugin to prepare for save.
  309. */
  310. virtual void prepareForSave();
  311. /*!
  312. * Get the plugin's save state.\n
  313. * The plugin will automatically call prepareForSave() as needed.
  314. *
  315. * \see loadSaveState()
  316. */
  317. const SaveState& getSaveState();
  318. /*!
  319. * Get the plugin's save state.
  320. *
  321. * \see getSaveState()
  322. */
  323. void loadSaveState(const SaveState& saveState);
  324. /*!
  325. * Save the current plugin state to \a filename.
  326. *
  327. * \see loadStateFromFile()
  328. */
  329. bool saveStateToFile(const char* const filename);
  330. /*!
  331. * Save the plugin state from \a filename.
  332. *
  333. * \see saveStateToFile()
  334. */
  335. bool loadStateFromFile(const char* const filename);
  336. // -------------------------------------------------------------------
  337. // Set data (internal stuff)
  338. /*!
  339. * Set the plugin's id to \a newId.
  340. *
  341. * \see getId()
  342. */
  343. void setId(const unsigned int newId) noexcept;
  344. /*!
  345. * Set the plugin's name to \a newName.
  346. *
  347. * \see getName() and getRealName()
  348. */
  349. virtual void setName(const char* const newName);
  350. /*!
  351. * Set a plugin's option.
  352. *
  353. * \see getOptions() and getAvailableOptions()
  354. */
  355. void setOption(const unsigned int option, const bool yesNo);
  356. /*!
  357. * Enable or disable the plugin according to \a yesNo. \n
  358. * When a plugin is disabled, it will never be processed or managed in any way.
  359. *
  360. * \see isEnabled()
  361. */
  362. void setEnabled(const bool yesNo) noexcept;
  363. /*!
  364. * Set plugin as active according to \a active.
  365. *
  366. * \param sendOsc Send message change over OSC
  367. * \param sendCallback Send message change to registered callback
  368. */
  369. void setActive(const bool active, const bool sendOsc, const bool sendCallback) noexcept;
  370. #ifndef BUILD_BRIDGE
  371. /*!
  372. * Set the plugin's dry/wet signal value to \a value.\n
  373. * \a value must be between 0.0 and 1.0.
  374. *
  375. * \param sendOsc Send message change over OSC
  376. * \param sendCallback Send message change to registered callback
  377. */
  378. void setDryWet(const float value, const bool sendOsc, const bool sendCallback) noexcept;
  379. /*!
  380. * Set the plugin's output volume to \a value.\n
  381. * \a value must be between 0.0 and 1.27.
  382. *
  383. * \param sendOsc Send message change over OSC
  384. * \param sendCallback Send message change to registered callback
  385. */
  386. void setVolume(const float value, const bool sendOsc, const bool sendCallback) noexcept;
  387. /*!
  388. * Set the plugin's output left balance value to \a value.\n
  389. * \a value must be between -1.0 and 1.0.
  390. *
  391. * \param sendOsc Send message change over OSC
  392. * \param sendCallback Send message change to registered callback
  393. *
  394. * \note Pure-Stereo plugins only!
  395. */
  396. void setBalanceLeft(const float value, const bool sendOsc, const bool sendCallback) noexcept;
  397. /*!
  398. * Set the plugin's output right balance value to \a value.\n
  399. * \a value must be between -1.0 and 1.0.
  400. *
  401. * \param sendOsc Send message change over OSC
  402. * \param sendCallback Send message change to registered callback
  403. *
  404. * \note Pure-Stereo plugins only!
  405. */
  406. void setBalanceRight(const float value, const bool sendOsc, const bool sendCallback) noexcept;
  407. /*!
  408. * Set the plugin's output panning value to \a value.\n
  409. * \a value must be between -1.0 and 1.0.
  410. *
  411. * \param sendOsc Send message change over OSC
  412. * \param sendCallback Send message change to registered callback
  413. *
  414. * \note Force-Stereo plugins only!
  415. */
  416. void setPanning(const float value, const bool sendOsc, const bool sendCallback) noexcept;
  417. #endif
  418. /*!
  419. * Set the plugin's midi control channel.
  420. *
  421. * \param sendOsc Send message change over OSC
  422. * \param sendCallback Send message change to registered callback
  423. */
  424. virtual void setCtrlChannel(const int8_t channel, const bool sendOsc, const bool sendCallback) noexcept;
  425. // -------------------------------------------------------------------
  426. // Set data (plugin-specific stuff)
  427. /*!
  428. * Set a plugin's parameter value.
  429. *
  430. * \param parameterId The parameter to change
  431. * \param value The new parameter value, must be within the parameter's range
  432. * \param sendGui Send message change to plugin's custom GUI, if any
  433. * \param sendOsc Send message change over OSC
  434. * \param sendCallback Send message change to registered callback
  435. *
  436. * \see getParameterValue()
  437. */
  438. virtual void setParameterValue(const uint32_t parameterId, const float value, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept;
  439. /*!
  440. * Set a plugin's parameter value, including internal parameters.\n
  441. * \a rindex can be negative to allow internal parameters change (as defined in InternalParametersIndex).
  442. *
  443. * \see setParameterValue()
  444. * \see setActive()
  445. * \see setDryWet()
  446. * \see setVolume()
  447. * \see setBalanceLeft()
  448. * \see setBalanceRight()
  449. */
  450. void setParameterValueByRealIndex(const int32_t rindex, const float value, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept;
  451. /*!
  452. * Set parameter's \a parameterId MIDI channel to \a channel.\n
  453. * \a channel must be between 0 and 15.
  454. */
  455. void setParameterMidiChannel(const uint32_t parameterId, uint8_t channel, const bool sendOsc, const bool sendCallback) noexcept;
  456. /*!
  457. * Set parameter's \a parameterId MIDI CC to \a cc.\n
  458. * \a cc must be between 0 and 95 (0x5F), or -1 for invalid.
  459. */
  460. void setParameterMidiCC(const uint32_t parameterId, int16_t cc, const bool sendOsc, const bool sendCallback) noexcept;
  461. /*!
  462. * Add a custom data set.\n
  463. * If \a key already exists, its current value will be swapped with \a value.
  464. *
  465. * \param type Type of data used in \a value.
  466. * \param key A key identifing this data set.
  467. * \param value The value of the data set, of type \a type.
  468. * \param sendGui Send message change to plugin's custom GUI, if any
  469. *
  470. * \see getCustomDataCount() and getCustomData()
  471. */
  472. virtual void setCustomData(const char* const type, const char* const key, const char* const value, const bool sendGui);
  473. /*!
  474. * Set the complete chunk data as \a stringData.\n
  475. * \a stringData must a base64 encoded string of binary data.
  476. *
  477. * \see getChunkData()
  478. *
  479. * \note Make sure to verify the plugin supports chunks before calling this function!
  480. */
  481. virtual void setChunkData(const char* const stringData);
  482. /*!
  483. * Change the current plugin program to \a index.
  484. *
  485. * If \a index is negative the plugin's program will be considered unset.\n
  486. * The plugin's default parameter values will be updated when this function is called.
  487. *
  488. * \param index New program index to use
  489. * \param sendGui Send message change to plugin's custom GUI, if any
  490. * \param sendOsc Send message change over OSC
  491. * \param sendCallback Send message change to registered callback
  492. * \param block Block the audio callback
  493. */
  494. virtual void setProgram(const int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept;
  495. /*!
  496. * Change the current MIDI plugin program to \a index.
  497. *
  498. * If \a index is negative the plugin's program will be considered unset.\n
  499. * The plugin's default parameter values will be updated when this function is called.
  500. *
  501. * \param index New program index to use
  502. * \param sendGui Send message change to plugin's custom GUI, if any
  503. * \param sendOsc Send message change over OSC
  504. * \param sendCallback Send message change to registered callback
  505. * \param block Block the audio callback
  506. */
  507. virtual void setMidiProgram(const int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept;
  508. /*!
  509. * This is an overloaded call to setMidiProgram().\n
  510. * It changes the current MIDI program using \a bank and \a program values instead of index.
  511. */
  512. void setMidiProgramById(const uint32_t bank, const uint32_t program, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept;
  513. // -------------------------------------------------------------------
  514. // Set gui stuff
  515. /*!
  516. * Idle function.
  517. *
  518. * \note This function must be always called from the main thread.
  519. */
  520. virtual void idle();
  521. /*!
  522. * Show (or hide) the plugin's custom UI according to \a yesNo.
  523. *
  524. * \note This function must be always called from the main thread.
  525. */
  526. virtual void showCustomUI(const bool yesNo);
  527. // -------------------------------------------------------------------
  528. // Plugin state
  529. /*!
  530. * Reload the plugin's entire state (including programs).\n
  531. * The plugin will be disabled during this call.
  532. */
  533. virtual void reload() = 0;
  534. /*!
  535. * Reload the plugin's programs state.
  536. */
  537. virtual void reloadPrograms(const bool doInit);
  538. // -------------------------------------------------------------------
  539. // Plugin processing
  540. /*!
  541. * Plugin activate call.
  542. */
  543. virtual void activate() noexcept;
  544. /*!
  545. * Plugin activate call.
  546. */
  547. virtual void deactivate() noexcept;
  548. /*!
  549. * Plugin process call.
  550. */
  551. virtual void process(float** const inBuffer, float** const outBuffer, const uint32_t frames) = 0;
  552. /*!
  553. * Tell the plugin the current buffer size changed.
  554. */
  555. virtual void bufferSizeChanged(const uint32_t newBufferSize);
  556. /*!
  557. * Tell the plugin the current sample rate changed.
  558. */
  559. virtual void sampleRateChanged(const double newSampleRate);
  560. /*!
  561. * Tell the plugin the current offline mode changed.
  562. */
  563. virtual void offlineModeChanged(const bool isOffline);
  564. #if 0
  565. /*!
  566. * Lock the plugin's master mutex.
  567. */
  568. void lock();
  569. #endif
  570. /*!
  571. * Try to lock the plugin's master mutex.
  572. * @param forcedOffline When true, always locks and returns true
  573. */
  574. bool tryLock(const bool forcedOffline) noexcept;
  575. /*!
  576. * Unlock the plugin's master mutex.
  577. */
  578. void unlock() noexcept;
  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() noexcept;
  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. virtual 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 (IFF 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, idle()) 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) noexcept;
  638. /*!
  639. * Tell the UI the current program has changed.
  640. */
  641. virtual void uiProgramChange(const uint32_t index) noexcept;
  642. /*!
  643. * Tell the UI the current midi program has changed.
  644. */
  645. virtual void uiMidiProgramChange(const uint32_t index) noexcept;
  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) noexcept;
  650. /*!
  651. * Tell the UI a note has been released.
  652. */
  653. virtual void uiNoteOff(const uint8_t channel, const uint8_t note) noexcept;
  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 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. const int64_t uniqueId;
  701. };
  702. static size_t getNativePluginCount() noexcept;
  703. static const NativePluginDescriptor* getNativePluginDescriptor(const size_t index) noexcept;
  704. static CarlaPlugin* newNative(const Initializer& init);
  705. static CarlaPlugin* newBridge(const Initializer& init, const BinaryType btype, const PluginType ptype, const char* const bridgeBinary);
  706. static CarlaPlugin* newLADSPA(const Initializer& init, const LADSPA_RDF_Descriptor* const rdfDescriptor);
  707. static CarlaPlugin* newDSSI(const Initializer& init);
  708. static CarlaPlugin* newLV2(const Initializer& init);
  709. static CarlaPlugin* newVST(const Initializer& init);
  710. static CarlaPlugin* newVST3(const Initializer& init);
  711. static CarlaPlugin* newAU(const Initializer& init);
  712. static CarlaPlugin* newJACK(const Initializer& init);
  713. static CarlaPlugin* newReWire(const Initializer& init);
  714. static CarlaPlugin* newCsound(const Initializer& init);
  715. static CarlaPlugin* newJuce(const Initializer& init, const char* const format);
  716. static CarlaPlugin* newFluidSynth(const Initializer& init, const bool use16Outs);
  717. static CarlaPlugin* newLinuxSampler(const Initializer& init, const char* const format, const bool use16Outs);
  718. static CarlaPlugin* newFileCSD(const Initializer& init);
  719. static CarlaPlugin* newFileGIG(const Initializer& init, const bool use16Outs);
  720. static CarlaPlugin* newFileSF2(const Initializer& init, const bool use16Outs);
  721. static CarlaPlugin* newFileSFZ(const Initializer& init);
  722. #endif
  723. // -------------------------------------------------------------------
  724. protected:
  725. /*!
  726. * Internal data, for CarlaPlugin subclasses only.
  727. */
  728. CarlaPluginProtectedData* const pData;
  729. friend struct CarlaPluginProtectedData;
  730. // -------------------------------------------------------------------
  731. // Helper classes
  732. /*!
  733. * Fully disable plugin in scope and also its engine client.\n
  734. * May wait-block on constructor for plugin process to end.
  735. */
  736. class ScopedDisabler
  737. {
  738. public:
  739. ScopedDisabler(CarlaPlugin* const plugin) noexcept;
  740. ~ScopedDisabler() noexcept;
  741. private:
  742. CarlaPlugin* const fPlugin;
  743. CARLA_PREVENT_HEAP_ALLOCATION
  744. CARLA_DECLARE_NON_COPY_CLASS(ScopedDisabler)
  745. };
  746. /*!
  747. * Lock the plugin's own run/process call.\n
  748. * Plugin will still work as normal, but output only silence.\n
  749. * On destructor needsReset flag might be set if the plugin might have missed some events.
  750. */
  751. class ScopedSingleProcessLocker
  752. {
  753. public:
  754. ScopedSingleProcessLocker(CarlaPlugin* const plugin, const bool block) noexcept;
  755. ~ScopedSingleProcessLocker() noexcept;
  756. private:
  757. CarlaPlugin* const fPlugin;
  758. const bool fBlock;
  759. CARLA_PREVENT_HEAP_ALLOCATION
  760. CARLA_DECLARE_NON_COPY_CLASS(ScopedSingleProcessLocker)
  761. };
  762. CARLA_DECLARE_NON_COPY_CLASS(CarlaPlugin)
  763. };
  764. /**@}*/
  765. // -----------------------------------------------------------------------
  766. CARLA_BACKEND_END_NAMESPACE
  767. #endif // CARLA_PLUGIN_HPP_INCLUDED