Revised journalling (undo/redo) to record full states instead of changes
Recording single changes of objects or their specific properties is completely superfluous as we have full implemented state tracking in all objects already. Therefore use SerializingObject::saveState() and SerializingObject::restoreState() in order to implement the undo/redo functionality. This is just an initial commit and needs some further work (especially regarding stability). However even things like undo/redo of addition/removal of Tracks and TrackContentObjects do work already.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* AutomatableModel.h - declaration of class AutomatableModel
|
||||
*
|
||||
* Copyright (c) 2007-2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
|
||||
* Copyright (c) 2007-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
|
||||
*
|
||||
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
|
||||
*
|
||||
@@ -180,23 +180,19 @@ public:
|
||||
static void unlinkModels( AutomatableModel * _m1,
|
||||
AutomatableModel * _m2 );
|
||||
|
||||
virtual void saveSettings( QDomDocument & _doc,
|
||||
QDomElement & _this,
|
||||
const QString & _name = QString( "value" ) );
|
||||
virtual void saveSettings( QDomDocument &doc, QDomElement &_this );
|
||||
virtual void loadSettings( const QDomElement &_this );
|
||||
|
||||
virtual void loadSettings( const QDomElement & _this,
|
||||
const QString & _name = QString( "value" ) );
|
||||
virtual void saveSettings( QDomDocument &doc,
|
||||
QDomElement &_this,
|
||||
const QString &name );
|
||||
virtual void loadSettings( const QDomElement &_this, const QString &name );
|
||||
|
||||
virtual QString nodeName() const
|
||||
{
|
||||
return "automatablemodel";
|
||||
}
|
||||
|
||||
void prepareJournalEntryFromOldVal();
|
||||
|
||||
void addJournalEntryFromOldToCurVal();
|
||||
|
||||
|
||||
QString displayValue( const float _val ) const
|
||||
{
|
||||
switch( m_dataType )
|
||||
@@ -217,9 +213,6 @@ public slots:
|
||||
|
||||
|
||||
protected:
|
||||
virtual void redoStep( JournalEntry & _je );
|
||||
virtual void undoStep( JournalEntry & _je );
|
||||
|
||||
float fittedValue( float _value ) const;
|
||||
|
||||
|
||||
@@ -239,7 +232,6 @@ private:
|
||||
// most objects will need this temporarily (until sampleExact is
|
||||
// standard)
|
||||
float m_oldValue;
|
||||
bool m_journalEntryReady;
|
||||
int m_setValueDepth;
|
||||
|
||||
AutoModelVector m_linkedModels;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* JournallingObject.h - declaration of class JournallingObject
|
||||
*
|
||||
* Copyright (c) 2006-2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
|
||||
* Copyright (c) 2006-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
|
||||
*
|
||||
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
|
||||
*
|
||||
@@ -27,6 +27,7 @@
|
||||
|
||||
#include "lmms_basics.h"
|
||||
#include "export.h"
|
||||
#include "mmp.h"
|
||||
#include "SerializingObject.h"
|
||||
|
||||
#include <QtCore/QVariant>
|
||||
@@ -34,57 +35,37 @@
|
||||
#include <QtCore/QStack>
|
||||
|
||||
|
||||
typedef uint32_t t_action_id;
|
||||
|
||||
|
||||
class JournalEntry
|
||||
class JournalCheckPoint
|
||||
{
|
||||
public:
|
||||
JournalEntry( const t_action_id _action_id, const QVariant & _data ) :
|
||||
m_actionID( _action_id ),
|
||||
m_data( _data )
|
||||
JournalCheckPoint( const multimediaProject &data =
|
||||
multimediaProject( multimediaProject::JournalData ) ) :
|
||||
m_data( data )
|
||||
{
|
||||
}
|
||||
|
||||
JournalEntry() :
|
||||
m_actionID( 0 ),
|
||||
m_data( 0 )
|
||||
~JournalCheckPoint()
|
||||
{
|
||||
}
|
||||
|
||||
~JournalEntry()
|
||||
{
|
||||
}
|
||||
|
||||
t_action_id actionID() const
|
||||
{
|
||||
return m_actionID;
|
||||
}
|
||||
|
||||
t_action_id & actionID()
|
||||
{
|
||||
return m_actionID;
|
||||
}
|
||||
|
||||
const QVariant & data() const
|
||||
const multimediaProject &data() const
|
||||
{
|
||||
return m_data;
|
||||
}
|
||||
|
||||
QVariant & data()
|
||||
multimediaProject &data()
|
||||
{
|
||||
return m_data;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
t_action_id m_actionID;
|
||||
QVariant m_data;
|
||||
multimediaProject m_data;
|
||||
|
||||
} ;
|
||||
|
||||
|
||||
typedef QVector<JournalEntry> JournalEntryVector;
|
||||
typedef QVector<JournalCheckPoint> JournalCheckPointVector;
|
||||
|
||||
|
||||
class EXPORT JournallingObject : public SerializingObject
|
||||
@@ -103,15 +84,15 @@ public:
|
||||
|
||||
void clear()
|
||||
{
|
||||
m_journalEntries.clear();
|
||||
m_currentJournalEntry = m_journalEntries.end();
|
||||
m_journalCheckPoints.clear();
|
||||
m_currentJournalCheckPoint = m_journalCheckPoints.end();
|
||||
}
|
||||
|
||||
void clearRedoSteps()
|
||||
{
|
||||
m_journalEntries.erase( m_currentJournalEntry,
|
||||
m_journalEntries.end() );
|
||||
m_currentJournalEntry = m_journalEntries.end();
|
||||
m_journalCheckPoints.erase( m_currentJournalCheckPoint,
|
||||
m_journalCheckPoints.end() );
|
||||
m_currentJournalCheckPoint = m_journalCheckPoints.end();
|
||||
|
||||
}
|
||||
|
||||
@@ -126,6 +107,8 @@ public:
|
||||
m_journalling = m_journallingStateStack.pop();
|
||||
}
|
||||
|
||||
void addJournalCheckPoint();
|
||||
|
||||
virtual QDomElement saveState( QDomDocument & _doc,
|
||||
QDomElement & _parent );
|
||||
|
||||
@@ -153,16 +136,6 @@ public:
|
||||
protected:
|
||||
void changeID( jo_id_t _id );
|
||||
|
||||
void addJournalEntry( const JournalEntry & _je );
|
||||
|
||||
// to be implemented by sub-objects
|
||||
virtual void undoStep( JournalEntry & )
|
||||
{
|
||||
}
|
||||
virtual void redoStep( JournalEntry & )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
void saveJournal( QDomDocument & _doc, QDomElement & _parent );
|
||||
@@ -171,8 +144,8 @@ private:
|
||||
|
||||
jo_id_t m_id;
|
||||
|
||||
JournalEntryVector m_journalEntries;
|
||||
JournalEntryVector::Iterator m_currentJournalEntry;
|
||||
JournalCheckPointVector m_journalCheckPoints;
|
||||
JournalCheckPointVector::Iterator m_currentJournalCheckPoint;
|
||||
|
||||
bool m_journalling;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* note.h - declaration of class note which contains all informations about a
|
||||
* note + definitions of several constants and enums
|
||||
*
|
||||
* Copyright (c) 2004-2010 Tobias Doerffel <tobydox/at/users.sourceforge.net>
|
||||
* Copyright (c) 2004-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
|
||||
*
|
||||
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
|
||||
*
|
||||
@@ -208,21 +208,8 @@ protected:
|
||||
QDomElement & _parent );
|
||||
virtual void loadSettings( const QDomElement & _this );
|
||||
|
||||
/* virtual void undoStep( JournalEntry & _je );
|
||||
virtual void redoStep( JournalEntry & _je );*/
|
||||
|
||||
|
||||
private:
|
||||
/* enum Actions
|
||||
{
|
||||
ChangeKey,
|
||||
ChangeVolume,
|
||||
ChangePanning,
|
||||
ChangeLength,
|
||||
ChangePosition
|
||||
} ;*/
|
||||
|
||||
|
||||
// for piano roll editing
|
||||
bool m_selected;
|
||||
int m_oldKey;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* position of a channel + calculation of volume for each
|
||||
* speaker
|
||||
*
|
||||
* Copyright (c) 2004-2008 Tobias Doerffel <tobydox/at/users.sourceforge.net>
|
||||
* Copyright (c) 2004-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
|
||||
*
|
||||
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
|
||||
*
|
||||
@@ -57,18 +57,6 @@ public:
|
||||
void loadSettings( const QDomElement & _this,
|
||||
const QString & _name = "surpos" );
|
||||
|
||||
inline void prepareJournalEntryFromOldVal()
|
||||
{
|
||||
m_posX.prepareJournalEntryFromOldVal();
|
||||
m_posY.prepareJournalEntryFromOldVal();
|
||||
}
|
||||
|
||||
inline void addJournalEntryFromOldToCurVal()
|
||||
{
|
||||
m_posX.addJournalEntryFromOldToCurVal();
|
||||
m_posY.addJournalEntryFromOldToCurVal();
|
||||
}
|
||||
|
||||
// AutomationPattern * automationPatternX();
|
||||
// AutomationPattern * automationPatternY();
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* track.h - declaration of classes concerning tracks -> necessary for all
|
||||
* track-like objects (beat/bassline, sample-track...)
|
||||
*
|
||||
* Copyright (c) 2004-2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
|
||||
* Copyright (c) 2004-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
|
||||
*
|
||||
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
|
||||
*
|
||||
@@ -128,11 +128,6 @@ public slots:
|
||||
void toggleMute();
|
||||
|
||||
|
||||
protected:
|
||||
virtual void undoStep( JournalEntry & _je );
|
||||
virtual void redoStep( JournalEntry & _je );
|
||||
|
||||
|
||||
signals:
|
||||
void lengthChanged();
|
||||
void positionChanged();
|
||||
@@ -275,17 +270,8 @@ protected:
|
||||
return "trackcontentwidget";
|
||||
}
|
||||
|
||||
virtual void undoStep( JournalEntry & _je );
|
||||
virtual void redoStep( JournalEntry & _je );
|
||||
|
||||
|
||||
private:
|
||||
enum Actions
|
||||
{
|
||||
AddTrackContentObject,
|
||||
RemoveTrackContentObject
|
||||
} ;
|
||||
|
||||
track * getTrack();
|
||||
midiTime getPosition( int _mouse_x );
|
||||
|
||||
@@ -539,8 +525,6 @@ public slots:
|
||||
|
||||
protected:
|
||||
virtual void modelChanged();
|
||||
virtual void undoStep( JournalEntry & _je );
|
||||
virtual void redoStep( JournalEntry & _je );
|
||||
|
||||
virtual QString nodeName() const
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* track_container_view.h - view-component for trackContainer
|
||||
*
|
||||
* Copyright (c) 2004-2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
|
||||
* Copyright (c) 2004-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
|
||||
*
|
||||
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
|
||||
*
|
||||
@@ -139,9 +139,6 @@ protected:
|
||||
virtual void mouseReleaseEvent( QMouseEvent * _me );
|
||||
virtual void resizeEvent( QResizeEvent * );
|
||||
|
||||
virtual void undoStep( JournalEntry & _je );
|
||||
virtual void redoStep( JournalEntry & _je );
|
||||
|
||||
midiTime m_currentPosition;
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user