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

Added ActionStack class and isOpposite method for StackedAction

This is meant to avoid opposite actions to be stacked at the same time
(for example a pause followed by an unpause, which would be a big waste of
ressources)
parent 117e9798
/*****************************************************************************
* ActionStack.h: Action stack
*****************************************************************************
* 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.
*****************************************************************************/
#include "ActionStack.h"
using namespace Action;
Stack::~Stack()
{
while ( empty() == false )
{
StackedAction* act = top();
delete act;
pop();
}
}
void Stack::addAction( StackedAction* act )
{
iterator it = begin();
iterator ite = end();
while ( it != ite )
{
if ( (*it)->isOpposite( act ) == true )
{
delete *it;
it = erase( it );
delete act;
}
else
++it;
}
}
/*****************************************************************************
* ActionStack.h: Action stack
*****************************************************************************
* 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 ACTIONSTACK_H
#define ACTIONSTACK_H
#include <QStack>
#include "StackedAction.hpp"
namespace Action
{
class Stack : public QStack<StackedAction*>
{
public:
~Stack();
void addAction( StackedAction* act );
};
}
#endif // ACTIONSTACK_H
......@@ -32,6 +32,10 @@ class StackedAction
public:
virtual ~StackedAction(){}
virtual void execute() = 0;
virtual bool isOpposite( const StackedAction* ) const
{
return false;
}
};
class WorkflowAction : public StackedAction
......
......@@ -81,12 +81,6 @@ 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 )
......@@ -220,7 +214,7 @@ void WorkflowRenderer::internalPlayPause( bool forcePause )
{
StackedAction* act = new PauseAction( m_mainWorkflow );
QMutexLocker lock( m_actionsMutex );
m_actions.push( act );
m_actions.addAction( act );
}
}
}
......@@ -257,7 +251,7 @@ void WorkflowRenderer::removeClip( const QUuid& uuid, uint32_t trackId, M
{
StackedAction* act = new RemoveClipAction( m_mainWorkflow, trackId, trackType, uuid );
QMutexLocker lock( m_actionsMutex );
m_actions.push( act );
m_actions.addAction( act );
}
else
m_mainWorkflow->removeClip( uuid, trackId, trackType );
......@@ -269,7 +263,7 @@ void WorkflowRenderer::addClip( Clip* clip, uint32_t trackId, qint64 star
{
StackedAction* act = new AddClipAction( m_mainWorkflow, trackId, trackType, clip, startingPos );
QMutexLocker lock( m_actionsMutex );
m_actions.push( act );
m_actions.addAction( act );
}
else
m_mainWorkflow->addClip( clip, trackId, startingPos, trackType );
......@@ -305,7 +299,7 @@ Clip* WorkflowRenderer::split( Clip* toSplit, uint32_t trackId, qint64 new
//Push the actions onto the action stack
QMutexLocker lock( m_actionsMutex );
m_actions.push( act );
m_actions.addAction( act );
m_actions.push( act2 );
}
else
......@@ -326,8 +320,8 @@ void WorkflowRenderer::unsplit( Clip* origin, Clip* splitted, uint32_t trackI
StackedAction* act2 = new ResizeClipAction( origin, splitted->getBegin(), oldEnd );
//Push the actions onto the action stack
QMutexLocker lock( m_actionsMutex );
m_actions.push( act );
m_actions.push( act2 );
m_actions.addAction( act );
m_actions.addAction( act2 );
}
else
{
......@@ -342,7 +336,7 @@ void WorkflowRenderer::resizeClip( Clip* clip, qint64 newBegin, qint64 newEnd
{
StackedAction* act = new ResizeClipAction( clip, newBegin, newEnd );
QMutexLocker lock( m_actionsMutex );
m_actions.push( act );
m_actions.addAction( act );
}
else
clip->setBoundaries( newBegin, newEnd );
......
......@@ -31,6 +31,7 @@
#include "Workflow/MainWorkflow.h"
#include "GenericRenderer.h"
#include "StackedAction.hpp"
#include "ActionStack.h"
class WorkflowRenderer : public GenericRenderer
{
......@@ -73,7 +74,7 @@ class WorkflowRenderer : public GenericRenderer
private:
unsigned char* m_renderVideoFrame;
unsigned char* m_renderAudioSample;
QStack<StackedAction*> m_actions;
Action::Stack m_actions;
QMutex* m_actionsMutex;
QMutex* m_condMutex;
QWaitCondition* m_waitCond;
......
......@@ -86,7 +86,8 @@ SOURCES += src/main.cpp \
src/GUI/TracksControls.cpp \
src/GUI/widgets/TrackControls.cpp \
src/GUI/wizard/ProjectWizard.cpp \
src/GUI/wizard/CustomWizardPage.cpp
src/GUI/wizard/CustomWizardPage.cpp \
src/Actions/ActionStack.cpp
HEADERS += src/GUI/MainWindow.h \
src/GUI/DockWidgetManager.h \
src/GUI/LibraryWidget.h \
......@@ -211,6 +212,7 @@ INCLUDEPATH += src/LibVLCpp \
src/EffectsEngine \
src/Configuration \
src/EffectsEngine \
src/Actions \
src
# QMAKE_CFLAGS+=-pg
......
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