Skip to content

Commit

Permalink
processAudioBypassed added and levelVisualizer changed to unique_ptr
Browse files Browse the repository at this point in the history
  • Loading branch information
RachelMaryamLocke committed Jul 19, 2023
1 parent 56328de commit c5f3bc5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 27 deletions.
57 changes: 34 additions & 23 deletions src/processors/other/LevelDetective.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#include "LevelDetective.h"
#include "../ParameterHelpers.h"

LevelDetective::LevelDetective (UndoManager* um) : BaseProcessor (
"Level Detective",
createParameterLayout(),
InputPort {},
OutputPort {},
um,
LevelDetective::LevelDetective (UndoManager* um) : BaseProcessor ("Level Detective",
createParameterLayout(),
InputPort {},
OutputPort {},
um,
[] (InputPort port)
{
return PortType::audio;
Expand All @@ -16,12 +15,12 @@ LevelDetective::LevelDetective (UndoManager* um) : BaseProcessor (
return PortType::level;
})
{
levelVisualizer = std::make_unique<LevelDetectorVisualizer>();
using namespace ParameterHelpers;
// loadParameterPointer (attackMsParam, vts, "attack");
// loadParameterPointer (releaseMsParam, vts, "release");

uiOptions.backgroundColour = Colours::teal.darker (0.1f);
uiOptions.powerColour = Colours::gold.darker (0.1f);
// loadParameterPointer (attackMsParam, vts, "attack");
// loadParameterPointer (releaseMsParam, vts, "release");
uiOptions.backgroundColour = Colours::teal.darker(0.1f);
uiOptions.powerColour = Colours::gold.darker(0.1f);
uiOptions.info.description = "A simple envelope follower";
uiOptions.info.authors = StringArray { "Rachel Locke" };
}
Expand All @@ -31,8 +30,8 @@ ParamLayout LevelDetective::createParameterLayout()
using namespace ParameterHelpers;
auto params = createBaseParams();

// createTimeMsParameter (params, "attack", "Attack", createNormalisableRange (1.0f, 100.0f, 10.0f), 10.0f);
// createTimeMsParameter (params, "release", "Release", createNormalisableRange (10.0f, 1000.0f, 100.0f), 400.0f);
// createTimeMsParameter (params, "attack", "Attack", createNormalisableRange (1.0f, 100.0f, 10.0f), 10.0f);
// createTimeMsParameter (params, "release", "Release", createNormalisableRange (10.0f, 1000.0f, 100.0f), 400.0f);

return { params.begin(), params.end() };
}
Expand All @@ -43,25 +42,26 @@ void LevelDetective::prepare (double sampleRate, int samplesPerBlock)
levelOutBuffer.setSize (1, samplesPerBlock);
level.prepare ({ sampleRate, (uint32) samplesPerBlock, 1 });

levelVisualizer.setBufferSize (int (levelVisualizer.secondsToVisualize * sampleRate / (double) samplesPerBlock));
levelVisualizer.setSamplesPerBlock (samplesPerBlock);
levelVisualizer->setBufferSize (int (levelVisualizer->secondsToVisualize * sampleRate / (double) samplesPerBlock));
levelVisualizer->setSamplesPerBlock (samplesPerBlock);
}

void LevelDetective::processAudio (AudioBuffer<float>& buffer)
{
const auto numSamples = buffer.getNumSamples();
levelOutBuffer.setSize (1, numSamples, false, false, true);
//if audio input connected, extract level from input signal and assign to levelOutBuffer
if (inputsConnected.contains (AudioInput))
{
//create span to fill audio visualiser buffer
nonstd::span<const float> audioChannelData = { buffer.getReadPointer (0), (size_t) buffer.getNumSamples() };
levelVisualizer.pushChannel (0, audioChannelData);
// level.setParameters(*attackMsParam, *releaseMsParam);

nonstd::span<const float> audioChannelData = {buffer.getReadPointer(0), (size_t)numSamples};
levelVisualizer->pushChannel (0, audioChannelData);
// level.setParameters(*attackMsParam, *releaseMsParam);
level.processBlock (buffer, levelOutBuffer);

//create span to fill audio visualiser buffer
nonstd::span<const float> levelChannelData = { levelOutBuffer.getReadPointer (0), (size_t) levelOutBuffer.getNumSamples() };
levelVisualizer.pushChannel (1, levelChannelData);
//create span to fill level visualiser buffer
nonstd::span<const float> levelChannelData = {levelOutBuffer.getReadPointer(0), (size_t)numSamples};
levelVisualizer->pushChannel(1, levelChannelData);
}
else
{
Expand All @@ -71,6 +71,17 @@ void LevelDetective::processAudio (AudioBuffer<float>& buffer)
outputBuffers.getReference (LevelOutput) = &levelOutBuffer;
}

void LevelDetective::processAudioBypassed (AudioBuffer<float>& buffer)
{
const auto numSamples = buffer.getNumSamples();
levelOutBuffer.setSize (1, numSamples, false, false, true);
if (inputsConnected.contains (AudioInput))
{
levelOutBuffer.clear();
outputBuffers.getReference (LevelOutput) = &levelOutBuffer;
}
}

bool LevelDetective::getCustomComponents (OwnedArray<Component>& customComps, chowdsp::HostContextProvider&)
{
struct LevelDetectiveEditor : juce::Component
Expand All @@ -80,7 +91,7 @@ bool LevelDetective::getCustomComponents (OwnedArray<Component>& customComps, ch
juce::Component* visualiser;
} levelDetectiveEditor;

levelDetectiveEditor.visualiser = &levelVisualizer;
levelDetectiveEditor.visualiser = levelVisualizer.get();

customComps.add (levelDetectiveEditor.visualiser);
return false;
Expand Down
9 changes: 5 additions & 4 deletions src/processors/other/LevelDetective.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once

#include "../../modules/chowdsp_utils/modules/gui/chowdsp_visualizers/CompressorPlots/chowdsp_LevelDetectorVisualizer.h"
#include "../BaseProcessor.h"

using namespace chowdsp::compressor;
Expand All @@ -17,8 +16,10 @@ class LevelDetective : public BaseProcessor

void prepare (double sampleRate, int samplesPerBlock) override;
void processAudio (AudioBuffer<float>& buffer) override;
void processAudioBypassed (AudioBuffer<float>& buffer) override;

private:

enum InputPort
{
AudioInput
Expand All @@ -29,11 +30,11 @@ class LevelDetective : public BaseProcessor
LevelOutput
};

// chowdsp::FloatParameter* attackMsParam = nullptr;
// chowdsp::FloatParameter* releaseMsParam = nullptr;
// chowdsp::FloatParameter* attackMsParam = nullptr;
// chowdsp::FloatParameter* releaseMsParam = nullptr;

AudioBuffer<float> levelOutBuffer;
chowdsp::LevelDetector<float> level;
LevelDetectorVisualizer levelVisualizer {};
std::unique_ptr<LevelDetectorVisualizer> levelVisualizer = nullptr;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LevelDetective)
};

0 comments on commit c5f3bc5

Please sign in to comment.