diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 366985baf..05a0c7ac7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -67,6 +67,7 @@ set(SOURCES analyzer/blockanalyzer.cpp analyzer/boomanalyzer.cpp analyzer/rainbowanalyzer.cpp + analyzer/sonogram.cpp equalizer/equalizer.cpp equalizer/equalizerslider.cpp @@ -310,6 +311,7 @@ set(HEADERS analyzer/blockanalyzer.h analyzer/boomanalyzer.h analyzer/rainbowanalyzer.h + analyzer/sonogram.h equalizer/equalizer.h equalizer/equalizerslider.h diff --git a/src/analyzer/analyzercontainer.cpp b/src/analyzer/analyzercontainer.cpp index 0bcf1e5a4..592eb2ebc 100644 --- a/src/analyzer/analyzercontainer.cpp +++ b/src/analyzer/analyzercontainer.cpp @@ -40,6 +40,7 @@ #include "blockanalyzer.h" #include "boomanalyzer.h" #include "rainbowanalyzer.h" +#include "sonogram.h" #include "core/logging.h" #include "engine/enginebase.h" @@ -85,6 +86,7 @@ AnalyzerContainer::AnalyzerContainer(QWidget *parent) AddAnalyzerType(); AddAnalyzerType(); AddAnalyzerType(); + AddAnalyzerType(); disable_action_ = context_menu_->addAction(tr("No analyzer"), this, &AnalyzerContainer::DisableAnalyzer); disable_action_->setCheckable(true); diff --git a/src/analyzer/sonogram.cpp b/src/analyzer/sonogram.cpp new file mode 100644 index 000000000..1b8b3acf9 --- /dev/null +++ b/src/analyzer/sonogram.cpp @@ -0,0 +1,97 @@ +/* + Strawberry Music Player + This file was part of Clementine. + Copyright 2004, Melchior FRANZ + Copyright 2009-2010, David Sansome + Copyright 2010, 2014, John Maguire + Copyright 2014-2015, Mark Furneaux + Copyright 2014, Krzysztof Sobiecki + + Strawberry 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. + + Strawberry 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 Strawberry. If not, see . + */ + +#include +#include + +#include "sonogram.h" + +const char *Sonogram::kName = QT_TRANSLATE_NOOP("AnalyzerContainer", "Sonogram"); + +Sonogram::Sonogram(QWidget *parent) + : Analyzer::Base(parent, 9), scope_size_(128) {} + +Sonogram::~Sonogram() {} + +void Sonogram::resizeEvent(QResizeEvent *e) { + + Q_UNUSED(e) + + canvas_ = QPixmap(size()); + canvas_.fill(palette().color(QPalette::Window)); + +} + +void Sonogram::analyze(QPainter &p, const Analyzer::Scope &s, bool new_frame) { + + if (!new_frame || engine_->state() == Engine::Paused) { + p.drawPixmap(0, 0, canvas_); + return; + } + + QPainter canvas_painter(&canvas_); + canvas_painter.drawPixmap(0, 0, canvas_, 1, 0, width() - 1, -1); + + Analyzer::Scope::const_iterator it = s.begin(), end = s.end(); + if (scope_size_ != static_cast(s.size())) { + scope_size_ = s.size(); + } + + for (int y = height() - 1; y;) { + QColor c; + if (it >= end || *it < .005) { + c = palette().color(QPalette::Window); + } + else if (*it < .05) { + c.setHsv(95, 255, 255 - static_cast(*it * 4000.0)); + } + else if (*it < 1.0) { + c.setHsv(95 - static_cast(*it * 90.0), 255, 255); + } + else { + c = Qt::red; + } + + canvas_painter.setPen(c); + canvas_painter.drawPoint(width() - 1, y--); + + if (it < end) ++it; + } + + canvas_painter.end(); + + p.drawPixmap(0, 0, canvas_); + +} + +void Sonogram::transform(Analyzer::Scope &scope) { + + fht_->power2(scope.data()); + fht_->scale(scope.data(), 1.0 / 256); + scope.resize(fht_->size() / 2); + +} + +void Sonogram::demo(QPainter &p) { + analyze(p, Analyzer::Scope(fht_->size(), 0), new_frame_); +} diff --git a/src/analyzer/sonogram.h b/src/analyzer/sonogram.h new file mode 100644 index 000000000..ecb795b4b --- /dev/null +++ b/src/analyzer/sonogram.h @@ -0,0 +1,51 @@ +/* + Strawberry Music Player + This file was part of Clementine. + Copyright 2004, Melchior FRANZ + Copyright 2009-2010, David Sansome + Copyright 2014, Krzysztof Sobiecki + Copyright 2014, John Maguire + Copyright 2015, Mark Furneaux + + Strawberry 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. + + Strawberry 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 Strawberry. If not, see . +*/ + +#ifndef SONOGRAM_H +#define SONOGRAM_H + +#include +#include + +#include "analyzerbase.h" + +class Sonogram : public Analyzer::Base { + Q_OBJECT + public: + Q_INVOKABLE explicit Sonogram(QWidget *); + ~Sonogram(); + + static const char *kName; + + protected: + void resizeEvent(QResizeEvent *e) override; + void analyze(QPainter &p, const Analyzer::Scope &s, bool new_frame) override; + void transform(Analyzer::Scope &scope) override; + void demo(QPainter &p) override; + + private: + QPixmap canvas_; + int scope_size_; +}; + +#endif // SONOGRAM_H