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