From e2de64d6f1beb9e492daf5b886e19933c1fa41dd Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdemultimedia@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- noatun/modules/voiceprint/voiceprint.cpp | 126 +++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 noatun/modules/voiceprint/voiceprint.cpp (limited to 'noatun/modules/voiceprint/voiceprint.cpp') diff --git a/noatun/modules/voiceprint/voiceprint.cpp b/noatun/modules/voiceprint/voiceprint.cpp new file mode 100644 index 00000000..4f6c7aea --- /dev/null +++ b/noatun/modules/voiceprint/voiceprint.cpp @@ -0,0 +1,126 @@ +#include "voiceprint.h" +#include +#include +#include +#include +#include "prefs.h" +#include +#include + +extern "C" +{ + KDE_EXPORT Plugin *create_plugin() + { + return new VoicePrint(); + } +} + +VoicePrint *VoicePrint::voicePrint=0; + +VoicePrint::VoicePrint() : QWidget(0,0,WRepaintNoErase), MonoFFTScope(50), Plugin() +{ + voicePrint=this; + mOffset=0; + mSegmentWidth=2; + setCaption(i18n("Voiceprint")); + resize(320, 240); + MonoFFTScope::start(); + show(); + setMaximumHeight(1024); +} + +VoicePrint::~VoicePrint() +{ +} + +void VoicePrint::init() +{ + Prefs *p=new Prefs(this); + p->reopen(); + p->save(); + resizeEvent(0); +} + +void VoicePrint::setColors(const QColor &bg, const QColor &fg, const QColor &l) +{ + mProgress=l; + mLowColor=bg.rgb(); + mHighColor=fg.rgb(); + setBackgroundColor(mLowColor); +} + +void VoicePrint::closeEvent(QCloseEvent *) +{ + unload(); +} + +void VoicePrint::resizeEvent(QResizeEvent *) +{ + mOffset=0; + mBuffer.resize(size()); + QPainter paint(&mBuffer); + paint.fillRect(QRect(0,0, QWidget::width(), height()), QColor(mLowColor)); + setBands(magic(height()/mSegmentWidth)); +} + +#define COLOR(color, bgcolor, fgcolor, foctet) \ + (int)( color(bgcolor) + (foctet) * (color(fgcolor) - color(bgcolor)) ) + +inline static QRgb averageByIntensity(QRgb bgcolor, QRgb fgcolor, int octet) +{ + float foctet = octet / 255.0; + + return qRgb(COLOR(qRed, bgcolor, fgcolor, foctet), + COLOR(qGreen, bgcolor, fgcolor, foctet), + COLOR(qBlue, bgcolor, fgcolor, foctet) + ); +} + +#undef COLOR + +void VoicePrint::paintEvent(QPaintEvent *e) +{ + bitBlt(this, e->rect().topLeft(), &mBuffer, e->rect(), Qt::CopyROP); +} + +void VoicePrint::scopeEvent(float *data, int bands) +{ + // save cpu + if(isHidden()) return; + + QPainter paint(&mBuffer); + // each square has a width of mSegmentWidth + float brightness = float(bands * mSegmentWidth); + for (int i=0; i255) band=255; + else if (band<0) band=0; + + QColor area(averageByIntensity(mLowColor, mHighColor, band)); + + int bandTop=i*height()/bands, bandBottom=(i+1)*height()/bands; + paint.fillRect(mOffset, bandTop, mSegmentWidth,bandBottom-bandTop,area); + } + + int newOffset = mOffset+mSegmentWidth; + if (newOffset>QWidget::width()) newOffset=0; + paint.fillRect(newOffset, 0, mSegmentWidth, height(), mProgress); + + // redraw changes with the minimum amount of work + if(newOffset != 0) + { + repaint(mOffset,0,mSegmentWidth*2,height(),false); + } + else + { + repaint(mOffset,0,mSegmentWidth,height(),false); + repaint(newOffset,0,mSegmentWidth,height(),false); + } + mOffset = newOffset; +} + +#include "voiceprint.moc" -- cgit v1.2.1