| 1 |
/**************************************************************************************** |
| 2 |
* Copyright (c) 2014 Matej Repinc <[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 ASCIIANALYZER_H |
| 18 |
#define ASCIIANALYZER_H |
| 19 |
|
| 20 |
#include "AnalyzerBase.h" |
| 21 |
|
| 22 |
#include <QImage> |
| 23 |
#include <QPixmap> |
| 24 |
#include <QSharedPointer> |
| 25 |
#include <QSize> |
| 26 |
|
| 27 |
class QPalette; |
| 28 |
|
| 29 |
class ASCIIAnalyzer : public Analyzer::Base |
| 30 |
{ |
| 31 |
public: |
| 32 |
explicit ASCIIAnalyzer( QWidget* ); |
| 33 |
|
| 34 |
static GLuint createTexture( const QImage &image ) { return instance->bindTexture( image ); } |
| 35 |
static void freeTexture( GLuint id ) { instance->deleteTexture( id ); } |
| 36 |
|
| 37 |
// Signed ints because most of what we compare them against are ints |
| 38 |
static const int BLOCK_HEIGHT = 12; |
| 39 |
static const int BLOCK_WIDTH = 12; |
| 40 |
static const int MIN_ROWS = 30; //arbitrary |
| 41 |
static const int MIN_COLUMNS = 32; //arbitrary |
| 42 |
static const int MAX_COLUMNS = 128; //must be 2**n |
| 43 |
static const int FADE_SIZE = 90; |
| 44 |
|
| 45 |
protected: |
| 46 |
virtual void initializeGL(); |
| 47 |
virtual void paintGL(); |
| 48 |
virtual void resizeGL( int w, int h ); |
| 49 |
virtual void transform( QVector<float>& ); |
| 50 |
virtual void analyze( const QVector<float>& ); |
| 51 |
virtual void paletteChange( const QPalette& ); |
| 52 |
|
| 53 |
void drawBackground(); |
| 54 |
void determineStep(); |
| 55 |
|
| 56 |
private: |
| 57 |
struct Texture |
| 58 |
{ |
| 59 |
Texture( const QPixmap &pixmap ) : |
| 60 |
id( ASCIIAnalyzer::createTexture( pixmap.toImage().mirrored() ) ), // Flip texture vertically for OpenGL bottom-left coordinate system |
| 61 |
size( pixmap.size() ) |
| 62 |
{} |
| 63 |
Texture( const Texture& texture ) |
| 64 |
{ |
| 65 |
id = texture.id; |
| 66 |
size = texture.size; |
| 67 |
} |
| 68 |
~Texture() |
| 69 |
{ |
| 70 |
ASCIIAnalyzer::freeTexture( id ); |
| 71 |
} |
| 72 |
|
| 73 |
GLuint id; |
| 74 |
QSize size; |
| 75 |
}; |
| 76 |
|
| 77 |
void drawTexture( Texture* texture, int x, int y, int sx, int sy ); |
| 78 |
|
| 79 |
static ASCIIAnalyzer* instance; |
| 80 |
|
| 81 |
int m_columns, m_rows; //number of rows and columns of blocks |
| 82 |
QPixmap m_barPixmap; |
| 83 |
QVector<float> m_scope; //so we don't create a vector every frame |
| 84 |
QVector<float> m_store; //current bar heights |
| 85 |
QVector<float> m_yscale; |
| 86 |
|
| 87 |
QSharedPointer<Texture> m_barTexture; |
| 88 |
QSharedPointer<Texture> m_topBarTexture; |
| 89 |
QSharedPointer<Texture> m_topSecondBarTexture; |
| 90 |
QSharedPointer<Texture> m_background; |
| 91 |
|
| 92 |
float m_step; //rows to fall per frame |
| 93 |
}; |
| 94 |
|
| 95 |
#endif |