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.

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