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: Ping-Pong Delay: stereo delay alternating between channels 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: PingPongDelayAudioProcessorEditor::PingPongDelayAudioProcessorEditor (PingPongDelayAudioProcessor* ownerFilter) andrewm@0: : AudioProcessorEditor (ownerFilter), andrewm@0: delayLengthLeftLabel_("", "L-R Delay (sec):"), andrewm@0: delayLengthRightLabel_("", "R-L Delay (sec):"), andrewm@0: feedbackLabel_("", "Feedback:"), andrewm@0: wetMixLabel_("", "Delayed Mix Level:") andrewm@0: { andrewm@0: andrewm@0: // Set up the sliders andrewm@0: addAndMakeVisible (&delayLengthLeftSlider_); andrewm@0: delayLengthLeftSlider_.setSliderStyle (Slider::Rotary); andrewm@0: delayLengthLeftSlider_.addListener (this); andrewm@0: delayLengthLeftSlider_.setRange (0.01, 2.0, 0.01); andrewm@0: andrewm@0: addAndMakeVisible (&delayLengthRightSlider_); andrewm@0: delayLengthRightSlider_.setSliderStyle (Slider::Rotary); andrewm@0: delayLengthRightSlider_.addListener (this); andrewm@0: delayLengthRightSlider_.setRange (0.01, 2.0, 0.01); andrewm@0: andrewm@0: addAndMakeVisible (&feedbackSlider_); andrewm@0: feedbackSlider_.setSliderStyle (Slider::Rotary); andrewm@0: feedbackSlider_.addListener (this); andrewm@0: feedbackSlider_.setRange (0.0, 0.995, 0.005); andrewm@0: andrewm@0: addAndMakeVisible (&wetMixSlider_); andrewm@0: wetMixSlider_.setSliderStyle (Slider::Rotary); andrewm@0: wetMixSlider_.addListener (this); andrewm@0: wetMixSlider_.setRange (0.0, 1.0, 0.01); andrewm@0: andrewm@0: addAndMakeVisible(&linkDelaysButton_); andrewm@0: linkDelaysButton_.setName("Link Delays"); andrewm@0: linkDelaysButton_.setButtonText("Link Delays"); andrewm@0: linkDelaysButton_.setToggleState(true, dontSendNotification); andrewm@0: linkDelaysButton_.addListener(this); andrewm@0: andrewm@0: addAndMakeVisible(&reverseChannelsButton_); andrewm@0: reverseChannelsButton_.setName("Reverse Output Channels"); andrewm@0: reverseChannelsButton_.setButtonText("Reverse Output Channels"); andrewm@0: reverseChannelsButton_.setToggleState(false, dontSendNotification); andrewm@0: reverseChannelsButton_.addListener(this); andrewm@0: andrewm@0: linkDelays_ = true; andrewm@0: andrewm@0: delayLengthLeftLabel_.attachToComponent(&delayLengthLeftSlider_, false); andrewm@0: delayLengthLeftLabel_.setFont(Font (11.0f)); andrewm@0: andrewm@0: delayLengthRightLabel_.attachToComponent(&delayLengthRightSlider_, false); andrewm@0: delayLengthRightLabel_.setFont(Font (11.0f)); andrewm@0: andrewm@0: feedbackLabel_.attachToComponent(&feedbackSlider_, false); andrewm@0: feedbackLabel_.setFont(Font (11.0f)); andrewm@0: andrewm@0: wetMixLabel_.attachToComponent(&wetMixSlider_, false); andrewm@0: wetMixLabel_.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(500, 140, 500, 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: PingPongDelayAudioProcessorEditor::~PingPongDelayAudioProcessorEditor() andrewm@0: { andrewm@0: } andrewm@0: andrewm@0: //============================================================================== andrewm@0: void PingPongDelayAudioProcessorEditor::paint (Graphics& g) andrewm@0: { andrewm@0: g.fillAll (Colours::grey); andrewm@0: } andrewm@0: andrewm@0: void PingPongDelayAudioProcessorEditor::resized() andrewm@0: { andrewm@0: delayLengthLeftSlider_.setBounds (20, 20, 150, 40); andrewm@0: delayLengthRightSlider_.setBounds (200, 20, 150, 40); andrewm@0: feedbackSlider_.setBounds (20, 80, 150, 40); andrewm@0: wetMixSlider_.setBounds(200, 80, 150, 40); andrewm@0: linkDelaysButton_.setBounds(380, 20, 100, 40); andrewm@0: linkDelaysButton_.changeWidthToFitText(); andrewm@0: reverseChannelsButton_.setBounds(380, 80, 100, 40); andrewm@0: reverseChannelsButton_.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 PingPongDelayAudioProcessorEditor::timerCallback() andrewm@0: { andrewm@0: PingPongDelayAudioProcessor* ourProcessor = getProcessor(); andrewm@0: andrewm@0: delayLengthLeftSlider_.setValue(ourProcessor->delayLengthLeft_, dontSendNotification); andrewm@0: delayLengthRightSlider_.setValue(ourProcessor->delayLengthRight_, dontSendNotification); andrewm@0: feedbackSlider_.setValue(ourProcessor->feedback_, dontSendNotification); andrewm@0: wetMixSlider_.setValue(ourProcessor->wetMix_, dontSendNotification); andrewm@0: reverseChannelsButton_.setToggleState(ourProcessor->reverseChannels_, dontSendNotification); andrewm@0: } andrewm@0: andrewm@0: // This is our Slider::Listener callback, when the user drags a slider. andrewm@0: void PingPongDelayAudioProcessorEditor::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 == &delayLengthLeftSlider_) andrewm@0: { andrewm@0: getProcessor()->setParameterNotifyingHost (PingPongDelayAudioProcessor::kDelayLengthLeftParam, andrewm@0: (float)delayLengthLeftSlider_.getValue()); andrewm@0: if(linkDelays_) andrewm@0: { andrewm@0: // Set the other slider to match this value andrewm@0: getProcessor()->setParameterNotifyingHost (PingPongDelayAudioProcessor::kDelayLengthRightParam, andrewm@0: (float)delayLengthLeftSlider_.getValue()); andrewm@0: delayLengthRightSlider_.setValue(delayLengthLeftSlider_.getValue(), dontSendNotification); andrewm@0: } andrewm@0: } andrewm@0: else if (slider == &delayLengthRightSlider_) andrewm@0: { andrewm@0: getProcessor()->setParameterNotifyingHost (PingPongDelayAudioProcessor::kDelayLengthRightParam, andrewm@0: (float)delayLengthRightSlider_.getValue()); andrewm@0: andrewm@0: if(linkDelays_) andrewm@0: { andrewm@0: // Set the other slider to match this value andrewm@0: getProcessor()->setParameterNotifyingHost (PingPongDelayAudioProcessor::kDelayLengthLeftParam, andrewm@0: (float)delayLengthRightSlider_.getValue()); andrewm@0: delayLengthLeftSlider_.setValue(delayLengthRightSlider_.getValue(), dontSendNotification); andrewm@0: } andrewm@0: } andrewm@0: else if (slider == &feedbackSlider_) andrewm@0: { andrewm@0: getProcessor()->setParameterNotifyingHost (PingPongDelayAudioProcessor::kFeedbackParam, andrewm@0: (float)feedbackSlider_.getValue()); andrewm@0: } andrewm@0: else if (slider == &wetMixSlider_) andrewm@0: { andrewm@0: getProcessor()->setParameterNotifyingHost (PingPongDelayAudioProcessor::kWetMixParam, andrewm@0: (float)wetMixSlider_.getValue()); andrewm@0: } andrewm@0: } andrewm@0: andrewm@0: // Callback for toggle button andrewm@0: void PingPongDelayAudioProcessorEditor::buttonClicked (Button *button) andrewm@0: { andrewm@0: if(button == &linkDelaysButton_) andrewm@0: { andrewm@0: linkDelays_ = button->getToggleState(); andrewm@0: andrewm@0: if(linkDelays_) andrewm@0: { andrewm@0: // Keep L and R delays equal, setting them to be if they aren't already andrewm@0: PingPongDelayAudioProcessor* ourProcessor = getProcessor(); andrewm@0: andrewm@0: delayLengthRightSlider_.setValue(ourProcessor->delayLengthLeft_, dontSendNotification); andrewm@0: ourProcessor->setParameterNotifyingHost(PingPongDelayAudioProcessor::kDelayLengthRightParam, andrewm@0: ourProcessor->delayLengthLeft_); andrewm@0: } andrewm@0: } andrewm@0: else if(button == &reverseChannelsButton_) andrewm@0: { andrewm@0: bool reverse = button->getToggleState(); andrewm@0: andrewm@0: if(reverse) andrewm@0: getProcessor()->setParameterNotifyingHost(PingPongDelayAudioProcessor::kReverseChannelsParam, 1.0); andrewm@0: else andrewm@0: getProcessor()->setParameterNotifyingHost(PingPongDelayAudioProcessor::kReverseChannelsParam, 0.0); andrewm@0: } andrewm@0: }