1
#include "voiceprint.h"
2
#include <noatun/player.h>
3
#include <noatun/app.h>
12
KDE_EXPORT Plugin *create_plugin()
14
return new VoicePrint();
18
VoicePrint *VoicePrint::voicePrint=0;
20
VoicePrint::VoicePrint() : QWidget(0,0,WRepaintNoErase), MonoFFTScope(50), Plugin()
25
setCaption(i18n("Voiceprint"));
27
MonoFFTScope::start();
29
setMaximumHeight(1024);
32
VoicePrint::~VoicePrint()
36
void VoicePrint::init()
38
Prefs *p=new Prefs(this);
44
void VoicePrint::setColors(const QColor &bg, const QColor &fg, const QColor &l)
49
setBackgroundColor(mLowColor);
52
void VoicePrint::closeEvent(QCloseEvent *)
57
void VoicePrint::resizeEvent(QResizeEvent *)
60
mBuffer.resize(size());
61
QPainter paint(&mBuffer);
62
paint.fillRect(QRect(0,0, QWidget::width(), height()), QColor(mLowColor));
63
setBands(magic(height()/mSegmentWidth));
66
#define COLOR(color, bgcolor, fgcolor, foctet) \
67
(int)( color(bgcolor) + (foctet) * (color(fgcolor) - color(bgcolor)) )
69
inline static QRgb averageByIntensity(QRgb bgcolor, QRgb fgcolor, int octet)
71
float foctet = octet / 255.0;
73
return qRgb(COLOR(qRed, bgcolor, fgcolor, foctet),
74
COLOR(qGreen, bgcolor, fgcolor, foctet),
75
COLOR(qBlue, bgcolor, fgcolor, foctet)
81
void VoicePrint::paintEvent(QPaintEvent *e)
83
bitBlt(this, e->rect().topLeft(), &mBuffer, e->rect(), Qt::CopyROP);
86
void VoicePrint::scopeEvent(float *data, int bands)
89
if(isHidden()) return;
91
QPainter paint(&mBuffer);
92
// each square has a width of mSegmentWidth
93
float brightness = float(bands * mSegmentWidth);
94
for (int i=0; i<bands ; i++)
96
float b=data[bands-i-1]+1.0;
97
// the more bands there are, the dimmer each becomes
98
b=log10(b)/log(2) * 16 * brightness;
100
if (band>255) band=255;
101
else if (band<0) band=0;
103
QColor area(averageByIntensity(mLowColor, mHighColor, band));
105
int bandTop=i*height()/bands, bandBottom=(i+1)*height()/bands;
106
paint.fillRect(mOffset, bandTop, mSegmentWidth,bandBottom-bandTop,area);
109
int newOffset = mOffset+mSegmentWidth;
110
if (newOffset>QWidget::width()) newOffset=0;
111
paint.fillRect(newOffset, 0, mSegmentWidth, height(), mProgress);
113
// redraw changes with the minimum amount of work
116
repaint(mOffset,0,mSegmentWidth*2,height(),false);
120
repaint(mOffset,0,mSegmentWidth,height(),false);
121
repaint(newOffset,0,mSegmentWidth,height(),false);
126
#include "voiceprint.moc"