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.

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