Collection of tools useful for audio production
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.

991 lines
28KB

  1. /*
  2. * Carla Plugin
  3. * Copyright (C) 2011-2012 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * 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 COPYING file
  16. */
  17. #ifndef CARLA_PLUGIN_HPP
  18. #define CARLA_PLUGIN_HPP
  19. #include "carla_midi.h"
  20. #include "carla_engine.hpp"
  21. #include "carla_osc_utils.hpp"
  22. #ifdef BUILD_BRIDGE
  23. //# include "carla_backend_utils.hpp"
  24. # include "carla_bridge_osc.hpp"
  25. //#else
  26. #endif
  27. #include "carla_plugin_thread.hpp"
  28. // common includes
  29. #include <cmath>
  30. #include <vector>
  31. #include <QtCore/QMutex>
  32. #ifdef Q_WS_X11
  33. #include <QtGui/QX11EmbedContainer>
  34. typedef QX11EmbedContainer GuiContainer;
  35. #else
  36. #include <QtGui/QWidget>
  37. typedef QWidget GuiContainer;
  38. #endif
  39. typedef struct _PluginDescriptor PluginDescriptor;
  40. CARLA_BACKEND_START_NAMESPACE
  41. /*!
  42. * @defgroup CarlaBackendPlugin Carla Backend Plugin
  43. *
  44. * The Carla Backend Plugin.
  45. * @{
  46. */
  47. #define CARLA_PROCESS_CONTINUE_CHECK if (! m_enabled) { x_engine->callback(CALLBACK_DEBUG, m_id, m_enabled, 0, 0.0, nullptr); return; }
  48. const unsigned short MAX_MIDI_EVENTS = 512;
  49. const unsigned short MAX_POST_EVENTS = 152;
  50. #ifndef BUILD_BRIDGE
  51. enum PluginBridgeInfoType {
  52. PluginBridgeAudioCount,
  53. PluginBridgeMidiCount,
  54. PluginBridgeParameterCount,
  55. PluginBridgeProgramCount,
  56. PluginBridgeMidiProgramCount,
  57. PluginBridgePluginInfo,
  58. PluginBridgeParameterInfo,
  59. PluginBridgeParameterData,
  60. PluginBridgeParameterRanges,
  61. PluginBridgeProgramInfo,
  62. PluginBridgeMidiProgramInfo,
  63. PluginBridgeConfigure,
  64. PluginBridgeSetParameterValue,
  65. PluginBridgeSetDefaultValue,
  66. PluginBridgeSetProgram,
  67. PluginBridgeSetMidiProgram,
  68. PluginBridgeSetCustomData,
  69. PluginBridgeSetChunkData,
  70. PluginBridgeUpdateNow,
  71. PluginBridgeError
  72. };
  73. #endif
  74. enum PluginPostEventType {
  75. PluginPostEventNull,
  76. PluginPostEventDebug,
  77. PluginPostEventParameterChange, // param, N, value
  78. PluginPostEventProgramChange, // index
  79. PluginPostEventMidiProgramChange, // index
  80. PluginPostEventNoteOn, // channel, note, velo
  81. PluginPostEventNoteOff, // channel, note
  82. PluginPostEventCustom
  83. };
  84. struct PluginAudioData {
  85. uint32_t count;
  86. uint32_t* rindexes;
  87. CarlaEngineAudioPort** ports;
  88. PluginAudioData()
  89. : count(0),
  90. rindexes(nullptr),
  91. ports(nullptr) {}
  92. };
  93. struct PluginMidiData {
  94. CarlaEngineMidiPort* portMin;
  95. CarlaEngineMidiPort* portMout;
  96. PluginMidiData()
  97. : portMin(nullptr),
  98. portMout(nullptr) {}
  99. };
  100. struct PluginParameterData {
  101. uint32_t count;
  102. ParameterData* data;
  103. ParameterRanges* ranges;
  104. CarlaEngineControlPort* portCin;
  105. CarlaEngineControlPort* portCout;
  106. PluginParameterData()
  107. : count(0),
  108. data(nullptr),
  109. ranges(nullptr),
  110. portCin(nullptr),
  111. portCout(nullptr) {}
  112. };
  113. struct PluginProgramData {
  114. uint32_t count;
  115. int32_t current;
  116. const char** names;
  117. PluginProgramData()
  118. : count(0),
  119. current(-1),
  120. names(nullptr) {}
  121. };
  122. struct PluginMidiProgramData {
  123. uint32_t count;
  124. int32_t current;
  125. MidiProgramData* data;
  126. PluginMidiProgramData()
  127. : count(0),
  128. current(-1),
  129. data(nullptr) {}
  130. };
  131. struct PluginPostEvent {
  132. PluginPostEventType type;
  133. int32_t value1;
  134. int32_t value2;
  135. double value3;
  136. const void* cdata;
  137. PluginPostEvent()
  138. : type(PluginPostEventNull),
  139. value1(-1),
  140. value2(-1),
  141. value3(0.0),
  142. cdata(nullptr) {}
  143. };
  144. struct ExternalMidiNote {
  145. int8_t channel; // invalid = -1
  146. uint8_t note;
  147. uint8_t velo;
  148. ExternalMidiNote()
  149. : channel(-1),
  150. note(0),
  151. velo(0) {}
  152. };
  153. /*!
  154. * \class CarlaPlugin
  155. *
  156. * \brief Carla Backend base plugin class
  157. *
  158. * This is the base class for all available plugin types available in Carla Backend.\n
  159. * All virtual calls are implemented in this class as fallback, so it's safe to only override needed calls.
  160. *
  161. * \see PluginType
  162. */
  163. class CarlaPlugin
  164. {
  165. public:
  166. /*!
  167. * This is the constructor of the base plugin class.
  168. *
  169. * \param engine The engine which this plugin belongs to, must not be null
  170. * \param id The 'id' of this plugin, must between 0 and CarlaEngine::maxPluginNumber()
  171. */
  172. CarlaPlugin(CarlaEngine* const engine, const unsigned short id);
  173. /*!
  174. * This is the de-constructor of the base plugin class.
  175. */
  176. virtual ~CarlaPlugin();
  177. // -------------------------------------------------------------------
  178. // Information (base)
  179. /*!
  180. * Get the plugin's type (ie, a subclass of CarlaPlugin).
  181. *
  182. * \note Plugin bridges will return their respective plugin type, there is no plugin type such as "bridge".\n
  183. * To check if a plugin is a bridge use:
  184. * \code
  185. * if (m_hints & PLUGIN_IS_BRIDGE)
  186. * ...
  187. * \endcode
  188. */
  189. PluginType type() const;
  190. /*!
  191. * Get the plugin's id (as passed in the constructor).
  192. *
  193. * \see setId()
  194. */
  195. unsigned short id() const;
  196. /*!
  197. * Get the plugin's hints.
  198. *
  199. * \see PluginHints
  200. */
  201. unsigned int hints() const;
  202. /*!
  203. * Check if the plugin is enabled.
  204. *
  205. * \see setEnabled()
  206. */
  207. bool enabled() const;
  208. /*!
  209. * Get the plugin's internal name.\n
  210. * This name is unique within all plugins in an engine.
  211. *
  212. * \see getRealName()
  213. */
  214. const char* name() const;
  215. /*!
  216. * Get the currently loaded DLL filename for this plugin.\n
  217. * (Sound kits return their exact filename).
  218. */
  219. const char* filename() const;
  220. /*!
  221. * Get the plugin's category (delay, filter, synth, etc).
  222. */
  223. virtual PluginCategory category();
  224. /*!
  225. * Get the plugin's native unique Id.\n
  226. * May return 0 on plugin types that don't support Ids.
  227. */
  228. virtual long uniqueId();
  229. // -------------------------------------------------------------------
  230. // Information (count)
  231. /*!
  232. * Get the number of audio inputs.
  233. */
  234. virtual uint32_t audioInCount();
  235. /*!
  236. * Get the number of audio outputs.
  237. */
  238. virtual uint32_t audioOutCount();
  239. /*!
  240. * Get the number of MIDI inputs.
  241. */
  242. virtual uint32_t midiInCount();
  243. /*!
  244. * Get the number of MIDI outputs.
  245. */
  246. virtual uint32_t midiOutCount();
  247. /*!
  248. * Get the number of parameters.\n
  249. * To know the number of parameter inputs and outputs separately use getParameterCountInfo() instead.
  250. */
  251. uint32_t parameterCount() const;
  252. /*!
  253. * Get the number of scalepoints for parameter \a parameterId.
  254. */
  255. virtual uint32_t parameterScalePointCount(const uint32_t parameterId);
  256. /*!
  257. * Get the number of programs.
  258. */
  259. uint32_t programCount() const;
  260. /*!
  261. * Get the number of MIDI programs.
  262. */
  263. uint32_t midiProgramCount() const;
  264. /*!
  265. * Get the number of custom data sets.
  266. */
  267. size_t customDataCount() const;
  268. // -------------------------------------------------------------------
  269. // Information (current data)
  270. /*!
  271. * Get the current program number (-1 if unset).
  272. *
  273. * \see setProgram()
  274. */
  275. int32_t currentProgram() const;
  276. /*!
  277. * Get the current MIDI program number (-1 if unset).
  278. *
  279. * \see setMidiProgram()
  280. * \see setMidiProgramById()
  281. */
  282. int32_t currentMidiProgram() const;
  283. /*!
  284. * Get the parameter data of \a parameterId.
  285. */
  286. const ParameterData* parameterData(const uint32_t parameterId) const;
  287. /*!
  288. * Get the parameter ranges of \a parameterId.
  289. */
  290. const ParameterRanges* parameterRanges(const uint32_t parameterId) const;
  291. /*!
  292. * Check if parameter \a parameterId is of output type.
  293. */
  294. bool parameterIsOutput(const uint32_t parameterId) const;
  295. /*!
  296. * Get the MIDI program at \a index.
  297. *
  298. * \see getMidiProgramName()
  299. */
  300. const MidiProgramData* midiProgramData(const uint32_t index) const;
  301. /*!
  302. * Get the custom data set at \a index.
  303. *
  304. * \see setCustomData()
  305. */
  306. const CustomData* customData(const size_t index) const;
  307. /*!
  308. * Get the complete plugin chunk data into \a dataPtr.
  309. *
  310. * \return The size of the chunk or 0 if invalid.
  311. *
  312. * \note Make sure to verify the plugin supports chunks before calling this function!
  313. *
  314. * \see setChunkData()
  315. */
  316. virtual int32_t chunkData(void** const dataPtr);
  317. // -------------------------------------------------------------------
  318. // Information (per-plugin data)
  319. /*!
  320. * Get the current parameter value of \a parameterId.
  321. */
  322. virtual double getParameterValue(const uint32_t parameterId);
  323. /*!
  324. * Get the scalepoint \a scalePointId value of the parameter \a parameterId.
  325. */
  326. virtual double getParameterScalePointValue(const uint32_t parameterId, const uint32_t scalePointId);
  327. /*!
  328. * Get the plugin's label (URI for PLUGIN_LV2).
  329. */
  330. virtual void getLabel(char* const strBuf);
  331. /*!
  332. * Get the plugin's maker.
  333. */
  334. virtual void getMaker(char* const strBuf);
  335. /*!
  336. * Get the plugin's copyright/license.
  337. */
  338. virtual void getCopyright(char* const strBuf);
  339. /*!
  340. * Get the plugin's (real) name.
  341. *
  342. * \see name()
  343. */
  344. virtual void getRealName(char* const strBuf);
  345. /*!
  346. * Get the name of the parameter \a parameterId.
  347. */
  348. virtual void getParameterName(const uint32_t parameterId, char* const strBuf);
  349. /*!
  350. * Get the symbol of the parameter \a parameterId.
  351. */
  352. virtual void getParameterSymbol(const uint32_t parameterId, char* const strBuf);
  353. /*!
  354. * Get the custom text of the parameter \a parameterId.
  355. */
  356. virtual void getParameterText(const uint32_t parameterId, char* const strBuf);
  357. /*!
  358. * Get the unit of the parameter \a parameterId.
  359. */
  360. virtual void getParameterUnit(const uint32_t parameterId, char* const strBuf);
  361. /*!
  362. * Get the scalepoint \a scalePointId label of the parameter \a parameterId.
  363. */
  364. virtual void getParameterScalePointLabel(const uint32_t parameterId, const uint32_t scalePointId, char* const strBuf);
  365. /*!
  366. * Get the name of the program at \a index.
  367. */
  368. void getProgramName(const uint32_t index, char* const strBuf);
  369. /*!
  370. * Get the name of the MIDI program at \a index.
  371. *
  372. * \see getMidiProgramInfo()
  373. */
  374. void getMidiProgramName(const uint32_t index, char* const strBuf);
  375. /*!
  376. * Get information about the plugin's parameter count.\n
  377. * This is used to check how many input, output and total parameters are available.\n
  378. *
  379. * \note Some parameters might not be input or output (ie, invalid).
  380. *
  381. * \see parameterCount()
  382. */
  383. void getParameterCountInfo(uint32_t* const ins, uint32_t* const outs, uint32_t* const total);
  384. /*!
  385. * Get information about the plugin's custom GUI, if provided.
  386. */
  387. virtual void getGuiInfo(GuiType* const type, bool* const resizable);
  388. // -------------------------------------------------------------------
  389. // Set data (internal stuff)
  390. #ifndef BUILD_BRIDGE
  391. /*!
  392. * Set the plugin's id to \a id.
  393. *
  394. * \see id()
  395. */
  396. void setId(const unsigned short id);
  397. #endif
  398. /*!
  399. * Enable or disable the plugin according to \a yesNo.
  400. *
  401. * When a plugin is disabled, it will never be processed or managed in any way.\n
  402. * To 'bypass' a plugin use setActive() instead.
  403. *
  404. * \see enabled()
  405. */
  406. void setEnabled(const bool yesNo);
  407. /*!
  408. * Set plugin as active according to \a active.
  409. *
  410. * \param sendOsc Send message change over OSC
  411. * \param sendCallback Send message change to registered callback
  412. */
  413. void setActive(const bool active, const bool sendOsc, const bool sendCallback);
  414. /*!
  415. * Set the plugin's dry/wet signal value to \a value.\n
  416. * \a value must be between 0.0 and 1.0.
  417. *
  418. * \param sendOsc Send message change over OSC
  419. * \param sendCallback Send message change to registered callback
  420. */
  421. void setDryWet(double value, const bool sendOsc, const bool sendCallback);
  422. /*!
  423. * Set the plugin's output volume to \a value.\n
  424. * \a value must be between 0.0 and 1.27.
  425. *
  426. * \param sendOsc Send message change over OSC
  427. * \param sendCallback Send message change to registered callback
  428. */
  429. void setVolume(double value, const bool sendOsc, const bool sendCallback);
  430. /*!
  431. * Set the plugin's output left balance value to \a value.\n
  432. * \a value must be between -1.0 and 1.0.
  433. *
  434. * \param sendOsc Send message change over OSC
  435. * \param sendCallback Send message change to registered callback
  436. */
  437. void setBalanceLeft(double value, const bool sendOsc, const bool sendCallback);
  438. /*!
  439. * Set the plugin's output right balance value to \a value.\n
  440. * \a value must be between -1.0 and 1.0.
  441. *
  442. * \param sendOsc Send message change over OSC
  443. * \param sendCallback Send message change to registered callback
  444. */
  445. void setBalanceRight(double value, const bool sendOsc, const bool sendCallback);
  446. #ifndef BUILD_BRIDGE
  447. /*!
  448. * BridgePlugin call used to set internal data.
  449. */
  450. virtual int setOscBridgeInfo(const PluginBridgeInfoType type, const int argc, const lo_arg* const* const argv, const char* const types);
  451. #endif
  452. // -------------------------------------------------------------------
  453. // Set data (plugin-specific stuff)
  454. /*!
  455. * Set a plugin's parameter value.
  456. *
  457. * \param parameterId The parameter to change
  458. * \param value The new parameter value, must be within the parameter's range
  459. * \param sendGui Send message change to plugin's custom GUI, if any
  460. * \param sendOsc Send message change over OSC
  461. * \param sendCallback Send message change to registered callback
  462. *
  463. * \see getParameterValue()
  464. */
  465. virtual void setParameterValue(const uint32_t parameterId, double value, const bool sendGui, const bool sendOsc, const bool sendCallback);
  466. /*!
  467. * Set a plugin's parameter value, including internal parameters.\n
  468. * \a rindex can be negative to allow internal parameters change (as defined in InternalParametersIndex).
  469. *
  470. * \see setParameterValue()
  471. * \see setActive()
  472. * \see setDryWet()
  473. * \see setVolume()
  474. * \see setBalanceLeft()
  475. * \see setBalanceRight()
  476. */
  477. void setParameterValueByRIndex(const int32_t rindex, const double value, const bool sendGui, const bool sendOsc, const bool sendCallback);
  478. /*!
  479. * Set parameter's \a parameterId MIDI channel to \a channel.\n
  480. * \a channel must be between 0 and 15.
  481. */
  482. void setParameterMidiChannel(const uint32_t parameterId, uint8_t channel, const bool sendOsc, const bool sendCallback);
  483. /*!
  484. * Set parameter's \a parameterId MIDI CC to \a cc.\n
  485. * \a cc must be between 0 and 95 (0x5F), or -1 for invalid.
  486. */
  487. void setParameterMidiCC(const uint32_t parameterId, int16_t cc, const bool sendOsc, const bool sendCallback);
  488. /*!
  489. * Add a custom data set.\n
  490. * If \a key already exists, its current value will be swapped with \a value.
  491. *
  492. * \param type Type of data used in \a value.
  493. * \param key A key identifing this data set.
  494. * \param value The value of the data set, of type \a type.
  495. * \param sendGui Send message change to plugin's custom GUI, if any
  496. *
  497. * \see customData()
  498. */
  499. virtual void setCustomData(const char* const type, const char* const key, const char* const value, const bool sendGui);
  500. /*!
  501. * Set the complete chunk data as \a stringData.\n
  502. * \a stringData must a base64 encoded string of binary data.
  503. *
  504. * \see chunkData()
  505. *
  506. * \note Make sure to verify the plugin supports chunks before calling this function!
  507. */
  508. virtual void setChunkData(const char* const stringData);
  509. /*!
  510. * Change the current plugin program to \a index.
  511. *
  512. * If \a index is negative the plugin's program will be considered unset.\n
  513. * The plugin's default parameter values will be updated when this function is called.
  514. *
  515. * \param index New program index to use
  516. * \param sendGui Send message change to plugin's custom GUI, if any
  517. * \param sendOsc Send message change over OSC
  518. * \param sendCallback Send message change to registered callback
  519. * \param block Block the audio callback
  520. */
  521. virtual void setProgram(int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback, const bool block);
  522. /*!
  523. * Change the current MIDI plugin program to \a index.
  524. *
  525. * If \a index is negative the plugin's program will be considered unset.\n
  526. * The plugin's default parameter values will be updated when this function is called.
  527. *
  528. * \param index New program index to use
  529. * \param sendGui Send message change to plugin's custom GUI, if any
  530. * \param sendOsc Send message change over OSC
  531. * \param sendCallback Send message change to registered callback
  532. * \param block Block the audio callback
  533. */
  534. virtual void setMidiProgram(int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback, const bool block);
  535. /*!
  536. * This is an overloaded call to setMidiProgram().\n
  537. * It changes the current MIDI program using \a bank and \a program values instead of index.
  538. */
  539. void setMidiProgramById(const uint32_t bank, const uint32_t program, const bool sendGui, const bool sendOsc, const bool sendCallback, const bool block);
  540. // -------------------------------------------------------------------
  541. // Set gui stuff
  542. /*!
  543. * Set the plugin's custom GUI container.\n
  544. *
  545. * \note This function must be always called from the main thread.
  546. */
  547. virtual void setGuiContainer(GuiContainer* const container);
  548. /*!
  549. * Show (or hide) the plugin's custom GUI according to \a yesNo.
  550. *
  551. * \note This function must be always called from the main thread.
  552. */
  553. virtual void showGui(const bool yesNo);
  554. /*!
  555. * Idle the plugin's custom GUI.
  556. *
  557. * \note This function must be always called from the main thread.
  558. */
  559. virtual void idleGui();
  560. // -------------------------------------------------------------------
  561. // Plugin state
  562. /*!
  563. * Reload the plugin's entire state (including programs).\n
  564. * The plugin will be disabled during this call.
  565. */
  566. virtual void reload();
  567. /*!
  568. * Reload the plugin's programs state.
  569. */
  570. virtual void reloadPrograms(const bool init);
  571. /*!
  572. * Tell the plugin to prepare for save.
  573. */
  574. virtual void prepareForSave();
  575. // -------------------------------------------------------------------
  576. // Plugin processing
  577. /*!
  578. * Plugin process callback.
  579. */
  580. virtual void process(float** const inBuffer, float** const outBuffer, const uint32_t frames, const uint32_t framesOffset = 0);
  581. /*!
  582. * Tell the plugin the current buffer size has changed.
  583. */
  584. virtual void bufferSizeChanged(const uint32_t newBufferSize);
  585. /*!
  586. * Recreate latency audio buffers.
  587. */
  588. void recreateLatencyBuffers();
  589. // -------------------------------------------------------------------
  590. // OSC stuff
  591. /*!
  592. * Register this plugin to the engine's OSC client (controller or bridge).
  593. */
  594. void registerToOscClient();
  595. /*!
  596. * Update the plugin's internal OSC data according to \a source and \a url.\n
  597. * This is used for OSC-GUI bridges.
  598. */
  599. void updateOscData(const lo_address source, const char* const url);
  600. /*!
  601. * Free the plugin's internal OSC memory data.
  602. */
  603. void freeOscData();
  604. /*!
  605. * Show the plugin's OSC based GUI.\n
  606. * This is a handy function that waits for the GUI to respond and automatically asks it to show itself.
  607. */
  608. bool waitForOscGuiShow();
  609. // -------------------------------------------------------------------
  610. // MIDI events
  611. /*!
  612. * Send a single midi note to be processed in the next audio callback.\n
  613. * A note with 0 velocity means note-off.
  614. */
  615. void sendMidiSingleNote(const uint8_t channel, const uint8_t note, const uint8_t velo, const bool sendGui, const bool sendOsc, const bool sendCallback);
  616. /*!
  617. * Send all midi notes off for the next audio callback.\n
  618. * This doesn't send the actual MIDI All-Notes-Off event, but 128 note-offs instead.
  619. */
  620. void sendMidiAllNotesOff();
  621. // -------------------------------------------------------------------
  622. // Post-poned events
  623. /*!
  624. * Post pone an event of type \a type.\n
  625. * The event will be processed later, but as soon as possible.
  626. */
  627. void postponeEvent(const PluginPostEventType type, const int32_t value1, const int32_t value2, const double value3, const void* const cdata = nullptr);
  628. /*!
  629. * Process all the post-poned events.
  630. * This function must be called from the main thread (ie, idleGui()) if PLUGIN_USES_SINGLE_THREAD is set.
  631. */
  632. void postEventsRun();
  633. /*!
  634. * Handle custom post event.\n
  635. * Implementation depends on plugin type.
  636. */
  637. virtual void postEventHandleCustom(const int32_t value1, const int32_t value2, const double value3, const void* const cdata);
  638. /*!
  639. * Tell the UI a parameter has changed.
  640. */
  641. virtual void uiParameterChange(const uint32_t index, const double value);
  642. /*!
  643. * Tell the UI the current program has changed.
  644. */
  645. virtual void uiProgramChange(const uint32_t index);
  646. /*!
  647. * Tell the UI the current midi program has changed.
  648. */
  649. virtual void uiMidiProgramChange(const uint32_t index);
  650. /*!
  651. * Tell the UI a note has been pressed.
  652. */
  653. virtual void uiNoteOn(const uint8_t channel, const uint8_t note, const uint8_t velo);
  654. /*!
  655. * Tell the UI a note has been released.
  656. */
  657. virtual void uiNoteOff(const uint8_t channel, const uint8_t note);
  658. // -------------------------------------------------------------------
  659. // Cleanup
  660. /*!
  661. * Clear the engine client ports of the plugin.
  662. */
  663. virtual void removeClientPorts();
  664. /*!
  665. * Initialize all RT buffers of the plugin.
  666. */
  667. virtual void initBuffers();
  668. /*!
  669. * Delete all temporary buffers of the plugin.
  670. */
  671. virtual void deleteBuffers();
  672. // -------------------------------------------------------------------
  673. // Library functions
  674. /*!
  675. * Open the DLL \a filename.
  676. */
  677. bool libOpen(const char* const filename);
  678. /*!
  679. * Close the DLL previously loaded in libOpen().
  680. */
  681. bool libClose();
  682. /*!
  683. * Get the symbol entry \a symbol of the currently loaded DLL.
  684. */
  685. void* libSymbol(const char* const symbol);
  686. /*!
  687. * Get the last DLL related error.
  688. */
  689. const char* libError(const char* const filename);
  690. // -------------------------------------------------------------------
  691. // Locks
  692. void engineProcessLock();
  693. void engineProcessUnlock();
  694. void engineMidiLock();
  695. void engineMidiUnlock();
  696. // -------------------------------------------------------------------
  697. // Plugin initializers
  698. struct initializer {
  699. CarlaEngine* const engine;
  700. const char* const filename;
  701. const char* const name;
  702. const char* const label;
  703. };
  704. static CarlaPlugin* newNative(const initializer& init);
  705. static CarlaPlugin* newLADSPA(const initializer& init, const void* const extra);
  706. static CarlaPlugin* newDSSI(const initializer& init, const void* const extra);
  707. static CarlaPlugin* newLV2(const initializer& init);
  708. static CarlaPlugin* newVST(const initializer& init);
  709. static CarlaPlugin* newGIG(const initializer& init);
  710. static CarlaPlugin* newSF2(const initializer& init);
  711. static CarlaPlugin* newSFZ(const initializer& init);
  712. //#ifndef BUILD_BRIDGE
  713. static CarlaPlugin* newBridge(const initializer& init, const BinaryType btype, const PluginType ptype, const void* const extra);
  714. //#endif
  715. static size_t getNativePluginCount();
  716. static const PluginDescriptor* getNativePluginDescriptor(const size_t index);
  717. // -------------------------------------------------------------------
  718. /*!
  719. * \class ScopedDisabler
  720. *
  721. * \brief Carla plugin scoped disabler
  722. *
  723. * This is a handy class that temporarily disables a plugin during a function scope.\n
  724. * It should be used when the plugin needs reload or state change, something like this:
  725. * \code
  726. * {
  727. * const CarlaPlugin::ScopedDisabler m(plugin);
  728. * plugin->setChunkData(data);
  729. * }
  730. * \endcode
  731. */
  732. class ScopedDisabler
  733. {
  734. public:
  735. /*!
  736. * Disable plugin \a plugin if \a disable is true.
  737. * The plugin is re-enabled in the deconstructor of this class if \a disable is true.
  738. *
  739. * \param plugin The plugin to disable
  740. * \param disable Wherever to disable the plugin or not, true by default
  741. */
  742. ScopedDisabler(CarlaPlugin* const plugin, const bool disable = true)
  743. : m_plugin(plugin),
  744. m_disable(disable)
  745. {
  746. if (m_disable)
  747. {
  748. m_plugin->engineProcessLock();
  749. m_plugin->setEnabled(false);
  750. m_plugin->engineProcessUnlock();
  751. }
  752. }
  753. ~ScopedDisabler()
  754. {
  755. if (m_disable)
  756. {
  757. m_plugin->engineProcessLock();
  758. m_plugin->setEnabled(true);
  759. m_plugin->engineProcessUnlock();
  760. }
  761. }
  762. private:
  763. CarlaPlugin* const m_plugin;
  764. const bool m_disable;
  765. };
  766. // -------------------------------------------------------------------
  767. protected:
  768. unsigned short m_id;
  769. CarlaEngine* const x_engine;
  770. CarlaEngineClient* x_client;
  771. double x_dryWet, x_volume;
  772. double x_balanceLeft, x_balanceRight;
  773. PluginType m_type;
  774. unsigned int m_hints;
  775. bool m_active;
  776. bool m_activeBefore;
  777. bool m_enabled;
  778. void* m_lib;
  779. const char* m_name;
  780. const char* m_filename;
  781. // options
  782. int8_t m_ctrlInChannel;
  783. bool m_fixedBufferSize;
  784. bool m_processHighPrecision;
  785. // latency
  786. uint32_t m_latency;
  787. float** m_latencyBuffers;
  788. // -------------------------------------------------------------------
  789. // Storage Data
  790. PluginAudioData aIn;
  791. PluginAudioData aOut;
  792. PluginMidiData midi;
  793. PluginParameterData param;
  794. PluginProgramData prog;
  795. PluginMidiProgramData midiprog;
  796. std::vector<CustomData> custom;
  797. // -------------------------------------------------------------------
  798. // Extra
  799. struct {
  800. CarlaOscData data;
  801. CarlaPluginThread* thread;
  802. } osc;
  803. struct {
  804. QMutex mutex;
  805. PluginPostEvent data[MAX_POST_EVENTS];
  806. } postEvents;
  807. ExternalMidiNote extMidiNotes[MAX_MIDI_EVENTS];
  808. // -------------------------------------------------------------------
  809. // Utilities
  810. static double fixParameterValue(double& value, const ParameterRanges& ranges)
  811. {
  812. if (value < ranges.min)
  813. value = ranges.min;
  814. else if (value > ranges.max)
  815. value = ranges.max;
  816. return value;
  817. }
  818. static float fixParameterValue(float& value, const ParameterRanges& ranges)
  819. {
  820. if (value < ranges.min)
  821. value = ranges.min;
  822. else if (value > ranges.max)
  823. value = ranges.max;
  824. return value;
  825. }
  826. friend class CarlaEngine; // FIXME
  827. friend class CarlaEngineJack;
  828. };
  829. /**@}*/
  830. CARLA_BACKEND_END_NAMESPACE
  831. #endif // CARLA_PLUGIN_HPP