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