The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

44 lines
1.4KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 6 technical preview.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. You may use this code under the terms of the GPL v3
  6. (see www.gnu.org/licenses).
  7. For this technical preview, this file is not subject to commercial licensing.
  8. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  9. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  10. DISCLAIMED.
  11. ==============================================================================
  12. */
  13. #pragma once
  14. //==============================================================================
  15. template <typename Type>
  16. class NumericValueSource : public ValueSourceFilter
  17. {
  18. public:
  19. NumericValueSource (const Value& source) : ValueSourceFilter (source) {}
  20. var getValue() const override
  21. {
  22. return (Type) sourceValue.getValue();
  23. }
  24. void setValue (const var& newValue) override
  25. {
  26. const Type newVal = static_cast<Type> (newValue);
  27. if (newVal != static_cast<Type> (getValue())) // this test is important, because if a property is missing, it won't
  28. sourceValue = newVal; // create it (causing an unwanted undo action) when a control sets it to 0
  29. }
  30. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (NumericValueSource)
  31. };