Fourier Scopes
Prev
Next

Fourier Scopes

The following example creates a simple level meter. The class inherits from a QWidget as well as a FFTScope. I leave it as a duty for you to create the rest of the plugin. See the many code examples in Noatun for a complete example.

void LameScope::scopeEvent(float *data, int size)
{
	int w=width();
	float fheight=height()*8;
	int h=height();
	int each=w/size;
	int x=0;

	QPainter paint(&this);
	repaint(); // clear the display, the background color is black

	// using pointers instead of arrays may be faster
	for (int c=0; c<size; c++)
	{
		// get the height of the band
		float n=d[c]+1.0;
		n=log10(n)/log(5)*fheight;
		int amp=(int)n;
		
		// clip it if it's out of range
		if (amp<0) amp=0;
		if (amp>h) amp=h;
		
		// draw
		p.fillRect(x, h-amp, each, amp, QColor(255,255,255));
		x+=each;
	}
}			

Prev
Next
Home