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.

1050 lines
31KB

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