1 /* eqspectrumview.h - defination of EqSpectrumView class. 2 * 3 * Copyright (c) 2014 David French <dave/dot/french3/at/googlemail/dot/com> 4 * 5 * This file is part of LMMS - https://lmms.io 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public 9 * License as published by the Free Software Foundation; either 10 * version 2 of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public 18 * License along with this program (see COPYING); if not, write to the 19 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 20 * Boston, MA 02110-1301 USA. 21 * 22 */ 23 #ifndef EQSPECTRUMVIEW_H 24 #define EQSPECTRUMVIEW_H 25 26 #include <QPainter> 27 #include <QPainterPath> 28 #include <QWidget> 29 30 #include "fft_helpers.h" 31 #include "lmms_basics.h" 32 #include "lmms_math.h" 33 34 35 const int MAX_BANDS = 2048; 36 class EqAnalyser 37 { 38 public: 39 EqAnalyser(); 40 virtual ~EqAnalyser(); 41 42 float m_bands[MAX_BANDS]; 43 bool getInProgress(); 44 void clear(); 45 46 void analyze( sampleFrame *buf, const fpp_t frames ); 47 48 float getEnergy() const; 49 int getSampleRate() const; 50 bool getActive() const; 51 52 void setActive(bool active); 53 54 private: 55 fftwf_plan m_fftPlan; 56 fftwf_complex * m_specBuf; 57 float m_absSpecBuf[FFT_BUFFER_SIZE+1]; 58 float m_buffer[FFT_BUFFER_SIZE*2]; 59 int m_framesFilledUp; 60 float m_energy; 61 int m_sampleRate; 62 bool m_active; 63 bool m_inProgress; 64 float m_fftWindow[FFT_BUFFER_SIZE]; 65 }; 66 67 68 69 70 class EqSpectrumView : public QWidget 71 { 72 Q_OBJECT 73 public: 74 explicit EqSpectrumView( EqAnalyser *b, QWidget *_parent = 0 ); ~EqSpectrumView()75 virtual ~EqSpectrumView() 76 { 77 } 78 79 QColor getColor() const; 80 void setColor( const QColor &value ); 81 82 protected: 83 virtual void paintEvent( QPaintEvent *event ); 84 85 private slots: 86 void periodicalUpdate(); 87 88 private: 89 QColor m_color; 90 EqAnalyser *m_analyser; 91 QPainterPath m_path; 92 float m_peakSum; 93 float m_pixelsPerUnitWidth; 94 float m_scale; 95 int m_skipBands; 96 bool m_periodicalUpdate; 97 QList<float> m_bandHeight; 98 99 float bandToFreq ( int index ); 100 }; 101 #endif // EQSPECTRUMVIEW_H 102