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.

1073 lines
32KB

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