Clementine-audio-player-Mac.../src/visualisations/projectmvisualisation.cpp

137 lines
3.5 KiB
C++
Raw Normal View History

/* This file is part of Clementine.
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/>.
*/
#include "projectmvisualisation.h"
2010-06-07 03:55:21 +02:00
#include "visualisationcontainer.h"
#include <QTimerEvent>
2010-06-06 20:18:06 +02:00
#include <QPainter>
#include <QPaintEngine>
#include <QtDebug>
2010-06-06 20:18:06 +02:00
#include <QGLWidget>
#include <QGraphicsView>
2010-06-07 03:55:21 +02:00
#include <QSettings>
2010-06-07 00:28:24 +02:00
#include <projectM.hpp>
2010-06-06 20:18:06 +02:00
#include <GL/gl.h>
2010-06-06 20:18:06 +02:00
ProjectMVisualisation::ProjectMVisualisation(QObject *parent)
: QGraphicsScene(parent),
projectm_(NULL),
2010-06-07 03:55:21 +02:00
mode_(0),
texture_size_(512)
{
2010-06-06 20:18:06 +02:00
connect(this, SIGNAL(sceneRectChanged(QRectF)), SLOT(SceneRectChanged(QRectF)));
}
ProjectMVisualisation::~ProjectMVisualisation() {
}
2010-06-06 20:18:06 +02:00
void ProjectMVisualisation::drawBackground(QPainter* p, const QRectF&) {
p->beginNativePainting();
2010-06-06 20:18:06 +02:00
if (!projectm_) {
projectm_.reset(new projectM("/usr/share/projectM/config.inp"));
projectm_->changeTextureSize(texture_size_);
2010-06-07 03:55:21 +02:00
Load();
2010-06-06 20:18:06 +02:00
}
2010-06-06 20:18:06 +02:00
projectm_->projectM_resetGL(sceneRect().width(), sceneRect().height());
projectm_->renderFrame();
2010-06-06 20:18:06 +02:00
p->endNativePainting();
}
2010-06-06 20:18:06 +02:00
void ProjectMVisualisation::SceneRectChanged(const QRectF &rect) {
if (projectm_)
projectm_->projectM_resetGL(rect.width(), rect.height());
}
void ProjectMVisualisation::SetTextureSize(int size) {
texture_size_ = size;
if (projectm_)
projectm_->changeTextureSize(texture_size_);
}
void ProjectMVisualisation::ConsumeBuffer(GstBuffer *buffer, GstEnginePipeline*) {
2010-06-07 00:22:02 +02:00
const int samples_per_channel = GST_BUFFER_SIZE(buffer) / sizeof(short) / 2;
const short* data = reinterpret_cast<short*>(GST_BUFFER_DATA(buffer));
2010-06-06 20:18:06 +02:00
if (projectm_)
2010-06-07 00:22:02 +02:00
projectm_->pcm()->addPCM16Data(data, samples_per_channel);
gst_buffer_unref(buffer);
}
2010-06-07 03:55:21 +02:00
void ProjectMVisualisation::set_selected(int preset, bool selected) {
if (selected)
selected_indices_.insert(preset);
else
selected_indices_.remove(preset);
Save();
}
void ProjectMVisualisation::set_all_selected(bool selected) {
selected_indices_.clear();
if (selected) {
int count = projectm_->getPlaylistSize();
for (int i=0 ; i<count ; ++i) {
selected_indices_ << i;
}
}
Save();
}
void ProjectMVisualisation::Load() {
QSettings s;
s.beginGroup(VisualisationContainer::kSettingsGroup);
QVariantList presets(s.value("presets").toList());
int count = projectm_->getPlaylistSize();
selected_indices_.clear();
if (presets.isEmpty()) {
for (int i=0 ; i<count ; ++i)
selected_indices_ << i;
} else {
foreach (const QVariant& var, presets)
if (var.toInt() < count)
selected_indices_ << var.toInt();
}
mode_ = s.value("mode", 0).toInt();
}
void ProjectMVisualisation::Save() {
QVariantList list;
foreach (int index, selected_indices_.values()) {
list << index;
}
QSettings s;
s.beginGroup(VisualisationContainer::kSettingsGroup);
s.setValue("presets", list);
s.setValue("mode", mode_);
}
void ProjectMVisualisation::set_mode(int mode) {
mode_ = mode;
Save();
}