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.

939 lines
28KB

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