annotate effects/phaser/Source/PluginEditor.cpp @ 1:04e171d2a747 tip

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