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

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