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.

162 lines
6.7KB

  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. /**
  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 ValueWithDefault object. This will add an item to the ComboBox for the
  63. default value with an ID of -1.
  64. @param valueToControl the ValueWithDefault 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 (ValueWithDefault& valueToControl,
  73. const String& propertyName,
  74. const StringArray& choices,
  75. const Array<var>& correspondingValues);
  76. /** Creates the component using a ValueWithDefault 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 (ValueWithDefault& valueToControl,
  81. const String& propertyName);
  82. /** Destructor. */
  83. ~ChoicePropertyComponent() override;
  84. //==============================================================================
  85. /** Called when the user selects an item from the combo box.
  86. Your subclass must use this callback to update the value that this component
  87. represents. The index is the index of the chosen item in the choices
  88. StringArray.
  89. */
  90. virtual void setIndex (int newIndex);
  91. /** Returns the index of the item that should currently be shown.
  92. This is the index of the item in the choices StringArray that will be shown.
  93. */
  94. virtual int getIndex() const;
  95. /** Returns the list of options. */
  96. const StringArray& getChoices() const;
  97. //==============================================================================
  98. /** @internal */
  99. void refresh() override;
  100. protected:
  101. /** The list of options that will be shown in the combo box.
  102. Your subclass must populate this array in its constructor. If any empty
  103. strings are added, these will be replaced with horizontal separators (see
  104. ComboBox::addSeparator() for more info).
  105. */
  106. StringArray choices;
  107. private:
  108. //==============================================================================
  109. class RemapperValueSource;
  110. class RemapperValueSourceWithDefault;
  111. //==============================================================================
  112. void createComboBox();
  113. void createComboBoxWithDefault (const String&);
  114. void changeIndex();
  115. //==============================================================================
  116. ComboBox comboBox;
  117. bool isCustomClass = false;
  118. WeakReference<ValueWithDefault> valueWithDefault;
  119. //==============================================================================
  120. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ChoicePropertyComponent)
  121. };
  122. } // namespace juce