andrewm@0: /* andrewm@0: This code accompanies the textbook: andrewm@0: andrewm@0: Digital Audio Effects: Theory, Implementation and Application andrewm@0: Joshua D. Reiss and Andrew P. McPherson andrewm@0: andrewm@0: --- andrewm@0: andrewm@0: Flanger: flanging effect using time-varying delay andrewm@0: See textbook Chapter 2: Delay Line Effects andrewm@0: andrewm@0: Code by Andrew McPherson, Brecht De Man and Joshua Reiss andrewm@0: andrewm@0: --- andrewm@0: andrewm@0: This program is free software: you can redistribute it and/or modify andrewm@0: it under the terms of the GNU General Public License as published by andrewm@0: the Free Software Foundation, either version 3 of the License, or andrewm@0: (at your option) any later version. andrewm@0: andrewm@0: This program is distributed in the hope that it will be useful, andrewm@0: but WITHOUT ANY WARRANTY; without even the implied warranty of andrewm@0: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the andrewm@0: GNU General Public License for more details. andrewm@0: andrewm@0: You should have received a copy of the GNU General Public License andrewm@0: along with this program. If not, see . andrewm@0: */ andrewm@0: andrewm@0: #include "PluginProcessor.h" andrewm@0: #include "PluginEditor.h" andrewm@0: andrewm@0: andrewm@0: //============================================================================== andrewm@0: FlangerAudioProcessorEditor::FlangerAudioProcessorEditor (FlangerAudioProcessor* ownerFilter) andrewm@0: : AudioProcessorEditor (ownerFilter), andrewm@0: delayLabel_("", "Min. Delay (sec):"), andrewm@0: sweepWidthLabel_("", "Sweep Width (sec.):"), andrewm@0: depthLabel_("", "Depth:"), andrewm@0: feedbackLabel_("", "Feedback:"), andrewm@0: frequencyLabel_("", "LFO Frequency:"), andrewm@0: waveformLabel_("", "LFO Waveform:"), andrewm@0: interpolationLabel_("", "Interpolation Type:") andrewm@0: { andrewm@0: andrewm@0: // Set up the sliders andrewm@0: addAndMakeVisible (&delaySlider_); andrewm@0: delaySlider_.setSliderStyle (Slider::Rotary); andrewm@0: delaySlider_.addListener (this); andrewm@0: delaySlider_.setRange (0.001, FlangerAudioProcessor::kMaximumDelay, 0.0005); andrewm@0: andrewm@0: addAndMakeVisible (&sweepWidthSlider_); andrewm@0: sweepWidthSlider_.setSliderStyle (Slider::Rotary); andrewm@0: sweepWidthSlider_.addListener (this); andrewm@0: sweepWidthSlider_.setRange (.001, FlangerAudioProcessor::kMaximumSweepWidth, 0.0005); andrewm@0: andrewm@0: addAndMakeVisible (&depthSlider_); andrewm@0: depthSlider_.setSliderStyle (Slider::Rotary); andrewm@0: depthSlider_.addListener (this); andrewm@0: depthSlider_.setRange (0.0, 1.0, 0.01); andrewm@0: andrewm@0: addAndMakeVisible (&feedbackSlider_); andrewm@0: feedbackSlider_.setSliderStyle (Slider::Rotary); andrewm@0: feedbackSlider_.addListener (this); andrewm@0: feedbackSlider_.setRange (0.0, 0.5, 0.01); andrewm@0: andrewm@0: addAndMakeVisible (&frequencySlider_); andrewm@0: frequencySlider_.setSliderStyle (Slider::Rotary); andrewm@0: frequencySlider_.addListener (this); andrewm@0: frequencySlider_.setRange (0.05, 2.0, 0.025); andrewm@0: andrewm@0: addAndMakeVisible(&waveformComboBox_); andrewm@0: waveformComboBox_.setEditableText(false); andrewm@0: waveformComboBox_.setJustificationType(Justification::left); andrewm@0: waveformComboBox_.addItem("Sine", FlangerAudioProcessor::kWaveformSine); andrewm@0: waveformComboBox_.addItem("Triangle", FlangerAudioProcessor::kWaveformTriangle); andrewm@0: waveformComboBox_.addItem("Square", FlangerAudioProcessor::kWaveformSquare); andrewm@0: waveformComboBox_.addItem("Sawtooth", FlangerAudioProcessor::kWaveformSawtooth); andrewm@0: waveformComboBox_.addListener(this); andrewm@0: andrewm@0: addAndMakeVisible(&interpolationComboBox_); andrewm@0: interpolationComboBox_.setEditableText(false); andrewm@0: interpolationComboBox_.setJustificationType(Justification::left); andrewm@0: interpolationComboBox_.addItem("None", FlangerAudioProcessor::kInterpolationNearestNeighbour); andrewm@0: interpolationComboBox_.addItem("Linear", FlangerAudioProcessor::kInterpolationLinear); andrewm@0: interpolationComboBox_.addItem("Cubic", FlangerAudioProcessor::kInterpolationCubic); andrewm@0: interpolationComboBox_.addListener(this); andrewm@0: andrewm@0: addAndMakeVisible(&stereoToggleButton_); andrewm@0: stereoToggleButton_.setName("Stereo"); andrewm@0: stereoToggleButton_.setButtonText("Stereo"); andrewm@0: stereoToggleButton_.addListener(this); andrewm@0: andrewm@0: delayLabel_.attachToComponent(&delaySlider_, false); andrewm@0: delayLabel_.setFont(Font (11.0f)); andrewm@0: andrewm@0: sweepWidthLabel_.attachToComponent(&sweepWidthSlider_, false); andrewm@0: sweepWidthLabel_.setFont(Font (11.0f)); andrewm@0: andrewm@0: depthLabel_.attachToComponent(&depthSlider_, false); andrewm@0: depthLabel_.setFont(Font (11.0f)); andrewm@0: andrewm@0: feedbackLabel_.attachToComponent(&feedbackSlider_, false); andrewm@0: feedbackLabel_.setFont(Font (11.0f)); andrewm@0: andrewm@0: frequencyLabel_.attachToComponent(&frequencySlider_, false); andrewm@0: frequencyLabel_.setFont(Font (11.0f)); andrewm@0: andrewm@0: waveformLabel_.attachToComponent(&waveformComboBox_, false); andrewm@0: waveformLabel_.setFont(Font (11.0f)); andrewm@0: andrewm@0: interpolationLabel_.attachToComponent(&interpolationComboBox_, false); andrewm@0: interpolationLabel_.setFont(Font (11.0f)); andrewm@0: andrewm@0: // add the triangular resizer component for the bottom-right of the UI andrewm@0: addAndMakeVisible(resizer_ = new ResizableCornerComponent (this, &resizeLimits_)); andrewm@0: resizeLimits_.setSizeLimits(550, 200, 600, 300); andrewm@0: andrewm@0: // set our component's initial size to be the last one that was stored in the filter's settings andrewm@0: setSize(ownerFilter->lastUIWidth_, andrewm@0: ownerFilter->lastUIHeight_); andrewm@0: andrewm@0: startTimer(50); andrewm@0: } andrewm@0: andrewm@0: FlangerAudioProcessorEditor::~FlangerAudioProcessorEditor() andrewm@0: { andrewm@0: } andrewm@0: andrewm@0: //============================================================================== andrewm@0: void FlangerAudioProcessorEditor::paint (Graphics& g) andrewm@0: { andrewm@0: g.fillAll (Colours::grey); andrewm@0: } andrewm@0: andrewm@0: void FlangerAudioProcessorEditor::resized() andrewm@0: { andrewm@0: delaySlider_.setBounds (20, 20, 150, 40); andrewm@0: sweepWidthSlider_.setBounds (200, 20, 150, 40); andrewm@0: depthSlider_.setBounds(380, 20, 150, 40); andrewm@0: feedbackSlider_.setBounds(20, 80, 150, 40); andrewm@0: frequencySlider_.setBounds(200, 80, 150, 40); andrewm@0: waveformComboBox_.setBounds(20, 140, 200, 30); andrewm@0: interpolationComboBox_.setBounds(250, 140, 200, 30); andrewm@0: stereoToggleButton_.setBounds(380, 80, 150, 40); andrewm@0: stereoToggleButton_.changeWidthToFitText(); andrewm@0: andrewm@0: resizer_->setBounds(getWidth() - 16, getHeight() - 16, 16, 16); andrewm@0: andrewm@0: getProcessor()->lastUIWidth_ = getWidth(); andrewm@0: getProcessor()->lastUIHeight_ = getHeight(); andrewm@0: } andrewm@0: andrewm@0: //============================================================================== andrewm@0: // This timer periodically checks whether any of the filter's parameters have changed... andrewm@0: void FlangerAudioProcessorEditor::timerCallback() andrewm@0: { andrewm@0: FlangerAudioProcessor* ourProcessor = getProcessor(); andrewm@0: andrewm@0: delaySlider_.setValue(ourProcessor->delay_, dontSendNotification); andrewm@0: sweepWidthSlider_.setValue(ourProcessor->sweepWidth_, dontSendNotification); andrewm@0: depthSlider_.setValue(ourProcessor->depth_, dontSendNotification); andrewm@0: feedbackSlider_.setValue(ourProcessor->feedback_, dontSendNotification); andrewm@0: frequencySlider_.setValue(ourProcessor->frequency_, dontSendNotification); b@1: waveformComboBox_.setSelectedId(ourProcessor->waveform_, dontSendNotification); b@1: interpolationComboBox_.setSelectedId(ourProcessor->interpolation_, dontSendNotification); b@1: stereoToggleButton_.setToggleState((ourProcessor->stereo_ != 0), dontSendNotification); andrewm@0: } andrewm@0: andrewm@0: // This is our Slider::Listener callback, when the user drags a slider. andrewm@0: void FlangerAudioProcessorEditor::sliderValueChanged (Slider* slider) andrewm@0: { andrewm@0: // It's vital to use setParameterNotifyingHost to change any parameters that are automatable andrewm@0: // by the host, rather than just modifying them directly, otherwise the host won't know andrewm@0: // that they've changed. andrewm@0: andrewm@0: if (slider == &delaySlider_) andrewm@0: { andrewm@0: getProcessor()->setParameterNotifyingHost (FlangerAudioProcessor::kDelayParam, andrewm@0: (float)delaySlider_.getValue()); andrewm@0: } andrewm@0: else if (slider == &sweepWidthSlider_) andrewm@0: { andrewm@0: getProcessor()->setParameterNotifyingHost (FlangerAudioProcessor::kSweepWidthParam, andrewm@0: (float)sweepWidthSlider_.getValue()); andrewm@0: } andrewm@0: else if (slider == &depthSlider_) andrewm@0: { andrewm@0: getProcessor()->setParameterNotifyingHost (FlangerAudioProcessor::kDepthParam, andrewm@0: (float)depthSlider_.getValue()); andrewm@0: } andrewm@0: else if (slider == &feedbackSlider_) andrewm@0: { andrewm@0: getProcessor()->setParameterNotifyingHost (FlangerAudioProcessor::kFeedbackParam, andrewm@0: (float)feedbackSlider_.getValue()); andrewm@0: } andrewm@0: else if (slider == &frequencySlider_) andrewm@0: { andrewm@0: getProcessor()->setParameterNotifyingHost (FlangerAudioProcessor::kFrequencyParam, andrewm@0: (float)frequencySlider_.getValue()); andrewm@0: } andrewm@0: } andrewm@0: andrewm@0: // Similar callback to sliderValueChanged for ComboBox updates andrewm@0: void FlangerAudioProcessorEditor::comboBoxChanged (ComboBox *comboBox) andrewm@0: { andrewm@0: if(comboBox == &waveformComboBox_) andrewm@0: { andrewm@0: getProcessor()->setParameterNotifyingHost (FlangerAudioProcessor::kWaveformParam, andrewm@0: (float)waveformComboBox_.getSelectedId()); andrewm@0: } andrewm@0: else if(comboBox == &interpolationComboBox_) andrewm@0: { andrewm@0: getProcessor()->setParameterNotifyingHost (FlangerAudioProcessor::kInterpolationParam, andrewm@0: (float)interpolationComboBox_.getSelectedId()); andrewm@0: } andrewm@0: } andrewm@0: andrewm@0: // Callback for toggle button andrewm@0: void FlangerAudioProcessorEditor::buttonClicked (Button *button) andrewm@0: { andrewm@0: if(button == &stereoToggleButton_) andrewm@0: { andrewm@0: if(button->getToggleState()) andrewm@0: getProcessor()->setParameterNotifyingHost (FlangerAudioProcessor::kStereoParam, 1.0); andrewm@0: else andrewm@0: getProcessor()->setParameterNotifyingHost (FlangerAudioProcessor::kStereoParam, 0.0); andrewm@0: } andrewm@0: }