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.

112 lines
4.5KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. namespace juce
  20. {
  21. /**
  22. Provides a class of AudioProcessorParameter that can be used to select
  23. an indexed, named choice from a list.
  24. @see AudioParameterFloat, AudioParameterInt, AudioParameterBool
  25. @tags{Audio}
  26. */
  27. class JUCE_API AudioParameterChoice : public RangedAudioParameter
  28. {
  29. public:
  30. /** Creates a AudioParameterChoice with the specified parameters.
  31. @param parameterID The parameter ID to use
  32. @param name The parameter name to use
  33. @param choices The set of choices to use
  34. @param defaultItemIndex The index of the default choice
  35. @param label An optional label for the parameter's value
  36. @param stringFromIndex An optional lambda function that converts a choice
  37. index to a string with a maximum length. This may
  38. be used by hosts to display the parameter's value.
  39. @param indexFromString An optional lambda function that parses a string and
  40. converts it into a choice index. Some hosts use this
  41. to allow users to type in parameter values.
  42. */
  43. AudioParameterChoice (const String& parameterID, const String& name,
  44. const StringArray& choices,
  45. int defaultItemIndex,
  46. const String& label = String(),
  47. std::function<String(int index, int maximumStringLength)> stringFromIndex = nullptr,
  48. std::function<int(const String& text)> indexFromString = nullptr);
  49. /** Destructor. */
  50. ~AudioParameterChoice() override;
  51. /** Returns the current index of the selected item. */
  52. int getIndex() const noexcept { return roundToInt (value); }
  53. /** Returns the current index of the selected item. */
  54. operator int() const noexcept { return getIndex(); }
  55. /** Returns the name of the currently selected item. */
  56. String getCurrentChoiceName() const noexcept { return choices[getIndex()]; }
  57. /** Returns the name of the currently selected item. */
  58. operator String() const noexcept { return getCurrentChoiceName(); }
  59. /** Changes the selected item to a new index. */
  60. AudioParameterChoice& operator= (int newValue);
  61. /** Returns the range of values that the parameter can take. */
  62. const NormalisableRange<float>& getNormalisableRange() const override { return range; }
  63. /** Provides access to the list of choices that this parameter is working with. */
  64. const StringArray choices;
  65. protected:
  66. /** Override this method if you are interested in receiving callbacks
  67. when the parameter value changes.
  68. */
  69. virtual void valueChanged (int newValue);
  70. private:
  71. //==============================================================================
  72. float getValue() const override;
  73. void setValue (float newValue) override;
  74. float getDefaultValue() const override;
  75. int getNumSteps() const override;
  76. bool isDiscrete() const override;
  77. String getText (float, int) const override;
  78. float getValueForText (const String&) const override;
  79. const NormalisableRange<float> range;
  80. float value;
  81. const float defaultValue;
  82. std::function<String(int, int)> stringFromIndexFunction;
  83. std::function<int(const String&)> indexFromStringFunction;
  84. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioParameterChoice)
  85. };
  86. } // namespace juce