From a109d71f09d01db637d816ec16198b180fb0142c Mon Sep 17 00:00:00 2001 From: xenakios Date: Thu, 23 Nov 2017 19:12:29 +0200 Subject: [PATCH] Use shared thumbnailcache for all plugin instances. Kind of a tricky thing with std::shared_ptr going on here using the deprecated unique method...But, oh well... --- Source/PluginEditor.cpp | 23 +++++++++++++++++++---- Source/PluginEditor.h | 4 +++- Source/PluginProcessor.cpp | 1 + 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/Source/PluginEditor.cpp b/Source/PluginEditor.cpp index 26fef6f..524f946 100644 --- a/Source/PluginEditor.cpp +++ b/Source/PluginEditor.cpp @@ -154,14 +154,21 @@ void PaulstretchpluginAudioProcessorEditor::chooseFile() } } -WaveformComponent::WaveformComponent(AudioFormatManager* afm) : m_thumbcache(100) +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); // The default priority of 2 is a bit too low in some cases, it seems... - m_thumbcache.getTimeSliceThread().setPriority(3); - m_thumb = std::make_unique(512, *afm, m_thumbcache); + m_thumbcache->getTimeSliceThread().setPriority(3); + m_thumb = std::make_unique(512, *afm, *m_thumbcache); m_thumb->addChangeListener(this); setOpaque(true); } @@ -271,7 +278,7 @@ void WaveformComponent::setAudioFile(File f) { m_waveimage = Image(); if (m_thumb != nullptr && f == m_curfile) // reloading same file, might happen that the overview needs to be redone... - m_thumbcache.removeThumb(m_thumb->getHashCode()); + m_thumbcache->removeThumb(m_thumb->getHashCode()); if (m_thumb != nullptr) m_thumb->reset(0, 0.0); m_thumb->setSource(new FileInputSource(f)); @@ -430,3 +437,11 @@ int WaveformComponent::getTimeSelectionEdge(int x, int y) return 2; 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 8e68216..5f8de83 100644 --- a/Source/PluginEditor.h +++ b/Source/PluginEditor.h @@ -175,7 +175,7 @@ public: Value ShowFileCacheRange; void setRecordingPosition(double pos) { m_rec_pos = pos; } private: - AudioThumbnailCache m_thumbcache; + std::shared_ptr m_thumbcache; std::unique_ptr m_thumb; Range m_view_range{ 0.0,1.0 }; @@ -221,3 +221,5 @@ private: void chooseFile(); 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 81b7e42..41286b7 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -96,6 +96,7 @@ PaulstretchpluginAudioProcessor::~PaulstretchpluginAudioProcessor() { g_activeprocessors.erase(this); m_bufferingthread.stopThread(1000); + cleanUpGUI(); } void PaulstretchpluginAudioProcessor::setPreBufferAmount(int x)