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.

1036 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. * Change parameter's @a parameterId CV controlled status.
  504. */
  505. void setParameterAsCvControl(uint32_t parameterId, bool cv_controlled, bool sendOsc, bool sendCallback) noexcept;
  506. /*!
  507. * Set parameter's @a parameterId MIDI channel to @a channel.
  508. * @a channel must be between 0 and 15.
  509. */
  510. virtual void setParameterMidiChannel(uint32_t parameterId, uint8_t channel, bool sendOsc, bool sendCallback) noexcept;
  511. /*!
  512. * Set parameter's @a parameterId MIDI CC to @a cc.
  513. * @a cc must be between 0 and 119 (0x77), or -1 for invalid.
  514. */
  515. virtual void setParameterMidiCC(uint32_t parameterId, int16_t cc, bool sendOsc, bool sendCallback) noexcept;
  516. /*!
  517. * Set parameter's @a parameterId mapped range to @a minimum and @a maximum.
  518. */
  519. virtual void setParameterMappedRange(uint32_t parameterId, float minimum, float maximum, bool sendOsc, bool sendCallback) noexcept;
  520. /*!
  521. * Add a custom data set.
  522. * If @a key already exists, its current value will be swapped with @a value.
  523. *
  524. * @param type Type of data used in @a value.
  525. * @param key A key identifying this data set.
  526. * @param value The value of the data set, of type @a type.
  527. * @param sendGui Send message change to plugin's custom GUI, if any
  528. *
  529. * @see getCustomDataCount() and getCustomData()
  530. */
  531. virtual void setCustomData(const char* type, const char* key, const char* value, bool sendGui);
  532. /*!
  533. * Set the complete chunk data as @a data.
  534. *
  535. * @see getChunkData()
  536. *
  537. * @note Make sure to verify the plugin supports chunks before calling this function
  538. */
  539. virtual void setChunkData(const void* data, std::size_t dataSize);
  540. /*!
  541. * Change the current plugin program to @a index.
  542. *
  543. * If @a index is negative the plugin's program will be considered unset.
  544. * The plugin's default parameter values will be updated when this function is called.
  545. *
  546. * @param index New program index to use
  547. * @param sendGui Send message change to plugin's custom GUI, if any
  548. * @param sendOsc Send message change over OSC
  549. * @param sendCallback Send message change to registered callback
  550. */
  551. virtual void setProgram(int32_t index, bool sendGui, bool sendOsc, bool sendCallback, bool doingInit = false) noexcept;
  552. /*!
  553. * Change the current MIDI plugin program to @a index.
  554. *
  555. * If @a index is negative the plugin's program will be considered unset.
  556. * The plugin's default parameter values will be updated when this function is called.
  557. *
  558. * @param index New program index to use
  559. * @param sendGui Send message change to plugin's custom GUI, if any
  560. * @param sendOsc Send message change over OSC
  561. * @param sendCallback Send message change to registered callback
  562. */
  563. virtual void setMidiProgram(int32_t index, bool sendGui, bool sendOsc, bool sendCallback, bool doingInit = false) noexcept;
  564. /*!
  565. * This is an overloaded call to setMidiProgram().
  566. * It changes the current MIDI program using @a bank and @a program values instead of index.
  567. */
  568. void setMidiProgramById(uint32_t bank, uint32_t program, bool sendGui, bool sendOsc, bool sendCallback) noexcept;
  569. /*!
  570. * Overloaded functions, to be called from within RT context only.
  571. */
  572. virtual void setProgramRT(uint32_t index, bool sendCallbackLater) noexcept;
  573. virtual void setMidiProgramRT(uint32_t index, bool sendCallbackLater) noexcept;
  574. // -------------------------------------------------------------------
  575. // Plugin state
  576. /*!
  577. * Reload the plugin's entire state (including programs).
  578. * The plugin will be disabled during this call.
  579. */
  580. virtual void reload() = 0;
  581. /*!
  582. * Reload the plugin's programs state.
  583. */
  584. virtual void reloadPrograms(bool doInit);
  585. // -------------------------------------------------------------------
  586. // Plugin processing
  587. protected:
  588. /*!
  589. * Plugin activate call.
  590. */
  591. virtual void activate() noexcept;
  592. /*!
  593. * Plugin activate call.
  594. */
  595. virtual void deactivate() noexcept;
  596. public:
  597. /*!
  598. * Plugin process call.
  599. */
  600. virtual void process(const float** audioIn, float** audioOut,
  601. const float** cvIn, float** cvOut, uint32_t frames) = 0;
  602. /*!
  603. * Tell the plugin the current buffer size changed.
  604. */
  605. virtual void bufferSizeChanged(uint32_t newBufferSize);
  606. /*!
  607. * Tell the plugin the current sample rate changed.
  608. */
  609. virtual void sampleRateChanged(double newSampleRate);
  610. /*!
  611. * Tell the plugin the current offline mode changed.
  612. */
  613. virtual void offlineModeChanged(bool isOffline);
  614. // -------------------------------------------------------------------
  615. // Misc
  616. /*!
  617. * Idle function (non-UI), called at regular intervals.
  618. * @note: This function is NOT called from the main thread.
  619. */
  620. virtual void idle();
  621. /*!
  622. * Try to lock the plugin's master mutex.
  623. * @param forcedOffline When true, always locks and returns true
  624. */
  625. bool tryLock(bool forcedOffline) noexcept;
  626. /*!
  627. * Unlock the plugin's master mutex.
  628. */
  629. void unlock() noexcept;
  630. // -------------------------------------------------------------------
  631. // Plugin buffers
  632. /*!
  633. * Initialize all RT buffers of the plugin.
  634. */
  635. virtual void initBuffers() const noexcept;
  636. /*!
  637. * Delete and clear all RT buffers.
  638. */
  639. virtual void clearBuffers() noexcept;
  640. // -------------------------------------------------------------------
  641. // OSC stuff
  642. /*!
  643. * Handle an OSC message.
  644. * FIXME
  645. */
  646. virtual void handleOscMessage(const char* method,
  647. int argc,
  648. const void* argv,
  649. const char* types,
  650. lo_message msg);
  651. // -------------------------------------------------------------------
  652. // MIDI events
  653. /*!
  654. * Send a single midi note to be processed in the next audio callback.
  655. * A note with 0 velocity means note-off.
  656. * @note Non-RT call
  657. */
  658. void sendMidiSingleNote(uint8_t channel, uint8_t note, uint8_t velo,
  659. bool sendGui, bool sendOsc, bool sendCallback);
  660. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  661. /*!
  662. * Send all midi notes off to the host callback.
  663. * This doesn't send the actual MIDI All-Notes-Off event, but 128 note-offs instead (IFF ctrlChannel is valid).
  664. * @note RT call
  665. */
  666. void postponeRtAllNotesOff();
  667. #endif
  668. // -------------------------------------------------------------------
  669. // UI Stuff
  670. /*!
  671. * Show (or hide) the plugin's custom UI according to @a yesNo.
  672. * This function is always called from the main thread.
  673. */
  674. virtual void showCustomUI(bool yesNo);
  675. /*!
  676. * UI idle function, called at regular intervals.
  677. * This function is only called from the main thread if PLUGIN_NEEDS_UI_MAIN_THREAD is set.
  678. * @note This function may sometimes be called even if the UI is not visible yet.
  679. */
  680. virtual void uiIdle();
  681. /*!
  682. * Tell the UI a parameter has changed.
  683. * @see uiIdle
  684. */
  685. virtual void uiParameterChange(uint32_t index, float value) noexcept;
  686. /*!
  687. * Tell the UI the current program has changed.
  688. * @see uiIdle
  689. */
  690. virtual void uiProgramChange(uint32_t index) noexcept;
  691. /*!
  692. * Tell the UI the current midi program has changed.
  693. * @see uiIdle
  694. */
  695. virtual void uiMidiProgramChange(uint32_t index) noexcept;
  696. /*!
  697. * Tell the UI a note has been pressed.
  698. * @see uiIdle
  699. */
  700. virtual void uiNoteOn(uint8_t channel, uint8_t note, uint8_t velo) noexcept;
  701. /*!
  702. * Tell the UI a note has been released.
  703. * @see uiIdle
  704. */
  705. virtual void uiNoteOff(uint8_t channel, uint8_t note) noexcept;
  706. // -------------------------------------------------------------------
  707. // Helper functions
  708. /*!
  709. * Get the plugin's engine, as passed in the constructor.
  710. */
  711. CarlaEngine* getEngine() const noexcept;
  712. /*!
  713. * Get the plugin's engine client.
  714. */
  715. CarlaEngineClient* getEngineClient() const noexcept;
  716. /*!
  717. * Get a plugin's audio input port.
  718. */
  719. CarlaEngineAudioPort* getAudioInPort(uint32_t index) const noexcept;
  720. /*!
  721. * Get a plugin's audio output port.
  722. */
  723. CarlaEngineAudioPort* getAudioOutPort(uint32_t index) const noexcept;
  724. /*!
  725. * Get a plugin's CV input port.
  726. */
  727. CarlaEngineCVPort* getCVInPort(uint32_t index) const noexcept;
  728. /*!
  729. * Get a plugin's CV output port.
  730. */
  731. CarlaEngineCVPort* getCVOutPort(uint32_t index) const noexcept;
  732. /*!
  733. * Get the plugin's default event input port.
  734. */
  735. CarlaEngineEventPort* getDefaultEventInPort() const noexcept;
  736. /*!
  737. * Get the plugin's default event output port.
  738. */
  739. CarlaEngineEventPort* getDefaultEventOutPort() const noexcept;
  740. /*!
  741. * Get the plugin's type native handle.
  742. * This will be LADSPA_Handle, LV2_Handle, etc.
  743. */
  744. virtual void* getNativeHandle() const noexcept;
  745. /*!
  746. * Get the plugin's type native descriptor.
  747. * This will be LADSPA_Descriptor, DSSI_Descriptor, LV2_Descriptor, AEffect, etc.
  748. */
  749. virtual const void* getNativeDescriptor() const noexcept;
  750. /*!
  751. * Get the plugin UI bridge process Id.
  752. */
  753. virtual uintptr_t getUiBridgeProcessId() const noexcept;
  754. // -------------------------------------------------------------------
  755. /*!
  756. * Get the plugin's patchbay nodeId.
  757. * @see setPatchbayNodeId()
  758. */
  759. uint32_t getPatchbayNodeId() const noexcept;
  760. /*!
  761. * Set the plugin's patchbay nodeId.
  762. * @see getPatchbayNodeId()
  763. */
  764. void setPatchbayNodeId(uint32_t nodeId) noexcept;
  765. // -------------------------------------------------------------------
  766. // Plugin initializers
  767. /*!
  768. * Get a plugin's binary type.
  769. * This is always BINARY_NATIVE unless the plugin is a bridge.
  770. */
  771. virtual BinaryType getBinaryType() const noexcept
  772. {
  773. return BINARY_NATIVE;
  774. }
  775. /*!
  776. * Handy function required by CarlaEngine::clonePlugin().
  777. */
  778. virtual const void* getExtraStuff() const noexcept
  779. {
  780. return nullptr;
  781. }
  782. #ifndef DOXYGEN
  783. struct Initializer {
  784. CarlaEngine* const engine;
  785. const uint id;
  786. const char* const filename;
  787. const char* const name;
  788. const char* const label;
  789. const int64_t uniqueId;
  790. const uint options; // see PluginOptions
  791. };
  792. static CarlaPlugin* newNative(const Initializer& init);
  793. static CarlaPlugin* newBridge(const Initializer& init, BinaryType btype, PluginType ptype, const char* bridgeBinary);
  794. static CarlaPlugin* newLADSPA(const Initializer& init, const LADSPA_RDF_Descriptor* rdfDescriptor);
  795. static CarlaPlugin* newDSSI(const Initializer& init);
  796. static CarlaPlugin* newLV2(const Initializer& init);
  797. static CarlaPlugin* newVST2(const Initializer& init);
  798. static CarlaPlugin* newVST3(const Initializer& init);
  799. static CarlaPlugin* newAU(const Initializer& init);
  800. static CarlaPlugin* newJuce(const Initializer& init, const char* format);
  801. static CarlaPlugin* newFluidSynth(const Initializer& init, bool use16Outs);
  802. static CarlaPlugin* newSFZero(const Initializer& init);
  803. static CarlaPlugin* newJackApp(const Initializer& init);
  804. #endif
  805. // -------------------------------------------------------------------
  806. protected:
  807. /*!
  808. * Internal data, for CarlaPlugin subclasses only.
  809. */
  810. struct ProtectedData;
  811. ProtectedData* const pData;
  812. // -------------------------------------------------------------------
  813. // Internal helper functions
  814. public:
  815. // FIXME: remove public exception on 2.1 release
  816. /*!
  817. * Call LV2 restore.
  818. */
  819. virtual void restoreLV2State() noexcept;
  820. protected:
  821. /*!
  822. * Give plugin bridges a change to update their custom data sets.
  823. */
  824. virtual void waitForBridgeSaveSignal() noexcept;
  825. // -------------------------------------------------------------------
  826. // Helper classes
  827. /*!
  828. * Fully disable plugin in scope and also its engine client.
  829. * May wait-block on constructor for plugin process to end.
  830. */
  831. class ScopedDisabler
  832. {
  833. public:
  834. ScopedDisabler(CarlaPlugin* plugin) noexcept;
  835. ~ScopedDisabler() noexcept;
  836. private:
  837. CarlaPlugin* const fPlugin;
  838. bool fWasEnabled;
  839. CARLA_PREVENT_HEAP_ALLOCATION
  840. CARLA_DECLARE_NON_COPY_CLASS(ScopedDisabler)
  841. };
  842. /*!
  843. * Lock the plugin's own run/process call.
  844. * Plugin will still work as normal, but output only silence.
  845. * On destructor needsReset flag might be set if the plugin might have missed some events.
  846. */
  847. class ScopedSingleProcessLocker
  848. {
  849. public:
  850. ScopedSingleProcessLocker(CarlaPlugin* plugin, bool block) noexcept;
  851. ~ScopedSingleProcessLocker() noexcept;
  852. private:
  853. CarlaPlugin* const fPlugin;
  854. const bool fBlock;
  855. CARLA_PREVENT_HEAP_ALLOCATION
  856. CARLA_DECLARE_NON_COPY_CLASS(ScopedSingleProcessLocker)
  857. };
  858. friend class CarlaEngineBridge;
  859. CARLA_DECLARE_NON_COPY_CLASS(CarlaPlugin)
  860. };
  861. /**@}*/
  862. // -----------------------------------------------------------------------
  863. CARLA_BACKEND_END_NAMESPACE
  864. #endif // CARLA_PLUGIN_HPP_INCLUDED