Range selection for AudioThumNail


#1

Hi,
would it make sense to add functionality to AudioThumbnail that allows to select a region of the sound with the mouse and to send the start and stop time to the change listener?
Perhaps it has been done already?
Best regards,
Bernhard


#2

The audio thumbnail isn’t a UI component - it simply provides the level data for you to use in whatever way you need. It’d be up to your own component to handle things like selection in a way that’s appropriate for your app.


#3

Oh, I see.

I did it now for example by extending the DemoThumbnailComp.
In case somebody ist interested:

class DemoThumbnailComp
...
    void mouseDown(const MouseEvent& e)
    {
        mouseDownX = e.x;
        startSel = startTime + (endTime - startTime) * (double) e.x / (double) getWidth();
    }

    void mouseDrag(const MouseEvent& e)
    {
        mouseUpX = e.x;
        endSel = startTime + (endTime - startTime) * (double) e.x / (double) getWidth();
        repaint();
    }

    void paint (Graphics& g)
    {
        g.fillAll (Colours::white);

        g.setColour (Colours::mediumblue);

        if (thumbnail.getTotalLength() > 0)
        {
            int heightPerChannel = (getHeight() - 4) / thumbnail.getNumChannels();

            for (int i = 0; i < thumbnail.getNumChannels(); ++i)
            {
                thumbnail.drawChannel (g, 2, 2 + heightPerChannel * i,
                                       getWidth() - 4, heightPerChannel,
                                       startTime, endTime,
                                       i, 1.0f);
            }

            g.setColour(Colours::tomato);
            g.drawRect(mouseDownX ,1 , mouseUpX - mouseDownX, getHeight()-2, 1);

        }
...

Thanks!!