Commit 2ed1e54b authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

Clip removal is now stacked.

parent 9fdbb069
......@@ -77,20 +77,23 @@ void Commands::MainWorkflow::MoveClip::undo()
m_undoRedoAction = true;
}
Commands::MainWorkflow::RemoveClips::RemoveClips( ::MainWorkflow* workflow, const QVector<ClipActionInfo>& clipsInfos ) :
m_workflow( workflow ), m_clips( clipsInfos )
Commands::MainWorkflow::RemoveClips::RemoveClips( WorkflowRenderer* renderer, const QVector<ClipActionInfo>& clipsInfos ) :
m_renderer( renderer ), m_clips( clipsInfos )
{
setText( QObject::tr( "Remove clip" ) );
}
void Commands::MainWorkflow::RemoveClips::redo()
{
for (int i = 0; i < m_clips.size(); ++i )
m_workflow->removeClip( m_clips.at( i ).clip->getUuid(), m_clips.at( i ).trackNumber, m_clips.at( i ).trackType );
{
const ClipActionInfo& clipInfo = m_clips.at( i );
m_renderer->removeClip( clipInfo.clip->getUuid(), clipInfo.trackNumber, clipInfo.trackType );
}
}
void Commands::MainWorkflow::RemoveClips::undo()
{
for (int i = 0; i < m_clips.size(); ++i )
m_workflow->addClip( m_clips.at( i ).clip, m_clips.at( i ).trackNumber, m_clips.at( i ).pos, m_clips.at( i ).trackType );
m_renderer->addClip( m_clips.at( i ).clip, m_clips.at( i ).trackNumber, m_clips.at( i ).pos, m_clips.at( i ).trackType );
}
Commands::MainWorkflow::ResizeClip::ResizeClip( ::MainWorkflow* mainWorkflow, const QUuid& uuid, unsigned int trackId,
......
......@@ -30,6 +30,7 @@
#include "UndoStack.h"
#include "MainWorkflow.h"
#include "Clip.h"
#include "WorkflowRenderer.h"
#define NEW_COMMAND(x) class x : public QUndoCommand
......@@ -84,13 +85,13 @@ namespace Commands
NEW_COMMAND( RemoveClips )
{
public:
RemoveClips( ::MainWorkflow* workflow, const QVector<ClipActionInfo>& clipsInfos );
RemoveClips( WorkflowRenderer* renderer, const QVector<ClipActionInfo>& clipsInfos );
virtual void redo();
virtual void undo();
private:
::MainWorkflow* m_workflow;
QVector<ClipActionInfo> m_clips;
WorkflowRenderer* m_renderer;
QVector<ClipActionInfo> m_clips;
};
NEW_COMMAND( ResizeClip )
......
......@@ -30,7 +30,7 @@ GreenFilterEffect::GreenFilterEffect() : GenericEffect(
GreenFilterEffect::m_videoInputsNames, GreenFilterEffect::m_nbVideoInputs,
GreenFilterEffect::m_videoOutputsNames, GreenFilterEffect::m_nbVideoOutputs
),
m_logo(QImage(QImage("vlmc.png").scaled(100, 100, Qt::KeepAspectRatio)).rgbSwapped()),
m_logo(QImage(QImage(":/images/images/vlmc.png").scaled(100, 100, Qt::KeepAspectRatio)).rgbSwapped()),
m_enabled( true )
{
};
......
......@@ -61,6 +61,7 @@ MainWindow::MainWindow( QWidget *parent ) :
QMainWindow( parent ), m_renderer( NULL )
{
m_ui.setupUi( this );
qRegisterMetaType<MainWorkflow::TrackType>( "MainWorkflow::TrackType" );
DockWidgetManager::instance( this )->setMainWindow( this );
initializeDockWidgets();
createStatusBar();
......@@ -269,7 +270,8 @@ void MainWindow::createStatusBar()
void MainWindow::initializeDockWidgets( void )
{
m_timeline = new Timeline( this );
WorkflowRenderer* workflowRenderer = new WorkflowRenderer();
m_timeline = new Timeline( workflowRenderer, this );
m_timeline->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
m_timeline->show();
setCentralWidget( m_timeline );
......@@ -290,7 +292,7 @@ void MainWindow::initializeDockWidgets( void )
QShortcut* clipShortcut = new QShortcut( QKeySequence( tr( "Ctrl+Return", "Start clip preview" ) ), this );
connect( clipShortcut, SIGNAL( activated() ), m_clipPreview, SLOT( on_pushButtonPlay_clicked() ) );
m_projectPreview = new PreviewWidget( new WorkflowRenderer(), this );
m_projectPreview = new PreviewWidget( workflowRenderer, this );
dockManager->addDockedWidget( m_projectPreview,
tr( "Project Preview" ),
Qt::AllDockWidgetAreas,
......
......@@ -29,8 +29,8 @@
Timeline* Timeline::m_instance = NULL;
Timeline::Timeline( QWidget *parent ) :
QWidget( parent ), m_scale( 1.0 )
Timeline::Timeline( WorkflowRenderer* renderer, QWidget *parent ) :
QWidget( parent ), m_scale( 1.0 ), m_renderer( renderer )
{
Q_ASSERT( m_instance == NULL );
m_instance = this;
......@@ -39,7 +39,7 @@ Timeline::Timeline( QWidget *parent ) :
m_mainWorkflow = MainWorkflow::getInstance();
m_tracksScene = new TracksScene( this );
m_tracksView = new TracksView( m_tracksScene, m_mainWorkflow, m_ui.tracksFrame );
m_tracksView = new TracksView( m_tracksScene, m_mainWorkflow, m_renderer, m_ui.tracksFrame );
m_tracksView->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
m_tracksView->scale(1, 1);
......@@ -72,7 +72,7 @@ Timeline::Timeline( QWidget *parent ) :
connect( m_tracksView, SIGNAL( durationChanged(int) ), this, SLOT( setDuration(int) ) );
connect( m_mainWorkflow, SIGNAL( clipAdded(Clip*,uint,qint64,MainWorkflow::TrackType ) ), this, SLOT( actionAddClip(Clip*,uint,qint64,MainWorkflow::TrackType ) ) );
connect( m_mainWorkflow, SIGNAL( clipMoved(QUuid, uint, qint64,MainWorkflow::TrackType ) ), this, SLOT( actionMoveClip(QUuid,uint,qint64,MainWorkflow::TrackType ) ) );
connect( m_mainWorkflow, SIGNAL( clipRemoved(QUuid,uint,MainWorkflow::TrackType ) ), this, SLOT( actionRemoveClip(QUuid,uint,MainWorkflow::TrackType )) );
connect( m_mainWorkflow, SIGNAL( clipRemoved(Clip*,uint,MainWorkflow::TrackType ) ), this, SLOT( actionRemoveClip(Clip*,uint,MainWorkflow::TrackType )) );
connect( m_mainWorkflow, SIGNAL( cleared() ), tracksView(), SLOT( clear() ) );
connect( m_tracksView, SIGNAL( videoTrackAdded(GraphicsTrack*) ),
......@@ -80,6 +80,11 @@ Timeline::Timeline( QWidget *parent ) :
connect( m_tracksView, SIGNAL( audioTrackAdded(GraphicsTrack*) ),
m_tracksControls, SLOT( addAudioTrack(GraphicsTrack*) ) );
connect( m_mainWorkflow, SIGNAL( frameChanged(qint64) ),
m_tracksView->tracksCursor(), SLOT( setCursorPos( qint64 ) ), Qt::QueuedConnection );
connect( m_tracksView->tracksCursor(), SIGNAL( cursorPositionChanged( qint64 ) ),
m_renderer, SLOT( timelineCursorChanged(qint64) ) );
m_tracksView->createLayout();
}
......@@ -130,7 +135,7 @@ void Timeline::actionMoveClip( const QUuid& uuid, unsigned int track, qint64 tim
tracksRuler()->update();
}
void Timeline::actionRemoveClip( const QUuid& uuid, unsigned int track, MainWorkflow::TrackType )
void Timeline::actionRemoveClip( Clip* clip, unsigned int track, MainWorkflow::TrackType )
{
tracksView()->removeMediaItem( uuid, track );
tracksView()->removeMediaItem( clip->getUuid(), track );
}
......@@ -28,6 +28,7 @@
#include "TracksRuler.h"
#include "TracksControls.h"
#include "Workflow/MainWorkflow.h"
#include "WorkflowRenderer.h"
class TracksScene;
class TracksView;
......@@ -37,7 +38,7 @@ class Timeline : public QWidget
Q_OBJECT
Q_DISABLE_COPY( Timeline )
public:
explicit Timeline( QWidget *parent = 0 );
explicit Timeline( WorkflowRenderer* renderer, QWidget *parent = 0 );
virtual ~Timeline();
TracksView* tracksView() { return m_tracksView; }
TracksScene* tracksScene() { return m_tracksScene; }
......@@ -50,7 +51,7 @@ public slots:
void setTool( ToolButtons button );
void actionAddClip( Clip* clip, unsigned int track, qint64 start, MainWorkflow::TrackType );
void actionMoveClip( const QUuid& uuid, unsigned int track, qint64 time, MainWorkflow::TrackType );
void actionRemoveClip( const QUuid& uuid, unsigned int track, MainWorkflow::TrackType );
void actionRemoveClip( Clip* clip, unsigned int track, MainWorkflow::TrackType );
protected:
virtual void changeEvent( QEvent *e );
......@@ -63,6 +64,7 @@ private:
TracksControls* m_tracksControls;
double m_scale;
MainWorkflow* m_mainWorkflow;
WorkflowRenderer* m_renderer;
static Timeline* m_instance;
};
......
......@@ -73,7 +73,7 @@ void TracksScene::keyPressEvent( QKeyEvent* keyEvent )
clipsinfos.append( ai );
}
Commands::trigger( new Commands::MainWorkflow::RemoveClips( tv->m_mainWorkflow,
Commands::trigger( new Commands::MainWorkflow::RemoveClips( tv->m_renderer,
clipsinfos ) );
}
......
......@@ -35,8 +35,9 @@
#include "Commands.h"
#include "GraphicsTrack.hpp"
TracksView::TracksView( QGraphicsScene* scene, MainWorkflow* mainWorkflow, QWidget* parent )
: QGraphicsView( scene, parent ), m_scene( scene ), m_mainWorkflow( mainWorkflow )
TracksView::TracksView( QGraphicsScene* scene, MainWorkflow* mainWorkflow, WorkflowRenderer* renderer, QWidget* parent )
: QGraphicsView( scene, parent ), m_scene( scene ), m_mainWorkflow( mainWorkflow ),
m_renderer( renderer )
{
//TODO should be defined by the settings
m_tracksHeight = 25;
......
......@@ -37,6 +37,7 @@
#include "MainWorkflow.h"
#include "TrackWorkflow.h"
#include "AbstractGraphicsMediaItem.h"
#include "WorkflowRenderer.h"
class GraphicsMovieItem;
class TracksScene;
......@@ -46,7 +47,7 @@ class TracksView : public QGraphicsView
Q_OBJECT
public:
TracksView( QGraphicsScene* scene, MainWorkflow* mainWorkflow, QWidget* parent = 0 );
TracksView( QGraphicsScene* scene, MainWorkflow* mainWorkflow, WorkflowRenderer* renderer, QWidget* parent = 0 );
void setDuration( int duration );
int duration() const { return m_projectDuration; }
int tracksHeight() const { return m_tracksHeight; }
......@@ -103,6 +104,7 @@ private:
GraphicsMovieItem* m_dragItem;
QGraphicsWidget* m_separator;
ToolButtons m_tool;
WorkflowRenderer* m_renderer;
// Mouse actions on Medias
bool m_actionMove;
......
......@@ -36,7 +36,7 @@ WorkflowRenderer::WorkflowRenderer() :
{
char buffer[64];
m_actionsLock = new QReadWriteLock;
m_actionsMutex = new QMutex;
m_media = new LibVLCpp::Media( "fake://" );
sprintf( buffer, ":invmem-width=%i", VIDEOWIDTH );
......@@ -67,10 +67,6 @@ WorkflowRenderer::WorkflowRenderer() :
m_renderVideoFrame = new unsigned char[VIDEOHEIGHT * VIDEOWIDTH * Pixel::NbComposantes];
//Workflow part
connect( m_mainWorkflow, SIGNAL( frameChanged(qint64) ),
Timeline::getInstance()->tracksView()->tracksCursor(), SLOT( setCursorPos( qint64 ) ), Qt::QueuedConnection );
connect( Timeline::getInstance()->tracksView()->tracksCursor(), SIGNAL( cursorPositionChanged( qint64 ) ),
this, SLOT( timelineCursorChanged(qint64) ) );
connect( m_mainWorkflow, SIGNAL( mainWorkflowPaused() ), this, SLOT( mainWorkflowPaused() ) );
connect( m_mainWorkflow, SIGNAL( mainWorkflowUnpaused() ), this, SLOT( mainWorkflowUnpaused() ) );
}
......@@ -80,16 +76,7 @@ WorkflowRenderer::~WorkflowRenderer()
{
stop();
//FIXME this is probably useless...
//etix says: yes it is...
disconnect( m_mediaPlayer, SIGNAL( playing() ), this, SLOT( __videoPlaying() ) );
disconnect( m_mediaPlayer, SIGNAL( paused() ), this, SLOT( __videoPaused() ) );
disconnect( m_mediaPlayer, SIGNAL( stopped() ), this, SLOT( __videoStopped() ) );
disconnect( m_mainWorkflow, SIGNAL( mainWorkflowEndReached() ), this, SLOT( __endReached() ) );
disconnect( m_mainWorkflow, SIGNAL( positionChanged( float ) ), this, SLOT( __positionChanged( float ) ) );
disconnect( m_mainWorkflow, SIGNAL( frameChanged( qint64 ) ), this, SLOT( __frameChanged( qint64 ) ) );
delete m_actionsLock;
delete m_actionsMutex;
delete m_media;
delete m_condMutex;
delete m_waitCond;
......@@ -124,28 +111,35 @@ void WorkflowRenderer::unlock( void* datas )
void WorkflowRenderer::checkActions()
{
QReadLocker lock( m_actionsLock );
QMutexLocker lock( m_actionsMutex );
if ( m_actions.size() == 0 )
return ;
while ( m_actions.empty() == false )
{
Actions act = m_actions.top();
StackedAction* act = m_actions.top();
m_actions.pop();
switch ( act )
switch ( act->action )
{
case Pause:
if ( m_pauseAsked == true )
continue ;
m_pauseAsked = true;
// m_mediaPlayer->pause();
pauseMainWorkflow();
//This will also pause the MainWorkflow via a signal/slot
break ;
case AddClip:
qDebug() << "Unstacked action";
m_mainWorkflow->addClip( act->clip, act->trackId, act->startingPos, act->trackType );
break ;
case RemoveClip:
m_mainWorkflow->removeClip( act->uuid, act->trackId, act->trackType );
break ;
default:
qDebug() << "Unhandled action:" << act;
qDebug() << "Unhandled action:" << act->action;
break ;
}
delete act;
}
}
......@@ -247,8 +241,9 @@ void WorkflowRenderer::internalPlayPause( bool forcePause )
{
if ( m_paused == false )
{
QWriteLocker lock( m_actionsLock );
m_actions.push( Pause );
QMutexLocker lock( m_actionsMutex );
StackedAction* act = new StackedAction( Pause );
m_actions.push( act );
}
}
}
......@@ -281,6 +276,31 @@ float WorkflowRenderer::getFps() const
return m_outputFps;
}
void WorkflowRenderer::removeClip( const QUuid& uuid, uint32_t trackId, MainWorkflow::TrackType trackType )
{
StackedAction* act = new StackedAction( RemoveClip );
act->uuid = uuid;
act->trackId = trackId;
act->trackType = trackType;
QMutexLocker lock( m_actionsMutex );
m_actions.push( act );
qDebug() << "<<<<<<<<";
}
void WorkflowRenderer::addClip( Clip* clip, uint32_t trackNumber, qint64 startingPos, MainWorkflow::TrackType trackType )
{
if ( m_isRendering == true )
{
StackedAction* act = new StackedAction( AddClip );
act->clip = clip;
act->trackId = trackNumber;
act->startingPos = startingPos;
act->trackType = trackType;
}
else
m_mainWorkflow->addClip( clip, trackNumber, startingPos, trackType );
}
/////////////////////////////////////////////////////////////////////
/////SLOTS :
/////////////////////////////////////////////////////////////////////
......@@ -332,4 +352,3 @@ void WorkflowRenderer::timelineCursorChanged( qint64 newFrame )
{
m_mainWorkflow->setCurrentFrame( newFrame );
}
......@@ -40,8 +40,20 @@ class WorkflowRenderer : public GenericRenderer
enum Actions
{
Pause,
AddClip,
RemoveClip,
//Unpause,
};
struct StackedAction
{
StackedAction( Actions act ) : action( act ), trackId( -1 ), clip( NULL ) {}
Actions action;
QUuid uuid;
uint32_t trackId;
MainWorkflow::TrackType trackType;
Clip* clip;
qint64 startingPos;
};
WorkflowRenderer();
~WorkflowRenderer();
......@@ -58,11 +70,12 @@ class WorkflowRenderer : public GenericRenderer
virtual qint64 getLengthMs() const;
virtual qint64 getCurrentFrame() const;
virtual float getFps() const;
void addClip( Clip* clip, uint32_t trackNumber, qint64 startingPos, MainWorkflow::TrackType trackType );
void removeClip( const QUuid& uuid, uint32_t trackId, MainWorkflow::TrackType trackType );
static void* lock( void* datas );
static void* lockAudio( void* datas );
static void unlock( void* datas );
private:
void internalPlayPause( bool forcePause );
void pauseMainWorkflow();
......@@ -79,8 +92,8 @@ class WorkflowRenderer : public GenericRenderer
private:
unsigned char* m_renderVideoFrame;
unsigned char* m_renderAudioSample;
QStack<Actions> m_actions;
QReadWriteLock* m_actionsLock;
QStack<StackedAction*> m_actions;
QMutex* m_actionsMutex;
bool m_pauseAsked;
bool m_unpauseAsked;
QMutex* m_condMutex;
......
......@@ -211,7 +211,7 @@ Clip* MainWorkflow::removeClip( const QUuid& uuid, unsigned int trackId, M
{
Clip* clip = m_tracks[trackType]->removeClip( uuid, trackId );
computeLength();
emit clipRemoved( uuid, trackId, trackType );
emit clipRemoved( clip, trackId, trackType );
return clip;
}
......
......@@ -54,6 +54,7 @@ class MainWorkflow : public QObject, public Singleton<MainWorkflow>
NbTrackType,
AudioTrack,
};
void addClip( Clip* clip, unsigned int trackId, qint64 start, TrackType type );
void startRender();
......@@ -177,7 +178,7 @@ class MainWorkflow : public QObject, public Singleton<MainWorkflow>
void mainWorkflowPaused();
void mainWorkflowUnpaused();
void clipAdded( Clip*, unsigned int, qint64, MainWorkflow::TrackType );
void clipRemoved( QUuid, unsigned int, MainWorkflow::TrackType );
void clipRemoved( Clip*, unsigned int, MainWorkflow::TrackType );
void clipMoved( QUuid, unsigned int, qint64, MainWorkflow::TrackType );
void cleared();
};
......
......@@ -294,6 +294,7 @@ bool TrackWorkflow::getOutput( qint64 currentFrame )
if ( checkEnd( currentFrame ) == true )
{
qDebug() << "end of track reached";
emit trackEndReached( m_trackId );
//We continue, as there can be ClipWorkflow that requires to be stopped.
}
......@@ -427,6 +428,7 @@ Clip* TrackWorkflow::removeClip( const QUuid& id )
computeLength();
disconnectClipWorkflow( cw );
delete cw;
qDebug() << "Removed clip";
return clip;
}
++it;
......
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