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.

2284 lines
63KB

  1. /*
  2. * Carla Backend
  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_H
  18. #define CARLA_PLUGIN_H
  19. #include "carla_engine.h"
  20. #include "carla_midi.h"
  21. #include "carla_shared.h"
  22. #include "carla_lib_includes.h"
  23. #ifdef BUILD_BRIDGE
  24. # include "carla_bridge_osc.h"
  25. #endif
  26. // common includes
  27. #include <cmath>
  28. #include <cstdio>
  29. #include <cstdlib>
  30. #include <vector>
  31. #include <QtGui/QDialog>
  32. #ifdef Q_WS_X11
  33. #include <QtGui/QX11EmbedContainer>
  34. typedef QX11EmbedContainer GuiContainer;
  35. #else
  36. typedef QWidget GuiContainer;
  37. #endif
  38. typedef struct _PluginDescriptor PluginDescriptor;
  39. CARLA_BACKEND_START_NAMESPACE
  40. /*!
  41. * @defgroup CarlaBackendPlugin Carla Backend Plugin
  42. *
  43. * The Carla Backend Plugin.
  44. * @{
  45. */
  46. #define CARLA_PROCESS_CONTINUE_CHECK if (! m_enabled) { x_engine->callback(CALLBACK_DEBUG, m_id, m_enabled, 0, 0.0); return; }
  47. const unsigned short MAX_MIDI_EVENTS = 512;
  48. const unsigned short MAX_POST_EVENTS = 152;
  49. #ifndef BUILD_BRIDGE
  50. enum PluginBridgeInfoType {
  51. PluginBridgeAudioCount,
  52. PluginBridgeMidiCount,
  53. PluginBridgeParameterCount,
  54. PluginBridgeProgramCount,
  55. PluginBridgeMidiProgramCount,
  56. PluginBridgePluginInfo,
  57. PluginBridgeParameterInfo,
  58. PluginBridgeParameterData,
  59. PluginBridgeParameterRanges,
  60. PluginBridgeProgramInfo,
  61. PluginBridgeMidiProgramInfo,
  62. PluginBridgeConfigure,
  63. PluginBridgeSetParameterValue,
  64. PluginBridgeSetDefaultValue,
  65. PluginBridgeSetProgram,
  66. PluginBridgeSetMidiProgram,
  67. PluginBridgeSetCustomData,
  68. PluginBridgeSetChunkData,
  69. PluginBridgeUpdateNow,
  70. PluginBridgeError
  71. };
  72. #endif
  73. enum PluginPostEventType {
  74. PluginPostEventNull,
  75. PluginPostEventDebug,
  76. PluginPostEventParameterChange, // param, N, value
  77. PluginPostEventProgramChange, // index
  78. PluginPostEventMidiProgramChange, // index
  79. PluginPostEventNoteOn, // channel, note, velo
  80. PluginPostEventNoteOff, // channel, note
  81. PluginPostEventCustom
  82. };
  83. struct PluginAudioData {
  84. uint32_t count;
  85. uint32_t* rindexes;
  86. CarlaEngineAudioPort** ports;
  87. PluginAudioData()
  88. : count(0),
  89. rindexes(nullptr),
  90. ports(nullptr) {}
  91. };
  92. struct PluginMidiData {
  93. CarlaEngineMidiPort* portMin;
  94. CarlaEngineMidiPort* portMout;
  95. PluginMidiData()
  96. : portMin(nullptr),
  97. portMout(nullptr) {}
  98. };
  99. struct PluginParameterData {
  100. uint32_t count;
  101. ParameterData* data;
  102. ParameterRanges* ranges;
  103. CarlaEngineControlPort* portCin;
  104. CarlaEngineControlPort* portCout;
  105. PluginParameterData()
  106. : count(0),
  107. data(nullptr),
  108. ranges(nullptr),
  109. portCin(nullptr),
  110. portCout(nullptr) {}
  111. };
  112. struct PluginProgramData {
  113. uint32_t count;
  114. int32_t current;
  115. const char** names;
  116. PluginProgramData()
  117. : count(0),
  118. current(-1),
  119. names(nullptr) {}
  120. };
  121. struct PluginMidiProgramData {
  122. uint32_t count;
  123. int32_t current;
  124. MidiProgramData* data;
  125. PluginMidiProgramData()
  126. : count(0),
  127. current(-1),
  128. data(nullptr) {}
  129. };
  130. struct PluginPostEvent {
  131. PluginPostEventType type;
  132. int32_t value1;
  133. int32_t value2;
  134. double value3;
  135. const void* cdata;
  136. PluginPostEvent()
  137. : type(PluginPostEventNull),
  138. value1(-1),
  139. value2(-1),
  140. value3(0.0),
  141. cdata(nullptr) {}
  142. };
  143. struct ExternalMidiNote {
  144. int8_t channel; // invalid = -1
  145. uint8_t note;
  146. uint8_t velo;
  147. ExternalMidiNote()
  148. : channel(-1),
  149. note(0),
  150. velo(0) {}
  151. };
  152. // fallback data
  153. static ParameterData paramDataNull;
  154. static ParameterRanges paramRangesNull;
  155. static MidiProgramData midiProgramDataNull;
  156. static CustomData customDataNull;
  157. /*!
  158. * \class CarlaPlugin
  159. *
  160. * \brief Carla Backend base plugin class
  161. *
  162. * This is the base class for all available plugin types available in Carla Backend.\n
  163. * All virtual calls are implemented in this class as fallback, so it's safe to only override needed calls.
  164. *
  165. * \see PluginType
  166. */
  167. class CarlaPlugin
  168. {
  169. public:
  170. /*!
  171. * This is the constructor of the base plugin class.
  172. *
  173. * \param engine The engine which this plugin belongs to, must not be null
  174. * \param id The 'id' of this plugin, must between 0 and CarlaEngine::maxPluginNumber()
  175. */
  176. CarlaPlugin(CarlaEngine* const engine, const unsigned short id)
  177. : m_id(id),
  178. x_engine(engine),
  179. x_client(nullptr),
  180. x_dryWet(1.0),
  181. x_volume(1.0),
  182. x_balanceLeft(-1.0),
  183. x_balanceRight(1.0)
  184. {
  185. CARLA_ASSERT(engine);
  186. CARLA_ASSERT(id < CarlaEngine::maxPluginNumber());
  187. qDebug("CarlaPlugin::CarlaPlugin(%p, %i)", engine, id);
  188. m_type = PLUGIN_NONE;
  189. m_hints = 0;
  190. m_active = false;
  191. m_activeBefore = false;
  192. m_enabled = false;
  193. m_lib = nullptr;
  194. m_name = nullptr;
  195. m_filename = nullptr;
  196. #ifndef BUILD_BRIDGE
  197. if (carlaOptions.processMode == PROCESS_MODE_CONTINUOUS_RACK)
  198. m_ctrlInChannel = m_id;
  199. else
  200. #endif
  201. m_ctrlInChannel = 0;
  202. m_latency = 0;
  203. m_latencyBuffers = nullptr;
  204. #ifndef BUILD_BRIDGE
  205. osc.data.path = nullptr;
  206. osc.data.source = nullptr;
  207. osc.data.target = nullptr;
  208. osc.thread = nullptr;
  209. #endif
  210. m_count += 1;
  211. }
  212. /*!
  213. * This is the de-constructor of the base plugin class.
  214. */
  215. virtual ~CarlaPlugin()
  216. {
  217. qDebug("CarlaPlugin::~CarlaPlugin()");
  218. // Remove client and ports
  219. if (x_client)
  220. {
  221. if (x_client->isActive())
  222. x_client->deactivate();
  223. removeClientPorts();
  224. delete x_client;
  225. }
  226. // Delete data
  227. deleteBuffers();
  228. // Unload DLL
  229. libClose();
  230. if (m_name)
  231. free((void*)m_name);
  232. if (m_filename)
  233. free((void*)m_filename);
  234. if (prog.count > 0)
  235. {
  236. for (uint32_t i=0; i < prog.count; i++)
  237. {
  238. if (prog.names[i])
  239. free((void*)prog.names[i]);
  240. }
  241. delete[] prog.names;
  242. }
  243. if (midiprog.count > 0)
  244. {
  245. for (uint32_t i=0; i < midiprog.count; i++)
  246. {
  247. if (midiprog.data[i].name)
  248. free((void*)midiprog.data[i].name);
  249. }
  250. delete[] midiprog.data;
  251. }
  252. if (custom.size() > 0)
  253. {
  254. for (size_t i=0; i < custom.size(); i++)
  255. {
  256. if (custom[i].key)
  257. free((void*)custom[i].key);
  258. if (custom[i].value)
  259. free((void*)custom[i].value);
  260. }
  261. custom.clear();
  262. }
  263. if (m_latencyBuffers)
  264. {
  265. for (uint32_t i=0; i < aIn.count; i++)
  266. delete[] m_latencyBuffers[i];
  267. delete[] m_latencyBuffers;
  268. }
  269. m_count -= 1;
  270. }
  271. // -------------------------------------------------------------------
  272. // Information (base)
  273. /*!
  274. * Get the plugin's type (ie, a subclass of CarlaPlugin).
  275. *
  276. * \note Plugin bridges will return their respective plugin type, there is no plugin type such as "bridge".\n
  277. * To check if a plugin is a bridge use:
  278. * \code
  279. * if (m_hints & PLUGIN_IS_BRIDGE)
  280. * ...
  281. * \endcode
  282. */
  283. PluginType type() const
  284. {
  285. return m_type;
  286. }
  287. /*!
  288. * Get the plugin's id (as passed in the constructor).
  289. *
  290. * \see setId()
  291. */
  292. unsigned short id() const
  293. {
  294. return m_id;
  295. }
  296. /*!
  297. * Get the plugin's hints.
  298. *
  299. * \see PluginHints
  300. */
  301. unsigned int hints() const
  302. {
  303. return m_hints;
  304. }
  305. /*!
  306. * Check if the plugin is enabled.
  307. *
  308. * \see setEnabled()
  309. */
  310. bool enabled() const
  311. {
  312. return m_enabled;
  313. }
  314. /*!
  315. * Get the plugin's internal name.\n
  316. * This name is unique within all plugins in an engine.
  317. *
  318. * \see getRealName()
  319. */
  320. const char* name() const
  321. {
  322. return m_name;
  323. }
  324. /*!
  325. * Get the currently loaded DLL filename for this plugin.\n
  326. * (Sound kits return their exact filename).
  327. */
  328. const char* filename() const
  329. {
  330. return m_filename;
  331. }
  332. /*!
  333. * Get the plugin's category (delay, filter, synth, etc).
  334. */
  335. virtual PluginCategory category()
  336. {
  337. return PLUGIN_CATEGORY_NONE;
  338. }
  339. /*!
  340. * Get the plugin's native unique Id.\n
  341. * May return 0 on plugin types that don't support Ids.
  342. */
  343. virtual long uniqueId()
  344. {
  345. return 0;
  346. }
  347. // -------------------------------------------------------------------
  348. // Information (count)
  349. /*!
  350. * Get the number of audio inputs.
  351. */
  352. virtual uint32_t audioInCount()
  353. {
  354. return aIn.count;
  355. }
  356. /*!
  357. * Get the number of audio outputs.
  358. */
  359. virtual uint32_t audioOutCount()
  360. {
  361. return aOut.count;
  362. }
  363. /*!
  364. * Get the number of MIDI inputs.
  365. */
  366. virtual uint32_t midiInCount()
  367. {
  368. return midi.portMin ? 1 : 0;
  369. }
  370. /*!
  371. * Get the number of MIDI outputs.
  372. */
  373. virtual uint32_t midiOutCount()
  374. {
  375. return midi.portMout ? 1 : 0;
  376. }
  377. /*!
  378. * Get the number of parameters.\n
  379. * To know the number of parameter inputs and outputs separately use getParameterCountInfo() instead.
  380. */
  381. uint32_t parameterCount() const
  382. {
  383. return param.count;
  384. }
  385. /*!
  386. * Get the number of scalepoints for parameter \a parameterId.
  387. */
  388. virtual uint32_t parameterScalePointCount(const uint32_t parameterId)
  389. {
  390. CARLA_ASSERT(parameterId < param.count);
  391. return 0;
  392. }
  393. /*!
  394. * Get the number of programs.
  395. */
  396. uint32_t programCount() const
  397. {
  398. return prog.count;
  399. }
  400. /*!
  401. * Get the number of MIDI programs.
  402. */
  403. uint32_t midiProgramCount() const
  404. {
  405. return midiprog.count;
  406. }
  407. /*!
  408. * Get the number of custom data sets.
  409. */
  410. size_t customDataCount() const
  411. {
  412. return custom.size();
  413. }
  414. // -------------------------------------------------------------------
  415. // Information (current data)
  416. /*!
  417. * Get the current program number (-1 if unset).
  418. *
  419. * \see setProgram()
  420. */
  421. int32_t currentProgram() const
  422. {
  423. return prog.current;
  424. }
  425. /*!
  426. * Get the current MIDI program number (-1 if unset).
  427. *
  428. * \see setMidiProgram()
  429. * \see setMidiProgramById()
  430. */
  431. int32_t currentMidiProgram() const
  432. {
  433. return midiprog.current;
  434. }
  435. /*!
  436. * Get the parameter data of \a parameterId.
  437. */
  438. const ParameterData* parameterData(const uint32_t parameterId) const
  439. {
  440. CARLA_ASSERT(parameterId < param.count);
  441. if (parameterId < param.count)
  442. return &param.data[parameterId];
  443. return &paramDataNull;
  444. }
  445. /*!
  446. * Get the parameter ranges of \a parameterId.
  447. */
  448. const ParameterRanges* parameterRanges(const uint32_t parameterId) const
  449. {
  450. CARLA_ASSERT(parameterId < param.count);
  451. if (parameterId < param.count)
  452. return &param.ranges[parameterId];
  453. return &paramRangesNull;
  454. }
  455. /*!
  456. * Check if parameter \a parameterId is of output type.
  457. */
  458. bool parameterIsOutput(const uint32_t parameterId) const
  459. {
  460. CARLA_ASSERT(parameterId < param.count);
  461. if (parameterId < param.count)
  462. return (param.data[parameterId].type == PARAMETER_OUTPUT);
  463. return false;
  464. }
  465. /*!
  466. * Get the MIDI program at \a index.
  467. *
  468. * \see getMidiProgramName()
  469. */
  470. const MidiProgramData* midiProgramData(const uint32_t index) const
  471. {
  472. CARLA_ASSERT(index < midiprog.count);
  473. if (index < midiprog.count)
  474. return &midiprog.data[index];
  475. return &midiProgramDataNull;
  476. }
  477. /*!
  478. * Get the custom data set at \a index.
  479. *
  480. * \see setCustomData()
  481. */
  482. const CustomData* customData(const size_t index) const
  483. {
  484. CARLA_ASSERT(index < custom.size());
  485. if (index < custom.size())
  486. return &custom[index];
  487. return &customDataNull;
  488. }
  489. /*!
  490. * Get the complete plugin chunk data into \a dataPtr.
  491. *
  492. * \return The size of the chunk or 0 if invalid.
  493. *
  494. * \note Make sure to verify the plugin supports chunks before calling this function!
  495. *
  496. * \see setChunkData()
  497. */
  498. virtual int32_t chunkData(void** const dataPtr)
  499. {
  500. CARLA_ASSERT(dataPtr);
  501. return 0;
  502. }
  503. // -------------------------------------------------------------------
  504. // Information (per-plugin data)
  505. /*!
  506. * Get the current parameter value of \a parameterId.
  507. */
  508. virtual double getParameterValue(const uint32_t parameterId)
  509. {
  510. CARLA_ASSERT(parameterId < param.count);
  511. return 0.0;
  512. }
  513. /*!
  514. * Get the scalepoint \a scalePointId value of the parameter \a parameterId.
  515. */
  516. virtual double getParameterScalePointValue(const uint32_t parameterId, const uint32_t scalePointId)
  517. {
  518. CARLA_ASSERT(parameterId < param.count);
  519. CARLA_ASSERT(scalePointId < parameterScalePointCount(parameterId));
  520. return 0.0;
  521. }
  522. /*!
  523. * Get the plugin's label (URI for PLUGIN_LV2).
  524. */
  525. virtual void getLabel(char* const strBuf)
  526. {
  527. *strBuf = 0;
  528. }
  529. /*!
  530. * Get the plugin's maker.
  531. */
  532. virtual void getMaker(char* const strBuf)
  533. {
  534. *strBuf = 0;
  535. }
  536. /*!
  537. * Get the plugin's copyright/license.
  538. */
  539. virtual void getCopyright(char* const strBuf)
  540. {
  541. *strBuf = 0;
  542. }
  543. /*!
  544. * Get the plugin's (real) name.
  545. *
  546. * \see name()
  547. */
  548. virtual void getRealName(char* const strBuf)
  549. {
  550. *strBuf = 0;;
  551. }
  552. /*!
  553. * Get the name of the parameter \a parameterId.
  554. */
  555. virtual void getParameterName(const uint32_t parameterId, char* const strBuf)
  556. {
  557. CARLA_ASSERT(parameterId < param.count);
  558. *strBuf = 0;
  559. }
  560. /*!
  561. * Get the symbol of the parameter \a parameterId.
  562. */
  563. virtual void getParameterSymbol(const uint32_t parameterId, char* const strBuf)
  564. {
  565. CARLA_ASSERT(parameterId < param.count);
  566. *strBuf = 0;
  567. }
  568. /*!
  569. * Get the custom text of the parameter \a parameterId.
  570. */
  571. virtual void getParameterText(const uint32_t parameterId, char* const strBuf)
  572. {
  573. CARLA_ASSERT(parameterId < param.count);
  574. *strBuf = 0;
  575. }
  576. /*!
  577. * Get the unit of the parameter \a parameterId.
  578. */
  579. virtual void getParameterUnit(const uint32_t parameterId, char* const strBuf)
  580. {
  581. CARLA_ASSERT(parameterId < param.count);
  582. *strBuf = 0;
  583. }
  584. /*!
  585. * Get the scalepoint \a scalePointId label of the parameter \a parameterId.
  586. */
  587. virtual void getParameterScalePointLabel(const uint32_t parameterId, const uint32_t scalePointId, char* const strBuf)
  588. {
  589. CARLA_ASSERT(parameterId < param.count);
  590. CARLA_ASSERT(scalePointId < parameterScalePointCount(parameterId));
  591. *strBuf = 0;
  592. }
  593. /*!
  594. * Get the name of the program at \a index.
  595. */
  596. void getProgramName(const uint32_t index, char* const strBuf)
  597. {
  598. CARLA_ASSERT(index < prog.count);
  599. if (index < prog.count && prog.names[index])
  600. strncpy(strBuf, prog.names[index], STR_MAX);
  601. else
  602. *strBuf = 0;
  603. }
  604. /*!
  605. * Get the name of the MIDI program at \a index.
  606. *
  607. * \see getMidiProgramInfo()
  608. */
  609. void getMidiProgramName(const uint32_t index, char* const strBuf)
  610. {
  611. CARLA_ASSERT(index < midiprog.count);
  612. if (index < midiprog.count && midiprog.data[index].name)
  613. strncpy(strBuf, midiprog.data[index].name, STR_MAX);
  614. else
  615. *strBuf = 0;
  616. }
  617. /*!
  618. * Get information about the plugin's parameter count.\n
  619. * This is used to check how many input, output and total parameters are available.\n
  620. *
  621. * \note Some parameters might not be input or output (ie, invalid).
  622. *
  623. * \see parameterCount()
  624. */
  625. void getParameterCountInfo(uint32_t* const ins, uint32_t* const outs, uint32_t* const total)
  626. {
  627. *ins = 0;
  628. *outs = 0;
  629. *total = param.count;
  630. for (uint32_t i=0; i < param.count; i++)
  631. {
  632. if (param.data[i].type == PARAMETER_INPUT)
  633. *ins += 1;
  634. else if (param.data[i].type == PARAMETER_OUTPUT)
  635. *outs += 1;
  636. }
  637. }
  638. /*!
  639. * Get information about the plugin's custom GUI, if provided.
  640. */
  641. virtual void getGuiInfo(GuiType* const type, bool* const resizable)
  642. {
  643. *type = GUI_NONE;
  644. *resizable = false;
  645. }
  646. // -------------------------------------------------------------------
  647. // Set data (internal stuff)
  648. #ifndef BUILD_BRIDGE
  649. /*!
  650. * Set the plugin's id to \a id.
  651. *
  652. * \see id()
  653. */
  654. void setId(const unsigned short id)
  655. {
  656. m_id = id;
  657. if (carlaOptions.processMode == PROCESS_MODE_CONTINUOUS_RACK)
  658. m_ctrlInChannel = id;
  659. }
  660. #endif
  661. /*!
  662. * Enable or disable the plugin according to \a yesNo.
  663. *
  664. * When a plugin is disabled, it will never be processed or managed in any way.\n
  665. * To 'bypass' a plugin use setActive() instead.
  666. *
  667. * \see enabled()
  668. */
  669. void setEnabled(const bool yesNo)
  670. {
  671. m_enabled = yesNo;
  672. }
  673. /*!
  674. * Set plugin as active according to \a active.
  675. *
  676. * \param sendOsc Send message change over OSC
  677. * \param sendCallback Send message change to registered callback
  678. */
  679. void setActive(const bool active, const bool sendOsc, const bool sendCallback)
  680. {
  681. m_active = active;
  682. double value = active ? 1.0 : 0.0;
  683. #ifndef BUILD_BRIDGE
  684. if (sendOsc)
  685. x_engine->osc_send_control_set_parameter_value(m_id, PARAMETER_ACTIVE, value);
  686. #else
  687. Q_UNUSED(sendOsc);
  688. #endif
  689. if (sendCallback)
  690. x_engine->callback(CALLBACK_PARAMETER_VALUE_CHANGED, m_id, PARAMETER_ACTIVE, 0, value);
  691. #ifndef BUILD_BRIDGE
  692. else if (m_hints & PLUGIN_IS_BRIDGE)
  693. osc_send_control(&osc.data, PARAMETER_ACTIVE, value);
  694. #endif
  695. }
  696. /*!
  697. * Set the plugin's dry/wet signal value to \a value.\n
  698. * \a value must be between 0.0 and 1.0.
  699. *
  700. * \param sendOsc Send message change over OSC
  701. * \param sendCallback Send message change to registered callback
  702. */
  703. void setDryWet(double value, const bool sendOsc, const bool sendCallback)
  704. {
  705. CARLA_ASSERT(value >= 0.0 && value <= 1.0);
  706. if (value < 0.0)
  707. value = 0.0;
  708. else if (value > 1.0)
  709. value = 1.0;
  710. x_dryWet = value;
  711. #ifndef BUILD_BRIDGE
  712. if (sendOsc)
  713. x_engine->osc_send_control_set_parameter_value(m_id, PARAMETER_DRYWET, value);
  714. #else
  715. Q_UNUSED(sendOsc);
  716. #endif
  717. if (sendCallback)
  718. x_engine->callback(CALLBACK_PARAMETER_VALUE_CHANGED, m_id, PARAMETER_DRYWET, 0, value);
  719. #ifndef BUILD_BRIDGE
  720. else if (m_hints & PLUGIN_IS_BRIDGE)
  721. osc_send_control(&osc.data, PARAMETER_DRYWET, value);
  722. #endif
  723. }
  724. /*!
  725. * Set the plugin's output volume to \a value.\n
  726. * \a value must be between 0.0 and 1.27.
  727. *
  728. * \param sendOsc Send message change over OSC
  729. * \param sendCallback Send message change to registered callback
  730. */
  731. void setVolume(double value, const bool sendOsc, const bool sendCallback)
  732. {
  733. CARLA_ASSERT(value >= 0.0 && value <= 1.27);
  734. if (value < 0.0)
  735. value = 0.0;
  736. else if (value > 1.27)
  737. value = 1.27;
  738. x_volume = value;
  739. #ifndef BUILD_BRIDGE
  740. if (sendOsc)
  741. x_engine->osc_send_control_set_parameter_value(m_id, PARAMETER_VOLUME, value);
  742. #else
  743. Q_UNUSED(sendOsc);
  744. #endif
  745. if (sendCallback)
  746. x_engine->callback(CALLBACK_PARAMETER_VALUE_CHANGED, m_id, PARAMETER_VOLUME, 0, value);
  747. #ifndef BUILD_BRIDGE
  748. else if (m_hints & PLUGIN_IS_BRIDGE)
  749. osc_send_control(&osc.data, PARAMETER_VOLUME, value);
  750. #endif
  751. }
  752. /*!
  753. * Set the plugin's output left balance value to \a value.\n
  754. * \a value must be between -1.0 and 1.0.
  755. *
  756. * \param sendOsc Send message change over OSC
  757. * \param sendCallback Send message change to registered callback
  758. */
  759. void setBalanceLeft(double value, const bool sendOsc, const bool sendCallback)
  760. {
  761. CARLA_ASSERT(value >= -1.0 && value <= 1.0);
  762. if (value < -1.0)
  763. value = -1.0;
  764. else if (value > 1.0)
  765. value = 1.0;
  766. x_balanceLeft = value;
  767. #ifndef BUILD_BRIDGE
  768. if (sendOsc)
  769. x_engine->osc_send_control_set_parameter_value(m_id, PARAMETER_BALANCE_LEFT, value);
  770. #else
  771. Q_UNUSED(sendOsc);
  772. #endif
  773. if (sendCallback)
  774. x_engine->callback(CALLBACK_PARAMETER_VALUE_CHANGED, m_id, PARAMETER_BALANCE_LEFT, 0, value);
  775. #ifndef BUILD_BRIDGE
  776. else if (m_hints & PLUGIN_IS_BRIDGE)
  777. osc_send_control(&osc.data, PARAMETER_BALANCE_LEFT, value);
  778. #endif
  779. }
  780. /*!
  781. * Set the plugin's output right balance value to \a value.\n
  782. * \a value must be between -1.0 and 1.0.
  783. *
  784. * \param sendOsc Send message change over OSC
  785. * \param sendCallback Send message change to registered callback
  786. */
  787. void setBalanceRight(double value, const bool sendOsc, const bool sendCallback)
  788. {
  789. CARLA_ASSERT(value >= -1.0 && value <= 1.0);
  790. if (value < -1.0)
  791. value = -1.0;
  792. else if (value > 1.0)
  793. value = 1.0;
  794. x_balanceRight = value;
  795. #ifndef BUILD_BRIDGE
  796. if (sendOsc)
  797. x_engine->osc_send_control_set_parameter_value(m_id, PARAMETER_BALANCE_RIGHT, value);
  798. #else
  799. Q_UNUSED(sendOsc);
  800. #endif
  801. if (sendCallback)
  802. x_engine->callback(CALLBACK_PARAMETER_VALUE_CHANGED, m_id, PARAMETER_BALANCE_RIGHT, 0, value);
  803. #ifndef BUILD_BRIDGE
  804. else if (m_hints & PLUGIN_IS_BRIDGE)
  805. osc_send_control(&osc.data, PARAMETER_BALANCE_RIGHT, value);
  806. #endif
  807. }
  808. #ifndef BUILD_BRIDGE
  809. /*!
  810. * BridgePlugin call used to set internal data.
  811. */
  812. virtual int setOscBridgeInfo(const PluginBridgeInfoType type, const int argc, const lo_arg* const* const argv, const char* const types)
  813. {
  814. return 1;
  815. Q_UNUSED(type);
  816. Q_UNUSED(argc);
  817. Q_UNUSED(argv);
  818. Q_UNUSED(types);
  819. }
  820. #endif
  821. // -------------------------------------------------------------------
  822. // Set data (plugin-specific stuff)
  823. /*!
  824. * Set a plugin's parameter value.
  825. *
  826. * \param parameterId The parameter to change
  827. * \param value The new parameter value, must be within the parameter's range
  828. * \param sendGui Send message change to plugin's custom GUI, if any
  829. * \param sendOsc Send message change over OSC
  830. * \param sendCallback Send message change to registered callback
  831. *
  832. * \see getParameterValue()
  833. */
  834. virtual void setParameterValue(const uint32_t parameterId, double value, const bool sendGui, const bool sendOsc, const bool sendCallback)
  835. {
  836. CARLA_ASSERT(parameterId < param.count);
  837. if (sendGui)
  838. uiParameterChange(parameterId, value);
  839. #ifndef BUILD_BRIDGE
  840. if (sendOsc)
  841. x_engine->osc_send_control_set_parameter_value(m_id, parameterId, value);
  842. #else
  843. Q_UNUSED(sendOsc);
  844. #endif
  845. if (sendCallback)
  846. x_engine->callback(CALLBACK_PARAMETER_VALUE_CHANGED, m_id, parameterId, 0, value);
  847. }
  848. /*!
  849. * Set a plugin's parameter value, including internal parameters.\n
  850. * \a rindex can be negative to allow internal parameters change (as defined in InternalParametersIndex).
  851. *
  852. * \see setParameterValue()
  853. * \see setActive()
  854. * \see setDryWet()
  855. * \see setVolume()
  856. * \see setBalanceLeft()
  857. * \see setBalanceRight()
  858. */
  859. void setParameterValueByRIndex(const int32_t rindex, const double value, const bool sendGui, const bool sendOsc, const bool sendCallback)
  860. {
  861. CARLA_ASSERT(rindex >= PARAMETER_BALANCE_RIGHT && rindex != PARAMETER_NULL);
  862. if (rindex == PARAMETER_ACTIVE)
  863. return setActive(value > 0.0, sendOsc, sendCallback);
  864. if (rindex == PARAMETER_DRYWET)
  865. return setDryWet(value, sendOsc, sendCallback);
  866. if (rindex == PARAMETER_VOLUME)
  867. return setVolume(value, sendOsc, sendCallback);
  868. if (rindex == PARAMETER_BALANCE_LEFT)
  869. return setBalanceLeft(value, sendOsc, sendCallback);
  870. if (rindex == PARAMETER_BALANCE_RIGHT)
  871. return setBalanceRight(value, sendOsc, sendCallback);
  872. for (uint32_t i=0; i < param.count; i++)
  873. {
  874. if (param.data[i].rindex == rindex)
  875. return setParameterValue(i, value, sendGui, sendOsc, sendCallback);
  876. }
  877. }
  878. /*!
  879. * Set parameter's \a parameterId MIDI channel to \a channel.\n
  880. * \a channel must be between 0 and 15.
  881. */
  882. void setParameterMidiChannel(const uint32_t parameterId, uint8_t channel, const bool sendOsc, const bool sendCallback)
  883. {
  884. CARLA_ASSERT(parameterId < param.count);
  885. CARLA_ASSERT(channel < 16);
  886. if (channel >= 16)
  887. channel = 16;
  888. param.data[parameterId].midiChannel = channel;
  889. #ifndef BUILD_BRIDGE
  890. if (sendOsc)
  891. x_engine->osc_send_control_set_parameter_midi_channel(m_id, parameterId, channel);
  892. #else
  893. Q_UNUSED(sendOsc);
  894. #endif
  895. if (sendCallback)
  896. x_engine->callback(CALLBACK_PARAMETER_MIDI_CHANNEL_CHANGED, m_id, parameterId, channel, 0.0);
  897. }
  898. /*!
  899. * Set parameter's \a parameterId MIDI CC to \a cc.\n
  900. * \a cc must be between 0 and 95 (0x5F), or -1 for invalid.
  901. */
  902. void setParameterMidiCC(const uint32_t parameterId, int16_t cc, const bool sendOsc, const bool sendCallback)
  903. {
  904. CARLA_ASSERT(parameterId < param.count);
  905. CARLA_ASSERT(cc >= -1);
  906. if (cc < -1 || cc > 0x5F)
  907. cc = -1;
  908. param.data[parameterId].midiCC = cc;
  909. #ifndef BUILD_BRIDGE
  910. if (sendOsc)
  911. x_engine->osc_send_control_set_parameter_midi_cc(m_id, parameterId, cc);
  912. #else
  913. Q_UNUSED(sendOsc);
  914. #endif
  915. if (sendCallback)
  916. x_engine->callback(CALLBACK_PARAMETER_MIDI_CC_CHANGED, m_id, parameterId, cc, 0.0);
  917. }
  918. /*!
  919. * Add a custom data set.\n
  920. * If \a key already exists, its current value will be swapped with \a value.
  921. *
  922. * \param type Type of data used in \a value.
  923. * \param key A key identifing this data set.
  924. * \param value The value of the data set, of type \a type.
  925. * \param sendGui Send message change to plugin's custom GUI, if any
  926. *
  927. * \see customData()
  928. */
  929. virtual void setCustomData(const CustomDataType type, const char* const key, const char* const value, const bool sendGui)
  930. {
  931. CARLA_ASSERT(type != CUSTOM_DATA_INVALID);
  932. CARLA_ASSERT(key);
  933. CARLA_ASSERT(value);
  934. if (type == CUSTOM_DATA_INVALID)
  935. return qCritical("CarlaPlugin::setCustomData(%s, \"%s\", \"%s\", %s) - type is invalid", CustomDataType2str(type), key, value, bool2str(sendGui));
  936. if (! key)
  937. return qCritical("CarlaPlugin::setCustomData(%s, \"%s\", \"%s\", %s) - key is null", CustomDataType2str(type), key, value, bool2str(sendGui));
  938. if (! value)
  939. return qCritical("CarlaPlugin::setCustomData(%s, \"%s\", \"%s\", %s) - value is null", CustomDataType2str(type), key, value, bool2str(sendGui));
  940. bool saveData = true;
  941. switch (type)
  942. {
  943. case CUSTOM_DATA_INVALID:
  944. saveData = false;
  945. break;
  946. case CUSTOM_DATA_STRING:
  947. // Ignore some keys
  948. if (strncmp(key, "OSC:", 4) == 0 || strcmp(key, "guiVisible") == 0)
  949. saveData = false;
  950. else if (strcmp(key, CARLA_BRIDGE_MSG_SAVE_NOW) == 0 || strcmp(key, CARLA_BRIDGE_MSG_SET_CHUNK) == 0 || strcmp(key, CARLA_BRIDGE_MSG_SET_CUSTOM) == 0)
  951. saveData = false;
  952. break;
  953. default:
  954. break;
  955. }
  956. if (saveData)
  957. {
  958. // Check if we already have this key
  959. for (size_t i=0; i < custom.size(); i++)
  960. {
  961. if (strcmp(custom[i].key, key) == 0)
  962. {
  963. free((void*)custom[i].value);
  964. custom[i].value = strdup(value);
  965. return;
  966. }
  967. }
  968. // Otherwise store it
  969. CustomData newData;
  970. newData.type = type;
  971. newData.key = strdup(key);
  972. newData.value = strdup(value);
  973. custom.push_back(newData);
  974. }
  975. }
  976. /*!
  977. * Set the complete chunk data as \a stringData.\n
  978. * \a stringData must a base64 encoded string of binary data.
  979. *
  980. * \see chunkData()
  981. *
  982. * \note Make sure to verify the plugin supports chunks before calling this function!
  983. */
  984. virtual void setChunkData(const char* const stringData)
  985. {
  986. CARLA_ASSERT(stringData);
  987. }
  988. /*!
  989. * Change the current plugin program to \a index.
  990. *
  991. * If \a index is negative the plugin's program will be considered unset.\n
  992. * The plugin's default parameter values will be updated when this function is called.
  993. *
  994. * \param index New program index to use
  995. * \param sendGui Send message change to plugin's custom GUI, if any
  996. * \param sendOsc Send message change over OSC
  997. * \param sendCallback Send message change to registered callback
  998. * \param block Block the audio callback
  999. */
  1000. virtual void setProgram(int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback, const bool block)
  1001. {
  1002. CARLA_ASSERT(index >= -1 && index < (int32_t)prog.count);
  1003. if (index < -1)
  1004. index = -1;
  1005. else if (index > (int32_t)prog.count)
  1006. return;
  1007. prog.current = index;
  1008. if (sendGui && index >= 0)
  1009. uiProgramChange(index);
  1010. // Change default parameter values
  1011. if (index >= 0)
  1012. {
  1013. for (uint32_t i=0; i < param.count; i++)
  1014. {
  1015. param.ranges[i].def = getParameterValue(i);
  1016. fixParameterValue(param.ranges[i].def, param.ranges[i]);
  1017. #ifndef BUILD_BRIDGE
  1018. if (sendOsc)
  1019. {
  1020. x_engine->osc_send_control_set_default_value(m_id, i, param.ranges[i].def);
  1021. x_engine->osc_send_control_set_parameter_value(m_id, i, param.ranges[i].def);
  1022. }
  1023. #endif
  1024. }
  1025. }
  1026. #ifndef BUILD_BRIDGE
  1027. if (sendOsc)
  1028. x_engine->osc_send_control_set_program(m_id, index);
  1029. #else
  1030. Q_UNUSED(sendOsc);
  1031. #endif
  1032. if (sendCallback)
  1033. x_engine->callback(CALLBACK_PROGRAM_CHANGED, m_id, index, 0, 0.0);
  1034. Q_UNUSED(block);
  1035. }
  1036. /*!
  1037. * Change the current MIDI plugin program to \a index.
  1038. *
  1039. * If \a index is negative the plugin's program will be considered unset.\n
  1040. * The plugin's default parameter values will be updated when this function is called.
  1041. *
  1042. * \param index New program index to use
  1043. * \param sendGui Send message change to plugin's custom GUI, if any
  1044. * \param sendOsc Send message change over OSC
  1045. * \param sendCallback Send message change to registered callback
  1046. * \param block Block the audio callback
  1047. */
  1048. virtual void setMidiProgram(int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback, const bool block)
  1049. {
  1050. CARLA_ASSERT(index >= -1 && index < (int32_t)midiprog.count);
  1051. if (index < -1)
  1052. index = -1;
  1053. else if (index > (int32_t)midiprog.count)
  1054. return;
  1055. midiprog.current = index;
  1056. if (sendGui && index >= 0)
  1057. uiMidiProgramChange(index);
  1058. // Change default parameter values (sound banks never change defaults)
  1059. if (index >= 0 && m_type != PLUGIN_GIG && m_type != PLUGIN_SF2 && m_type != PLUGIN_SFZ)
  1060. {
  1061. for (uint32_t i=0; i < param.count; i++)
  1062. {
  1063. param.ranges[i].def = getParameterValue(i);
  1064. fixParameterValue(param.ranges[i].def, param.ranges[i]);
  1065. #ifndef BUILD_BRIDGE
  1066. if (sendOsc)
  1067. {
  1068. x_engine->osc_send_control_set_default_value(m_id, i, param.ranges[i].def);
  1069. x_engine->osc_send_control_set_parameter_value(m_id, i, param.ranges[i].def);
  1070. }
  1071. #endif
  1072. }
  1073. }
  1074. #ifndef BUILD_BRIDGE
  1075. if (sendOsc)
  1076. x_engine->osc_send_control_set_midi_program(m_id, index);
  1077. #else
  1078. Q_UNUSED(sendOsc);
  1079. #endif
  1080. if (sendCallback)
  1081. x_engine->callback(CALLBACK_MIDI_PROGRAM_CHANGED, m_id, index, 0, 0.0);
  1082. Q_UNUSED(block);
  1083. }
  1084. /*!
  1085. * This is an overloaded call to setMidiProgram().\n
  1086. * It changes the current MIDI program using \a bank and \a program values instead of index.
  1087. */
  1088. void setMidiProgramById(const uint32_t bank, const uint32_t program, const bool sendGui, const bool sendOsc, const bool sendCallback, const bool block)
  1089. {
  1090. CARLA_ASSERT(program < 128);
  1091. for (uint32_t i=0; i < midiprog.count; i++)
  1092. {
  1093. if (midiprog.data[i].bank == bank && midiprog.data[i].program == program)
  1094. return setMidiProgram(i, sendGui, sendOsc, sendCallback, block);
  1095. }
  1096. }
  1097. // -------------------------------------------------------------------
  1098. // Set gui stuff
  1099. /*!
  1100. * Set the plugin's custom GUI container.\n
  1101. *
  1102. * \note This function must be always called from the main thread.
  1103. */
  1104. virtual void setGuiContainer(GuiContainer* const container)
  1105. {
  1106. Q_UNUSED(container);
  1107. }
  1108. /*!
  1109. * Show (or hide) the plugin's custom GUI according to \a yesNo.
  1110. *
  1111. * \note This function must be always called from the main thread.
  1112. */
  1113. virtual void showGui(const bool yesNo)
  1114. {
  1115. Q_UNUSED(yesNo);
  1116. }
  1117. /*!
  1118. * Idle the plugin's custom GUI.
  1119. *
  1120. * \note This function must be always called from the main thread.
  1121. */
  1122. virtual void idleGui()
  1123. {
  1124. if (! m_enabled)
  1125. return;
  1126. if (m_hints & PLUGIN_USES_SINGLE_THREAD)
  1127. {
  1128. // Process postponed events
  1129. postEventsRun();
  1130. // Update parameter outputs
  1131. for (uint32_t i=0; i < param.count; i++)
  1132. {
  1133. if (param.data[i].type == PARAMETER_OUTPUT)
  1134. uiParameterChange(i, getParameterValue(i));
  1135. }
  1136. }
  1137. }
  1138. // -------------------------------------------------------------------
  1139. // Plugin state
  1140. /*!
  1141. * Reload the plugin's entire state (including programs).\n
  1142. * The plugin will be disabled during this call.
  1143. */
  1144. virtual void reload()
  1145. {
  1146. }
  1147. /*!
  1148. * Reload the plugin's programs state.
  1149. */
  1150. virtual void reloadPrograms(const bool init)
  1151. {
  1152. Q_UNUSED(init);
  1153. }
  1154. /*!
  1155. * Tell the plugin to prepare for save.
  1156. */
  1157. virtual void prepareForSave()
  1158. {
  1159. }
  1160. // -------------------------------------------------------------------
  1161. // Plugin processing
  1162. /*!
  1163. * Plugin process callback.
  1164. */
  1165. virtual void process(float** const inBuffer, float** const outBuffer, const uint32_t frames, const uint32_t framesOffset = 0)
  1166. {
  1167. Q_UNUSED(inBuffer);
  1168. Q_UNUSED(outBuffer);
  1169. Q_UNUSED(frames);
  1170. Q_UNUSED(framesOffset);
  1171. }
  1172. /*!
  1173. * Tell the plugin the current buffer size has changed.
  1174. */
  1175. virtual void bufferSizeChanged(const uint32_t newBufferSize)
  1176. {
  1177. Q_UNUSED(newBufferSize);
  1178. }
  1179. /*!
  1180. * Recreate latency audio buffers.
  1181. */
  1182. void recreateLatencyBuffers()
  1183. {
  1184. if (m_latencyBuffers)
  1185. {
  1186. for (uint32_t i=0; i < aIn.count; i++)
  1187. delete[] m_latencyBuffers[i];
  1188. delete[] m_latencyBuffers;
  1189. }
  1190. if (aIn.count > 0 && m_latency > 0)
  1191. {
  1192. m_latencyBuffers = new float* [aIn.count];
  1193. for (uint32_t i=0; i < aIn.count; i++)
  1194. m_latencyBuffers[i] = new float [m_latency];
  1195. }
  1196. else
  1197. m_latencyBuffers = nullptr;
  1198. }
  1199. // -------------------------------------------------------------------
  1200. // OSC stuff
  1201. /*!
  1202. * Register this plugin to the engine's OSC controller.
  1203. */
  1204. void registerToOscControl()
  1205. {
  1206. if (! x_engine->isOscControlRegisted())
  1207. return;
  1208. #ifndef BUILD_BRIDGE
  1209. x_engine->osc_send_control_add_plugin_start(m_id, m_name);
  1210. #endif
  1211. // Base data
  1212. {
  1213. char bufName[STR_MAX] = { 0 };
  1214. char bufLabel[STR_MAX] = { 0 };
  1215. char bufMaker[STR_MAX] = { 0 };
  1216. char bufCopyright[STR_MAX] = { 0 };
  1217. getRealName(bufName);
  1218. getLabel(bufLabel);
  1219. getMaker(bufMaker);
  1220. getCopyright(bufCopyright);
  1221. #ifdef BUILD_BRIDGE
  1222. x_engine->osc_send_bridge_plugin_info(category(), m_hints, bufName, bufLabel, bufMaker, bufCopyright, uniqueId());
  1223. #else
  1224. x_engine->osc_send_control_set_plugin_data(m_id, m_type, category(), m_hints, bufName, bufLabel, bufMaker, bufCopyright, uniqueId());
  1225. #endif
  1226. }
  1227. // Base count
  1228. {
  1229. uint32_t cIns, cOuts, cTotals;
  1230. getParameterCountInfo(&cIns, &cOuts, &cTotals);
  1231. #ifdef BUILD_BRIDGE
  1232. x_engine->osc_send_bridge_audio_count(audioInCount(), audioOutCount(), audioInCount() + audioOutCount());
  1233. x_engine->osc_send_bridge_midi_count(midiInCount(), midiOutCount(), midiInCount() + midiOutCount());
  1234. x_engine->osc_send_bridge_parameter_count(cIns, cOuts, cTotals);
  1235. #else
  1236. x_engine->osc_send_control_set_plugin_ports(m_id, audioInCount(), audioOutCount(), midiInCount(), midiOutCount(), cIns, cOuts, cTotals);
  1237. #endif
  1238. }
  1239. // Plugin Parameters
  1240. #ifdef BUILD_BRIDGE
  1241. uint32_t maxParameters = MAX_PARAMETERS;
  1242. #else
  1243. uint32_t maxParameters = carlaOptions.maxParameters;
  1244. #endif
  1245. if (param.count > 0 && param.count < maxParameters)
  1246. {
  1247. char bufName[STR_MAX], bufUnit[STR_MAX];
  1248. for (uint32_t i=0; i < param.count; i++)
  1249. {
  1250. getParameterName(i, bufName);
  1251. getParameterUnit(i, bufUnit);
  1252. #ifdef BUILD_BRIDGE
  1253. x_engine->osc_send_bridge_parameter_info(i, bufName, bufUnit);
  1254. x_engine->osc_send_bridge_parameter_data(i, param.data[i].type, param.data[i].rindex, param.data[i].hints, param.data[i].midiChannel, param.data[i].midiCC);
  1255. x_engine->osc_send_bridge_parameter_ranges(i, param.ranges[i].def, param.ranges[i].min, param.ranges[i].max, param.ranges[i].step, param.ranges[i].stepSmall, param.ranges[i].stepLarge);
  1256. x_engine->osc_send_bridge_set_parameter_value(i, getParameterValue(i));
  1257. #else
  1258. x_engine->osc_send_control_set_parameter_data(m_id, i, param.data[i].type, param.data[i].hints, bufName, bufUnit, getParameterValue(i));
  1259. x_engine->osc_send_control_set_parameter_ranges(m_id, i, param.ranges[i].min, param.ranges[i].max, param.ranges[i].def, param.ranges[i].step, param.ranges[i].stepSmall, param.ranges[i].stepLarge);
  1260. x_engine->osc_send_control_set_parameter_midi_cc(m_id, i, param.data[i].midiCC);
  1261. x_engine->osc_send_control_set_parameter_midi_channel(m_id, i, param.data[i].midiChannel);
  1262. x_engine->osc_send_control_set_parameter_value(m_id, i, getParameterValue(i));
  1263. #endif
  1264. }
  1265. }
  1266. // Programs
  1267. if (prog.count > 0)
  1268. {
  1269. #ifdef BUILD_BRIDGE
  1270. x_engine->osc_send_bridge_program_count(prog.count);
  1271. for (uint32_t i=0; i < prog.count; i++)
  1272. x_engine->osc_send_bridge_program_info(i, prog.names[i]);
  1273. x_engine->osc_send_bridge_set_program(prog.current);
  1274. #else
  1275. x_engine->osc_send_control_set_program_count(m_id, prog.count);
  1276. for (uint32_t i=0; i < prog.count; i++)
  1277. x_engine->osc_send_control_set_program_name(m_id, i, prog.names[i]);
  1278. x_engine->osc_send_control_set_program(m_id, prog.current);
  1279. #endif
  1280. }
  1281. // MIDI Programs
  1282. if (midiprog.count > 0)
  1283. {
  1284. #ifdef BUILD_BRIDGE
  1285. x_engine->osc_send_bridge_midi_program_count(midiprog.count);
  1286. for (uint32_t i=0; i < midiprog.count; i++)
  1287. x_engine->osc_send_bridge_midi_program_info(i, midiprog.data[i].bank, midiprog.data[i].program, midiprog.data[i].name);
  1288. x_engine->osc_send_bridge_set_midi_program(prog.current);
  1289. #else
  1290. x_engine->osc_send_control_set_midi_program_count(m_id, midiprog.count);
  1291. for (uint32_t i=0; i < midiprog.count; i++)
  1292. x_engine->osc_send_control_set_midi_program_data(m_id, i, midiprog.data[i].bank, midiprog.data[i].program, midiprog.data[i].name);
  1293. x_engine->osc_send_control_set_midi_program(m_id, midiprog.current);
  1294. #endif
  1295. }
  1296. #ifndef BUILD_BRIDGE
  1297. x_engine->osc_send_control_add_plugin_end(m_id);
  1298. // Internal Parameters
  1299. {
  1300. x_engine->osc_send_control_set_parameter_value(m_id, PARAMETER_ACTIVE, m_active ? 1.0 : 0.0);
  1301. x_engine->osc_send_control_set_parameter_value(m_id, PARAMETER_DRYWET, x_dryWet);
  1302. x_engine->osc_send_control_set_parameter_value(m_id, PARAMETER_VOLUME, x_volume);
  1303. x_engine->osc_send_control_set_parameter_value(m_id, PARAMETER_BALANCE_LEFT, x_balanceLeft);
  1304. x_engine->osc_send_control_set_parameter_value(m_id, PARAMETER_BALANCE_RIGHT, x_balanceRight);
  1305. }
  1306. #endif
  1307. }
  1308. #ifndef BUILD_BRIDGE
  1309. /*!
  1310. * Update the plugin's internal OSC data according to \a source and \a url.\n
  1311. * This is used for OSC-GUI bridges.
  1312. */
  1313. void updateOscData(const lo_address source, const char* const url)
  1314. {
  1315. // FIXME - remove debug prints later
  1316. qWarning("CarlaPlugin::updateOscData(%p, \"%s\")", source, url);
  1317. const char* host;
  1318. const char* port;
  1319. const int proto = lo_address_get_protocol(source);
  1320. osc.data.free();
  1321. host = lo_address_get_hostname(source);
  1322. port = lo_address_get_port(source);
  1323. osc.data.source = lo_address_new_with_proto(proto, host, port);
  1324. qWarning("CarlaPlugin::updateOscData() - source: host \"%s\", port \"%s\"", host, port);
  1325. host = lo_url_get_hostname(url);
  1326. port = lo_url_get_port(url);
  1327. osc.data.path = lo_url_get_path(url);
  1328. osc.data.target = lo_address_new_with_proto(proto, host, port);
  1329. qWarning("CarlaPlugin::updateOscData() - target: host \"%s\", port \"%s\", path \"%s\"", host, port, osc.data.path);
  1330. free((void*)host);
  1331. free((void*)port);
  1332. if (m_hints & PLUGIN_IS_BRIDGE)
  1333. return;
  1334. osc_send_sample_rate(&osc.data, x_engine->getSampleRate());
  1335. for (size_t i=0; i < custom.size(); i++)
  1336. {
  1337. // TODO
  1338. //if (m_type == PLUGIN_LV2)
  1339. //osc_send_lv2_transfer_event(&osc.data, getCustomDataTypeString(custom[i].type), /*custom[i].key,*/ custom[i].value);
  1340. //else
  1341. if (custom[i].type == CUSTOM_DATA_STRING)
  1342. osc_send_configure(&osc.data, custom[i].key, custom[i].value);
  1343. }
  1344. if (prog.current >= 0)
  1345. osc_send_program(&osc.data, prog.current);
  1346. if (midiprog.current >= 0)
  1347. {
  1348. if (m_type == PLUGIN_DSSI)
  1349. osc_send_program(&osc.data, midiprog.data[midiprog.current].bank, midiprog.data[midiprog.current].program);
  1350. else
  1351. osc_send_midi_program(&osc.data, midiprog.data[midiprog.current].bank, midiprog.data[midiprog.current].program);
  1352. }
  1353. for (uint32_t i=0; i < param.count; i++)
  1354. osc_send_control(&osc.data, param.data[i].rindex, getParameterValue(i));
  1355. qWarning("CarlaPlugin::updateOscData() - done");
  1356. }
  1357. /*!
  1358. * Free the plugin's internal OSC memory data.
  1359. */
  1360. void freeOscData()
  1361. {
  1362. osc.data.free();
  1363. }
  1364. /*!
  1365. * Show the plugin's OSC based GUI.\n
  1366. * This is a handy function that waits for the GUI to respond and automatically asks it to show itself.
  1367. */
  1368. bool showOscGui()
  1369. {
  1370. qWarning("CarlaPlugin::showOscGui()");
  1371. // wait for UI 'update' call
  1372. for (uint i=0; i < carlaOptions.oscUiTimeout; i++)
  1373. {
  1374. if (osc.data.target)
  1375. {
  1376. qWarning("CarlaPlugin::showOscGui() - got response, asking UI to show itself now");
  1377. osc_send_show(&osc.data);
  1378. return true;
  1379. }
  1380. else
  1381. carla_msleep(100);
  1382. }
  1383. qWarning("CarlaPlugin::showOscGui() - Timeout while waiting for UI to respond");
  1384. return false;
  1385. }
  1386. #endif
  1387. // -------------------------------------------------------------------
  1388. // MIDI events
  1389. /*!
  1390. * Send a single midi note to be processed in the next audio callback.\n
  1391. * A note with 0 velocity means note-off.
  1392. */
  1393. void sendMidiSingleNote(const uint8_t channel, const uint8_t note, const uint8_t velo, const bool sendGui, const bool sendOsc, const bool sendCallback)
  1394. {
  1395. CARLA_ASSERT(channel < 16);
  1396. CARLA_ASSERT(note < 128);
  1397. CARLA_ASSERT(velo < 128);
  1398. if (! m_active)
  1399. return;
  1400. engineMidiLock();
  1401. for (unsigned short i=0; i < MAX_MIDI_EVENTS; i++)
  1402. {
  1403. if (extMidiNotes[i].channel < 0)
  1404. {
  1405. extMidiNotes[i].channel = channel;
  1406. extMidiNotes[i].note = note;
  1407. extMidiNotes[i].velo = velo;
  1408. break;
  1409. }
  1410. }
  1411. engineMidiUnlock();
  1412. if (sendGui)
  1413. {
  1414. if (velo > 0)
  1415. uiNoteOn(channel, note, velo);
  1416. else
  1417. uiNoteOff(channel, note);
  1418. }
  1419. #ifndef BUILD_BRIDGE
  1420. if (sendOsc)
  1421. {
  1422. if (velo > 0)
  1423. x_engine->osc_send_control_note_on(m_id, channel, note, velo);
  1424. else
  1425. x_engine->osc_send_control_note_off(m_id, channel, note);
  1426. }
  1427. #else
  1428. Q_UNUSED(sendOsc);
  1429. #endif
  1430. if (sendCallback)
  1431. x_engine->callback(velo ? CALLBACK_NOTE_ON : CALLBACK_NOTE_OFF, m_id, channel, note, velo);
  1432. }
  1433. /*!
  1434. * Send all midi notes off for the next audio callback.\n
  1435. * This doesn't send the actual MIDI All-Notes-Off event, but 128 note-offs instead.
  1436. */
  1437. void sendMidiAllNotesOff()
  1438. {
  1439. engineMidiLock();
  1440. postEvents.mutex.lock();
  1441. unsigned short postPad = 0;
  1442. for (unsigned short i=0; i < MAX_POST_EVENTS; i++)
  1443. {
  1444. if (postEvents.data[i].type == PluginPostEventNull)
  1445. {
  1446. postPad = i;
  1447. break;
  1448. }
  1449. }
  1450. if (postPad == MAX_POST_EVENTS - 1)
  1451. {
  1452. qWarning("post-events buffer full, making room for all notes off now");
  1453. postPad -= 128;
  1454. }
  1455. for (unsigned short i=0; i < 128; i++)
  1456. {
  1457. extMidiNotes[i].channel = m_ctrlInChannel;
  1458. extMidiNotes[i].note = i;
  1459. extMidiNotes[i].velo = 0;
  1460. postEvents.data[i + postPad].type = PluginPostEventNoteOff;
  1461. postEvents.data[i + postPad].value1 = m_ctrlInChannel;
  1462. postEvents.data[i + postPad].value2 = i;
  1463. postEvents.data[i + postPad].value3 = 0.0;
  1464. }
  1465. postEvents.mutex.unlock();
  1466. engineMidiUnlock();
  1467. }
  1468. // -------------------------------------------------------------------
  1469. // Post-poned events
  1470. /*!
  1471. * Post pone an event of type \a type.\n
  1472. * The event will be processed later, but as soon as possible.
  1473. */
  1474. void postponeEvent(const PluginPostEventType type, const int32_t value1, const int32_t value2, const double value3, const void* const cdata = nullptr)
  1475. {
  1476. postEvents.mutex.lock();
  1477. for (unsigned short i=0; i < MAX_POST_EVENTS; i++)
  1478. {
  1479. if (postEvents.data[i].type == PluginPostEventNull)
  1480. {
  1481. postEvents.data[i].type = type;
  1482. postEvents.data[i].value1 = value1;
  1483. postEvents.data[i].value2 = value2;
  1484. postEvents.data[i].value3 = value3;
  1485. postEvents.data[i].cdata = cdata;
  1486. break;
  1487. }
  1488. }
  1489. postEvents.mutex.unlock();
  1490. }
  1491. /*!
  1492. * Process all the post-poned events.
  1493. * This function will only be called from the main thread if PLUGIN_USES_SINGLE_THREAD is set.
  1494. */
  1495. void postEventsRun()
  1496. {
  1497. PluginPostEvent newPostEvents[MAX_POST_EVENTS];
  1498. // Make a safe copy of events, and clear them
  1499. postEvents.mutex.lock();
  1500. memcpy(newPostEvents, postEvents.data, sizeof(PluginPostEvent)*MAX_POST_EVENTS);
  1501. for (unsigned short i=0; i < MAX_POST_EVENTS; i++)
  1502. postEvents.data[i].type = PluginPostEventNull;
  1503. postEvents.mutex.unlock();
  1504. // Handle events now
  1505. for (uint32_t i=0; i < MAX_POST_EVENTS; i++)
  1506. {
  1507. const PluginPostEvent* const event = &newPostEvents[i];
  1508. switch (event->type)
  1509. {
  1510. case PluginPostEventNull:
  1511. break;
  1512. case PluginPostEventDebug:
  1513. x_engine->callback(CALLBACK_DEBUG, m_id, event->value1, event->value2, event->value3);
  1514. break;
  1515. case PluginPostEventParameterChange:
  1516. // Update UI
  1517. if (event->value1 >= 0)
  1518. uiParameterChange(event->value1, event->value3);
  1519. #ifndef BUILD_BRIDGE
  1520. // Update OSC control client
  1521. if (x_engine->isOscControlRegisted())
  1522. x_engine->osc_send_control_set_parameter_value(m_id, event->value1, event->value3);
  1523. #endif
  1524. // Update Host
  1525. x_engine->callback(CALLBACK_PARAMETER_VALUE_CHANGED, m_id, event->value1, 0, event->value3);
  1526. break;
  1527. case PluginPostEventProgramChange:
  1528. // Update UI
  1529. if (event->value1 >= 0)
  1530. uiProgramChange(event->value1);
  1531. #ifndef BUILD_BRIDGE
  1532. // Update OSC control client
  1533. if (x_engine->isOscControlRegisted())
  1534. {
  1535. x_engine->osc_send_control_set_program(m_id, event->value1);
  1536. for (uint32_t j=0; j < param.count; j++)
  1537. x_engine->osc_send_control_set_default_value(m_id, j, param.ranges[j].def);
  1538. }
  1539. #endif
  1540. // Update Host
  1541. x_engine->callback(CALLBACK_PROGRAM_CHANGED, m_id, event->value1, 0, 0.0);
  1542. break;
  1543. case PluginPostEventMidiProgramChange:
  1544. // Update UI
  1545. if (event->value1 >= 0)
  1546. uiMidiProgramChange(event->value1);
  1547. #ifndef BUILD_BRIDGE
  1548. // Update OSC control client
  1549. if (x_engine->isOscControlRegisted())
  1550. {
  1551. x_engine->osc_send_control_set_midi_program(m_id, event->value1);
  1552. for (uint32_t j=0; j < param.count; j++)
  1553. x_engine->osc_send_control_set_default_value(m_id, j, param.ranges[j].def);
  1554. }
  1555. #endif
  1556. // Update Host
  1557. x_engine->callback(CALLBACK_MIDI_PROGRAM_CHANGED, m_id, event->value1, 0, 0.0);
  1558. break;
  1559. case PluginPostEventNoteOn:
  1560. // Update UI
  1561. uiNoteOn(event->value1, event->value2, rint(event->value3));
  1562. #ifndef BUILD_BRIDGE
  1563. // Update OSC control client
  1564. if (x_engine->isOscControlRegisted())
  1565. x_engine->osc_send_control_note_on(m_id, event->value1, event->value2, rint(event->value3));
  1566. #endif
  1567. // Update Host
  1568. x_engine->callback(CALLBACK_NOTE_ON, m_id, event->value1, event->value2, rint(event->value3));
  1569. break;
  1570. case PluginPostEventNoteOff:
  1571. // Update UI
  1572. uiNoteOff(event->value1, event->value2);
  1573. #ifndef BUILD_BRIDGE
  1574. // Update OSC control client
  1575. if (x_engine->isOscControlRegisted())
  1576. x_engine->osc_send_control_note_off(m_id, event->value1, event->value2);
  1577. #endif
  1578. // Update Host
  1579. x_engine->callback(CALLBACK_NOTE_OFF, m_id, event->value1, event->value2, 0.0);
  1580. break;
  1581. case PluginPostEventCustom:
  1582. // Handle custom event
  1583. postEventHandleCustom(event->value1, event->value2, event->value3, event->cdata);
  1584. break;
  1585. }
  1586. }
  1587. }
  1588. /*!
  1589. * Handle custom post event.\n
  1590. * Implementation depends on plugin type.
  1591. */
  1592. virtual void postEventHandleCustom(const int32_t value1, const int32_t value2, const double value3, const void* const cdata)
  1593. {
  1594. Q_UNUSED(value1);
  1595. Q_UNUSED(value2);
  1596. Q_UNUSED(value3);
  1597. Q_UNUSED(cdata);
  1598. }
  1599. /*!
  1600. * Tell the UI a parameter has changed.
  1601. */
  1602. virtual void uiParameterChange(const uint32_t index, const double value)
  1603. {
  1604. CARLA_ASSERT(index < param.count);
  1605. Q_UNUSED(value);
  1606. }
  1607. /*!
  1608. * Tell the UI the current program has changed.
  1609. */
  1610. virtual void uiProgramChange(const uint32_t index)
  1611. {
  1612. CARLA_ASSERT(index < prog.count);
  1613. }
  1614. /*!
  1615. * Tell the UI the current midi program has changed.
  1616. */
  1617. virtual void uiMidiProgramChange(const uint32_t index)
  1618. {
  1619. CARLA_ASSERT(index < midiprog.count);
  1620. }
  1621. /*!
  1622. * Tell the UI a note has been pressed.
  1623. */
  1624. virtual void uiNoteOn(const uint8_t channel, const uint8_t note, const uint8_t velo)
  1625. {
  1626. CARLA_ASSERT(channel < 16);
  1627. CARLA_ASSERT(note < 128);
  1628. CARLA_ASSERT(velo > 0 && velo < 128);
  1629. }
  1630. /*!
  1631. * Tell the UI a note has been released.
  1632. */
  1633. virtual void uiNoteOff(const uint8_t channel, const uint8_t note)
  1634. {
  1635. CARLA_ASSERT(channel < 16);
  1636. CARLA_ASSERT(note < 128);
  1637. }
  1638. // -------------------------------------------------------------------
  1639. // Cleanup
  1640. /*!
  1641. * Clear the engine client ports of the plugin.
  1642. */
  1643. virtual void removeClientPorts()
  1644. {
  1645. qDebug("CarlaPlugin::removeClientPorts() - start");
  1646. for (uint32_t i=0; i < aIn.count; i++)
  1647. {
  1648. delete aIn.ports[i];
  1649. aIn.ports[i] = nullptr;
  1650. }
  1651. for (uint32_t i=0; i < aOut.count; i++)
  1652. {
  1653. delete aOut.ports[i];
  1654. aOut.ports[i] = nullptr;
  1655. }
  1656. if (midi.portMin)
  1657. {
  1658. delete midi.portMin;
  1659. midi.portMin = nullptr;
  1660. }
  1661. if (midi.portMout)
  1662. {
  1663. delete midi.portMout;
  1664. midi.portMout = nullptr;
  1665. }
  1666. if (param.portCin)
  1667. {
  1668. delete param.portCin;
  1669. param.portCin = nullptr;
  1670. }
  1671. if (param.portCout)
  1672. {
  1673. delete param.portCout;
  1674. param.portCout = nullptr;
  1675. }
  1676. qDebug("CarlaPlugin::removeClientPorts() - end");
  1677. }
  1678. /*!
  1679. * Initialize all RT buffers of the plugin.
  1680. */
  1681. virtual void initBuffers()
  1682. {
  1683. for (uint32_t i=0; i < aIn.count; i++)
  1684. {
  1685. if (aIn.ports[i])
  1686. aIn.ports[i]->initBuffer(x_engine);
  1687. }
  1688. for (uint32_t i=0; i < aOut.count; i++)
  1689. {
  1690. if (aOut.ports[i])
  1691. aOut.ports[i]->initBuffer(x_engine);
  1692. }
  1693. if (param.portCin)
  1694. param.portCin->initBuffer(x_engine);
  1695. if (param.portCout)
  1696. param.portCout->initBuffer(x_engine);
  1697. if (midi.portMin)
  1698. midi.portMin->initBuffer(x_engine);
  1699. if (midi.portMout)
  1700. midi.portMout->initBuffer(x_engine);
  1701. }
  1702. /*!
  1703. * Delete all temporary buffers of the plugin.
  1704. */
  1705. virtual void deleteBuffers()
  1706. {
  1707. qDebug("CarlaPlugin::deleteBuffers() - start");
  1708. if (aIn.count > 0)
  1709. {
  1710. delete[] aIn.ports;
  1711. delete[] aIn.rindexes;
  1712. }
  1713. if (aOut.count > 0)
  1714. {
  1715. delete[] aOut.ports;
  1716. delete[] aOut.rindexes;
  1717. }
  1718. if (param.count > 0)
  1719. {
  1720. delete[] param.data;
  1721. delete[] param.ranges;
  1722. }
  1723. aIn.count = 0;
  1724. aIn.ports = nullptr;
  1725. aIn.rindexes = nullptr;
  1726. aOut.count = 0;
  1727. aOut.ports = nullptr;
  1728. aOut.rindexes = nullptr;
  1729. param.count = 0;
  1730. param.data = nullptr;
  1731. param.ranges = nullptr;
  1732. param.portCin = nullptr;
  1733. param.portCout = nullptr;
  1734. qDebug("CarlaPlugin::deleteBuffers() - end");
  1735. }
  1736. // -------------------------------------------------------------------
  1737. // Library functions
  1738. /*!
  1739. * Open the DLL \a filename.
  1740. */
  1741. bool libOpen(const char* const filename)
  1742. {
  1743. m_lib = lib_open(filename);
  1744. return bool(m_lib);
  1745. }
  1746. /*!
  1747. * Close the DLL previously loaded in libOpen().
  1748. */
  1749. bool libClose()
  1750. {
  1751. if (m_lib)
  1752. return lib_close(m_lib);
  1753. return false;
  1754. }
  1755. /*!
  1756. * Get the symbol entry \a symbol of the currently loaded DLL.
  1757. */
  1758. void* libSymbol(const char* const symbol)
  1759. {
  1760. if (m_lib)
  1761. return lib_symbol(m_lib, symbol);
  1762. return nullptr;
  1763. }
  1764. /*!
  1765. * Get the last DLL related error.
  1766. */
  1767. const char* libError(const char* const filename)
  1768. {
  1769. return lib_error(filename);
  1770. }
  1771. // -------------------------------------------------------------------
  1772. // Locks
  1773. void engineProcessLock()
  1774. {
  1775. x_engine->processLock();
  1776. }
  1777. void engineProcessUnlock()
  1778. {
  1779. x_engine->processUnlock();
  1780. }
  1781. void engineMidiLock()
  1782. {
  1783. x_engine->midiLock();
  1784. }
  1785. void engineMidiUnlock()
  1786. {
  1787. x_engine->midiUnlock();
  1788. }
  1789. // -------------------------------------------------------------------
  1790. // Plugin initializers
  1791. struct initializer {
  1792. CarlaEngine* const engine;
  1793. const char* const filename;
  1794. const char* const name;
  1795. const char* const label;
  1796. };
  1797. static CarlaPlugin* newLADSPA(const initializer& init, const void* const extra);
  1798. static CarlaPlugin* newDSSI(const initializer& init, const void* const extra);
  1799. static CarlaPlugin* newLV2(const initializer& init);
  1800. static CarlaPlugin* newVST(const initializer& init);
  1801. static CarlaPlugin* newGIG(const initializer& init);
  1802. static CarlaPlugin* newSF2(const initializer& init);
  1803. static CarlaPlugin* newSFZ(const initializer& init);
  1804. #ifndef BUILD_BRIDGE
  1805. static CarlaPlugin* newBridge(const initializer& init, const BinaryType btype, const PluginType ptype);
  1806. #endif
  1807. static CarlaPlugin* newNative(const initializer& init);
  1808. static size_t getNativePluginCount();
  1809. static const PluginDescriptor* getNativePlugin(size_t index);
  1810. // -------------------------------------------------------------------
  1811. /*!
  1812. * \class ScopedDisabler
  1813. *
  1814. * \brief Carla plugin scoped disabler
  1815. *
  1816. * This is a handy class that temporarily disables a plugin during a function scope.\n
  1817. * It should be used when the plugin needs reload or state change, something like this:
  1818. * \code
  1819. * {
  1820. * const CarlaPlugin::ScopedDisabler m(plugin);
  1821. * plugin->setChunkData(data);
  1822. * }
  1823. * \endcode
  1824. */
  1825. class ScopedDisabler
  1826. {
  1827. public:
  1828. /*!
  1829. * Disable plugin \a plugin if \a disable is true.
  1830. * The plugin is re-enabled in the deconstructor of this class if \a disable is true.
  1831. *
  1832. * \param plugin The plugin to disable
  1833. * \param disable Wherever to disable the plugin or not, true by default
  1834. */
  1835. ScopedDisabler(CarlaPlugin* const plugin, const bool disable = true)
  1836. : m_plugin(plugin),
  1837. m_disable(disable)
  1838. {
  1839. if (m_disable)
  1840. {
  1841. m_plugin->engineProcessLock();
  1842. m_plugin->setEnabled(false);
  1843. m_plugin->engineProcessUnlock();
  1844. }
  1845. }
  1846. ~ScopedDisabler()
  1847. {
  1848. if (m_disable)
  1849. {
  1850. m_plugin->engineProcessLock();
  1851. m_plugin->setEnabled(true);
  1852. m_plugin->engineProcessUnlock();
  1853. }
  1854. }
  1855. private:
  1856. CarlaPlugin* const m_plugin;
  1857. const bool m_disable;
  1858. };
  1859. // -------------------------------------------------------------------
  1860. protected:
  1861. unsigned short m_id;
  1862. CarlaEngine* const x_engine;
  1863. CarlaEngineClient* x_client;
  1864. double x_dryWet, x_volume;
  1865. double x_balanceLeft, x_balanceRight;
  1866. PluginType m_type;
  1867. unsigned int m_hints;
  1868. bool m_active;
  1869. bool m_activeBefore;
  1870. bool m_enabled;
  1871. void* m_lib;
  1872. const char* m_name;
  1873. const char* m_filename;
  1874. int8_t m_ctrlInChannel;
  1875. uint32_t m_latency;
  1876. float** m_latencyBuffers;
  1877. // -------------------------------------------------------------------
  1878. // Storage Data
  1879. PluginAudioData aIn;
  1880. PluginAudioData aOut;
  1881. PluginMidiData midi;
  1882. PluginParameterData param;
  1883. PluginProgramData prog;
  1884. PluginMidiProgramData midiprog;
  1885. std::vector<CustomData> custom;
  1886. // -------------------------------------------------------------------
  1887. // Extra
  1888. #ifndef BUILD_BRIDGE
  1889. struct {
  1890. CarlaOscData data;
  1891. CarlaPluginThread* thread;
  1892. } osc;
  1893. #endif
  1894. struct {
  1895. QMutex mutex;
  1896. PluginPostEvent data[MAX_POST_EVENTS];
  1897. } postEvents;
  1898. ExternalMidiNote extMidiNotes[MAX_MIDI_EVENTS];
  1899. // -------------------------------------------------------------------
  1900. // Utilities
  1901. static unsigned int m_count;
  1902. static double fixParameterValue(double& value, const ParameterRanges& ranges)
  1903. {
  1904. if (value < ranges.min)
  1905. value = ranges.min;
  1906. else if (value > ranges.max)
  1907. value = ranges.max;
  1908. return value;
  1909. }
  1910. static float fixParameterValue(float& value, const ParameterRanges& ranges)
  1911. {
  1912. if (value < ranges.min)
  1913. value = ranges.min;
  1914. else if (value > ranges.max)
  1915. value = ranges.max;
  1916. return value;
  1917. }
  1918. static double abs(const double& value)
  1919. {
  1920. return (value < 0.0) ? -value : value;
  1921. }
  1922. friend class CarlaEngineJack;
  1923. };
  1924. /**@}*/
  1925. CARLA_BACKEND_END_NAMESPACE
  1926. #endif // CARLA_PLUGIN_H