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.

SnappingSlider.h 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. @tweaker falkTX
  23. ==============================================================================
  24. */
  25. #ifndef DISTRHO_VEX_SNAPPINGSLIDERCOMPONENT_HEADER_INCLUDED
  26. #define DISTRHO_VEX_SNAPPINGSLIDERCOMPONENT_HEADER_INCLUDED
  27. #ifndef CARLA_EXPORT
  28. #define CARLA_EXPORT
  29. #endif
  30. #ifdef CARLA_EXPORT
  31. #include "juce_gui_basics.h"
  32. #else
  33. #include "../StandardHeader.h"
  34. #endif
  35. class SnappingSlider : public Slider
  36. {
  37. public:
  38. SnappingSlider(const String& name)
  39. : Slider(name),
  40. snapTarget(0.0f),
  41. snapMargin(0.05f)
  42. {
  43. }
  44. void setSnap(const float target, const float margin)
  45. {
  46. snapTarget = target;
  47. snapMargin = margin;
  48. }
  49. #if 0
  50. // FIXME?
  51. double snapValue(const double attemptedValue , const bool userIsDragging)
  52. {
  53. if (std::fabs(attemptedValue - snapTarget) < snapMargin)
  54. return snapTarget;
  55. return attemptedValue;
  56. }
  57. #endif
  58. private:
  59. float snapTarget, snapMargin;
  60. };
  61. #endif // DISTRHO_VEX_SNAPPINGSLIDERCOMPONENT_HEADER_INCLUDED