Commit ea05cddb authored by Geoffroy Lacarriere's avatar Geoffroy Lacarriere

Move of the graphic audioGraph generation in a new runnable class

parent 9c09dc17
#include "AudioSpectrumDrawer.h"
AudioSpectrumDrawer::AudioSpectrumDrawer( QPainter* painter, int height, int width, QList<int>* audioValueList )
: m_painter( painter ), m_height( height ), m_width( width ), m_audioValueList( audioValueList )
{
m_painter->setRenderHint( QPainter::Antialiasing, true );
m_painter->setPen( QPen( QColor( 79, 106, 25 ), 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin ) );
}
void AudioSpectrumDrawer::run()
{
qreal max = 0;
for( int i = 0; i < m_audioValueList->count(); i++ )
if ( m_audioValueList->at(i) > max )
max = m_audioValueList->at(i);
for( int x = 0; x < m_audioValueList->count(); x++ )
{
if ( x <= m_height )
{
qreal y = ( (qreal)m_audioValueList->at(x) / max ) * 500;
y -= 365;
m_path.lineTo( x, y );
}
}
m_painter->drawPath( m_path );
}
#ifndef AUDIOSPECTRUMDRAWER_H
#define AUDIOSPECTRUMDRAWER_H
#include <QList>
#include <QPainter>
#include <QRunnable>
class AudioSpectrumDrawer : public QRunnable
{
private:
QPainter* m_painter;
int m_height;
int m_width;
QList<int>* m_audioValueList;
QPainterPath m_path;
public:
AudioSpectrumDrawer( QPainter* painter, int height, int width, QList<int>* audioValueList );
void run();
};
#endif // AUDIOSPECTRUMDRAWER_H
FORMS += ui/About.ui \
ui/ClipProperty.ui \
ui/Import.ui \
ui/MainWindow.ui \
ui/PreviewWidget.ui \
ui/TagWidget.ui \
ui/Timeline.ui \
ui/transcode.ui \
ui/WorkflowFileRendererDialog.ui
HEADERS += About.h \
AbstractGraphicsMediaItem.h \
ClickableLabel.h \
ClipProperty.h \
DockWidgetManager.h \
FileInfoListModel.h \
GraphicsAudioItem.h \
GraphicsCursorItem.h \
GraphicsMovieItem.h \
GraphicsTrack.hpp \
ImportMediaCellView.h \
ImportMediaListController.h \
LanguagePreferences.h \
LCDTimecode.h \
MainWindow.h \
PreviewRuler.h \
PreviewWidget.h \
TagWidget.h \
Timeline.h \
TracksControls.h \
TracksRuler.h \
TracksScene.h \
TracksView.h \
UndoStack.h \
WorkflowFileRendererDialog.h
SOURCES += About.cpp \
AbstractGraphicsMediaItem.cpp \
ClickableLabel.cpp \
ClipProperty.cpp \
DockWidgetManager.cpp \
FileInfoListModel.cpp \
GraphicsAudioItem.cpp \
GraphicsCursorItem.cpp \
GraphicsMovieItem.cpp \
ImportMediaCellView.cpp \
ImportMediaListController.cpp \
LanguagePreferences.cpp \
LCDTimecode.cpp \
MainWindow.cpp \
PreviewRuler.cpp \
PreviewWidget.cpp \
TagWidget.cpp \
Timeline.cpp \
TracksControls.cpp \
TracksRuler.cpp \
TracksScene.cpp \
TracksView.cpp \
UndoStack.cpp \
WorkflowFileRendererDialog.cpp
FORMS += ui/About.ui \
ui/ClipProperty.ui \
ui/Import.ui \
ui/MainWindow.ui \
ui/PreviewWidget.ui \
ui/TagWidget.ui \
ui/Timeline.ui \
ui/transcode.ui \
ui/WorkflowFileRendererDialog.ui
HEADERS += About.h \
AbstractGraphicsMediaItem.h \
ClickableLabel.h \
ClipProperty.h \
DockWidgetManager.h \
FileInfoListModel.h \
GraphicsAudioItem.h \
GraphicsCursorItem.h \
GraphicsMovieItem.h \
GraphicsTrack.hpp \
ImportMediaCellView.h \
ImportMediaListController.h \
LanguagePreferences.h \
LCDTimecode.h \
MainWindow.h \
PreviewRuler.h \
PreviewWidget.h \
TagWidget.h \
Timeline.h \
TracksControls.h \
TracksRuler.h \
TracksScene.h \
TracksView.h \
UndoStack.h \
WorkflowFileRendererDialog.h \
AudioSpectrumDrawer.h
SOURCES += About.cpp \
AbstractGraphicsMediaItem.cpp \
ClickableLabel.cpp \
ClipProperty.cpp \
DockWidgetManager.cpp \
FileInfoListModel.cpp \
GraphicsAudioItem.cpp \
GraphicsCursorItem.cpp \
GraphicsMovieItem.cpp \
ImportMediaCellView.cpp \
ImportMediaListController.cpp \
LanguagePreferences.cpp \
LCDTimecode.cpp \
MainWindow.cpp \
PreviewRuler.cpp \
PreviewWidget.cpp \
TagWidget.cpp \
Timeline.cpp \
TracksControls.cpp \
TracksRuler.cpp \
TracksScene.cpp \
TracksView.cpp \
UndoStack.cpp \
WorkflowFileRendererDialog.cpp \
AudioSpectrumDrawer.cpp
......@@ -31,49 +31,6 @@
#include <QThreadPool>
#include <QRunnable>
class AudioSpectrumHelper : public QRunnable
{
private:
QList<int>* m_audioValueList;
QImage* m_image;
QPainter* m_painter;
QPainterPath m_path;
public:
AudioSpectrumHelper(QList<int>* audioValueList) : m_audioValueList( audioValueList )
{
int imageHeight = 50;
m_image = new QImage( m_audioValueList->count(), imageHeight, QImage::Format_RGB32 );
m_image->fill( 0 );
m_painter = new QPainter( m_image );
m_painter->setRenderHint( QPainter::Antialiasing, true );
m_painter->setPen( QPen( QColor( 79, 106, 25 ), 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin ) );
}
void run()
{
int averageValue = 0;
qreal max = 0;
for( int i = 0; i < m_audioValueList->count(); i++ )
{
averageValue += m_audioValueList->at(i);
if ( m_audioValueList->at(i) > max )
max = m_audioValueList->at(i);
}
averageValue /= m_audioValueList->count();
for( int x = 0; x < m_audioValueList->count(); x++ )
{
qreal y = ( (qreal)m_audioValueList->at(x) / max ) * 500;
y -= 365;
m_path.lineTo( x, y );
}
m_painter->drawPath( m_path );
}
};
MetaDataWorker::MetaDataWorker( LibVLCpp::MediaPlayer* mediaPlayer, Media* media, MetaDataWorker::MetaDataType type ) :
m_mediaPlayer( mediaPlayer ),
m_type( type ),
......@@ -200,8 +157,7 @@ void MetaDataWorker::renderSnapshot()
connect( m_mediaPlayer, SIGNAL( snapshotTaken() ), this, SLOT( setSnapshot() ), Qt::QueuedConnection );
//The slot should be triggered in this methode
m_mediaPlayer->takeSnapshot( m_tmpSnapshotFilename.toStdString().c_str()
, 0, 0 );
m_mediaPlayer->takeSnapshot( m_tmpSnapshotFilename.toStdString().c_str(), 0, 0 );
//Snapshot slot should has been called (but maybe not in next version...)
}
......@@ -221,7 +177,8 @@ void MetaDataWorker::setSnapshot()
//CHECKME:
//This is synchrone, but it may become asynchrone in the future...
// connect( m_mediaPlayer, SIGNAL( stopped () ), this, SLOT( mediaPlayerStopped() ), Qt::QueuedConnection );
m_mediaPlayer->stop();
if ( m_mediaIsPlaying )
m_mediaPlayer->stop();
emit mediaPlayerIdle( m_mediaPlayer );
if ( m_type == Snapshot )
......@@ -296,9 +253,10 @@ void MetaDataWorker::generateAudioSpectrum()
disconnect( m_mediaPlayer, SIGNAL( endReached() ), this, SLOT( generateAudioSpectrum() ) );
m_mediaPlayer->stop();
emit mediaPlayerIdle( m_mediaPlayer );
AudioSpectrumHelper* audioSpectrum = new AudioSpectrumHelper( m_media->getAudioValues() );
audioSpectrum->setAutoDelete( true );
QThreadPool::globalInstance()->start( audioSpectrum );
// AudioSpectrumHelper* audioSpectrum = new AudioSpectrumHelper( m_media->getAudioValues() );
// audioSpectrum->setAutoDelete( true );
// QThreadPool::globalInstance()->start( audioSpectrum );
m_media->emitAudioSpectrumComuted();
delete this;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment