| 1 |
/**************************************************************************************** |
| 2 |
* Copyright (c) 2017 Malte Veerman <[email protected]> * |
| 3 |
* * |
| 4 |
* This program is free software; you can redistribute it and/or modify it under * |
| 5 |
* the terms of the GNU General Public License as published by the Free Software * |
| 6 |
* Foundation; either version 2 of the License, or (at your option) any later * |
| 7 |
* version. * |
| 8 |
* * |
| 9 |
* This program is distributed in the hope that it will be useful, but WITHOUT ANY * |
| 10 |
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * |
| 11 |
* PARTICULAR PURPOSE. See the GNU General Pulic License for more details. * |
| 12 |
* * |
| 13 |
* You should have received a copy of the GNU General Public License along with * |
| 14 |
* this program. If not, see <http://www.gnu.org/licenses/>. * |
| 15 |
****************************************************************************************/ |
| 16 |
|
| 17 |
#ifndef BLOCKWORKER_H |
| 18 |
#define BLOCKWORKER_H |
| 19 |
|
| 20 |
#include "AnalyzerWorker.h" |
| 21 |
|
| 22 |
#include <QElapsedTimer> |
| 23 |
#include <QMutex> |
| 24 |
#include <QTime> |
| 25 |
#include <QVector> |
| 26 |
|
| 27 |
|
| 28 |
class BlockWorker : public Analyzer::Worker |
| 29 |
{ |
| 30 |
friend class BlockRenderer; |
| 31 |
|
| 32 |
Q_OBJECT |
| 33 |
|
| 34 |
public: |
| 35 |
BlockWorker( int rows, int columns, qreal step, bool showFadebars ); |
| 36 |
|
| 37 |
void setStep( qreal step ) { m_step = step; } |
| 38 |
void setRows( int rows ); |
| 39 |
void setColumns( int columns ); |
| 40 |
void setRefreshRate( qreal refreshRate ) { m_refreshTime = std::floor( 1000.0 / refreshRate ); } |
| 41 |
void setShowFadebars( bool showFadebars ) { m_showFadebars = showFadebars; } |
| 42 |
|
| 43 |
Q_SIGNALS: |
| 44 |
void finished(); |
| 45 |
|
| 46 |
protected: |
| 47 |
void analyze() override; |
| 48 |
|
| 49 |
private: |
| 50 |
struct Fadebar |
| 51 |
{ |
| 52 |
int y; |
| 53 |
qreal intensity; |
| 54 |
Fadebar() |
| 55 |
{ |
| 56 |
y = 0; |
| 57 |
intensity = 0.0; |
| 58 |
} |
| 59 |
Fadebar( int y, qreal intensity ) |
| 60 |
{ |
| 61 |
this->y = y; |
| 62 |
this->intensity = intensity; |
| 63 |
} |
| 64 |
}; |
| 65 |
mutable QMutex m_mutex; //used to lock m_store and m_fadebars |
| 66 |
QVector<double> m_store; //current bar heights |
| 67 |
QVector<double> m_yscale; |
| 68 |
QVector<QList<Fadebar> > m_fadebars; |
| 69 |
qreal m_step; |
| 70 |
int m_rows; |
| 71 |
int m_columns; |
| 72 |
int m_refreshTime; |
| 73 |
bool m_showFadebars; |
| 74 |
QElapsedTimer m_lastUpdate; |
| 75 |
}; |
| 76 |
|
| 77 |
#endif //BLOCKWORKER_H |