2010-03-24 00:11:46 +01:00
|
|
|
/* This file is part of Clementine.
|
2014-11-29 20:07:01 +01:00
|
|
|
Copyright 2010-2011, David Sansome <davidsansome@gmail.com>
|
|
|
|
Copyright 2010, 2014, John Maguire <john.maguire@gmail.com>
|
|
|
|
Copyright 2011-2012, Arnaud Bienner <arnaud.bienner@gmail.com>
|
|
|
|
Copyright 2013, Vasily Fomin <vasili.fomin@gmail.com>
|
|
|
|
Copyright 2014, Krzysztof Sobiecki <sobkas@gmail.com>
|
2015-11-21 16:20:47 +01:00
|
|
|
Copyright 2014-2015, Mark Furneaux <mark@furneaux.ca>
|
2010-03-24 00:11:46 +01:00
|
|
|
|
|
|
|
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/>.
|
|
|
|
*/
|
|
|
|
|
2010-03-20 23:45:54 +01:00
|
|
|
#include "analyzercontainer.h"
|
|
|
|
#include "baranalyzer.h"
|
|
|
|
#include "blockanalyzer.h"
|
2010-03-21 18:22:05 +01:00
|
|
|
#include "boomanalyzer.h"
|
|
|
|
#include "sonogram.h"
|
2015-11-21 16:20:47 +01:00
|
|
|
#include "rainbowanalyzer.h"
|
2010-03-21 18:22:05 +01:00
|
|
|
#include "turbine.h"
|
2011-04-22 18:50:29 +02:00
|
|
|
#include "core/logging.h"
|
2010-03-20 23:45:54 +01:00
|
|
|
|
|
|
|
#include <QHBoxLayout>
|
2015-11-21 16:20:47 +01:00
|
|
|
#include <QMouseEvent>
|
2010-03-20 23:45:54 +01:00
|
|
|
#include <QSettings>
|
2010-06-23 17:52:56 +02:00
|
|
|
#include <QTimer>
|
2010-03-21 18:22:05 +01:00
|
|
|
#include <QtDebug>
|
2010-03-20 23:45:54 +01:00
|
|
|
|
|
|
|
const char* AnalyzerContainer::kSettingsGroup = "Analyzer";
|
2011-03-05 19:53:48 +01:00
|
|
|
const char* AnalyzerContainer::kSettingsFramerate = "framerate";
|
2010-03-20 23:45:54 +01:00
|
|
|
|
2011-03-05 19:53:48 +01:00
|
|
|
// Framerates
|
2012-03-22 20:03:17 +01:00
|
|
|
const int AnalyzerContainer::kLowFramerate = 20;
|
|
|
|
const int AnalyzerContainer::kMediumFramerate = 25;
|
|
|
|
const int AnalyzerContainer::kHighFramerate = 30;
|
|
|
|
const int AnalyzerContainer::kSuperHighFramerate = 60;
|
2011-03-04 01:38:15 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
AnalyzerContainer::AnalyzerContainer(QWidget* parent)
|
|
|
|
: QWidget(parent),
|
|
|
|
current_framerate_(kMediumFramerate),
|
|
|
|
context_menu_(new QMenu(this)),
|
|
|
|
context_menu_framerate_(new QMenu(tr("Framerate"), this)),
|
|
|
|
group_(new QActionGroup(this)),
|
|
|
|
group_framerate_(new QActionGroup(this)),
|
|
|
|
mapper_(new QSignalMapper(this)),
|
|
|
|
mapper_framerate_(new QSignalMapper(this)),
|
|
|
|
visualisation_action_(nullptr),
|
|
|
|
double_click_timer_(new QTimer(this)),
|
|
|
|
ignore_next_click_(false),
|
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
|
|
|
psychedelic_colors_on_(false),
|
2014-02-07 16:34:20 +01:00
|
|
|
current_analyzer_(nullptr),
|
|
|
|
engine_(nullptr) {
|
2010-03-20 23:45:54 +01:00
|
|
|
QHBoxLayout* layout = new QHBoxLayout(this);
|
|
|
|
setLayout(layout);
|
|
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
2011-03-04 01:38:15 +01:00
|
|
|
// Init framerate sub-menu
|
2011-03-05 19:53:48 +01:00
|
|
|
AddFramerate(tr("Low (%1 fps)").arg(kLowFramerate), kLowFramerate);
|
|
|
|
AddFramerate(tr("Medium (%1 fps)").arg(kMediumFramerate), kMediumFramerate);
|
|
|
|
AddFramerate(tr("High (%1 fps)").arg(kHighFramerate), kHighFramerate);
|
2014-02-07 16:34:20 +01:00
|
|
|
AddFramerate(tr("Super high (%1 fps)").arg(kSuperHighFramerate),
|
|
|
|
kSuperHighFramerate);
|
2011-03-05 19:53:48 +01:00
|
|
|
connect(mapper_framerate_, SIGNAL(mapped(int)), SLOT(ChangeFramerate(int)));
|
2011-03-04 01:38:15 +01:00
|
|
|
|
|
|
|
context_menu_->addMenu(context_menu_framerate_);
|
|
|
|
context_menu_->addSeparator();
|
|
|
|
|
2010-08-28 20:48:16 +02:00
|
|
|
AddAnalyzerType<BarAnalyzer>();
|
|
|
|
AddAnalyzerType<BlockAnalyzer>();
|
|
|
|
AddAnalyzerType<BoomAnalyzer>();
|
|
|
|
AddAnalyzerType<Sonogram>();
|
|
|
|
AddAnalyzerType<TurbineAnalyzer>();
|
2015-11-21 16:20:47 +01:00
|
|
|
AddAnalyzerType<Rainbow::NyanCatAnalyzer>();
|
|
|
|
AddAnalyzerType<Rainbow::RainbowDashAnalyzer>();
|
2011-06-23 01:25:08 +02:00
|
|
|
|
2010-03-20 23:45:54 +01:00
|
|
|
connect(mapper_, SIGNAL(mapped(int)), SLOT(ChangeAnalyzer(int)));
|
2014-02-07 16:34:20 +01:00
|
|
|
disable_action_ = context_menu_->addAction(tr("No analyzer"), this,
|
|
|
|
SLOT(DisableAnalyzer()));
|
2010-03-20 23:45:54 +01:00
|
|
|
disable_action_->setCheckable(true);
|
|
|
|
group_->addAction(disable_action_);
|
|
|
|
|
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
|
|
|
context_menu_->addSeparator();
|
|
|
|
psychedelic_enable_ = context_menu_->addAction(
|
|
|
|
tr("Use Psychedelic Colors"), this, SLOT(TogglePsychedelicColors()));
|
|
|
|
psychedelic_enable_->setCheckable(true);
|
|
|
|
|
2010-06-23 17:52:56 +02:00
|
|
|
context_menu_->addSeparator();
|
|
|
|
// Visualisation action gets added in SetActions
|
|
|
|
|
|
|
|
double_click_timer_->setSingleShot(true);
|
|
|
|
double_click_timer_->setInterval(250);
|
|
|
|
connect(double_click_timer_, SIGNAL(timeout()), SLOT(ShowPopupMenu()));
|
|
|
|
|
2010-03-20 23:45:54 +01:00
|
|
|
Load();
|
|
|
|
}
|
|
|
|
|
2010-06-23 17:52:56 +02:00
|
|
|
void AnalyzerContainer::SetActions(QAction* visualisation) {
|
|
|
|
visualisation_action_ = visualisation;
|
|
|
|
context_menu_->addAction(visualisation_action_);
|
|
|
|
}
|
|
|
|
|
2010-03-21 17:20:27 +01:00
|
|
|
void AnalyzerContainer::mouseReleaseEvent(QMouseEvent* e) {
|
2010-06-23 17:52:56 +02:00
|
|
|
if (e->button() == Qt::LeftButton) {
|
|
|
|
if (ignore_next_click_) {
|
|
|
|
ignore_next_click_ = false;
|
|
|
|
} else {
|
|
|
|
// Might be the first click in a double click, so wait a while before
|
|
|
|
// actually doing anything
|
|
|
|
double_click_timer_->start();
|
|
|
|
last_click_pos_ = e->globalPos();
|
|
|
|
}
|
|
|
|
} else if (e->button() == Qt::RightButton) {
|
2010-03-21 17:20:27 +01:00
|
|
|
context_menu_->popup(e->globalPos());
|
2010-06-23 17:52:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnalyzerContainer::ShowPopupMenu() {
|
|
|
|
context_menu_->popup(last_click_pos_);
|
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void AnalyzerContainer::mouseDoubleClickEvent(QMouseEvent*) {
|
2010-06-23 17:52:56 +02:00
|
|
|
double_click_timer_->stop();
|
|
|
|
ignore_next_click_ = true;
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
if (visualisation_action_) visualisation_action_->trigger();
|
2010-03-20 23:45:54 +01:00
|
|
|
}
|
|
|
|
|
2013-07-27 08:12:41 +02:00
|
|
|
void AnalyzerContainer::wheelEvent(QWheelEvent* e) {
|
|
|
|
emit WheelEvent(e->delta());
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnalyzerContainer::SetEngine(EngineBase* engine) {
|
2014-02-07 16:34:20 +01:00
|
|
|
if (current_analyzer_) current_analyzer_->set_engine(engine);
|
2010-03-20 23:45:54 +01:00
|
|
|
engine_ = engine;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnalyzerContainer::DisableAnalyzer() {
|
|
|
|
delete current_analyzer_;
|
2014-02-06 16:49:49 +01:00
|
|
|
current_analyzer_ = nullptr;
|
2010-03-20 23:45:54 +01:00
|
|
|
|
|
|
|
Save();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
void AnalyzerContainer::TogglePsychedelicColors() {
|
2015-07-02 14:10:08 +02:00
|
|
|
psychedelic_colors_on_ = !psychedelic_colors_on_;
|
2015-08-19 01:21:34 +02:00
|
|
|
if (current_analyzer_) {
|
|
|
|
current_analyzer_->psychedelicModeChanged(psychedelic_colors_on_);
|
|
|
|
}
|
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
|
|
|
SavePsychedelic();
|
|
|
|
}
|
|
|
|
|
2010-03-20 23:45:54 +01:00
|
|
|
void AnalyzerContainer::ChangeAnalyzer(int id) {
|
2015-11-21 16:20:47 +01:00
|
|
|
QObject* instance =
|
|
|
|
analyzer_types_[id]->newInstance(Q_ARG(QWidget*, this));
|
2010-03-21 18:22:05 +01:00
|
|
|
|
|
|
|
if (!instance) {
|
2019-08-22 05:43:16 +02:00
|
|
|
qLog(Warning) << "Couldn't initialise a new"
|
2014-02-07 16:34:20 +01:00
|
|
|
<< analyzer_types_[id]->className();
|
2010-03-21 18:22:05 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-03-20 23:45:54 +01:00
|
|
|
delete current_analyzer_;
|
2010-08-28 20:48:16 +02:00
|
|
|
current_analyzer_ = qobject_cast<Analyzer::Base*>(instance);
|
|
|
|
current_analyzer_->set_engine(engine_);
|
2011-03-05 19:53:48 +01:00
|
|
|
// Even if it is not supposed to happen, I don't want to get a dbz error
|
2014-02-07 16:34:20 +01:00
|
|
|
current_framerate_ =
|
|
|
|
current_framerate_ == 0 ? kMediumFramerate : current_framerate_;
|
2011-11-01 02:04:42 +01:00
|
|
|
current_analyzer_->changeTimeout(1000 / current_framerate_);
|
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
|
|
|
current_analyzer_->psychedelicModeChanged(psychedelic_colors_on_);
|
2010-03-20 23:45:54 +01:00
|
|
|
|
|
|
|
layout()->addWidget(current_analyzer_);
|
|
|
|
|
|
|
|
Save();
|
|
|
|
}
|
|
|
|
|
2011-03-05 19:53:48 +01:00
|
|
|
void AnalyzerContainer::ChangeFramerate(int new_framerate) {
|
2014-02-07 16:34:20 +01:00
|
|
|
if (current_analyzer_) {
|
2011-03-05 19:53:48 +01:00
|
|
|
// Even if it is not supposed to happen, I don't want to get a dbz error
|
|
|
|
new_framerate = new_framerate == 0 ? kMediumFramerate : new_framerate;
|
|
|
|
current_analyzer_->changeTimeout(1000 / new_framerate);
|
2014-05-13 00:15:00 +02:00
|
|
|
|
2014-05-13 22:43:46 +02:00
|
|
|
// notify the current analyzer that the framerate has changed
|
|
|
|
current_analyzer_->framerateChanged();
|
2011-03-04 01:38:15 +01:00
|
|
|
}
|
2011-03-05 19:53:48 +01:00
|
|
|
SaveFramerate(new_framerate);
|
2011-03-04 01:38:15 +01:00
|
|
|
}
|
|
|
|
|
2010-03-20 23:45:54 +01:00
|
|
|
void AnalyzerContainer::Load() {
|
|
|
|
QSettings s;
|
|
|
|
s.beginGroup(kSettingsGroup);
|
|
|
|
|
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
|
|
|
// Colours
|
|
|
|
psychedelic_colors_on_ = s.value("psychedelic", false).toBool();
|
|
|
|
psychedelic_enable_->setChecked(psychedelic_colors_on_);
|
|
|
|
|
2011-03-04 01:38:15 +01:00
|
|
|
// Analyzer
|
2010-03-20 23:45:54 +01:00
|
|
|
QString type = s.value("type", "BlockAnalyzer").toString();
|
|
|
|
if (type.isEmpty()) {
|
|
|
|
DisableAnalyzer();
|
|
|
|
disable_action_->setChecked(true);
|
|
|
|
} else {
|
2014-02-07 16:34:20 +01:00
|
|
|
for (int i = 0; i < analyzer_types_.count(); ++i) {
|
2010-03-20 23:45:54 +01:00
|
|
|
if (type == analyzer_types_[i]->className()) {
|
|
|
|
ChangeAnalyzer(i);
|
|
|
|
actions_[i]->setChecked(true);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-03-04 01:38:15 +01:00
|
|
|
|
|
|
|
// Framerate
|
2011-11-01 02:04:42 +01:00
|
|
|
current_framerate_ = s.value(kSettingsFramerate, kMediumFramerate).toInt();
|
2014-02-07 16:34:20 +01:00
|
|
|
for (int i = 0; i < framerate_list_.count(); ++i) {
|
|
|
|
if (current_framerate_ == framerate_list_[i]) {
|
2011-03-05 19:53:48 +01:00
|
|
|
ChangeFramerate(current_framerate_);
|
2011-03-04 01:38:15 +01:00
|
|
|
group_framerate_->actions()[i]->setChecked(true);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-05 19:53:48 +01:00
|
|
|
void AnalyzerContainer::SaveFramerate(int framerate) {
|
2015-11-21 16:20:47 +01:00
|
|
|
// For now, framerate is common for all analyzers.
|
|
|
|
// Maybe each analyzer should have its own framerate?
|
2011-03-05 19:53:48 +01:00
|
|
|
current_framerate_ = framerate;
|
2011-03-04 01:38:15 +01:00
|
|
|
QSettings s;
|
|
|
|
s.beginGroup(kSettingsGroup);
|
2011-03-05 19:53:48 +01:00
|
|
|
s.setValue(kSettingsFramerate, current_framerate_);
|
2010-03-20 23:45:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void AnalyzerContainer::Save() {
|
|
|
|
QSettings s;
|
|
|
|
s.beginGroup(kSettingsGroup);
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
s.setValue("type", current_analyzer_
|
|
|
|
? current_analyzer_->metaObject()->className()
|
|
|
|
: QVariant());
|
2010-03-20 23:45:54 +01:00
|
|
|
}
|
2011-03-04 01:38:15 +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
|
|
|
void AnalyzerContainer::SavePsychedelic() {
|
|
|
|
QSettings s;
|
|
|
|
s.beginGroup(kSettingsGroup);
|
|
|
|
|
|
|
|
s.setValue("psychedelic", psychedelic_colors_on_);
|
|
|
|
}
|
|
|
|
|
2011-03-05 19:53:48 +01:00
|
|
|
void AnalyzerContainer::AddFramerate(const QString& name, int framerate) {
|
2014-02-07 16:34:20 +01:00
|
|
|
QAction* action =
|
|
|
|
context_menu_framerate_->addAction(name, mapper_framerate_, SLOT(map()));
|
2011-03-05 19:53:48 +01:00
|
|
|
mapper_framerate_->setMapping(action, framerate);
|
2011-03-04 01:38:15 +01:00
|
|
|
group_framerate_->addAction(action);
|
2011-03-05 19:53:48 +01:00
|
|
|
framerate_list_ << framerate;
|
2011-03-04 01:38:15 +01:00
|
|
|
action->setCheckable(true);
|
|
|
|
}
|
2015-11-21 16:20:47 +01:00
|
|
|
|