Hi Jules,
I’m working with Eric on the project that the original post refers to. First, a couple of questions:
(1) When a thumbnail is built using setSource(), then its data used to paint a waveform view, is that data different (more detailed) than it would be if we subsequently called saveTo() and then loadFrom()? We were originally assuming it would be the same, and that a thumbnail loaded from a saved file would still show detail when zoomed in.
(2) Is it “legal” to call setSource(aValidSource) followed by loadFrom()? This is what causes a crash (see below). It isn’t clear from the documentation, and after trying, the two seem mutually exclusive (provided aValidSource is indeed a valid source, not 0).
Let me explain what we’re trying to do in the hopes it helps with context.
In our application, we have a waveform view component (obviously). We want to store thumbnail data persistently to a file so the view can quickly be restored between user sessions.
Currently in our code, when the user opens audio file “foo.wav” for the first time, a thumbnail is computed and saved to a file “foo.jat”. We store the full path of foo.wav in a separate session document.
Given we have in our code an AudioThumbnail object called ‘thumbnail’:
When opening a new file, we call thumbnail.setSource(). This churns through the audio file, computing the thumbnail, taking time to display in the view. When it’s finished computing, we call thumbnail.saveTo() to save it to the .jat file. The waveform view now displays a nice, detailed waveform which we can zoom into at sample level.
When we close and reopen the session, we create a FileInputSource object “wavSource” from foo.wav and a FileInputStream object “jatStream” from foo.jat. We then call thumbnail.setSource(wavSource), followed by thumbnail.loadFrom(jatStream). This causes a crash in the thumb cache worker thread, in AudioThumbnail::generateSection(), line 313.
However, if instead of calling thumbnail.setSource(wavSource), we call thumbnail.setSource(0), we get no crash. The waveform view paints thumbnail data loaded from the .jat file, but when we zoom in near sample level, we get no detail (per the topic of this post). If we call setSource(wavSource) after loadFrom(jatStream), the thumbnail object seems to disregard the data loaded from jatStream and starts recomputing the thumbnail all over.
A work-around that I have been experimenting with is this:
-
When audio file is opened for the first time, call AudioThumbnail::setSource(). Save the thumbnail data to .jat file. Save session file (disregarding waveform zoom setting for now).
-
When session file is re-opened, call AudioThumbnail::setSource(0), followed by AudioThumbnail::loadFrom(jatFile). Paint the waveform view using data from the .jat file, showing the waveform fully zoomed out.
-
Upon zooming in to a point at which greater detail is needed, then call setSource().
This works, but seems like extra code we have to write whereas we would have expected JUCE to take care of managing it automatically. Any help is appreciated!
Thanks,
Bill
P.S. in response to Godwin’s post, we tried destroying and recreating the thumbnail object, but still got the crash.