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"
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
,
41 ProcessorParameterPropertyComp (const String
& name
, AudioProcessor
& owner_
, const int index_
)
42 : PropertyComponent (name
),
45 paramHasChanged (false),
46 slider (owner_
, index_
)
49 addAndMakeVisible (&slider
);
50 owner_
.addListener (this);
53 ~ProcessorParameterPropertyComp()
55 owner
.removeListener (this);
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;
77 startTimer (1000 / 50);
81 startTimer (jmin (1000 / 4, getTimerInterval() + 10));
86 //==============================================================================
87 class ParamSlider
: public Slider
90 ParamSlider (AudioProcessor
& owner_
, const int index_
)
94 setRange (0.0, 1.0, 0.0);
95 setSliderStyle (Slider::LinearBar
);
96 setTextBoxIsEditable (false);
97 setScrollWheelEnabled (false);
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
);
114 //==============================================================================
115 AudioProcessor
& owner
;
118 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ParamSlider
);
121 AudioProcessor
& owner
;
123 bool volatile paramHasChanged
;
126 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ProcessorParameterPropertyComp
);
130 //==============================================================================
131 GenericAudioProcessorEditor::GenericAudioProcessorEditor (AudioProcessor
* const owner_
)
132 : AudioProcessorEditor (owner_
)
134 jassert (owner_
!= nullptr);
137 addAndMakeVisible (&panel
);
139 Array
<PropertyComponent
*> params
;
141 const int numParams
= owner_
->getNumParameters();
144 for (int i
= 0; i
< numParams
; ++i
)
146 String
name (owner_
->getParameterName (i
));
147 if (name
.trim().isEmpty())
150 ProcessorParameterPropertyComp
* const pc
= new ProcessorParameterPropertyComp (name
, *owner_
, i
);
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());