2009-12-24 20:16:07 +01:00
|
|
|
//
|
|
|
|
// Amarok BarAnalyzer 3 - Jet Turbine: Symmetric version of analyzer 1
|
|
|
|
//
|
|
|
|
// Author: Stanislav Karchebny <berkus@users.sf.net>, (C) 2003
|
|
|
|
// Max Howell (I modified it to use boom analyzer code)
|
|
|
|
//
|
|
|
|
// Copyright: like rest of Amarok
|
|
|
|
//
|
|
|
|
|
|
|
|
#include <cmath>
|
2010-03-22 14:49:08 +01:00
|
|
|
#include <QPainter>
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
#include "turbine.h"
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
const char* TurbineAnalyzer::kName =
|
|
|
|
QT_TRANSLATE_NOOP("AnalyzerContainer", "Turbine");
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void TurbineAnalyzer::analyze(QPainter& p, const Scope& scope, bool new_frame) {
|
2014-04-27 07:54:42 +02:00
|
|
|
if (!new_frame) {
|
|
|
|
p.drawPixmap(0, 0, canvas_);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
float h;
|
|
|
|
const uint hd2 = height() / 2;
|
|
|
|
const uint MAX_HEIGHT = hd2 - 1;
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2014-04-27 07:54:42 +02:00
|
|
|
QPainter canvas_painter(&canvas_);
|
|
|
|
canvas_.fill(palette().color(QPalette::Background));
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
for (uint i = 0, x = 0, y; i < BAND_COUNT; ++i, x += COLUMN_WIDTH + 1) {
|
|
|
|
h = log10(scope[i] * 256.0) * F * 0.5;
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
if (h > MAX_HEIGHT) h = MAX_HEIGHT;
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
if (h > bar_height[i]) {
|
|
|
|
bar_height[i] = h;
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
if (h > peak_height[i]) {
|
|
|
|
peak_height[i] = h;
|
|
|
|
peak_speed[i] = 0.01;
|
|
|
|
} else
|
|
|
|
goto peak_handling;
|
|
|
|
} else {
|
|
|
|
if (bar_height[i] > 0.0) {
|
|
|
|
bar_height[i] -= K_barHeight; // 1.4
|
|
|
|
if (bar_height[i] < 0.0) bar_height[i] = 0.0;
|
|
|
|
}
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
peak_handling:
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
if (peak_height[i] > 0.0) {
|
|
|
|
peak_height[i] -= peak_speed[i];
|
|
|
|
peak_speed[i] *= F_peakSpeed; // 1.12
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
if (peak_height[i] < bar_height[i]) peak_height[i] = bar_height[i];
|
|
|
|
if (peak_height[i] < 0.0) peak_height[i] = 0.0;
|
|
|
|
}
|
|
|
|
}
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
y = hd2 - uint(bar_height[i]);
|
2014-04-27 07:54:42 +02:00
|
|
|
canvas_painter.drawPixmap(x + 1, y, barPixmap, 0, y, -1, -1);
|
|
|
|
canvas_painter.drawPixmap(x + 1, hd2, barPixmap, 0, int(bar_height[i]), -1,
|
|
|
|
-1);
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2014-04-27 07:54:42 +02:00
|
|
|
canvas_painter.setPen(palette().color(QPalette::Highlight));
|
2014-02-07 16:34:20 +01:00
|
|
|
if (bar_height[i] > 0)
|
2014-04-27 07:54:42 +02:00
|
|
|
canvas_painter.drawRect(x, y, COLUMN_WIDTH - 1,
|
|
|
|
(int)bar_height[i] * 2 - 1);
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
const uint x2 = x + COLUMN_WIDTH - 1;
|
2014-04-27 07:54:42 +02:00
|
|
|
canvas_painter.setPen(palette().color(QPalette::Base));
|
2014-02-07 16:34:20 +01:00
|
|
|
y = hd2 - uint(peak_height[i]);
|
2014-04-27 07:54:42 +02:00
|
|
|
canvas_painter.drawLine(x, y, x2, y);
|
2014-02-07 16:34:20 +01:00
|
|
|
y = hd2 + uint(peak_height[i]);
|
2014-04-27 07:54:42 +02:00
|
|
|
canvas_painter.drawLine(x, y, x2, y);
|
2014-02-07 16:34:20 +01:00
|
|
|
}
|
2014-04-27 07:54:42 +02:00
|
|
|
|
|
|
|
p.drawPixmap(0, 0, canvas_);
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|