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.

993 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. #include "carla_plugin_thread.hpp"
  23. #ifdef BUILD_BRIDGE
  24. # include "carla_bridge_osc.hpp"
  25. #endif
  26. // common includes
  27. #include <cmath>
  28. #include <vector>
  29. #include <QtCore/QMutex>
  30. #ifdef Q_WS_X11
  31. #include <QtGui/QX11EmbedContainer>
  32. typedef QX11EmbedContainer GuiContainer;
  33. #else
  34. #include <QtGui/QWidget>
  35. typedef QWidget GuiContainer;
  36. #endif
  37. typedef struct _PluginDescriptor PluginDescriptor;
  38. CARLA_BACKEND_START_NAMESPACE
  39. /*!
  40. * @defgroup CarlaBackendPlugin Carla Backend Plugin
  41. *
  42. * The Carla Backend Plugin.
  43. * @{
  44. */
  45. #define CARLA_PROCESS_CONTINUE_CHECK if (! m_enabled) { x_engine->callback(CALLBACK_DEBUG, m_id, m_enabled, 0, 0.0); return; }
  46. const unsigned short MAX_MIDI_EVENTS = 512;
  47. const unsigned short MAX_POST_EVENTS = 152;
  48. #ifndef BUILD_BRIDGE
  49. enum PluginBridgeInfoType {
  50. PluginBridgeAudioCount,
  51. PluginBridgeMidiCount,
  52. PluginBridgeParameterCount,
  53. PluginBridgeProgramCount,
  54. PluginBridgeMidiProgramCount,
  55. PluginBridgePluginInfo,
  56. PluginBridgeParameterInfo,
  57. PluginBridgeParameterData,
  58. PluginBridgeParameterRanges,
  59. PluginBridgeProgramInfo,
  60. PluginBridgeMidiProgramInfo,
  61. PluginBridgeConfigure,
  62. PluginBridgeSetParameterValue,
  63. PluginBridgeSetDefaultValue,
  64. PluginBridgeSetProgram,
  65. PluginBridgeSetMidiProgram,
  66. PluginBridgeSetCustomData,
  67. PluginBridgeSetChunkData,
  68. PluginBridgeUpdateNow,
  69. PluginBridgeError
  70. };
  71. #endif
  72. enum PluginPostEventType {
  73. PluginPostEventNull,
  74. PluginPostEventDebug,
  75. PluginPostEventParameterChange, // param, N, value
  76. PluginPostEventProgramChange, // index
  77. PluginPostEventMidiProgramChange, // index
  78. PluginPostEventNoteOn, // channel, note, velo
  79. PluginPostEventNoteOff, // channel, note
  80. PluginPostEventCustom
  81. };
  82. struct PluginAudioData {
  83. uint32_t count;
  84. uint32_t* rindexes;
  85. CarlaEngineAudioPort** ports;
  86. PluginAudioData()
  87. : count(0),
  88. rindexes(nullptr),
  89. ports(nullptr) {}
  90. };
  91. struct PluginMidiData {
  92. CarlaEngineMidiPort* portMin;
  93. CarlaEngineMidiPort* portMout;
  94. PluginMidiData()
  95. : portMin(nullptr),
  96. portMout(nullptr) {}
  97. };
  98. struct PluginParameterData {
  99. uint32_t count;
  100. ParameterData* data;
  101. ParameterRanges* ranges;
  102. CarlaEngineControlPort* portCin;
  103. CarlaEngineControlPort* portCout;
  104. PluginParameterData()
  105. : count(0),
  106. data(nullptr),
  107. ranges(nullptr),
  108. portCin(nullptr),
  109. portCout(nullptr) {}
  110. };
  111. struct PluginProgramData {
  112. uint32_t count;
  113. int32_t current;
  114. const char** names;
  115. PluginProgramData()
  116. : count(0),
  117. current(-1),
  118. names(nullptr) {}
  119. };
  120. struct PluginMidiProgramData {
  121. uint32_t count;
  122. int32_t current;
  123. MidiProgramData* data;
  124. PluginMidiProgramData()
  125. : count(0),
  126. current(-1),
  127. data(nullptr) {}
  128. };
  129. struct PluginPostEvent {
  130. PluginPostEventType type;
  131. int32_t value1;
  132. int32_t value2;
  133. double value3;
  134. const void* cdata;
  135. PluginPostEvent()
  136. : type(PluginPostEventNull),
  137. value1(-1),
  138. value2(-1),
  139. value3(0.0),
  140. cdata(nullptr) {}
  141. };
  142. struct ExternalMidiNote {
  143. int8_t channel; // invalid = -1
  144. uint8_t note;
  145. uint8_t velo;
  146. ExternalMidiNote()
  147. : channel(-1),
  148. note(0),
  149. velo(0) {}
  150. };
  151. /*!
  152. * \class CarlaPlugin
  153. *
  154. * \brief Carla Backend base plugin class
  155. *
  156. * This is the base class for all available plugin types available in Carla Backend.\n
  157. * All virtual calls are implemented in this class as fallback, so it's safe to only override needed calls.
  158. *
  159. * \see PluginType
  160. */
  161. class CarlaPlugin
  162. {
  163. public:
  164. /*!
  165. * This is the constructor of the base plugin class.
  166. *
  167. * \param engine The engine which this plugin belongs to, must not be null
  168. * \param id The 'id' of this plugin, must between 0 and CarlaEngine::maxPluginNumber()
  169. */
  170. CarlaPlugin(CarlaEngine* const engine, const unsigned short id);
  171. /*!
  172. * This is the de-constructor of the base plugin class.
  173. */
  174. virtual ~CarlaPlugin();
  175. // -------------------------------------------------------------------
  176. // Information (base)
  177. /*!
  178. * Get the plugin's type (ie, a subclass of CarlaPlugin).
  179. *
  180. * \note Plugin bridges will return their respective plugin type, there is no plugin type such as "bridge".\n
  181. * To check if a plugin is a bridge use:
  182. * \code
  183. * if (m_hints & PLUGIN_IS_BRIDGE)
  184. * ...
  185. * \endcode
  186. */
  187. PluginType type() const;
  188. /*!
  189. * Get the plugin's id (as passed in the constructor).
  190. *
  191. * \see setId()
  192. */
  193. unsigned short id() const;
  194. /*!
  195. * Get the plugin's hints.
  196. *
  197. * \see PluginHints
  198. */
  199. unsigned int hints() const;
  200. /*!
  201. * Check if the plugin is enabled.
  202. *
  203. * \see setEnabled()
  204. */
  205. bool enabled() const;
  206. /*!
  207. * Get the plugin's internal name.\n
  208. * This name is unique within all plugins in an engine.
  209. *
  210. * \see getRealName()
  211. */
  212. const char* name() const;
  213. /*!
  214. * Get the currently loaded DLL filename for this plugin.\n
  215. * (Sound kits return their exact filename).
  216. */
  217. const char* filename() const;
  218. /*!
  219. * Get the plugin's category (delay, filter, synth, etc).
  220. */
  221. virtual PluginCategory category();
  222. /*!
  223. * Get the plugin's native unique Id.\n
  224. * May return 0 on plugin types that don't support Ids.
  225. */
  226. virtual long uniqueId();
  227. // -------------------------------------------------------------------
  228. // Information (count)
  229. /*!
  230. * Get the number of audio inputs.
  231. */
  232. virtual uint32_t audioInCount();
  233. /*!
  234. * Get the number of audio outputs.
  235. */
  236. virtual uint32_t audioOutCount();
  237. /*!
  238. * Get the number of MIDI inputs.
  239. */
  240. virtual uint32_t midiInCount();
  241. /*!
  242. * Get the number of MIDI outputs.
  243. */
  244. virtual uint32_t midiOutCount();
  245. /*!
  246. * Get the number of parameters.\n
  247. * To know the number of parameter inputs and outputs separately use getParameterCountInfo() instead.
  248. */
  249. uint32_t parameterCount() const;
  250. /*!
  251. * Get the number of scalepoints for parameter \a parameterId.
  252. */
  253. virtual uint32_t parameterScalePointCount(const uint32_t parameterId);
  254. /*!
  255. * Get the number of programs.
  256. */
  257. uint32_t programCount() const;
  258. /*!
  259. * Get the number of MIDI programs.
  260. */
  261. uint32_t midiProgramCount() const;
  262. /*!
  263. * Get the number of custom data sets.
  264. */
  265. size_t customDataCount() const;
  266. // -------------------------------------------------------------------
  267. // Information (current data)
  268. /*!
  269. * Get the current program number (-1 if unset).
  270. *
  271. * \see setProgram()
  272. */
  273. int32_t currentProgram() const;
  274. /*!
  275. * Get the current MIDI program number (-1 if unset).
  276. *
  277. * \see setMidiProgram()
  278. * \see setMidiProgramById()
  279. */
  280. int32_t currentMidiProgram() const;
  281. /*!
  282. * Get the parameter data of \a parameterId.
  283. */
  284. const ParameterData* parameterData(const uint32_t parameterId) const;
  285. /*!
  286. * Get the parameter ranges of \a parameterId.
  287. */
  288. const ParameterRanges* parameterRanges(const uint32_t parameterId) const;
  289. /*!
  290. * Check if parameter \a parameterId is of output type.
  291. */
  292. bool parameterIsOutput(const uint32_t parameterId) const;
  293. /*!
  294. * Get the MIDI program at \a index.
  295. *
  296. * \see getMidiProgramName()
  297. */
  298. const MidiProgramData* midiProgramData(const uint32_t index) const;
  299. /*!
  300. * Get the custom data set at \a index.
  301. *
  302. * \see setCustomData()
  303. */
  304. const CustomData* customData(const size_t index) const;
  305. /*!
  306. * Get the complete plugin chunk data into \a dataPtr.
  307. *
  308. * \return The size of the chunk or 0 if invalid.
  309. *
  310. * \note Make sure to verify the plugin supports chunks before calling this function!
  311. *
  312. * \see setChunkData()
  313. */
  314. virtual int32_t chunkData(void** const dataPtr);
  315. // -------------------------------------------------------------------
  316. // Information (per-plugin data)
  317. /*!
  318. * Get the current parameter value of \a parameterId.
  319. */
  320. virtual double getParameterValue(const uint32_t parameterId);
  321. /*!
  322. * Get the scalepoint \a scalePointId value of the parameter \a parameterId.
  323. */
  324. virtual double getParameterScalePointValue(const uint32_t parameterId, const uint32_t scalePointId);
  325. /*!
  326. * Get the plugin's label (URI for PLUGIN_LV2).
  327. */
  328. virtual void getLabel(char* const strBuf);
  329. /*!
  330. * Get the plugin's maker.
  331. */
  332. virtual void getMaker(char* const strBuf);
  333. /*!
  334. * Get the plugin's copyright/license.
  335. */
  336. virtual void getCopyright(char* const strBuf);
  337. /*!
  338. * Get the plugin's (real) name.
  339. *
  340. * \see name()
  341. */
  342. virtual void getRealName(char* const strBuf);
  343. /*!
  344. * Get the name of the parameter \a parameterId.
  345. */
  346. virtual void getParameterName(const uint32_t parameterId, char* const strBuf);
  347. /*!
  348. * Get the symbol of the parameter \a parameterId.
  349. */
  350. virtual void getParameterSymbol(const uint32_t parameterId, char* const strBuf);
  351. /*!
  352. * Get the custom text of the parameter \a parameterId.
  353. */
  354. virtual void getParameterText(const uint32_t parameterId, char* const strBuf);
  355. /*!
  356. * Get the unit of the parameter \a parameterId.
  357. */
  358. virtual void getParameterUnit(const uint32_t parameterId, char* const strBuf);
  359. /*!
  360. * Get the scalepoint \a scalePointId label of the parameter \a parameterId.
  361. */
  362. virtual void getParameterScalePointLabel(const uint32_t parameterId, const uint32_t scalePointId, char* const strBuf);
  363. /*!
  364. * Get the name of the program at \a index.
  365. */
  366. void getProgramName(const uint32_t index, char* const strBuf);
  367. /*!
  368. * Get the name of the MIDI program at \a index.
  369. *
  370. * \see getMidiProgramInfo()
  371. */
  372. void getMidiProgramName(const uint32_t index, char* const strBuf);
  373. /*!
  374. * Get information about the plugin's parameter count.\n
  375. * This is used to check how many input, output and total parameters are available.\n
  376. *
  377. * \note Some parameters might not be input or output (ie, invalid).
  378. *
  379. * \see parameterCount()
  380. */
  381. void getParameterCountInfo(uint32_t* const ins, uint32_t* const outs, uint32_t* const total);
  382. /*!
  383. * Get information about the plugin's custom GUI, if provided.
  384. */
  385. virtual void getGuiInfo(GuiType* const type, bool* const resizable);
  386. // -------------------------------------------------------------------
  387. // Set data (internal stuff)
  388. #ifndef BUILD_BRIDGE
  389. /*!
  390. * Set the plugin's id to \a id.
  391. *
  392. * \see id()
  393. */
  394. void setId(const unsigned short id);
  395. #endif
  396. /*!
  397. * Enable or disable the plugin according to \a yesNo.
  398. *
  399. * When a plugin is disabled, it will never be processed or managed in any way.\n
  400. * To 'bypass' a plugin use setActive() instead.
  401. *
  402. * \see enabled()
  403. */
  404. void setEnabled(const bool yesNo);
  405. /*!
  406. * Set plugin as active according to \a active.
  407. *
  408. * \param sendOsc Send message change over OSC
  409. * \param sendCallback Send message change to registered callback
  410. */
  411. void setActive(const bool active, const bool sendOsc, const bool sendCallback);
  412. /*!
  413. * Set the plugin's dry/wet signal value to \a value.\n
  414. * \a value must be between 0.0 and 1.0.
  415. *
  416. * \param sendOsc Send message change over OSC
  417. * \param sendCallback Send message change to registered callback
  418. */
  419. void setDryWet(double value, const bool sendOsc, const bool sendCallback);
  420. /*!
  421. * Set the plugin's output volume to \a value.\n
  422. * \a value must be between 0.0 and 1.27.
  423. *
  424. * \param sendOsc Send message change over OSC
  425. * \param sendCallback Send message change to registered callback
  426. */
  427. void setVolume(double value, const bool sendOsc, const bool sendCallback);
  428. /*!
  429. * Set the plugin's output left balance value to \a value.\n
  430. * \a value must be between -1.0 and 1.0.
  431. *
  432. * \param sendOsc Send message change over OSC
  433. * \param sendCallback Send message change to registered callback
  434. */
  435. void setBalanceLeft(double value, const bool sendOsc, const bool sendCallback);
  436. /*!
  437. * Set the plugin's output right balance value to \a value.\n
  438. * \a value must be between -1.0 and 1.0.
  439. *
  440. * \param sendOsc Send message change over OSC
  441. * \param sendCallback Send message change to registered callback
  442. */
  443. void setBalanceRight(double value, const bool sendOsc, const bool sendCallback);
  444. #ifndef BUILD_BRIDGE
  445. /*!
  446. * BridgePlugin call used to set internal data.
  447. */
  448. virtual int setOscBridgeInfo(const PluginBridgeInfoType type, const int argc, const lo_arg* const* const argv, const char* const types);
  449. #endif
  450. // -------------------------------------------------------------------
  451. // Set data (plugin-specific stuff)
  452. /*!
  453. * Set a plugin's parameter value.
  454. *
  455. * \param parameterId The parameter to change
  456. * \param value The new parameter value, must be within the parameter's range
  457. * \param sendGui Send message change to plugin's custom GUI, if any
  458. * \param sendOsc Send message change over OSC
  459. * \param sendCallback Send message change to registered callback
  460. *
  461. * \see getParameterValue()
  462. */
  463. virtual void setParameterValue(const uint32_t parameterId, double value, const bool sendGui, const bool sendOsc, const bool sendCallback);
  464. /*!
  465. * Set a plugin's parameter value, including internal parameters.\n
  466. * \a rindex can be negative to allow internal parameters change (as defined in InternalParametersIndex).
  467. *
  468. * \see setParameterValue()
  469. * \see setActive()
  470. * \see setDryWet()
  471. * \see setVolume()
  472. * \see setBalanceLeft()
  473. * \see setBalanceRight()
  474. */
  475. void setParameterValueByRIndex(const int32_t rindex, const double value, const bool sendGui, const bool sendOsc, const bool sendCallback);
  476. /*!
  477. * Set parameter's \a parameterId MIDI channel to \a channel.\n
  478. * \a channel must be between 0 and 15.
  479. */
  480. void setParameterMidiChannel(const uint32_t parameterId, uint8_t channel, const bool sendOsc, const bool sendCallback);
  481. /*!
  482. * Set parameter's \a parameterId MIDI CC to \a cc.\n
  483. * \a cc must be between 0 and 95 (0x5F), or -1 for invalid.
  484. */
  485. void setParameterMidiCC(const uint32_t parameterId, int16_t cc, const bool sendOsc, const bool sendCallback);
  486. /*!
  487. * Add a custom data set.\n
  488. * If \a key already exists, its current value will be swapped with \a value.
  489. *
  490. * \param type Type of data used in \a value.
  491. * \param key A key identifing this data set.
  492. * \param value The value of the data set, of type \a type.
  493. * \param sendGui Send message change to plugin's custom GUI, if any
  494. *
  495. * \see customData()
  496. */
  497. virtual void setCustomData(const CustomDataType type, const char* const key, const char* const value, const bool sendGui);
  498. /*!
  499. * Set the complete chunk data as \a stringData.\n
  500. * \a stringData must a base64 encoded string of binary data.
  501. *
  502. * \see chunkData()
  503. *
  504. * \note Make sure to verify the plugin supports chunks before calling this function!
  505. */
  506. virtual void setChunkData(const char* const stringData);
  507. /*!
  508. * Change the current plugin program to \a index.
  509. *
  510. * If \a index is negative the plugin's program will be considered unset.\n
  511. * The plugin's default parameter values will be updated when this function is called.
  512. *
  513. * \param index New program index to use
  514. * \param sendGui Send message change to plugin's custom GUI, if any
  515. * \param sendOsc Send message change over OSC
  516. * \param sendCallback Send message change to registered callback
  517. * \param block Block the audio callback
  518. */
  519. virtual void setProgram(int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback, const bool block);
  520. /*!
  521. * Change the current MIDI plugin program to \a index.
  522. *
  523. * If \a index is negative the plugin's program will be considered unset.\n
  524. * The plugin's default parameter values will be updated when this function is called.
  525. *
  526. * \param index New program index to use
  527. * \param sendGui Send message change to plugin's custom GUI, if any
  528. * \param sendOsc Send message change over OSC
  529. * \param sendCallback Send message change to registered callback
  530. * \param block Block the audio callback
  531. */
  532. virtual void setMidiProgram(int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback, const bool block);
  533. /*!
  534. * This is an overloaded call to setMidiProgram().\n
  535. * It changes the current MIDI program using \a bank and \a program values instead of index.
  536. */
  537. void setMidiProgramById(const uint32_t bank, const uint32_t program, const bool sendGui, const bool sendOsc, const bool sendCallback, const bool block);
  538. // -------------------------------------------------------------------
  539. // Set gui stuff
  540. /*!
  541. * Set the plugin's custom GUI container.\n
  542. *
  543. * \note This function must be always called from the main thread.
  544. */
  545. virtual void setGuiContainer(GuiContainer* const container);
  546. /*!
  547. * Show (or hide) the plugin's custom GUI according to \a yesNo.
  548. *
  549. * \note This function must be always called from the main thread.
  550. */
  551. virtual void showGui(const bool yesNo);
  552. /*!
  553. * Idle the plugin's custom GUI.
  554. *
  555. * \note This function must be always called from the main thread.
  556. */
  557. virtual void idleGui();
  558. // -------------------------------------------------------------------
  559. // Plugin state
  560. /*!
  561. * Reload the plugin's entire state (including programs).\n
  562. * The plugin will be disabled during this call.
  563. */
  564. virtual void reload();
  565. /*!
  566. * Reload the plugin's programs state.
  567. */
  568. virtual void reloadPrograms(const bool init);
  569. /*!
  570. * Tell the plugin to prepare for save.
  571. */
  572. virtual void prepareForSave();
  573. // -------------------------------------------------------------------
  574. // Plugin processing
  575. /*!
  576. * Plugin process callback.
  577. */
  578. virtual void process(float** const inBuffer, float** const outBuffer, const uint32_t frames, const uint32_t framesOffset = 0);
  579. /*!
  580. * Tell the plugin the current buffer size has changed.
  581. */
  582. virtual void bufferSizeChanged(const uint32_t newBufferSize);
  583. /*!
  584. * Recreate latency audio buffers.
  585. */
  586. void recreateLatencyBuffers();
  587. // -------------------------------------------------------------------
  588. // OSC stuff
  589. /*!
  590. * Register this plugin to the engine's OSC controller.
  591. */
  592. void registerToOscControl();
  593. #ifndef BUILD_BRIDGE
  594. /*!
  595. * Update the plugin's internal OSC data according to \a source and \a url.\n
  596. * This is used for OSC-GUI bridges.
  597. */
  598. void updateOscData(const lo_address source, const char* const url);
  599. /*!
  600. * Free the plugin's internal OSC memory data.
  601. */
  602. void freeOscData();
  603. /*!
  604. * Show the plugin's OSC based GUI.\n
  605. * This is a handy function that waits for the GUI to respond and automatically asks it to show itself.
  606. */
  607. bool showOscGui();
  608. #endif
  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. #ifndef BUILD_BRIDGE
  800. struct {
  801. CarlaOscData data;
  802. CarlaPluginThread* thread;
  803. } osc;
  804. #endif
  805. struct {
  806. QMutex mutex;
  807. PluginPostEvent data[MAX_POST_EVENTS];
  808. } postEvents;
  809. ExternalMidiNote extMidiNotes[MAX_MIDI_EVENTS];
  810. // -------------------------------------------------------------------
  811. // Utilities
  812. static double fixParameterValue(double& value, const ParameterRanges& ranges)
  813. {
  814. if (value < ranges.min)
  815. value = ranges.min;
  816. else if (value > ranges.max)
  817. value = ranges.max;
  818. return value;
  819. }
  820. static float fixParameterValue(float& value, const ParameterRanges& ranges)
  821. {
  822. if (value < ranges.min)
  823. value = ranges.min;
  824. else if (value > ranges.max)
  825. value = ranges.max;
  826. return value;
  827. }
  828. friend class CarlaEngine; // FIXME
  829. friend class CarlaEngineJack;
  830. };
  831. /**@}*/
  832. CARLA_BACKEND_END_NAMESPACE
  833. #endif // CARLA_PLUGIN_HPP