annotate effects/delay/Source/PluginEditor.cpp @ 1:04e171d2a747 tip

JUCE 4 compatible. Standardised paths on Mac: modules '../../juce/modules'; VST folder '~/SDKs/vstsdk2.4' (JUCE default). Replaced deprecated 'getSampleData(channel)'; getToggleState(...); setToggleState(...); setSelectedId(...). Removed unused variables. Ignore JUCE code and build files.
author Brecht De Man <b.deman@qmul.ac.uk>
date Sun, 22 Nov 2015 15:23:40 +0000
parents e32fe563e124
children
rev   line source
andrewm@0 1 /*
andrewm@0 2 This code accompanies the textbook:
andrewm@0 3
andrewm@0 4 Digital Audio Effects: Theory, Implementation and Application
andrewm@0 5 Joshua D. Reiss and Andrew P. McPherson
andrewm@0 6
andrewm@0 7 ---
andrewm@0 8
andrewm@0 9 Delay: basic delay effect with feedback
andrewm@0 10 See textbook Chapter 2: Delay Line Effects
andrewm@0 11
andrewm@0 12 Code by Andrew McPherson, Brecht de Man and Joshua Reiss
andrewm@0 13
andrewm@0 14 ---
andrewm@0 15
andrewm@0 16 This program is free software: you can redistribute it and/or modify
andrewm@0 17 it under the terms of the GNU General Public License as published by
andrewm@0 18 the Free Software Foundation, either version 3 of the License, or
andrewm@0 19 (at your option) any later version.
andrewm@0 20
andrewm@0 21 This program is distributed in the hope that it will be useful,
andrewm@0 22 but WITHOUT ANY WARRANTY; without even the implied warranty of
andrewm@0 23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
andrewm@0 24 GNU General Public License for more details.
andrewm@0 25
andrewm@0 26 You should have received a copy of the GNU General Public License
andrewm@0 27 along with this program. If not, see <http://www.gnu.org/licenses/>.
andrewm@0 28 */
andrewm@0 29
andrewm@0 30 #include "PluginProcessor.h"
andrewm@0 31 #include "PluginEditor.h"
andrewm@0 32
andrewm@0 33
andrewm@0 34 //==============================================================================
andrewm@0 35 DelayAudioProcessorEditor::DelayAudioProcessorEditor (DelayAudioProcessor* ownerFilter)
andrewm@0 36 : AudioProcessorEditor (ownerFilter),
andrewm@0 37 delayLengthLabel_("", "Delay (sec):"),
andrewm@0 38 feedbackLabel_("", "Feedback:"),
andrewm@0 39 dryMixLabel_("", "Dry Mix Level:"),
andrewm@0 40 wetMixLabel_("", "Delayed Mix Level:")
andrewm@0 41 {
andrewm@0 42
andrewm@0 43 // Set up the sliders
andrewm@0 44 addAndMakeVisible (&delayLengthSlider_);
andrewm@0 45 delayLengthSlider_.setSliderStyle (Slider::Rotary);
andrewm@0 46 delayLengthSlider_.addListener (this);
andrewm@0 47 delayLengthSlider_.setRange (0.01, 2.0, 0.01);
andrewm@0 48
andrewm@0 49 addAndMakeVisible (&feedbackSlider_);
andrewm@0 50 feedbackSlider_.setSliderStyle (Slider::Rotary);
andrewm@0 51 feedbackSlider_.addListener (this);
andrewm@0 52 feedbackSlider_.setRange (0.0, 0.995, 0.005);
andrewm@0 53
andrewm@0 54 addAndMakeVisible (&dryMixSlider_);
andrewm@0 55 dryMixSlider_.setSliderStyle (Slider::Rotary);
andrewm@0 56 dryMixSlider_.addListener (this);
andrewm@0 57 dryMixSlider_.setRange (0.0, 1.0, 0.01);
andrewm@0 58
andrewm@0 59 addAndMakeVisible (&wetMixSlider_);
andrewm@0 60 wetMixSlider_.setSliderStyle (Slider::Rotary);
andrewm@0 61 wetMixSlider_.addListener (this);
andrewm@0 62 wetMixSlider_.setRange (0.0, 1.0, 0.01);
andrewm@0 63
andrewm@0 64 delayLengthLabel_.attachToComponent(&delayLengthSlider_, false);
andrewm@0 65 delayLengthLabel_.setFont(Font (11.0f));
andrewm@0 66
andrewm@0 67 feedbackLabel_.attachToComponent(&feedbackSlider_, false);
andrewm@0 68 feedbackLabel_.setFont(Font (11.0f));
andrewm@0 69
andrewm@0 70 dryMixLabel_.attachToComponent(&dryMixSlider_, false);
andrewm@0 71 dryMixLabel_.setFont(Font (11.0f));
andrewm@0 72
andrewm@0 73 wetMixLabel_.attachToComponent(&wetMixSlider_, false);
andrewm@0 74 wetMixLabel_.setFont(Font (11.0f));
andrewm@0 75
andrewm@0 76 // add the triangular resizer component for the bottom-right of the UI
andrewm@0 77 addAndMakeVisible(resizer_ = new ResizableCornerComponent (this, &resizeLimits_));
andrewm@0 78 resizeLimits_.setSizeLimits(370, 140, 500, 300);
andrewm@0 79
andrewm@0 80 // set our component's initial size to be the last one that was stored in the filter's settings
andrewm@0 81 setSize(ownerFilter->lastUIWidth_,
andrewm@0 82 ownerFilter->lastUIHeight_);
andrewm@0 83
andrewm@0 84 startTimer(50);
andrewm@0 85 }
andrewm@0 86
andrewm@0 87 DelayAudioProcessorEditor::~DelayAudioProcessorEditor()
andrewm@0 88 {
andrewm@0 89 }
andrewm@0 90
andrewm@0 91 //==============================================================================
andrewm@0 92 void DelayAudioProcessorEditor::paint (Graphics& g)
andrewm@0 93 {
andrewm@0 94 g.fillAll (Colours::grey);
andrewm@0 95 }
andrewm@0 96
andrewm@0 97 void DelayAudioProcessorEditor::resized()
andrewm@0 98 {
andrewm@0 99 delayLengthSlider_.setBounds (20, 20, 150, 40);
andrewm@0 100 feedbackSlider_.setBounds (200, 20, 150, 40);
andrewm@0 101 dryMixSlider_.setBounds(20, 80, 150, 40);
andrewm@0 102 wetMixSlider_.setBounds(200, 80, 150, 40);
andrewm@0 103
andrewm@0 104 resizer_->setBounds(getWidth() - 16, getHeight() - 16, 16, 16);
andrewm@0 105
andrewm@0 106 getProcessor()->lastUIWidth_ = getWidth();
andrewm@0 107 getProcessor()->lastUIHeight_ = getHeight();
andrewm@0 108 }
andrewm@0 109
andrewm@0 110 //==============================================================================
andrewm@0 111 // This timer periodically checks whether any of the filter's parameters have changed...
andrewm@0 112 void DelayAudioProcessorEditor::timerCallback()
andrewm@0 113 {
andrewm@0 114 DelayAudioProcessor* ourProcessor = getProcessor();
andrewm@0 115
andrewm@0 116 delayLengthSlider_.setValue(ourProcessor->delayLength_, dontSendNotification);
andrewm@0 117 feedbackSlider_.setValue(ourProcessor->feedback_, dontSendNotification);
andrewm@0 118 dryMixSlider_.setValue(ourProcessor->dryMix_, dontSendNotification);
andrewm@0 119 wetMixSlider_.setValue(ourProcessor->wetMix_, dontSendNotification);
andrewm@0 120 }
andrewm@0 121
andrewm@0 122 // This is our Slider::Listener callback, when the user drags a slider.
andrewm@0 123 void DelayAudioProcessorEditor::sliderValueChanged (Slider* slider)
andrewm@0 124 {
andrewm@0 125 // It's vital to use setParameterNotifyingHost to change any parameters that are automatable
andrewm@0 126 // by the host, rather than just modifying them directly, otherwise the host won't know
andrewm@0 127 // that they've changed.
andrewm@0 128
andrewm@0 129 if (slider == &delayLengthSlider_)
andrewm@0 130 {
andrewm@0 131 getProcessor()->setParameterNotifyingHost (DelayAudioProcessor::kDelayLengthParam,
andrewm@0 132 (float)delayLengthSlider_.getValue());
andrewm@0 133 }
andrewm@0 134 else if (slider == &feedbackSlider_)
andrewm@0 135 {
andrewm@0 136 getProcessor()->setParameterNotifyingHost (DelayAudioProcessor::kFeedbackParam,
andrewm@0 137 (float)feedbackSlider_.getValue());
andrewm@0 138 }
andrewm@0 139 else if (slider == &dryMixSlider_)
andrewm@0 140 {
andrewm@0 141 getProcessor()->setParameterNotifyingHost (DelayAudioProcessor::kDryMixParam,
andrewm@0 142 (float)dryMixSlider_.getValue());
andrewm@0 143 }
andrewm@0 144 else if (slider == &wetMixSlider_)
andrewm@0 145 {
andrewm@0 146 getProcessor()->setParameterNotifyingHost (DelayAudioProcessor::kWetMixParam,
andrewm@0 147 (float)wetMixSlider_.getValue());
andrewm@0 148 }
andrewm@0 149 }