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

PreviewWidget should now handle both Clip and Media

parent 8484c3db
......@@ -29,7 +29,9 @@ ClipRenderer::ClipRenderer() :
GenericRenderer(),
m_clipLoaded( false ),
m_vlcMedia( NULL ),
m_selectedClip( NULL ),
m_selectedMedia( NULL ),
m_begin( 0 ),
m_end( -1 ),
m_mediaChanged( false )
{
connect( m_mediaPlayer, SIGNAL( stopped() ), this, SLOT( __videoStopped() ) );
......@@ -44,9 +46,22 @@ ClipRenderer::~ClipRenderer()
stop();
}
void ClipRenderer::setMedia( Media* media )
{
m_selectedMedia = media;
m_begin = 0;
m_end = media->getNbFrames();
if ( m_isRendering == true )
m_mediaChanged = true;
else
m_clipLoaded = false;
}
void ClipRenderer::setClip( Clip* clip )
{
m_selectedClip = clip;
m_selectedMedia = clip->getParent();
m_begin = clip->getBegin();
m_end = clip->getEnd();
if ( m_isRendering == true )
m_mediaChanged = true;
else
......@@ -55,17 +70,17 @@ void ClipRenderer::setClip( Clip* clip )
void ClipRenderer::startPreview()
{
if ( m_selectedClip == NULL )
if ( m_selectedMedia == NULL )
return ;
//If an old media is found, we delete it, and disconnect
if ( m_vlcMedia != NULL )
delete m_vlcMedia;
m_vlcMedia = new LibVLCpp::Media( m_selectedClip->getParent()->getFileInfo()->absoluteFilePath() );
m_vlcMedia = new LibVLCpp::Media( m_selectedMedia->getFileInfo()->absoluteFilePath() );
m_mediaPlayer->setMedia( m_vlcMedia );
m_mediaPlayer->play();
m_mediaPlayer->setPosition( m_selectedClip->getBegin() / m_selectedClip->getLength() );
m_mediaPlayer->setPosition( m_begin / m_end );
m_clipLoaded = true;
m_isRendering = true;
m_paused = false;
......@@ -76,8 +91,8 @@ void ClipRenderer::setPosition( float newPos )
{
if ( m_clipLoaded == false || m_isRendering == false )
return ;
float begin = m_selectedClip->getBegin() / m_selectedClip->getLength();
float end = m_selectedClip->getEnd() / m_selectedClip->getEnd();
float begin = m_begin / ( m_end - m_begin );
float end = m_end / ( m_end - m_begin );
float pos = newPos * ( end - begin ) + begin;
m_mediaPlayer->setPosition( pos );
}
......@@ -116,7 +131,7 @@ void ClipRenderer::togglePlayPause( bool forcePause )
if ( m_isRendering == false )
{
m_mediaPlayer->play();
m_mediaPlayer->setPosition( m_selectedClip->getBegin() / m_selectedClip->getLength() );
m_mediaPlayer->setPosition( m_begin / ( m_end - m_begin ) );
m_isRendering = true;
}
else
......@@ -142,13 +157,14 @@ void ClipRenderer::previousFrame()
}
}
//FIXME: this won't work with clips !
void ClipRenderer::mediaUnloaded( const QUuid& uuid )
{
if ( m_selectedClip != NULL && m_selectedClip->getUuid() == uuid )
if ( m_selectedMedia != NULL && m_selectedMedia->getUuid() == uuid )
{
m_mediaPlayer->stop();
m_clipLoaded = false;
m_selectedClip = NULL;
m_selectedMedia = NULL;
m_isRendering = false;
m_paused = false;
}
......@@ -177,8 +193,8 @@ void ClipRenderer::__positionChanged()
if ( m_clipLoaded == false)
return ;
float begin = m_selectedClip->getBegin() / m_selectedClip->getLength();
float end = m_selectedClip->getEnd() / m_selectedClip->getEnd();
float begin = m_begin / ( m_end - m_begin );
float end = m_end / ( m_end - m_begin );
float pos = ( m_mediaPlayer->getPosition() - begin ) /
( end - begin );
emit positionChanged( pos );
......
......@@ -51,7 +51,9 @@ private:
private:
bool m_clipLoaded;
LibVLCpp::Media* m_vlcMedia;
Clip* m_selectedClip;
Media* m_selectedMedia;
qint64 m_begin;
qint64 m_end;
/**
* \brief This flags is used to know if a new media has been selected in the
* library. If so, we must relaunch the render if the play button is clicked again.
......@@ -60,6 +62,7 @@ private:
public slots:
virtual void setClip( Clip* clip );
virtual void setMedia( Media* media );
virtual void mediaUnloaded( const QUuid& );
void __positionChanged();
......
......@@ -86,6 +86,7 @@ public slots:
virtual void __videoPlaying() = 0;
virtual void __endReached() = 0;
virtual void setClip( Clip* ) = 0;
virtual void setMedia( Media* ) = 0;
virtual void mediaUnloaded( const QUuid& ) = 0;
......
......@@ -81,7 +81,8 @@ class WorkflowRenderer : public GenericRenderer
QWaitCondition* m_waitCond;
public slots:
void setClip( Clip* ){}
virtual void setClip( Clip* ){}
virtual void setMedia( Media* ) {}
void mediaUnloaded( const QUuid& ) {}
void timelineCursorChanged( qint64 newFrame );
......
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