Commit f79d8339 authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

Refactored code to match the new Renderer/PreviewWidget behaviour

parent 84c2f6c8
......@@ -36,6 +36,7 @@
#include "Transcode.h"
#include "FileBrowser.h"
#include "PreviewWidget.h"
#include "WorkflowRenderer.h"
MainWindow::MainWindow( QWidget *parent ) :
QMainWindow( parent ), m_renderer( NULL )
......@@ -144,7 +145,7 @@ void MainWindow::m_initializeDockWidgets( void )
setupLibrary();
dockManager->addDockedWidget( new PreviewWidget( m_timeline->getMainWorkflow(), this ),
dockManager->addDockedWidget( new PreviewWidget( new WorkflowRenderer( m_timeline->getMainWorkflow() ), this ),
tr( "Preview" ),
Qt::AllDockWidgetAreas,
QDockWidget::AllDockWidgetFeatures,
......
......@@ -30,12 +30,11 @@
#include "MediaListWidget.h"
#include "Library.h"
PreviewWidget::PreviewWidget( MainWorkflow* mainWorkflow, QWidget *parent ) :
PreviewWidget::PreviewWidget( GenericRenderer* genericRenderer, QWidget *parent ) :
QWidget( parent ),
m_ui( new Ui::PreviewWidget ),
m_currentPreviewRenderer( NULL ),
m_previewStopped( true ),
m_sliderPosBackup( 0 )
m_renderer( genericRenderer ),
m_previewStopped( true )
{
m_ui->setupUi( this );
......@@ -50,42 +49,18 @@ PreviewWidget::PreviewWidget( MainWorkflow* mainWorkflow, QWidget *parent ) :
connect( m_ui->seekSlider, SIGNAL( sliderPosChanged(int) ), this, SLOT( seekSliderMoved(int) ) );
connect( m_ui->seekSlider, SIGNAL( sliderReleased() ), this, SLOT( seekSliderReleased() ) );
initClipPreview();
initRenderPreview( mainWorkflow );
m_currentMode = m_ui->tabWidget->currentIndex();
m_currentPreviewRenderer = m_renderPreview;
connect( m_ui->tabWidget, SIGNAL( currentChanged(int) ), this, SLOT( changedTab(int) ) );
m_renderer->setRenderWidget( m_ui->renderWidget );
connect( m_renderer, SIGNAL( stopped() ), this, SLOT( videoStopped() ) );
connect( m_renderer, SIGNAL( paused() ), this, SLOT( videoPaused() ) );
connect( m_renderer, SIGNAL( playing() ), this, SLOT( videoPlaying() ) );
connect( m_renderer, SIGNAL( positionChanged(float) ), this, SLOT( positionChanged(float) ) );
connect( m_renderer, SIGNAL( endReached() ), this, SLOT( endReached() ) );
}
PreviewWidget::~PreviewWidget()
{
delete m_ui;
delete m_clipPreview;
delete m_renderPreview;
}
void PreviewWidget::initClipPreview()
{
m_clipPreview = new ClipPreviewWidget( m_ui->clipPreviewRenderWidget );
connectPreview( m_clipPreview );
}
void PreviewWidget::initRenderPreview( MainWorkflow* mainWorkflow )
{
m_renderPreview = new RenderPreviewWidget( mainWorkflow, m_ui->renderPreviewRenderWidget );
connectPreview( m_renderPreview );
}
void PreviewWidget::connectPreview( GenericPreviewWidget* target )
{
//WARNING: the slots must NOT be virtual, since this is called from the constructor
// which would be unsafe... if not fatal...
connect( target, SIGNAL( stopped() ), this, SLOT( videoStopped() ) );
connect( target, SIGNAL( paused() ), this, SLOT( videoPaused() ) );
connect( target, SIGNAL( playing() ), this, SLOT( videoPlaying() ) );
connect( target, SIGNAL( positionChanged(float) ), this, SLOT( positionChanged(float) ) );
connect( target, SIGNAL( endReached() ), this, SLOT( endReached() ) );
delete m_renderer;
}
void PreviewWidget::changeEvent( QEvent *e )
......@@ -130,14 +105,11 @@ void PreviewWidget::dropEvent( QDropEvent* event )
qDebug() << "Unknown media" << event->mimeData()->data( "vlmc/uuid" );
return ;
}
if ( m_currentMode != PreviewWidget::clipPreviewMode )
m_ui->tabWidget->setCurrentIndex( PreviewWidget::clipPreviewMode );
m_clipPreview->startPreview( media );
m_renderer->startPreview( media );
event->acceptProposedAction();
m_previewStopped = false;
}
//else: I don't see how we could drag and drop a workflow :o (at the moment)
}
void PreviewWidget::positionChanged( float newPos )
......@@ -149,7 +121,7 @@ void PreviewWidget::positionChanged( float newPos )
void PreviewWidget::seekSliderPressed()
{
disconnect( m_currentPreviewRenderer, SIGNAL( positionChanged( float ) ),
disconnect( m_renderer, SIGNAL( positionChanged( float ) ),
this, SLOT( positionChanged( float ) ) );
}
......@@ -162,7 +134,7 @@ void PreviewWidget::seekSliderMoved( int )
}
m_endReached = false;
//Putting back the slider value into vlc position
m_currentPreviewRenderer->setPosition( (float)m_ui->seekSlider->value() / 1000.0f );
m_renderer->setPosition( (float)m_ui->seekSlider->value() / 1000.0f );
}
void PreviewWidget::seekSliderReleased()
......@@ -173,10 +145,10 @@ void PreviewWidget::seekSliderReleased()
//When we will release our slider, if endReached is true, we actually set the position.
//Otherwise, we do nothing.
//This prevents the video to stop if we put the slider to the maximum right by mistake
m_currentPreviewRenderer->setPosition( (float)m_ui->seekSlider->maximum() );
m_renderer->setPosition( (float)m_ui->seekSlider->maximum() );
m_previewStopped = false;
}
connect( m_currentPreviewRenderer, SIGNAL( positionChanged( float ) ),
connect( m_renderer, SIGNAL( positionChanged( float ) ),
this, SLOT( positionChanged( float ) ) );
}
......@@ -185,7 +157,7 @@ void PreviewWidget::on_pushButtonStop_clicked()
if ( m_previewStopped == false )
{
m_previewStopped = true;
m_currentPreviewRenderer->stop();
m_renderer->stop();
}
}
......@@ -197,7 +169,7 @@ void PreviewWidget::on_pushButtonPlay_clicked()
// qDebug() << methodIndex;
// QMetaMethod method = m_currentPreviewRenderer->metaObject()->method( methodIndex );
// qDebug() << method.invoke( m_currentPreviewRenderer, Qt::QueuedConnection, Q_ARG(bool, false) );
m_currentPreviewRenderer->togglePlayPause();
m_renderer->togglePlayPause();
}
void PreviewWidget::videoPaused()
......@@ -224,35 +196,15 @@ void PreviewWidget::endReached()
m_ui->seekSlider->setValue( 0 );
}
void PreviewWidget::changedTab( int tabId )
{
m_currentPreviewRenderer->togglePlayPause( true );
if ( tabId == PreviewWidget::clipPreviewMode )
{
m_currentPreviewRenderer = m_clipPreview;
}
else if ( tabId == PreviewWidget::renderPreviewMode )
{
m_currentPreviewRenderer = m_renderPreview;
}
else
qDebug() << "Unknown and uncoherent tabId for PreviewWidget : " << tabId;
m_currentMode = !m_currentMode;
int tmp = m_ui->seekSlider->value();
m_ui->seekSlider->setValue( m_sliderPosBackup );
m_sliderPosBackup = tmp;
}
void PreviewWidget::on_pushButtonNextFrame_clicked()
{
if ( m_previewStopped == false )
m_currentPreviewRenderer->nextFrame();
m_renderer->nextFrame();
}
void PreviewWidget::on_pushButtonPreviousFrame_clicked()
{
if ( m_previewStopped == false )
m_currentPreviewRenderer->previousFrame();
m_renderer->previousFrame();
}
......@@ -26,8 +26,7 @@
#include <QWidget>
#include "Workflow/MainWorkflow.h"
#include "ClipPreviewWidget.h"
#include "RenderPreviewWidget.h"
#include "GenericRenderer.h"
namespace Ui {
class PreviewWidget;
......@@ -39,26 +38,14 @@ class PreviewWidget : public QWidget
Q_DISABLE_COPY( PreviewWidget )
public:
explicit PreviewWidget( MainWorkflow* mainWorkflow, QWidget* parent = NULL );
explicit PreviewWidget( GenericRenderer* renderer, QWidget* parent = NULL );
virtual ~PreviewWidget();
private:
void initRenderPreview( MainWorkflow* );
void initClipPreview();
void connectPreview( GenericPreviewWidget* target );
private:
Ui::PreviewWidget* m_ui;
GenericPreviewWidget* m_clipPreview;
GenericPreviewWidget* m_renderPreview;
GenericPreviewWidget* m_currentPreviewRenderer;
GenericRenderer* m_renderer;
bool m_endReached;
bool m_previewStopped;
int m_currentMode;
static const int renderPreviewMode = 0;
static const int clipPreviewMode = 1;
int m_sliderPosBackup;
protected:
virtual void changeEvent( QEvent *e );
......@@ -77,8 +64,6 @@ private slots:
void videoPlaying();
void videoStopped();
void endReached();
void changedTab( int );
};
#endif // PREVIEWWIDGET_H
......@@ -22,19 +22,20 @@
#include <QtDebug>
#include "ClipPreviewWidget.h"
#include "ClipRenderer.h"
ClipPreviewWidget::ClipPreviewWidget( QWidget* renderWidget ) :
GenericPreviewWidget( renderWidget ),
m_clipLoaded( false ), m_vlcMedia( NULL )
ClipRenderer::ClipRenderer() :
GenericRenderer(),
m_clipLoaded( false ),
m_vlcMedia( NULL )
{
}
ClipPreviewWidget::~ClipPreviewWidget()
ClipRenderer::~ClipRenderer()
{
}
void ClipPreviewWidget::startPreview( Media* media )
void ClipRenderer::startPreview( Media* media )
{
if ( m_vlcMedia != NULL )
delete m_vlcMedia;
......@@ -54,14 +55,14 @@ void ClipPreviewWidget::startPreview( Media* media )
m_paused = false;
}
void ClipPreviewWidget::setPosition( float newPos )
void ClipRenderer::setPosition( float newPos )
{
if ( m_clipLoaded == false || m_isRendering == false )
return ;
m_mediaPlayer->setPosition( newPos );
}
void ClipPreviewWidget::stop()
void ClipRenderer::stop()
{
if ( m_clipLoaded == true && m_isRendering == true )
{
......@@ -76,7 +77,7 @@ void ClipPreviewWidget::stop()
}
}
void ClipPreviewWidget::togglePlayPause( bool forcePause )
void ClipRenderer::togglePlayPause( bool forcePause )
{
if ( m_clipLoaded == false)
return ;
......@@ -95,7 +96,7 @@ void ClipPreviewWidget::togglePlayPause( bool forcePause )
}
}
void ClipPreviewWidget::nextFrame()
void ClipRenderer::nextFrame()
{
if ( m_isRendering == true && m_paused == true )
{
......@@ -104,7 +105,7 @@ void ClipPreviewWidget::nextFrame()
}
}
void ClipPreviewWidget::previousFrame()
void ClipRenderer::previousFrame()
{
if ( m_isRendering == false && m_paused == true )
{
......@@ -116,29 +117,29 @@ void ClipPreviewWidget::previousFrame()
/////////////////////////////////////////////////////////////////////
/////SLOTS :
/////////////////////////////////////////////////////////////////////
void ClipPreviewWidget::__videoPaused()
void ClipRenderer::__videoPaused()
{
emit paused();
}
void ClipPreviewWidget::__videoStopped()
void ClipRenderer::__videoStopped()
{
emit stopped();
}
void ClipPreviewWidget::__videoPlaying()
void ClipRenderer::__videoPlaying()
{
emit playing();
}
void ClipPreviewWidget::__positionChanged()
void ClipRenderer::__positionChanged()
{
if ( m_clipLoaded == false)
return ;
emit positionChanged( m_mediaPlayer->getPosition() );
}
void ClipPreviewWidget::__endReached()
void ClipRenderer::__endReached()
{
m_mediaPlayer->stop();
m_isRendering = false;
......
......@@ -28,7 +28,7 @@
#include "VLCMediaPlayer.h"
#include "Media.h"
#include "GenericPreviewWidget.h"
#include "GenericRenderer.h"
//TODO: This should really share a common interface with RenderPreviewWorkflow
class ClipRenderer : public GenericRenderer
......@@ -37,7 +37,7 @@ class ClipRenderer : public GenericRenderer
Q_DISABLE_COPY( ClipRenderer )
public:
explicit ClipRenderer( QWidget* renderWidget );
explicit ClipRenderer();
virtual ~ClipRenderer();
virtual void startPreview( Media* media );
......
......@@ -35,18 +35,21 @@ class GenericRenderer : public QObject
Q_DISABLE_COPY( GenericRenderer );
public:
explicit GenericRenderer( QWidget* renderWidget ) :
explicit GenericRenderer() :
m_paused( false ),
m_isRendering( false )
{
m_mediaPlayer = new LibVLCpp::MediaPlayer();
m_mediaPlayer->setDrawable( renderWidget->winId() );
}
virtual ~GenericRenderer()
{
delete m_mediaPlayer;
}
virtual void setRenderWidget( QWidget* renderWidget )
{
m_mediaPlayer->setDrawable( renderWidget->winId() );
}
virtual void startPreview( Media* media ) = 0;
virtual void setPosition( float newPos ) = 0;
virtual void togglePlayPause( bool forcePause = false ) = 0;
......
/*****************************************************************************
* RenderPreviewWidget.cpp: Allow a current workflow preview
* WorkflowRenderer.cpp: Allow a current workflow preview
*****************************************************************************
* Copyright (C) 2008-2009 the VLMC team
*
......@@ -24,11 +24,10 @@
#include <QThread>
#include "vlmc.h"
#include "RenderPreviewWidget.h"
#include "WorkflowRenderer.h"
#include "Timeline.h"
RenderPreviewWidget::RenderPreviewWidget( MainWorkflow* mainWorkflow, QWidget* renderWidget ) :
GenericPreviewWidget( renderWidget ),
WorkflowRenderer::WorkflowRenderer( MainWorkflow* mainWorkflow ) :
m_mainWorkflow( mainWorkflow ),
m_framePlayed( false )
{
......@@ -46,9 +45,9 @@ RenderPreviewWidget::RenderPreviewWidget( MainWorkflow* mainWorkflow, QWidget* r
m_media->addOption( buffer );
sprintf( buffer, ":invmem-height=%i", VIDEOHEIGHT );
m_media->addOption( buffer );
sprintf( buffer, ":invmem-lock=%lld", (qint64)RenderPreviewWidget::lock );
sprintf( buffer, ":invmem-lock=%lld", (qint64)WorkflowRenderer::lock );
m_media->addOption( buffer );
sprintf( buffer, ":invmem-unlock=%lld", (qint64)RenderPreviewWidget::unlock );
sprintf( buffer, ":invmem-unlock=%lld", (qint64)WorkflowRenderer::unlock );
m_media->addOption( buffer );
sprintf( buffer, ":invmem-data=%lld", (qint64)this );
m_media->addOption( buffer );
......@@ -62,7 +61,7 @@ RenderPreviewWidget::RenderPreviewWidget( MainWorkflow* mainWorkflow, QWidget* r
}
RenderPreviewWidget::~RenderPreviewWidget()
WorkflowRenderer::~WorkflowRenderer()
{
m_mediaPlayer->stop();
......@@ -75,29 +74,29 @@ RenderPreviewWidget::~RenderPreviewWidget()
delete m_media;
}
void* RenderPreviewWidget::lock( void* datas )
void* WorkflowRenderer::lock( void* datas )
{
RenderPreviewWidget* self = reinterpret_cast<RenderPreviewWidget*>( datas );
WorkflowRenderer* self = reinterpret_cast<WorkflowRenderer*>( datas );
void* ret = self->m_mainWorkflow->getOutput();
return ret;
}
void RenderPreviewWidget::unlock( void* datas )
void WorkflowRenderer::unlock( void* datas )
{
RenderPreviewWidget* self = reinterpret_cast<RenderPreviewWidget*>( datas );
WorkflowRenderer* self = reinterpret_cast<WorkflowRenderer*>( datas );
QWriteLocker lock( self->m_framePlayedLock );
self->m_framePlayed = true;
}
void RenderPreviewWidget::stopPreview()
void WorkflowRenderer::stopPreview()
{
disconnect( m_mainWorkflow, SIGNAL( frameChanged(qint64) ),
Timeline::getInstance()->tracksView()->tracksCursor(), SLOT( updateCursorPos( qint64 ) ) );
stop();
}
void RenderPreviewWidget::startPreview( Media* )
void WorkflowRenderer::startPreview( Media* )
{
char buff[128];
......@@ -111,12 +110,12 @@ void RenderPreviewWidget::startPreview( Media* )
m_paused = false;
}
void RenderPreviewWidget::setPosition( float newPos )
void WorkflowRenderer::setPosition( float newPos )
{
m_mainWorkflow->setPosition( newPos );
}
void RenderPreviewWidget::nextFrame()
void WorkflowRenderer::nextFrame()
{
{
QWriteLocker lock( m_framePlayedLock );
......@@ -134,12 +133,12 @@ void RenderPreviewWidget::nextFrame()
m_mediaPlayer->pause();
}
void RenderPreviewWidget::previousFrame()
void WorkflowRenderer::previousFrame()
{
}
void RenderPreviewWidget::togglePlayPause( bool forcePause )
void WorkflowRenderer::togglePlayPause( bool forcePause )
{
//If force pause is true, we just ensure that this render is paused... no need to start it.
if ( m_isRendering == false && forcePause == false )
......@@ -164,7 +163,7 @@ void RenderPreviewWidget::togglePlayPause( bool forcePause )
}
}
void RenderPreviewWidget::stop()
void WorkflowRenderer::stop()
{
m_isRendering = false;
m_paused = false;
......@@ -176,33 +175,33 @@ void RenderPreviewWidget::stop()
/////SLOTS :
/////////////////////////////////////////////////////////////////////
void RenderPreviewWidget::__endReached()
void WorkflowRenderer::__endReached()
{
stopPreview();
emit endReached();
}
void RenderPreviewWidget::__positionChanged()
void WorkflowRenderer::__positionChanged()
{
qFatal("This should never be used ! Get out of here !");
}
void RenderPreviewWidget::__positionChanged( float pos )
void WorkflowRenderer::__positionChanged( float pos )
{
emit positionChanged( pos );
}
void RenderPreviewWidget::__videoPaused()
void WorkflowRenderer::__videoPaused()
{
emit paused();
}
void RenderPreviewWidget::__videoPlaying()
void WorkflowRenderer::__videoPlaying()
{
emit playing();
}
void RenderPreviewWidget::__videoStopped()
void WorkflowRenderer::__videoStopped()
{
emit endReached();
}
......@@ -28,15 +28,15 @@
#include <QWidget>
#include "Workflow/MainWorkflow.h"
#include "GenericPreviewWidget.h"
#include "GenericRenderer.h"
class WorkflowRenderer : public GenericPreviewWidget
class WorkflowRenderer : public GenericRenderer
{
Q_OBJECT
Q_DISABLE_COPY( WorkflowRenderer )
public:
WorkflowRenderer( MainWorkflow* mainWorkflow, QWidget* renderWidget );
WorkflowRenderer( MainWorkflow* mainWorkflow );
~WorkflowRenderer();
virtual void startPreview( Media* );
......
......@@ -21,7 +21,7 @@ SOURCES += src/main.cpp \
src/LibVLCpp/VLCMedia.cpp \
src/gui/TracksView.cpp \
src/gui/TracksScene.cpp \
src/gui/ClipRenderer.cpp \
src/renderer/ClipRenderer.cpp \
src/gui/TracksRuler.cpp \
src/gui/Preferences.cpp \
src/gui/ListViewMediaItem.cpp \
......@@ -41,7 +41,7 @@ SOURCES += src/main.cpp \
src/Workflow/TrackWorkflow.cpp \
src/Workflow/MainWorkflow.cpp \
src/gui/PreviewWidget.cpp \
src/gui/WorkflowRenderer.cpp \
src/renderer/WorkflowRenderer.cpp \
src/API/vlmc_module_variables.cpp \
src/API/Module.cpp \
src/API/ModuleManager.cpp \
......@@ -57,7 +57,7 @@ HEADERS += src/gui/MainWindow.h \
src/LibVLCpp/VLCMedia.h \
src/gui/TracksView.h \
src/gui/TracksScene.h \
src/gui/ClipRenderer.h \
src/renderer/ClipRenderer.h \
src/gui/TracksRuler.h \
src/gui/Preferences.h \
src/gui/ListViewMediaItem.h \
......@@ -79,8 +79,8 @@ HEADERS += src/gui/MainWindow.h \
src/Workflow/TrackWorkflow.h \
src/Workflow/MainWorkflow.h \
src/gui/PreviewWidget.h \
src/gui/WorkflowRenderer.h \
src/gui/GenericRenderer.h \
src/renderer/WorkflowRenderer.h \
src/renderer/GenericRenderer.h \
src/tools/Toggleable.hpp \
src/API/vlmc_module.h \
src/API/Module.h \
......@@ -106,7 +106,7 @@ RESOURCES += ressources.qrc
INCLUDEPATH += src/LibVLCpp \
src/gui \
src/tools \
src/renderer
src/renderer \
src
LIBS = -L/usr/local/lib \
-lvlc
......
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