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...

This commit is contained in:
xenakios 2017-11-23 19:12:29 +02:00
parent 9207325698
commit a109d71f09
3 changed files with 23 additions and 5 deletions

View File

@ -154,14 +154,21 @@ void PaulstretchpluginAudioProcessorEditor::chooseFile()
}
}
WaveformComponent::WaveformComponent(AudioFormatManager* afm) : m_thumbcache(100)
std::shared_ptr<AudioThumbnailCache> g_thumbcache;
WaveformComponent::WaveformComponent(AudioFormatManager* afm)
{
if (g_thumbcache == nullptr)
{
g_thumbcache = std::make_shared<AudioThumbnailCache>(100);
}
m_thumbcache = g_thumbcache;
TimeSelectionChangedCallback = [](Range<double>, 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<AudioThumbnail>(512, *afm, m_thumbcache);
m_thumbcache->getTimeSliceThread().setPriority(3);
m_thumb = std::make_unique<AudioThumbnail>(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;
}
}

View File

@ -175,7 +175,7 @@ public:
Value ShowFileCacheRange;
void setRecordingPosition(double pos) { m_rec_pos = pos; }
private:
AudioThumbnailCache m_thumbcache;
std::shared_ptr<AudioThumbnailCache> m_thumbcache;
std::unique_ptr<AudioThumbnail> m_thumb;
Range<double> m_view_range{ 0.0,1.0 };
@ -221,3 +221,5 @@ private:
void chooseFile();
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PaulstretchpluginAudioProcessorEditor)
};
void cleanUpGUI();

View File

@ -96,6 +96,7 @@ PaulstretchpluginAudioProcessor::~PaulstretchpluginAudioProcessor()
{
g_activeprocessors.erase(this);
m_bufferingthread.stopThread(1000);
cleanUpGUI();
}
void PaulstretchpluginAudioProcessor::setPreBufferAmount(int x)