1 /* This file is part of Clementine. 2 Copyright 2004, Max Howell <max.howell@methylblue.com> 3 Copyright 2009-2010, David Sansome <davidsansome@gmail.com> 4 Copyright 2010, 2014, John Maguire <john.maguire@gmail.com> 5 Copyright 2011, Arnaud Bienner <arnaud.bienner@gmail.com> 6 Copyright 2014-2015, Mark Furneaux <mark@furneaux.ca> 7 Copyright 2014, Krzysztof Sobiecki <sobkas@gmail.com> 8 9 Clementine is free software: you can redistribute it and/or modify 10 it under the terms of the GNU General Public License as published by 11 the Free Software Foundation, either version 3 of the License, or 12 (at your option) any later version. 13 14 Clementine is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with Clementine. If not, see <http://www.gnu.org/licenses/>. 21 */ 22 23 /* Original Author: Max Howell <max.howell@methylblue.com> 2004 24 */ 25 26 #ifndef ANALYZERS_ANALYZERBASE_H_ 27 #define ANALYZERS_ANALYZERBASE_H_ 28 29 #include "config.h" 30 31 #if defined(__FreeBSD__) || defined(__DragonFly__) 32 #include <sys/types.h> 33 #endif 34 35 #include "fht.h" 36 #include "engines/engine_fwd.h" 37 #include "engines/enginebase.h" 38 #include <QPixmap> 39 #include <QBasicTimer> 40 #include <QWidget> 41 #include <vector> 42 43 #ifdef HAVE_OPENGL 44 #include <QGLWidget> 45 #ifdef Q_OS_MACX 46 #include <OpenGL/gl.h> 47 #include <OpenGL/glu.h> 48 #else 49 #include <GL/gl.h> 50 #include <GL/glu.h> 51 #endif 52 #endif 53 54 class QEvent; 55 class QPaintEvent; 56 class QResizeEvent; 57 58 namespace Analyzer { 59 60 typedef std::vector<float> Scope; 61 62 class Base : public QWidget { 63 Q_OBJECT 64 65 public: ~Base()66 ~Base() { delete fht_; } 67 timeout()68 uint timeout() const { return timeout_; } 69 set_engine(EngineBase * engine)70 void set_engine(EngineBase* engine) { engine_ = engine; } 71 changeTimeout(uint newTimeout)72 void changeTimeout(uint newTimeout) { 73 timeout_ = newTimeout; 74 if (timer_.isActive()) { 75 timer_.stop(); 76 timer_.start(timeout_, this); 77 } 78 } 79 framerateChanged()80 virtual void framerateChanged() {} 81 virtual void psychedelicModeChanged(bool); 82 83 protected: 84 explicit Base(QWidget*, uint scopeSize = 7); 85 86 void hideEvent(QHideEvent*); 87 void showEvent(QShowEvent*); 88 void paintEvent(QPaintEvent*); 89 void timerEvent(QTimerEvent*); 90 91 void polishEvent(); 92 93 int resizeExponent(int); 94 int resizeForBands(int); 95 int BandFrequency(int) const; 96 void updateBandSize(const int); 97 QColor getPsychedelicColor(const Scope&, const int, const int); init()98 virtual void init() {} 99 virtual void transform(Scope&); 100 virtual void analyze(QPainter& p, const Scope&, bool new_frame) = 0; 101 virtual void demo(QPainter& p); 102 103 protected: 104 static const int kSampleRate = 105 44100; // we shouldn't need to care about ultrasonics 106 107 QBasicTimer timer_; 108 uint timeout_; 109 FHT* fht_; 110 EngineBase* engine_; 111 Scope lastScope_; 112 113 bool new_frame_; 114 bool is_playing_; 115 116 QVector<uint> barkband_table_; 117 double prev_colors_[10][3]; 118 int prev_color_index_; 119 int bands_; 120 bool psychedelic_enabled_; 121 }; 122 123 void interpolate(const Scope&, Scope&); 124 void initSin(Scope&, const uint = 6000); 125 126 } // END namespace Analyzer 127 128 #endif // ANALYZERS_ANALYZERBASE_H_ 129