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

    This file contains the basic framework code for a JUCE plugin processor.

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

#pragma once

#include <JuceHeader.h>
#include "CMLSReverb.h"
#include "CMLSDelay.h"
#include "CMLSChorus.h"
#include "CMLSProcessorChain.h"
#include "CMLSEqualizer.h"
#include "CMLSDistortion.h"
#include "APVTSListeners.h"

//==============================================================================
/**
*/
class CMLSProjectAudioProcessor  : public juce::AudioProcessor
{
public:
    //==============================================================================
    CMLSProjectAudioProcessor();
    ~CMLSProjectAudioProcessor() override;

    //==============================================================================
    void prepareToPlay (double sampleRate, int samplesPerBlock) override;
    void releaseResources() override;

   #ifndef JucePlugin_PreferredChannelConfigurations
    bool isBusesLayoutSupported (const BusesLayout& layouts) const override;
   #endif

    void processBlock (juce::AudioBuffer<float>&, juce::MidiBuffer&) override;

    //==============================================================================
    juce::AudioProcessorEditor* createEditor() override;
    bool hasEditor() const override;

    //==============================================================================
    const juce::String getName() const override;

    bool acceptsMidi() const override;
    bool producesMidi() const override;
    bool isMidiEffect() const override;
    double getTailLengthSeconds() const override;

    //==============================================================================
    int getNumPrograms() override;
    int getCurrentProgram() override;
    void setCurrentProgram (int index) override;
    const juce::String getProgramName (int index) override;
    void changeProgramName (int index, const juce::String& newName) override;

    //==============================================================================
    void getStateInformation (juce::MemoryBlock& destData) override;
    void setStateInformation (const void* data, int sizeInBytes) override;

    // Mute/unmute slot by number
    void muteEffectInSlot(int slot);
    void unmuteEffectInSlot(int slot);
	void swapEffectInSlot(int slot1, int slot2);

	// Value Tree State for parameters
    juce::AudioProcessorValueTreeState apvts;
    juce::AudioProcessorValueTreeState* getApvts();

private:
    //==============================================================================

    // Effects processing chain
    juce::dsp::ProcessorBase* equalizer;
	juce::dsp::ProcessorBase* distortion;
    juce::dsp::ProcessorBase* chorus;
    juce::dsp::ProcessorBase* delay;
    juce::dsp::ProcessorBase* reverb;

	CMLSProcessorChain processorChain;
	APVTSListeners apvtsListeners;

	juce::AudioProcessorValueTreeState::ParameterLayout createParameters();

    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CMLSProjectAudioProcessor)
};
