diff options
| author | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2012-08-13 19:29:59 +0000 |
|---|---|---|
| committer | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2012-08-13 19:29:59 +0000 |
| commit | 5e6fcfd6786612b1de0c65d72a6129ae94393978 (patch) | |
| tree | 49e054f154017460e4b8abe52686cc939ce8dbb9 /src/plugins/Visual/analyzer/analyzer.cpp | |
| parent | 19f137d27e2101d1735693f3cb18b24444c755ee (diff) | |
| download | qmmp-5e6fcfd6786612b1de0c65d72a6129ae94393978.tar.gz qmmp-5e6fcfd6786612b1de0c65d72a6129ae94393978.tar.bz2 qmmp-5e6fcfd6786612b1de0c65d72a6129ae94393978.zip | |
analyzer plugin: refactoring, added full screen mode ('F' hotkey)
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@2882 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src/plugins/Visual/analyzer/analyzer.cpp')
| -rw-r--r-- | src/plugins/Visual/analyzer/analyzer.cpp | 158 |
1 files changed, 80 insertions, 78 deletions
diff --git a/src/plugins/Visual/analyzer/analyzer.cpp b/src/plugins/Visual/analyzer/analyzer.cpp index 5c5af8113..8dd65afcf 100644 --- a/src/plugins/Visual/analyzer/analyzer.cpp +++ b/src/plugins/Visual/analyzer/analyzer.cpp @@ -35,19 +35,23 @@ #define VISUAL_NODE_SIZE 512 //samples #define VISUAL_BUFFER_SIZE (5*VISUAL_NODE_SIZE) -Analyzer::Analyzer (QWidget *parent) - : Visual (parent), m_fps (20) +Analyzer::Analyzer (QWidget *parent) : Visual (parent), m_fps (20) { + m_intern_vis_data = 0; + m_peaks = 0; + m_x_scale = 0; + m_buffer_at = 0; + m_rows = 0; + m_cols = 0; QSettings settings(Qmmp::configFile(), QSettings::IniFormat); restoreGeometry(settings.value("Analyzer/geometry").toByteArray()); //setAttribute(Qt::WA_TranslucentBackground); - //setFixedSize(2*300-30,105); setMinimumSize(2*300-30,105); m_timer = new QTimer (this); connect(m_timer, SIGNAL (timeout()), this, SLOT (timeout())); m_left_buffer = new short[VISUAL_BUFFER_SIZE]; m_right_buffer = new short[VISUAL_BUFFER_SIZE]; - m_buffer_at = 0; + clear(); setWindowTitle (tr("Qmmp Analyzer")); @@ -69,22 +73,31 @@ Analyzer::Analyzer (QWidget *parent) m_peakColor.setNamedColor(settings.value("Analyzer/peak_color", "Cyan").toString()); m_cell_size = QSize(15, 6); //m_cell_size = QSize(5, 3); + + QAction *fullScreenAction = new QAction(this); + fullScreenAction->setShortcut(tr("F")); + connect(fullScreenAction, SIGNAL(triggered()), SLOT(toggleFullScreen())); + addAction(fullScreenAction); } Analyzer::~Analyzer() { delete [] m_left_buffer; delete [] m_right_buffer; + + if(m_peaks) + delete [] m_peaks; + if(m_intern_vis_data) + delete [] m_intern_vis_data; + if(m_x_scale) + delete [] m_x_scale; } void Analyzer::clear() { m_buffer_at = 0; - for (int i = 0; i< 7500; ++i) - { - m_intern_vis_data[i] = 0; - m_peaks[i] = 0; - } + m_rows = 0; + m_cols = 0; update(); } @@ -165,84 +178,86 @@ void Analyzer::process (short *left, short *right) if (!state) state = fft_init(); - m_rows = (height() - 2) / m_cell_size.height(); - m_cols = (width() - 2) / m_cell_size.width() / 2; + int rows = (height() - 2) / m_cell_size.height(); + int cols = (width() - 2) / m_cell_size.width() / 2; + + if(m_rows != rows || m_cols != cols) + { + m_rows = rows; + m_cols = cols; + if(m_peaks) + delete [] m_peaks; + if(m_intern_vis_data) + delete [] m_intern_vis_data; + if(m_x_scale) + delete [] m_x_scale; + m_peaks = new double[m_cols * 2]; + m_intern_vis_data = new double[m_cols * 2]; + m_x_scale = new int[m_cols + 1]; + + for(int i = 0; i < m_cols * 2; ++i) + { + m_peaks[i] = 0; + m_intern_vis_data[i] = 0; + } + for(int i = 0; i < m_cols + 1; ++i) + m_x_scale[i] = pow(pow(255.0, 1.0 / m_cols), i); + } short dest_l[256]; short dest_r[256]; + short yl, yr; + int j, k, magnitude_l, magnitude_r; calc_freq (dest_l, left); calc_freq (dest_r, right); - int xscale_short[m_cols + 1]; - for(int i = 0; i < m_cols + 1; ++i) - { - xscale_short[i] = pow(pow(255.0, 1.0 / m_cols), i); - //qDebug("=%d", int(xscale_short[i])); - } - double y_scale = (double) 1.25 * m_rows / log(256); - int yl,yr, j; - for (int i = 0; i < m_cols; i++) { + j = m_cols * 2 - i - 1; //mirror index yl = yr = 0; + magnitude_l = magnitude_r = 0; - if(xscale_short[i] == xscale_short[i + 1]) + if(m_x_scale[i] == m_x_scale[i + 1]) { yl = dest_l[i]; yr = dest_r[i]; } - else + for (k = m_x_scale[i]; k < m_x_scale[i + 1]; k++) { - for (j = xscale_short[i]; j < xscale_short[i + 1]; j++) - { - if (dest_l[j] > yl) - yl = dest_l[j]; - if (dest_r[j] > yr) - yr = dest_r[j]; - } + yl = qMax(dest_l[k], yl); + yr = qMax(dest_r[k], yr); } - yl >>= 7; + yl >>= 7; //256 yr >>= 7; - int magnitude_l = 0; - int magnitude_r = 0; if (yl) { magnitude_l = int(log (yl) * y_scale); - if (magnitude_l > m_rows) - magnitude_l = m_rows; - if (magnitude_l < 0) - magnitude_l = 0; + magnitude_l = qBound(0, magnitude_l, m_rows); } if (yr) { magnitude_r = int(log (yr) * y_scale); - if (magnitude_r > m_rows) - magnitude_r = m_rows; - if (magnitude_r < 0) - magnitude_r = 0; + magnitude_r = qBound(0, magnitude_r, m_rows); } m_intern_vis_data[i] -= m_analyzer_falloff * m_rows / 15; - m_intern_vis_data[i] = magnitude_l > m_intern_vis_data[i] - ? magnitude_l : m_intern_vis_data[i]; + m_intern_vis_data[i] = magnitude_l > m_intern_vis_data[i] ? magnitude_l : m_intern_vis_data[i]; - m_intern_vis_data[m_cols * 2 - 1 - i] -= m_analyzer_falloff * m_rows / 15; - m_intern_vis_data[m_cols * 2 - 1 - i] = magnitude_r > m_intern_vis_data[2*m_cols-1-i] - ? magnitude_r : m_intern_vis_data[2*m_cols-1-i]; + m_intern_vis_data[j] -= m_analyzer_falloff * m_rows / 15; + m_intern_vis_data[j] = magnitude_r > m_intern_vis_data[j] ? magnitude_r : m_intern_vis_data[j]; if (m_show_peaks) { m_peaks[i] -= m_peaks_falloff * m_rows / 15; m_peaks[i] = magnitude_l > m_peaks[i] ? magnitude_l : m_peaks[i]; - m_peaks[m_cols * 2 - 1 - i] -= m_peaks_falloff * m_rows / 15; - m_peaks[m_cols * 2 - 1 - i] = magnitude_r > m_peaks[2*m_cols-1-i] - ? magnitude_r : m_peaks[2*m_cols-1-i]; + m_peaks[j] -= m_peaks_falloff * m_rows / 15; + m_peaks[j] = magnitude_r > m_peaks[j] ? magnitude_r : m_peaks[j]; } } } @@ -250,27 +265,17 @@ void Analyzer::process (short *left, short *right) void Analyzer::draw (QPainter *p) { QBrush brush(Qt::SolidPattern); - //m_x_steps = (width() - 2) / m_cell_size.width() / 2; - //m_y_steps = (height() - 2) / m_cell_size.height(); - for (int j = 0; j < m_cols; ++j) - { - for (int i = 0; i <= m_intern_vis_data[j]; ++i) - { - if (i <= m_rows/3) - brush.setColor(m_color1); - else if (i > m_rows/3 && i <= 2 * m_rows / 3) - brush.setColor(m_color2); - else - brush.setColor(m_color3); + int x = 0; + int rdx = qMax(0, width() - 2 * m_cell_size.width() * m_cols); + for (int j = 0; j < m_cols * 2; ++j) + { + x = j * m_cell_size.width() + 1; + if(j >= m_cols) + x += rdx; //correct right part position - p->fillRect (j* m_cell_size.width() +1, height() - i*m_cell_size.height() + 1, - m_cell_size.width() -2, m_cell_size.height() - 2, brush); - } - - for (int i = 0; i <= m_intern_vis_data[m_cols+j]; ++i) + for (int i = 0; i <= m_intern_vis_data[j]; ++i) { - if (i <= m_rows/3) brush.setColor(m_color1); else if (i > m_rows/3 && i <= 2 * m_rows / 3) @@ -278,22 +283,19 @@ void Analyzer::draw (QPainter *p) else brush.setColor(m_color3); - p->fillRect (width() / 2 + j* m_cell_size.width() +1, height() - i*m_cell_size.height() + 1, - m_cell_size.width() -2, m_cell_size.height() - 2, brush); + p->fillRect (x, height() - i * m_cell_size.height() + 1, + m_cell_size.width() - 2, m_cell_size.height() - 2, brush); } if (m_show_peaks) { - p->fillRect (j* m_cell_size.width() +1, height() - int(m_peaks[j])*m_cell_size.height() + 1, - m_cell_size.width() -2, m_cell_size.height() - 2, m_peakColor); - - p->fillRect (width() / 2 + j* m_cell_size.width() +1, - height() - int(m_peaks[m_cols+j])*m_cell_size.height() + 1, - m_cell_size.width() -2, m_cell_size.height() - 2, m_peakColor); - - - //p->fillRect (j*15+1, height() - int(m_peaks[j])*7, 12, 4, m_peakColor); - //p->fillRect ((j+19)*15+1, height() - int(m_peaks[j+19])*7, 12, 4, m_peakColor); + p->fillRect (x, height() - int(m_peaks[j])*m_cell_size.height() + 1, + m_cell_size.width() - 2, m_cell_size.height() - 2, m_peakColor); } } } + +void Analyzer::toggleFullScreen() +{ + setWindowState(windowState() ^Qt::WindowFullScreen); +} |
