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.

1006 lines
30KB

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