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: Tremolo: amplitude modulation using a low-frequency oscillator andrewm@0: See textbook Chapter 5: Amplitude Modulation 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: TremoloAudioProcessorEditor::TremoloAudioProcessorEditor (TremoloAudioProcessor* ownerFilter) andrewm@0: : AudioProcessorEditor (ownerFilter), andrewm@0: depthLabel_("", "Depth:"), andrewm@0: frequencyLabel_("", "Frequency:"), andrewm@0: waveformLabel_("", "Waveform:") andrewm@0: { andrewm@0: // Set up the sliders 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.2, 20.0, 0.05); andrewm@0: andrewm@0: addAndMakeVisible(&waveformComboBox_); andrewm@0: waveformComboBox_.setEditableText(false); andrewm@0: waveformComboBox_.setJustificationType(Justification::left); andrewm@0: waveformComboBox_.addItem("Sine", TremoloAudioProcessor::kWaveformSine); andrewm@0: waveformComboBox_.addItem("Triangle", TremoloAudioProcessor::kWaveformTriangle); andrewm@0: waveformComboBox_.addItem("Square", TremoloAudioProcessor::kWaveformSquare); andrewm@0: waveformComboBox_.addItem("Square (with sloped edges)", TremoloAudioProcessor::kWaveformSquareSlopedEdges); andrewm@0: waveformComboBox_.addListener(this); 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: // add the triangular resizer component for the bottom-right of the UI andrewm@0: addAndMakeVisible(resizer_ = new ResizableCornerComponent (this, &resizeLimits_)); andrewm@0: resizeLimits_.setSizeLimits(370, 140, 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: TremoloAudioProcessorEditor::~TremoloAudioProcessorEditor() andrewm@0: { andrewm@0: } andrewm@0: andrewm@0: //============================================================================== andrewm@0: void TremoloAudioProcessorEditor::paint (Graphics& g) andrewm@0: { andrewm@0: g.fillAll (Colours::grey); andrewm@0: } andrewm@0: andrewm@0: void TremoloAudioProcessorEditor::resized() andrewm@0: { andrewm@0: frequencySlider_.setBounds(20, 20, 150, 40); andrewm@0: depthSlider_.setBounds (200, 20, 150, 40); andrewm@0: waveformComboBox_.setBounds (20, 80, 200, 30); 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 TremoloAudioProcessorEditor::timerCallback() andrewm@0: { andrewm@0: TremoloAudioProcessor* ourProcessor = getProcessor(); andrewm@0: andrewm@0: depthSlider_.setValue(ourProcessor->depth_, dontSendNotification); andrewm@0: frequencySlider_.setValue(ourProcessor->frequency_, dontSendNotification); andrewm@0: waveformComboBox_.setSelectedId(ourProcessor->waveform_, dontSendNotification); andrewm@0: } andrewm@0: andrewm@0: // This is our Slider::Listener callback, when the user drags a slider. andrewm@0: void TremoloAudioProcessorEditor::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 == &depthSlider_) andrewm@0: { andrewm@0: getProcessor()->setParameterNotifyingHost (TremoloAudioProcessor::kDepthParam, andrewm@0: (float)depthSlider_.getValue()); andrewm@0: } andrewm@0: else if (slider == &frequencySlider_) andrewm@0: { andrewm@0: getProcessor()->setParameterNotifyingHost (TremoloAudioProcessor::kFrequencyParam, andrewm@0: (float)frequencySlider_.getValue()); andrewm@0: } andrewm@0: } andrewm@0: andrewm@0: // Similar callback to sliderValueChanged for ComboBox updates andrewm@0: void TremoloAudioProcessorEditor::comboBoxChanged (ComboBox *comboBox) andrewm@0: { andrewm@0: if(comboBox == &waveformComboBox_) andrewm@0: { andrewm@0: getProcessor()->setParameterNotifyingHost (TremoloAudioProcessor::kWaveformParam, andrewm@0: (float)waveformComboBox_.getSelectedId()); andrewm@0: } andrewm@0: }