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.

1056 lines
31KB

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