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.

1084 lines
32KB

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