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: Wah-Wah: filter effect using variable-frequency filter
andrewm@0: See textbook Chapter 4: Filter 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: #include
andrewm@0:
andrewm@0: //==============================================================================
andrewm@0: WahwahAudioProcessorEditor::WahwahAudioProcessorEditor (WahwahAudioProcessor* ownerFilter)
andrewm@0: : AudioProcessorEditor (ownerFilter),
andrewm@0: centreFrequencyLabel_("", "Centre frequency (Hz):"),
andrewm@0: qLabel_("", "Q:")
andrewm@0: {
andrewm@0: // Set up the sliders
andrewm@0:
andrewm@0: addAndMakeVisible(¢reFrequencySlider_);
andrewm@0: centreFrequencySlider_.setSliderStyle(Slider::Rotary);
andrewm@0: centreFrequencySlider_.addListener(this);
andrewm@0: centreFrequencySlider_.setRange(400.0, 2000.0, 0.1);
andrewm@0:
andrewm@0: addAndMakeVisible(&qSlider_);
andrewm@0: qSlider_.setSliderStyle(Slider::Rotary);
andrewm@0: qSlider_.addListener(this);
andrewm@0: qSlider_.setRange(2.0, 20.0, 0.1);
andrewm@0:
andrewm@0: // Make the centre frequency slider (approximately) logarithmic for a
andrewm@0: // more natural feel
andrewm@0: centreFrequencySlider_.setSkewFactorFromMidPoint(sqrt(400.0 * 2000.0));
andrewm@0:
andrewm@0: centreFrequencyLabel_.attachToComponent(¢reFrequencySlider_, false);
andrewm@0: centreFrequencyLabel_.setFont(Font (11.0f));
andrewm@0:
andrewm@0: qLabel_.attachToComponent(&qSlider_, false);
andrewm@0: qLabel_.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, 100, 550, 160);
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: WahwahAudioProcessorEditor::~WahwahAudioProcessorEditor()
andrewm@0: {
andrewm@0: }
andrewm@0:
andrewm@0: //==============================================================================
andrewm@0: void WahwahAudioProcessorEditor::paint (Graphics& g)
andrewm@0: {
andrewm@0: g.fillAll (Colours::grey);
andrewm@0: }
andrewm@0:
andrewm@0: void WahwahAudioProcessorEditor::resized()
andrewm@0: {
andrewm@0: centreFrequencySlider_.setBounds(20, 20, 150, 40);
andrewm@0: qSlider_.setBounds(200, 20, 150, 40);
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 WahwahAudioProcessorEditor::timerCallback()
andrewm@0: {
andrewm@0: WahwahAudioProcessor* ourProcessor = getProcessor();
andrewm@0:
andrewm@0: centreFrequencySlider_.setValue(ourProcessor->centreFrequency_, dontSendNotification);
andrewm@0: qSlider_.setValue(ourProcessor->q_, dontSendNotification);
andrewm@0: }
andrewm@0:
andrewm@0: // This is our Slider::Listener callback, when the user drags a slider.
andrewm@0: void WahwahAudioProcessorEditor::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 == ¢reFrequencySlider_)
andrewm@0: {
andrewm@0: getProcessor()->setParameterNotifyingHost (WahwahAudioProcessor::kCentreFrequencyParam,
andrewm@0: (float)centreFrequencySlider_.getValue());
andrewm@0: }
andrewm@0: else if (slider == &qSlider_)
andrewm@0: {
andrewm@0: getProcessor()->setParameterNotifyingHost (WahwahAudioProcessor::kQParam,
andrewm@0: (float)qSlider_.getValue());
andrewm@0: }
andrewm@0: }