From e9e1c455507cf5c2fac3eeff4525010ea9e34002 Mon Sep 17 00:00:00 2001 From: xenakios Date: Thu, 23 Nov 2017 19:36:46 +0200 Subject: [PATCH] Nicer way to deal with the shared audiothumbnailcache --- Source/PluginEditor.cpp | 14 -------------- Source/PluginEditor.h | 10 ++++++++-- Source/PluginProcessor.cpp | 1 - Source/PluginProcessor.h | 6 +++--- 4 files changed, 11 insertions(+), 20 deletions(-) diff --git a/Source/PluginEditor.cpp b/Source/PluginEditor.cpp index 524f946..ca8f4c4 100644 --- a/Source/PluginEditor.cpp +++ b/Source/PluginEditor.cpp @@ -154,15 +154,8 @@ void PaulstretchpluginAudioProcessorEditor::chooseFile() } } -std::shared_ptr g_thumbcache; - WaveformComponent::WaveformComponent(AudioFormatManager* afm) { - if (g_thumbcache == nullptr) - { - g_thumbcache = std::make_shared(100); - } - m_thumbcache = g_thumbcache; TimeSelectionChangedCallback = [](Range, int) {}; if (m_use_opengl == true) m_ogl.attachTo(*this); @@ -438,10 +431,3 @@ int WaveformComponent::getTimeSelectionEdge(int x, int y) return 0; } -void cleanUpGUI() -{ - if (g_thumbcache.unique()) - { - g_thumbcache = nullptr; - } -} \ No newline at end of file diff --git a/Source/PluginEditor.h b/Source/PluginEditor.h index 5f8de83..3eedb45 100644 --- a/Source/PluginEditor.h +++ b/Source/PluginEditor.h @@ -133,6 +133,13 @@ private: bool m_dragging = false; }; +class MyThumbCache : public AudioThumbnailCache +{ +public: + MyThumbCache() : AudioThumbnailCache(100) { Logger::writeToLog("Constructed AudioThumbNailCache"); } + ~MyThumbCache() { Logger::writeToLog("Destructed AudioThumbNailCache"); } +}; + class WaveformComponent : public Component, public ChangeListener, public Timer { public: @@ -175,7 +182,7 @@ public: Value ShowFileCacheRange; void setRecordingPosition(double pos) { m_rec_pos = pos; } private: - std::shared_ptr m_thumbcache; + SharedResourcePointer m_thumbcache; std::unique_ptr m_thumb; Range m_view_range{ 0.0,1.0 }; @@ -222,4 +229,3 @@ private: JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PaulstretchpluginAudioProcessorEditor) }; -void cleanUpGUI(); \ No newline at end of file diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index 41286b7..81b7e42 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -96,7 +96,6 @@ PaulstretchpluginAudioProcessor::~PaulstretchpluginAudioProcessor() { g_activeprocessors.erase(this); m_bufferingthread.stopThread(1000); - cleanUpGUI(); } void PaulstretchpluginAudioProcessor::setPreBufferAmount(int x) diff --git a/Source/PluginProcessor.h b/Source/PluginProcessor.h index 963b32b..7e147e5 100644 --- a/Source/PluginProcessor.h +++ b/Source/PluginProcessor.h @@ -13,9 +13,8 @@ #include "../JuceLibraryCode/JuceHeader.h" #include "PS_Source/PaulStretchControl.h" -//============================================================================== -/** -*/ +class MyThumbCache; + class PaulstretchpluginAudioProcessor : public AudioProcessor { public: @@ -97,6 +96,7 @@ private: void setPreBufferAmount(int x); void setFFTSize(double size); void startplay(Range playrange, int numoutchans, String& err); + SharedResourcePointer m_thumbcache; //============================================================================== JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PaulstretchpluginAudioProcessor) };