Fix analyzer framerate when mouseover play scrubber

This patch prevents the framerate of all analyzers from
increasing beyond the framerate set in the interface at all times.
It however will allow the analyser to redraw as often as required
to prevent artifacting when the play scrubber is drawn in front.
This commit is contained in:
Mark Furneaux 2014-04-27 01:54:42 -04:00
parent f793d09d8e
commit 7d3d0f04cf
8 changed files with 81 additions and 26 deletions

View File

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

View File

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

View File

@ -58,6 +58,7 @@ void BlockAnalyzer::resizeEvent(QResizeEvent* e) {
QWidget::resizeEvent(e); QWidget::resizeEvent(e);
m_background = QPixmap(size()); m_background = QPixmap(size());
canvas_ = QPixmap(size());
const uint oldRows = m_rows; 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 } // 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 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); Analyzer::interpolate(s, m_scope);
// Paint the background // 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) { for (uint y, x = 0; x < m_scope.size(); ++x) {
// determine y // determine y
@ -163,21 +171,24 @@ void BlockAnalyzer::analyze(QPainter& p, const Analyzer::Scope& s,
if (m_fade_intensity[x] > 0) { if (m_fade_intensity[x] > 0) {
const uint offset = --m_fade_intensity[x]; const uint offset = --m_fade_intensity[x];
const uint y = m_y + (m_fade_pos[x] * (HEIGHT + 1)); const uint y = m_y + (m_fade_pos[x] * (HEIGHT + 1));
p.drawPixmap(x * (WIDTH + 1), y, m_fade_bars[offset], 0, 0, WIDTH, canvas_painter.drawPixmap(x * (WIDTH + 1), y, m_fade_bars[offset], 0, 0,
height() - y); WIDTH, height() - y);
} }
if (m_fade_intensity[x] == 0) m_fade_pos[x] = m_rows; 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, // REMEMBER: y is a number from 0 to m_rows, 0 means all blocks are glowing,
// m_rows means none are // m_rows means none are
p.drawPixmap(x * (WIDTH + 1), y * (HEIGHT + 1) + m_y, *bar(), 0, canvas_painter.drawPixmap(x * (WIDTH + 1), y * (HEIGHT + 1) + m_y, *bar(),
y * (HEIGHT + 1), bar()->width(), bar()->height()); 0, y * (HEIGHT + 1), bar()->width(),
bar()->height());
} }
for (uint x = 0; x < m_store.size(); ++x) for (uint x = 0; x < m_store.size(); ++x)
p.drawPixmap(x * (WIDTH + 1), int(m_store[x]) * (HEIGHT + 1) + m_y, canvas_painter.drawPixmap(
m_topBarPixmap); 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) { 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_barPixmap;
QPixmap m_topBarPixmap; QPixmap m_topBarPixmap;
QPixmap m_background; QPixmap m_background;
QPixmap canvas_;
Scope m_scope; // so we don't create a vector every frame Scope m_scope; // so we don't create a vector every frame
std::vector<float> m_store; // current bar heights std::vector<float> m_store; // current bar heights
std::vector<float> m_yscale; std::vector<float> m_yscale;

View File

@ -37,6 +37,8 @@ void BoomAnalyzer::init() {
F = double(HEIGHT) / (log10(256) * 1.1 /*<- max. amplitude*/); F = double(HEIGHT) / (log10(256) * 1.1 /*<- max. amplitude*/);
barPixmap = QPixmap(COLUMN_WIDTH - 2, HEIGHT); barPixmap = QPixmap(COLUMN_WIDTH - 2, HEIGHT);
canvas_ = QPixmap(size());
canvas_.fill(palette().color(QPalette::Background));
QPainter p(&barPixmap); QPainter p(&barPixmap);
for (uint y = 0; y < HEIGHT; ++y) { 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) { void BoomAnalyzer::analyze(QPainter& p, const Scope& scope, bool new_frame) {
if (!new_frame) {
p.drawPixmap(0, 0, canvas_);
return;
}
float h; float h;
const uint MAX_HEIGHT = height() - 1; 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) { for (uint i = 0, x = 0, y; i < BAND_COUNT; ++i, x += COLUMN_WIDTH + 1) {
h = log10(scope[i] * 256.0) * F; 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]); y = height() - uint(bar_height[i]);
p.drawPixmap(x + 1, y, barPixmap, 0, y, -1, -1); canvas_painter.drawPixmap(x + 1, y, barPixmap, 0, y, -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, height() - y - 1); if (bar_height[i] > 0)
canvas_painter.drawRect(x, y, COLUMN_WIDTH - 1, height() - y - 1);
y = height() - uint(peak_height[i]); y = height() - uint(peak_height[i]);
p.setPen(palette().color(QPalette::Base)); canvas_painter.setPen(palette().color(QPalette::Base));
p.drawLine(x, y, x + COLUMN_WIDTH - 1, y); 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; std::vector<float> peak_speed;
QPixmap barPixmap; QPixmap barPixmap;
QPixmap canvas_;
}; };
#endif #endif

View File

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

View File

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