view AddressPlugin/PluginEditor.cpp @ 2:13ec2fa02a26 tip

(none)
author Yannick JACOB <y.jacob@se12.qmul.ac.uk>
date Tue, 03 Sep 2013 15:33:42 +0100
parents 2cd427e000b0
children
line wrap: on
line source
/*
  ==============================================================================

    This file was auto-generated by the Introjucer!

    It contains the basic startup code for a Juce application.

  ==============================================================================
*/

#include "PluginProcessor.h"
#include "PluginEditor.h"


//==============================================================================
ADRessAudioProcessorEditor::ADRessAudioProcessorEditor (ADRessAudioProcessor* ownerFilter)
    : AudioProcessorEditor (ownerFilter),
      fftSizeLabel_("", "FFT Size:"),
      hopSizeLabel_("", "Hop Size:"),
      windowTypeLabel_("", "Window Type:"),
	  widthLabel_("", "Width:"),
      widthSlider_("width"),
      azimuthLabel_("", "Azimuth:"),
      azimuthSlider_("azimuth")
{
    // This is where our plugin's editor size is set.
    // setSize(170, 80);
    
	betaE_ = 5;
    // Set up the selection boxes
    
    addAndMakeVisible(&fftSizeComboBox_);
    fftSizeComboBox_.setEditableText(false);
    fftSizeComboBox_.setJustificationType(Justification::left);
    fftSizeComboBox_.addItem("1024", 1024);
    fftSizeComboBox_.addItem("2048", 2048);
	fftSizeComboBox_.addItem("4096", 4096);
    fftSizeComboBox_.addListener(this);
    
    addAndMakeVisible(&hopSizeComboBox_);
    hopSizeComboBox_.setEditableText(false);
    hopSizeComboBox_.setJustificationType(Justification::left);
    hopSizeComboBox_.addItem("1/4 Window", ADRessAudioProcessor::kHopSize1_4Window);
    hopSizeComboBox_.addItem("1/8 Window", ADRessAudioProcessor::kHopSize1_8Window);
    hopSizeComboBox_.addListener(this);
    
    addAndMakeVisible(&windowTypeComboBox_);
    windowTypeComboBox_.setEditableText(false);
    windowTypeComboBox_.setJustificationType(Justification::left);
    windowTypeComboBox_.addItem("Rectangular", ADRessAudioProcessor::kWindowRectangular);
    windowTypeComboBox_.addItem("Bartlett", ADRessAudioProcessor::kWindowBartlett);
    windowTypeComboBox_.addItem("Hann", ADRessAudioProcessor::kWindowHann);
    windowTypeComboBox_.addItem("Hamming", ADRessAudioProcessor::kWindowHamming);
    windowTypeComboBox_.addListener(this);

	
	// Set up the sliders
    addAndMakeVisible(&widthSlider_);
    widthSlider_.setSliderStyle(Slider::Rotary);
    widthSlider_.addListener(this);
    widthSlider_.setRange(0, betaE_, 1);
    
    widthLabel_.attachToComponent(&widthSlider_, false);
    widthLabel_.setFont(Font (11.0f));


	    // Set up the sliders
    addAndMakeVisible(&azimuthSlider_);
    azimuthSlider_.setSliderStyle(Slider::Rotary);
    azimuthSlider_.addListener(this);
    azimuthSlider_.setRange(0, 2*betaE_, 1);


    
    azimuthLabel_.attachToComponent(&azimuthSlider_, false);
    azimuthLabel_.setFont(Font (11.0f));

    fftSizeLabel_.attachToComponent(&fftSizeComboBox_, false);
    fftSizeLabel_.setFont(Font (11.0f));
    
    hopSizeLabel_.attachToComponent(&hopSizeComboBox_, false);
    hopSizeLabel_.setFont(Font (11.0f));
    
    windowTypeLabel_.attachToComponent(&windowTypeComboBox_, false);
    windowTypeLabel_.setFont(Font (11.0f));
    
    // add the triangular resizer component for the bottom-right of the UI
    addAndMakeVisible(resizer_ = new ResizableCornerComponent (this, &resizeLimits_));
    resizeLimits_.setSizeLimits(360, 400, 360, 400);
    
    // set our component's initial size to be the last one that was stored in the filter's settings
    setSize(ownerFilter->lastUIWidth_,
            ownerFilter->lastUIHeight_);
    
    startTimer(50);
}

ADRessAudioProcessorEditor::~ADRessAudioProcessorEditor()
{
}

//==============================================================================
void ADRessAudioProcessorEditor::paint (Graphics& g)
{
    g.fillAll (Colours::grey);
}

void ADRessAudioProcessorEditor::resized()
{
    fftSizeComboBox_.setBounds(20, 20, 150, 30);
    hopSizeComboBox_.setBounds(200, 20, 150, 30);
    windowTypeComboBox_.setBounds(20, 75, 150, 30);
	widthSlider_.setBounds(200, 70, 150, 40);

	azimuthSlider_.setBounds(20, 150, 150, 40);
    resizer_->setBounds(getWidth() - 16, getHeight() - 16, 16, 16);
    
    getProcessor()->lastUIWidth_ = getWidth();
    getProcessor()->lastUIHeight_ = getHeight();
}

//==============================================================================
// This timer periodically checks whether any of the filter's parameters have changed...
void ADRessAudioProcessorEditor::timerCallback()
{
    ADRessAudioProcessor* ourProcessor = getProcessor();
    
    fftSizeComboBox_.setSelectedId(ourProcessor->fftSelectedSize_, false);
    hopSizeComboBox_.setSelectedId(ourProcessor->hopSelectedSize_, false);
    windowTypeComboBox_.setSelectedId(ourProcessor->windowType_, false);

	widthSlider_.setValue(ourProcessor->width_, dontSendNotification);
	azimuthSlider_.setValue(ourProcessor->azimuth_, dontSendNotification);
}

// This is our Slider::Listener callback, when the user drags a slider.
void ADRessAudioProcessorEditor::sliderValueChanged (Slider* slider)
{
	if (slider == &widthSlider_)
    {
        // It's vital to use setParameterNotifyingHost to change any parameters that are automatable
        // by the host, rather than just modifying them directly, otherwise the host won't know
        // that they've changed.
        getProcessor()->setParameterNotifyingHost (ADRessAudioProcessor::kWidthParam,
                                                   (float)widthSlider_.getValue());
	}
	
    if (slider == &azimuthSlider_)
    {
		getProcessor()->setParameterNotifyingHost (ADRessAudioProcessor::kAzimuthParam,
                                                   (float)azimuthSlider_.getValue());
	}
}

// Similar callback to sliderValueChanged for ComboBox updates
void ADRessAudioProcessorEditor::comboBoxChanged (ComboBox *comboBox)
{
    if(comboBox == &fftSizeComboBox_)
    {
        getProcessor()->setParameterNotifyingHost (ADRessAudioProcessor::kFFTSizeParam,
                                                   (float)fftSizeComboBox_.getSelectedId());
    }
    else if(comboBox == &hopSizeComboBox_)
    {
        getProcessor()->setParameterNotifyingHost (ADRessAudioProcessor::kHopSizeParam,
                                                   (float)hopSizeComboBox_.getSelectedId());
    }
    else if(comboBox == &windowTypeComboBox_)
    {
        getProcessor()->setParameterNotifyingHost (ADRessAudioProcessor::kWindowTypeParam,
                                                   (float)windowTypeComboBox_.getSelectedId());
    }
}

int ADRessAudioProcessorEditor::getBeta()
{
	return betaE_;
}