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.

984 lines
29KB

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