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.

1069 lines
32KB

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