Let nyanalyzer cat nap inbetween songs
This commit is contained in:
parent
aff1cc5339
commit
41d8c61e0d
BIN
data/nyancat.png
BIN
data/nyancat.png
Binary file not shown.
Before Width: | Height: | Size: 1012 B After Width: | Height: | Size: 1.2 KiB |
@ -49,6 +49,7 @@ Analyzer::Base::Base( QWidget *parent, uint scopeSize )
|
|||||||
, m_engine(NULL)
|
, m_engine(NULL)
|
||||||
, m_lastScope(512)
|
, m_lastScope(512)
|
||||||
, new_frame_(false)
|
, new_frame_(false)
|
||||||
|
, is_playing_(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,16 +82,14 @@ void Analyzer::Base::transform( Scope &scope ) //virtual
|
|||||||
|
|
||||||
void Analyzer::Base::paintEvent(QPaintEvent * e)
|
void Analyzer::Base::paintEvent(QPaintEvent * e)
|
||||||
{
|
{
|
||||||
EngineBase *engine = m_engine;
|
|
||||||
|
|
||||||
QPainter p(this);
|
QPainter p(this);
|
||||||
p.fillRect(e->rect(), palette().color(QPalette::Window));
|
p.fillRect(e->rect(), palette().color(QPalette::Window));
|
||||||
|
|
||||||
switch( engine->state() )
|
switch( m_engine->state() )
|
||||||
{
|
{
|
||||||
case Engine::Playing:
|
case Engine::Playing:
|
||||||
{
|
{
|
||||||
const Engine::Scope &thescope = engine->scope();
|
const Engine::Scope &thescope = m_engine->scope();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
// convert to mono here - our built in analyzers need mono, but we the engines provide interleaved pcm
|
// convert to mono here - our built in analyzers need mono, but we the engines provide interleaved pcm
|
||||||
@ -100,6 +99,7 @@ void Analyzer::Base::paintEvent(QPaintEvent * e)
|
|||||||
i += 2;
|
i += 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
is_playing_ = true;
|
||||||
transform( m_lastScope );
|
transform( m_lastScope );
|
||||||
analyze( p, m_lastScope, new_frame_ );
|
analyze( p, m_lastScope, new_frame_ );
|
||||||
|
|
||||||
@ -108,13 +108,16 @@ void Analyzer::Base::paintEvent(QPaintEvent * e)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Engine::Paused:
|
case Engine::Paused:
|
||||||
|
is_playing_ = false;
|
||||||
analyze(p, m_lastScope, new_frame_);
|
analyze(p, m_lastScope, new_frame_);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
is_playing_ = false;
|
||||||
demo(p);
|
demo(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
new_frame_ = false;
|
new_frame_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,9 +155,6 @@ int Analyzer::Base::resizeForBands( int bands )
|
|||||||
return m_fht->size() / 2;
|
return m_fht->size() / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Analyzer::Base::paused(QPainter&) //virtual
|
|
||||||
{}
|
|
||||||
|
|
||||||
void Analyzer::Base::demo(QPainter& p) //virtual
|
void Analyzer::Base::demo(QPainter& p) //virtual
|
||||||
{
|
{
|
||||||
static int t = 201; //FIXME make static to namespace perhaps
|
static int t = 201; //FIXME make static to namespace perhaps
|
||||||
|
@ -68,7 +68,6 @@ protected:
|
|||||||
virtual void init() {}
|
virtual void init() {}
|
||||||
virtual void transform( Scope& );
|
virtual void transform( Scope& );
|
||||||
virtual void analyze( QPainter& p, const Scope&, bool new_frame) = 0;
|
virtual void analyze( QPainter& p, const Scope&, bool new_frame) = 0;
|
||||||
virtual void paused(QPainter& p);
|
|
||||||
virtual void demo(QPainter& p);
|
virtual void demo(QPainter& p);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -79,6 +78,7 @@ protected:
|
|||||||
Scope m_lastScope;
|
Scope m_lastScope;
|
||||||
|
|
||||||
bool new_frame_;
|
bool new_frame_;
|
||||||
|
bool is_playing_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -78,7 +78,8 @@ void NyanCatAnalyzer::analyze(QPainter& p, const Analyzer::Scope& s, bool new_fr
|
|||||||
// Discard the second half of the transform
|
// Discard the second half of the transform
|
||||||
const int scope_size = s.size() / 2;
|
const int scope_size = s.size() / 2;
|
||||||
|
|
||||||
if (new_frame) {
|
if ((new_frame && is_playing_) ||
|
||||||
|
(buffer_[0].isNull() && buffer_[1].isNull())) {
|
||||||
// Transform the music into rainbows!
|
// Transform the music into rainbows!
|
||||||
for (int band=0 ; band<kRainbowBands ; ++band) {
|
for (int band=0 ; band<kRainbowBands ; ++band) {
|
||||||
float* band_start = history_ + band * kHistorySize;
|
float* band_start = history_ + band * kHistorySize;
|
||||||
@ -161,7 +162,10 @@ void NyanCatAnalyzer::analyze(QPainter& p, const Analyzer::Scope& s, bool new_fr
|
|||||||
|
|
||||||
// Draw nyan cat (he's been waiting for this for 75 lines).
|
// Draw nyan cat (he's been waiting for this for 75 lines).
|
||||||
// Nyan nyan nyan nyan.
|
// Nyan nyan nyan nyan.
|
||||||
QRect cat_dest(width() - kCatWidth, (height() - kCatHeight) / 2,
|
if (!is_playing_) {
|
||||||
kCatWidth, kCatHeight);
|
// Ssshhh!
|
||||||
p.drawPixmap(cat_dest, cat_, CatSourceRect());
|
p.drawPixmap(SleepingCatDestRect(), cat_, SleepingCatSourceRect());
|
||||||
|
} else {
|
||||||
|
p.drawPixmap(CatDestRect(), cat_, CatSourceRect());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,8 +40,9 @@ protected:
|
|||||||
private:
|
private:
|
||||||
static const int kCatHeight = 21;
|
static const int kCatHeight = 21;
|
||||||
static const int kCatWidth = 34;
|
static const int kCatWidth = 34;
|
||||||
static const int kCatFrameCount = 5;
|
static const int kCatFrameCount = 6;
|
||||||
static const int kRainbowOverlap = 13;
|
static const int kRainbowOverlap = 13;
|
||||||
|
static const int kSleepingCatHeight = 24;
|
||||||
|
|
||||||
static const int kHistorySize = 128;
|
static const int kHistorySize = 128;
|
||||||
static const int kRainbowBands = 6;
|
static const int kRainbowBands = 6;
|
||||||
@ -54,6 +55,20 @@ private:
|
|||||||
return QRect(0, kCatHeight * frame_, kCatWidth, kCatHeight);
|
return QRect(0, kCatHeight * frame_, kCatWidth, kCatHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline QRect SleepingCatSourceRect() const {
|
||||||
|
return QRect(0, kCatHeight * kCatFrameCount, kCatWidth, kSleepingCatHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline QRect CatDestRect() const {
|
||||||
|
return QRect(width() - kCatWidth, (height() - kCatHeight) / 2,
|
||||||
|
kCatWidth, kCatHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline QRect SleepingCatDestRect() const {
|
||||||
|
return QRect(width() - kCatWidth, (height() - kSleepingCatHeight) / 2,
|
||||||
|
kCatWidth, kSleepingCatHeight);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// "constants" that get initialised in the constructor
|
// "constants" that get initialised in the constructor
|
||||||
float band_scale_[kRainbowBands];
|
float band_scale_[kRainbowBands];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user