Selaa lähdekoodia

JUCE part fully implemented

LuigiBiasi-Athenagroup 6 kuukautta sitten
vanhempi
commit
b9e5210f8a

BIN
JUCE/CMLSProject.vst3


+ 1 - 1
JUCE/CMLSProject/Source/CMLSChorus.cpp

@@ -82,7 +82,7 @@ void CMLSChorus::setAmount(float value) {
     float depth = depthRange->convertFrom0to1(value);
 
     delayLine1.setRate(freq);
-    delayLine2.setRate(freq); //+ LFO_FREQ_DELTA
+    delayLine2.setRate(freq + LFO_FREQ_DELTA); //+ LFO_FREQ_DELTA
     delayLine1.setDepth(depth);
     delayLine2.setDepth(depth);
 }

+ 2 - 2
JUCE/CMLSProject/Source/CMLSChorus.h

@@ -14,10 +14,10 @@
 
 #define DELAY_CENTER 0.015 // Center for delay in seconds
 #define LFO_MIN_FREQ 0.0f // Minimum frequency of the LFO
-#define LFO_MAX_FREQ 5.0f // Maximum frequency of the LFO
+#define LFO_MAX_FREQ 3.0f // Maximum frequency of the LFO
 #define LFO_FREQ_DELTA 0.3f // Frequency delta between the two LFOs
 #define LFO_MIN_DEPTH 0.0f // Minimum depth of the LFO
-#define LFO_MAX_DEPTH 5.0f // Maximum depth of the LFO
+#define LFO_MAX_DEPTH 0.1f // Maximum depth of the LFO
 
 class CMLSChorus : public juce::dsp::ProcessorBase {
     public:

+ 10 - 2
JUCE/CMLSProject/Source/CMLSDelay.cpp

@@ -9,6 +9,7 @@
 */
 
 #include "CMLSDelay.h"
+#include <windows.h>
 
 CMLSDelay::CMLSDelay() {
 	//feedbackRange = new juce::NormalisableRange<float>(MIN_FEEDBACK, MAX_FEEDBACK);
@@ -29,7 +30,8 @@ void CMLSDelay::reset() {
 void CMLSDelay::prepare(const juce::dsp::ProcessSpec& spec) {
 	this->maximumDelaySamples = spec.sampleRate * MAX_DELAY_LENGTH;
 	this->delayRange = new juce::NormalisableRange<float>(0, this->maximumDelaySamples);
-	
+	this->delaySmoothing = new juce::SmoothedValue<float, juce::ValueSmoothingTypes::Linear>(this->delayLength);
+
 	this->delayLine.prepare(spec);
 	this->delayLine.setMaximumDelayInSamples(this->maximumDelaySamples);
 
@@ -52,11 +54,13 @@ void CMLSDelay::process(const juce::dsp::ProcessContextReplacing<float>& context
 			audioBlock.setSample(
 				channel,
 				i,
-				this->delayLine.popSample(channel, this->delayLength)
+				this->delayLine.popSample(channel, this->delayLine.getDelay())
 			);
 		}
 	}
 
+	this->lastDelayInSamples = this->delayLine.getDelay();
+
 	// Adding wet (elaborated) signal
 	this->mixer.mixWetSamples(audioBlock);
 }
@@ -68,6 +72,10 @@ void CMLSDelay::setDryWet(float value) {
 
 void CMLSDelay::setAmount(float value) {
 	this->delayLength = this->delayRange->convertFrom0to1(value);
+	this->delayLine.setDelay(this->delayLength);
+	std::string test = std::to_string(this->delayLength) + "\n";
+	OutputDebugString(test.c_str());
+	
 }
 
 const float CMLSDelay::getDryWet() {

+ 1 - 0
JUCE/CMLSProject/Source/CMLSDelay.h

@@ -51,4 +51,5 @@ class CMLSDelay : public juce::dsp::ProcessorBase
 		// Range converters
 		juce::NormalisableRange<float>* delayRange;
 		juce::SmoothedValue<float, juce::ValueSmoothingTypes::Linear>* delaySmoothing;
+		int lastDelayInSamples = 0;
 };

+ 27 - 22
JUCE/CMLSProject/Source/OSCReceiverWrapper.cpp

@@ -9,10 +9,12 @@
 */
 
 #include "OSCReceiverWrapper.h"
-#include <windows.h>
 
-OSCReceiverWrapper::OSCReceiverWrapper(int port, juce::AudioProcessor* pluginProcessor) {
-	this->pluginProcessor = (CMLSProjectAudioProcessor*)pluginProcessor;
+OSCReceiverWrapper::OSCReceiverWrapper(int port, juce::AudioProcessorValueTreeState* apvts) {
+	this->apvts = apvts;
+
+    this->eqGainRange = new juce::NormalisableRange<float>(MINEQBANDGAIN, MAXEQBANDGAIN);
+    this->distortionDriveRange = new juce::NormalisableRange<float>(MINDISTORTIONDRIVE, MAXDISTORTIONDRIVE);
 
     if (!this->connect(port)) {
         this->oscConnectionError();
@@ -41,18 +43,12 @@ OSCReceiverWrapper::OSCReceiverWrapper(int port, juce::AudioProcessor* pluginPro
     addListener(this, "/pressure");
     addListener(this, "/aspectX");
     addListener(this, "/aspectY");
-
-    std::string test = "Connection opened\n";
-    OutputDebugString(test.c_str());
 }
 
 OSCReceiverWrapper::~OSCReceiverWrapper() {}
 
 void OSCReceiverWrapper::oscMessageReceived(const juce::OSCMessage& message)
 {
-    std::string debugString = "=== OSC Message at address: " + message.getAddressPattern().toString().toStdString() + " ===\n";
-    OutputDebugString(debugString.c_str());
-    
     if (!message.isEmpty() && message.size() == 1) {
 	    auto address = message.getAddressPattern().toString();
         float argument = 0.0;
@@ -135,33 +131,42 @@ void OSCReceiverWrapper::oscConnectionError() {
 
 void OSCReceiverWrapper::processMessage() {
     if (this->currentPreset == Preset::PENCIL) {
-        this->pluginProcessor->setReverbRoomSize(this->aspectY + 0.5);
+        this->apvts->state.setProperty("REVERBROOMSIZE", this->aspectY + 0.5, nullptr);
     }
     else if (this->currentPreset == Preset::CRAYON) {
-        this->pluginProcessor->setDelayAmount(this->aspectX + 0.5);
-        this->pluginProcessor->setReverbDryWet(this->aspectY + 0.5);
+        this->apvts->state.setProperty("DELAYAMOUNT", this->aspectX + 0.5, nullptr);
+        this->apvts->state.setProperty("REVERBDRYWET", this->aspectY + 0.5, nullptr);
     }
     else if (this->currentPreset == Preset::WATERCOLOR) {
         // Changing parameters of single effects
         if (this->thickness <= 6) { //EQ
-            this->pluginProcessor->setEqLowGain(this->aspectX + 0.5);
-            this->pluginProcessor->setEqHighGain(this->aspectY + 0.5);
+            this->apvts->state.setProperty("EQLOWBANDGAIN",
+                this->eqGainRange->convertFrom0to1(this->aspectX + 0.5),
+                nullptr
+            );
+            this->apvts->state.setProperty("EQHIGHBANDGAIN",
+                this->eqGainRange->convertFrom0to1(this->aspectY + 0.5),
+                nullptr
+            );
         }
         else if (this->thickness <= 12) { // Dist
-            this->pluginProcessor->setDistortionDrive(this->aspectY + 0.5);
-            this->pluginProcessor->setDistortionMix(this->aspectX + 0.5);
+            this->apvts->state.setProperty("DISTORTIONMIX", this->aspectX + 0.5, nullptr);
+            this->apvts->state.setProperty("DISTORTIONDRIVE",
+                this->distortionDriveRange->convertFrom0to1(this->aspectY + 0.5),
+                nullptr
+            );
         }
         else if (this->thickness <= 18) { // Chorus
-            this->pluginProcessor->setChorusAmount(this->aspectY + 0.5);
-            this->pluginProcessor->setChorusDryWet(this->aspectX + 0.5);
+            this->apvts->state.setProperty("CHORUSDRYWET", this->aspectX + 0.5, nullptr);
+            this->apvts->state.setProperty("CHORUSAMOUNT", this->aspectY + 0.5, nullptr);
         }
         else if (this->thickness <= 24) { // Reverb
-            this->pluginProcessor->setReverbRoomSize(this->aspectY + 0.5);
-            this->pluginProcessor->setReverbDryWet(this->aspectX + 0.5);
+            this->apvts->state.setProperty("REVERBDRYWET", this->aspectX + 0.5, nullptr);
+            this->apvts->state.setProperty("REVERBROOMSIZE", this->aspectY + 0.5, nullptr);
         }
         else if (this->thickness <= 30) { //Delay
-            this->pluginProcessor->setDelayAmount(this->aspectY + 0.5);
-            this->pluginProcessor->setDelayDryWet(this->aspectX + 0.5);
+            this->apvts->state.setProperty("DELAYDRYWET", this->aspectX + 0.5, nullptr);
+            this->apvts->state.setProperty("DELAYAMOUNT", this->aspectY + 0.5, nullptr);
         }
     }
 }

+ 10 - 2
JUCE/CMLSProject/Source/OSCReceiverWrapper.h

@@ -12,6 +12,11 @@
 #include <JuceHeader.h>
 #include "PluginProcessor.h"
 
+#define MINEQBANDGAIN -60.0f
+#define MAXEQBANDGAIN 20.0f
+#define MINDISTORTIONDRIVE 1.0f
+#define MAXDISTORTIONDRIVE 15.0f
+
 enum Preset {
     NONE,
     PENCIL,
@@ -28,7 +33,7 @@ class OSCReceiverWrapper : public juce::Component,
                            private juce::OSCReceiver::ListenerWithOSCAddress<juce::OSCReceiver::MessageLoopCallback>
 {
     public:
-        OSCReceiverWrapper(int port, juce::AudioProcessor* pluginProcessor);
+        OSCReceiverWrapper(int port, juce::AudioProcessorValueTreeState* apvts);
         ~OSCReceiverWrapper();
 
 		void oscMessageReceived(const juce::OSCMessage& message) override;
@@ -44,5 +49,8 @@ class OSCReceiverWrapper : public juce::Component,
         float pressure;
         float thickness;
 
-        CMLSProjectAudioProcessor *pluginProcessor;
+        juce::AudioProcessorValueTreeState* apvts;
+        
+        juce::NormalisableRange<float>* eqGainRange;
+        juce::NormalisableRange<float>* distortionDriveRange;
 };

+ 2 - 157
JUCE/CMLSProject/Source/PluginEditor.cpp

@@ -14,96 +14,10 @@ CMLSProjectAudioProcessorEditor::CMLSProjectAudioProcessorEditor (CMLSProjectAud
     : AudioProcessorEditor (&p), audioProcessor (p)
 {
     // OSC receiver
-    this->oscReceiver = new OSCReceiverWrapper(57120, &p);
+    this->oscReceiver = new OSCReceiverWrapper(57121, p.getApvts());
 
     // Make sure that before the constructor has finished, you've set the
     // editor's size to whatever you need it to be.
-    setSize (400, 300);
-
-    // Add aliders to the editor (Equalizer)
-    this->equalizerLowGainSlider.setRange(0.0, 1.0);
-    this->equalizerLowGainSlider.setTextBoxStyle(juce::Slider::TextBoxRight, false, 100, 20);
-    this->equalizerLowGainSlider.addListener(this);
-    this->equalizerLowGainLabel.setText("Equalizer Low Gain", juce::dontSendNotification);
-
-    addAndMakeVisible(this->equalizerLowGainSlider);
-    addAndMakeVisible(this->equalizerLowGainLabel);
-
-    this->equalizerHighGainSlider.setRange(0.0, 1.0);
-    this->equalizerHighGainSlider.setTextBoxStyle(juce::Slider::TextBoxRight, false, 100, 20);
-    this->equalizerHighGainSlider.addListener(this);
-    this->equalizerHighGainLabel.setText("Equalizer High Gain", juce::dontSendNotification);
-
-    addAndMakeVisible(this->equalizerHighGainSlider);
-    addAndMakeVisible(this->equalizerHighGainLabel);
-
-    // Add aliders to the editor (Distortion)
-    this->distortionDriveSlider.setRange(0.0, 1.0);
-    this->distortionDriveSlider.setTextBoxStyle(juce::Slider::TextBoxRight, false, 100, 20);
-    this->distortionDriveSlider.addListener(this);
-    this->distortionDriveLabel.setText("Distortion Drive", juce::dontSendNotification);
-
-    addAndMakeVisible(this->distortionDriveSlider);
-    addAndMakeVisible(this->distortionDriveLabel);
-
-    this->distortionMixSlider.setRange(0.0, 1.0);
-    this->distortionMixSlider.setTextBoxStyle(juce::Slider::TextBoxRight, false, 100, 20);
-    this->distortionMixSlider.addListener(this);
-    this->distortionMixLabel.setText("Distortion Mix", juce::dontSendNotification);
-
-    addAndMakeVisible(this->distortionMixSlider);
-    addAndMakeVisible(this->distortionMixLabel);
-
-	// Add aliders to the editor (Chorus)
-    this->chorusDryWetSlider.setRange(0.0, 1.0);
-    this->chorusDryWetSlider.setTextBoxStyle(juce::Slider::TextBoxRight, false, 100, 20);
-    this->chorusDryWetSlider.addListener(this);
-    this->chorusDryWetLabel.setText("Chorus Dry/Wet", juce::dontSendNotification);
-
-    addAndMakeVisible(this->chorusDryWetSlider);
-    addAndMakeVisible(this->chorusDryWetLabel);
-
-    this->chorusAmountSlider.setRange(0.0, 1.0);
-    this->chorusAmountSlider.setTextBoxStyle(juce::Slider::TextBoxRight, false, 100, 20);
-    this->chorusAmountSlider.addListener(this);
-    this->chorusAmountLabel.setText("Chorus Amount", juce::dontSendNotification);
-
-    addAndMakeVisible(this->chorusAmountSlider);
-    addAndMakeVisible(this->chorusAmountLabel);
-
-    // Add sliders to the editor (Reverb)
-    this->reverbDryWetSlider.setRange(0.0, 1.0);
-    this->reverbDryWetSlider.setTextBoxStyle(juce::Slider::TextBoxRight, false, 100, 20);
-    this->reverbDryWetSlider.addListener(this);
-    this->reverbDryWetLabel.setText("Reverb Dry/Wet", juce::dontSendNotification);
-
-    addAndMakeVisible(this->reverbDryWetSlider);
-    addAndMakeVisible(this->reverbDryWetLabel);
-
-    this->reverbRoomSizeSlider.setRange(0.0, 1.0);
-    this->reverbRoomSizeSlider.setTextBoxStyle(juce::Slider::TextBoxRight, false, 100, 20);
-    this->reverbRoomSizeSlider.addListener(this);
-    this->reverbRoomSizeLabel.setText("Reverb Room Size", juce::dontSendNotification);
-
-    addAndMakeVisible(this->reverbRoomSizeSlider);
-    addAndMakeVisible(this->reverbRoomSizeLabel);
-
-	// Add sliders to the editor (Delay)
-    this->delayDryWetSlider.setRange(0.0, 1.0);
-    this->delayDryWetSlider.setTextBoxStyle(juce::Slider::TextBoxRight, false, 100, 20);
-    this->delayDryWetSlider.addListener(this);
-    this->delayDryWetLabel.setText("Delay Dry/Wet", juce::dontSendNotification);
-
-    addAndMakeVisible(this->delayDryWetSlider);
-    addAndMakeVisible(this->delayDryWetLabel);
-
-    this->delayAmountSlider.setRange(0.0, 1.0);
-    this->delayAmountSlider.setTextBoxStyle(juce::Slider::TextBoxRight, false, 100, 20);
-    this->delayAmountSlider.addListener(this);
-    this->delayAmountLabel.setText("Delay Amount", juce::dontSendNotification);
-
-    addAndMakeVisible(this->delayAmountSlider);
-    addAndMakeVisible(this->delayAmountLabel);
 }
 
 CMLSProjectAudioProcessorEditor::~CMLSProjectAudioProcessorEditor()
@@ -118,73 +32,4 @@ void CMLSProjectAudioProcessorEditor::paint (juce::Graphics& g)
 }
 
 void CMLSProjectAudioProcessorEditor::resized()
-{
-	//titleLabel.setBounds(10, 10, getWidth() - 20, 20);
-    equalizerLowGainSlider.setBounds(130, 10, getWidth() - 130, 20);
-    equalizerLowGainLabel.setBounds(10, 10, 100, 20);
-    equalizerHighGainSlider.setBounds(130, 30, getWidth() - 130, 20);
-    equalizerHighGainLabel.setBounds(10, 30, 100, 20);
-
-    distortionDriveSlider.setBounds(130, 70, getWidth() - 130, 20);
-    distortionDriveLabel.setBounds(10, 70, 100, 20);
-    distortionMixSlider.setBounds(130, 90, getWidth() - 130, 20);
-    distortionMixLabel.setBounds(10, 90, 100, 20);
-
-    chorusDryWetSlider.setBounds(130, 130, getWidth() - 130, 20);
-    chorusDryWetLabel.setBounds(10, 130, 100, 20);
-    chorusAmountSlider.setBounds(130, 150, getWidth() - 130, 20);
-	chorusAmountLabel.setBounds(10, 150, 100, 20);
-
-    reverbDryWetSlider.setBounds(130, 190, getWidth() - 130, 20);
-	reverbDryWetLabel.setBounds(10, 190, 100, 20);
-    reverbRoomSizeSlider.setBounds(130, 210, getWidth() - 130, 20);
-	reverbRoomSizeLabel.setBounds(10, 210, 100, 20);
-
-    delayDryWetSlider.setBounds(130, 250, getWidth() - 130, 20);
-	delayDryWetLabel.setBounds(10, 250, 100, 20);
-    delayAmountSlider.setBounds(130, 270, getWidth() - 130, 20);
-	delayAmountLabel.setBounds(10, 270, 100, 20);
-}
-
-void CMLSProjectAudioProcessorEditor::sliderValueChanged(juce::Slider* slider){
-	if (slider == &this->chorusDryWetSlider)
-	{
-		this->audioProcessor.setChorusDryWet(slider->getValue());
-	}
-	else if (slider == &this->chorusAmountSlider)
-	{
-		this->audioProcessor.setChorusAmount(slider->getValue());
-	}
-	else if (slider == &this->reverbDryWetSlider)
-	{
-		this->audioProcessor.setReverbDryWet(slider->getValue());
-	}
-	else if (slider == &this->reverbRoomSizeSlider)
-	{
-		this->audioProcessor.setReverbRoomSize(slider->getValue());
-	}
-	else if (slider == &this->delayDryWetSlider)
-	{
-		this->audioProcessor.setDelayDryWet(slider->getValue());
-	}
-	else if (slider == &this->delayAmountSlider)
-	{
-		this->audioProcessor.setDelayAmount(slider->getValue());
-	}
-    else if (slider == &this->equalizerLowGainSlider)
-    {
-        this->audioProcessor.setEqLowGain(slider->getValue());
-    }
-    else if (slider == &this->equalizerHighGainSlider)
-    {
-        this->audioProcessor.setEqHighGain(slider->getValue());
-    }
-    else if (slider == &this->distortionDriveSlider)
-    {
-        this->audioProcessor.setDistortionDrive(slider->getValue());
-    }
-    else if (slider == &this->distortionMixSlider)
-    {
-        this->audioProcessor.setDistortionMix(slider->getValue());
-    }
-}
+{}

+ 6 - 44
JUCE/CMLSProject/Source/PluginProcessor.cpp

@@ -218,46 +218,8 @@ void CMLSProjectAudioProcessor::swapEffectInSlot(int slot1, int slot2) {
 	this->processorChain.swapPlaces(slot1, slot2);
 }
 
-void CMLSProjectAudioProcessor::setEqLowGain(float value) {
-	((CMLSEqualizer*)this->equalizer)->setEqLowGain(value);
-}
-
-void CMLSProjectAudioProcessor::setEqHighGain(float value) {
-    ((CMLSEqualizer*)this->equalizer)->setEqHighGain(value);
-}
-
-void CMLSProjectAudioProcessor::setDistortionDrive(float value) {
-    ((CMLSDistortion*)this->distortion)->setDrive(value);
-}
-
-void CMLSProjectAudioProcessor::setDistortionMix(float value) {
-	((CMLSDistortion*)this->distortion)->setMix(value);
-}
-
-void CMLSProjectAudioProcessor::setChorusDryWet(float value) {
-    //auto& instance = this->processorChain.template get<0>();
-	//instance.setDryWet(value);
-	((CMLSChorus*)this->chorus)->setDryWet(value);
-}
-
-void CMLSProjectAudioProcessor::setChorusAmount(float value) {
-	((CMLSChorus*)this->chorus)->setAmount(value);
-}
-
-void CMLSProjectAudioProcessor::setReverbDryWet(float value) {
-    ((CMLSReverb*)this->reverb)->setDryWet(value);
-}
-
-void CMLSProjectAudioProcessor::setReverbRoomSize(float value) {
-	((CMLSReverb*)this->reverb)->setRoomSize(value);
-}
-
-void CMLSProjectAudioProcessor::setDelayDryWet(float value) {
-    ((CMLSDelay*)this->delay)->setDryWet(value);
-}
-
-void CMLSProjectAudioProcessor::setDelayAmount(float value) {
-    ((CMLSDelay*)this->delay)->setAmount(value);
+juce::AudioProcessorValueTreeState* CMLSProjectAudioProcessor::getApvts() {
+    return &this->apvts;
 }
 
 //==============================================================================
@@ -275,14 +237,14 @@ juce::AudioProcessorValueTreeState::ParameterLayout CMLSProjectAudioProcessor::c
         "EQLOWBANDGAIN",
         "EqLowBandGain",
         -60.0f,
-        5.0f,
+        20.0f,
         0.0f
     ));
     params.push_back(std::make_unique<juce::AudioParameterFloat>(
         "EQHIGHBANDGAIN",
         "EqHighBandGain",
         -60.0f,
-        5.0f,
+        20.0f,
         0.0f
     ));
 
@@ -290,9 +252,9 @@ juce::AudioProcessorValueTreeState::ParameterLayout CMLSProjectAudioProcessor::c
     params.push_back(std::make_unique<juce::AudioParameterFloat>(
         "DISTORTIONDRIVE",
         "DistortionDrive",
-        0.0f,
         1.0f,
-        0.0f
+        15.0f,
+        1.0f
     ));
     params.push_back(std::make_unique<juce::AudioParameterFloat>(
         "DISTORTIONMIX",

+ 1 - 16
JUCE/CMLSProject/Source/PluginProcessor.h

@@ -65,24 +65,9 @@ public:
     void unmuteEffectInSlot(int slot);
 	void swapEffectInSlot(int slot1, int slot2);
 
-    // Parameter controls
-    void setEqLowGain(float value);
-    void setEqHighGain(float value);
-
-    void setDistortionDrive(float value);
-    void setDistortionMix(float value);
-
-	void setChorusDryWet(float value);
-	void setChorusAmount(float value);
-
-	void setReverbDryWet(float value);
-	void setReverbRoomSize(float value);
-
-	void setDelayDryWet(float value);
-	void setDelayAmount(float value);
-
 	// Value Tree State for parameters
     juce::AudioProcessorValueTreeState apvts;
+    juce::AudioProcessorValueTreeState* getApvts();
 
 private:
     //==============================================================================

BIN
JUCE/VST3_Parameters.png