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.

1026 lines
30KB

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