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

    This file was auto-generated by the Introjucer!

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

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

#include "PluginProcessor.h"
#include "PluginEditor.h"
#include <random>

using namespace gin;

//==============================================================================
String onOffTextFunction (const Parameter&, float v)
{
    return v > 0.0f ? "On" : "Off";
}

String modeTextFunction (const Parameter&, float v)
{
    switch (int (v))
    {
        case 0:  return "Spectroscope";
        case 1:  return "Sonogram";
        default: return "";
    }
}

//==============================================================================
PluginProcessor::PluginProcessor()
{
    addExtParam (PARAM_MODE, "Mode", "", "", {0.0f, 1.0f, 1.0f, 1.0f}, 0.0f, 0.0f, modeTextFunction);
    addExtParam (PARAM_LOG,  "Log",  "", "", {0.0f, 1.0f, 1.0f, 1.0f}, 0.0f, 0.0f, onOffTextFunction);
}

PluginProcessor::~PluginProcessor()
{
}

//==============================================================================
void PluginProcessor::prepareToPlay (double, int)
{
}

void PluginProcessor::releaseResources()
{
}

void PluginProcessor::processBlock (AudioSampleBuffer& buffer, MidiBuffer&)
{
    ScopedLock sl (lock);
    if (editor != nullptr)
    {
        const int num = buffer.getNumSamples();
        editor->scopeL.copySamples (buffer.getReadPointer (0), num);
        editor->sonogramL.copySamples (buffer.getReadPointer (0), num);
        
        if (getTotalNumInputChannels() > 1)
        {
            editor->scopeR.copySamples (buffer.getReadPointer (1), num);
            editor->sonogramR.copySamples (buffer.getReadPointer (1), num);
        }
    }
}

//==============================================================================
bool PluginProcessor::hasEditor() const
{
    return true;
}

AudioProcessorEditor* PluginProcessor::createEditor()
{
    editor = new PluginEditor (*this);
    return editor;
}

//==============================================================================
// This creates new instances of the plugin..
AudioProcessor* JUCE_CALLTYPE createPluginFilter()
{
    return new PluginProcessor();
}
