Skip to content

Commit

Permalink
Merge branch 'interim_presentation' into 'master'
Browse files Browse the repository at this point in the history
Interim presentation

See merge request komplexpraktika/audio/FXPlugIn-Dynamics-SoSe20!3
  • Loading branch information
cornzz committed May 27, 2020
2 parents 58ee9b8 + 0bf1957 commit b7ea9aa
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 74 deletions.
128 changes: 61 additions & 67 deletions Source/PluginEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,35 +53,35 @@ Level1Editor::Level1Editor(Ckpa_compressorAudioProcessor& p) : processor(p)

//======================================

else if (processor.parameters.parameterTypes[i] == "ToggleButton") {
ToggleButton* aButton;
toggles.add(aButton = new ToggleButton());
aButton->setToggleState(parameter->getDefaultValue(), dontSendNotification);
//else if (processor.parameters.parameterTypes[i] == "ToggleButton") {
// ToggleButton* aButton;
// toggles.add(aButton = new ToggleButton());
// aButton->setToggleState(parameter->getDefaultValue(), dontSendNotification);

ButtonAttachment* aButtonAttachment;
buttonAttachments.add(aButtonAttachment =
new ButtonAttachment(processor.parameters.valueTreeState, parameter->paramID, *aButton));
// ButtonAttachment* aButtonAttachment;
// buttonAttachments.add(aButtonAttachment =
// new ButtonAttachment(processor.parameters.valueTreeState, parameter->paramID, *aButton));

components.add(aButton);
editorHeight += buttonHeight;
}
// components.add(aButton);
// editorHeight += buttonHeight;
//}

//======================================
////======================================

else if (processor.parameters.parameterTypes[i] == "ComboBox") {
ComboBox* aComboBox;
comboBoxes.add(aComboBox = new ComboBox());
aComboBox->setEditableText(false);
aComboBox->setJustificationType(Justification::left);
aComboBox->addItemList(processor.parameters.comboBoxItemLists[comboBoxCounter++], 1);
//else if (processor.parameters.parameterTypes[i] == "ComboBox") {
// ComboBox* aComboBox;
// comboBoxes.add(aComboBox = new ComboBox());
// aComboBox->setEditableText(false);
// aComboBox->setJustificationType(Justification::left);
// aComboBox->addItemList(processor.parameters.comboBoxItemLists[comboBoxCounter++], 1);

ComboBoxAttachment* aComboBoxAttachment;
comboBoxAttachments.add(aComboBoxAttachment =
new ComboBoxAttachment(processor.parameters.valueTreeState, parameter->paramID, *aComboBox));
// ComboBoxAttachment* aComboBoxAttachment;
// comboBoxAttachments.add(aComboBoxAttachment =
// new ComboBoxAttachment(processor.parameters.valueTreeState, parameter->paramID, *aComboBox));

components.add(aComboBox);
editorHeight += comboBoxHeight;
}
// components.add(aComboBox);
// editorHeight += comboBoxHeight;
//}

//======================================

Expand All @@ -105,7 +105,7 @@ Level1Editor::Level1Editor(Ckpa_compressorAudioProcessor& p) : processor(p)
//======================================
//Levelmeter for input
inputMeter.setLookAndFeel (&lnf);
inputMeter.setMeterSource (&processor.getMeterSource());
inputMeter.setMeterSource (&processor.meterSourceInput);
inputMeter.setSelectedChannel(0);
components.add(&inputMeter);
addAndMakeVisible(inputMeter);
Expand All @@ -117,7 +117,7 @@ Level1Editor::Level1Editor(Ckpa_compressorAudioProcessor& p) : processor(p)

// Levelmeter for output
outputMeter.setLookAndFeel(&lnf);
outputMeter.setMeterSource(&processor.getMeterSource());
outputMeter.setMeterSource(&processor.meterSourceOutput);
outputMeter.setSelectedChannel(0);
components.add(&outputMeter);
addAndMakeVisible(outputMeter);
Expand All @@ -129,7 +129,7 @@ Level1Editor::Level1Editor(Ckpa_compressorAudioProcessor& p) : processor(p)

// Levelmeter for gain reduction
gainReductionMeter.setLookAndFeel(&lnf);
gainReductionMeter.setMeterSource(&processor.getMeterSource());
gainReductionMeter.setMeterSource(&processor.meterSourceGainReduction);
gainReductionMeter.setSelectedChannel(0);
components.add(&gainReductionMeter);
addAndMakeVisible(gainReductionMeter);
Expand Down Expand Up @@ -164,15 +164,15 @@ void Level1Editor::resized()
if (Slider* aSlider = dynamic_cast<Slider*> (components[i]))
components[i]->setBounds(r.removeFromTop(sliderHeight));

if (ToggleButton* aButton = dynamic_cast<ToggleButton*> (components[i]))
components[i]->setBounds(r.removeFromTop(buttonHeight));
//if (ToggleButton* aButton = dynamic_cast<ToggleButton*> (components[i]))
// components[i]->setBounds(r.removeFromTop(buttonHeight));

if (ComboBox* aComboBox = dynamic_cast<ComboBox*> (components[i]))
components[i]->setBounds(r.removeFromTop(comboBoxHeight));

if (foleys::LevelMeter* aLevelMeter = dynamic_cast<foleys::LevelMeter*> (components[i]))
{
if (i + 1 == components.size())
if (i + 2 != components.size())
r.removeFromTop(levelMeterHeight);
components[i]->setBounds(r.removeFromTop(levelMeterHeight));
}
Expand All @@ -191,40 +191,25 @@ Level2Editor::Level2Editor(Ckpa_compressorAudioProcessor& p) : processor(p)

const Array<AudioProcessorParameter*> parameters = processor.getParameters();
auto* dhl = new DraggableHorizontalLine(); // TODO: This is leaking

Slider* thresholdLine;
controlLines.add(thresholdLine = new Slider());
thresholdLine->setSliderStyle(Slider::LinearVertical);
thresholdLine->setTextBoxStyle(Slider::NoTextBox, true, 0, 0);
thresholdLine->setLookAndFeel(dhl);
const AudioProcessorParameterWithID* thresholdParamter = dynamic_cast<AudioProcessorParameterWithID*> (parameters[0]);
SliderAttachment* thresholdSliderAttachment;
sliderAttachments.add(thresholdSliderAttachment = new SliderAttachment(processor.parameters.valueTreeState, thresholdParamter->paramID, *thresholdLine));
addAndMakeVisible(thresholdLine);

Slider* makeupGainLine;
controlLines.add(makeupGainLine = new Slider());
makeupGainLine->setSliderStyle(Slider::LinearVertical);
makeupGainLine->setTextBoxStyle(Slider::NoTextBox, true, 0, 0);
makeupGainLine->setLookAndFeel(dhl);
const AudioProcessorParameterWithID* makeupGainParameter = dynamic_cast<AudioProcessorParameterWithID*> (parameters[4]);
SliderAttachment* makeupGainSliderAttachment;
sliderAttachments.add(makeupGainSliderAttachment = new SliderAttachment(processor.parameters.valueTreeState, makeupGainParameter->paramID, *makeupGainLine));
addAndMakeVisible(makeupGainLine);

Slider* ratioLine;
controlLines.add(ratioLine = new Slider());
ratioLine->setSliderStyle(Slider::LinearVertical);
ratioLine->setTextBoxStyle(Slider::NoTextBox, true, 0, 0);
ratioLine->setLookAndFeel(dhl);
const AudioProcessorParameterWithID* ratioParamter = dynamic_cast<AudioProcessorParameterWithID*> (parameters[1]);
SliderAttachment* ratioSliderAttachment;
sliderAttachments.add(ratioSliderAttachment = new SliderAttachment(processor.parameters.valueTreeState, ratioParamter->paramID, *ratioLine));
addAndMakeVisible(ratioLine);
int ind[] = { 0, 4, 1 };
for (int i : ind)
{
Slider* controlLine;
controlLines.add(controlLine = new Slider());
controlLine->setSliderStyle(Slider::LinearVertical);
controlLine->setTextBoxStyle(Slider::NoTextBox, true, 0, 0);
controlLine->setLookAndFeel(dhl);
if (i == 4 || i == 1)
controlLine->setColour(Slider::thumbColourId, (i == 4) ? Colour(0xFF2E8B00) : Colour(0xFFCB8035));
const AudioProcessorParameterWithID* controlLineParamter = dynamic_cast<AudioProcessorParameterWithID*> (parameters[i]);
SliderAttachment* controlLineSliderAttachment;
sliderAttachments.add(controlLineSliderAttachment = new SliderAttachment(processor.parameters.valueTreeState, controlLineParamter->paramID, *controlLine));
addAndMakeVisible(controlLine);
}

//======================================

setSize(editorWidth, 500);
setSize(editorWidth, 400); // TODO: unnecessary?
}

Level2Editor::~Level2Editor()
Expand All @@ -245,7 +230,7 @@ void Level2Editor::resized()
controlLines[0]->setBounds(rVis.removeFromLeft(20).removeFromTop(rVis.getHeight() / 2)); // Threshold

rVis = getLocalBounds().reduced(editorMargin);
controlLines[1]->setBounds(rVis.removeFromRight(20).removeFromTop(rVis.getHeight() / 2)); // Makeup Gain
controlLines[1]->setBounds(rVis.removeFromRight(20).removeFromTop(rVis.getHeight() * 0.75).withTrimmedTop(rVis.getHeight() * 0.25)); // Makeup Gain

rVis = getLocalBounds().reduced(editorMargin);
controlLines[2]->setBounds(rVis.removeFromLeft(rVis.getHeight() / 2 + 10).removeFromRight(20).removeFromTop(rVis.getHeight() / 2)); // Ratio
Expand All @@ -257,23 +242,31 @@ void Level2Editor::resized()
Ckpa_compressorAudioProcessorEditor::Ckpa_compressorAudioProcessorEditor(Ckpa_compressorAudioProcessor& p)
: AudioProcessorEditor(&p),
processor(p),
tabs(p),
powerButton("powerButton", DrawableButton::ImageFitted)
tabs(p)
{
addAndMakeVisible(tabs);
setSize(editorWidth, 400);
setSize(editorWidth, 375);

//======================================
const Array<AudioProcessorParameter*> parameters = processor.getParameters();

DrawableButton* powerButton;
buttons.add(powerButton = new DrawableButton("powerButton", DrawableButton::ImageFitted));
std::unique_ptr<Drawable> d = Drawable::createFromSVG(*XmlDocument::parse(powerButtonSVG));
std::unique_ptr<Drawable> normal = d->createCopy();
normal->replaceColour(Colours::black, getLookAndFeel().findColour(Slider::thumbColourId));
std::unique_ptr<Drawable> over = d->createCopy();
over->replaceColour(Colours::black, getLookAndFeel().findColour(Slider::thumbColourId).brighter(0.15));
std::unique_ptr<Drawable> down = d->createCopy();
down->replaceColour(Colours::black, getLookAndFeel().findColour(Slider::thumbColourId).darker(0.15));
powerButton.setImages(normal.get(), over.get(), down.get(), d.get());
buttons[0]->setImages(normal.get(), over.get(), down.get(), d.get());
const AudioProcessorParameterWithID* buttonParameter = dynamic_cast<AudioProcessorParameterWithID*> (parameters[5]);
ButtonAttachment* powerButtonAttachment;
buttonAttachments.add(powerButtonAttachment = new ButtonAttachment(processor.parameters.valueTreeState, buttonParameter->paramID, *powerButton));
addAndMakeVisible(powerButton);
powerButton->setClickingTogglesState(true);
Rectangle<int> r = getLocalBounds();
powerButton->setBounds(r.removeFromBottom(30).removeFromRight(30));
}

Ckpa_compressorAudioProcessorEditor::~Ckpa_compressorAudioProcessorEditor()
Expand All @@ -287,6 +280,7 @@ void Ckpa_compressorAudioProcessorEditor::paint(Graphics& g)

void Ckpa_compressorAudioProcessorEditor::resized()
{
tabs.setBounds(getLocalBounds());
powerButton.setBounds(getLocalBounds().removeFromBottom(30).removeFromRight(30));
Rectangle<int> r = getLocalBounds();
tabs.setBounds(r);
//buttons[0]->setBounds(r.removeFromBottom(30).removeFromRight(30));
}
8 changes: 7 additions & 1 deletion Source/PluginEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,20 +130,26 @@ class Ckpa_compressorAudioProcessorEditor : public AudioProcessorEditor
//==============================================================================
void paint (Graphics&) override;
void resized() override;


private:
// This reference is provided as a quick way for your editor to
// access the processor object that created it.
Ckpa_compressorAudioProcessor& processor;

OwnedArray<DrawableButton> buttons;

typedef AudioProcessorValueTreeState::ButtonAttachment ButtonAttachment;

OwnedArray<ButtonAttachment> buttonAttachments;

enum {
editorWidth = 500,
editorMargin = 10,
editorPadding = 10,
};

std::string powerButtonSVG = "<svg xmlns='http://www.w3.org/2000/svg' height='24' viewBox='0 0 24 24' width='24'><path d='M0 0h24v24H0z' fill='none'/><path d='M13 3h-2v10h2V3zm4.83 2.17l-1.42 1.42C17.99 7.86 19 9.81 19 12c0 3.87-3.13 7-7 7s-7-3.13-7-7c0-2.19 1.01-4.14 2.58-5.42L6.17 5.17C4.23 6.82 3 9.26 3 12c0 4.97 4.03 9 9 9s9-4.03 9-9c0-2.74-1.23-5.18-3.17-6.83z'/></svg>";
DrawableButton powerButton;

MainTabbedComponent tabs;

Expand Down
24 changes: 20 additions & 4 deletions Source/PluginProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Ckpa_compressorAudioProcessor::Ckpa_compressorAudioProcessor()
, paramAttack(parameters, "Attack", "ms", 0.1f, 100.0f, 2.0f, [](float value) { return value * 0.001f; })
, paramRelease(parameters, "Release", "ms", 10.0f, 1000.0f, 300.0f, [](float value) { return value * 0.001f; })
, paramMakeupGain(parameters, "Makeup gain", "dB", -12.0f, 12.0f, 0.0f)
, paramBypass(parameters, "Bypass")
, paramBypass(parameters, "")
{
parameters.valueTreeState.state = ValueTree(Identifier(getName().removeCharacters("- ")));
}
Expand Down Expand Up @@ -87,8 +87,13 @@ void Ckpa_compressorAudioProcessor::processBlock (AudioBuffer<float>& buffer, Mi
const int numInputChannels = getTotalNumInputChannels();
const int numOutputChannels = getTotalNumOutputChannels();
const int numSamples = buffer.getNumSamples();

// Create copy of buffer before compression
AudioBuffer<float> bufferBefore;
bufferBefore.makeCopyOf(buffer);

AudioBuffer<float> bufferGainReduction;
bufferGainReduction.makeCopyOf(buffer);

// Don't compress if bypass activated
if (!(bool)paramBypass.getTargetValue()) {
Expand Down Expand Up @@ -129,14 +134,25 @@ void Ckpa_compressorAudioProcessor::processBlock (AudioBuffer<float>& buffer, Mi
ylPrev = yl;

for (int channel = 0; channel < numInputChannels; ++channel) {
float newValue = buffer.getSample(channel, sample) * control;
float oldValue = buffer.getSample(channel, sample);
float newValue = oldValue * control;
buffer.setSample(channel, sample, newValue);
bufferGainReduction.setSample(channel, sample, oldValue - newValue);
}
}
}
else {
for (int sample = 0; sample < numSamples; ++sample) {
for (int channel = 0; channel < numInputChannels; ++channel) {
bufferGainReduction.setSample(channel, sample, 0);
}
}
}

// Push signal to level meter buffer
meterSource.measureBlock(buffer);
// Push signal to level metersources
meterSourceInput.measureBlock(bufferBefore);
meterSourceOutput.measureBlock(buffer);
meterSourceGainReduction.measureBlock(bufferGainReduction);

// Push signal to visualiser buffer
visualiser.pushBuffer(bufferBefore, buffer);
Expand Down
6 changes: 4 additions & 2 deletions Source/PluginProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class Ckpa_compressorAudioProcessor : public AudioProcessor
#endif

void processBlock (AudioBuffer<float>&, MidiBuffer&) override;
foleys::LevelMeterSource& getMeterSource() { return meterSource; }

//==============================================================================
AudioProcessorEditor* createEditor() override;
Expand Down Expand Up @@ -99,12 +98,15 @@ class Ckpa_compressorAudioProcessor : public AudioProcessor
PluginParameterLinSlider paramMakeupGain;
PluginParameterToggle paramBypass;

foleys::LevelMeterSource meterSourceInput;
foleys::LevelMeterSource meterSourceOutput;
foleys::LevelMeterSource meterSourceGainReduction;

//====================================== Level 2

Visualiser visualiser;

private:
foleys::LevelMeterSource meterSource;

//==============================================================================

Expand Down

0 comments on commit b7ea9aa

Please sign in to comment.