From dad22297d1443d3fce02a534d332bbe535afae70 Mon Sep 17 00:00:00 2001 From: David Sansome Date: Wed, 22 Jun 2011 23:25:08 +0000 Subject: [PATCH] Add a nyan cat analyzer. Nyan nyan nyan nyan. --- data/data.qrc | 1 + data/nyancat.png | Bin 0 -> 1012 bytes src/CMakeLists.txt | 2 + src/analyzers/analyzercontainer.cpp | 3 + src/analyzers/nyancatanalyzer.cpp | 110 ++++++++++++++++++++++++++++ src/analyzers/nyancatanalyzer.h | 67 +++++++++++++++++ 6 files changed, 183 insertions(+) create mode 100644 data/nyancat.png create mode 100644 src/analyzers/nyancatanalyzer.cpp create mode 100644 src/analyzers/nyancatanalyzer.h diff --git a/data/data.qrc b/data/data.qrc index a4d776abd..3d7d6dabc 100644 --- a/data/data.qrc +++ b/data/data.qrc @@ -339,5 +339,6 @@ pythonlibs/uic/properties.py pythonlibs/uic/uiparser.py pythonlibs/clementinelogging.py + nyancat.png diff --git a/data/nyancat.png b/data/nyancat.png new file mode 100644 index 0000000000000000000000000000000000000000..a129ea0f241f8c9e0b1bf422d93610524dc14174 GIT binary patch literal 1012 zcmVPx#24YJ`L;(K){{a7>y{D4^000SaNLh0L01FcU01FcV0GgZ_00007bV*G`2ipb| z6C5x)*aQ3k00VSML_t(|+U=Wdj_V){MRCNA+BLzNoHb3?#QXDTf!JUJX{r{aYN8<@ z7h~{&IACNYnDGMLl~F|a!*LaNUws~^L_C~c!EG0b*~B;GMC?0#tQ5bgL{JZMjy_h3 z*;HnB^&5f*10L!YdO3eK0IZo*z=J`==W)Qm2@ml+?|q0qvlR-1YN#?TM#S7QMIBXa zd4l&o3WJfZqQr0_G9li3gNOzZQ!%s^oNOf29?Ur_B-W_kpcJw1nSW@?|7$`yYU*OR z5kOey=G^l>(z=bBX}$Nylbw84y~EMH;{B*PZuo*I&=J1kUN&d_CH{@)dclMShj@{8 zPs2i~MY-csf?nyc+yjZJ0$M_zT_eQ+xO?&FNk!Cz1ZnGLfsz#}j~52Ytd&?Iz7B+F zNR1>>w-VQa`Q##1x8Qlf^LN4X0ibz!J^-|xIs_?zZp_>fptqqXS6W;F=s?9IOUxB8 ztE)5sZEI_dQFzt>^d?=2)!>=p5iLMJDL#ef`0It|9)Qj$o`mKOcN4L7dWQ@(3)4C zb0}Mrg@4Wx&KXl+!p%8z2b$`+x{bg?AQ|L>atu4_6(or++XwvhzI3tj~ERTXyQgy_!$n2G2>uK(o?2 i1)jBpHUhuh;QbF3H)b^tB9i9-0000(); AddAnalyzerType(); AddAnalyzerType(); + AddAnalyzerType(); + connect(mapper_, SIGNAL(mapped(int)), SLOT(ChangeAnalyzer(int))); disable_action_ = context_menu_->addAction(tr("No analyzer"), this, SLOT(DisableAnalyzer())); diff --git a/src/analyzers/nyancatanalyzer.cpp b/src/analyzers/nyancatanalyzer.cpp new file mode 100644 index 000000000..f86cdb486 --- /dev/null +++ b/src/analyzers/nyancatanalyzer.cpp @@ -0,0 +1,110 @@ +/* This file is part of Clementine. + Copyright 2010, David Sansome + + Clementine is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Clementine is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Clementine. If not, see . +*/ + +#include "nyancatanalyzer.h" +#include "core/logging.h" + +#include + +#include + +const char* NyanCatAnalyzer::kName = "Nyan nyan nyan"; + + +NyanCatAnalyzer::NyanCatAnalyzer(QWidget* parent) + : Analyzer::Base(parent, 9), + cat_(":/nyancat.png"), + timer_id_(startTimer(kFrameIntervalMs)), + frame_(0) +{ + memset(history_, 0, sizeof(history_)); + + for (int i=0 ; ispectrum(&s.front()); +} + +void NyanCatAnalyzer::timerEvent(QTimerEvent* e) { + if (e->timerId() == timer_id_) { + frame_ = (frame_ + 1) % kCatFrameCount; + } else { + Analyzer::Base::timerEvent(e); + } +} + +void NyanCatAnalyzer::analyze(QPainter& p, const Analyzer::Scope& s) { + // Discard the second half of the transform + const int scope_size = s.size() / 2; + + // Transform the music into rainbows! + for (int band=0 ; band=0 ; --band) { + p.setPen(colors_[band]); + p.drawPolyline(&polyline[band*kHistorySize], kHistorySize); + } + + // Draw nyan cat (he's been waiting for this for 50 lines). + // Nyan nyan nyan nyan. + QRect cat_dest(width() - kCatWidth, (height() - kCatHeight) / 2, + kCatWidth, kCatHeight); + p.drawPixmap(cat_dest, cat_, CatSourceRect()); +} diff --git a/src/analyzers/nyancatanalyzer.h b/src/analyzers/nyancatanalyzer.h new file mode 100644 index 000000000..411f5d320 --- /dev/null +++ b/src/analyzers/nyancatanalyzer.h @@ -0,0 +1,67 @@ +/* This file is part of Clementine. + Copyright 2010, David Sansome + + Clementine is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Clementine is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Clementine. If not, see . +*/ + +#ifndef NYANCATANALYZER_H +#define NYANCATANALYZER_H + +#include "analyzerbase.h" + +#include + + +class NyanCatAnalyzer : public Analyzer::Base { + Q_OBJECT + +public: + Q_INVOKABLE NyanCatAnalyzer(QWidget* parent); + + static const char* kName; + + void timerEvent(QTimerEvent* e); + +protected: + void transform( Scope& ); + void analyze( QPainter& p, const Analyzer::Scope& ); + +private: + static const int kCatHeight = 21; + static const int kCatWidth = 34; + static const int kCatFrameCount = 5; + static const int kRainbowOverlap = 13; + + static const int kHistorySize = 256; + static const int kRainbowBands = 6; + static const float kPixelScale = 0.01; + + static const int kFrameIntervalMs = 150; + +private: + inline QRect CatSourceRect() const { + return QRect(0, kCatHeight * frame_, kCatWidth, kCatHeight); + } + +private: + QPixmap cat_; + + int timer_id_; + int frame_; + + float history_[kHistorySize * kRainbowBands]; + QPen colors_[kRainbowBands]; +}; + +#endif // NYANCATANALYZER_H