Skip to content

Commit

Permalink
Fix double-delete error for levelVisualizer
Browse files Browse the repository at this point in the history
  • Loading branch information
jatinchowdhury18 committed Jul 20, 2023
1 parent 82ff2da commit 1a038ff
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
31 changes: 19 additions & 12 deletions src/processors/other/LevelDetective.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ LevelDetective::LevelDetective (UndoManager* um) : BaseProcessor (
InputPort {},
OutputPort {},
um,
[] (InputPort port)
[] (InputPort)
{
return PortType::audio;
},
[] (OutputPort port)
[] (OutputPort)
{
return PortType::level;
})
{
levelVisualizer = std::make_unique<LevelDetectorVisualizer>();
// levelVisualizer = std::make_unique<LevelDetectorVisualizer>();
using namespace ParameterHelpers;
// loadParameterPointer (attackMsParam, vts, "attack");
// loadParameterPointer (releaseMsParam, vts, "release");
Expand All @@ -43,8 +43,8 @@ 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)
Expand All @@ -56,13 +56,13 @@ void LevelDetective::processAudio (AudioBuffer<float>& buffer)
{
//create span to fill audio visualiser buffer
nonstd::span<const float> audioChannelData = { buffer.getReadPointer (0), (size_t) numSamples };
levelVisualizer->pushChannel (0, audioChannelData);
levelVisualizer.pushChannel (0, audioChannelData);
// level.setParameters(*attackMsParam, *releaseMsParam);
level.processBlock (buffer, levelOutBuffer);

//create span to fill level visualiser buffer
nonstd::span<const float> levelChannelData = { levelOutBuffer.getReadPointer (0), (size_t) numSamples };
levelVisualizer->pushChannel (1, levelChannelData);
levelVisualizer.pushChannel (1, levelChannelData);
}
else
{
Expand All @@ -87,13 +87,20 @@ bool LevelDetective::getCustomComponents (OwnedArray<Component>& customComps, ch
{
struct LevelDetectiveEditor : juce::Component
{
//Parameters here?
explicit LevelDetectiveEditor (juce::Component& viz) : visualiser (viz)
{
addAndMakeVisible (visualiser);
}

juce::Component* visualiser;
} levelDetectiveEditor;
void resized() override
{
visualiser.setBounds (getLocalBounds());
}

levelDetectiveEditor.visualiser = levelVisualizer.get();
juce::Component& visualiser;
};

customComps.add (std::make_unique<LevelDetectiveEditor> (levelVisualizer));

customComps.add (levelDetectiveEditor.visualiser);
return false;
}
3 changes: 2 additions & 1 deletion src/processors/other/LevelDetective.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class LevelDetective : public BaseProcessor

AudioBuffer<float> levelOutBuffer;
chowdsp::LevelDetector<float> level;
std::unique_ptr<LevelDetectorVisualizer> levelVisualizer = nullptr;
LevelDetectorVisualizer levelVisualizer;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LevelDetective)
};

0 comments on commit 1a038ff

Please sign in to comment.