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.

154 lines
6.5KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - 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 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-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. /**
  22. A PropertyComponent that shows its value as a combo box.
  23. This type of property component contains a list of options and has a
  24. combo box to choose one.
  25. Your subclass's constructor must add some strings to the choices StringArray
  26. and these are shown in the list.
  27. The getIndex() method will be called to find out which option is the currently
  28. selected one. If you call refresh() it will call getIndex() to check whether
  29. the value has changed, and will update the combo box if needed.
  30. If the user selects a different item from the list, setIndex() will be
  31. called to let your class process this.
  32. @see PropertyComponent, PropertyPanel
  33. @tags{GUI}
  34. */
  35. class JUCE_API ChoicePropertyComponent : public PropertyComponent
  36. {
  37. private:
  38. /** Delegating constructor. */
  39. ChoicePropertyComponent (const String&, const StringArray&, const Array<var>&);
  40. protected:
  41. /** Creates the component.
  42. Your subclass's constructor must add a list of options to the choices member variable.
  43. */
  44. ChoicePropertyComponent (const String& propertyName);
  45. public:
  46. /** Creates the component.
  47. Note that if you call this constructor then you must use the Value to interact with the
  48. index, and you can't override the class with your own setIndex or getIndex methods.
  49. If you want to use those methods, call the other constructor instead.
  50. @param valueToControl the value that the combo box will read and control
  51. @param propertyName the name of the property
  52. @param choices the list of possible values that the drop-down list will contain
  53. @param correspondingValues a list of values corresponding to each item in the 'choices' StringArray.
  54. These are the values that will be read and written to the
  55. valueToControl value. This array must contain the same number of items
  56. as the choices array
  57. */
  58. ChoicePropertyComponent (const Value& valueToControl,
  59. const String& propertyName,
  60. const StringArray& choices,
  61. const Array<var>& correspondingValues);
  62. /** Creates the component using a ValueTreePropertyWithDefault object. This will add an item to the ComboBox for the
  63. default value with an ID of -1.
  64. @param valueToControl the ValueTreePropertyWithDefault object that contains the Value object that the combo box will read and control.
  65. @param propertyName the name of the property
  66. @param choices the list of possible values that the drop-down list will contain
  67. @param correspondingValues a list of values corresponding to each item in the 'choices' StringArray.
  68. These are the values that will be read and written to the
  69. valueToControl value. This array must contain the same number of items
  70. as the choices array
  71. */
  72. ChoicePropertyComponent (const ValueTreePropertyWithDefault& valueToControl,
  73. const String& propertyName,
  74. const StringArray& choices,
  75. const Array<var>& correspondingValues);
  76. /** Creates the component using a ValueTreePropertyWithDefault object, adding an item to the ComboBox for the
  77. default value with an ID of -1 as well as adding separate "Enabled" and "Disabled" options.
  78. This is useful for simple on/off choices that also need a default value.
  79. */
  80. ChoicePropertyComponent (const ValueTreePropertyWithDefault& valueToControl,
  81. const String& propertyName);
  82. //==============================================================================
  83. /** Called when the user selects an item from the combo box.
  84. Your subclass must use this callback to update the value that this component
  85. represents. The index is the index of the chosen item in the choices
  86. StringArray.
  87. */
  88. virtual void setIndex (int newIndex);
  89. /** Returns the index of the item that should currently be shown.
  90. This is the index of the item in the choices StringArray that will be shown.
  91. */
  92. virtual int getIndex() const;
  93. /** Returns the list of options. */
  94. const StringArray& getChoices() const;
  95. //==============================================================================
  96. /** @internal */
  97. void refresh() override;
  98. protected:
  99. /** The list of options that will be shown in the combo box.
  100. Your subclass must populate this array in its constructor. If any empty
  101. strings are added, these will be replaced with horizontal separators (see
  102. ComboBox::addSeparator() for more info).
  103. */
  104. StringArray choices;
  105. private:
  106. //==============================================================================
  107. void initialiseComboBox (const Value&);
  108. void refreshChoices();
  109. void refreshChoices (const String&);
  110. void changeIndex();
  111. //==============================================================================
  112. ValueTreePropertyWithDefault value;
  113. ComboBox comboBox;
  114. bool isCustomClass = false;
  115. //==============================================================================
  116. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ChoicePropertyComponent)
  117. };
  118. } // namespace juce