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.

1087 lines
29KB

  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_plugin_thread.hpp"
  22. # include "carla_backend.hpp"
  23. #ifdef BUILD_BRIDGE
  24. # include "carla_bridge_osc.hpp"
  25. #else
  26. # include "carla_osc_utils.hpp"
  27. #endif
  28. // common includes
  29. //#include <cmath>
  30. //#include <vector>
  31. //#include <QtCore/QMutex>
  32. //#include <QtGui/QMainWindow>
  33. //#ifdef Q_WS_X11
  34. //# include <QtGui/QX11EmbedContainer>
  35. //typedef QX11EmbedContainer GuiContainer;
  36. //#else
  37. //# include <QtGui/QWidget>
  38. //typedef QWidget GuiContainer;
  39. //#endif
  40. typedef struct _PluginDescriptor PluginDescriptor;
  41. CARLA_BACKEND_START_NAMESPACE
  42. /*!
  43. * @defgroup CarlaBackendPlugin Carla Backend Plugin
  44. *
  45. * The Carla Backend Plugin.
  46. * @{
  47. */
  48. #define CARLA_PROCESS_CONTINUE_CHECK if (! m_enabled) { x_engine->callback(CALLBACK_DEBUG, m_id, m_enabled, 0, 0.0, nullptr); return; }
  49. const unsigned short MAX_MIDI_EVENTS = 512;
  50. const unsigned short MAX_POST_EVENTS = 152;
  51. #ifndef BUILD_BRIDGE
  52. enum PluginBridgeInfoType {
  53. PluginBridgeAudioCount,
  54. PluginBridgeMidiCount,
  55. PluginBridgeParameterCount,
  56. PluginBridgeProgramCount,
  57. PluginBridgeMidiProgramCount,
  58. PluginBridgePluginInfo,
  59. PluginBridgeParameterInfo,
  60. PluginBridgeParameterData,
  61. PluginBridgeParameterRanges,
  62. PluginBridgeProgramInfo,
  63. PluginBridgeMidiProgramInfo,
  64. PluginBridgeConfigure,
  65. PluginBridgeSetParameterValue,
  66. PluginBridgeSetDefaultValue,
  67. PluginBridgeSetProgram,
  68. PluginBridgeSetMidiProgram,
  69. PluginBridgeSetCustomData,
  70. PluginBridgeSetChunkData,
  71. PluginBridgeUpdateNow,
  72. PluginBridgeError
  73. };
  74. #endif
  75. enum PluginPostEventType {
  76. PluginPostEventNull,
  77. PluginPostEventDebug,
  78. PluginPostEventParameterChange, // param, N, value
  79. PluginPostEventProgramChange, // index
  80. PluginPostEventMidiProgramChange, // index
  81. PluginPostEventNoteOn, // channel, note, velo
  82. PluginPostEventNoteOff, // channel, note
  83. PluginPostEventCustom
  84. };
  85. struct PluginAudioData {
  86. uint32_t count;
  87. uint32_t* rindexes;
  88. CarlaEngineAudioPort** ports;
  89. PluginAudioData()
  90. : count(0),
  91. rindexes(nullptr),
  92. ports(nullptr) {}
  93. };
  94. struct PluginMidiData {
  95. CarlaEngineMidiPort* portMin;
  96. CarlaEngineMidiPort* portMout;
  97. PluginMidiData()
  98. : portMin(nullptr),
  99. portMout(nullptr) {}
  100. };
  101. struct PluginParameterData {
  102. uint32_t count;
  103. ParameterData* data;
  104. ParameterRanges* ranges;
  105. CarlaEngineControlPort* portCin;
  106. CarlaEngineControlPort* portCout;
  107. PluginParameterData()
  108. : count(0),
  109. data(nullptr),
  110. ranges(nullptr),
  111. portCin(nullptr),
  112. portCout(nullptr) {}
  113. };
  114. struct PluginProgramData {
  115. uint32_t count;
  116. int32_t current;
  117. const char** names;
  118. PluginProgramData()
  119. : count(0),
  120. current(-1),
  121. names(nullptr) {}
  122. };
  123. struct PluginMidiProgramData {
  124. uint32_t count;
  125. int32_t current;
  126. MidiProgramData* data;
  127. PluginMidiProgramData()
  128. : count(0),
  129. current(-1),
  130. data(nullptr) {}
  131. };
  132. struct PluginPostEvent {
  133. PluginPostEventType type;
  134. int32_t value1;
  135. int32_t value2;
  136. double value3;
  137. const void* cdata;
  138. PluginPostEvent()
  139. : type(PluginPostEventNull),
  140. value1(-1),
  141. value2(-1),
  142. value3(0.0),
  143. cdata(nullptr) {}
  144. };
  145. struct ExternalMidiNote {
  146. int8_t channel; // invalid = -1
  147. uint8_t note;
  148. uint8_t velo;
  149. ExternalMidiNote()
  150. : channel(-1),
  151. note(0),
  152. velo(0) {}
  153. };
  154. class CarlaPluginPrivateData;
  155. /*!
  156. * \class CarlaPlugin
  157. *
  158. * \brief Carla Backend base plugin class
  159. *
  160. * This is the base class for all available plugin types available in Carla Backend.\n
  161. * All virtual calls are implemented in this class as fallback, so it's safe to only override needed calls.
  162. *
  163. * \see PluginType
  164. */
  165. class CarlaPlugin
  166. {
  167. public:
  168. /*!
  169. * This is the constructor of the base plugin class.
  170. *
  171. * \param engine The engine which this plugin belongs to, must not be null
  172. * \param id The 'id' of this plugin, must between 0 and CarlaEngine::maxPluginNumber()
  173. */
  174. CarlaPlugin(CarlaEngine* const engine, const unsigned short id);
  175. /*!
  176. * This is the de-constructor of the base plugin class.
  177. */
  178. virtual ~CarlaPlugin();
  179. // -------------------------------------------------------------------
  180. // Information (base)
  181. /*!
  182. * Get the plugin's type (ie, a subclass of CarlaPlugin).
  183. *
  184. * \note Plugin bridges will return their respective plugin type, there is no plugin type such as "bridge".\n
  185. * To check if a plugin is a bridge use:
  186. * \code
  187. * if (m_hints & PLUGIN_IS_BRIDGE)
  188. * ...
  189. * \endcode
  190. */
  191. PluginType type() const;
  192. /*!
  193. * Get the plugin's id (as passed in the constructor).
  194. *
  195. * \see setId()
  196. */
  197. unsigned short id() const;
  198. /*!
  199. * Get the plugin's hints.
  200. *
  201. * \see PluginHints
  202. */
  203. unsigned int hints() const;
  204. /*!
  205. * Check if the plugin is enabled.
  206. *
  207. * \see setEnabled()
  208. */
  209. bool enabled() const;
  210. /*!
  211. * Get the plugin's internal name.\n
  212. * This name is unique within all plugins in an engine.
  213. *
  214. * \see getRealName()
  215. */
  216. const char* name() const;
  217. /*!
  218. * Get the currently loaded DLL filename for this plugin.\n
  219. * (Sound kits return their exact filename).
  220. */
  221. const char* filename() const;
  222. /*!
  223. * Get the plugin's category (delay, filter, synth, etc).
  224. */
  225. virtual PluginCategory category();
  226. /*!
  227. * Get the plugin's native unique Id.\n
  228. * May return 0 on plugin types that don't support Ids.
  229. */
  230. virtual long uniqueId();
  231. // -------------------------------------------------------------------
  232. // Information (count)
  233. /*!
  234. * Get the number of audio inputs.
  235. */
  236. virtual uint32_t audioInCount();
  237. /*!
  238. * Get the number of audio outputs.
  239. */
  240. virtual uint32_t audioOutCount();
  241. /*!
  242. * Get the number of MIDI inputs.
  243. */
  244. virtual uint32_t midiInCount();
  245. /*!
  246. * Get the number of MIDI outputs.
  247. */
  248. virtual uint32_t midiOutCount();
  249. /*!
  250. * Get the number of parameters.\n
  251. * To know the number of parameter inputs and outputs separately use getParameterCountInfo() instead.
  252. */
  253. uint32_t parameterCount() const;
  254. /*!
  255. * Get the number of scalepoints for parameter \a parameterId.
  256. */
  257. virtual uint32_t parameterScalePointCount(const uint32_t parameterId);
  258. /*!
  259. * Get the number of programs.
  260. */
  261. uint32_t programCount() const;
  262. /*!
  263. * Get the number of MIDI programs.
  264. */
  265. uint32_t midiProgramCount() const;
  266. /*!
  267. * Get the number of custom data sets.
  268. */
  269. size_t customDataCount() const;
  270. // -------------------------------------------------------------------
  271. // Information (current data)
  272. /*!
  273. * Get the current program number (-1 if unset).
  274. *
  275. * \see setProgram()
  276. */
  277. int32_t currentProgram() const;
  278. /*!
  279. * Get the current MIDI program number (-1 if unset).
  280. *
  281. * \see setMidiProgram()
  282. * \see setMidiProgramById()
  283. */
  284. int32_t currentMidiProgram() const;
  285. /*!
  286. * Get the parameter data of \a parameterId.
  287. */
  288. const ParameterData* parameterData(const uint32_t parameterId) const;
  289. /*!
  290. * Get the parameter ranges of \a parameterId.
  291. */
  292. const ParameterRanges* parameterRanges(const uint32_t parameterId) const;
  293. /*!
  294. * Check if parameter \a parameterId is of output type.
  295. */
  296. bool parameterIsOutput(const uint32_t parameterId) const;
  297. /*!
  298. * Get the MIDI program at \a index.
  299. *
  300. * \see getMidiProgramName()
  301. */
  302. const MidiProgramData* midiProgramData(const uint32_t index) const;
  303. /*!
  304. * Get the custom data set at \a index.
  305. *
  306. * \see setCustomData()
  307. */
  308. const CustomData* customData(const size_t index) const;
  309. /*!
  310. * Get the complete plugin chunk data into \a dataPtr.
  311. *
  312. * \return The size of the chunk or 0 if invalid.
  313. *
  314. * \note Make sure to verify the plugin supports chunks before calling this function!
  315. *
  316. * \see setChunkData()
  317. */
  318. virtual int32_t chunkData(void** const dataPtr);
  319. // -------------------------------------------------------------------
  320. // Information (per-plugin data)
  321. /*!
  322. * Get the current parameter value of \a parameterId.
  323. */
  324. virtual double getParameterValue(const uint32_t parameterId);
  325. /*!
  326. * Get the scalepoint \a scalePointId value of the parameter \a parameterId.
  327. */
  328. virtual double getParameterScalePointValue(const uint32_t parameterId, const uint32_t scalePointId);
  329. /*!
  330. * Get the plugin's label (URI for PLUGIN_LV2).
  331. */
  332. virtual void getLabel(char* const strBuf);
  333. /*!
  334. * Get the plugin's maker.
  335. */
  336. virtual void getMaker(char* const strBuf);
  337. /*!
  338. * Get the plugin's copyright/license.
  339. */
  340. virtual void getCopyright(char* const strBuf);
  341. /*!
  342. * Get the plugin's (real) name.
  343. *
  344. * \see name()
  345. */
  346. virtual void getRealName(char* const strBuf);
  347. /*!
  348. * Get the name of the parameter \a parameterId.
  349. */
  350. virtual void getParameterName(const uint32_t parameterId, char* const strBuf);
  351. /*!
  352. * Get the symbol of the parameter \a parameterId.
  353. */
  354. virtual void getParameterSymbol(const uint32_t parameterId, char* const strBuf);
  355. /*!
  356. * Get the custom text of the parameter \a parameterId.
  357. */
  358. virtual void getParameterText(const uint32_t parameterId, char* const strBuf);
  359. /*!
  360. * Get the unit of the parameter \a parameterId.
  361. */
  362. virtual void getParameterUnit(const uint32_t parameterId, char* const strBuf);
  363. /*!
  364. * Get the scalepoint \a scalePointId label of the parameter \a parameterId.
  365. */
  366. virtual void getParameterScalePointLabel(const uint32_t parameterId, const uint32_t scalePointId, char* const strBuf);
  367. /*!
  368. * Get the name of the program at \a index.
  369. */
  370. void getProgramName(const uint32_t index, char* const strBuf);
  371. /*!
  372. * Get the name of the MIDI program at \a index.
  373. *
  374. * \see getMidiProgramInfo()
  375. */
  376. void getMidiProgramName(const uint32_t index, char* const strBuf);
  377. /*!
  378. * Get information about the plugin's parameter count.\n
  379. * This is used to check how many input, output and total parameters are available.\n
  380. *
  381. * \note Some parameters might not be input or output (ie, invalid).
  382. *
  383. * \see parameterCount()
  384. */
  385. void getParameterCountInfo(uint32_t* const ins, uint32_t* const outs, uint32_t* const total);
  386. /*!
  387. * Get information about the plugin's custom GUI, if provided.
  388. */
  389. //virtual void getGuiInfo(GuiType* const type, bool* const resizable);
  390. // -------------------------------------------------------------------
  391. // Set data (internal stuff)
  392. /*!
  393. * Set the plugin's id to \a id.
  394. *
  395. * \see id()
  396. */
  397. void setId(const unsigned short id);
  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. #ifndef BUILD_BRIDGE
  705. static CarlaPlugin* newNative(const Initializer& init);
  706. #endif
  707. static CarlaPlugin* newLADSPA(const Initializer& init, const void* const extra);
  708. static CarlaPlugin* newDSSI(const Initializer& init, const void* const extra);
  709. static CarlaPlugin* newLV2(const Initializer& init);
  710. static CarlaPlugin* newVST(const Initializer& init);
  711. #ifndef BUILD_BRIDGE
  712. static CarlaPlugin* newGIG(const Initializer& init);
  713. static CarlaPlugin* newSF2(const Initializer& init);
  714. static CarlaPlugin* newSFZ(const Initializer& init);
  715. static CarlaPlugin* newBridge(const Initializer& init, const BinaryType btype, const PluginType ptype, const void* const extra);
  716. #endif
  717. static size_t getNativePluginCount();
  718. static const PluginDescriptor* getNativePluginDescriptor(const size_t index);
  719. // -------------------------------------------------------------------
  720. /*!
  721. * \class ScopedDisabler
  722. *
  723. * \brief Carla plugin scoped disabler
  724. *
  725. * This is a handy class that temporarily disables a plugin during a function scope.\n
  726. * It should be used when the plugin needs reload or state change, something like this:
  727. * \code
  728. * {
  729. * const CarlaPlugin::ScopedDisabler m(plugin);
  730. * plugin->setChunkData(data);
  731. * }
  732. * \endcode
  733. */
  734. class ScopedDisabler
  735. {
  736. public:
  737. /*!
  738. * Disable plugin \a plugin if \a disable is true.
  739. * The plugin is re-enabled in the deconstructor of this class if \a disable is true.
  740. *
  741. * \param plugin The plugin to disable
  742. * \param disable Wherever to disable the plugin or not, true by default
  743. */
  744. ScopedDisabler(CarlaPlugin* const plugin, const bool disable = true)
  745. : m_plugin(plugin),
  746. m_disable(disable)
  747. {
  748. if (m_disable)
  749. {
  750. m_plugin->engineProcessLock();
  751. m_plugin->setEnabled(false);
  752. m_plugin->engineProcessUnlock();
  753. }
  754. }
  755. ~ScopedDisabler()
  756. {
  757. if (m_disable)
  758. {
  759. m_plugin->engineProcessLock();
  760. m_plugin->setEnabled(true);
  761. m_plugin->engineProcessUnlock();
  762. }
  763. }
  764. private:
  765. CarlaPlugin* const m_plugin;
  766. const bool m_disable;
  767. };
  768. // -------------------------------------------------------------------
  769. protected:
  770. CarlaPluginPrivateData* const data;
  771. friend class CarlaPluginInternal;
  772. #if 0
  773. unsigned short m_id;
  774. CarlaEngine* const x_engine;
  775. CarlaEngineClient* x_client;
  776. double x_dryWet, x_volume;
  777. double x_balanceLeft, x_balanceRight;
  778. PluginType m_type;
  779. unsigned int m_hints;
  780. bool m_active;
  781. bool m_activeBefore;
  782. bool m_enabled;
  783. void* m_lib;
  784. const char* m_name;
  785. const char* m_filename;
  786. // options
  787. int8_t m_ctrlInChannel;
  788. bool m_fixedBufferSize;
  789. bool m_processHighPrecision;
  790. // latency
  791. uint32_t m_latency;
  792. float** m_latencyBuffers;
  793. // -------------------------------------------------------------------
  794. // Storage Data
  795. PluginAudioData aIn;
  796. PluginAudioData aOut;
  797. PluginMidiData midi;
  798. PluginParameterData param;
  799. PluginProgramData prog;
  800. PluginMidiProgramData midiprog;
  801. std::vector<CustomData> custom;
  802. // -------------------------------------------------------------------
  803. // Extra
  804. struct {
  805. CarlaOscData data;
  806. CarlaPluginThread* thread;
  807. } osc;
  808. struct {
  809. QMutex mutex;
  810. PluginPostEvent data[MAX_POST_EVENTS];
  811. } postEvents;
  812. ExternalMidiNote extMidiNotes[MAX_MIDI_EVENTS];
  813. // -------------------------------------------------------------------
  814. // Utilities
  815. static double fixParameterValue(double& value, const ParameterRanges& ranges)
  816. {
  817. if (value < ranges.min)
  818. value = ranges.min;
  819. else if (value > ranges.max)
  820. value = ranges.max;
  821. return value;
  822. }
  823. static float fixParameterValue(float& value, const ParameterRanges& ranges)
  824. {
  825. if (value < ranges.min)
  826. value = ranges.min;
  827. else if (value > ranges.max)
  828. value = ranges.max;
  829. return value;
  830. }
  831. friend class CarlaEngine; // FIXME
  832. friend class CarlaEngineJack;
  833. #endif
  834. };
  835. #if 0
  836. /*!
  837. * \class CarlaPluginGUI
  838. *
  839. * \brief Carla Backend gui plugin class
  840. *
  841. * \see CarlaPlugin
  842. */
  843. class CarlaPluginGUI : public QMainWindow
  844. {
  845. public:
  846. /*!
  847. * \class Callback
  848. *
  849. * \brief Carla plugin GUI callback
  850. */
  851. class Callback
  852. {
  853. public:
  854. virtual ~Callback() {}
  855. virtual void guiClosedCallback() = 0;
  856. };
  857. // -------------------------------------------------------------------
  858. // Constructor and destructor
  859. /*!
  860. * TODO
  861. */
  862. CarlaPluginGUI(QWidget* const parent, Callback* const callback);
  863. /*!
  864. * TODO
  865. */
  866. ~CarlaPluginGUI();
  867. // -------------------------------------------------------------------
  868. // Get data
  869. /*!
  870. * TODO
  871. */
  872. GuiContainer* getContainer() const;
  873. /*!
  874. * TODO
  875. */
  876. WId getWinId() const;
  877. // -------------------------------------------------------------------
  878. // Set data
  879. /*!
  880. * TODO
  881. */
  882. void setNewSize(const int width, const int height);
  883. /*!
  884. * TODO
  885. */
  886. void setResizable(const bool resizable);
  887. /*!
  888. * TODO
  889. */
  890. void setTitle(const char* const title);
  891. /*!
  892. * TODO
  893. */
  894. void setVisible(const bool yesNo);
  895. // -------------------------------------------------------------------
  896. private:
  897. Callback* const m_callback;
  898. GuiContainer* m_container;
  899. QByteArray m_geometry;
  900. bool m_resizable;
  901. void hideEvent(QHideEvent* const event);
  902. void closeEvent(QCloseEvent* const event);
  903. };
  904. #endif
  905. /**@}*/
  906. CARLA_BACKEND_END_NAMESPACE
  907. #endif // CARLA_PLUGIN_HPP