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.

111 lines
4.5KB

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