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

    CMLSDelay.h
    Created: 3 May 2025 5:39:35pm
    Author:  Luigi
	Ref. https://github.com/flipbug/simple-delay/tree/master

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

#pragma once
#include <JuceHeader.h>

#define MAX_DELAY_LENGTH 1.0f // Maximum delay time in seconds
#define MIN_FEEDBACK -100.0f
#define MAX_FEEDBACK 0.0f

class CMLSDelay : public juce::dsp::ProcessorBase
{
	public:
		CMLSDelay();
		~CMLSDelay() override;

		void reset() override;
		void prepare(const juce::dsp::ProcessSpec&) override;
		void process(const juce::dsp::ProcessContextReplacing<float>&) override;
	
		// Parameter getters and setters
		void setDryWet(float value);
		void setAmount(float value);
		const float getDryWet();
		const float getAmount();

	private:
		//Parameters
		float dryWetProp;
		float feedback;
		float delayLength;
		float amount;

		int maximumDelaySamples = 0;

		// Dry/Wet mixer
		juce::dsp::DryWetMixer<float> mixer;

		// DelayLine
		juce::dsp::DelayLine<float, juce::dsp::DelayLineInterpolationTypes::Linear> delayLine;
		juce::dsp::DelayLine<float, juce::dsp::DelayLineInterpolationTypes::Linear> delayLine2;

		// Range converters
		juce::NormalisableRange<float>* delayRange;
		juce::SmoothedValue<float, juce::ValueSmoothingTypes::Linear>* delaySmoothing;
		int lastDelayInSamples = 0;
};