Make playlist items use the full width available to them and adjust correctly when...
[amarok.git] / src / analyzers / sonogram.cpp
blobf18de02953acfc04c86970f3dd6983d5923f1ed3
1 //
2 //
3 // C++ Implementation: Sonogram
4 //
5 // Description:
6 //
7 //
8 // Author: Melchior FRANZ <mfranz@kde.org>, (C) 2004
9 //
10 // Copyright: See COPYING file that comes with this distribution
14 #include <QPainter>
15 //Added by qt3to4:
16 #include <QResizeEvent>
17 #include <QPaintEvent>
18 #include "debug.h"
19 #include "sonogram.h"
21 Sonogram::Sonogram(QWidget *parent) :
22 Analyzer::Base2D(parent, 16, 9)
27 Sonogram::~Sonogram()
32 void Sonogram::init()
37 void Sonogram::resizeEvent(QResizeEvent *e)
39 DEBUG_BLOCK
41 //only for gcc < 4.0
42 #if !( __GNUC__ > 4 || ( __GNUC__ == 4 && __GNUC_MINOR__ >= 0 ) )
43 resizeForBands(height() < 128 ? 128 : height());
44 #endif
46 Analyzer::Base2D::resizeEvent( e );
47 // p.drawPixmap( 0, 0, background() )
48 // bitBlt(this, 0, 0, background());
52 void Sonogram::analyze(const Scope &s)
54 Q_UNUSED( s )
55 // Analyzer::interpolate( s, m_scope );
56 update();
59 void
60 Sonogram::paintEvent( QPaintEvent * )
62 int x = width() - 1;
63 QColor c;
64 QPainter p( this );
66 // bitBlt(canvas(), 0, 0, canvas(), 1, 0, x, height());
67 // p.drawPixmap( 0, 0, this, 1, 0, x, height() );
68 const Scope &s = m_scope;
69 Scope::const_iterator it = s.begin(), end = s.end();
70 for (int y = height() - 1; y;) {
71 if (it >= end || *it < .005)
72 c = p.background().color();
73 else if (*it < .05)
74 c.setHsv(95, 255, 255 - int(*it * 4000.0));
75 else if (*it < 1.0)
76 c.setHsv(95 - int(*it * 90.0), 255, 255);
77 else
78 c = Qt::red;
80 p.setPen(c);
81 p.drawPoint(x, y--);
83 if (it < end)
84 ++it;
89 void Sonogram::transform(Scope &scope)
91 float *front = static_cast<float*>(&scope.front());
92 m_fht->power2(front);
93 m_fht->scale(front, 1.0 / 256);
94 scope.resize( m_fht->size() / 2 );
98 void Sonogram::demo()
100 analyze(Scope(m_fht->size(), 0));