2014-11-29 20:07:01 +01:00
|
|
|
/* This file is part of Clementine.
|
|
|
|
Copyright 2004, Melchior FRANZ <mfranz@kde.org>
|
|
|
|
Copyright 2009-2010, David Sansome <davidsansome@gmail.com>
|
|
|
|
Copyright 2010, 2014, John Maguire <john.maguire@gmail.com>
|
Add "Psychedelic Colour" mode to all analyzers
(Well, except Nyanalyzer and Rainbow dash because they are already colourful enough.)
I have added functionality for any 2D analyzer to change any part of its colour palatte with the frequency content of the music, in the same way that Moodbars do.
I find this gives the analyzer a sort of "third dimention".
This is built into Analyzer::Base, so all analyzers can use it and override it as they please. I have thus added support for Block, Boom, Turbine, Sonogram, and Bar, however Boom and Block seem to look the best in my opinion.
This is of course all optional and is toggled by a checkbox in the context menu for the analyzer, disabled by default.
I have not been able to measure any increase in CPU activity with this enabled, even at 60fps.
2015-07-01 17:48:03 +02:00
|
|
|
Copyright 2014-2015, Mark Furneaux <mark@furneaux.ca>
|
2014-11-29 20:07:01 +01:00
|
|
|
Copyright 2014, Krzysztof Sobiecki <sobkas@gmail.com>
|
|
|
|
|
|
|
|
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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Original Author: Melchior FRANZ <mfranz@kde.org> 2004
|
|
|
|
*/
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
#include "sonogram.h"
|
|
|
|
|
2010-03-22 14:49:08 +01:00
|
|
|
#include <QPainter>
|
|
|
|
|
2014-05-13 14:46:22 +02:00
|
|
|
using Analyzer::Scope;
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
const char* Sonogram::kName =
|
|
|
|
QT_TRANSLATE_NOOP("AnalyzerContainer", "Sonogram");
|
2010-03-21 18:22:05 +01:00
|
|
|
|
Add "Psychedelic Colour" mode to all analyzers
(Well, except Nyanalyzer and Rainbow dash because they are already colourful enough.)
I have added functionality for any 2D analyzer to change any part of its colour palatte with the frequency content of the music, in the same way that Moodbars do.
I find this gives the analyzer a sort of "third dimention".
This is built into Analyzer::Base, so all analyzers can use it and override it as they please. I have thus added support for Block, Boom, Turbine, Sonogram, and Bar, however Boom and Block seem to look the best in my opinion.
This is of course all optional and is toggled by a checkbox in the context menu for the analyzer, disabled by default.
I have not been able to measure any increase in CPU activity with this enabled, even at 60fps.
2015-07-01 17:48:03 +02:00
|
|
|
Sonogram::Sonogram(QWidget* parent)
|
|
|
|
: Analyzer::Base(parent, 9), scope_size_(128) {}
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
Sonogram::~Sonogram() {}
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void Sonogram::resizeEvent(QResizeEvent* e) {
|
|
|
|
QWidget::resizeEvent(e);
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
// only for gcc < 4.0
|
|
|
|
#if !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 0))
|
|
|
|
resizeForBands(height() < 128 ? 128 : height());
|
2010-08-28 20:48:16 +02:00
|
|
|
#endif
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
canvas_ = QPixmap(size());
|
|
|
|
canvas_.fill(palette().color(QPalette::Background));
|
Add "Psychedelic Colour" mode to all analyzers
(Well, except Nyanalyzer and Rainbow dash because they are already colourful enough.)
I have added functionality for any 2D analyzer to change any part of its colour palatte with the frequency content of the music, in the same way that Moodbars do.
I find this gives the analyzer a sort of "third dimention".
This is built into Analyzer::Base, so all analyzers can use it and override it as they please. I have thus added support for Block, Boom, Turbine, Sonogram, and Bar, however Boom and Block seem to look the best in my opinion.
This is of course all optional and is toggled by a checkbox in the context menu for the analyzer, disabled by default.
I have not been able to measure any increase in CPU activity with this enabled, even at 60fps.
2015-07-01 17:48:03 +02:00
|
|
|
updateBandSize(scope_size_);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sonogram::psychedelicModeChanged(bool enabled) {
|
|
|
|
psychedelic_enabled_ = enabled;
|
|
|
|
updateBandSize(scope_size_);
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void Sonogram::analyze(QPainter& p, const Scope& s, bool new_frame) {
|
2015-07-12 05:12:44 +02:00
|
|
|
if (!new_frame || engine_->state() == Engine::Paused) {
|
2014-04-27 07:54:42 +02:00
|
|
|
p.drawPixmap(0, 0, canvas_);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
int x = width() - 1;
|
|
|
|
QColor c;
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
QPainter canvas_painter(&canvas_);
|
|
|
|
canvas_painter.drawPixmap(0, 0, canvas_, 1, 0, x, -1);
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
Scope::const_iterator it = s.begin(), end = s.end();
|
Add "Psychedelic Colour" mode to all analyzers
(Well, except Nyanalyzer and Rainbow dash because they are already colourful enough.)
I have added functionality for any 2D analyzer to change any part of its colour palatte with the frequency content of the music, in the same way that Moodbars do.
I find this gives the analyzer a sort of "third dimention".
This is built into Analyzer::Base, so all analyzers can use it and override it as they please. I have thus added support for Block, Boom, Turbine, Sonogram, and Bar, however Boom and Block seem to look the best in my opinion.
This is of course all optional and is toggled by a checkbox in the context menu for the analyzer, disabled by default.
I have not been able to measure any increase in CPU activity with this enabled, even at 60fps.
2015-07-01 17:48:03 +02:00
|
|
|
if (scope_size_ != s.size()) {
|
|
|
|
scope_size_ = s.size();
|
|
|
|
updateBandSize(scope_size_);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (psychedelic_enabled_) {
|
|
|
|
c = getPsychedelicColor(s, 20, 100);
|
|
|
|
for (int y = height() - 1; y;) {
|
|
|
|
if (it >= end || *it < .005) {
|
|
|
|
c = palette().color(QPalette::Background);
|
|
|
|
} else if (*it < .05) {
|
|
|
|
c.setHsv(c.hue(), c.saturation(), 255 - static_cast<int>(*it * 4000.0));
|
|
|
|
} else if (*it < 1.0) {
|
|
|
|
c.setHsv((c.hue() + static_cast<int>(*it * 90.0)) % 255, 255, 255);
|
|
|
|
} else {
|
|
|
|
c = getPsychedelicColor(s, 10, 50);
|
|
|
|
}
|
|
|
|
|
|
|
|
canvas_painter.setPen(c);
|
|
|
|
canvas_painter.drawPoint(x, y--);
|
|
|
|
|
|
|
|
if (it < end) ++it;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (int y = height() - 1; y;) {
|
|
|
|
if (it >= end || *it < .005)
|
|
|
|
c = palette().color(QPalette::Background);
|
|
|
|
else if (*it < .05)
|
|
|
|
c.setHsv(95, 255, 255 - static_cast<int>(*it * 4000.0));
|
|
|
|
else if (*it < 1.0)
|
|
|
|
c.setHsv(95 - static_cast<int>(*it * 90.0), 255, 255);
|
|
|
|
else
|
|
|
|
c = Qt::red;
|
|
|
|
|
|
|
|
canvas_painter.setPen(c);
|
|
|
|
canvas_painter.drawPoint(x, y--);
|
|
|
|
|
|
|
|
if (it < end) ++it;
|
|
|
|
}
|
2014-02-07 16:34:20 +01:00
|
|
|
}
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
canvas_painter.end();
|
2010-03-21 18:22:05 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
p.drawPixmap(0, 0, canvas_);
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void Sonogram::transform(Scope& scope) {
|
|
|
|
float* front = static_cast<float*>(&scope.front());
|
Add "Psychedelic Colour" mode to all analyzers
(Well, except Nyanalyzer and Rainbow dash because they are already colourful enough.)
I have added functionality for any 2D analyzer to change any part of its colour palatte with the frequency content of the music, in the same way that Moodbars do.
I find this gives the analyzer a sort of "third dimention".
This is built into Analyzer::Base, so all analyzers can use it and override it as they please. I have thus added support for Block, Boom, Turbine, Sonogram, and Bar, however Boom and Block seem to look the best in my opinion.
This is of course all optional and is toggled by a checkbox in the context menu for the analyzer, disabled by default.
I have not been able to measure any increase in CPU activity with this enabled, even at 60fps.
2015-07-01 17:48:03 +02:00
|
|
|
fht_->power2(front);
|
|
|
|
fht_->scale(front, 1.0 / 256);
|
|
|
|
scope.resize(fht_->size() / 2);
|
2010-08-28 20:48:16 +02:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void Sonogram::demo(QPainter& p) {
|
Add "Psychedelic Colour" mode to all analyzers
(Well, except Nyanalyzer and Rainbow dash because they are already colourful enough.)
I have added functionality for any 2D analyzer to change any part of its colour palatte with the frequency content of the music, in the same way that Moodbars do.
I find this gives the analyzer a sort of "third dimention".
This is built into Analyzer::Base, so all analyzers can use it and override it as they please. I have thus added support for Block, Boom, Turbine, Sonogram, and Bar, however Boom and Block seem to look the best in my opinion.
This is of course all optional and is toggled by a checkbox in the context menu for the analyzer, disabled by default.
I have not been able to measure any increase in CPU activity with this enabled, even at 60fps.
2015-07-01 17:48:03 +02:00
|
|
|
analyze(p, Scope(fht_->size(), 0), new_frame_);
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|