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.

92 lines
3.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 6 technical preview.
  4. Copyright (c) 2020 - Raw Material Software Limited
  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. namespace juce
  14. {
  15. /**
  16. Provides a class of AudioProcessorParameter that can be used as a boolean value.
  17. @see AudioParameterFloat, AudioParameterInt, AudioParameterChoice
  18. @tags{Audio}
  19. */
  20. class JUCE_API AudioParameterBool : public RangedAudioParameter
  21. {
  22. public:
  23. /** Creates a AudioParameterBool with the specified parameters.
  24. @param parameterID The parameter ID to use
  25. @param parameterName The parameter name to use
  26. @param defaultValue The default value
  27. @param parameterLabel An optional label for the parameter's value
  28. @param stringFromBool An optional lambda function that converts a bool
  29. value to a string with a maximum length. This may
  30. be used by hosts to display the parameter's value.
  31. @param boolFromString An optional lambda function that parses a string and
  32. converts it into a bool value. Some hosts use this
  33. to allow users to type in parameter values.
  34. */
  35. AudioParameterBool (const String& parameterID, const String& parameterName, bool defaultValue,
  36. const String& parameterLabel = String(),
  37. std::function<String(bool value, int maximumStringLength)> stringFromBool = nullptr,
  38. std::function<bool(const String& text)> boolFromString = nullptr);
  39. /** Destructor. */
  40. ~AudioParameterBool() override;
  41. /** Returns the parameter's current boolean value. */
  42. bool get() const noexcept { return value >= 0.5f; }
  43. /** Returns the parameter's current boolean value. */
  44. operator bool() const noexcept { return get(); }
  45. /** Changes the parameter's current value to a new boolean. */
  46. AudioParameterBool& operator= (bool newValue);
  47. /** Returns the range of values that the parameter can take. */
  48. const NormalisableRange<float>& getNormalisableRange() const override { return range; }
  49. protected:
  50. /** Override this method if you are interested in receiving callbacks
  51. when the parameter value changes.
  52. */
  53. virtual void valueChanged (bool newValue);
  54. private:
  55. //==============================================================================
  56. float getValue() const override;
  57. void setValue (float newValue) override;
  58. float getDefaultValue() const override;
  59. int getNumSteps() const override;
  60. bool isDiscrete() const override;
  61. bool isBoolean() const override;
  62. String getText (float, int) const override;
  63. float getValueForText (const String&) const override;
  64. const NormalisableRange<float> range { 0.0f, 1.0f, 1.0f };
  65. std::atomic<float> value;
  66. const float defaultValue;
  67. std::function<String(bool, int)> stringFromBoolFunction;
  68. std::function<bool(const String&)> boolFromStringFunction;
  69. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioParameterBool)
  70. };
  71. } // namespace juce