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.

1076 lines
32KB

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