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: Chorus: chorus effect based on time-varying delays 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: ChorusAudioProcessorEditor::ChorusAudioProcessorEditor (ChorusAudioProcessor* ownerFilter) andrewm@0: : AudioProcessorEditor (ownerFilter), andrewm@0: delayLabel_("", "Min. Delay (sec):"), andrewm@0: sweepWidthLabel_("", "Sweep Width (sec.):"), andrewm@0: depthLabel_("", "Depth:"), andrewm@0: frequencyLabel_("", "LFO Frequency:"), andrewm@0: waveformLabel_("", "LFO Waveform:"), andrewm@0: interpolationLabel_("", "Interpolation Type:"), andrewm@0: numVoicesLabel_("", "Number of Voices:") 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 (.01, ChorusAudioProcessor::kMaximumDelay, 0.001); andrewm@0: andrewm@0: addAndMakeVisible (&sweepWidthSlider_); andrewm@0: sweepWidthSlider_.setSliderStyle (Slider::Rotary); andrewm@0: sweepWidthSlider_.addListener (this); andrewm@0: sweepWidthSlider_.setRange (.01, ChorusAudioProcessor::kMaximumSweepWidth, 0.001); 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 (&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", ChorusAudioProcessor::kWaveformSine); andrewm@0: waveformComboBox_.addItem("Triangle", ChorusAudioProcessor::kWaveformTriangle); andrewm@0: waveformComboBox_.addItem("Square", ChorusAudioProcessor::kWaveformSquare); andrewm@0: waveformComboBox_.addItem("Sawtooth", ChorusAudioProcessor::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", ChorusAudioProcessor::kInterpolationNearestNeighbour); andrewm@0: interpolationComboBox_.addItem("Linear", ChorusAudioProcessor::kInterpolationLinear); andrewm@0: interpolationComboBox_.addItem("Cubic", ChorusAudioProcessor::kInterpolationCubic); andrewm@0: interpolationComboBox_.addListener(this); andrewm@0: andrewm@0: addAndMakeVisible(&numVoicesComboBox_); andrewm@0: numVoicesComboBox_.setEditableText(false); andrewm@0: numVoicesComboBox_.setJustificationType(Justification::left); andrewm@0: numVoicesComboBox_.addItem("2", 2); andrewm@0: numVoicesComboBox_.addItem("3", 3); andrewm@0: numVoicesComboBox_.addItem("4", 4); andrewm@0: numVoicesComboBox_.addItem("5", 5); andrewm@0: numVoicesComboBox_.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: 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: numVoicesLabel_.attachToComponent(&numVoicesComboBox_, false); andrewm@0: numVoicesLabel_.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: ChorusAudioProcessorEditor::~ChorusAudioProcessorEditor() andrewm@0: { andrewm@0: } andrewm@0: andrewm@0: //============================================================================== andrewm@0: void ChorusAudioProcessorEditor::paint (Graphics& g) andrewm@0: { andrewm@0: g.fillAll (Colours::grey); andrewm@0: } andrewm@0: andrewm@0: void ChorusAudioProcessorEditor::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: frequencySlider_.setBounds(20, 80, 150, 40); andrewm@0: numVoicesComboBox_.setBounds(200, 80, 150, 30); 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 ChorusAudioProcessorEditor::timerCallback() andrewm@0: { andrewm@0: ChorusAudioProcessor* 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: frequencySlider_.setValue(ourProcessor->frequency_, dontSendNotification); b@1: waveformComboBox_.setSelectedId(ourProcessor->waveform_, dontSendNotification); b@1: interpolationComboBox_.setSelectedId(ourProcessor->interpolation_, dontSendNotification); b@1: numVoicesComboBox_.setSelectedId(ourProcessor->numVoices_, 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 ChorusAudioProcessorEditor::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 (ChorusAudioProcessor::kDelayParam, andrewm@0: (float)delaySlider_.getValue()); andrewm@0: } andrewm@0: else if (slider == &sweepWidthSlider_) andrewm@0: { andrewm@0: getProcessor()->setParameterNotifyingHost (ChorusAudioProcessor::kSweepWidthParam, andrewm@0: (float)sweepWidthSlider_.getValue()); andrewm@0: } andrewm@0: else if (slider == &depthSlider_) andrewm@0: { andrewm@0: getProcessor()->setParameterNotifyingHost (ChorusAudioProcessor::kDepthParam, andrewm@0: (float)depthSlider_.getValue()); andrewm@0: } andrewm@0: else if (slider == &frequencySlider_) andrewm@0: { andrewm@0: getProcessor()->setParameterNotifyingHost (ChorusAudioProcessor::kFrequencyParam, andrewm@0: (float)frequencySlider_.getValue()); andrewm@0: } andrewm@0: } andrewm@0: andrewm@0: // Similar callback to sliderValueChanged for ComboBox updates andrewm@0: void ChorusAudioProcessorEditor::comboBoxChanged (ComboBox *comboBox) andrewm@0: { andrewm@0: if(comboBox == &waveformComboBox_) andrewm@0: { andrewm@0: getProcessor()->setParameterNotifyingHost (ChorusAudioProcessor::kWaveformParam, andrewm@0: (float)waveformComboBox_.getSelectedId()); andrewm@0: } andrewm@0: else if(comboBox == &interpolationComboBox_) andrewm@0: { andrewm@0: getProcessor()->setParameterNotifyingHost (ChorusAudioProcessor::kInterpolationParam, andrewm@0: (float)interpolationComboBox_.getSelectedId()); andrewm@0: } andrewm@0: else if(comboBox == &numVoicesComboBox_) andrewm@0: { andrewm@0: getProcessor()->setParameterNotifyingHost (ChorusAudioProcessor::kNumVoicesParam, andrewm@0: (float)numVoicesComboBox_.getSelectedId()); andrewm@0: } andrewm@0: } andrewm@0: andrewm@0: // Callback for toggle button andrewm@0: void ChorusAudioProcessorEditor::buttonClicked (Button *button) andrewm@0: { andrewm@0: if(button == &stereoToggleButton_) andrewm@0: { andrewm@0: if(button->getToggleState()) andrewm@0: { andrewm@0: getProcessor()->setParameterNotifyingHost (ChorusAudioProcessor::kStereoParam, 1.0); andrewm@0: andrewm@0: // Stereo chorus only makes sense with 3 or more voices (1 input, 2 delayed voices) andrewm@0: if(numVoicesComboBox_.getSelectedId() == 2) andrewm@0: { andrewm@0: numVoicesComboBox_.setSelectedId(3); andrewm@0: getProcessor()->setParameterNotifyingHost (ChorusAudioProcessor::kNumVoicesParam, 3); andrewm@0: } andrewm@0: numVoicesComboBox_.setItemEnabled(2, false); andrewm@0: } andrewm@0: else andrewm@0: { andrewm@0: getProcessor()->setParameterNotifyingHost (ChorusAudioProcessor::kStereoParam, 0.0); andrewm@0: numVoicesComboBox_.setItemEnabled(2, true); andrewm@0: } andrewm@0: } andrewm@0: }