From b77cb613e2fca4a7544755cadbf0899191258686 Mon Sep 17 00:00:00 2001 From: narunlifescience Date: Sat, 21 Nov 2015 09:20:47 -0600 Subject: [PATCH] combine nyancatanalyzer & rainbowdashanalyzer(eliminate duplicated code) update minor modifications format add seperate classes for nyancat & dash format minor correction restore previous name Nyanalyzer cat --- src/CMakeLists.txt | 6 +- src/analyzers/analyzercontainer.cpp | 19 +- src/analyzers/analyzercontainer.h | 3 +- ...yancatanalyzer.cpp => rainbowanalyzer.cpp} | 78 +++++--- .../{nyancatanalyzer.h => rainbowanalyzer.h} | 91 ++++++--- src/analyzers/rainbowdashanalyzer.cpp | 182 ------------------ src/analyzers/rainbowdashanalyzer.h | 108 ----------- 7 files changed, 128 insertions(+), 359 deletions(-) rename src/analyzers/{nyancatanalyzer.cpp => rainbowanalyzer.cpp} (66%) rename src/analyzers/{nyancatanalyzer.h => rainbowanalyzer.h} (50%) delete mode 100644 src/analyzers/rainbowdashanalyzer.cpp delete mode 100644 src/analyzers/rainbowdashanalyzer.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e735855db..f1046911b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -69,8 +69,7 @@ set(SOURCES analyzers/baranalyzer.cpp analyzers/blockanalyzer.cpp analyzers/boomanalyzer.cpp - analyzers/nyancatanalyzer.cpp - analyzers/rainbowdashanalyzer.cpp + analyzers/rainbowanalyzer.cpp analyzers/sonogram.cpp analyzers/turbine.cpp analyzers/fht.cpp @@ -402,8 +401,7 @@ set(HEADERS analyzers/baranalyzer.h analyzers/blockanalyzer.h analyzers/boomanalyzer.h - analyzers/nyancatanalyzer.h - analyzers/rainbowdashanalyzer.h + analyzers/rainbowanalyzer.h analyzers/sonogram.h analyzers/turbine.h diff --git a/src/analyzers/analyzercontainer.cpp b/src/analyzers/analyzercontainer.cpp index 46120a4a0..de04bb0bc 100644 --- a/src/analyzers/analyzercontainer.cpp +++ b/src/analyzers/analyzercontainer.cpp @@ -3,8 +3,8 @@ Copyright 2010, 2014, John Maguire Copyright 2011-2012, Arnaud Bienner Copyright 2013, Vasily Fomin - Copyright 2014-2015, Mark Furneaux Copyright 2014, Krzysztof Sobiecki + Copyright 2014-2015, Mark Furneaux Clementine is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -24,14 +24,13 @@ #include "baranalyzer.h" #include "blockanalyzer.h" #include "boomanalyzer.h" -#include "nyancatanalyzer.h" -#include "rainbowdashanalyzer.h" #include "sonogram.h" +#include "rainbowanalyzer.h" #include "turbine.h" #include "core/logging.h" -#include #include +#include #include #include #include @@ -80,8 +79,8 @@ AnalyzerContainer::AnalyzerContainer(QWidget* parent) AddAnalyzerType(); AddAnalyzerType(); AddAnalyzerType(); - AddAnalyzerType(); - AddAnalyzerType(); + AddAnalyzerType(); + AddAnalyzerType(); connect(mapper_, SIGNAL(mapped(int)), SLOT(ChangeAnalyzer(int))); disable_action_ = context_menu_->addAction(tr("No analyzer"), this, @@ -160,7 +159,8 @@ void AnalyzerContainer::TogglePsychedelicColors() { } void AnalyzerContainer::ChangeAnalyzer(int id) { - QObject* instance = analyzer_types_[id]->newInstance(Q_ARG(QWidget*, this)); + QObject* instance = + analyzer_types_[id]->newInstance(Q_ARG(QWidget*, this)); if (!instance) { qLog(Warning) << "Couldn't intialise a new" @@ -229,8 +229,8 @@ void AnalyzerContainer::Load() { } void AnalyzerContainer::SaveFramerate(int framerate) { - // For now, framerate is common for all analyzers. Maybe each analyzer should - // have its own framerate? + // For now, framerate is common for all analyzers. + // Maybe each analyzer should have its own framerate? current_framerate_ = framerate; QSettings s; s.beginGroup(kSettingsGroup); @@ -261,3 +261,4 @@ void AnalyzerContainer::AddFramerate(const QString& name, int framerate) { framerate_list_ << framerate; action->setCheckable(true); } + diff --git a/src/analyzers/analyzercontainer.h b/src/analyzers/analyzercontainer.h index 1a91c6d3d..08835fcd9 100644 --- a/src/analyzers/analyzercontainer.h +++ b/src/analyzers/analyzercontainer.h @@ -99,9 +99,8 @@ template void AnalyzerContainer::AddAnalyzerType() { int id = analyzer_types_.count(); analyzer_types_ << &T::staticMetaObject; - QAction* action = - context_menu_->addAction(tr(T::kName), mapper_, SLOT(map())); + context_menu_->addAction(tr(T::kName), mapper_, SLOT(map())); group_->addAction(action); mapper_->setMapping(action, id); action->setCheckable(true); diff --git a/src/analyzers/nyancatanalyzer.cpp b/src/analyzers/rainbowanalyzer.cpp similarity index 66% rename from src/analyzers/nyancatanalyzer.cpp rename to src/analyzers/rainbowanalyzer.cpp index 2424f5635..c8aa0cf9b 100644 --- a/src/analyzers/nyancatanalyzer.cpp +++ b/src/analyzers/rainbowanalyzer.cpp @@ -1,9 +1,12 @@ /* This file is part of Clementine. Copyright 2011, Tyler Rhodes Copyright 2011-2012, 2014, David Sansome + Copyright 2014, Alibek Omarov Copyright 2014, John Maguire Copyright 2014, Krzysztof Sobiecki - + Copyright 2014-2015, Mark Furneaux + Copyright 2015, Arun Narayanankutty + 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 @@ -18,24 +21,33 @@ along with Clementine. If not, see . */ -#include "nyancatanalyzer.h" +#include "rainbowanalyzer.h" #include #include -#include +#include #include "core/arraysize.h" #include "core/logging.h" using Analyzer::Scope; -const char* NyanCatAnalyzer::kName = "Nyanalyzer cat"; -const float NyanCatAnalyzer::kPixelScale = 0.02f; +const int Rainbow::RainbowAnalyzer::kHeight[] = { 21, 33 }; +const int Rainbow::RainbowAnalyzer::kWidth[] = { 34, 53 }; +const int Rainbow::RainbowAnalyzer::kFrameCount[] = { 6, 16 }; +const int Rainbow::RainbowAnalyzer::kRainbowHeight[] = { 21, 16 }; +const int Rainbow::RainbowAnalyzer::kRainbowOverlap[] = { 13, 15 }; +const int Rainbow::RainbowAnalyzer::kSleepingHeight[] = { 24, 33 }; -NyanCatAnalyzer::NyanCatAnalyzer(QWidget* parent) +const char* Rainbow::NyanCatAnalyzer::kName = "Nyanalyzer Cat"; +const char* Rainbow::RainbowDashAnalyzer::kName = "Rainbow Dash"; +const float Rainbow::RainbowAnalyzer::kPixelScale = 0.02f; + +Rainbow::RainbowAnalyzer::RainbowType Rainbow::RainbowAnalyzer::rainbowtype; + +Rainbow::RainbowAnalyzer::RainbowAnalyzer(const RainbowType& rbtype, QWidget* parent) : Analyzer::Base(parent, 9), - cat_(":/nyancat.png"), timer_id_(startTimer(kFrameIntervalMs)), frame_(0), current_buffer_(0), @@ -43,12 +55,15 @@ NyanCatAnalyzer::NyanCatAnalyzer(QWidget* parent) px_per_frame_(0), x_offset_(0), background_brush_(QColor(0x0f, 0x43, 0x73)) { + rainbowtype = rbtype; + cat_dash_[0] = QPixmap(":/nyancat.png"); + cat_dash_[1] = QPixmap(":/rainbowdash.png"); memset(history_, 0, sizeof(history_)); for (int i = 0; i < kRainbowBands; ++i) { colors_[i] = QPen(QColor::fromHsv(i * 255 / kRainbowBands, 255, 255), - kCatHeight / kRainbowBands, Qt::SolidLine, Qt::FlatCap, - Qt::RoundJoin); + kRainbowHeight[rainbowtype] / kRainbowBands, + Qt::SolidLine, Qt::FlatCap, Qt::RoundJoin); // pow constants computed so that // | band_scale(0) | ~= .5 and | band_scale(5) | ~= 32 @@ -57,29 +72,30 @@ NyanCatAnalyzer::NyanCatAnalyzer(QWidget* parent) } } -void NyanCatAnalyzer::transform(Scope& s) { fht_->spectrum(&s.front()); } +void Rainbow::RainbowAnalyzer::transform(Scope& s) { fht_->spectrum(&s.front()); } -void NyanCatAnalyzer::timerEvent(QTimerEvent* e) { +void Rainbow::RainbowAnalyzer::timerEvent(QTimerEvent* e) { if (e->timerId() == timer_id_) { - frame_ = (frame_ + 1) % kCatFrameCount; + frame_ = (frame_ + 1) % kFrameCount[rainbowtype]; } else { Analyzer::Base::timerEvent(e); } } -void NyanCatAnalyzer::resizeEvent(QResizeEvent* e) { +void Rainbow::RainbowAnalyzer::resizeEvent(QResizeEvent* e) { // Invalidate the buffer so it's recreated from scratch in the next paint // event. buffer_[0] = QPixmap(); buffer_[1] = QPixmap(); - available_rainbow_width_ = width() - kCatWidth + kRainbowOverlap; + available_rainbow_width_ = width() - kWidth[rainbowtype] + + kRainbowOverlap[rainbowtype]; px_per_frame_ = static_cast(available_rainbow_width_) / (kHistorySize - 1) + 1; x_offset_ = px_per_frame_ * (kHistorySize - 1) - available_rainbow_width_; } -void NyanCatAnalyzer::analyze(QPainter& p, const Analyzer::Scope& s, +void Rainbow::RainbowAnalyzer::analyze(QPainter& p, const Analyzer::Scope& s, bool new_frame) { // Discard the second half of the transform const int scope_size = s.size() / 2; @@ -113,13 +129,15 @@ void NyanCatAnalyzer::analyze(QPainter& p, const Analyzer::Scope& s, QPointF* dest = polyline; float* source = history_; - const float top_of_cat = - static_cast(height()) / 2 - static_cast(kCatHeight) / 2; + const float top_of = + static_cast(height()) / 2 - static_cast( + kRainbowHeight[rainbowtype]) / 2; for (int band = 0; band < kRainbowBands; ++band) { // Calculate the Y position of this band. const float y = - static_cast(kCatHeight) / (kRainbowBands + 1) * (band + 0.5) + - top_of_cat; + static_cast(kRainbowHeight[rainbowtype]) / ( + kRainbowBands + 1) * (band + 0.5) + + top_of; // Add each point in the line. for (int x = 0; x < kHistorySize; ++x) { @@ -160,8 +178,8 @@ void NyanCatAnalyzer::analyze(QPainter& p, const Analyzer::Scope& s, x_offset_ + available_rainbow_width_ - px_per_frame_, 0); buffer_painter.fillRect( x_offset_ + available_rainbow_width_ - px_per_frame_, 0, - kCatWidth - kRainbowOverlap + px_per_frame_, height(), - background_brush_); + kWidth[rainbowtype] - kRainbowOverlap[rainbowtype] + px_per_frame_, + height(), background_brush_); for (int band = kRainbowBands - 1; band >= 0; --band) { buffer_painter.setPen(colors_[band]); @@ -174,12 +192,22 @@ void NyanCatAnalyzer::analyze(QPainter& p, const Analyzer::Scope& s, // Draw the buffer on to the widget p.drawPixmap(0, 0, buffer_[current_buffer_], x_offset_, 0, 0, 0); - // Draw nyan cat (he's been waiting for this for 75 lines). - // Nyan nyan nyan nyan. + // Draw rainbow analyzer (nyan cat or rainbowdash) + // Nyan nyan nyan nyan dash dash dash dash. if (!is_playing_) { // Ssshhh! - p.drawPixmap(SleepingCatDestRect(), cat_, SleepingCatSourceRect()); + p.drawPixmap(SleepingDestRect(rainbowtype), cat_dash_[rainbowtype], + SleepingSourceRect(rainbowtype)); } else { - p.drawPixmap(CatDestRect(), cat_, CatSourceRect()); + p.drawPixmap(DestRect(rainbowtype), cat_dash_[rainbowtype], + SourceRect(rainbowtype)); } } + +Rainbow::NyanCatAnalyzer::NyanCatAnalyzer(QWidget* parent) + :RainbowAnalyzer(Rainbow::RainbowAnalyzer::Nyancat, parent) { +} + +Rainbow::RainbowDashAnalyzer::RainbowDashAnalyzer(QWidget* parent) + :RainbowAnalyzer(Rainbow::RainbowAnalyzer::Dash, parent) { +} diff --git a/src/analyzers/nyancatanalyzer.h b/src/analyzers/rainbowanalyzer.h similarity index 50% rename from src/analyzers/nyancatanalyzer.h rename to src/analyzers/rainbowanalyzer.h index f144fd94b..ccb70b673 100644 --- a/src/analyzers/nyancatanalyzer.h +++ b/src/analyzers/rainbowanalyzer.h @@ -2,7 +2,10 @@ Copyright 2011, Tyler Rhodes Copyright 2011-2012, David Sansome Copyright 2011, 2014, John Maguire + Copyright 2014, Alibek Omarov Copyright 2014, Krzysztof Sobiecki + Copyright 2014-2015, Mark Furneaux + Copyright 2015, Arun Narayanankutty Clementine is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -18,20 +21,24 @@ along with Clementine. If not, see . */ -#ifndef ANALYZERS_NYANCATANALYZER_H_ -#define ANALYZERS_NYANCATANALYZER_H_ +#ifndef ANALYZERS_RAINBOWANALYZER_H_ +#define ANALYZERS_RAINBOWANALYZER_H_ #include "analyzerbase.h" -#include +#include -class NyanCatAnalyzer : public Analyzer::Base { +namespace Rainbow { +class RainbowAnalyzer : public Analyzer::Base { Q_OBJECT public: - Q_INVOKABLE NyanCatAnalyzer(QWidget* parent); + enum RainbowType { + Nyancat = 0, + Dash = 1 + }; - static const char* kName; + RainbowAnalyzer(const RainbowType& rbtype, QWidget* parent); protected: void transform(Analyzer::Scope&); @@ -41,11 +48,12 @@ class NyanCatAnalyzer : public Analyzer::Base { void resizeEvent(QResizeEvent* e); private: - static const int kCatHeight = 21; - static const int kCatWidth = 34; - static const int kCatFrameCount = 6; - static const int kRainbowOverlap = 13; - static const int kSleepingCatHeight = 24; + static const int kHeight[]; + static const int kWidth[]; + static const int kFrameCount[]; + static const int kRainbowHeight[]; + static const int kRainbowOverlap[]; + static const int kSleepingHeight[]; static const int kHistorySize = 128; static const int kRainbowBands = 6; @@ -53,23 +61,28 @@ class NyanCatAnalyzer : public Analyzer::Base { static const int kFrameIntervalMs = 150; - private: - inline QRect CatSourceRect() const { - return QRect(0, kCatHeight * frame_, kCatWidth, kCatHeight); + static RainbowType rainbowtype; + + inline QRect SourceRect(RainbowType rainbowtype) const { + return QRect(0, kHeight[rainbowtype] * frame_, + kWidth[rainbowtype], kHeight[rainbowtype]); } - inline QRect SleepingCatSourceRect() const { - return QRect(0, kCatHeight * kCatFrameCount, kCatWidth, kSleepingCatHeight); + inline QRect SleepingSourceRect(RainbowType rainbowtype) const { + return QRect(0, kHeight[rainbowtype] * kFrameCount[rainbowtype], + kWidth[rainbowtype], kSleepingHeight[rainbowtype]); } - inline QRect CatDestRect() const { - return QRect(width() - kCatWidth, (height() - kCatHeight) / 2, kCatWidth, - kCatHeight); + inline QRect DestRect(RainbowType rainbowtype) const { + return QRect(width() - kWidth[rainbowtype], (height() - + kHeight[rainbowtype]) / 2, kWidth[rainbowtype], + kHeight[rainbowtype]); } - inline QRect SleepingCatDestRect() const { - return QRect(width() - kCatWidth, (height() - kSleepingCatHeight) / 2, - kCatWidth, kSleepingCatHeight); + inline QRect SleepingDestRect(RainbowType rainbowtype) const { + return QRect(width() - kWidth[rainbowtype], (height() - + kSleepingHeight[rainbowtype]) / 2, kWidth[rainbowtype], + kSleepingHeight[rainbowtype]); } private: @@ -77,17 +90,18 @@ class NyanCatAnalyzer : public Analyzer::Base { float band_scale_[kRainbowBands]; QPen colors_[kRainbowBands]; - // Nyan cat! - QPixmap cat_; + // Rainbow Nyancat & Dash + QPixmap cat_dash_[2]; - // For the nyan cat animation + // For the cat or dash animation int timer_id_; int frame_; // The y positions of each point on the rainbow. float history_[kHistorySize * kRainbowBands]; - // A cache of the last frame's rainbow, so it can be used in the next frame. + // A cache of the last frame's rainbow, + // so it can be used in the next frame. QPixmap buffer_[2]; int current_buffer_; @@ -98,11 +112,30 @@ class NyanCatAnalyzer : public Analyzer::Base { // X spacing between each point in the polyline. int px_per_frame_; - // Amount the buffer_ is shifted to the left (off the edge of the widget) to - // make the rainbow extend from 0 to available_rainbow_width_. + // Amount the buffer_ is shifted to the left (off the edge of the widget) + // to make the rainbow extend from 0 to available_rainbow_width_. int x_offset_; QBrush background_brush_; }; -#endif // ANALYZERS_NYANCATANALYZER_H_ +class NyanCatAnalyzer : public RainbowAnalyzer { + Q_OBJECT + + public: + Q_INVOKABLE NyanCatAnalyzer(QWidget* parent); + + static const char* kName; +}; + +class RainbowDashAnalyzer : public RainbowAnalyzer { + Q_OBJECT + + public: + Q_INVOKABLE RainbowDashAnalyzer(QWidget* parent); + + static const char* kName; +}; +} + +#endif // ANALYZERS_RAINBOWANALYZER_H_ diff --git a/src/analyzers/rainbowdashanalyzer.cpp b/src/analyzers/rainbowdashanalyzer.cpp deleted file mode 100644 index c7182163d..000000000 --- a/src/analyzers/rainbowdashanalyzer.cpp +++ /dev/null @@ -1,182 +0,0 @@ -/* This file is part of Clementine. - Copyright 2014, Alibek Omarov - Copyright 2014-2015, Mark Furneaux - Copyright 2014, Krzysztof Sobiecki - Copyright 2014, 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 "rainbowdashanalyzer.h" - -#include - -#include -#include - -#include "core/arraysize.h" -#include "core/logging.h" - -using Analyzer::Scope; - -const char* RainbowDashAnalyzer::kName = "Rainbow Dash"; -const float RainbowDashAnalyzer::kPixelScale = 0.02f; - -RainbowDashAnalyzer::RainbowDashAnalyzer(QWidget* parent) - : Analyzer::Base(parent, 9), - dash_(":/rainbowdash.png"), - timer_id_(startTimer(kFrameIntervalMs)), - frame_(0), - current_buffer_(0), - available_rainbow_width_(0), - px_per_frame_(0), - x_offset_(0), - background_brush_(QColor(0x0f, 0x43, 0x73)) { - memset(history_, 0, sizeof(history_)); - - for (int i = 0; i < kRainbowBands; ++i) { - colors_[i] = QPen(QColor::fromHsv(i * 255 / kRainbowBands, 255, 255), - kRainbowHeight / kRainbowBands, Qt::SolidLine, - Qt::FlatCap, Qt::RoundJoin); - - // pow constants computed so that - // | band_scale(0) | ~= .5 and | band_scale(5) | ~= 32 - band_scale_[i] = - -std::cos(M_PI * i / (kRainbowBands - 1)) * 0.5 * std::pow(2.3, i); - } -} - -void RainbowDashAnalyzer::transform(Scope& s) { fht_->spectrum(&s.front()); } - -void RainbowDashAnalyzer::timerEvent(QTimerEvent* e) { - if (e->timerId() == timer_id_) { - frame_ = (frame_ + 1) % kDashFrameCount; - } else { - Analyzer::Base::timerEvent(e); - } -} - -void RainbowDashAnalyzer::resizeEvent(QResizeEvent* e) { - // Invalidate the buffer so it's recreated from scratch in the next paint - // event. - buffer_[0] = QPixmap(); - buffer_[1] = QPixmap(); - - available_rainbow_width_ = width() - kDashWidth + kRainbowOverlap; - px_per_frame_ = - static_cast(available_rainbow_width_) / (kHistorySize - 1) + 1; - x_offset_ = px_per_frame_ * (kHistorySize - 1) - available_rainbow_width_; -} - -void RainbowDashAnalyzer::analyze(QPainter& p, const Analyzer::Scope& s, - bool new_frame) { - // Discard the second half of the transform - const int scope_size = s.size() / 2; - - if ((new_frame && is_playing_) || - (buffer_[0].isNull() && buffer_[1].isNull())) { - // 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)); - } - - // 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 = 0.0; - for (int i = 0; i < samples_per_band; ++i) { - accumulator += s[sample++]; - } - history_[(band + 1) * kHistorySize - 1] = accumulator * band_scale_[band]; - } - - // Create polylines for the rainbows. - QPointF polyline[kRainbowBands * kHistorySize]; - QPointF* dest = polyline; - float* source = history_; - - const float top_of_Dash = static_cast(height()) / 2 - - static_cast(kRainbowHeight) / 2; - for (int band = 0; band < kRainbowBands; ++band) { - // Calculate the Y position of this band. - const float y = static_cast(kRainbowHeight) / (kRainbowBands + 1) * - (band + 0.5) + - top_of_Dash; - - // Add each point in the line. - for (int x = 0; x < kHistorySize; ++x) { - *dest = QPointF(px_per_frame_ * x, y + *source * kPixelScale); - ++dest; - ++source; - } - } - - // Do we have to draw the whole rainbow into the buffer? - if (buffer_[0].isNull()) { - for (int i = 0; i < 2; ++i) { - buffer_[i] = QPixmap(QSize(width() + x_offset_, height())); - buffer_[i].fill(background_brush_.color()); - } - current_buffer_ = 0; - - QPainter buffer_painter(&buffer_[0]); - buffer_painter.setRenderHint(QPainter::Antialiasing); - for (int band = kRainbowBands - 1; band >= 0; --band) { - buffer_painter.setPen(colors_[band]); - buffer_painter.drawPolyline(&polyline[band * kHistorySize], - kHistorySize); - buffer_painter.drawPolyline(&polyline[band * kHistorySize], - kHistorySize); - } - } else { - const int last_buffer = current_buffer_; - current_buffer_ = (current_buffer_ + 1) % 2; - - // We can just shuffle the buffer along a bit and draw the new frame's - // data. - QPainter buffer_painter(&buffer_[current_buffer_]); - buffer_painter.setRenderHint(QPainter::Antialiasing); - - buffer_painter.drawPixmap( - 0, 0, buffer_[last_buffer], px_per_frame_, 0, - x_offset_ + available_rainbow_width_ - px_per_frame_, 0); - buffer_painter.fillRect( - x_offset_ + available_rainbow_width_ - px_per_frame_, 0, - kDashWidth - kRainbowOverlap + px_per_frame_, height(), - background_brush_); - - for (int band = kRainbowBands - 1; band >= 0; --band) { - buffer_painter.setPen(colors_[band]); - buffer_painter.drawPolyline(&polyline[(band + 1) * kHistorySize - 3], - 3); - } - } - } - - // Draw the buffer on to the widget - p.drawPixmap(0, 0, buffer_[current_buffer_], x_offset_, 0, 0, 0); - - if (!is_playing_) { - // Ssshhh! - p.drawPixmap(SleepingDashDestRect(), dash_, SleepingDashSourceRect()); - } else { - p.drawPixmap(DashDestRect(), dash_, DashSourceRect()); - } -} diff --git a/src/analyzers/rainbowdashanalyzer.h b/src/analyzers/rainbowdashanalyzer.h deleted file mode 100644 index d8d97c11c..000000000 --- a/src/analyzers/rainbowdashanalyzer.h +++ /dev/null @@ -1,108 +0,0 @@ -/* This file is part of Clementine. - Copyright 2014, Alibek Omarov - Copyright 2014-2015, Mark Furneaux - Copyright 2014, Krzysztof Sobiecki - - 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 ANALYZERS_RAINBOWDASHANALYZER_H_ -#define ANALYZERS_RAINBOWDASHANALYZER_H_ - -#include "analyzerbase.h" - -#include - -class RainbowDashAnalyzer : public Analyzer::Base { - Q_OBJECT - - public: - Q_INVOKABLE RainbowDashAnalyzer(QWidget* parent); - - static const char* kName; - - protected: - void transform(Analyzer::Scope&); - void analyze(QPainter& p, const Analyzer::Scope&, bool new_frame); - - void timerEvent(QTimerEvent* e); - void resizeEvent(QResizeEvent* e); - - private: - static const int kDashHeight = 33; - static const int kDashWidth = 53; - static const int kRainbowHeight = 16; - static const int kDashFrameCount = 16; - static const int kRainbowOverlap = 15; - static const int kSleepingDashHeight = 33; - - static const int kHistorySize = 128; - static const int kRainbowBands = 6; - static const float kPixelScale; - - static const int kFrameIntervalMs = 150; - - private: - inline QRect DashSourceRect() const { - return QRect(0, kDashHeight * frame_, kDashWidth, kDashHeight); - } - - inline QRect SleepingDashSourceRect() const { - return QRect(0, kDashHeight * kDashFrameCount, kDashWidth, - kSleepingDashHeight); - } - - inline QRect DashDestRect() const { - return QRect(width() - kDashWidth, (height() - kDashHeight) / 2, kDashWidth, - kDashHeight); - } - - inline QRect SleepingDashDestRect() const { - return QRect(width() - kDashWidth, (height() - kSleepingDashHeight) / 2, - kDashWidth, kSleepingDashHeight); - } - - private: - // "constants" that get initialised in the constructor - float band_scale_[kRainbowBands]; - QPen colors_[kRainbowBands]; - - QPixmap dash_; - - // For the animation - int timer_id_; - int frame_; - - // The y positions of each point on the rainbow. - float history_[kHistorySize * kRainbowBands]; - - // A cache of the last frame's rainbow, so it can be used in the next frame. - QPixmap buffer_[2]; - int current_buffer_; - - // Geometry information that's updated on resize: - // The width of the widget minus the space for the pony - int available_rainbow_width_; - - // X spacing between each point in the polyline. - int px_per_frame_; - - // Amount the buffer_ is shifted to the left (off the edge of the widget) to - // make the rainbow extend from 0 to available_rainbow_width_. - int x_offset_; - - QBrush background_brush_; -}; - -#endif // ANALYZERS_RAINBOWDASHANALYZER_H_