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

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