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

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