Is viewport still ideal for very large components?


I have previously programmed using Windows Forms, in C#, and noticed that rendering large bitmaps (for displaying my wave forms) could be a disaster, depending on the length of the audio. The application would immediately crash (stating that there was not enough memory) if the audio was lengthy. Of course JUCE is much better than Windows Forms, but I am just wondering if I might still run into issues with the length of the audio, and subsequently the size of the viewport components.
At present, I am not using a Viewport at all. I have created a scroll bar, and re-render a section of the wave every time the user moves the scroll bar. However, this is causing problems because have components in the foreground, on top of the waveform and these need to move as the wave form is scrolled. Quick scrolling creates a temporary jittery glitch around the transparencies of those foreground components. So I figure, scrolling a viewport might be a solution, if there are no major drawbacks.
Any thoughts?


Check out the AudioThumbnail class, which is designed especially for this situation. It does nifty stuff in the background to reduce draw time/memory usage for audio waveforms.


Thanks I’m having a look right now. It looks useful, but I still am interested in the general question of whether viewports are less ideal for large components. I do have one other GUI element that displays data that is somewhat of a hybrid between a waveform and a graph. The data is not actually audio, but the data might be of considerable length. Therefore, I will at some point need to create something more custom.


A Viewport is fine for large components as long as they’re smart enough to draw themselves efficiently - i.e. not to waste time drawing all the areas of themselves which are occluded.

Of course it also depends how big they are - coordinates are 32-bit ints, so if your component is super-large then things will start to overflow.


Cool thanks Jules.
But if I only draw areas that are presently visible, isn’t there a risk that the user scrolls the component before it has any visuals? Like, if they scroll very quickly, I imagine the whole viewable area might be blank for fraction of a second.


No, that’s not how components work. Everything gets drawn synchronously.