The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

124 lines
3.7KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. class ChannelClickListener
  18. {
  19. public:
  20. virtual ~ChannelClickListener() {}
  21. virtual void channelButtonClicked (int channelIndex) = 0;
  22. };
  23. class SurroundEditor : public AudioProcessorEditor,
  24. public ButtonListener,
  25. private Timer
  26. {
  27. public:
  28. SurroundEditor (AudioProcessor& parent)
  29. : AudioProcessorEditor (parent),
  30. currentChannelLayout (AudioChannelSet::disabled()),
  31. noChannelsLabel ("noChannelsLabel", "Input disabled")
  32. {
  33. addAndMakeVisible (noChannelsLabel);
  34. setSize (640, 64);
  35. timerCallback();
  36. startTimer (500);
  37. }
  38. ~SurroundEditor()
  39. {
  40. }
  41. void resized() override
  42. {
  43. Rectangle<int> r = getLocalBounds();
  44. noChannelsLabel.setBounds (r);
  45. if (channelButtons.size() > 0)
  46. {
  47. const int buttonWidth = r.getWidth() / channelButtons.size();
  48. for (int i = 0; i < channelButtons.size(); ++i)
  49. channelButtons[i]->setBounds (r.removeFromLeft (buttonWidth));
  50. }
  51. }
  52. void paint (Graphics& g) override
  53. {
  54. g.fillAll (Colours::white);
  55. }
  56. void buttonClicked (Button* btn) override
  57. {
  58. if (TextButton* textButton = dynamic_cast<TextButton*> (btn))
  59. {
  60. const int channelIndex = channelButtons.indexOf (textButton);
  61. if (ChannelClickListener* listener = dynamic_cast<ChannelClickListener*> (getAudioProcessor()))
  62. listener->channelButtonClicked (channelIndex);
  63. }
  64. }
  65. private:
  66. void timerCallback() override
  67. {
  68. const AudioChannelSet& channelSet = getAudioProcessor()->busArrangement.outputBuses.getReference (0).channels;
  69. if (channelSet != currentChannelLayout)
  70. {
  71. currentChannelLayout = channelSet;
  72. channelButtons.clear();
  73. if (currentChannelLayout == AudioChannelSet::disabled())
  74. {
  75. noChannelsLabel.setVisible (true);
  76. }
  77. else
  78. {
  79. const int numChannels = currentChannelLayout.size();
  80. for (int i = 0; i < numChannels; ++i)
  81. {
  82. const String channelName =
  83. AudioChannelSet::getAbbreviatedChannelTypeName (currentChannelLayout.getTypeOfChannel (i));
  84. TextButton* newButton;
  85. channelButtons.add (newButton = new TextButton (channelName, channelName));
  86. newButton->addListener (this);
  87. addAndMakeVisible (newButton);
  88. }
  89. noChannelsLabel.setVisible (false);
  90. resized();
  91. }
  92. }
  93. }
  94. AudioChannelSet currentChannelLayout;
  95. Label noChannelsLabel;
  96. OwnedArray<TextButton> channelButtons;
  97. };