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.

155 lines
6.4KB

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