<commit_before>/*
  ==============================================================================

    This file was auto-generated!

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

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

#include "PluginProcessor.h"
#include "PluginEditor.h"


//==============================================================================
ATKColoredCompressorAudioProcessor::ATKColoredCompressorAudioProcessor()
  :
#ifndef JucePlugin_PreferredChannelConfigurations
    AudioProcessor (BusesProperties()
                     #if ! JucePlugin_IsMidiEffect
                      #if ! JucePlugin_IsSynth
                       .withInput  ("Input",  AudioChannelSet::stereo(), true)
                      #endif
                       .withOutput ("Output", AudioChannelSet::stereo(), true)
                     #endif
                       ),
#endif
  inFilter(nullptr, 1, 0, false), outFilter(nullptr, 1, 0, false), gainCompressorFilter(1, 256*1024), parameters(*this, nullptr), sampleRate(0), old_rms(0), old_attack(0), old_release(0), old_threshold(-1), old_slope(-1), old_softness(-5), old_color(-1), old_quality(-1), old_makeup(-1), old_drywet(-1)
{
  powerFilter.set_input_port(0, &inFilter, 0);
  attackReleaseFilter.set_input_port(0, &powerFilter, 0);
  gainCompressorFilter.set_input_port(0, &attackReleaseFilter, 0);
  applyGainFilter.set_input_port(0, &gainCompressorFilter, 0);
  applyGainFilter.set_input_port(1, &inFilter, 0);
  volumeFilter.set_input_port(0, &applyGainFilter, 0);
  drywetFilter.set_input_port(0, &volumeFilter, 0);
  drywetFilter.set_input_port(1, &inFilter, 0);
  outFilter.set_input_port(0, &drywetFilter, 0);
  
  parameters.createAndAddParameter("power", "Power", " ms", NormalisableRange<float>(0, 100), 10, nullptr, nullptr);
  parameters.createAndAddParameter("attack", "Attack", " ms", NormalisableRange<float>(1, 100), 10, nullptr, nullptr);
  parameters.createAndAddParameter("release", "Release", " ms",  NormalisableRange<float>(1, 100), 10, nullptr, nullptr);
  parameters.createAndAddParameter("threshold", "Threshold", " dB", NormalisableRange<float>(-40, 0), 0, nullptr, nullptr);
  parameters.createAndAddParameter("slope", "Slope", "", NormalisableRange<float>(1.5, 100), 2, nullptr, nullptr);
  parameters.createAndAddParameter("color", "Color", "", NormalisableRange<float>(-.5, .5), 0, nullptr, nullptr);
  parameters.createAndAddParameter("quality", "Quality", "", NormalisableRange<float>(0.01, .2), .1, nullptr, nullptr);
  parameters.createAndAddParameter("softness", "Softness", "", NormalisableRange<float>(-4, 0), -2, nullptr, nullptr);
  parameters.createAndAddParameter("makeup", "Makeup gain", " dB", NormalisableRange<float>(0, 40), 0, nullptr, nullptr);
  parameters.createAndAddParameter("drywet", "Dry/Wet", "", NormalisableRange<float>(0, 100), 100, nullptr, nullptr);
  
  parameters.state = ValueTree (Identifier ("ATKColoredCompressor"));;
}

ATKColoredCompressorAudioProcessor::~ATKColoredCompressorAudioProcessor()
{
}

//==============================================================================
const String ATKColoredCompressorAudioProcessor::getName() const
{
    return JucePlugin_Name;
}

bool ATKColoredCompressorAudioProcessor::acceptsMidi() const
{
   #if JucePlugin_WantsMidiInput
    return true;
   #else
    return false;
   #endif
}

bool ATKColoredCompressorAudioProcessor::producesMidi() const
{
   #if JucePlugin_ProducesMidiOutput
    return true;
   #else
    return false;
   #endif
}

double ATKColoredCompressorAudioProcessor::getTailLengthSeconds() const
{
    return 0.0;
}

int ATKColoredCompressorAudioProcessor::getNumPrograms()
{
    return 1;   // NB: some hosts don't cope very well if you tell them there are 0 programs,
                // so this should be at least 1, even if you're not really implementing programs.
}

int ATKColoredCompressorAudioProcessor::getCurrentProgram()
{
    return 0;
}

void ATKColoredCompressorAudioProcessor::setCurrentProgram (int index)
{
}

const String ATKColoredCompressorAudioProcessor::getProgramName (int index)
{
    return {};
}

void ATKColoredCompressorAudioProcessor::changeProgramName (int index, const String& newName)
{
}

//==============================================================================
void ATKColoredCompressorAudioProcessor::prepareToPlay (double dbSampleRate, int samplesPerBlock)
{
	auto sampleRate = std::lround(dbSampleRate);
  
  if(sampleRate != inFilter.get_output_sampling_rate())
  {
    inFilter.set_input_sampling_rate(sampleRate);
    inFilter.set_output_sampling_rate(sampleRate);
    powerFilter.set_input_sampling_rate(sampleRate);
    powerFilter.set_output_sampling_rate(sampleRate);
    attackReleaseFilter.set_input_sampling_rate(sampleRate);
    attackReleaseFilter.set_output_sampling_rate(sampleRate);
    gainCompressorFilter.set_input_sampling_rate(sampleRate);
    gainCompressorFilter.set_output_sampling_rate(sampleRate);
    applyGainFilter.set_input_sampling_rate(sampleRate);
    applyGainFilter.set_output_sampling_rate(sampleRate);
    volumeFilter.set_input_sampling_rate(sampleRate);
    volumeFilter.set_output_sampling_rate(sampleRate);
    drywetFilter.set_input_sampling_rate(sampleRate);
    drywetFilter.set_output_sampling_rate(sampleRate);
    outFilter.set_input_sampling_rate(sampleRate);
    outFilter.set_output_sampling_rate(sampleRate);
    outFilter.set_input_sampling_rate(sampleRate);
    outFilter.set_output_sampling_rate(sampleRate);
    
    if (old_rms == 0)
    {
      powerFilter.set_memory(0);
    }
    else
    {
      powerFilter.set_memory(std::exp(-1e3 / (old_rms * sampleRate)));
    }
    attackReleaseFilter.set_release(std::exp(-1e3/(old_release * sampleRate))); // in ms
    attackReleaseFilter.set_attack(std::exp(-1e3/(old_attack * sampleRate))); // in ms

    powerFilter.full_setup();
    attackReleaseFilter.full_setup();
  }
}

void ATKColoredCompressorAudioProcessor::releaseResources()
{
    // When playback stops, you can use this as an opportunity to free up any
    // spare memory, etc.
}

#ifndef JucePlugin_PreferredChannelConfigurations
bool ATKColoredCompressorAudioProcessor::isBusesLayoutSupported (const BusesLayout& layouts) const
{
  #if JucePlugin_IsMidiEffect
    ignoreUnused (layouts);
    return true;
  #else
    // This is the place where you check if the layout is supported.
    if (layouts.getMainOutputChannelSet() != AudioChannelSet::stereo())
        return false;

    // This checks if the input layout matches the output layout
   #if ! JucePlugin_IsSynth
    if (layouts.getMainOutputChannelSet() != layouts.getMainInputChannelSet())
        return false;
   #endif<commit_msg>Fixed full_setup calls<commit_after>/*
  ==============================================================================

    This file was auto-generated!

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

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

#include "PluginProcessor.h"
#include "PluginEditor.h"


//==============================================================================
ATKColoredCompressorAudioProcessor::ATKColoredCompressorAudioProcessor()
  :
#ifndef JucePlugin_PreferredChannelConfigurations
    AudioProcessor (BusesProperties()
                     #if ! JucePlugin_IsMidiEffect
                      #if ! JucePlugin_IsSynth
                       .withInput  ("Input",  AudioChannelSet::stereo(), true)
                      #endif
                       .withOutput ("Output", AudioChannelSet::stereo(), true)
                     #endif
                       ),
#endif
  inFilter(nullptr, 1, 0, false), outFilter(nullptr, 1, 0, false), gainCompressorFilter(1, 256*1024), parameters(*this, nullptr), sampleRate(0), old_rms(0), old_attack(0), old_release(0), old_threshold(-1), old_slope(-1), old_softness(-5), old_color(-1), old_quality(-1), old_makeup(-1), old_drywet(-1)
{
  powerFilter.set_input_port(0, &inFilter, 0);
  attackReleaseFilter.set_input_port(0, &powerFilter, 0);
  gainCompressorFilter.set_input_port(0, &attackReleaseFilter, 0);
  applyGainFilter.set_input_port(0, &gainCompressorFilter, 0);
  applyGainFilter.set_input_port(1, &inFilter, 0);
  volumeFilter.set_input_port(0, &applyGainFilter, 0);
  drywetFilter.set_input_port(0, &volumeFilter, 0);
  drywetFilter.set_input_port(1, &inFilter, 0);
  outFilter.set_input_port(0, &drywetFilter, 0);
  
  parameters.createAndAddParameter("power", "Power", " ms", NormalisableRange<float>(0, 100), 10, nullptr, nullptr);
  parameters.createAndAddParameter("attack", "Attack", " ms", NormalisableRange<float>(1, 100), 10, nullptr, nullptr);
  parameters.createAndAddParameter("release", "Release", " ms",  NormalisableRange<float>(1, 100), 10, nullptr, nullptr);
  parameters.createAndAddParameter("threshold", "Threshold", " dB", NormalisableRange<float>(-40, 0), 0, nullptr, nullptr);
  parameters.createAndAddParameter("slope", "Slope", "", NormalisableRange<float>(1.5, 100), 2, nullptr, nullptr);
  parameters.createAndAddParameter("color", "Color", "", NormalisableRange<float>(-.5, .5), 0, nullptr, nullptr);
  parameters.createAndAddParameter("quality", "Quality", "", NormalisableRange<float>(0.01, .2), .1, nullptr, nullptr);
  parameters.createAndAddParameter("softness", "Softness", "", NormalisableRange<float>(-4, 0), -2, nullptr, nullptr);
  parameters.createAndAddParameter("makeup", "Makeup gain", " dB", NormalisableRange<float>(0, 40), 0, nullptr, nullptr);
  parameters.createAndAddParameter("drywet", "Dry/Wet", "", NormalisableRange<float>(0, 100), 100, nullptr, nullptr);
  
  parameters.state = ValueTree (Identifier ("ATKColoredCompressor"));;
}

ATKColoredCompressorAudioProcessor::~ATKColoredCompressorAudioProcessor()
{
}

//==============================================================================
const String ATKColoredCompressorAudioProcessor::getName() const
{
    return JucePlugin_Name;
}

bool ATKColoredCompressorAudioProcessor::acceptsMidi() const
{
   #if JucePlugin_WantsMidiInput
    return true;
   #else
    return false;
   #endif
}

bool ATKColoredCompressorAudioProcessor::producesMidi() const
{
   #if JucePlugin_ProducesMidiOutput
    return true;
   #else
    return false;
   #endif
}

double ATKColoredCompressorAudioProcessor::getTailLengthSeconds() const
{
    return 0.0;
}

int ATKColoredCompressorAudioProcessor::getNumPrograms()
{
    return 1;   // NB: some hosts don't cope very well if you tell them there are 0 programs,
                // so this should be at least 1, even if you're not really implementing programs.
}

int ATKColoredCompressorAudioProcessor::getCurrentProgram()
{
    return 0;
}

void ATKColoredCompressorAudioProcessor::setCurrentProgram (int index)
{
}

const String ATKColoredCompressorAudioProcessor::getProgramName (int index)
{
    return {};
}

void ATKColoredCompressorAudioProcessor::changeProgramName (int index, const String& newName)
{
}

//==============================================================================
void ATKColoredCompressorAudioProcessor::prepareToPlay (double dbSampleRate, int samplesPerBlock)
{
	auto sampleRate = std::lround(dbSampleRate);
  
  if(sampleRate != inFilter.get_output_sampling_rate())
  {
    inFilter.set_input_sampling_rate(sampleRate);
    inFilter.set_output_sampling_rate(sampleRate);
    powerFilter.set_input_sampling_rate(sampleRate);
    powerFilter.set_output_sampling_rate(sampleRate);
    attackReleaseFilter.set_input_sampling_rate(sampleRate);
    attackReleaseFilter.set_output_sampling_rate(sampleRate);
    gainCompressorFilter.set_input_sampling_rate(sampleRate);
    gainCompressorFilter.set_output_sampling_rate(sampleRate);
    applyGainFilter.set_input_sampling_rate(sampleRate);
    applyGainFilter.set_output_sampling_rate(sampleRate);
    volumeFilter.set_input_sampling_rate(sampleRate);
    volumeFilter.set_output_sampling_rate(sampleRate);
    drywetFilter.set_input_sampling_rate(sampleRate);
    drywetFilter.set_output_sampling_rate(sampleRate);
    outFilter.set_input_sampling_rate(sampleRate);
    outFilter.set_output_sampling_rate(sampleRate);
    outFilter.set_input_sampling_rate(sampleRate);
    outFilter.set_output_sampling_rate(sampleRate);
    
    if (old_rms == 0)
    {
      powerFilter.set_memory(0);
    }
    else
    {
      powerFilter.set_memory(std::exp(-1e3 / (old_rms * sampleRate)));
    }
    attackReleaseFilter.set_release(std::exp(-1e3/(old_release * sampleRate))); // in ms
    attackReleaseFilter.set_attack(std::exp(-1e3/(old_attack * sampleRate))); // in ms
  }
  powerFilter.full_setup();
  attackReleaseFilter.full_setup();
}

void ATKColoredCompressorAudioProcessor::releaseResources()
{
    // When playback stops, you can use this as an opportunity to free up any
    // spare memory, etc.
}

#ifndef JucePlugin_PreferredChannelConfigurations
bool ATKColoredCompressorAudioProcessor::isBusesLayoutSupported (const BusesLayout& layouts) const
{
  #if JucePlugin_IsMidiEffect
    ignoreUnused (layouts);
    return true;
  #else
    // This is the place where you check if the layout is supported.
    if (layouts.getMainOutputChannelSet() != AudioChannelSet::stereo())
        return false;

    // This checks if the input layout matches the output layout
   #if ! JucePlugin_IsSynth
    if (layouts.getMainOutputChannelSet() != layouts.getMainInputChannelSet())
        return false;
   #endif
{'fraction_non_alphanumeric': 0.16518650088809947, 'fraction_numerical': 0.015541740674955595, 'mean_word_length': 5.344131455399061, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5709510', 'n_tokens_mistral': 4246, 'n_tokens_neox': 3942, 'n_words': 749}