Make playlist items use the full width available to them and adjust correctly when...
[amarok.git] / src / analyzers / analyzerbase.h
blob9a444fe69eaeeb00aa7713395b23d6a8b02a3fc6
1 // Maintainer: Max Howell <max.howell@methylblue.com>, (C) 2004
2 // Copyright: See COPYING file that comes with this distribution
4 #ifndef ANALYZERBASE_H
5 #define ANALYZERBASE_H
8 #include "config-amarok.h" //HAVE_QGLWIDGET
10 #ifdef __FreeBSD__
11 #include <sys/types.h>
12 #endif
14 #include "fht.h" //stack allocated and convenience
15 #include <QPixmap> //stack allocated and convenience
16 #include <QTimer> //stack allocated
17 #include <qwidget.h> //baseclass
18 //Added by qt3to4:
19 #include <QResizeEvent>
20 #include <QEvent>
21 #include <QPaintEvent>
22 #include <vector> //included for convenience
24 #ifdef HAVE_QGLWIDGET
25 #include <qgl.h> //baseclass
26 #ifdef Q_WS_MACX
27 #include <OpenGL/gl.h> //included for convenience
28 #include <OpenGL/glu.h> //included for convenience
29 #else
30 #include <GL/gl.h> //included for convenience
31 #include <GL/glu.h> //included for convenience
32 #endif
33 #else
34 //this is a workaround for compile problems due to moc
35 #define QGLWidget QWidget
36 #endif
38 #include <qimage.h> //for bitBlt
40 class QEvent;
41 class QPaintEvent;
42 class QResizeEvent;
45 namespace Analyzer {
47 typedef std::vector<float> Scope;
49 template<class W> class Base : public W
51 public:
52 uint timeout() const { return m_timeout; }
54 protected:
55 Base( QWidget*, uint, uint = 7 );
56 ~Base() { delete m_fht; }
58 void drawFrame();
59 int resizeExponent( int );
60 int resizeForBands( int );
61 virtual void transform( Scope& );
62 virtual void analyze( const Scope& ) = 0;
63 virtual void paused();
64 virtual void demo();
66 void changeTimeout( uint newTimeout )
68 m_timer.start( newTimeout );
69 m_timeout = newTimeout;
72 private:
73 bool event( QEvent* );
75 protected:
76 QTimer m_timer;
77 uint m_timeout;
78 FHT *m_fht;
82 class Base2D : public Base<QWidget>
84 Q_OBJECT
85 public:
86 const QPixmap *background() const { return &m_background; }
88 private slots:
89 void draw() { drawFrame(); }
91 protected slots:
92 void set50fps() { changeTimeout( 50 ); }
93 void set33fps() { changeTimeout( 33 ); }
94 void set25fps() { changeTimeout( 25 ); }
95 void set20fps() { changeTimeout( 20 ); }
96 void set10fps() { changeTimeout( 10 ); }
98 protected:
99 Base2D( QWidget*, uint timeout, uint scopeSize = 7 );
101 virtual void init() {}
103 QPixmap *background() { return &m_background; }
105 void resizeEvent( QResizeEvent* );
107 void polish();
109 private:
110 QPixmap m_background;
115 //This mess is because moc generates an entry for this class despite the #if block
116 //1. the Q_OBJECT macro must be exposed
117 //2. we have to define the class
118 //3. we have to declare a ctor (to satisfy the inheritance)
119 //4. the slot must also by visible (!)
120 //TODO find out how to stop moc generating a metaobject for this class
121 class Base3D : public Base<QGLWidget>
123 Q_OBJECT
124 #ifdef HAVE_QGLWIDGET
125 protected:
126 Base3D( QWidget*, uint, uint = 7 );
127 private slots:
128 void draw() { drawFrame(); }
129 #else
130 protected:
131 Base3D( QWidget *w, uint i1, uint i2 ) : Base<QGLWidget>( w, i1, i2 ) {}
132 private slots:
133 void draw() {}
134 #endif
138 class Factory
140 //Currently this is a rather small class, its only purpose
141 //to ensure that making changes to analyzers will not require
142 //rebuilding the world!
144 //eventually it would be better to make analyzers pluggable
145 //but I can't be arsed, nor can I see much reason to do so
146 //yet!
147 public:
148 static QWidget* createAnalyzer( QWidget* );
149 static QWidget* createPlaylistAnalyzer( QWidget *);
153 void interpolate( const Scope&, Scope& );
154 void initSin( Scope&, const uint = 6000 );
156 } //END namespace Analyzer
158 using Analyzer::Scope;
160 #endif