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

    This file was auto-generated by the Introjucer!

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

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

#pragma once

#include "../JuceLibraryCode/JuceHeader.h"
#include "PluginProcessor.h"

class ControllerComponent : public Component,
                            private Timer
{
public:
    ControllerComponent (ControllerState& cs, int controller_)
      : state (cs), controller (controller_)
    {
        startTimerHz (30);
    }
    
    void timerCallback() override
    {
        int newValue = controller >= 0 ? state.getControllerValue (controller) : state.getPitchBend();
        if (newValue != value)
        {
            value = newValue;
            repaint();
        }
    }
    
    void paint (Graphics& g) override
    {
        g.setColour (Colours::white);
        g.drawRect (getLocalBounds());
        
        float p = controller >= 0 ? value / 127.0f : value / 16384.0f;
        
        int h = getHeight() - 2;
        int w = getWidth() - 2;
        
        g.setColour (Colours::white.withAlpha (0.75f));
        g.drawRect (1, int (1 + h - h * p), w, 1);
    }
    
    ControllerState& state;
    int controller = 0;
    int value = 0;
};
//==============================================================================
/**
*/
class KeyboardAudioProcessorEditor  : public gin::GinAudioProcessorEditor
{
public:
    KeyboardAudioProcessorEditor (KeyboardAudioProcessor&);
    ~KeyboardAudioProcessorEditor();

    //==============================================================================
    void resized() override;
    
private:
    KeyboardAudioProcessor& processor;
    MidiKeyboardComponent keyboard;
    ControllerComponent modWheel, pitchWheel;
    
    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (KeyboardAudioProcessorEditor)
};
