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

Removing stacked actions.

parent 6372272b
/*****************************************************************************
* ActionStack.h: Action stack
*****************************************************************************
* Copyright (C) 2008-2010 VideoLAN
*
* 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.
*****************************************************************************/
#include "ActionStack.h"
#include <QDebug>
using namespace Action;
Stack::~Stack()
{
while ( empty() == false )
{
Action::Generic* act = top();
delete act;
pop();
}
}
void Stack::addAction( Action::Generic* act )
{
iterator it = begin();
iterator ite = end();
while ( it != ite )
{
if ( (*it)->isOpposite( act ) == true )
{
qDebug() << "is opposite == true";
delete *it;
it = erase( it );
delete act;
}
else
++it;
}
push_back( act );
}
/*****************************************************************************
* ActionStack.h: Action stack
*****************************************************************************
* Copyright (C) 2008-2010 VideoLAN
*
* 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 ACTIONSTACK_H
#define ACTIONSTACK_H
#include <QStack>
#include "StackedAction.h"
namespace Action
{
class Stack : public QStack<Action::Generic*>
{
public:
~Stack();
void addAction( Action::Generic* act );
};
}
#endif // ACTIONSTACK_H
/*****************************************************************************
* StackedAction.cpp: Stores an action to be executed later
*****************************************************************************
* Copyright (C) 2008-2010 VideoLAN
*
* 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.
*****************************************************************************/
#include "StackedAction.h"
#include "MainWorkflow.h"
#include "Clip.h"
using namespace Action;
Generic::Generic( Type type ) : m_type( type )
{
}
Generic::~Generic()
{
}
bool
Generic::isOpposite( const Generic* ) const
{
return false;
}
Generic::Type
Generic::getType() const
{
return m_type;
}
Workflow::Workflow( MainWorkflow *mainWorkflow, Type type ) :
Generic( type ),
m_mainWorkflow( mainWorkflow )
{
}
Track::Track( MainWorkflow *mainWorkflow, quint32 trackId,
MainWorkflow::TrackType trackType, Type type) :
Workflow( mainWorkflow, type ),
m_trackId( trackId ),
m_trackType( trackType )
{
}
AddClip::AddClip(MainWorkflow *mainWorkflow, quint32 trackId,
MainWorkflow::TrackType trackType, Clip *clip, qint64 startingPos ) :
Track( mainWorkflow, trackId, trackType, Add ),
m_clip( clip ), m_startingPos( startingPos )
{
}
void
AddClip::execute()
{
m_mainWorkflow->addClip( m_clip, m_trackId, m_startingPos, m_trackType );
}
RemoveClip::RemoveClip( MainWorkflow* mainWorkflow, quint32 trackId,
MainWorkflow::TrackType trackType, const QUuid& uuid ) :
Track( mainWorkflow, trackId, trackType, Remove ),
m_uuid( uuid )
{
}
void
RemoveClip::execute()
{
m_mainWorkflow->removeClip( m_uuid, m_trackId, m_trackType );
}
MoveClip::MoveClip( MainWorkflow* mainWorkflow, const QUuid& uuid, quint32 oldTrack,
quint32 newTrack, qint64 newPos, MainWorkflow::TrackType trackType,
bool undoRedoAction ) :
Track( mainWorkflow, oldTrack, trackType, Move ),
m_uuid( uuid ), m_newTrack( newTrack ),
m_newPos( newPos ), m_undoRedoAction( undoRedoAction )
{
}
void
MoveClip::execute()
{
m_mainWorkflow->moveClip( m_uuid, m_trackId, m_newTrack, m_newPos, m_trackType, m_undoRedoAction );
}
ResizeClip::ResizeClip( Clip* clip, qint64 newBegin, qint64 newEnd, bool resizeForSplit ) :
Generic( Resize ),
m_clip( clip ),
m_newBegin( newBegin ),
m_newEnd( newEnd ),
m_resizeForSplit( resizeForSplit )
{
}
void
ResizeClip::execute()
{
m_clip->setBoundaries( m_newBegin, m_newEnd, m_resizeForSplit );
}
Pause::Pause( MainWorkflow* mainWorkflow ) :
Workflow( mainWorkflow, Generic::Pause )
{
}
void
Pause::execute()
{
m_mainWorkflow->pause();
}
bool
Pause::isOpposite( const Generic* act ) const
{
return ( act->getType() == Unpause );
}
Unpause::Unpause( MainWorkflow* mainWorkflow ) :
Workflow( mainWorkflow, Generic::Unpause )
{
}
void
Unpause::execute()
{
m_mainWorkflow->unpause();
}
bool
Unpause::isOpposite( const Generic* act ) const
{
return ( act->getType() == Generic::Pause );
}
/*****************************************************************************
* StackedAction.hpp: Stores an action to be executed later
*****************************************************************************
* Copyright (C) 2008-2010 VideoLAN
*
* 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>
class Clip;
#include "MainWorkflow.h"
namespace Action
{
class Generic
{
public:
enum Type
{
Pause,
Unpause,
Resize,
Remove,
Add,
Move,
};
Generic( Type type );
virtual ~Generic();
virtual void execute() = 0;
virtual bool isOpposite( const Generic* ) const;
Type getType() const;
private:
Type m_type;
};
class Workflow : public Generic
{
public:
Workflow( MainWorkflow* mainWorkflow, Type type );
protected:
MainWorkflow* m_mainWorkflow;
};
class Track : public Workflow
{
public:
Track( MainWorkflow* mainWorkflow, quint32 trackId, MainWorkflow::TrackType trackType, Type type );
protected:
quint32 m_trackId;
MainWorkflow::TrackType m_trackType;
};
class AddClip : public Track
{
public:
AddClip( MainWorkflow* mainWorkflow, quint32 trackId, MainWorkflow::TrackType trackType,
Clip* clip, qint64 startingPos );
void execute();
protected:
Clip* m_clip;
qint64 m_startingPos;
};
class RemoveClip : public Track
{
public:
RemoveClip( MainWorkflow* mainWorkflow, quint32 trackId, MainWorkflow::TrackType trackType,
const QUuid& uuid );
void execute();
protected:
QUuid m_uuid;
};
class MoveClip : public Track
{
public:
MoveClip( MainWorkflow* mainWorkflow, const QUuid& uuid, quint32 oldTrack,
quint32 newTrack, qint64 newPos, MainWorkflow::TrackType trackType, bool undoRedoAction );
void execute();
private:
QUuid m_uuid;
quint32 m_newTrack;
qint64 m_newPos;
bool m_undoRedoAction;
};
class ResizeClip : public Generic
{
public:
ResizeClip( Clip* clip, qint64 newBegin, qint64 newEnd, bool resizeForSplit );
void execute();
protected:
Clip* m_clip;
qint64 m_newBegin;
qint64 m_newEnd;
bool m_resizeForSplit;
};
class Pause : public Workflow
{
public:
Pause( MainWorkflow* mainWorkflow );
void execute();
bool isOpposite( const Generic* act ) const;
};
class Unpause : public Workflow
{
public:
Unpause( MainWorkflow* mainWorkflow );
void execute();
bool isOpposite( const Generic* act ) const;
};
}
#endif // STACKEDACTION_H
#INPUT
HEADERS += ActionStack.h \
StackedAction.hpp
SOURCES += ActionStack.cpp
......@@ -5,8 +5,6 @@ SUBDIRS(EffectsEngine/Plugins/src)
SET(VLMC_SRCS
main.cpp
Actions/ActionStack.cpp
Actions/StackedAction.cpp
API/Module.cpp
API/ModuleManager.cpp
API/vlmc_module_variables.cpp
......@@ -114,7 +112,6 @@ ELSE (WIN32)
ENDIF(WIN32)
SET (VLMC_HDRS
Actions/StackedAction.h
Commands/KeyboardShortcutHelper.h
Configuration/SettingsManager.h
Configuration/SettingValue.h
......@@ -239,7 +236,6 @@ INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_BINARY_DIR}/src
.
Actions
API
Commands
Configuration
......
......@@ -51,12 +51,12 @@ Commands::MainWorkflow::AddClip::~AddClip()
void Commands::MainWorkflow::AddClip::redo()
{
m_renderer->addClip( m_clip, m_trackNumber, m_pos, m_trackType );
::MainWorkflow::getInstance()->addClip( m_clip, m_trackNumber, m_pos, m_trackType );
}
void Commands::MainWorkflow::AddClip::undo()
{
m_renderer->removeClip( m_clip->getUuid(), m_trackNumber, m_trackType );
::MainWorkflow::getInstance()->removeClip( m_clip->getUuid(), m_trackNumber, m_trackType );
}
Commands::MainWorkflow::MoveClip::MoveClip( ::MainWorkflow* workflow, const QUuid& uuid,
......@@ -97,11 +97,11 @@ Commands::MainWorkflow::RemoveClip::RemoveClip( WorkflowRenderer* renderer, Clip
void Commands::MainWorkflow::RemoveClip::redo()
{
m_renderer->removeClip( m_clip->getUuid(), m_trackNumber, m_trackType );
::MainWorkflow::getInstance()->removeClip( m_clip->getUuid(), m_trackNumber, m_trackType );
}
void Commands::MainWorkflow::RemoveClip::undo()
{
m_renderer->addClip( m_clip, m_trackNumber, m_pos, m_trackType );
::MainWorkflow::getInstance()->addClip( m_clip, m_trackNumber, m_pos, m_trackType );
}
Commands::MainWorkflow::ResizeClip::ResizeClip( WorkflowRenderer* renderer, const QUuid& uuid,
......@@ -128,7 +128,7 @@ Commands::MainWorkflow::ResizeClip::ResizeClip( WorkflowRenderer* renderer, cons
void Commands::MainWorkflow::ResizeClip::redo()
{
m_renderer->resizeClip( m_clip, m_newBegin, m_newEnd, m_newPos, m_trackId, m_trackType, m_undoRedoAction );
::MainWorkflow::getInstance()->resizeClip( m_clip, m_newBegin, m_newEnd, m_newPos, m_trackId, m_trackType, m_undoRedoAction );
m_undoRedoAction = true;
}
......@@ -139,7 +139,7 @@ void Commands::MainWorkflow::ResizeClip::undo()
//In the other cases, we need to move, then resize.
if ( m_oldBegin == m_newBegin )
{
m_renderer->resizeClip( m_clip, m_oldBegin, m_oldEnd, m_oldPos, m_trackId, m_trackType, m_undoRedoAction );
::MainWorkflow::getInstance()->resizeClip( m_clip, m_oldBegin, m_oldEnd, m_oldPos, m_trackId, m_trackType, m_undoRedoAction );
}
else
{
......@@ -169,10 +169,10 @@ Commands::MainWorkflow::SplitClip::~SplitClip()
void Commands::MainWorkflow::SplitClip::redo()
{
m_newClip = m_renderer->split( m_toSplit, m_newClip, m_trackId, m_newClipPos, m_newClipBegin, m_trackType );
m_newClip = ::MainWorkflow::getInstance()->split( m_toSplit, m_newClip, m_trackId, m_newClipPos, m_newClipBegin, m_trackType );
}
void Commands::MainWorkflow::SplitClip::undo()
{
m_renderer->unsplit( m_toSplit, m_newClip, m_trackId, m_trackType );
::MainWorkflow::getInstance()->unsplit( m_toSplit, m_newClip, m_trackId, m_trackType );
}
......@@ -217,8 +217,9 @@ void AbstractGraphicsMediaItem::resize( qint64 size, From from )
if ( clip()->getParent()->getFileType() != Media::Image )
if ( clip()->getBegin() + size > clip()->getMaxEnd() )
return;
tracksView()->getRenderer()->resizeClip( clip(), clip()->getBegin(), clip()->getBegin() + size, 0, //This parameter is unused in this case
trackNumber(), mediaType() );
//FIXME
// tracksView()->getRenderer()->resizeClip( clip(), clip()->getBegin(), clip()->getBegin() + size, 0, //This parameter is unused in this case
// trackNumber(), mediaType() );
}
else
{
......@@ -233,17 +234,19 @@ void AbstractGraphicsMediaItem::resize( qint64 size, From from )
qint64 newStart = startPos() + ( oldLength - size );
if ( newStart < 0 )
return ;
tracksView()->getRenderer()->resizeClip( clip(), qMax( clip()->getEnd() - size, (qint64)0 ), clip()->getEnd(),
newStart, trackNumber(), mediaType() );
setStartPos( newStart );
// tracksView()->getRenderer()->resizeClip( clip(), qMax( clip()->getEnd() - size, (qint64)0 ), clip()->getEnd(),
// newStart, trackNumber(), mediaType() );
// setStartPos( newStart );
//FIXME
}
else
{
m_resizeExpected = true;
qint64 oldLength = clip()->getLength();
tracksView()->getRenderer()->resizeClip( clip(), 0, size, startPos() + ( oldLength - size ),
trackNumber(), mediaType() );
setStartPos( startPos() + ( oldLength - size ) );
// tracksView()->getRenderer()->resizeClip( clip(), 0, size, startPos() + ( oldLength - size ),
// trackNumber(), mediaType() );
// setStartPos( startPos() + ( oldLength - size ) );
//FIXME
}
}
......
......@@ -169,7 +169,7 @@ void TracksView::deleteMedia( const QUuid& uuid )
removeMediaItem( itemUuid, itemTn, itemTt );
// Removing the item from the backend.
m_renderer->removeClip( itemUuid,
MainWorkflow::getInstance()->removeClip( itemUuid,
itemTn,
itemTt );
}
......
......@@ -30,8 +30,6 @@
#include "LightVideoFrame.h"
#include "MainWorkflow.h"
#include "GenericRenderer.h"
#include "StackedAction.h"
#include "ActionStack.h"
#include "AudioClipWorkflow.h"
#include "VLCMedia.h"
#include "Clip.h"
......@@ -44,7 +42,6 @@ WorkflowRenderer::WorkflowRenderer() :
m_stopping( false ),
m_oldLength( 0 )
{
m_actionsMutex = new QMutex;
}
void WorkflowRenderer::initializeRenderer()
......@@ -101,7 +98,6 @@ WorkflowRenderer::~WorkflowRenderer()
delete m_videoEsHandler;
delete m_audioEsHandler;
delete m_actionsMutex;
delete m_media;
delete m_waitCond;
}
......@@ -197,25 +193,8 @@ WorkflowRenderer::lockAudio( qint64 *pts, size_t *bufferSize, void **buffer )
return 0;
}
void WorkflowRenderer::unlock( void* datas, size_t, void* )
void WorkflowRenderer::unlock( void*, size_t, void* )
{
EsHandler* handler = reinterpret_cast<EsHandler*>( datas );
handler->self->checkActions();
}
void WorkflowRenderer::checkActions()
{
QMutexLocker lock( m_actionsMutex );
if ( m_actions.size() == 0 )
return ;
while ( m_actions.empty() == false )
{
Action::Generic* act = m_actions.top();
m_actions.pop();
act->execute();
delete act;
}
}
void WorkflowRenderer::startPreview()
......@@ -285,17 +264,13 @@ void WorkflowRenderer::internalPlayPause( bool forcePause )
{
if ( m_paused == true && forcePause == false )
{
Action::Generic* act = new Action::Unpause( m_mainWorkflow );
QMutexLocker lock( m_actionsMutex );
m_actions.addAction( act );
m_mainWorkflow->unpause();
}
else
{
if ( m_paused == false )
{
Action::Generic* act = new Action::Pause( m_mainWorkflow );
QMutexLocker lock( m_actionsMutex );
m_actions.addAction( act );
m_mainWorkflow->pause();
}
}
}
......@@ -340,30 +315,6 @@ float WorkflowRenderer::getFps() const
return m_outputFps;
}
void WorkflowRenderer::removeClip( const QUuid& uuid, uint32_t trackId, MainWorkflow::TrackType trackType )
{
if ( m_isRendering == true )
{
Action::Generic* act = new Action::RemoveClip( m_mainWorkflow, trackId, trackType, uuid );
QMutexLocker lock( m_actionsMutex );
m_actions.addAction( act );
}
else
m_mainWorkflow->removeClip( uuid, trackId, trackType );
}
void WorkflowRenderer::addClip( Clip* clip, uint32_t trackId, qint64 startingPos, MainWorkflow::TrackType trackType )
{
if ( m_isRendering == true )
{
Action::Generic* act = new Action::AddClip( m_mainWorkflow, trackId, trackType, clip, startingPos );
QMutexLocker lock( m_actionsMutex );
m_actions.addAction( act );
}
else
m_mainWorkflow->addClip( clip, trackId, startingPos, trackType );
}
void WorkflowRenderer::timelineCursorChanged( qint64 newFrame )
{
m_mainWorkflow->setCurrentFrame( newFrame, MainWorkflow::TimelineCursor );
......@@ -379,80 +330,6 @@ void WorkflowRenderer::rulerCursorChanged( qint64 newFrame )
m_mainWorkflow->setCurrentFrame( newFrame, MainWorkflow::RulerCursor );
}
Clip* WorkflowRenderer::split( Clip* toSplit, Clip* newClip, uint32_t trackId, qint64 newClipPos, qint64 newClipBegin, MainWorkflow::TrackType trackType )
{
if ( newClip == NULL )
newClip = new Clip( toSplit, newClipBegin, toSplit->getEnd() );
if ( m_isRendering == true )
{
//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
Action::Generic* act = new Action::AddClip( m_mainWorkflow, trackId, trackType, newClip, newClipPos );
//resizing it
Action::Generic* act2 = new Action::ResizeClip( toSplit, toSplit->getBegin(), newClipBegin, true );
//Push the actions onto the action stack
QMutexLocker lock( m_actionsMutex );
m_actions.addAction( act );
m_actions.addAction( act2 );
}
else
{
toSplit->setEnd( newClipBegin, true );
m_mainWorkflow->addClip( newClip, trackId, newClipPos, trackType );
}