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.

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