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

    This file was auto-generated by the Introjucer!

    It contains the basic framework code for a JUCE plugin editor.

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

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

using namespace gin;

//==============================================================================
CompensatedDelayAudioProcessorEditor::CompensatedDelayAudioProcessorEditor (CompensatedDelayAudioProcessor& p)
    : gin::ProcessorEditor (p), proc (p)
{
    for (auto pp : p.getPluginParameters())
    {
        ParamComponent* pc;
        
        if (pp == proc.mode)
            pc = new Select (pp);
        else if (pp->isOnOff())
            pc = new Switch (pp);
        else
            pc = new Knob (pp);
        
        addAndMakeVisible (pc);
        controls.add (pc);
    }
    
    setGridSize (6, 1);
    
    proc.mode->addListener (this);
    
    valueUpdated (proc.mode);
}

CompensatedDelayAudioProcessorEditor::~CompensatedDelayAudioProcessorEditor()
{
    proc.mode->removeListener (this);
}

//==============================================================================
void CompensatedDelayAudioProcessorEditor::resized()
{
    gin::ProcessorEditor::resized();

    componentForParam (*proc.mode)->setBounds (getGridArea (2, 0));
    componentForParam (*proc.time)->setBounds (getGridArea (3, 0));
    componentForParam (*proc.samples)->setBounds (getGridArea (3, 0));
}

void CompensatedDelayAudioProcessorEditor::valueUpdated (Parameter* param)
{
    if (param == proc.mode)
    {
        bool samples = proc.mode->getUserValueInt() == 0;
        componentForParam (*proc.samples)->setVisible (samples);
        componentForParam (*proc.time)->setVisible (! samples);
    }
}
