Marking Audio Data, DrawChannels, Paint Help


#1

Hello guys and Happy New Year!
I’m pretty new at JUCE and I got a problem with something. In my project I have a component, which draws me channels of my audio (using AudioThumbnail::drawChannels()). What i wanna do is add a possibility to mark audio data, like it’s possible in DAWs (using mouse). I’ve made a new component for this. I’ve come up with something like this:

void paint(Graphics&g) override
{
	markAudio(g);
}

void mouseDown(const MouseEvent & event)override
{
	xDown=event.position.x;
}

void mouseUp(const MouseEvent & event)override
{
	xUp = event.position.x;
	repaint();
}

void markAudio(Graphics&g)
{
	double diff = xUp - xDown;
	double duration = transportSource.getLengthInSeconds();
	const double positionDown = (xDown / getWidth()) * duration;
	const double positionUp = (xUp / getWidth()) * duration;
	const Rectangle<int> markBounds(xDown, 0, xUp, getHeight());
	g.setColour(Colours::darkblue);
	thumbnail.drawChannels(g, markBounds, positionDown, positionUp, 1.0f);
}

.
.
.

        AudioTransportSource &transportSource;
        AudioThumbnail &thumbnail;
        double xDown, xUp;

Can u tell me if my thinking is right? What should i do to make it work? This code currently doesnt paint anything for me in my component.


#2

Create a Range with a start and end point and have a couple of methods which converts samples to and from pixels… then repaint when required. make sure your Range has a limit of zero and length of the audio file.

I believe there may be code in the dRowAudio demo which may help you.

Rail