2010-06-06 16:06:23 +02:00
|
|
|
/* 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"
|
|
|
|
|
|
|
|
#include <QTimerEvent>
|
2010-06-06 20:18:06 +02:00
|
|
|
#include <QPainter>
|
|
|
|
#include <QPaintEngine>
|
2010-06-06 16:06:23 +02:00
|
|
|
#include <QtDebug>
|
2010-06-06 20:18:06 +02:00
|
|
|
#include <QGLWidget>
|
|
|
|
#include <QGraphicsView>
|
2010-06-06 16:06:23 +02:00
|
|
|
|
|
|
|
#include <libprojectM/projectM.hpp>
|
2010-06-06 20:18:06 +02:00
|
|
|
#include <GL/gl.h>
|
2010-06-06 16:06:23 +02:00
|
|
|
|
2010-06-06 20:18:06 +02:00
|
|
|
ProjectMVisualisation::ProjectMVisualisation(QObject *parent)
|
|
|
|
: QGraphicsScene(parent),
|
2010-06-06 16:06:23 +02:00
|
|
|
projectm_(NULL)
|
|
|
|
{
|
2010-06-06 20:18:06 +02:00
|
|
|
connect(this, SIGNAL(sceneRectChanged(QRectF)), SLOT(SceneRectChanged(QRectF)));
|
2010-06-06 16:06:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ProjectMVisualisation::~ProjectMVisualisation() {
|
|
|
|
}
|
|
|
|
|
2010-06-06 20:18:06 +02:00
|
|
|
void ProjectMVisualisation::drawBackground(QPainter* p, const QRectF&) {
|
|
|
|
p->beginNativePainting();
|
2010-06-06 16:06:23 +02:00
|
|
|
|
2010-06-06 20:18:06 +02:00
|
|
|
if (!projectm_) {
|
|
|
|
projectm_.reset(new projectM("/usr/share/projectM/config.inp"));
|
|
|
|
}
|
2010-06-06 16:06:23 +02:00
|
|
|
|
2010-06-06 20:18:06 +02:00
|
|
|
projectm_->projectM_resetGL(sceneRect().width(), sceneRect().height());
|
2010-06-06 16:06:23 +02:00
|
|
|
projectm_->renderFrame();
|
2010-06-06 20:18:06 +02:00
|
|
|
|
|
|
|
p->endNativePainting();
|
2010-06-06 16:06:23 +02:00
|
|
|
}
|
|
|
|
|
2010-06-06 20:18:06 +02:00
|
|
|
void ProjectMVisualisation::SceneRectChanged(const QRectF &rect) {
|
|
|
|
if (projectm_)
|
|
|
|
projectm_->projectM_resetGL(rect.width(), rect.height());
|
2010-06-06 16:06:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProjectMVisualisation::ConsumeBuffer(GstBuffer *buffer, GstEnginePipeline*) {
|
|
|
|
const int samples = GST_BUFFER_SIZE(buffer) / sizeof(short);
|
|
|
|
const short* data = reinterpret_cast<short*>(GST_BUFFER_DATA(buffer));
|
|
|
|
|
2010-06-06 20:18:06 +02:00
|
|
|
if (projectm_)
|
|
|
|
projectm_->pcm()->addPCM16Data(data, samples);
|
2010-06-06 16:06:23 +02:00
|
|
|
gst_buffer_unref(buffer);
|
|
|
|
}
|