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:
parent
a81c5fdf90
commit
aa20b6b3e2
@ -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();
|
||||
}
|
||||
|
@ -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_;
|
||||
};
|
||||
|
||||
|
||||
|
@ -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 );
|
||||
|
||||
|
@ -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& );
|
||||
|
||||
/**
|
||||
|
@ -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
|
||||
// . . . . # .
|
||||
|
@ -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& );
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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 );
|
||||
|
@ -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++];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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_);
|
||||
}
|
||||
|
||||
|
@ -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*);
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
};
|
||||
|
@ -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 ""
|
||||
|
||||
|
@ -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 ""
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user