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: Ring Modulator: modulation using a carrier 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: RingModulatorAudioProcessorEditor::RingModulatorAudioProcessorEditor (RingModulatorAudioProcessor* ownerFilter) andrewm@0: : AudioProcessorEditor (ownerFilter), andrewm@0: sweepWidthLabel_("", "LFO Sweep Width (Hz):"), andrewm@0: lfoFrequencyLabel_("", "LFO Frequency:"), andrewm@0: carrierFrequencyLabel_("", "Carrier Frequency:"), andrewm@0: waveformLabel_("", "LFO Waveform:") andrewm@0: { andrewm@0: // Set up the sliders andrewm@0: addAndMakeVisible (&carrierFrequencySlider_); andrewm@0: carrierFrequencySlider_.setSliderStyle (Slider::Rotary); andrewm@0: carrierFrequencySlider_.addListener (this); andrewm@0: carrierFrequencySlider_.setRange (1.0, 1000.0, 1.0); andrewm@0: andrewm@0: addAndMakeVisible (&sweepWidthSlider_); andrewm@0: sweepWidthSlider_.setSliderStyle (Slider::Rotary); andrewm@0: sweepWidthSlider_.addListener (this); andrewm@0: sweepWidthSlider_.setRange (0.0, 100.0, 0.2); andrewm@0: andrewm@0: addAndMakeVisible (&lfoFrequencySlider_); andrewm@0: lfoFrequencySlider_.setSliderStyle (Slider::Rotary); andrewm@0: lfoFrequencySlider_.addListener (this); andrewm@0: lfoFrequencySlider_.setRange (0.1, 10.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", RingModulatorAudioProcessor::kWaveformSine); andrewm@0: waveformComboBox_.addItem("Triangle", RingModulatorAudioProcessor::kWaveformTriangle); andrewm@0: waveformComboBox_.addItem("Square", RingModulatorAudioProcessor::kWaveformSquare); andrewm@0: waveformComboBox_.addItem("Sawtooth (rising)", RingModulatorAudioProcessor::kWaveformSawtooth); andrewm@0: waveformComboBox_.addItem("Sawtooth (falling)", RingModulatorAudioProcessor::kWaveformInverseSawtooth); andrewm@0: waveformComboBox_.addListener(this); andrewm@0: andrewm@0: carrierFrequencyLabel_.attachToComponent(&carrierFrequencySlider_, false); andrewm@0: carrierFrequencyLabel_.setFont(Font (11.0f)); andrewm@0: andrewm@0: sweepWidthLabel_.attachToComponent(&sweepWidthSlider_, false); andrewm@0: sweepWidthLabel_.setFont(Font (11.0f)); andrewm@0: andrewm@0: lfoFrequencyLabel_.attachToComponent(&lfoFrequencySlider_, false); andrewm@0: lfoFrequencyLabel_.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, 160, 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: RingModulatorAudioProcessorEditor::~RingModulatorAudioProcessorEditor() andrewm@0: { andrewm@0: } andrewm@0: andrewm@0: //============================================================================== andrewm@0: void RingModulatorAudioProcessorEditor::paint (Graphics& g) andrewm@0: { andrewm@0: g.fillAll (Colours::grey); andrewm@0: } andrewm@0: andrewm@0: void RingModulatorAudioProcessorEditor::resized() andrewm@0: { andrewm@0: carrierFrequencySlider_.setBounds(20, 20, 150, 40); andrewm@0: lfoFrequencySlider_.setBounds(200, 20, 150, 40); andrewm@0: sweepWidthSlider_.setBounds (20, 80, 150, 40); andrewm@0: waveformComboBox_.setBounds (200, 80, 150, 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 RingModulatorAudioProcessorEditor::timerCallback() andrewm@0: { andrewm@0: RingModulatorAudioProcessor* ourProcessor = getProcessor(); andrewm@0: andrewm@0: carrierFrequencySlider_.setValue(ourProcessor->carrierFrequency_, dontSendNotification); andrewm@0: sweepWidthSlider_.setValue(ourProcessor->sweepWidth_, dontSendNotification); andrewm@0: lfoFrequencySlider_.setValue(ourProcessor->lfoFrequency_, dontSendNotification); b@1: 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 RingModulatorAudioProcessorEditor::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 == &carrierFrequencySlider_) andrewm@0: { andrewm@0: getProcessor()->setParameterNotifyingHost (RingModulatorAudioProcessor::kCarrierFrequencyParam, andrewm@0: (float)carrierFrequencySlider_.getValue()); andrewm@0: } andrewm@0: else if (slider == &sweepWidthSlider_) andrewm@0: { andrewm@0: getProcessor()->setParameterNotifyingHost (RingModulatorAudioProcessor::kSweepWidthParam, andrewm@0: (float)sweepWidthSlider_.getValue()); andrewm@0: } andrewm@0: else if (slider == &lfoFrequencySlider_) andrewm@0: { andrewm@0: getProcessor()->setParameterNotifyingHost (RingModulatorAudioProcessor::kLFOFrequencyParam, andrewm@0: (float)lfoFrequencySlider_.getValue()); andrewm@0: } andrewm@0: } andrewm@0: andrewm@0: // Similar callback to sliderValueChanged for ComboBox updates andrewm@0: void RingModulatorAudioProcessorEditor::comboBoxChanged (ComboBox *comboBox) andrewm@0: { andrewm@0: if(comboBox == &waveformComboBox_) andrewm@0: { andrewm@0: getProcessor()->setParameterNotifyingHost (RingModulatorAudioProcessor::kWaveformParam, andrewm@0: (float)waveformComboBox_.getSelectedId()); andrewm@0: } andrewm@0: }