Merge pull request #4313 from TheUbuntuGuy/master

Fix analyzer framerate when mouseover play scrubber.  Fixes ##2504
This commit is contained in:
David Sansome 2014-04-27 16:51:36 +10:00
commit ec0565d07d
8 changed files with 78 additions and 28 deletions

View File

@ -20,12 +20,7 @@ const char* BarAnalyzer::kName =
QT_TRANSLATE_NOOP("AnalyzerContainer", "Bar analyzer");
BarAnalyzer::BarAnalyzer(QWidget* parent)
: Analyzer::Base(parent, 8)
//, m_bands( BAND_COUNT )
//, barVector( BAND_COUNT, 0 )
//, roofVector( BAND_COUNT, 50 )
//, roofVelocityVector( BAND_COUNT, ROOF_VELOCITY_REDUCTION_FACTOR )
{
: Analyzer::Base(parent, 8) {
// roof pixmaps don't depend on size() so we do in the ctor
m_bg = parent->palette().color(QPalette::Background);
@ -69,6 +64,8 @@ void BarAnalyzer::init() {
m_pixBarGradient = QPixmap(height() * COLUMN_WIDTH, height());
m_pixCompose = QPixmap(size());
canvas_ = QPixmap(size());
canvas_.fill(palette().color(QPalette::Background));
QPainter p(&m_pixBarGradient);
for (int x = 0, r = 0x40, g = 0x30, b = 0xff, r2 = 255 - r; x < height();
@ -88,10 +85,17 @@ void BarAnalyzer::init() {
}
void BarAnalyzer::analyze(QPainter& p, const Scope& s, bool new_frame) {
if (!new_frame) {
p.drawPixmap(0, 0, canvas_);
return;
}
// Analyzer::interpolate( s, m_bands );
Scope& v = m_scope;
Analyzer::interpolate(s, v);
QPainter canvas_painter(&canvas_);
canvas_.fill(palette().color(QPalette::Background));
for (uint i = 0, x = 0, y2; i < v.size(); ++i, x += COLUMN_WIDTH + 1) {
// assign pre[log10]'d value
@ -134,11 +138,12 @@ void BarAnalyzer::analyze(QPainter& p, const Scope& s, bool new_frame) {
// );
// bitBlt( canvas(), x, m_roofMem[i][c], &m_pixRoof[ NUM_ROOFS - 1 - c ]
// );
p.drawPixmap(x, m_roofMem[i][c], m_pixRoof[NUM_ROOFS - 1 - c]);
canvas_painter.drawPixmap(x, m_roofMem[i][c],
m_pixRoof[NUM_ROOFS - 1 - c]);
// blt the bar
p.drawPixmap(x, height() - y2, *gradient(), y2 * COLUMN_WIDTH,
height() - y2, COLUMN_WIDTH, y2);
canvas_painter.drawPixmap(x, height() - y2, *gradient(), y2 * COLUMN_WIDTH,
height() - y2, COLUMN_WIDTH, y2);
/*bitBlt( canvas(), x, height() - y2,
gradient(), y2 * COLUMN_WIDTH, height() - y2, COLUMN_WIDTH, y2,
Qt::CopyROP );*/
@ -158,4 +163,6 @@ void BarAnalyzer::analyze(QPainter& p, const Scope& s, bool new_frame) {
++roofVelocityVector[i];
}
}
p.drawPixmap(0, 0, canvas_);
}

View File

@ -52,6 +52,7 @@ class BarAnalyzer : public Analyzer::Base {
private:
QPixmap m_pixBarGradient;
QPixmap m_pixCompose;
QPixmap canvas_;
Scope m_scope; // so we don't create a vector every frame
QColor m_bg;
};

View File

@ -58,6 +58,7 @@ void BlockAnalyzer::resizeEvent(QResizeEvent* e) {
QWidget::resizeEvent(e);
m_background = QPixmap(size());
canvas_ = QPixmap(size());
const uint oldRows = m_rows;
@ -135,10 +136,17 @@ void BlockAnalyzer::analyze(QPainter& p, const Analyzer::Scope& s,
// m_yscale looks similar to: { 0.7, 0.5, 0.25, 0.15, 0.1, 0 }
// if it contains 6 elements there are 5 rows in the analyzer
if (!new_frame) {
p.drawPixmap(0, 0, canvas_);
return;
}
QPainter canvas_painter(&canvas_);
Analyzer::interpolate(s, m_scope);
// Paint the background
p.drawPixmap(0, 0, m_background);
canvas_painter.drawPixmap(0, 0, m_background);
for (uint y, x = 0; x < m_scope.size(); ++x) {
// determine y
@ -163,21 +171,24 @@ void BlockAnalyzer::analyze(QPainter& p, const Analyzer::Scope& s,
if (m_fade_intensity[x] > 0) {
const uint offset = --m_fade_intensity[x];
const uint y = m_y + (m_fade_pos[x] * (HEIGHT + 1));
p.drawPixmap(x * (WIDTH + 1), y, m_fade_bars[offset], 0, 0, WIDTH,
height() - y);
canvas_painter.drawPixmap(x * (WIDTH + 1), y, m_fade_bars[offset], 0, 0,
WIDTH, height() - y);
}
if (m_fade_intensity[x] == 0) m_fade_pos[x] = m_rows;
// REMEMBER: y is a number from 0 to m_rows, 0 means all blocks are glowing,
// m_rows means none are
p.drawPixmap(x * (WIDTH + 1), y * (HEIGHT + 1) + m_y, *bar(), 0,
y * (HEIGHT + 1), bar()->width(), bar()->height());
canvas_painter.drawPixmap(x * (WIDTH + 1), y * (HEIGHT + 1) + m_y, *bar(),
0, y * (HEIGHT + 1), bar()->width(),
bar()->height());
}
for (uint x = 0; x < m_store.size(); ++x)
p.drawPixmap(x * (WIDTH + 1), int(m_store[x]) * (HEIGHT + 1) + m_y,
m_topBarPixmap);
canvas_painter.drawPixmap(
x * (WIDTH + 1), int(m_store[x]) * (HEIGHT + 1) + m_y, m_topBarPixmap);
p.drawPixmap(0, 0, canvas_);
}
static inline void adjustToLimits(int& b, int& f, uint& amount) {

View File

@ -48,6 +48,7 @@ class BlockAnalyzer : public Analyzer::Base {
QPixmap m_barPixmap;
QPixmap m_topBarPixmap;
QPixmap m_background;
QPixmap canvas_;
Scope m_scope; // so we don't create a vector every frame
std::vector<float> m_store; // current bar heights
std::vector<float> m_yscale;

View File

@ -37,6 +37,8 @@ void BoomAnalyzer::init() {
F = double(HEIGHT) / (log10(256) * 1.1 /*<- max. amplitude*/);
barPixmap = QPixmap(COLUMN_WIDTH - 2, HEIGHT);
canvas_ = QPixmap(size());
canvas_.fill(palette().color(QPalette::Background));
QPainter p(&barPixmap);
for (uint y = 0; y < HEIGHT; ++y) {
@ -69,9 +71,16 @@ void BoomAnalyzer::transform(Scope& s) {
}
void BoomAnalyzer::analyze(QPainter& p, const Scope& scope, bool new_frame) {
if (!new_frame) {
p.drawPixmap(0, 0, canvas_);
return;
}
float h;
const uint MAX_HEIGHT = height() - 1;
QPainter canvas_painter(&canvas_);
canvas_.fill(palette().color(QPalette::Background));
for (uint i = 0, x = 0, y; i < BAND_COUNT; ++i, x += COLUMN_WIDTH + 1) {
h = log10(scope[i] * 256.0) * F;
@ -103,12 +112,15 @@ void BoomAnalyzer::analyze(QPainter& p, const Scope& scope, bool new_frame) {
}
y = height() - uint(bar_height[i]);
p.drawPixmap(x + 1, y, barPixmap, 0, y, -1, -1);
p.setPen(palette().color(QPalette::Highlight));
if (bar_height[i] > 0) p.drawRect(x, y, COLUMN_WIDTH - 1, height() - y - 1);
canvas_painter.drawPixmap(x + 1, y, barPixmap, 0, y, -1, -1);
canvas_painter.setPen(palette().color(QPalette::Highlight));
if (bar_height[i] > 0)
canvas_painter.drawRect(x, y, COLUMN_WIDTH - 1, height() - y - 1);
y = height() - uint(peak_height[i]);
p.setPen(palette().color(QPalette::Base));
p.drawLine(x, y, x + COLUMN_WIDTH - 1, y);
canvas_painter.setPen(palette().color(QPalette::Base));
canvas_painter.drawLine(x, y, x + COLUMN_WIDTH - 1, y);
}
p.drawPixmap(0, 0, canvas_);
}

View File

@ -39,6 +39,7 @@ class BoomAnalyzer : public Analyzer::Base {
std::vector<float> peak_speed;
QPixmap barPixmap;
QPixmap canvas_;
};
#endif

View File

@ -35,6 +35,11 @@ void Sonogram::resizeEvent(QResizeEvent* e) {
}
void Sonogram::analyze(QPainter& p, const Scope& s, bool new_frame) {
if (!new_frame) {
p.drawPixmap(0, 0, canvas_);
return;
}
int x = width() - 1;
QColor c;

View File

@ -16,10 +16,18 @@ const char* TurbineAnalyzer::kName =
QT_TRANSLATE_NOOP("AnalyzerContainer", "Turbine");
void TurbineAnalyzer::analyze(QPainter& p, const Scope& scope, bool new_frame) {
if (!new_frame) {
p.drawPixmap(0, 0, canvas_);
return;
}
float h;
const uint hd2 = height() / 2;
const uint MAX_HEIGHT = hd2 - 1;
QPainter canvas_painter(&canvas_);
canvas_.fill(palette().color(QPalette::Background));
for (uint i = 0, x = 0, y; i < BAND_COUNT; ++i, x += COLUMN_WIDTH + 1) {
h = log10(scope[i] * 256.0) * F * 0.5;
@ -51,18 +59,22 @@ void TurbineAnalyzer::analyze(QPainter& p, const Scope& scope, bool new_frame) {
}
y = hd2 - uint(bar_height[i]);
p.drawPixmap(x + 1, y, barPixmap, 0, y, -1, -1);
p.drawPixmap(x + 1, hd2, barPixmap, 0, int(bar_height[i]), -1, -1);
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);
p.setPen(palette().color(QPalette::Highlight));
canvas_painter.setPen(palette().color(QPalette::Highlight));
if (bar_height[i] > 0)
p.drawRect(x, y, COLUMN_WIDTH - 1, (int)bar_height[i] * 2 - 1);
canvas_painter.drawRect(x, y, COLUMN_WIDTH - 1,
(int)bar_height[i] * 2 - 1);
const uint x2 = x + COLUMN_WIDTH - 1;
p.setPen(palette().color(QPalette::Base));
canvas_painter.setPen(palette().color(QPalette::Base));
y = hd2 - uint(peak_height[i]);
p.drawLine(x, y, x2, y);
canvas_painter.drawLine(x, y, x2, y);
y = hd2 + uint(peak_height[i]);
p.drawLine(x, y, x2, y);
canvas_painter.drawLine(x, y, x2, y);
}
p.drawPixmap(0, 0, canvas_);
}