Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.0KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCETICE project - Copyright 2008 by Lucio Asnaghi.
  4. JUCETICE is based around the JUCE library - "Jules' Utility Class Extensions"
  5. Copyright 2008 by Julian Storer.
  6. ------------------------------------------------------------------------------
  7. JUCE and JUCETICE can be redistributed and/or modified under the terms of
  8. the GNU Lesser General Public License, as published by the Free Software
  9. Foundation; either version 2 of the License, or (at your option) any later
  10. version.
  11. JUCE and JUCETICE are distributed in the hope that they will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License for more details.
  15. You should have received a copy of the GNU Lesser General Public License
  16. along with JUCE and JUCETICE; if not, visit www.gnu.org/licenses or write to
  17. Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  18. Boston, MA 02111-1307 USA
  19. ==============================================================================
  20. @author rockhardbuns
  21. @tweaker Lucio Asnaghi
  22. ==============================================================================
  23. */
  24. #ifndef __JUCETICE_VEXSNAPPINGSLIDERCOMPONENT_HEADER__
  25. #define __JUCETICE_VEXSNAPPINGSLIDERCOMPONENT_HEADER__
  26. #include "../StandardHeader.h"
  27. class SnappingSlider : public Slider
  28. {
  29. public:
  30. SnappingSlider(const String& name)
  31. : Slider(name),
  32. snapTarget(0.0f),
  33. snapMargin(0.05f)
  34. {
  35. }
  36. void setSnap(const float target, const float margin)
  37. {
  38. snapTarget = target;
  39. snapMargin = margin;
  40. }
  41. double snapValue(const double attemptedValue, const bool userIsDragging)
  42. {
  43. if (std::fabs(attemptedValue - snapTarget) < snapMargin)
  44. return snapTarget;
  45. return attemptedValue;
  46. }
  47. private:
  48. float snapTarget, snapMargin;
  49. };
  50. #endif