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.

983 lines
29KB

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