The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
4.0KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCE_AUDIOTHUMBNAILCACHE_JUCEHEADER__
  19. #define __JUCE_AUDIOTHUMBNAILCACHE_JUCEHEADER__
  20. #include "juce_AudioThumbnailBase.h"
  21. //==============================================================================
  22. /**
  23. An instance of this class is used to manage multiple AudioThumbnail objects.
  24. The cache runs a single background thread that is shared by all the thumbnails
  25. that need it, and it maintains a set of low-res previews in memory, to avoid
  26. having to re-scan audio files too often.
  27. @see AudioThumbnail
  28. */
  29. class JUCE_API AudioThumbnailCache
  30. {
  31. public:
  32. //==============================================================================
  33. /** Creates a cache object.
  34. The maxNumThumbsToStore parameter lets you specify how many previews should
  35. be kept in memory at once.
  36. */
  37. explicit AudioThumbnailCache (int maxNumThumbsToStore);
  38. /** Destructor. */
  39. ~AudioThumbnailCache();
  40. //==============================================================================
  41. /** Clears out any stored thumbnails.
  42. */
  43. void clear();
  44. /** Reloads the specified thumb if this cache contains the appropriate stored
  45. data.
  46. This is called automatically by the AudioThumbnail class, so you shouldn't
  47. normally need to call it directly.
  48. */
  49. bool loadThumb (AudioThumbnailBase& thumb, int64 hashCode);
  50. /** Stores the cachable data from the specified thumb in this cache.
  51. This is called automatically by the AudioThumbnail class, so you shouldn't
  52. normally need to call it directly.
  53. */
  54. void storeThumb (const AudioThumbnailBase& thumb, int64 hashCode);
  55. //==============================================================================
  56. /** Attempts to re-load a saved cache of thumbnails from a stream.
  57. The cache data must have been written by the writeToStream() method.
  58. This will replace all currently-loaded thumbnails with the new data.
  59. */
  60. bool readFromStream (InputStream& source);
  61. /** Writes all currently-loaded cache data to a stream.
  62. The resulting data can be re-loaded with readFromStream().
  63. */
  64. void writeToStream (OutputStream& stream);
  65. /** Returns the thread that client thumbnails can use. */
  66. TimeSliceThread& getTimeSliceThread() noexcept { return thread; }
  67. private:
  68. //==============================================================================
  69. TimeSliceThread thread;
  70. class ThumbnailCacheEntry;
  71. friend class OwnedArray<ThumbnailCacheEntry>;
  72. OwnedArray<ThumbnailCacheEntry> thumbs;
  73. CriticalSection lock;
  74. int maxNumThumbsToStore;
  75. ThumbnailCacheEntry* findThumbFor (int64 hash) const;
  76. int findOldestThumb() const;
  77. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioThumbnailCache);
  78. };
  79. #endif // __JUCE_AUDIOTHUMBNAILCACHE_JUCEHEADER__