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

    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";
}

//==============================================================================
inline bool oddEven (int x)
{
    return (x % 2 == 0) ? 1 : -1;
}
//==============================================================================
ChannelMuteAudioProcessor::ChannelMuteAudioProcessor()
{
    //==============================================================================
    addExtParam (PARAM_MUTE_L,    "Mute L",       "", "",   {  0.0f,  1.0f, 1.0f, 1.0f}, 0.0f, 0.0f, onOffTextFunction);
    addExtParam (PARAM_LEVEL_L,   "Level L",      "", "dB", {-100.0f, 6.0f, 0.0f, 5.0f}, 0.0f, 0.0f);
    addExtParam (PARAM_MUTE_R,    "Mute R",       "", "",   {  0.0f,  1.0f, 1.0f, 1.0f}, 0.0f, 0.0f, onOffTextFunction);
    addExtParam (PARAM_LEVEL_R,   "Level R",      "", "dB", {-100.0f, 6.0f, 0.0f, 5.0f}, 0.0f, 0.0f);
}

ChannelMuteAudioProcessor::~ChannelMuteAudioProcessor()
{
}

//==============================================================================
void ChannelMuteAudioProcessor::prepareToPlay (double sampleRate, int)
{
    lVal.reset (sampleRate, 0.05);
    rVal.reset (sampleRate, 0.05);
}

void ChannelMuteAudioProcessor::releaseResources()
{
}

void ChannelMuteAudioProcessor::processBlock (AudioSampleBuffer& buffer, MidiBuffer&)
{
    lVal.setTargetValue (parameterIntValue (PARAM_MUTE_L) ? 0.0f : Decibels::decibelsToGain (parameterValue (PARAM_LEVEL_L)));
    rVal.setTargetValue (parameterIntValue (PARAM_MUTE_R) ? 0.0f : Decibels::decibelsToGain (parameterValue (PARAM_LEVEL_R)));

    applyGain (buffer, 0, lVal);
    applyGain (buffer, 1, rVal);
}

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

AudioProcessorEditor* ChannelMuteAudioProcessor::createEditor()
{
    editor = new ChannelMuteAudioProcessorEditor (*this);
    return editor;
}

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