From ce7f583d4171cf42c3946455401da899f57a7759 Mon Sep 17 00:00:00 2001 From: Alberto Roletto <73691506+sadmemelord@users.noreply.github.com> Date: Thu, 2 Feb 2023 18:40:54 +0100 Subject: [PATCH] slider attachment and gui working --- QuasoCompressor.jucer | 4 +++ Source/GUI/Sliders/SliderProps.cpp | 27 ++++++++++++-- Source/Parameters/Parameters.cpp | 29 ++++++++++++++++ Source/Parameters/Parameters.h | 30 ++++++++++++++++ Source/PluginEditor.cpp | 2 +- Source/PluginEditor.h | 14 ++++++++ Source/PluginProcessor.cpp | 56 +++++++++++++++--------------- Source/PluginProcessor.h | 1 + 8 files changed, 131 insertions(+), 32 deletions(-) create mode 100644 Source/Parameters/Parameters.cpp create mode 100644 Source/Parameters/Parameters.h diff --git a/QuasoCompressor.jucer b/QuasoCompressor.jucer index 0141445..51a4a4a 100644 --- a/QuasoCompressor.jucer +++ b/QuasoCompressor.jucer @@ -5,6 +5,10 @@ companyName="sadmemelord"> + + + + diff --git a/Source/GUI/Sliders/SliderProps.cpp b/Source/GUI/Sliders/SliderProps.cpp index db9c58a..c36b9d6 100644 --- a/Source/GUI/Sliders/SliderProps.cpp +++ b/Source/GUI/Sliders/SliderProps.cpp @@ -16,20 +16,41 @@ void QuasoCompressorAudioProcessorEditor::setCommonSliderProps(juce::Slider& sli addAndMakeVisible(slider); slider.setSliderStyle(juce::Slider::SliderStyle::RotaryVerticalDrag); slider.setTextBoxStyle(juce::Slider::TextBoxBelow, false, 72, 36); + + //setting colours based on the custom look and feel slider.setColour(juce::Slider::ColourIds::textBoxOutlineColourId, juce::Colours::transparentBlack); - slider.setColour(juce::Slider::ColourIds::trackColourId, juce::Colours::whitesmoke.darker(0.75)); - slider.setColour(juce::Slider::ColourIds::rotarySliderOutlineColourId, + slider.setColour(juce::Slider::ColourIds::trackColourId, slider.findColour(juce::Slider::ColourIds::rotarySliderOutlineColourId).brighter(0.2)); + slider.setColour(juce::Slider::ColourIds::rotarySliderFillColourId, juce::Colours::whitesmoke.darker(1)); + slider.setColour(juce::Slider::ColourIds::rotarySliderOutlineColourId, + slider.findColour(juce::Slider::ColourIds::rotarySliderOutlineColourId).brighter(0.15)); + slider.setColour(juce::Slider::ColourIds::thumbColourId, juce::Colours::cornflowerblue.darker(0.3)); + slider.setLookAndFeel(&customDialLAF); + //setting shadow properties based on the juce::shadowdrop shadowProperties.radius = 25; shadowProperties.offset = juce::Point(0,0); - shadowProperties.colour = juce::Colours::black.brighter(0.1); + shadowProperties.colour = juce::Colours::black.brighter(0.05); dialShadow.setShadowProperties(shadowProperties); slider.setComponentEffect(&dialShadow); } +void QuasoCompressorAudioProcessorEditor::attachSliders() +{ + //method to attach dials to apvts + using SliderAttachment = juce::AudioProcessorValueTreeState::SliderAttachment; + + inputAttach = std::make_unique(audioProcessor.apvts, inputID, inputDial); + threshAttach = std::make_unique(audioProcessor.apvts, threshID, threshDial); + ratioAttach = std::make_unique(audioProcessor.apvts, ratioID, ratioDial); + attackAttach = std::make_unique(audioProcessor.apvts, attackID, attackDial); + releaseAttach = std::make_unique(audioProcessor.apvts, releaseID, releaseDial); + outputAttach = std::make_unique(audioProcessor.apvts, outputID, outputDial); + +} + void QuasoCompressorAudioProcessorEditor::setCommonLabelProps(juce::Label& label) { //setting properties common to every slider diff --git a/Source/Parameters/Parameters.cpp b/Source/Parameters/Parameters.cpp new file mode 100644 index 0000000..27a8cf4 --- /dev/null +++ b/Source/Parameters/Parameters.cpp @@ -0,0 +1,29 @@ +/* + ============================================================================== + + Parameters.cpp + Created: 2 Feb 2023 4:48:43pm + Author: Utente + + ============================================================================== +*/ + +#include "Parameters.h" + +const juce::String inputID = "input"; +const juce::String inputName = "Input"; + +const juce::String threshID = "thresh"; +const juce::String threshName = "Thresh"; + +const juce::String ratioID = "ratio"; +const juce::String ratioName = "Ratio"; + +const juce::String attackID = "attack"; +const juce::String attackName = "Attack"; + +const juce::String releaseID = "release"; +const juce::String releaseName = "Release"; + +const juce::String outputID = "output"; +const juce::String outputName = "Output"; \ No newline at end of file diff --git a/Source/Parameters/Parameters.h b/Source/Parameters/Parameters.h new file mode 100644 index 0000000..e47ffe9 --- /dev/null +++ b/Source/Parameters/Parameters.h @@ -0,0 +1,30 @@ +/* + ============================================================================== + + Parameters.h + Created: 2 Feb 2023 4:48:43pm + Author: Utente + + ============================================================================== +*/ + +#pragma once +#include + +extern const juce::String inputID; +extern const juce::String inputName; + +extern const juce::String threshID; +extern const juce::String threshName; + +extern const juce::String ratioID; +extern const juce::String ratioName; + +extern const juce::String attackID; +extern const juce::String attackName; + +extern const juce::String releaseID; +extern const juce::String releaseName; + +extern const juce::String outputID; +extern const juce::String outputName; diff --git a/Source/PluginEditor.cpp b/Source/PluginEditor.cpp index 42574de..70b4900 100644 --- a/Source/PluginEditor.cpp +++ b/Source/PluginEditor.cpp @@ -30,7 +30,7 @@ QuasoCompressorAudioProcessorEditor::QuasoCompressorAudioProcessorEditor (QuasoC dialLabels[i]->attachToComponent(dials[i], false); } - + attachSliders(); setSize(1000, 500); diff --git a/Source/PluginEditor.h b/Source/PluginEditor.h index fabcb52..cf80cef 100644 --- a/Source/PluginEditor.h +++ b/Source/PluginEditor.h @@ -77,6 +77,20 @@ class QuasoCompressorAudioProcessorEditor : public juce::AudioProcessorEditor void setCommonSliderProps(juce::Slider& slider); void setCommonLabelProps(juce::Label& label); + //setting up attachment + using Attachment = std::unique_ptr; + + Attachment inputAttach; + Attachment threshAttach; + Attachment ratioAttach; + Attachment attackAttach; + Attachment releaseAttach; + Attachment outputAttach; + + //method to attach sliders to the apvts + void attachSliders(); + + diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index f01e736..a75b9a8 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -27,23 +27,23 @@ QuasoCompressorAudioProcessor::QuasoCompressorAudioProcessor() { //every paramaters needs a listener inside the constructor of the main AudioProcessor class //everything the listener receives a changes from its parameter ID the parameterChanged method is called - apvts.addParameterListener("input", this); - apvts.addParameterListener("thresh", this); - apvts.addParameterListener("ratio", this); - apvts.addParameterListener("attack", this); - apvts.addParameterListener("release", this); - apvts.addParameterListener("output", this); + apvts.addParameterListener(inputID, this); + apvts.addParameterListener(threshID, this); + apvts.addParameterListener(ratioID, this); + apvts.addParameterListener(attackID, this); + apvts.addParameterListener(releaseID, this); + apvts.addParameterListener(outputID, this); } QuasoCompressorAudioProcessor::~QuasoCompressorAudioProcessor() { //the listener for each parameter has to be removed in the destructor - apvts.removeParameterListener("input", this); - apvts.removeParameterListener("thresh", this); - apvts.removeParameterListener("ratio", this); - apvts.removeParameterListener("attack", this); - apvts.removeParameterListener("release", this); - apvts.removeParameterListener("output", this); + apvts.removeParameterListener(inputID, this); + apvts.removeParameterListener(threshID, this); + apvts.removeParameterListener(ratioID, this); + apvts.removeParameterListener(attackID, this); + apvts.removeParameterListener(releaseID, this); + apvts.removeParameterListener(outputID, this); } @@ -57,22 +57,22 @@ juce::AudioProcessorValueTreeState::ParameterLayout QuasoCompressorAudioProcesso juce::NormalisableRange attackRange = juce::NormalisableRange(0.0f, 200.0f, 1.0f); attackRange.setSkewForCentre(50.0f); - juce::NormalisableRange releaseRange = juce::NormalisableRange(0.0f, 5000.0f, 1.0f); + juce::NormalisableRange releaseRange = juce::NormalisableRange( 5.0f, 5000.0f, 1.0f); releaseRange.setSkewForCentre(160.0f); //parameters are created - auto pInput = std::make_unique("input", "Input", -60.0f, 24.0f, 0.0f); - auto pThresh = std::make_unique("thresh", "Threshold", -60.0f, 10.0f, 0.0f); - auto pRatio = std::make_unique("ratio", "Ratio", 1.0f, 20.0f, 1.0f); - auto pAttack = std::make_unique("attack", "Attack", attackRange, 50.0f); - auto pRelease = std::make_unique("release", "Release", releaseRange, 160.0f); - auto pOutput = std::make_unique("output", "Output", -60.0f, 24.0f, 0.0f); + auto pInput = std::make_unique(inputID, inputName, -60.0f, 24.0f, 0.0f); + auto pThresh = std::make_unique(threshID, threshName, -60.0f, 10.0f, 0.0f); + auto pRatio = std::make_unique(ratioID, ratioName, 1.0f, 20.0f, 1.0f); + auto pAttack = std::make_unique(attackID, attackName, attackRange, 50.0f); + auto pRelease = std::make_unique(releaseID, releaseName, releaseRange, 160.0f); + auto pOutput = std::make_unique(outputID, outputName, -60.0f, 24.0f, 0.0f); //different type of parameters like floats or selection are pushed into the params vector params.push_back(std::move(pInput)); params.push_back(std::move(pThresh)); params.push_back(std::move(pRatio)); - params.push_back(std::move(pAttack)); + params.push_back(std::move(pAttack)); params.push_back(std::move(pRelease)); params.push_back(std::move(pOutput)); @@ -90,12 +90,12 @@ void QuasoCompressorAudioProcessor::parameterChanged(const juce::String& paramet void QuasoCompressorAudioProcessor::updateParameters() { //the load method is needed because the raw parameters are atomic - inputModule.setGainDecibels(apvts.getRawParameterValue("input")->load()); - compressorModule.setThreshold(apvts.getRawParameterValue("thresh")->load()); - compressorModule.setRatio(apvts.getRawParameterValue("ratio")->load()); - compressorModule.setAttack(apvts.getRawParameterValue("attack")->load()); - compressorModule.setRelease(apvts.getRawParameterValue("release")->load()); - outputModule.setGainDecibels(apvts.getRawParameterValue("output")->load()); + inputModule.setGainDecibels(apvts.getRawParameterValue(inputID)->load()); + compressorModule.setThreshold(apvts.getRawParameterValue(threshID)->load()); + compressorModule.setRatio(apvts.getRawParameterValue(ratioID)->load()); + compressorModule.setAttack(apvts.getRawParameterValue(attackID)->load()); + compressorModule.setRelease(apvts.getRawParameterValue(releaseID)->load()); + outputModule.setGainDecibels(apvts.getRawParameterValue(outputID)->load()); } @@ -175,8 +175,8 @@ void QuasoCompressorAudioProcessor::prepareToPlay (double sampleRate, int sample //prepare dsp modules for processing inputModule.prepare(spec); inputModule.setRampDurationSeconds(0.02); + outputModule.setRampDurationSeconds(0.02); outputModule.prepare(spec); - outputModule.setRampDurationSeconds(0.02); compressorModule.prepare(spec); updateParameters(); @@ -220,7 +220,7 @@ void QuasoCompressorAudioProcessor::processBlock (juce::AudioBuffer& buff auto totalNumInputChannels = getTotalNumInputChannels(); auto totalNumOutputChannels = getTotalNumOutputChannels(); - juce::dsp::AudioBlock block(buffer); + juce::dsp::AudioBlock block{ buffer }; //process DSP modules inputModule.process(juce::dsp::ProcessContextReplacing(block)); diff --git a/Source/PluginProcessor.h b/Source/PluginProcessor.h index 5e543e5..984af8a 100644 --- a/Source/PluginProcessor.h +++ b/Source/PluginProcessor.h @@ -9,6 +9,7 @@ #pragma once #include +#include "./Parameters/Parameters.h" //============================================================================== /**