PianoRoll: initial undo/redo support

Most editing operations in PianoRoll are now tracked by the revised
journalling and thus are included in global undo/redo.
This commit is contained in:
Tobias Doerffel
2014-01-07 23:43:36 +01:00
parent a5c3cf6a99
commit d0f6eaef3b

View File

@@ -2,7 +2,7 @@
* piano_roll.cpp - implementation of piano-roll which is used for actual
* writing of melodies
*
* Copyright (c) 2004-2010 Tobias Doerffel <tobydox/at/users.sourceforge.net>
* Copyright (c) 2004-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
* Copyright (c) 2008 Andrew Kelley <superjoe30/at/gmail/dot/com>
*
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
@@ -1369,6 +1369,15 @@ void pianoRoll::keyReleaseEvent( QKeyEvent * _ke )
m_editMode = m_ctrlMode;
update();
break;
// update after undo/redo
case Qt::Key_Z:
case Qt::Key_R:
if( validPattern() && _ke->modifiers() == Qt::ControlModifier )
{
update();
}
break;
}
}
@@ -1535,6 +1544,7 @@ void pianoRoll::mousePressEvent( QMouseEvent * _me )
// area
if( edit_note == true )
{
m_pattern->addJournalCheckPoint();
// scribble note edit changes
mouseMoveEvent( _me );
return;
@@ -1552,6 +1562,7 @@ void pianoRoll::mousePressEvent( QMouseEvent * _me )
if( it == notes.begin()-1 )
{
is_new_note = true;
m_pattern->addJournalCheckPoint();
m_pattern->setType( pattern::MelodyPattern );
// then set new note
@@ -1597,8 +1608,7 @@ void pianoRoll::mousePressEvent( QMouseEvent * _me )
// ops (move, resize) after this
// code-block
it = notes.begin();
while( it != notes.end() &&
*it != created_new_note )
while( it != notes.end() && *it != created_new_note )
{
++it;
}
@@ -1677,6 +1687,7 @@ void pianoRoll::mousePressEvent( QMouseEvent * _me )
RESIZE_AREA_WIDTH &&
m_currentNote->length() > 0 )
{
m_pattern->addJournalCheckPoint();
// then resize the note
m_action = ActionResizeNote;
@@ -1686,6 +1697,11 @@ void pianoRoll::mousePressEvent( QMouseEvent * _me )
}
else
{
if( !created_new_note )
{
m_pattern->addJournalCheckPoint();
}
// otherwise move it
m_action = ActionMoveNote;
@@ -1741,6 +1757,7 @@ void pianoRoll::mousePressEvent( QMouseEvent * _me )
m_mouseDownRight = true;
if( it != notes.begin()-1 )
{
m_pattern->addJournalCheckPoint();
if( ( *it )->length() > 0 )
{
m_pattern->removeNote( *it );
@@ -2595,7 +2612,6 @@ void pianoRoll::dragNotes( int x, int y, bool alt, bool shift )
if( ( *it )->selected() )
{
if( m_action == ActionMoveNote )
{
// moving note
@@ -3599,7 +3615,12 @@ void pianoRoll::pasteNotes()
// remove selection and select the newly pasted notes
clearSelectedNotes();
if( !list.isEmpty() )
{
m_pattern->addJournalCheckPoint();
}
for( int i = 0; !list.item( i ).isNull(); ++i )
{
// create the note
@@ -3635,7 +3656,8 @@ void pianoRoll::deleteSelectedNotes()
}
bool update_after_delete = false;
m_pattern->addJournalCheckPoint();
// get note-vector of current pattern
const NoteVector & notes = m_pattern->notes();