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