Mercurial > hg > audio_effects_textbook_code
comparison effects/flanger/Source/PluginEditor.cpp @ 0:e32fe563e124
First commit
author | Andrew McPherson <andrewm@eecs.qmul.ac.uk> |
---|---|
date | Fri, 10 Oct 2014 15:41:23 +0100 |
parents | |
children | 04e171d2a747 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e32fe563e124 |
---|---|
1 /* | |
2 This code accompanies the textbook: | |
3 | |
4 Digital Audio Effects: Theory, Implementation and Application | |
5 Joshua D. Reiss and Andrew P. McPherson | |
6 | |
7 --- | |
8 | |
9 Flanger: flanging effect using time-varying delay | |
10 See textbook Chapter 2: Delay Line Effects | |
11 | |
12 Code by Andrew McPherson, Brecht De Man and Joshua Reiss | |
13 | |
14 --- | |
15 | |
16 This program is free software: you can redistribute it and/or modify | |
17 it under the terms of the GNU General Public License as published by | |
18 the Free Software Foundation, either version 3 of the License, or | |
19 (at your option) any later version. | |
20 | |
21 This program is distributed in the hope that it will be useful, | |
22 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
24 GNU General Public License for more details. | |
25 | |
26 You should have received a copy of the GNU General Public License | |
27 along with this program. If not, see <http://www.gnu.org/licenses/>. | |
28 */ | |
29 | |
30 #include "PluginProcessor.h" | |
31 #include "PluginEditor.h" | |
32 | |
33 | |
34 //============================================================================== | |
35 FlangerAudioProcessorEditor::FlangerAudioProcessorEditor (FlangerAudioProcessor* ownerFilter) | |
36 : AudioProcessorEditor (ownerFilter), | |
37 delayLabel_("", "Min. Delay (sec):"), | |
38 sweepWidthLabel_("", "Sweep Width (sec.):"), | |
39 depthLabel_("", "Depth:"), | |
40 feedbackLabel_("", "Feedback:"), | |
41 frequencyLabel_("", "LFO Frequency:"), | |
42 waveformLabel_("", "LFO Waveform:"), | |
43 interpolationLabel_("", "Interpolation Type:") | |
44 { | |
45 | |
46 // Set up the sliders | |
47 addAndMakeVisible (&delaySlider_); | |
48 delaySlider_.setSliderStyle (Slider::Rotary); | |
49 delaySlider_.addListener (this); | |
50 delaySlider_.setRange (0.001, FlangerAudioProcessor::kMaximumDelay, 0.0005); | |
51 | |
52 addAndMakeVisible (&sweepWidthSlider_); | |
53 sweepWidthSlider_.setSliderStyle (Slider::Rotary); | |
54 sweepWidthSlider_.addListener (this); | |
55 sweepWidthSlider_.setRange (.001, FlangerAudioProcessor::kMaximumSweepWidth, 0.0005); | |
56 | |
57 addAndMakeVisible (&depthSlider_); | |
58 depthSlider_.setSliderStyle (Slider::Rotary); | |
59 depthSlider_.addListener (this); | |
60 depthSlider_.setRange (0.0, 1.0, 0.01); | |
61 | |
62 addAndMakeVisible (&feedbackSlider_); | |
63 feedbackSlider_.setSliderStyle (Slider::Rotary); | |
64 feedbackSlider_.addListener (this); | |
65 feedbackSlider_.setRange (0.0, 0.5, 0.01); | |
66 | |
67 addAndMakeVisible (&frequencySlider_); | |
68 frequencySlider_.setSliderStyle (Slider::Rotary); | |
69 frequencySlider_.addListener (this); | |
70 frequencySlider_.setRange (0.05, 2.0, 0.025); | |
71 | |
72 addAndMakeVisible(&waveformComboBox_); | |
73 waveformComboBox_.setEditableText(false); | |
74 waveformComboBox_.setJustificationType(Justification::left); | |
75 waveformComboBox_.addItem("Sine", FlangerAudioProcessor::kWaveformSine); | |
76 waveformComboBox_.addItem("Triangle", FlangerAudioProcessor::kWaveformTriangle); | |
77 waveformComboBox_.addItem("Square", FlangerAudioProcessor::kWaveformSquare); | |
78 waveformComboBox_.addItem("Sawtooth", FlangerAudioProcessor::kWaveformSawtooth); | |
79 waveformComboBox_.addListener(this); | |
80 | |
81 addAndMakeVisible(&interpolationComboBox_); | |
82 interpolationComboBox_.setEditableText(false); | |
83 interpolationComboBox_.setJustificationType(Justification::left); | |
84 interpolationComboBox_.addItem("None", FlangerAudioProcessor::kInterpolationNearestNeighbour); | |
85 interpolationComboBox_.addItem("Linear", FlangerAudioProcessor::kInterpolationLinear); | |
86 interpolationComboBox_.addItem("Cubic", FlangerAudioProcessor::kInterpolationCubic); | |
87 interpolationComboBox_.addListener(this); | |
88 | |
89 addAndMakeVisible(&stereoToggleButton_); | |
90 stereoToggleButton_.setName("Stereo"); | |
91 stereoToggleButton_.setButtonText("Stereo"); | |
92 stereoToggleButton_.addListener(this); | |
93 | |
94 delayLabel_.attachToComponent(&delaySlider_, false); | |
95 delayLabel_.setFont(Font (11.0f)); | |
96 | |
97 sweepWidthLabel_.attachToComponent(&sweepWidthSlider_, false); | |
98 sweepWidthLabel_.setFont(Font (11.0f)); | |
99 | |
100 depthLabel_.attachToComponent(&depthSlider_, false); | |
101 depthLabel_.setFont(Font (11.0f)); | |
102 | |
103 feedbackLabel_.attachToComponent(&feedbackSlider_, false); | |
104 feedbackLabel_.setFont(Font (11.0f)); | |
105 | |
106 frequencyLabel_.attachToComponent(&frequencySlider_, false); | |
107 frequencyLabel_.setFont(Font (11.0f)); | |
108 | |
109 waveformLabel_.attachToComponent(&waveformComboBox_, false); | |
110 waveformLabel_.setFont(Font (11.0f)); | |
111 | |
112 interpolationLabel_.attachToComponent(&interpolationComboBox_, false); | |
113 interpolationLabel_.setFont(Font (11.0f)); | |
114 | |
115 // add the triangular resizer component for the bottom-right of the UI | |
116 addAndMakeVisible(resizer_ = new ResizableCornerComponent (this, &resizeLimits_)); | |
117 resizeLimits_.setSizeLimits(550, 200, 600, 300); | |
118 | |
119 // set our component's initial size to be the last one that was stored in the filter's settings | |
120 setSize(ownerFilter->lastUIWidth_, | |
121 ownerFilter->lastUIHeight_); | |
122 | |
123 startTimer(50); | |
124 } | |
125 | |
126 FlangerAudioProcessorEditor::~FlangerAudioProcessorEditor() | |
127 { | |
128 } | |
129 | |
130 //============================================================================== | |
131 void FlangerAudioProcessorEditor::paint (Graphics& g) | |
132 { | |
133 g.fillAll (Colours::grey); | |
134 } | |
135 | |
136 void FlangerAudioProcessorEditor::resized() | |
137 { | |
138 delaySlider_.setBounds (20, 20, 150, 40); | |
139 sweepWidthSlider_.setBounds (200, 20, 150, 40); | |
140 depthSlider_.setBounds(380, 20, 150, 40); | |
141 feedbackSlider_.setBounds(20, 80, 150, 40); | |
142 frequencySlider_.setBounds(200, 80, 150, 40); | |
143 waveformComboBox_.setBounds(20, 140, 200, 30); | |
144 interpolationComboBox_.setBounds(250, 140, 200, 30); | |
145 stereoToggleButton_.setBounds(380, 80, 150, 40); | |
146 stereoToggleButton_.changeWidthToFitText(); | |
147 | |
148 resizer_->setBounds(getWidth() - 16, getHeight() - 16, 16, 16); | |
149 | |
150 getProcessor()->lastUIWidth_ = getWidth(); | |
151 getProcessor()->lastUIHeight_ = getHeight(); | |
152 } | |
153 | |
154 //============================================================================== | |
155 // This timer periodically checks whether any of the filter's parameters have changed... | |
156 void FlangerAudioProcessorEditor::timerCallback() | |
157 { | |
158 FlangerAudioProcessor* ourProcessor = getProcessor(); | |
159 | |
160 delaySlider_.setValue(ourProcessor->delay_, dontSendNotification); | |
161 sweepWidthSlider_.setValue(ourProcessor->sweepWidth_, dontSendNotification); | |
162 depthSlider_.setValue(ourProcessor->depth_, dontSendNotification); | |
163 feedbackSlider_.setValue(ourProcessor->feedback_, dontSendNotification); | |
164 frequencySlider_.setValue(ourProcessor->frequency_, dontSendNotification); | |
165 waveformComboBox_.setSelectedId(ourProcessor->waveform_, false); | |
166 interpolationComboBox_.setSelectedId(ourProcessor->interpolation_, false); | |
167 stereoToggleButton_.setToggleState((ourProcessor->stereo_ != 0), false); | |
168 } | |
169 | |
170 // This is our Slider::Listener callback, when the user drags a slider. | |
171 void FlangerAudioProcessorEditor::sliderValueChanged (Slider* slider) | |
172 { | |
173 // It's vital to use setParameterNotifyingHost to change any parameters that are automatable | |
174 // by the host, rather than just modifying them directly, otherwise the host won't know | |
175 // that they've changed. | |
176 | |
177 if (slider == &delaySlider_) | |
178 { | |
179 getProcessor()->setParameterNotifyingHost (FlangerAudioProcessor::kDelayParam, | |
180 (float)delaySlider_.getValue()); | |
181 } | |
182 else if (slider == &sweepWidthSlider_) | |
183 { | |
184 getProcessor()->setParameterNotifyingHost (FlangerAudioProcessor::kSweepWidthParam, | |
185 (float)sweepWidthSlider_.getValue()); | |
186 } | |
187 else if (slider == &depthSlider_) | |
188 { | |
189 getProcessor()->setParameterNotifyingHost (FlangerAudioProcessor::kDepthParam, | |
190 (float)depthSlider_.getValue()); | |
191 } | |
192 else if (slider == &feedbackSlider_) | |
193 { | |
194 getProcessor()->setParameterNotifyingHost (FlangerAudioProcessor::kFeedbackParam, | |
195 (float)feedbackSlider_.getValue()); | |
196 } | |
197 else if (slider == &frequencySlider_) | |
198 { | |
199 getProcessor()->setParameterNotifyingHost (FlangerAudioProcessor::kFrequencyParam, | |
200 (float)frequencySlider_.getValue()); | |
201 } | |
202 } | |
203 | |
204 // Similar callback to sliderValueChanged for ComboBox updates | |
205 void FlangerAudioProcessorEditor::comboBoxChanged (ComboBox *comboBox) | |
206 { | |
207 if(comboBox == &waveformComboBox_) | |
208 { | |
209 getProcessor()->setParameterNotifyingHost (FlangerAudioProcessor::kWaveformParam, | |
210 (float)waveformComboBox_.getSelectedId()); | |
211 } | |
212 else if(comboBox == &interpolationComboBox_) | |
213 { | |
214 getProcessor()->setParameterNotifyingHost (FlangerAudioProcessor::kInterpolationParam, | |
215 (float)interpolationComboBox_.getSelectedId()); | |
216 } | |
217 } | |
218 | |
219 // Callback for toggle button | |
220 void FlangerAudioProcessorEditor::buttonClicked (Button *button) | |
221 { | |
222 if(button == &stereoToggleButton_) | |
223 { | |
224 if(button->getToggleState()) | |
225 getProcessor()->setParameterNotifyingHost (FlangerAudioProcessor::kStereoParam, 1.0); | |
226 else | |
227 getProcessor()->setParameterNotifyingHost (FlangerAudioProcessor::kStereoParam, 0.0); | |
228 } | |
229 } |