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.

122 lines
4.6KB

  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. #pragma once
  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. */
  34. class JUCE_API ChoicePropertyComponent : public PropertyComponent,
  35. private ComboBox::Listener
  36. {
  37. protected:
  38. /** Creates the component.
  39. Your subclass's constructor must add a list of options to the choices member variable.
  40. */
  41. ChoicePropertyComponent (const String& propertyName);
  42. public:
  43. /** Creates the component.
  44. Note that if you call this constructor then you must use the Value to interact with the
  45. index, and you can't override the class with your own setIndex or getIndex methods.
  46. If you want to use those methods, call the other constructor instead.
  47. @param valueToControl the value that the combo box will read and control
  48. @param propertyName the name of the property
  49. @param choices the list of possible values that the drop-down list will contain
  50. @param correspondingValues a list of values corresponding to each item in the 'choices' StringArray.
  51. These are the values that will be read and written to the
  52. valueToControl value. This array must contain the same number of items
  53. as the choices array
  54. */
  55. ChoicePropertyComponent (const Value& valueToControl,
  56. const String& propertyName,
  57. const StringArray& choices,
  58. const Array<var>& correspondingValues);
  59. /** Destructor. */
  60. ~ChoicePropertyComponent();
  61. //==============================================================================
  62. /** Called when the user selects an item from the combo box.
  63. Your subclass must use this callback to update the value that this component
  64. represents. The index is the index of the chosen item in the choices
  65. StringArray.
  66. */
  67. virtual void setIndex (int newIndex);
  68. /** Returns the index of the item that should currently be shown.
  69. This is the index of the item in the choices StringArray that will be shown.
  70. */
  71. virtual int getIndex() const;
  72. /** Returns the list of options. */
  73. const StringArray& getChoices() const;
  74. //==============================================================================
  75. /** @internal */
  76. void refresh();
  77. protected:
  78. /** The list of options that will be shown in the combo box.
  79. Your subclass must populate this array in its constructor. If any empty
  80. strings are added, these will be replaced with horizontal separators (see
  81. ComboBox::addSeparator() for more info).
  82. */
  83. StringArray choices;
  84. private:
  85. ComboBox comboBox;
  86. bool isCustomClass;
  87. class RemapperValueSource;
  88. void createComboBox();
  89. void comboBoxChanged (ComboBox*);
  90. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ChoicePropertyComponent)
  91. };