Skip to content

Commit

Permalink
Reorganizing git files, adding configurable chebyshev
Browse files Browse the repository at this point in the history
  • Loading branch information
jbarkuloo committed Sep 15, 2021
1 parent 1affef4 commit fb02c03
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 1,076 deletions.
2 changes: 2 additions & 0 deletions Distortion_Project/Distortion_Project.jucer
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<MODULEPATH id="juce_graphics" path="../../../../../../../../../JUCE/modules"/>
<MODULEPATH id="juce_gui_basics" path="../../../../../../../../../JUCE/modules"/>
<MODULEPATH id="juce_gui_extra" path="../../../../../../../../../JUCE/modules"/>
<MODULEPATH id="juce_dsp" path="../../../modules"/>
</MODULEPATHS>
</VS2019>
</EXPORTFORMATS>
Expand All @@ -47,6 +48,7 @@
<MODULE id="juce_audio_utils" showAllCode="1" useLocalCopy="0" useGlobalPath="1"/>
<MODULE id="juce_core" showAllCode="1" useLocalCopy="0" useGlobalPath="1"/>
<MODULE id="juce_data_structures" showAllCode="1" useLocalCopy="0" useGlobalPath="1"/>
<MODULE id="juce_dsp" showAllCode="1" useLocalCopy="0" useGlobalPath="1"/>
<MODULE id="juce_events" showAllCode="1" useLocalCopy="0" useGlobalPath="1"/>
<MODULE id="juce_graphics" showAllCode="1" useLocalCopy="0" useGlobalPath="1"/>
<MODULE id="juce_gui_basics" showAllCode="1" useLocalCopy="0" useGlobalPath="1"/>
Expand Down
61 changes: 47 additions & 14 deletions Distortion_Project/Source/PluginEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

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

//==============================================================================
Distortion_ProjectAudioProcessorEditor::Distortion_ProjectAudioProcessorEditor (Distortion_ProjectAudioProcessor& p)
Expand Down Expand Up @@ -64,7 +64,21 @@ Distortion_ProjectAudioProcessorEditor::Distortion_ProjectAudioProcessorEditor (
// clipSliderNeg Style and position
clipSliderNeg.setSliderStyle(juce::Slider::SliderStyle::RotaryHorizontalVerticalDrag);
clipSliderNeg.setTextBoxStyle(juce::Slider::TextEntryBoxPosition((((getWidth() / 3) * 1 - 25), (getHeight() / 2) + 5 - (25 / 2))), true, 50, 25);

//highPassSlider colors
highPassSlider.setColour(juce::Slider::rotarySliderOutlineColourId, juce::Colour::Colour(0.52f, 0.4f, 0.3f, 1.0f));
highPassSlider.setColour(juce::Slider::rotarySliderFillColourId, juce::Colour::Colour(0.52f, 0.4f, 0.7f, 1.0f));
highPassSlider.setColour(juce::Slider::textBoxOutlineColourId, juce::Colours::transparentWhite);
//highPassSlider style and position
highPassSlider.setSliderStyle(juce::Slider::SliderStyle::RotaryHorizontalVerticalDrag);
highPassSlider.setTextBoxStyle(juce::Slider::TextEntryBoxPosition((((getWidth() / 3) * 4 - 25), (getHeight() / 1) + 5 - (25 / 2))), true, 50, 25);
//lowPassSlider colors
lowPassSlider.setColour(juce::Slider::rotarySliderOutlineColourId, juce::Colour::Colour(0.52f, 0.4f, 0.3f, 1.0f));
lowPassSlider.setColour(juce::Slider::rotarySliderFillColourId, juce::Colour::Colour(0.52f, 0.4f, 0.7f, 1.0f));
lowPassSlider.setColour(juce::Slider::textBoxOutlineColourId, juce::Colours::transparentWhite);
//LO2PassSlider style and position
lowPassSlider.setSliderStyle(juce::Slider::SliderStyle::RotaryHorizontalVerticalDrag);
lowPassSlider.setTextBoxStyle(juce::Slider::TextEntryBoxPosition((((getWidth() / 3) * 4 - 25), (getHeight() / 2) + 5 - (25 / 2))), true, 50, 25);

// Add items to ComboBox
typeBox.addItem("Soft", 1);
typeBox.addItem("Hard", 2);
Expand All @@ -81,7 +95,8 @@ Distortion_ProjectAudioProcessorEditor::Distortion_ProjectAudioProcessorEditor (
addAndMakeVisible(NameLabel);
addAndMakeVisible(audioProcessor.visualiser);
addAndMakeVisible(clipSliderNeg);

addAndMakeVisible(highPassSlider);
addAndMakeVisible(lowPassSlider);

// Add Listeners
inGainSlider.addListener(this);
Expand All @@ -90,8 +105,8 @@ Distortion_ProjectAudioProcessorEditor::Distortion_ProjectAudioProcessorEditor (
clipSlider.addListener(this);
clipSliderNeg.addListener(this);
typeBox.addListener(this); //typeBox requires listener


highPassSlider.addListener(this);
lowPassSlider.addListener(this);
//
driveSlider.addMouseListener(this, false);

Expand All @@ -101,7 +116,9 @@ Distortion_ProjectAudioProcessorEditor::Distortion_ProjectAudioProcessorEditor (
driveSlider.setLookAndFeel(&otherLookAndFeel);
clipSlider.setLookAndFeel(&otherLookAndFeel);
clipSliderNeg.setLookAndFeel(&otherLookAndFeel);

highPassSlider.setLookAndFeel(&otherLookAndFeel);
lowPassSlider.setLookAndFeel(&otherLookAndFeel);

//Pimpl(Slider & s, SliderStyle sliderStyle, TextEntryBoxPosition textBoxPosition)


Expand All @@ -115,10 +132,14 @@ Distortion_ProjectAudioProcessorEditor::Distortion_ProjectAudioProcessorEditor (
typeBoxAttachment = std::make_unique<BoxAttachments>(audioProcessor.apvts,
"TYPE", typeBox);
clipSliderAttachment = std::make_unique<SliderAttachments>(audioProcessor.apvts,
"CLIP", clipSlider);
"CLIPPOS", clipSlider);
//added for experimentation
clipSliderNegAttachment = std::make_unique<SliderAttachments>(audioProcessor.apvts,
"CLIPNEG", clipSliderNeg);
highPassSliderAttachment = std::make_unique<SliderAttachments>(audioProcessor.apvts,
"HIGH(Hz)", highPassSlider);
lowPassSliderAttachment = std::make_unique<SliderAttachments>(audioProcessor.apvts,
"LOW(Hz)", lowPassSlider);

// Make sure that before the constructor has finished, you've set the
// editor's size to whatever you need it to be.
Expand All @@ -133,6 +154,8 @@ Distortion_ProjectAudioProcessorEditor::~Distortion_ProjectAudioProcessorEditor(
driveSlider.setLookAndFeel(nullptr);
clipSlider.setLookAndFeel(nullptr);
clipSliderNeg.setLookAndFeel(nullptr);
highPassSlider.setLookAndFeel(nullptr);
lowPassSlider.setLookAndFeel(nullptr);
}

//==============================================================================
Expand All @@ -153,18 +176,19 @@ void Distortion_ProjectAudioProcessorEditor::paint(juce::Graphics& g)
// **********************************(Should change these to labels!!)**********************************************
g.drawText("INGAIN", ((getWidth() / 5) * 1) - driveSlider.getWidth()/2, (getHeight() / 4) + driveSlider.getHeight()/20, 100, 100, juce::Justification::centred, false);
g.drawText("DRIVE", ((getWidth() / 5) * 2) - driveSlider.getWidth() / 2, (getHeight() / 4) + driveSlider.getHeight() / 20, 100, 100, juce::Justification::centred, false);
g.drawText("CLIP", ((getWidth() / 5) * 1) - (100 / 2), (getHeight() / 2) + 5, 100, 100, juce::Justification::centred, false);
g.drawText("CLIPPOS", ((getWidth() / 5) * 1) - (100 / 2), (getHeight() / 2) + 5, 100, 100, juce::Justification::centred, false);
g.drawText("OUTGAIN", ((getWidth() / 5) * 2) - (100 / 2), (getHeight() / 2) + 5, 100, 100, juce::Justification::centred, false);
g.drawText("CLIPNEG", ((getWidth() / 5) * 1) - (100 / 2), (getHeight() / 1.38) + 5, 100, 100, juce::Justification::centred, false);

g.drawText("HIGH(Hz)", ((getWidth() / 5) * 4) - (100 / 2), (getHeight() / 2) + 5, 100, 100, juce::Justification::centred, false);
g.drawText("LOW(Hz)", ((getWidth() / 5) * 4) - (100 / 2), (getHeight() / 1.38) + 5, 100, 100, juce::Justification::centred, false);

// Label for Name of our Organization
titleLabel.setText("U F A E S", juce::dontSendNotification);
titleLabel.setJustificationType(juce::Justification::right);

// Label for Name of Plugin
NameLabel.setFont(juce::Font(25.0f, juce::Font::bold));
NameLabel.setText("T A K E 1", juce::dontSendNotification);
NameLabel.setText("Distortion Multieffect", juce::dontSendNotification);
NameLabel.setJustificationType(juce::Justification::left);


Expand All @@ -185,7 +209,10 @@ void Distortion_ProjectAudioProcessorEditor::resized()
(getHeight() / 2) - (100 / 2), 100, 100);
clipSliderNeg.setBounds(((getWidth() / 5) * 1) - (100 / 2),
(getHeight() / 1.4) - (100 / 2), 100, 100);

highPassSlider.setBounds(((getWidth() / 5) * 4) - (100 / 2),
(getHeight() / 2) - (100 / 2), 100, 100);
lowPassSlider.setBounds(((getWidth() / 5) * 4) - (100 / 2),
(getHeight() / 1.4) - (100 / 2), 100, 100);
// ComboBox Bounds
juce::Rectangle<int> area = getLocalBounds().reduced(60);
typeBox.setBounds(area.removeFromTop(20));
Expand Down Expand Up @@ -213,6 +240,8 @@ void Distortion_ProjectAudioProcessorEditor::sliderValueChanged(juce::Slider* sl
float inGainValue = static_cast<float>(((inGainSlider.getValue() + 40.0) / 80.0) * 0.2 + 0.5);
float outGainValue = static_cast<float>(((outGainSlider.getValue() + 40.0) / 80.0) * 0.2 + 0.5);
float clipValueNeg = static_cast<float>(((clipSliderNeg.getValue() + 40.0) / 20.0) * 0.2 + 0.5);
float highPassValue = static_cast<float>(((highPassSlider.getValue()))); //lisp moment
float lowPassValue = static_cast<float>(((lowPassSlider.getValue() )));
// Limit Brightness between specific range
//float driveBrightness = juce::jlimit(0.5f, 0.7f, driveValue);
//float clipBrightness = juce::jlimit(0.5f, 0.7f, clipValue);
Expand All @@ -231,6 +260,10 @@ void Distortion_ProjectAudioProcessorEditor::sliderValueChanged(juce::Slider* sl
juce::Colour::Colour(0.52f, 0.4f, outGainValue, 1.0f));
clipSliderNeg.setColour(juce::Slider::rotarySliderFillColourId,
juce::Colour::Colour(0.52f, 0.4f, clipValueNeg, 1.0f));
highPassSlider.setColour(juce::Slider::rotarySliderFillColourId,
juce::Colour::Colour(0.52f, 0.4f, highPassValue, 1.0f));
lowPassSlider.setColour(juce::Slider::rotarySliderFillColourId,
juce::Colour::Colour(0.52f, 0.4f, lowPassValue, 1.0f));
}

// Default Constructor
Expand Down Expand Up @@ -330,8 +363,8 @@ void mySlider::mouseDown(const juce::MouseEvent& e)
m.addItem(1, "Do something Here");
//m.addItem(2, "item 2");

const int result = m.show();

//const int result = m.show();
/*
if (result == 0)
{
// user dismissed the menu without picking anything
Expand All @@ -343,7 +376,7 @@ void mySlider::mouseDown(const juce::MouseEvent& e)
else if (result == 2)
{
// user picked item 2
}
}*/
}
else
{
Expand Down
4 changes: 4 additions & 0 deletions Distortion_Project/Source/PluginEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class Distortion_ProjectAudioProcessorEditor : public juce::AudioProcessorEdito
mySlider driveSlider;
mySlider clipSlider;
mySlider clipSliderNeg;
mySlider highPassSlider;
mySlider lowPassSlider;
juce::ComboBox typeBox;

// Create Label Objects
Expand All @@ -100,5 +102,7 @@ class Distortion_ProjectAudioProcessorEditor : public juce::AudioProcessorEdito
std::unique_ptr<SliderAttachments> inGainSliderAttachment;
std::unique_ptr<SliderAttachments> outGainSliderAttachment;
std::unique_ptr<SliderAttachments> clipSliderNegAttachment;
std::unique_ptr<SliderAttachments> highPassSliderAttachment;
std::unique_ptr<SliderAttachments> lowPassSliderAttachment;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Distortion_ProjectAudioProcessorEditor)
};
60 changes: 48 additions & 12 deletions Distortion_Project/Source/PluginProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,21 @@ void Distortion_ProjectAudioProcessor::prepareToPlay (double sampleRate, int sam
update();
reset();
isActive = true;

highPass.setType(juce::dsp::StateVariableTPTFilterType::highpass);
lowPass.setType(juce::dsp::StateVariableTPTFilterType::lowpass);
//highPass.setResonance(3.2);syntax for setting resonance if you want to for some reason
juce::dsp::ProcessSpec spec;
spec.sampleRate = sampleRate;
spec.maximumBlockSize = samplesPerBlock;
spec.numChannels = getTotalNumOutputChannels();

highPass.prepare(spec);
lowPass.prepare(spec);

}


void Distortion_ProjectAudioProcessor::releaseResources()
{
// When playback stops, you can use this as an opportunity to free up any
Expand Down Expand Up @@ -176,11 +188,14 @@ void Distortion_ProjectAudioProcessor::processBlock (juce::AudioBuffer<float>& b
//driveNormal.applyGain(buffer, buffer.getNumSamples());
//clipNormal.applyGain(buffer, buffer.getNumSamples());
inGainNormal.applyGain(buffer, buffer.getNumSamples());

//Highpass filtering
juce::dsp::AudioBlock <float> block1(buffer);
highPass.process(juce::dsp::ProcessContextReplacing<float>(block1));
for (int channel = 0; channel < totalNumInputChannels; ++channel)
{
auto* channelData = buffer.getWritePointer(channel);



//Soft Clip
if (typeNormal == 0.0)
{
Expand All @@ -206,11 +221,19 @@ void Distortion_ProjectAudioProcessor::processBlock (juce::AudioBuffer<float>& b
for (auto i = 0; i < buffer.getNumSamples(); i++)
{
float val = channelData[i] * driveNormal.getCurrentValue();
val = (4 * pow(val, 3) - 3 * val) + (2 * pow(val, 2) - 1) + val + 1;
channelData[i] = juce::jlimit(-1.f,1.f,val);
float a = clipNormal.getCurrentValue() / 4;
float b = 0.5 - a;
float c = clipNeg.getCurrentValue() / 4;
float d = 0.5 - c;

val = (4 * pow(val, 3) - 3 * val)*c + (2 * pow(val, 2) - 1)*b + val*c + 1*d;
channelData[i] = tanh(val);
}
}
}
//lowpass filtering
juce::dsp::AudioBlock <float> block(buffer);
lowPass.process(juce::dsp::ProcessContextReplacing<float>(block));
outGainNormal.applyGain(buffer, buffer.getNumSamples());
visualiser.pushBuffer(buffer);
}
Expand Down Expand Up @@ -272,18 +295,23 @@ void Distortion_ProjectAudioProcessor::update()
auto type = apvts.getRawParameterValue("TYPE");
typeNormal = type->load();

auto clip = apvts.getRawParameterValue("CLIP");
clipNormal = juce::Decibels::decibelsToGain(clip->load());
auto clip = apvts.getRawParameterValue("CLIPPOS");
clipNormal = clip->load();

auto clipneg = apvts.getRawParameterValue("CLIPNEG");
clipNeg = juce::Decibels::decibelsToGain(clipneg->load());
clipNeg = clipneg->load();


auto inGain = apvts.getRawParameterValue("INGAIN");
inGainNormal.setTargetValue(juce::Decibels::decibelsToGain(inGain->load()));

auto outGain = apvts.getRawParameterValue("OUTGAIN");
outGainNormal.setTargetValue(juce::Decibels::decibelsToGain(outGain->load()));
//filter stuff
auto high = apvts.getRawParameterValue("HIGH(Hz)");
highPass.setCutoffFrequency(high->load());
auto low = apvts.getRawParameterValue("LOW(Hz)");
lowPass.setCutoffFrequency(low->load());
}

void Distortion_ProjectAudioProcessor::reset()
Expand All @@ -294,6 +322,9 @@ void Distortion_ProjectAudioProcessor::reset()
outGainNormal.reset(getSampleRate(), 0.050);
clipNeg.reset(getSampleRate(), 0.050);
visualiser.clear();
highPass.reset();
lowPass.reset();

}

//==============================================================================
Expand Down Expand Up @@ -323,12 +354,15 @@ juce::AudioProcessorValueTreeState::ParameterLayout Distortion_ProjectAudioProce

auto driveParam = std::make_unique<juce::AudioParameterFloat>("DRIVE", "Drive",
juce::NormalisableRange<float>(0.0f, 100.0f, 0.1f), 20.0f, "%", juce::AudioProcessorParameter::genericParameter, valueToTextFunction, textToValueFunction);
auto clipParam = std::make_unique<juce::AudioParameterFloat>("CLIP", "Threshold",
juce::NormalisableRange<float>(-40.0f, 0.0f, 0.1f), 0.0f, "dB", juce::AudioProcessorParameter::genericParameter, valueToTextFunction, textToValueFunction);
auto clipParam = std::make_unique<juce::AudioParameterFloat>("CLIPPOS", "Threshold",
juce::NormalisableRange<float>(0.0f, 1.0f, 0.01f), 1.0f, "Gain", juce::AudioProcessorParameter::genericParameter, valueToTextFunction, textToValueFunction);
auto clipParamNeg = std::make_unique<juce::AudioParameterFloat>("CLIPNEG", "Threshold",
juce::NormalisableRange<float>(-40.0f, 0.0f, 0.1f), 0.0f, "dB", juce::AudioProcessorParameter::genericParameter, valueToTextFunction, textToValueFunction);


juce::NormalisableRange<float>(0.0f, 1.0f, 0.01f), 1.0f, "Gain", juce::AudioProcessorParameter::genericParameter, valueToTextFunction, textToValueFunction);
//filter stuff: feel free to mess around with cutoff params, i just used arbitrary bounds
auto highPassParam = std::make_unique<juce::AudioParameterFloat>("HIGH(Hz)", "High Cutoff",
juce::NormalisableRange<float>(100.0f,10000.0f, 4.0f), 1000.0f, "Hz", juce::AudioProcessorParameter::genericParameter, valueToTextFunction, textToValueFunction);
auto lowPassParam = std::make_unique<juce::AudioParameterFloat>("LOW(Hz)", "Low Cutoff",
juce::NormalisableRange<float>(20.0f, 2000.0f, 4.0f), 1000.0f, "Hz", juce::AudioProcessorParameter::genericParameter, valueToTextFunction, textToValueFunction);
juce::StringArray choices;
choices.add("Soft");
choices.add("Hard");
Expand All @@ -342,6 +376,8 @@ juce::AudioProcessorValueTreeState::ParameterLayout Distortion_ProjectAudioProce
params.push_back(std::move(clipParam));
params.push_back(std::move(typeParam));
params.push_back(std::move(clipParamNeg));
params.push_back(std::move(highPassParam));
params.push_back(std::move(lowPassParam));



Expand Down
11 changes: 8 additions & 3 deletions Distortion_Project/Source/PluginProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class Distortion_ProjectAudioProcessor : public juce::AudioProcessor,

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

void releaseResources() override;

#ifndef JucePlugin_PreferredChannelConfigurations
bool isBusesLayoutSupported (const BusesLayout& layouts) const override;
#endif
Expand Down Expand Up @@ -74,7 +74,6 @@ class Distortion_ProjectAudioProcessor : public juce::AudioProcessor,
void prepare(double sampleRate, int samplesPerBlock); // Pass sample rate/buffer size to DSP
void update(); // Update DSP when a user changes parameters
void reset() override; // Reset DSP parameters

juce::AudioProcessorValueTreeState apvts; //Create APVTS object to connect to editor
juce::AudioProcessorValueTreeState::ParameterLayout createParameters();
Visualiser visualiser;
Expand All @@ -87,7 +86,13 @@ class Distortion_ProjectAudioProcessor : public juce::AudioProcessor,
juce::LinearSmoothedValue<float> driveNormal { 0.0 };
juce::LinearSmoothedValue<float> clipNormal { 0.0 };
juce::LinearSmoothedValue<float> clipNeg{ 0.0 };

juce::SmoothedValue<float, juce::ValueSmoothingTypes::Multiplicative> hiPassCutoffFrequency{};
juce::SmoothedValue<float, juce::ValueSmoothingTypes::Multiplicative> lowPassCutoffFrequency{};
juce::dsp::StateVariableTPTFilter<float> highPass;

juce::dsp::StateVariableTPTFilter<float> lowPass;

//juce::dsp::ProcessSpec processSpec;
void valueTreePropertyChanged(juce::ValueTree &treeWhosePropertyHasChanged, const juce::Identifier &property) override
{
ignoreUnused(property);
Expand Down
Loading

0 comments on commit fb02c03

Please sign in to comment.