Add TAL-Reverb-II plugin to test
[juce-lv2.git] / juce / source / src / audio / processors / juce_GenericAudioProcessorEditor.cpp
blobf737a5e1893544948f1336b6237d8d9fae69d364
1 /*
2 ==============================================================================
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
5 Copyright 2004-11 by Raw Material Software Ltd.
7 ------------------------------------------------------------------------------
9 JUCE can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the JUCE distribution, or can be found
12 online at www.gnu.org/licenses.
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 ------------------------------------------------------------------------------
20 To release a closed-source product which uses JUCE, commercial licenses are
21 available: visit www.rawmaterialsoftware.com/juce for more information.
23 ==============================================================================
26 #include "../../core/juce_StandardHeader.h"
28 BEGIN_JUCE_NAMESPACE
30 #include "juce_GenericAudioProcessorEditor.h"
31 #include "juce_AudioProcessor.h"
32 #include "../../gui/components/controls/juce_Slider.h"
35 //==============================================================================
36 class ProcessorParameterPropertyComp : public PropertyComponent,
37 public AudioProcessorListener,
38 public Timer
40 public:
41 ProcessorParameterPropertyComp (const String& name, AudioProcessor& owner_, const int index_)
42 : PropertyComponent (name),
43 owner (owner_),
44 index (index_),
45 paramHasChanged (false),
46 slider (owner_, index_)
48 startTimer (100);
49 addAndMakeVisible (&slider);
50 owner_.addListener (this);
53 ~ProcessorParameterPropertyComp()
55 owner.removeListener (this);
58 void refresh()
60 paramHasChanged = false;
61 slider.setValue (owner.getParameter (index), false);
64 void audioProcessorChanged (AudioProcessor*) {}
66 void audioProcessorParameterChanged (AudioProcessor*, int parameterIndex, float)
68 if (parameterIndex == index)
69 paramHasChanged = true;
72 void timerCallback()
74 if (paramHasChanged)
76 refresh();
77 startTimer (1000 / 50);
79 else
81 startTimer (jmin (1000 / 4, getTimerInterval() + 10));
85 private:
86 //==============================================================================
87 class ParamSlider : public Slider
89 public:
90 ParamSlider (AudioProcessor& owner_, const int index_)
91 : owner (owner_),
92 index (index_)
94 setRange (0.0, 1.0, 0.0);
95 setSliderStyle (Slider::LinearBar);
96 setTextBoxIsEditable (false);
97 setScrollWheelEnabled (false);
100 void valueChanged()
102 const float newVal = (float) getValue();
104 if (owner.getParameter (index) != newVal)
105 owner.setParameter (index, newVal);
108 const String getTextFromValue (double /*value*/)
110 return owner.getParameterText (index);
113 private:
114 //==============================================================================
115 AudioProcessor& owner;
116 const int index;
118 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ParamSlider);
121 AudioProcessor& owner;
122 const int index;
123 bool volatile paramHasChanged;
124 ParamSlider slider;
126 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ProcessorParameterPropertyComp);
130 //==============================================================================
131 GenericAudioProcessorEditor::GenericAudioProcessorEditor (AudioProcessor* const owner_)
132 : AudioProcessorEditor (owner_)
134 jassert (owner_ != nullptr);
135 setOpaque (true);
137 addAndMakeVisible (&panel);
139 Array <PropertyComponent*> params;
141 const int numParams = owner_->getNumParameters();
142 int totalHeight = 0;
144 for (int i = 0; i < numParams; ++i)
146 String name (owner_->getParameterName (i));
147 if (name.trim().isEmpty())
148 name = "Unnamed";
150 ProcessorParameterPropertyComp* const pc = new ProcessorParameterPropertyComp (name, *owner_, i);
151 params.add (pc);
152 totalHeight += pc->getPreferredHeight();
155 panel.addProperties (params);
157 setSize (400, jlimit (25, 400, totalHeight));
160 GenericAudioProcessorEditor::~GenericAudioProcessorEditor()
164 void GenericAudioProcessorEditor::paint (Graphics& g)
166 g.fillAll (Colours::white);
169 void GenericAudioProcessorEditor::resized()
171 panel.setBounds (getLocalBounds());
175 END_JUCE_NAMESPACE