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 30KB

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