From 7d3d0f04cf454b9637dcc18b59d3300d538e0ead Mon Sep 17 00:00:00 2001 From: Mark Furneaux Date: Sun, 27 Apr 2014 01:54:42 -0400 Subject: [PATCH] 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. --- src/analyzers/baranalyzer.cpp | 26 +++++++++++++++++++------- src/analyzers/baranalyzer.h | 1 + src/analyzers/blockanalyzer.cpp | 25 ++++++++++++++++++------- src/analyzers/blockanalyzer.h | 1 + src/analyzers/boomanalyzer.cpp | 22 +++++++++++++++++----- src/analyzers/boomanalyzer.h | 1 + src/analyzers/sonogram.cpp | 5 +++++ src/analyzers/turbine.cpp | 26 +++++++++++++++++++------- 8 files changed, 81 insertions(+), 26 deletions(-) diff --git a/src/analyzers/baranalyzer.cpp b/src/analyzers/baranalyzer.cpp index c4a39bc54..f61dd8ed1 100644 --- a/src/analyzers/baranalyzer.cpp +++ b/src/analyzers/baranalyzer.cpp @@ -21,10 +21,10 @@ const char* BarAnalyzer::kName = 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 ) +//, m_bands( BAND_COUNT ) +//, barVector( BAND_COUNT, 0 ) +//, roofVector( BAND_COUNT, 50 ) +//, roofVelocityVector( BAND_COUNT, ROOF_VELOCITY_REDUCTION_FACTOR ) { // roof pixmaps don't depend on size() so we do in the ctor m_bg = parent->palette().color(QPalette::Background); @@ -69,6 +69,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 +90,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 +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 ] // ); - 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 +168,6 @@ void BarAnalyzer::analyze(QPainter& p, const Scope& s, bool new_frame) { ++roofVelocityVector[i]; } } + + p.drawPixmap(0, 0, canvas_); } diff --git a/src/analyzers/baranalyzer.h b/src/analyzers/baranalyzer.h index bf6950323..ffe9e27a4 100644 --- a/src/analyzers/baranalyzer.h +++ b/src/analyzers/baranalyzer.h @@ -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; }; diff --git a/src/analyzers/blockanalyzer.cpp b/src/analyzers/blockanalyzer.cpp index e88881aa0..6b4d630f4 100644 --- a/src/analyzers/blockanalyzer.cpp +++ b/src/analyzers/blockanalyzer.cpp @@ -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) { diff --git a/src/analyzers/blockanalyzer.h b/src/analyzers/blockanalyzer.h index 26c8f30cd..d6c6d4ac9 100644 --- a/src/analyzers/blockanalyzer.h +++ b/src/analyzers/blockanalyzer.h @@ -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 m_store; // current bar heights std::vector m_yscale; diff --git a/src/analyzers/boomanalyzer.cpp b/src/analyzers/boomanalyzer.cpp index 07a40e24a..ef5b4092e 100644 --- a/src/analyzers/boomanalyzer.cpp +++ b/src/analyzers/boomanalyzer.cpp @@ -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_); } diff --git a/src/analyzers/boomanalyzer.h b/src/analyzers/boomanalyzer.h index e93b68d12..bb9532735 100644 --- a/src/analyzers/boomanalyzer.h +++ b/src/analyzers/boomanalyzer.h @@ -39,6 +39,7 @@ class BoomAnalyzer : public Analyzer::Base { std::vector peak_speed; QPixmap barPixmap; + QPixmap canvas_; }; #endif diff --git a/src/analyzers/sonogram.cpp b/src/analyzers/sonogram.cpp index e067d32f6..b7e290714 100644 --- a/src/analyzers/sonogram.cpp +++ b/src/analyzers/sonogram.cpp @@ -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; diff --git a/src/analyzers/turbine.cpp b/src/analyzers/turbine.cpp index 63a7d0309..5b00cae94 100644 --- a/src/analyzers/turbine.cpp +++ b/src/analyzers/turbine.cpp @@ -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_); }