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.

CarlaPlugin.hpp 32KB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084
  1. /*
  2. * Carla Plugin Host
  3. * Copyright (C) 2011-2023 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. #include "CarlaPluginPtr.hpp"
  21. // -----------------------------------------------------------------------
  22. // Avoid including extra libs here
  23. typedef void* lo_message;
  24. typedef struct _NativePluginDescriptor NativePluginDescriptor;
  25. struct LADSPA_RDF_Descriptor;
  26. // -----------------------------------------------------------------------
  27. CARLA_BACKEND_START_NAMESPACE
  28. #ifdef _MSC_VER
  29. # define CARLA_PLUGIN_WARN_UNUSED_RESULT
  30. #else
  31. # define CARLA_PLUGIN_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
  32. #endif
  33. // -----------------------------------------------------------------------
  34. /*!
  35. * @defgroup CarlaPluginAPI Carla Plugin API
  36. *
  37. * The Carla Plugin API.
  38. * @{
  39. */
  40. class CarlaEngineAudioPort;
  41. class CarlaEngineCVPort;
  42. class CarlaEngineEventPort;
  43. class CarlaEngineCVSourcePorts;
  44. class CarlaEngineBridge;
  45. struct CarlaStateSave;
  46. struct EngineEvent;
  47. // -----------------------------------------------------------------------
  48. /*!
  49. * Carla Backend base plugin class
  50. *
  51. * This is the base class for all available plugin types available in Carla Backend.
  52. * All virtual calls are implemented in this class as fallback (except reload and process),
  53. * so it's safe to only override needed calls.
  54. *
  55. * @see PluginType
  56. */
  57. class CARLA_API 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* engine, uint 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".
  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. uint getId() const noexcept;
  91. /*!
  92. * Get the plugin's hints.
  93. *
  94. * @see PluginHints
  95. */
  96. uint getHints() const noexcept;
  97. /*!
  98. * Get the plugin's options (currently in use).
  99. *
  100. * @see PluginOptions, getOptionsAvailable() and setOption()
  101. */
  102. uint getOptionsEnabled() const noexcept;
  103. /*!
  104. * Check if the plugin is enabled.
  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.
  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.
  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.
  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. virtual 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 CV inputs.
  151. */
  152. uint32_t getCVInCount() const noexcept;
  153. /*!
  154. * Get the number of CV outputs.
  155. */
  156. uint32_t getCVOutCount() const noexcept;
  157. /*!
  158. * Get the number of MIDI inputs.
  159. */
  160. virtual uint32_t getMidiInCount() const noexcept;
  161. /*!
  162. * Get the number of MIDI outputs.
  163. */
  164. virtual uint32_t getMidiOutCount() const noexcept;
  165. /*!
  166. * Get the number of parameters.
  167. * To know the number of parameter inputs and outputs separately use getParameterCountInfo() instead.
  168. */
  169. uint32_t getParameterCount() const noexcept;
  170. /*!
  171. * Get the number of scalepoints for parameter @a parameterId.
  172. */
  173. virtual uint32_t getParameterScalePointCount(uint32_t parameterId) const noexcept;
  174. /*!
  175. * Get the number of programs.
  176. */
  177. uint32_t getProgramCount() const noexcept;
  178. /*!
  179. * Get the number of MIDI programs.
  180. */
  181. uint32_t getMidiProgramCount() const noexcept;
  182. /*!
  183. * Get the number of custom data sets.
  184. */
  185. uint32_t getCustomDataCount() const noexcept;
  186. // -------------------------------------------------------------------
  187. // Information (current data)
  188. /*!
  189. * Get the current program number (-1 if unset).
  190. *
  191. * @see setProgram()
  192. */
  193. int32_t getCurrentProgram() const noexcept;
  194. /*!
  195. * Get the current MIDI program number (-1 if unset).
  196. *
  197. * @see setMidiProgram()
  198. * @see setMidiProgramById()
  199. */
  200. int32_t getCurrentMidiProgram() const noexcept;
  201. /*!
  202. * Get hints about an audio port.
  203. */
  204. virtual uint getAudioPortHints(bool isOutput, uint32_t portIndex) const noexcept;
  205. /*!
  206. * Get the parameter data of @a parameterId.
  207. */
  208. const ParameterData& getParameterData(uint32_t parameterId) const noexcept;
  209. /*!
  210. * Get the parameter ranges of @a parameterId.
  211. */
  212. const ParameterRanges& getParameterRanges(uint32_t parameterId) const noexcept;
  213. /*!
  214. * Check if parameter @a parameterId is of output type.
  215. */
  216. bool isParameterOutput(uint32_t parameterId) const noexcept;
  217. /*!
  218. * Get the MIDI program at @a index.
  219. *
  220. * @see getMidiProgramName()
  221. */
  222. const MidiProgramData& getMidiProgramData(uint32_t index) const noexcept;
  223. /*!
  224. * Get the custom data set at @a index.
  225. *
  226. * @see getCustomDataCount() and setCustomData()
  227. */
  228. const CustomData& getCustomData(uint32_t index) const noexcept;
  229. /*!
  230. * Get the complete plugin chunk data into @a dataPtr.
  231. *
  232. * @note Make sure to verify the plugin supports chunks before calling this function!
  233. * @return The size of the chunk or 0 if invalid.
  234. *
  235. * @see setChunkData()
  236. */
  237. virtual std::size_t getChunkData(void** dataPtr) noexcept;
  238. // -------------------------------------------------------------------
  239. // Information (per-plugin data)
  240. /*!
  241. * Get the plugin available options.
  242. *
  243. * @see PluginOptions, getOptions() and setOption()
  244. */
  245. virtual uint getOptionsAvailable() const noexcept;
  246. /*!
  247. * Get the current parameter value of @a parameterId.
  248. */
  249. virtual float getParameterValue(uint32_t parameterId) const noexcept;
  250. /*!
  251. * Get the scalepoint @a scalePointId value of the parameter @a parameterId.
  252. */
  253. virtual float getParameterScalePointValue(uint32_t parameterId, uint32_t scalePointId) const noexcept;
  254. /*!
  255. * Get the plugin's label (URI for LV2 plugins).
  256. */
  257. CARLA_PLUGIN_WARN_UNUSED_RESULT
  258. virtual bool getLabel(char* strBuf) const noexcept;
  259. /*!
  260. * Get the plugin's maker.
  261. */
  262. CARLA_PLUGIN_WARN_UNUSED_RESULT
  263. virtual bool getMaker(char* strBuf) const noexcept;
  264. /*!
  265. * Get the plugin's copyright/license.
  266. */
  267. CARLA_PLUGIN_WARN_UNUSED_RESULT
  268. virtual bool getCopyright(char* strBuf) const noexcept;
  269. /*!
  270. * Get the plugin's (real) name.
  271. *
  272. * @see getName() and setName()
  273. */
  274. CARLA_PLUGIN_WARN_UNUSED_RESULT
  275. virtual bool getRealName(char* strBuf) const noexcept;
  276. /*!
  277. * Get the name of the parameter @a parameterId.
  278. */
  279. CARLA_PLUGIN_WARN_UNUSED_RESULT
  280. virtual bool getParameterName(uint32_t parameterId, char* strBuf) const noexcept;
  281. /*!
  282. * Get the symbol of the parameter @a parameterId.
  283. */
  284. CARLA_PLUGIN_WARN_UNUSED_RESULT
  285. virtual bool getParameterSymbol(uint32_t parameterId, char* strBuf) const noexcept;
  286. /*!
  287. * Get the custom text of the parameter @a parameterId.
  288. * @see PARAMETER_USES_CUSTOM_TEXT
  289. */
  290. CARLA_PLUGIN_WARN_UNUSED_RESULT
  291. virtual bool getParameterText(uint32_t parameterId, char* strBuf) noexcept;
  292. /*!
  293. * Get the unit of the parameter @a parameterId.
  294. */
  295. CARLA_PLUGIN_WARN_UNUSED_RESULT
  296. virtual bool getParameterUnit(uint32_t parameterId, char* strBuf) const noexcept;
  297. /*!
  298. * Get the comment (documentation) of the parameter @a parameterId.
  299. */
  300. CARLA_PLUGIN_WARN_UNUSED_RESULT
  301. virtual bool getParameterComment(uint32_t parameterId, char* strBuf) const noexcept;
  302. /*!
  303. * Get the group name of the parameter @a parameterId.
  304. * @note The group name is prefixed by a unique symbol and ":".
  305. */
  306. CARLA_PLUGIN_WARN_UNUSED_RESULT
  307. virtual bool getParameterGroupName(uint32_t parameterId, char* strBuf) const noexcept;
  308. /*!
  309. * Get the scalepoint @a scalePointId label of the parameter @a parameterId.
  310. */
  311. CARLA_PLUGIN_WARN_UNUSED_RESULT
  312. virtual bool getParameterScalePointLabel(uint32_t parameterId, uint32_t scalePointId, char* strBuf) const noexcept;
  313. /*!
  314. * Get the current parameter value of @a parameterId.
  315. * @a parameterId can be negative to allow internal parameters.
  316. * @see InternalParametersIndex
  317. */
  318. float getInternalParameterValue(int32_t parameterId) const noexcept;
  319. /*!
  320. * Get the name of the program at @a index.
  321. */
  322. CARLA_PLUGIN_WARN_UNUSED_RESULT
  323. bool getProgramName(uint32_t index, char* strBuf) const noexcept;
  324. /*!
  325. * Get the name of the MIDI program at @a index.
  326. *
  327. * @see getMidiProgramInfo()
  328. */
  329. CARLA_PLUGIN_WARN_UNUSED_RESULT
  330. bool getMidiProgramName(uint32_t index, char* strBuf) const noexcept;
  331. /*!
  332. * Get information about the plugin's parameter count.
  333. * This is used to check how many input, output and total parameters are available.
  334. *
  335. * @note Some parameters might not be input or output (ie, invalid).
  336. *
  337. * @see getParameterCount()
  338. */
  339. void getParameterCountInfo(uint32_t& ins, uint32_t& outs) const noexcept;
  340. // -------------------------------------------------------------------
  341. // Set data (state)
  342. /*!
  343. * Tell the plugin to prepare for save.
  344. * @param temporary Wherever we are saving into a temporary location
  345. * (for duplication, renaming or similar)
  346. */
  347. virtual void prepareForSave(bool temporary);
  348. /*!
  349. * Reset all possible parameters.
  350. */
  351. virtual void resetParameters() noexcept;
  352. /*!
  353. * Randomize all possible parameters.
  354. */
  355. virtual void randomizeParameters() noexcept;
  356. /*!
  357. * Get the plugin's save state.
  358. * The plugin will automatically call prepareForSave() if requested.
  359. *
  360. * @see loadStateSave()
  361. */
  362. const CarlaStateSave& getStateSave(bool callPrepareForSave = true);
  363. /*!
  364. * Get the plugin's save state.
  365. *
  366. * @see getStateSave()
  367. */
  368. void loadStateSave(const CarlaStateSave& stateSave);
  369. /*!
  370. * Save the current plugin state to @a filename.
  371. *
  372. * @see loadStateFromFile()
  373. */
  374. bool saveStateToFile(const char* filename);
  375. /*!
  376. * Save the plugin state from @a filename.
  377. *
  378. * @see saveStateToFile()
  379. */
  380. bool loadStateFromFile(const char* filename);
  381. #ifndef CARLA_PLUGIN_ONLY_BRIDGE
  382. /*!
  383. * Export this plugin as its own LV2 plugin, using a carla wrapper around it for the LV2 functionality.
  384. */
  385. bool exportAsLV2(const char* lv2path);
  386. #endif
  387. // -------------------------------------------------------------------
  388. // Set data (internal stuff)
  389. /*!
  390. * Set the plugin's id to @a newId.
  391. *
  392. * @see getId()
  393. * @note RT call
  394. */
  395. virtual void setId(uint newId) noexcept;
  396. /*!
  397. * Set the plugin's name to @a newName.
  398. *
  399. * @see getName() and getRealName()
  400. */
  401. virtual void setName(const char* newName);
  402. /*!
  403. * Set a plugin's option.
  404. *
  405. * @see getOptions() and getOptionsAvailable()
  406. */
  407. virtual void setOption(uint option, bool yesNo, bool sendCallback);
  408. /*!
  409. * Enable or disable the plugin according to @a yesNo.
  410. * When a plugin is disabled, it will never be processed or managed in any way.
  411. *
  412. * @see isEnabled()
  413. */
  414. void setEnabled(bool yesNo) noexcept;
  415. /*!
  416. * Set plugin as active according to @a active.
  417. *
  418. * @param sendOsc Send message change over OSC
  419. * @param sendCallback Send message change to registered callback
  420. */
  421. void setActive(bool active, bool sendOsc, bool sendCallback) noexcept;
  422. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  423. /*!
  424. * Set the plugin's dry/wet signal value to @a value.
  425. * @a value must be between 0.0 and 1.0.
  426. *
  427. * @param sendOsc Send message change over OSC
  428. * @param sendCallback Send message change to registered callback
  429. */
  430. void setDryWet(float value, bool sendOsc, bool sendCallback) noexcept;
  431. /*!
  432. * Set the plugin's output volume to @a value.
  433. * @a value must be between 0.0 and 1.27.
  434. *
  435. * @param sendOsc Send message change over OSC
  436. * @param sendCallback Send message change to registered callback
  437. */
  438. void setVolume(float value, bool sendOsc, bool sendCallback) noexcept;
  439. /*!
  440. * Set the plugin's output left balance value to @a value.
  441. * @a value must be between -1.0 and 1.0.
  442. *
  443. * @param sendOsc Send message change over OSC
  444. * @param sendCallback Send message change to registered callback
  445. *
  446. * @note Pure-Stereo plugins only!
  447. */
  448. void setBalanceLeft(float value, bool sendOsc, bool sendCallback) noexcept;
  449. /*!
  450. * Set the plugin's output right balance value to @a value.
  451. * @a value must be between -1.0 and 1.0.
  452. *
  453. * @param sendOsc Send message change over OSC
  454. * @param sendCallback Send message change to registered callback
  455. *
  456. * @note Pure-Stereo plugins only!
  457. */
  458. void setBalanceRight(float value, bool sendOsc, bool sendCallback) noexcept;
  459. /*!
  460. * Set the plugin's output panning value to @a value.
  461. * @a value must be between -1.0 and 1.0.
  462. *
  463. * @param sendOsc Send message change over OSC
  464. * @param sendCallback Send message change to registered callback
  465. *
  466. * @note Force-Stereo plugins only!
  467. */
  468. void setPanning(float value, bool sendOsc, bool sendCallback) noexcept;
  469. /*!
  470. * Overloaded functions, to be called from within RT context only.
  471. */
  472. void setDryWetRT(float value, bool sendCallbackLater) noexcept;
  473. void setVolumeRT(float value, bool sendCallbackLater) noexcept;
  474. void setBalanceLeftRT(float value, bool sendCallbackLater) noexcept;
  475. void setBalanceRightRT(float value, bool sendCallbackLater) noexcept;
  476. void setPanningRT(float value, bool sendCallbackLater) noexcept;
  477. #endif // ! BUILD_BRIDGE_ALTERNATIVE_ARCH
  478. /*!
  479. * Set the plugin's midi control channel.
  480. *
  481. * @param sendOsc Send message change over OSC
  482. * @param sendCallback Send message change to registered callback
  483. */
  484. virtual void setCtrlChannel(int8_t channel, bool sendOsc, bool sendCallback) noexcept;
  485. // -------------------------------------------------------------------
  486. // Set data (plugin-specific stuff)
  487. /*!
  488. * Set a plugin's parameter value.
  489. *
  490. * @param parameterId The parameter to change
  491. * @param value The new parameter value, must be within the parameter's range
  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. *
  496. * @see getParameterValue()
  497. */
  498. virtual void setParameterValue(uint32_t parameterId, float value, bool sendGui, bool sendOsc, bool sendCallback) noexcept;
  499. /*!
  500. * Overloaded function, to be called from within RT context only.
  501. */
  502. virtual void setParameterValueRT(uint32_t parameterId, float value, uint32_t frameOffset, bool sendCallbackLater) noexcept;
  503. /*!
  504. * Set a plugin's parameter value, including internal parameters.
  505. * @a rindex can be negative to allow internal parameters change (as defined in InternalParametersIndex).
  506. *
  507. * @see setParameterValue()
  508. * @see setActive()
  509. * @see setDryWet()
  510. * @see setVolume()
  511. * @see setBalanceLeft()
  512. * @see setBalanceRight()
  513. */
  514. void setParameterValueByRealIndex(int32_t rindex, float value, bool sendGui, bool sendOsc, bool sendCallback) noexcept;
  515. /*!
  516. * Set parameter's @a parameterId MIDI channel to @a channel.
  517. * @a channel must be between 0 and 15.
  518. */
  519. virtual void setParameterMidiChannel(uint32_t parameterId, uint8_t channel, bool sendOsc, bool sendCallback) noexcept;
  520. /*!
  521. * Set parameter's @a parameterId mapped control index to @a index.
  522. * @see ParameterData::mappedControlIndex
  523. */
  524. virtual void setParameterMappedControlIndex(uint32_t parameterId, int16_t index,
  525. bool sendOsc, bool sendCallback, bool reconfigureNow) noexcept;
  526. /*!
  527. * Set parameter's @a parameterId mapped range to @a minimum and @a maximum.
  528. */
  529. virtual void setParameterMappedRange(uint32_t parameterId, float minimum, float maximum,
  530. bool sendOsc, bool sendCallback) noexcept;
  531. /*!
  532. * Add a custom data set.
  533. * If @a key already exists, its current value will be swapped with @a value.
  534. *
  535. * @param type Type of data used in @a value.
  536. * @param key A key identifying this data set.
  537. * @param value The value of the data set, of type @a type.
  538. * @param sendGui Send message change to plugin's custom GUI, if any
  539. *
  540. * @see getCustomDataCount() and getCustomData()
  541. */
  542. virtual void setCustomData(const char* type, const char* key, const char* value, bool sendGui);
  543. /*!
  544. * Set the complete chunk data as @a data.
  545. *
  546. * @see getChunkData()
  547. *
  548. * @note Make sure to verify the plugin supports chunks before calling this function
  549. */
  550. virtual void setChunkData(const void* data, std::size_t dataSize);
  551. /*!
  552. * Change the current plugin program to @a index.
  553. *
  554. * If @a index is negative the plugin's program will be considered unset.
  555. * The plugin's default parameter values will be updated when this function is called.
  556. *
  557. * @param index New program index to use
  558. * @param sendGui Send message change to plugin's custom GUI, if any
  559. * @param sendOsc Send message change over OSC
  560. * @param sendCallback Send message change to registered callback
  561. */
  562. virtual void setProgram(int32_t index, bool sendGui, bool sendOsc, bool sendCallback, bool doingInit = false) noexcept;
  563. /*!
  564. * Change the current MIDI plugin program to @a index.
  565. *
  566. * If @a index is negative the plugin's program will be considered unset.
  567. * The plugin's default parameter values will be updated when this function is called.
  568. *
  569. * @param index New program index to use
  570. * @param sendGui Send message change to plugin's custom GUI, if any
  571. * @param sendOsc Send message change over OSC
  572. * @param sendCallback Send message change to registered callback
  573. */
  574. virtual void setMidiProgram(int32_t index, bool sendGui, bool sendOsc, bool sendCallback, bool doingInit = false) noexcept;
  575. /*!
  576. * This is an overloaded call to setMidiProgram().
  577. * It changes the current MIDI program using @a bank and @a program values instead of index.
  578. */
  579. void setMidiProgramById(uint32_t bank, uint32_t program, bool sendGui, bool sendOsc, bool sendCallback) noexcept;
  580. /*!
  581. * Overloaded functions, to be called from within RT context only.
  582. */
  583. virtual void setProgramRT(uint32_t index, bool sendCallbackLater) noexcept;
  584. virtual void setMidiProgramRT(uint32_t index, bool sendCallbackLater) noexcept;
  585. // -------------------------------------------------------------------
  586. // Plugin state
  587. /*!
  588. * Reload the plugin's entire state (including programs).
  589. * The plugin will be disabled during this call.
  590. */
  591. virtual void reload() = 0;
  592. /*!
  593. * Reload the plugin's programs state.
  594. */
  595. virtual void reloadPrograms(bool doInit);
  596. // -------------------------------------------------------------------
  597. // Plugin processing
  598. protected:
  599. /*!
  600. * Plugin activate call.
  601. */
  602. virtual void activate() noexcept;
  603. /*!
  604. * Plugin activate call.
  605. */
  606. virtual void deactivate() noexcept;
  607. public:
  608. /*!
  609. * Plugin process call.
  610. */
  611. virtual void process(const float* const* audioIn, float** audioOut,
  612. const float* const* cvIn, float** cvOut, uint32_t frames) = 0;
  613. /*!
  614. * Tell the plugin the current buffer size changed.
  615. */
  616. virtual void bufferSizeChanged(uint32_t newBufferSize);
  617. /*!
  618. * Tell the plugin the current sample rate changed.
  619. */
  620. virtual void sampleRateChanged(double newSampleRate);
  621. /*!
  622. * Tell the plugin the current offline mode changed.
  623. */
  624. virtual void offlineModeChanged(bool isOffline);
  625. // -------------------------------------------------------------------
  626. // Misc
  627. /*!
  628. * Idle function (non-UI), called at regular intervals.
  629. * @note: This function is NOT called from the main thread.
  630. */
  631. virtual void idle();
  632. /*!
  633. * Try to lock the plugin's master mutex.
  634. * @param forcedOffline When true, always locks and returns true
  635. */
  636. bool tryLock(bool forcedOffline) noexcept;
  637. /*!
  638. * Unlock the plugin's master mutex.
  639. */
  640. void unlock() noexcept;
  641. // -------------------------------------------------------------------
  642. // Plugin buffers
  643. /*!
  644. * Initialize all RT buffers of the plugin.
  645. */
  646. virtual void initBuffers() const noexcept;
  647. /*!
  648. * Delete and clear all RT buffers.
  649. */
  650. virtual void clearBuffers() noexcept;
  651. // -------------------------------------------------------------------
  652. // OSC stuff
  653. /*!
  654. * Handle an OSC message.
  655. * FIXME
  656. */
  657. virtual void handleOscMessage(const char* method,
  658. int argc,
  659. const void* argv,
  660. const char* types,
  661. lo_message msg);
  662. // -------------------------------------------------------------------
  663. // MIDI events
  664. /*!
  665. * Send a single midi note to be processed in the next audio callback.
  666. * A note with 0 velocity means note-off.
  667. * @note Non-RT call
  668. */
  669. void sendMidiSingleNote(uint8_t channel, uint8_t note, uint8_t velo,
  670. bool sendGui, bool sendOsc, bool sendCallback);
  671. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  672. /*!
  673. * Send all midi notes off to the host callback.
  674. * This doesn't send the actual MIDI All-Notes-Off event, but 128 note-offs instead (IFF ctrlChannel is valid).
  675. * @note RT call
  676. */
  677. void postponeRtAllNotesOff();
  678. #endif
  679. // -------------------------------------------------------------------
  680. // UI Stuff
  681. /*!
  682. * Set a custom title for the plugin UI window created by Carla.
  683. */
  684. virtual void setCustomUITitle(const char* title) noexcept;
  685. /*!
  686. * Show (or hide) the plugin's custom UI according to @a yesNo.
  687. * This function is always called from the main thread.
  688. */
  689. virtual void showCustomUI(bool yesNo);
  690. /*!
  691. * Embed the plugin's custom UI to the system pointer @a ptr.
  692. * This function is always called from the main thread.
  693. * @note This is very experimental and subject to change at this point
  694. */
  695. virtual void* embedCustomUI(void* ptr);
  696. /*!
  697. * UI idle function, called at regular intervals.
  698. * This function is only called from the main thread if PLUGIN_NEEDS_UI_MAIN_THREAD is set.
  699. * @note This function may sometimes be called even if the UI is not visible yet.
  700. */
  701. virtual void uiIdle();
  702. /*!
  703. * Tell the UI a parameter has changed.
  704. * @see uiIdle
  705. */
  706. virtual void uiParameterChange(uint32_t index, float value) noexcept;
  707. /*!
  708. * Tell the UI the current program has changed.
  709. * @see uiIdle
  710. */
  711. virtual void uiProgramChange(uint32_t index) noexcept;
  712. /*!
  713. * Tell the UI the current midi program has changed.
  714. * @see uiIdle
  715. */
  716. virtual void uiMidiProgramChange(uint32_t index) noexcept;
  717. /*!
  718. * Tell the UI a note has been pressed.
  719. * @see uiIdle
  720. */
  721. virtual void uiNoteOn(uint8_t channel, uint8_t note, uint8_t velo) noexcept;
  722. /*!
  723. * Tell the UI a note has been released.
  724. * @see uiIdle
  725. */
  726. virtual void uiNoteOff(uint8_t channel, uint8_t note) noexcept;
  727. // -------------------------------------------------------------------
  728. // Helper functions
  729. /*!
  730. * Get the plugin's engine, as passed in the constructor.
  731. */
  732. CarlaEngine* getEngine() const noexcept;
  733. /*!
  734. * Get the plugin's engine client.
  735. */
  736. CarlaEngineClient* getEngineClient() const noexcept;
  737. /*!
  738. * Get a plugin's audio input port.
  739. */
  740. CarlaEngineAudioPort* getAudioInPort(uint32_t index) const noexcept;
  741. /*!
  742. * Get a plugin's audio output port.
  743. */
  744. CarlaEngineAudioPort* getAudioOutPort(uint32_t index) const noexcept;
  745. /*!
  746. * Get a plugin's CV input port.
  747. */
  748. CarlaEngineCVPort* getCVInPort(uint32_t index) const noexcept;
  749. /*!
  750. * Get a plugin's CV output port.
  751. */
  752. CarlaEngineCVPort* getCVOutPort(uint32_t index) const noexcept;
  753. /*!
  754. * Get the plugin's default event input port.
  755. */
  756. CarlaEngineEventPort* getDefaultEventInPort() const noexcept;
  757. /*!
  758. * Get the plugin's default event output port.
  759. */
  760. CarlaEngineEventPort* getDefaultEventOutPort() const noexcept;
  761. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  762. /*!
  763. * Check if the plugin is interested on MIDI learn, and if so, map this event to the parameter that wants it.
  764. * Event MUST be of control type and not have been handled before.
  765. */
  766. void checkForMidiLearn(EngineEvent& event) noexcept;
  767. #endif
  768. /*!
  769. * Get the plugin's type native handle.
  770. * This will be LADSPA_Handle, LV2_Handle, etc.
  771. */
  772. virtual void* getNativeHandle() const noexcept;
  773. /*!
  774. * Get the plugin's type native descriptor.
  775. * This will be LADSPA_Descriptor, DSSI_Descriptor, LV2_Descriptor, AEffect, etc.
  776. */
  777. virtual const void* getNativeDescriptor() const noexcept;
  778. /*!
  779. * Get the plugin UI bridge process Id.
  780. */
  781. virtual uintptr_t getUiBridgeProcessId() const noexcept;
  782. // -------------------------------------------------------------------
  783. /*!
  784. * Get the plugin's patchbay nodeId.
  785. * @see setPatchbayNodeId()
  786. */
  787. uint32_t getPatchbayNodeId() const noexcept;
  788. /*!
  789. * Set the plugin's patchbay nodeId.
  790. * @see getPatchbayNodeId()
  791. */
  792. void setPatchbayNodeId(uint32_t nodeId) noexcept;
  793. // -------------------------------------------------------------------
  794. // Plugin initializers
  795. /*!
  796. * Get a plugin's binary type.
  797. * This is always BINARY_NATIVE unless the plugin is a bridge.
  798. */
  799. virtual BinaryType getBinaryType() const noexcept
  800. {
  801. return BINARY_NATIVE;
  802. }
  803. /*!
  804. * Handy function required by CarlaEngine::clonePlugin().
  805. */
  806. virtual const void* getExtraStuff() const noexcept
  807. {
  808. return nullptr;
  809. }
  810. #ifndef DOXYGEN
  811. struct Initializer {
  812. CarlaEngine* const engine;
  813. const uint id;
  814. const char* const filename;
  815. const char* const name;
  816. const char* const label;
  817. const int64_t uniqueId;
  818. const uint options; // see PluginOptions
  819. };
  820. static CarlaPluginPtr newBridge(const Initializer& init,
  821. BinaryType btype, PluginType ptype,
  822. const char* binaryArchName, const char* bridgeBinary);
  823. #ifndef CARLA_PLUGIN_ONLY_BRIDGE
  824. static CarlaPluginPtr newNative(const Initializer& init);
  825. static CarlaPluginPtr newLADSPA(const Initializer& init, const LADSPA_RDF_Descriptor* rdfDescriptor);
  826. static CarlaPluginPtr newDSSI(const Initializer& init);
  827. static CarlaPluginPtr newLV2(const Initializer& init);
  828. static CarlaPluginPtr newVST2(const Initializer& init);
  829. static CarlaPluginPtr newVST3(const Initializer& init);
  830. static CarlaPluginPtr newAU(const Initializer& init);
  831. static CarlaPluginPtr newJSFX(const Initializer& init);
  832. static CarlaPluginPtr newCLAP(const Initializer& init);
  833. static CarlaPluginPtr newJuce(const Initializer& init, const char* format);
  834. static CarlaPluginPtr newFluidSynth(const Initializer& init, PluginType ptype, bool use16Outs);
  835. static CarlaPluginPtr newSFZero(const Initializer& init);
  836. static CarlaPluginPtr newJackApp(const Initializer& init);
  837. #endif
  838. #endif
  839. // -------------------------------------------------------------------
  840. protected:
  841. /*!
  842. * Internal data, for CarlaPlugin subclasses only.
  843. */
  844. struct ProtectedData;
  845. ProtectedData* const pData;
  846. // -------------------------------------------------------------------
  847. // Internal helper functions
  848. protected:
  849. /*!
  850. * Clone/copy files from another LV2 plugin into this one..
  851. */
  852. virtual void cloneLV2Files(const CarlaPlugin& other);
  853. /*!
  854. * Call LV2 restore.
  855. * @param temporary Wherever we are saving into a temporary location
  856. * (for duplication, renaming or similar)
  857. */
  858. virtual void restoreLV2State(bool temporary) noexcept;
  859. /*!
  860. * Allow engine to signal that plugin will be deleted soon.
  861. */
  862. virtual void prepareForDeletion() noexcept;
  863. /*!
  864. * Give plugin bridges a change to update their custom data sets.
  865. */
  866. virtual void waitForBridgeSaveSignal() noexcept;
  867. // -------------------------------------------------------------------
  868. // Helper classes
  869. /*!
  870. * Fully disable plugin in scope and also its engine client.
  871. * May wait-block on constructor for plugin process to end.
  872. */
  873. class ScopedDisabler
  874. {
  875. public:
  876. ScopedDisabler(CarlaPlugin* plugin) noexcept;
  877. ~ScopedDisabler() noexcept;
  878. private:
  879. CarlaPlugin* const fPlugin;
  880. bool fWasEnabled;
  881. CARLA_PREVENT_HEAP_ALLOCATION
  882. CARLA_DECLARE_NON_COPYABLE(ScopedDisabler)
  883. };
  884. /*!
  885. * Lock the plugin's own run/process call.
  886. * Plugin will still work as normal, but output only silence.
  887. * On destructor needsReset flag might be set if the plugin might have missed some events.
  888. */
  889. class ScopedSingleProcessLocker
  890. {
  891. public:
  892. ScopedSingleProcessLocker(CarlaPlugin* plugin, bool block) noexcept;
  893. ~ScopedSingleProcessLocker() noexcept;
  894. private:
  895. CarlaPlugin* const fPlugin;
  896. const bool fBlock;
  897. CARLA_PREVENT_HEAP_ALLOCATION
  898. CARLA_DECLARE_NON_COPYABLE(ScopedSingleProcessLocker)
  899. };
  900. friend class CarlaEngine;
  901. friend class CarlaEngineBridge;
  902. CARLA_DECLARE_NON_COPYABLE(CarlaPlugin)
  903. };
  904. /**@}*/
  905. // -----------------------------------------------------------------------
  906. CARLA_BACKEND_END_NAMESPACE
  907. #endif // CARLA_PLUGIN_HPP_INCLUDED