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.

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