1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-16 19:31:02 +01:00

Don't shift the rainbow data along when the widget is being repainted as a result of an expose event

This commit is contained in:
David Sansome 2011-06-23 20:36:14 +00:00
parent a81c5fdf90
commit aa20b6b3e2
16 changed files with 56 additions and 36 deletions

View File

@ -48,6 +48,7 @@ Analyzer::Base::Base( QWidget *parent, uint scopeSize )
, m_fht( new FHT(scopeSize) )
, m_engine(NULL)
, m_lastScope(512)
, new_frame_(false)
{
}
@ -100,19 +101,21 @@ void Analyzer::Base::paintEvent(QPaintEvent * e)
}
transform( m_lastScope );
analyze( p, m_lastScope );
analyze( p, m_lastScope, new_frame_ );
//scope.resize( m_fht->size() );
break;
}
case Engine::Paused:
analyze(p, m_lastScope);
analyze(p, m_lastScope, new_frame_);
break;
default:
demo(p);
}
new_frame_ = false;
}
int Analyzer::Base::resizeExponent( int exp )
@ -165,9 +168,9 @@ void Analyzer::Base::demo(QPainter& p) //virtual
for( uint i = 0; i < s.size(); ++i )
s[i] = dt * (sin( M_PI + (i * M_PI) / s.size() ) + 1.0);
analyze( p, s );
analyze( p, s, new_frame_ );
}
else analyze( p, Scope( 32, 0 ) );
else analyze( p, Scope( 32, 0 ), new_frame_ );
++t;
}
@ -222,5 +225,6 @@ void Analyzer::Base::timerEvent(QTimerEvent* e) {
if (e->timerId() != m_timer.timerId())
return;
new_frame_ = true;
update();
}

View File

@ -67,7 +67,7 @@ protected:
int resizeForBands( int );
virtual void init() {}
virtual void transform( Scope& );
virtual void analyze( QPainter& p, const Scope& ) = 0;
virtual void analyze( QPainter& p, const Scope&, bool new_frame) = 0;
virtual void paused(QPainter& p);
virtual void demo(QPainter& p);
@ -77,6 +77,8 @@ protected:
FHT *m_fht;
EngineBase* m_engine;
Scope m_lastScope;
bool new_frame_;
};

View File

@ -94,7 +94,7 @@ void BarAnalyzer::init()
}
void BarAnalyzer::analyze( QPainter& p, const Scope &s )
void BarAnalyzer::analyze( QPainter& p, const Scope &s, bool new_frame)
{
//Analyzer::interpolate( s, m_bands );

View File

@ -18,7 +18,7 @@ class BarAnalyzer : public Analyzer::Base
Q_INVOKABLE BarAnalyzer( QWidget* );
void init();
virtual void analyze( QPainter& p, const Scope& );
virtual void analyze( QPainter& p, const Scope&, bool new_frame);
//virtual void transform( Scope& );
/**

View File

@ -117,7 +117,7 @@ BlockAnalyzer::transform( Analyzer::Scope &s ) //pure virtual
}
void
BlockAnalyzer::analyze( QPainter& p, const Analyzer::Scope &s )
BlockAnalyzer::analyze( QPainter& p, const Analyzer::Scope &s, bool new_frame)
{
// y = 2 3 2 1 0 2
// . . . . # .

View File

@ -35,7 +35,7 @@ public:
protected:
virtual void transform( Scope& );
virtual void analyze( QPainter& p, const Scope& );
virtual void analyze( QPainter& p, const Scope&, bool new_frame);
virtual void resizeEvent( QResizeEvent* );
virtual void paletteChange( const QPalette& );

View File

@ -79,7 +79,7 @@ BoomAnalyzer::transform( Scope &s )
}
void
BoomAnalyzer::analyze( QPainter& p, const Scope& scope )
BoomAnalyzer::analyze( QPainter& p, const Scope& scope, bool new_frame)
{
float h;
const uint MAX_HEIGHT = height() - 1;

View File

@ -21,7 +21,7 @@ public:
virtual void init();
virtual void transform( Scope &s );
virtual void analyze( QPainter& p, const Scope& );
virtual void analyze( QPainter& p, const Scope&, bool new_frame);
public slots:
void changeK_barHeight( int );

View File

@ -53,30 +53,32 @@ void NyanCatAnalyzer::timerEvent(QTimerEvent* e) {
}
}
void NyanCatAnalyzer::analyze(QPainter& p, const Analyzer::Scope& s) {
void NyanCatAnalyzer::analyze(QPainter& p, const Analyzer::Scope& s, bool new_frame) {
// Discard the second half of the transform
const int scope_size = s.size() / 2;
// Transform the music into rainbows!
for (int band=0 ; band<kRainbowBands ; ++band) {
float* band_start = history_ + band * kHistorySize;
if (new_frame) {
// Transform the music into rainbows!
for (int band=0 ; band<kRainbowBands ; ++band) {
float* band_start = history_ + band * kHistorySize;
// Move the history of each band across by 1 frame.
memmove(band_start, band_start + 1, (kHistorySize - 1) * sizeof(float));
// Move the history of each band across by 1 frame.
memmove(band_start, band_start + 1, (kHistorySize - 1) * sizeof(float));
// And set the new frame to 0.
band_start[kHistorySize-1] = 0;
}
// And set the new frame to 0.
band_start[kHistorySize-1] = 0;
}
// Now accumulate the scope data into each band. Should maybe use a series
// of band pass filters for this, so bands can leak into neighbouring bands,
// but for now it's a series of separate square filters.
const int samples_per_band = scope_size / kRainbowBands;
int sample = 0;
for (int band=0 ; band<kRainbowBands ; ++band) {
float* accumulator = &history_[(band+1) * kHistorySize - 1];
for (int i=0 ; i<samples_per_band ; ++i) {
*accumulator += s[sample++];
// Now accumulate the scope data into each band. Should maybe use a series
// of band pass filters for this, so bands can leak into neighbouring bands,
// but for now it's a series of separate square filters.
const int samples_per_band = scope_size / kRainbowBands;
int sample = 0;
for (int band=0 ; band<kRainbowBands ; ++band) {
float* accumulator = &history_[(band+1) * kHistorySize - 1];
for (int i=0 ; i<samples_per_band ; ++i) {
*accumulator += s[sample++];
}
}
}

View File

@ -33,8 +33,8 @@ public:
void timerEvent(QTimerEvent* e);
protected:
void transform( Scope& );
void analyze( QPainter& p, const Analyzer::Scope& );
void transform(Scope&);
void analyze(QPainter& p, const Analyzer::Scope&, bool new_frame);
private:
static const int kCatHeight = 21;

View File

@ -42,7 +42,7 @@ void Sonogram::resizeEvent(QResizeEvent *e)
}
void Sonogram::analyze(QPainter& p, const Scope &s)
void Sonogram::analyze(QPainter& p, const Scope &s, bool new_frame)
{
int x = width() - 1;
QColor c;
@ -85,6 +85,6 @@ void Sonogram::transform(Scope &scope)
void Sonogram::demo(QPainter& p)
{
analyze(p, Scope(m_fht->size(), 0));
analyze(p, Scope(m_fht->size(), 0), new_frame_);
}

View File

@ -30,7 +30,7 @@ public:
static const char* kName;
protected:
void analyze(QPainter& p, const Scope&);
void analyze(QPainter& p, const Scope&, bool new_frame);
void transform(Scope&);
void demo(QPainter& p);
void resizeEvent(QResizeEvent*);

View File

@ -14,7 +14,7 @@
const char* TurbineAnalyzer::kName = QT_TRANSLATE_NOOP("AnalyzerContainer", "Turbine");
void TurbineAnalyzer::analyze( QPainter& p, const Scope &scope )
void TurbineAnalyzer::analyze( QPainter& p, const Scope &scope, bool new_frame)
{
float h;
const uint hd2 = height() / 2;

View File

@ -17,7 +17,7 @@ class TurbineAnalyzer : public BoomAnalyzer
public:
Q_INVOKABLE TurbineAnalyzer( QWidget *parent ) : BoomAnalyzer( parent ) {}
void analyze( QPainter& p, const Scope& );
void analyze( QPainter& p, const Scope&, bool new_frame);
static const char* kName;
};

View File

@ -1748,6 +1748,9 @@ msgstr ""
msgid "Most played"
msgstr ""
msgid "Mount point"
msgstr ""
msgid "Mount points"
msgstr ""
@ -2859,6 +2862,9 @@ msgstr ""
msgid "Turn off"
msgstr ""
msgid "URI"
msgstr ""
msgid "URL(s)"
msgstr ""

View File

@ -1738,6 +1738,9 @@ msgstr ""
msgid "Most played"
msgstr ""
msgid "Mount point"
msgstr ""
msgid "Mount points"
msgstr ""
@ -2849,6 +2852,9 @@ msgstr ""
msgid "Turn off"
msgstr ""
msgid "URI"
msgstr ""
msgid "URL(s)"
msgstr ""