annotate effects/pvoc_pitchshift/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 PVOC Pitch Shift: pitch shifter using phase vocoder
andrewm@0 10 See textbook Chapter 8: The Phase Vocoder
andrewm@0 11
andrewm@0 12 Code by Andrew McPherson, Brecht De Man and Joshua Reiss
andrewm@0 13 Based on a project by Xinyuan Lai
andrewm@0 14
andrewm@0 15 This code requires the fftw library version 3 to compile:
andrewm@0 16 http://fftw.org
andrewm@0 17
andrewm@0 18 ---
andrewm@0 19
andrewm@0 20 This program is free software: you can redistribute it and/or modify
andrewm@0 21 it under the terms of the GNU General Public License as published by
andrewm@0 22 the Free Software Foundation, either version 3 of the License, or
andrewm@0 23 (at your option) any later version.
andrewm@0 24
andrewm@0 25 This program is distributed in the hope that it will be useful,
andrewm@0 26 but WITHOUT ANY WARRANTY; without even the implied warranty of
andrewm@0 27 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
andrewm@0 28 GNU General Public License for more details.
andrewm@0 29
andrewm@0 30 You should have received a copy of the GNU General Public License
andrewm@0 31 along with this program. If not, see <http://www.gnu.org/licenses/>.
andrewm@0 32 */
andrewm@0 33
andrewm@0 34 #include "PluginProcessor.h"
andrewm@0 35 #include "PluginEditor.h"
andrewm@0 36
andrewm@0 37 //==============================================================================
andrewm@0 38 PVOCPitchShiftAudioProcessorEditor::PVOCPitchShiftAudioProcessorEditor (PVOCPitchShiftAudioProcessor* ownerFilter)
andrewm@0 39 : AudioProcessorEditor (ownerFilter),
andrewm@0 40 fftSizeLabel_("", "FFT Size:"),
andrewm@0 41 hopSizeLabel_("", "Hop Size:"),
andrewm@0 42 windowTypeLabel_("", "Window Type:"),
andrewm@0 43 pitchShiftLabel_("", "Pitch Shift:") // (⊙_⊙)
andrewm@0 44 {
andrewm@0 45 // This is where our plugin's editor size is set.
andrewm@0 46 // setSize(170, 80);
andrewm@0 47
andrewm@0 48 // Set up the selection boxes
andrewm@0 49
andrewm@0 50 addAndMakeVisible(&fftSizeComboBox_);
andrewm@0 51 fftSizeComboBox_.setEditableText(false);
andrewm@0 52 fftSizeComboBox_.setJustificationType(Justification::left);
andrewm@0 53 fftSizeComboBox_.addItem("64", 64);
andrewm@0 54 fftSizeComboBox_.addItem("128", 128);
andrewm@0 55 fftSizeComboBox_.addItem("256", 256);
andrewm@0 56 fftSizeComboBox_.addItem("512", 512);
andrewm@0 57 fftSizeComboBox_.addItem("1024", 1024);
andrewm@0 58 fftSizeComboBox_.addItem("2048", 2048);
andrewm@0 59 fftSizeComboBox_.addListener(this);
andrewm@0 60
andrewm@0 61 addAndMakeVisible(&hopSizeComboBox_);
andrewm@0 62 hopSizeComboBox_.setEditableText(false);
andrewm@0 63 hopSizeComboBox_.setJustificationType(Justification::left);
andrewm@0 64 hopSizeComboBox_.addItem("1 Window", PVOCPitchShiftAudioProcessor::kHopSize1Window);
andrewm@0 65 hopSizeComboBox_.addItem("1/2 Window", PVOCPitchShiftAudioProcessor::kHopSize1_2Window);
andrewm@0 66 hopSizeComboBox_.addItem("1/4 Window", PVOCPitchShiftAudioProcessor::kHopSize1_4Window);
andrewm@0 67 hopSizeComboBox_.addItem("1/8 Window", PVOCPitchShiftAudioProcessor::kHopSize1_8Window);
andrewm@0 68 hopSizeComboBox_.addListener(this);
andrewm@0 69
andrewm@0 70 addAndMakeVisible(&windowTypeComboBox_);
andrewm@0 71 windowTypeComboBox_.setEditableText(false);
andrewm@0 72 windowTypeComboBox_.setJustificationType(Justification::left);
andrewm@0 73 windowTypeComboBox_.addItem("Rectangular", PVOCPitchShiftAudioProcessor::kWindowRectangular);
andrewm@0 74 windowTypeComboBox_.addItem("Bartlett", PVOCPitchShiftAudioProcessor::kWindowBartlett);
andrewm@0 75 windowTypeComboBox_.addItem("Hann", PVOCPitchShiftAudioProcessor::kWindowHann);
andrewm@0 76 windowTypeComboBox_.addItem("Hamming", PVOCPitchShiftAudioProcessor::kWindowHamming);
andrewm@0 77 windowTypeComboBox_.addListener(this);
andrewm@0 78
andrewm@0 79 // (⊙_⊙)
andrewm@0 80 addAndMakeVisible(&pitchShiftComboBox_);
andrewm@0 81 pitchShiftComboBox_.setEditableText(false);
andrewm@0 82 pitchShiftComboBox_.setJustificationType(Justification::left);
andrewm@0 83 pitchShiftComboBox_.addItem("+6", PVOCPitchShiftAudioProcessor::kShiftP6);
andrewm@0 84 pitchShiftComboBox_.addItem("+5", PVOCPitchShiftAudioProcessor::kShiftP5);
andrewm@0 85 pitchShiftComboBox_.addItem("+4", PVOCPitchShiftAudioProcessor::kShiftP4);
andrewm@0 86 pitchShiftComboBox_.addItem("+3", PVOCPitchShiftAudioProcessor::kShiftP3);
andrewm@0 87 pitchShiftComboBox_.addItem("+2", PVOCPitchShiftAudioProcessor::kShiftP2);
andrewm@0 88 pitchShiftComboBox_.addItem("+1", PVOCPitchShiftAudioProcessor::kShiftP1);
andrewm@0 89 pitchShiftComboBox_.addItem("0", PVOCPitchShiftAudioProcessor::kShift0);
andrewm@0 90 pitchShiftComboBox_.addItem("-1", PVOCPitchShiftAudioProcessor::kShiftM1);
andrewm@0 91 pitchShiftComboBox_.addItem("-2", PVOCPitchShiftAudioProcessor::kShiftM2);
andrewm@0 92 pitchShiftComboBox_.addItem("-3", PVOCPitchShiftAudioProcessor::kShiftM3);
andrewm@0 93 pitchShiftComboBox_.addItem("-4", PVOCPitchShiftAudioProcessor::kShiftM4);
andrewm@0 94 pitchShiftComboBox_.addItem("-5", PVOCPitchShiftAudioProcessor::kShiftM5);
andrewm@0 95 pitchShiftComboBox_.addItem("-6", PVOCPitchShiftAudioProcessor::kShiftM6);
andrewm@0 96 pitchShiftComboBox_.addListener(this);
andrewm@0 97
andrewm@0 98 fftSizeLabel_.attachToComponent(&fftSizeComboBox_, false);
andrewm@0 99 fftSizeLabel_.setFont(Font (11.0f));
andrewm@0 100
andrewm@0 101 hopSizeLabel_.attachToComponent(&hopSizeComboBox_, false);
andrewm@0 102 hopSizeLabel_.setFont(Font (11.0f));
andrewm@0 103
andrewm@0 104 windowTypeLabel_.attachToComponent(&windowTypeComboBox_, false);
andrewm@0 105 windowTypeLabel_.setFont(Font (11.0f));
andrewm@0 106
andrewm@0 107 // (⊙_⊙)
andrewm@0 108 pitchShiftLabel_.attachToComponent(&pitchShiftComboBox_, false);
andrewm@0 109 pitchShiftLabel_.setFont(Font (11.0f));
andrewm@0 110
andrewm@0 111 // add the triangular resizer component for the bottom-right of the UI
andrewm@0 112 addAndMakeVisible(resizer_ = new ResizableCornerComponent (this, &resizeLimits_));
andrewm@0 113 resizeLimits_.setSizeLimits(370, 120, 400, 160);
andrewm@0 114
andrewm@0 115 // set our component's initial size to be the last one that was stored in the filter's settings
andrewm@0 116 setSize(ownerFilter->lastUIWidth_,
andrewm@0 117 ownerFilter->lastUIHeight_);
andrewm@0 118
andrewm@0 119 startTimer(50);
andrewm@0 120 }
andrewm@0 121
andrewm@0 122 PVOCPitchShiftAudioProcessorEditor::~PVOCPitchShiftAudioProcessorEditor()
andrewm@0 123 {
andrewm@0 124 }
andrewm@0 125
andrewm@0 126 //==============================================================================
andrewm@0 127 void PVOCPitchShiftAudioProcessorEditor::paint (Graphics& g)
andrewm@0 128 {
andrewm@0 129 g.fillAll (Colours::grey);
andrewm@0 130 }
andrewm@0 131
andrewm@0 132 void PVOCPitchShiftAudioProcessorEditor::resized()
andrewm@0 133 {
andrewm@0 134 fftSizeComboBox_.setBounds(20, 20, 150, 30);
andrewm@0 135 hopSizeComboBox_.setBounds(200, 20, 150, 30);
andrewm@0 136 windowTypeComboBox_.setBounds(20, 70, 150, 30);
andrewm@0 137 pitchShiftComboBox_.setBounds(200, 70, 150, 30); //(⊙_⊙)
andrewm@0 138
andrewm@0 139 resizer_->setBounds(getWidth() - 16, getHeight() - 16, 16, 16);
andrewm@0 140
andrewm@0 141 getProcessor()->lastUIWidth_ = getWidth();
andrewm@0 142 getProcessor()->lastUIHeight_ = getHeight();
andrewm@0 143 }
andrewm@0 144
andrewm@0 145 //==============================================================================
andrewm@0 146 // This timer periodically checks whether any of the filter's parameters have changed...
andrewm@0 147 void PVOCPitchShiftAudioProcessorEditor::timerCallback()
andrewm@0 148 {
andrewm@0 149 PVOCPitchShiftAudioProcessor* ourProcessor = getProcessor();
andrewm@0 150
b@1 151 fftSizeComboBox_.setSelectedId(ourProcessor->fftSelectedSize_, dontSendNotification);
b@1 152 hopSizeComboBox_.setSelectedId(ourProcessor->hopSelectedSize_, dontSendNotification);
b@1 153 windowTypeComboBox_.setSelectedId(ourProcessor->windowType_, dontSendNotification);
b@1 154 pitchShiftComboBox_.setSelectedId(ourProcessor->pitchSelectedShift_, dontSendNotification); // (⊙_⊙)
andrewm@0 155 }
andrewm@0 156
andrewm@0 157 // This is our Slider::Listener callback, when the user drags a slider.
andrewm@0 158 void PVOCPitchShiftAudioProcessorEditor::sliderValueChanged (Slider* slider)
andrewm@0 159 {
andrewm@0 160 }
andrewm@0 161
andrewm@0 162 // Similar callback to sliderValueChanged for ComboBox updates
andrewm@0 163 void PVOCPitchShiftAudioProcessorEditor::comboBoxChanged (ComboBox *comboBox)
andrewm@0 164 {
andrewm@0 165 if(comboBox == &fftSizeComboBox_)
andrewm@0 166 {
andrewm@0 167 getProcessor()->setParameterNotifyingHost (PVOCPitchShiftAudioProcessor::kFFTSizeParam,
andrewm@0 168 (float)fftSizeComboBox_.getSelectedId());
andrewm@0 169 }
andrewm@0 170 else if(comboBox == &hopSizeComboBox_)
andrewm@0 171 {
andrewm@0 172 getProcessor()->setParameterNotifyingHost (PVOCPitchShiftAudioProcessor::kHopSizeParam,
andrewm@0 173 (float)hopSizeComboBox_.getSelectedId());
andrewm@0 174 }
andrewm@0 175 else if(comboBox == &windowTypeComboBox_)
andrewm@0 176 {
andrewm@0 177 getProcessor()->setParameterNotifyingHost (PVOCPitchShiftAudioProcessor::kWindowTypeParam,
andrewm@0 178 (float)windowTypeComboBox_.getSelectedId());
andrewm@0 179 }
andrewm@0 180 // (⊙_⊙)
andrewm@0 181 else if(comboBox == &pitchShiftComboBox_)
andrewm@0 182 {
andrewm@0 183 getProcessor()->setParameterNotifyingHost (PVOCPitchShiftAudioProcessor::kPitchShiftParam,
andrewm@0 184 (float)pitchShiftComboBox_.getSelectedId());
andrewm@0 185 }
andrewm@0 186 }