Commit 41f52c1f authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

Refactored stacked events

This is way much cleaner, much more evolutive, and allows more advanced
operation in the future.
parent 522b11ec
/*****************************************************************************
* StackedAction.hpp: Stores an action to be executed later
*****************************************************************************
* Copyright (C) 2008-2009 the VLMC team
*
* Authors: Hugo Beauzee-Luyssen <hugo@vlmc.org>
*
* This program 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 2
* of the License, or (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef STACKEDACTION_H
#define STACKEDACTION_H
#include <QUuid>
#include "MainWorkflow.h"
class StackedAction
{
public:
virtual ~StackedAction(){}
virtual void execute() = 0;
};
class WorkflowAction : public StackedAction
{
public:
WorkflowAction( MainWorkflow* mainWorkflow ) : m_mainWorkflow( mainWorkflow ) {}
protected:
MainWorkflow* m_mainWorkflow;
};
class TrackAction : public WorkflowAction
{
public:
TrackAction( MainWorkflow* mainWorkflow, uint32_t trackId, MainWorkflow::TrackType trackType ) :
WorkflowAction( mainWorkflow ), m_trackId( trackId ), m_trackType( trackType )
{
}
protected:
uint32_t m_trackId;
MainWorkflow::TrackType m_trackType;
};
class AddClipAction : public TrackAction
{
public:
AddClipAction( MainWorkflow* mainWorkflow, uint32_t trackId, MainWorkflow::TrackType trackType,
Clip* clip, qint64 startingPos ) : TrackAction( mainWorkflow, trackId, trackType ),
m_clip( clip ), m_startingPos( startingPos )
{
}
void execute()
{
m_mainWorkflow->addClip( m_clip, m_trackId, m_startingPos, m_trackType );
}
protected:
Clip* m_clip;
qint64 m_startingPos;
};
class RemoveClipAction : public TrackAction
{
public:
RemoveClipAction( MainWorkflow* mainWorkflow, uint32_t trackId, MainWorkflow::TrackType trackType,
const QUuid& uuid ) : TrackAction( mainWorkflow, trackId, trackType ),
m_uuid( uuid )
{
}
void execute()
{
m_mainWorkflow->removeClip( m_uuid, m_trackId, m_trackType );
}
protected:
QUuid m_uuid;
};
class ResizeClipAction : public StackedAction
{
public:
ResizeClipAction( Clip* clip, qint64 newBegin, qint64 newEnd ) : m_clip( clip ),
m_newBegin( newBegin ), m_newEnd( newEnd )
{
}
void execute()
{
m_clip->setBoundaries( m_newBegin, m_newEnd );
}
protected:
Clip* m_clip;
qint64 m_newBegin;
qint64 m_newEnd;
};
class PauseAction : public WorkflowAction
{
public:
PauseAction( MainWorkflow* mainWorkflow ) : WorkflowAction( mainWorkflow )
{
}
void execute()
{
m_mainWorkflow->pause();
}
};
#endif // STACKEDACTION_H
......@@ -83,6 +83,12 @@ WorkflowRenderer::~WorkflowRenderer()
delete m_media;
delete m_condMutex;
delete m_waitCond;
while ( m_actions.empty() == false )
{
StackedAction* act = m_actions.top();
delete act;
m_actions.pop();
}
}
void* WorkflowRenderer::lockAudio( void* datas )
......@@ -122,28 +128,14 @@ void WorkflowRenderer::checkActions()
{
StackedAction* act = m_actions.top();
m_actions.pop();
switch ( act->action )
{
case Pause:
if ( m_pauseAsked == true )
continue ;
m_pauseAsked = true;
pauseMainWorkflow();
//This will also pause the MainWorkflow via a signal/slot
break ;
case AddClip:
m_mainWorkflow->addClip( act->clip, act->trackId, act->startingPos, act->trackType );
break ;
case RemoveClip:
m_mainWorkflow->removeClip( act->uuid, act->trackId, act->trackType );
break ;
case ResizeClip:
act->clip->setBoundaries( act->newBegin, act->newEnd );
break ;
default:
qDebug() << "Unhandled action:" << act->action;
break ;
}
// case Pause:
// if ( m_pauseAsked == true )
// continue ;
// m_pauseAsked = true;
// pauseMainWorkflow();
// //This will also pause the MainWorkflow via a signal/slot
// break ;
act->execute();
delete act;
}
}
......@@ -238,8 +230,8 @@ void WorkflowRenderer::internalPlayPause( bool forcePause )
{
if ( m_paused == false )
{
StackedAction* act = new PauseAction( m_mainWorkflow );
QMutexLocker lock( m_actionsMutex );
StackedAction* act = new StackedAction( Pause );
m_actions.push( act );
}
}
......@@ -277,10 +269,7 @@ void WorkflowRenderer::removeClip( const QUuid& uuid, uint32_t trackId, M
{
if ( m_isRendering == true )
{
StackedAction* act = new StackedAction( RemoveClip );
act->uuid = uuid;
act->trackId = trackId;
act->trackType = trackType;
StackedAction* act = new RemoveClipAction( m_mainWorkflow, trackId, trackType, uuid );
QMutexLocker lock( m_actionsMutex );
m_actions.push( act );
}
......@@ -288,20 +277,16 @@ void WorkflowRenderer::removeClip( const QUuid& uuid, uint32_t trackId, M
m_mainWorkflow->removeClip( uuid, trackId, trackType );
}
void WorkflowRenderer::addClip( Clip* clip, uint32_t trackNumber, qint64 startingPos, MainWorkflow::TrackType trackType )
void WorkflowRenderer::addClip( Clip* clip, uint32_t trackId, 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;
StackedAction* act = new AddClipAction( m_mainWorkflow, trackId, trackType, clip, startingPos );
QMutexLocker lock( m_actionsMutex );
m_actions.push( act );
}
else
m_mainWorkflow->addClip( clip, trackNumber, startingPos, trackType );
m_mainWorkflow->addClip( clip, trackId, startingPos, trackType );
}
void WorkflowRenderer::timelineCursorChanged( qint64 newFrame )
......@@ -328,17 +313,9 @@ Clip* WorkflowRenderer::split( Clip* toSplit, uint32_t trackId, qint64 new
//adding clip
//We can NOT call addClip, as it would lock the action lock and then release it,
//thus potentially breaking the synchrone way of doing this
StackedAction* act = new StackedAction( AddClip );
act->clip = newClip;
act->trackId = trackId;
act->startingPos = newClipPos;
act->trackType = trackType;
StackedAction* act = new AddClipAction( m_mainWorkflow, trackId, trackType, newClip, newClipPos );
//resizing it
StackedAction* act2 = new StackedAction( ResizeClip );
act2->clip = toSplit;
act2->newBegin = toSplit->getBegin();
act2->newEnd = newClipBegin;
StackedAction* act2 = new ResizeClipAction( toSplit, toSplit->getBegin(), newClipBegin );
//Push the actions onto the action stack
QMutexLocker lock( m_actionsMutex );
......@@ -358,17 +335,9 @@ void WorkflowRenderer::unsplit( Clip* origin, Clip* splitted, uint32_t trackI
if ( m_isRendering == true )
{
//removing clip
StackedAction* act = new StackedAction( RemoveClip );
act->uuid = splitted->getUuid();
act->trackId = trackId;
act->trackType = trackType;
StackedAction* act = new RemoveClipAction( m_mainWorkflow, trackId, trackType, splitted->getUuid() );
//resizing it
StackedAction* act2 = new StackedAction( ResizeClip );
act2->clip = origin;
act2->newBegin = splitted->getBegin();
act2->newEnd = oldEnd;
StackedAction* act2 = new ResizeClipAction( origin, splitted->getBegin(), oldEnd );
//Push the actions onto the action stack
QMutexLocker lock( m_actionsMutex );
m_actions.push( act );
......@@ -385,10 +354,7 @@ void WorkflowRenderer::resizeClip( Clip* clip, qint64 newBegin, qint64 newEnd
{
if ( m_isRendering == true )
{
StackedAction* act = new StackedAction( ResizeClip );
act->clip = clip;
act->newBegin = newBegin;
act->newEnd = newEnd;
StackedAction* act = new ResizeClipAction( clip, newBegin, newEnd );
QMutexLocker lock( m_actionsMutex );
m_actions.push( act );
}
......
......@@ -30,6 +30,7 @@
#include "Workflow/MainWorkflow.h"
#include "GenericRenderer.h"
#include "StackedAction.hpp"
class WorkflowRenderer : public GenericRenderer
{
......@@ -37,26 +38,6 @@ class WorkflowRenderer : public GenericRenderer
Q_DISABLE_COPY( WorkflowRenderer )
public:
enum Actions
{
Pause,
AddClip,
RemoveClip,
ResizeClip,
//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;
qint64 newBegin;
qint64 newEnd;
};
WorkflowRenderer();
~WorkflowRenderer();
......
......@@ -84,11 +84,9 @@ SOURCES += src/main.cpp \
src/Configuration/VLMCSettingsDefault.cpp \
src/Configuration/ProjectSettingsDefault.cpp \
src/GUI/TracksControls.cpp \
src/GUI/widgets/TrackControls.cpp \
# Wizard Files
src/GUI/widgets/TrackControls.cpp \ # Wizard Files
src/GUI/wizard/ProjectWizard.cpp \
src/GUI/wizard/CustomWizardPage.cpp
HEADERS += src/GUI/MainWindow.h \
src/GUI/DockWidgetManager.h \
src/GUI/LibraryWidget.h \
......@@ -168,11 +166,11 @@ HEADERS += src/GUI/MainWindow.h \
src/Configuration/ProjectSettingsDefault.h \
src/GUI/PreferenceWidget.h \
src/GUI/TracksControls.h \
src/GUI/widgets/TrackControls.h \
# wizard includes
src/GUI/widgets/TrackControls.h \ # wizard includes
src/GUI/wizard/ProjectWizard.h \
src/GUI/wizard/PageFactory.h \
src/GUI/wizard/CustomWizardPage.h
src/GUI/wizard/CustomWizardPage.h \
src/Commands/StackedAction.hpp
FORMS += src/GUI/ui/MainWindow.ui \
src/GUI/ui/PreviewWidget.ui \
src/GUI/ui/LanguagePreferences.ui \
......
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