diff --git a/modules/juce_audio_utils/gui/juce_AudioThumbnail.cpp b/modules/juce_audio_utils/gui/juce_AudioThumbnail.cpp index 7482758069..de2f2b5bd6 100644 --- a/modules/juce_audio_utils/gui/juce_AudioThumbnail.cpp +++ b/modules/juce_audio_utils/gui/juce_AudioThumbnail.cpp @@ -573,12 +573,12 @@ void AudioThumbnail::createChannels (const int length) } //============================================================================== -void AudioThumbnail::loadFrom (InputStream& rawInput) +bool AudioThumbnail::loadFrom (InputStream& rawInput) { BufferedInputStream input (rawInput, 4096); if (input.readByte() != 'j' || input.readByte() != 'a' || input.readByte() != 't' || input.readByte() != 'm') - return; + return false; const ScopedLock sl (lock); clearChannelData(); @@ -596,6 +596,8 @@ void AudioThumbnail::loadFrom (InputStream& rawInput) for (int i = 0; i < numThumbnailSamples; ++i) for (int chan = 0; chan < numChannels; ++chan) channels.getUnchecked(chan)->getData(i)->read (input); + + return true; } void AudioThumbnail::saveTo (OutputStream& output) const diff --git a/modules/juce_audio_utils/gui/juce_AudioThumbnail.h b/modules/juce_audio_utils/gui/juce_AudioThumbnail.h index a2a40e13c0..1f95f63e17 100644 --- a/modules/juce_audio_utils/gui/juce_AudioThumbnail.h +++ b/modules/juce_audio_utils/gui/juce_AudioThumbnail.h @@ -119,7 +119,7 @@ public: previously have been created by the saveTo() method. @see saveTo */ - void loadFrom (InputStream& input); + bool loadFrom (InputStream& input); /** Saves the low res thumbnail data to an output stream. diff --git a/modules/juce_audio_utils/gui/juce_AudioThumbnailBase.h b/modules/juce_audio_utils/gui/juce_AudioThumbnailBase.h index b25c42d650..fa4931c860 100644 --- a/modules/juce_audio_utils/gui/juce_AudioThumbnailBase.h +++ b/modules/juce_audio_utils/gui/juce_AudioThumbnailBase.h @@ -83,7 +83,7 @@ public: previously have been created by the saveTo() method. @see saveTo */ - virtual void loadFrom (InputStream& input) = 0; + virtual bool loadFrom (InputStream& input) = 0; /** Saves the low res thumbnail data to an output stream. diff --git a/modules/juce_audio_utils/gui/juce_AudioThumbnailCache.cpp b/modules/juce_audio_utils/gui/juce_AudioThumbnailCache.cpp index 510c07a6e7..292ff5dfa9 100644 --- a/modules/juce_audio_utils/gui/juce_AudioThumbnailCache.cpp +++ b/modules/juce_audio_utils/gui/juce_AudioThumbnailCache.cpp @@ -26,16 +26,16 @@ class AudioThumbnailCache::ThumbnailCacheEntry { public: - ThumbnailCacheEntry (const int64 hash_) - : hash (hash_), + ThumbnailCacheEntry (const int64 hashCode) + : hash (hashCode), lastUsed (Time::getMillisecondCounter()) { } ThumbnailCacheEntry (InputStream& in) - : lastUsed (0) + : hash (in.readInt64()), + lastUsed (0) { - hash = in.readInt64(); const int64 len = in.readInt64(); in.readIntoMemoryBlock (data, (ssize_t) len); } diff --git a/modules/juce_audio_utils/gui/juce_AudioThumbnailCache.h b/modules/juce_audio_utils/gui/juce_AudioThumbnailCache.h index a78203f9e4..0e79aca1e3 100644 --- a/modules/juce_audio_utils/gui/juce_AudioThumbnailCache.h +++ b/modules/juce_audio_utils/gui/juce_AudioThumbnailCache.h @@ -54,8 +54,7 @@ public: virtual ~AudioThumbnailCache(); //============================================================================== - /** Clears out any stored thumbnails. - */ + /** Clears out any stored thumbnails. */ void clear(); /** Reloads the specified thumb if this cache contains the appropriate stored @@ -89,9 +88,14 @@ public: TimeSliceThread& getTimeSliceThread() noexcept { return thread; } protected: - /** */ + /** This can be overridden to provide a custom callback for saving thumbnails + once they have finished being loaded. + */ virtual void saveNewlyFinishedThumbnail (const AudioThumbnailBase&, int64 hashCode); - /** */ + + /** This can be overridden to provide a custom callback for loading thumbnails + from pre-saved files to save the cache the trouble of having to create them. + */ virtual bool loadNewThumb (AudioThumbnailBase&, int64 hashCode); private: