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 Ping-Pong Delay: stereo delay alternating between channels
|
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 PingPongDelayAudioProcessorEditor::PingPongDelayAudioProcessorEditor (PingPongDelayAudioProcessor* ownerFilter)
|
andrewm@0
|
36 : AudioProcessorEditor (ownerFilter),
|
andrewm@0
|
37 delayLengthLeftLabel_("", "L-R Delay (sec):"),
|
andrewm@0
|
38 delayLengthRightLabel_("", "R-L Delay (sec):"),
|
andrewm@0
|
39 feedbackLabel_("", "Feedback:"),
|
andrewm@0
|
40 wetMixLabel_("", "Delayed Mix Level:")
|
andrewm@0
|
41 {
|
andrewm@0
|
42
|
andrewm@0
|
43 // Set up the sliders
|
andrewm@0
|
44 addAndMakeVisible (&delayLengthLeftSlider_);
|
andrewm@0
|
45 delayLengthLeftSlider_.setSliderStyle (Slider::Rotary);
|
andrewm@0
|
46 delayLengthLeftSlider_.addListener (this);
|
andrewm@0
|
47 delayLengthLeftSlider_.setRange (0.01, 2.0, 0.01);
|
andrewm@0
|
48
|
andrewm@0
|
49 addAndMakeVisible (&delayLengthRightSlider_);
|
andrewm@0
|
50 delayLengthRightSlider_.setSliderStyle (Slider::Rotary);
|
andrewm@0
|
51 delayLengthRightSlider_.addListener (this);
|
andrewm@0
|
52 delayLengthRightSlider_.setRange (0.01, 2.0, 0.01);
|
andrewm@0
|
53
|
andrewm@0
|
54 addAndMakeVisible (&feedbackSlider_);
|
andrewm@0
|
55 feedbackSlider_.setSliderStyle (Slider::Rotary);
|
andrewm@0
|
56 feedbackSlider_.addListener (this);
|
andrewm@0
|
57 feedbackSlider_.setRange (0.0, 0.995, 0.005);
|
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 addAndMakeVisible(&linkDelaysButton_);
|
andrewm@0
|
65 linkDelaysButton_.setName("Link Delays");
|
andrewm@0
|
66 linkDelaysButton_.setButtonText("Link Delays");
|
andrewm@0
|
67 linkDelaysButton_.setToggleState(true, dontSendNotification);
|
andrewm@0
|
68 linkDelaysButton_.addListener(this);
|
andrewm@0
|
69
|
andrewm@0
|
70 addAndMakeVisible(&reverseChannelsButton_);
|
andrewm@0
|
71 reverseChannelsButton_.setName("Reverse Output Channels");
|
andrewm@0
|
72 reverseChannelsButton_.setButtonText("Reverse Output Channels");
|
andrewm@0
|
73 reverseChannelsButton_.setToggleState(false, dontSendNotification);
|
andrewm@0
|
74 reverseChannelsButton_.addListener(this);
|
andrewm@0
|
75
|
andrewm@0
|
76 linkDelays_ = true;
|
andrewm@0
|
77
|
andrewm@0
|
78 delayLengthLeftLabel_.attachToComponent(&delayLengthLeftSlider_, false);
|
andrewm@0
|
79 delayLengthLeftLabel_.setFont(Font (11.0f));
|
andrewm@0
|
80
|
andrewm@0
|
81 delayLengthRightLabel_.attachToComponent(&delayLengthRightSlider_, false);
|
andrewm@0
|
82 delayLengthRightLabel_.setFont(Font (11.0f));
|
andrewm@0
|
83
|
andrewm@0
|
84 feedbackLabel_.attachToComponent(&feedbackSlider_, false);
|
andrewm@0
|
85 feedbackLabel_.setFont(Font (11.0f));
|
andrewm@0
|
86
|
andrewm@0
|
87 wetMixLabel_.attachToComponent(&wetMixSlider_, false);
|
andrewm@0
|
88 wetMixLabel_.setFont(Font (11.0f));
|
andrewm@0
|
89
|
andrewm@0
|
90 // add the triangular resizer component for the bottom-right of the UI
|
andrewm@0
|
91 addAndMakeVisible(resizer_ = new ResizableCornerComponent (this, &resizeLimits_));
|
andrewm@0
|
92 resizeLimits_.setSizeLimits(500, 140, 500, 300);
|
andrewm@0
|
93
|
andrewm@0
|
94 // set our component's initial size to be the last one that was stored in the filter's settings
|
andrewm@0
|
95 setSize(ownerFilter->lastUIWidth_,
|
andrewm@0
|
96 ownerFilter->lastUIHeight_);
|
andrewm@0
|
97
|
andrewm@0
|
98 startTimer(50);
|
andrewm@0
|
99 }
|
andrewm@0
|
100
|
andrewm@0
|
101 PingPongDelayAudioProcessorEditor::~PingPongDelayAudioProcessorEditor()
|
andrewm@0
|
102 {
|
andrewm@0
|
103 }
|
andrewm@0
|
104
|
andrewm@0
|
105 //==============================================================================
|
andrewm@0
|
106 void PingPongDelayAudioProcessorEditor::paint (Graphics& g)
|
andrewm@0
|
107 {
|
andrewm@0
|
108 g.fillAll (Colours::grey);
|
andrewm@0
|
109 }
|
andrewm@0
|
110
|
andrewm@0
|
111 void PingPongDelayAudioProcessorEditor::resized()
|
andrewm@0
|
112 {
|
andrewm@0
|
113 delayLengthLeftSlider_.setBounds (20, 20, 150, 40);
|
andrewm@0
|
114 delayLengthRightSlider_.setBounds (200, 20, 150, 40);
|
andrewm@0
|
115 feedbackSlider_.setBounds (20, 80, 150, 40);
|
andrewm@0
|
116 wetMixSlider_.setBounds(200, 80, 150, 40);
|
andrewm@0
|
117 linkDelaysButton_.setBounds(380, 20, 100, 40);
|
andrewm@0
|
118 linkDelaysButton_.changeWidthToFitText();
|
andrewm@0
|
119 reverseChannelsButton_.setBounds(380, 80, 100, 40);
|
andrewm@0
|
120 reverseChannelsButton_.changeWidthToFitText();
|
andrewm@0
|
121
|
andrewm@0
|
122 resizer_->setBounds(getWidth() - 16, getHeight() - 16, 16, 16);
|
andrewm@0
|
123
|
andrewm@0
|
124 getProcessor()->lastUIWidth_ = getWidth();
|
andrewm@0
|
125 getProcessor()->lastUIHeight_ = getHeight();
|
andrewm@0
|
126 }
|
andrewm@0
|
127
|
andrewm@0
|
128 //==============================================================================
|
andrewm@0
|
129 // This timer periodically checks whether any of the filter's parameters have changed...
|
andrewm@0
|
130 void PingPongDelayAudioProcessorEditor::timerCallback()
|
andrewm@0
|
131 {
|
andrewm@0
|
132 PingPongDelayAudioProcessor* ourProcessor = getProcessor();
|
andrewm@0
|
133
|
andrewm@0
|
134 delayLengthLeftSlider_.setValue(ourProcessor->delayLengthLeft_, dontSendNotification);
|
andrewm@0
|
135 delayLengthRightSlider_.setValue(ourProcessor->delayLengthRight_, dontSendNotification);
|
andrewm@0
|
136 feedbackSlider_.setValue(ourProcessor->feedback_, dontSendNotification);
|
andrewm@0
|
137 wetMixSlider_.setValue(ourProcessor->wetMix_, dontSendNotification);
|
andrewm@0
|
138 reverseChannelsButton_.setToggleState(ourProcessor->reverseChannels_, dontSendNotification);
|
andrewm@0
|
139 }
|
andrewm@0
|
140
|
andrewm@0
|
141 // This is our Slider::Listener callback, when the user drags a slider.
|
andrewm@0
|
142 void PingPongDelayAudioProcessorEditor::sliderValueChanged (Slider* slider)
|
andrewm@0
|
143 {
|
andrewm@0
|
144 // It's vital to use setParameterNotifyingHost to change any parameters that are automatable
|
andrewm@0
|
145 // by the host, rather than just modifying them directly, otherwise the host won't know
|
andrewm@0
|
146 // that they've changed.
|
andrewm@0
|
147
|
andrewm@0
|
148 if (slider == &delayLengthLeftSlider_)
|
andrewm@0
|
149 {
|
andrewm@0
|
150 getProcessor()->setParameterNotifyingHost (PingPongDelayAudioProcessor::kDelayLengthLeftParam,
|
andrewm@0
|
151 (float)delayLengthLeftSlider_.getValue());
|
andrewm@0
|
152 if(linkDelays_)
|
andrewm@0
|
153 {
|
andrewm@0
|
154 // Set the other slider to match this value
|
andrewm@0
|
155 getProcessor()->setParameterNotifyingHost (PingPongDelayAudioProcessor::kDelayLengthRightParam,
|
andrewm@0
|
156 (float)delayLengthLeftSlider_.getValue());
|
andrewm@0
|
157 delayLengthRightSlider_.setValue(delayLengthLeftSlider_.getValue(), dontSendNotification);
|
andrewm@0
|
158 }
|
andrewm@0
|
159 }
|
andrewm@0
|
160 else if (slider == &delayLengthRightSlider_)
|
andrewm@0
|
161 {
|
andrewm@0
|
162 getProcessor()->setParameterNotifyingHost (PingPongDelayAudioProcessor::kDelayLengthRightParam,
|
andrewm@0
|
163 (float)delayLengthRightSlider_.getValue());
|
andrewm@0
|
164
|
andrewm@0
|
165 if(linkDelays_)
|
andrewm@0
|
166 {
|
andrewm@0
|
167 // Set the other slider to match this value
|
andrewm@0
|
168 getProcessor()->setParameterNotifyingHost (PingPongDelayAudioProcessor::kDelayLengthLeftParam,
|
andrewm@0
|
169 (float)delayLengthRightSlider_.getValue());
|
andrewm@0
|
170 delayLengthLeftSlider_.setValue(delayLengthRightSlider_.getValue(), dontSendNotification);
|
andrewm@0
|
171 }
|
andrewm@0
|
172 }
|
andrewm@0
|
173 else if (slider == &feedbackSlider_)
|
andrewm@0
|
174 {
|
andrewm@0
|
175 getProcessor()->setParameterNotifyingHost (PingPongDelayAudioProcessor::kFeedbackParam,
|
andrewm@0
|
176 (float)feedbackSlider_.getValue());
|
andrewm@0
|
177 }
|
andrewm@0
|
178 else if (slider == &wetMixSlider_)
|
andrewm@0
|
179 {
|
andrewm@0
|
180 getProcessor()->setParameterNotifyingHost (PingPongDelayAudioProcessor::kWetMixParam,
|
andrewm@0
|
181 (float)wetMixSlider_.getValue());
|
andrewm@0
|
182 }
|
andrewm@0
|
183 }
|
andrewm@0
|
184
|
andrewm@0
|
185 // Callback for toggle button
|
andrewm@0
|
186 void PingPongDelayAudioProcessorEditor::buttonClicked (Button *button)
|
andrewm@0
|
187 {
|
andrewm@0
|
188 if(button == &linkDelaysButton_)
|
andrewm@0
|
189 {
|
andrewm@0
|
190 linkDelays_ = button->getToggleState();
|
andrewm@0
|
191
|
andrewm@0
|
192 if(linkDelays_)
|
andrewm@0
|
193 {
|
andrewm@0
|
194 // Keep L and R delays equal, setting them to be if they aren't already
|
andrewm@0
|
195 PingPongDelayAudioProcessor* ourProcessor = getProcessor();
|
andrewm@0
|
196
|
andrewm@0
|
197 delayLengthRightSlider_.setValue(ourProcessor->delayLengthLeft_, dontSendNotification);
|
andrewm@0
|
198 ourProcessor->setParameterNotifyingHost(PingPongDelayAudioProcessor::kDelayLengthRightParam,
|
andrewm@0
|
199 ourProcessor->delayLengthLeft_);
|
andrewm@0
|
200 }
|
andrewm@0
|
201 }
|
andrewm@0
|
202 else if(button == &reverseChannelsButton_)
|
andrewm@0
|
203 {
|
andrewm@0
|
204 bool reverse = button->getToggleState();
|
andrewm@0
|
205
|
andrewm@0
|
206 if(reverse)
|
andrewm@0
|
207 getProcessor()->setParameterNotifyingHost(PingPongDelayAudioProcessor::kReverseChannelsParam, 1.0);
|
andrewm@0
|
208 else
|
andrewm@0
|
209 getProcessor()->setParameterNotifyingHost(PingPongDelayAudioProcessor::kReverseChannelsParam, 0.0);
|
andrewm@0
|
210 }
|
andrewm@0
|
211 } |