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: Parametric EQ: parametric equaliser adjusting frequency, Q and gain
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: #ifdef _MSC_VER
andrewm@0: #define snprintf _snprintf_s //support for pre-2014 versions of Visual Studio
andrewm@0: #endif // _MSC_VER
andrewm@0:
andrewm@0: //==============================================================================
andrewm@0: ParametricEQAudioProcessorEditor::ParametricEQAudioProcessorEditor (ParametricEQAudioProcessor* ownerFilter)
andrewm@0: : AudioProcessorEditor (ownerFilter),
andrewm@0: centreFrequencyLabel_("", "Centre frequency (Hz):"),
andrewm@0: qLabel_("", "Q:"),
andrewm@0: gainDecibelsLabel_("", "Gain (dB):"),
andrewm@0: bandwidthLabel_("", "Bandwidth:")
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(10.0, 20000.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(10.0 * 20000.0));
andrewm@0:
andrewm@0: addAndMakeVisible(&qSlider_);
andrewm@0: qSlider_.setSliderStyle(Slider::Rotary);
andrewm@0: qSlider_.addListener(this);
andrewm@0: qSlider_.setRange(0.1, 20.0, 0.01);
andrewm@0:
andrewm@0: addAndMakeVisible(&gainDecibelsSlider_);
andrewm@0: gainDecibelsSlider_.setSliderStyle(Slider::Rotary);
andrewm@0: gainDecibelsSlider_.addListener(this);
andrewm@0: gainDecibelsSlider_.setRange(-12.0, 12.0, 0.1);
andrewm@0:
andrewm@0: // This label is informational and exists apart from other controls
andrewm@0: // The other labels are attached to sliders and combo boxes
andrewm@0: addAndMakeVisible(&bandwidthLabel_);
andrewm@0: bandwidthLabel_.setFont(Font (12.0f));
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: gainDecibelsLabel_.attachToComponent(&gainDecibelsSlider_, false);
andrewm@0: gainDecibelsLabel_.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, 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: ParametricEQAudioProcessorEditor::~ParametricEQAudioProcessorEditor()
andrewm@0: {
andrewm@0: }
andrewm@0:
andrewm@0: //==============================================================================
andrewm@0: void ParametricEQAudioProcessorEditor::paint (Graphics& g)
andrewm@0: {
andrewm@0: g.fillAll (Colours::grey);
andrewm@0: }
andrewm@0:
andrewm@0: void ParametricEQAudioProcessorEditor::resized()
andrewm@0: {
andrewm@0: centreFrequencySlider_.setBounds(20, 20, 150, 40);
andrewm@0: qSlider_.setBounds(200, 20, 150, 40);
andrewm@0: gainDecibelsSlider_.setBounds(380, 20, 150, 40);
andrewm@0: bandwidthLabel_.setBounds(20, 70, 350, 20);
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 ParametricEQAudioProcessorEditor::timerCallback()
andrewm@0: {
andrewm@0: ParametricEQAudioProcessor* ourProcessor = getProcessor();
andrewm@0:
andrewm@0: centreFrequencySlider_.setValue(ourProcessor->centreFrequency_, dontSendNotification);
andrewm@0: qSlider_.setValue(ourProcessor->q_, dontSendNotification);
andrewm@0: gainDecibelsSlider_.setValue(ourProcessor->gainDecibels_, dontSendNotification);
andrewm@0: updateBandwidthLabel();
andrewm@0: }
andrewm@0:
andrewm@0: // This is our Slider::Listener callback, when the user drags a slider.
andrewm@0: void ParametricEQAudioProcessorEditor::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 (ParametricEQAudioProcessor::kCentreFrequencyParam,
andrewm@0: (float)centreFrequencySlider_.getValue());
andrewm@0: updateBandwidthLabel();
andrewm@0: }
andrewm@0: else if (slider == &qSlider_)
andrewm@0: {
andrewm@0: getProcessor()->setParameterNotifyingHost (ParametricEQAudioProcessor::kQParam,
andrewm@0: (float)qSlider_.getValue());
andrewm@0: updateBandwidthLabel();
andrewm@0: }
andrewm@0: else if (slider == &gainDecibelsSlider_)
andrewm@0: {
andrewm@0: getProcessor()->setParameterNotifyingHost (ParametricEQAudioProcessor::kGainDecibelsParam,
andrewm@0: (float)gainDecibelsSlider_.getValue());
andrewm@0: }
andrewm@0: }
andrewm@0:
andrewm@0: void ParametricEQAudioProcessorEditor::updateBandwidthLabel()
andrewm@0: {
andrewm@0: char str[64];
andrewm@0: ParametricEQAudioProcessor* ourProcessor = getProcessor();
andrewm@0:
andrewm@0: snprintf(str, 64, "Bandwidth: %.1f Hz", ourProcessor->centreFrequency_ / ourProcessor->q_);
andrewm@0:
andrewm@0: bandwidthLabel_.setText(str, dontSendNotification);
andrewm@0: }