Add AudioThumbnail to a Viewport


#1

Hey guys, I’m new to JUCE and want to add an AudioThumbnail to a viewport.
I got a parent component, wich is viewed in the viewport. Adding stuff like buttons and sliders via addAndMakeVisible() works fine, but since i cant add a AudioThumbnail via addAndMakeVisible(),
i have no idea how to do it. Any ideas?


#2

Put your Component inside a ViewPort and in your Component in paint() use AudioThumbnail::drawChannels()

Rail


#3

Thanks for your reply. I already tried to make my own class inheriting from Component, wrapping an AudioThumbnail inside of it, like in the FilePlayback-Demo from the examples. The problem is, I get a Runtime error, when trying to set the Bounds of my Component. My Class basically looks like this:

class LayerThumbnail    :       public Component,
				....
{
public:
    LayerThumbnail(AudioFormatManager& formatManager,
     ....
    {
		thumbnail.addChangeListener(this);
           ....
		currentPositionMarker.setFill(Colours::white.withAlpha(0.85f));
		addAndMakeVisible(currentPositionMarker);
    }

 	void paint(Graphics& g) override
	{
		g.fillAll(Colours::darkgrey);
		g.setColour(Colours::lightblue);

		if (thumbnail.getTotalLength() > 0.0)
		{
			thumbArea.removeFromBottom(scrollbar.getHeight() + 4);
			thumbnail.drawChannels(g, getLocalBounds(),
				visibleRange.getStart(), visibleRange.getEnd(), 1.0f);
		}
		else
		{
			g.setFont(14.0f);
			g.drawFittedText("(No audio file selected)", getLocalBounds(), Justification::centred, 2);
		}
	}

	 void resized() override
	{
		scrollbar.setBounds(getLocalBounds().removeFromBottom(14).reduced(2));
	}

 private:
	AudioTransportSource& transportSource;
	Slider& zoomSlider;
	ScrollBar scrollbar;

	AudioThumbnailCache thumbnailCache;
	AudioThumbnail thumbnail;

In PluginEditor.h, I add:

ScopedPointer<LayerThumbnail> thumbnail;
AudioFormatManager formatManager;
AudioSourcePlayer audioSourcePlayer;
AudioTransportSource transportSource;

and in PluginEditor.cpp:

	thumbnail = new LayerThumbnail(formatManager, transportSource, zoomSlider);
	addAndMakeVisible(thumbnail);
	thumbnail->addChangeListener(this);

wich works fine, but when i try to do

void ThumbAudioProcessorEditor::resized()
{
	thumbnail->setBounds(10, 10, 150, 50);
}

it compiles, and when I run it in Debugmode, it throws this exception:


#4

Looks like you haven’t given LayerThumbnail a size anywhere. Therefore its width is zero in resized()


#5

Ok now I gave LayerThumbnail a size via setSize() in its constructor, but the error is the same, when i try to set its Bounds in the PluginEditor. Do I have to do anything else to make it work? In the JUCE Demo it works just by creating an object of LayerThumbnail and adjust its size via SetBounds()