Suggestion for new method AudioThumbnail::setReader (w/code)

Short story - I want thumbnails for my CD tracks but juce::AudioThumbnail only accepts InputSources.

This is a pity, as that InputSource is only used to create an AudioFormatReader, and I can easily make an AudioCDReader, which is an AudioFormatReader.

I could imagine that anyone wanting to do CD thumbnails would have this issue - or someone wanting to do thumbnails of any other non-standard representation, e.g. URLs.

I was able to easily solve this issue by adding a single method to juce::AudioThumbnail, void setReader (AudioFormatReader* reader, int64 hashCode);This works fine on my development system, at least, and I don’t see any reason why it would not work in general.

The full code is here: void AudioThumbnail::setReader (AudioFormatReader* reader_, int64 hashCode) { if (! (cache.loadThumb (*this, hashCode) && isFullyLoaded())) { { const ScopedLock sl (readerLock); reader = reader_; } if (reader != 0) { initialiseFromAudioFile (*reader); cache.addThumbnail (this); } } }

Seems like a good request. I’m just in the middle of tarting-up the thumbnail stuff, so I’ll see what I can do…

These days we talk about “easy virtueing up” the code to avoid possible accusations of gender bias. :wink:

:lol:

Jules, the new methods for the AudioThumbnail are great!
But looks like calling
AudioThumbnail::isFullyLoaded()
returns always false now.

Ah yes, thanks, I’ll get that sorted out!

Fast work, Jules.

I dropped it in in place of my hacked code and it not only worked, it didn’t have a bug my code did. :smiley: Instant thumbnails for CD tracks!

I’m discovering more about CDs and will report in a separate thread.

Jules,
what about adding a method to AudioThumbnailCache that would let save and load the whole content of it to a file?
I know there are already AudioThumbnailCache::storeThumb and AudioThumbnailCache::loadThumb,
but I’d like to be able to load the content before creating the thumbnails.

Well you can already do that - just create a thumbnail, load it, and add it to the cache.

Sorry to revive this old thread, but recently I added a couple of functions to the AudioThumbnailCache to do what I needed.
They are something like:

[code]void AudioThumbnailCache::storeCache(File& file)
{
FileOutputStream* mo = file.createOutputStream();

for (int i = thumbs.size(); --i >= 0;)
{
	mo->writeInt64(thumbs[i]->data.getSize());
	mo->write(thumbs[i]->data.getData(), thumbs[i]->data.getSize());
	mo->writeInt64(thumbs[i]->hash);
}

delete mo;

}

void AudioThumbnailCache::loadCache(File& file)
{
FileInputStream* mi = file.createInputStream();

while(mi->getPosition() < mi->getTotalLength())
{
	ThumbnailCacheEntry* te = new ThumbnailCacheEntry();
	
	int64 size = mi->readInt64();
	te->data.setSize(size);
	mi->read(te->data.getData(), (int)size); 
  te->hash = mi->readInt64();
	
	thumbs.add(te);
}

delete mi;

}[/code]

These let me store and load the whole cache to/from a file, BEFORE creating the thumbnails. In this way, when the thumbnails get re-created (and they use AudioThumbnail::setReader), the waveforms are immediately fully loaded.
I don’t know if you like the idea, but could this be an addition to the AudioThumbnailCache class?

ScopedPointers, please!! And check your pointers for nullness!

…but aside from that, thanks, not a bad idea! Can’t look at it right now, but remind me again if I forget.

Yeah! I usually use scoped pointers, but this code was just an idea…
Thank you!

Bump :stuck_out_tongue: