From b3b290f6dd40af1205a90f3844a776824e962a79 Mon Sep 17 00:00:00 2001 From: NoiseByNorthwest Date: Sun, 22 Jan 2012 13:25:58 +0100 Subject: [PATCH] Piano-roll: preserve melody when resizing a note by holding shift --- include/piano_roll.h | 2 +- src/gui/piano_roll.cpp | 53 +++++++++++++++++++++++++++++++++--------- 2 files changed, 43 insertions(+), 12 deletions(-) diff --git a/include/piano_roll.h b/include/piano_roll.h index 426fd8170..c00d64990 100644 --- a/include/piano_roll.h +++ b/include/piano_roll.h @@ -204,7 +204,7 @@ private: inline int noteEditRight() const; inline int noteEditLeft() const; - void dragNotes( int x, int y, bool alt ); + void dragNotes( int x, int y, bool alt, bool shift ); static const int cm_scrollAmtHoriz = 10; static const int cm_scrollAmtVert = 1; diff --git a/src/gui/piano_roll.cpp b/src/gui/piano_roll.cpp index 030c9fe48..7bb995fd5 100644 --- a/src/gui/piano_roll.cpp +++ b/src/gui/piano_roll.cpp @@ -927,8 +927,8 @@ void pianoRoll::keyPressEvent( QKeyEvent * _ke ) m_action == ActionResizeNote ) { dragNotes( m_lastMouseX, m_lastMouseY, - _ke->modifiers() & - Qt::AltModifier ); + _ke->modifiers() & Qt::AltModifier, + _ke->modifiers() & Qt::ShiftModifier ); } } _ke->accept(); @@ -955,8 +955,8 @@ void pianoRoll::keyPressEvent( QKeyEvent * _ke ) m_action == ActionResizeNote ) { dragNotes( m_lastMouseX, m_lastMouseY, - _ke->modifiers() & - Qt::AltModifier ); + _ke->modifiers() & Qt::AltModifier, + _ke->modifiers() & Qt::ShiftModifier ); } } _ke->accept(); @@ -995,8 +995,8 @@ void pianoRoll::keyPressEvent( QKeyEvent * _ke ) m_action == ActionResizeNote ) { dragNotes( m_lastMouseX, m_lastMouseY, - _ke->modifiers() & - Qt::AltModifier ); + _ke->modifiers() & Qt::AltModifier, + _ke->modifiers() & Qt::ShiftModifier ); } } @@ -1033,8 +1033,8 @@ void pianoRoll::keyPressEvent( QKeyEvent * _ke ) m_action == ActionResizeNote ) { dragNotes( m_lastMouseX, m_lastMouseY, - _ke->modifiers() & - Qt::AltModifier ); + _ke->modifiers() & Qt::AltModifier, + _ke->modifiers() & Qt::ShiftModifier ); } } @@ -1944,7 +1944,12 @@ void pianoRoll::mouseMoveEvent( QMouseEvent * _me ) pauseTestNotes(); } - dragNotes(_me->x(), _me->y(), _me->modifiers() & Qt::AltModifier); + dragNotes( + _me->x(), + _me->y(), + _me->modifiers() & Qt::AltModifier, + _me->modifiers() & Qt::ShiftModifier + ); if( replay_note && m_action == ActionMoveNote ) { @@ -2318,7 +2323,7 @@ void pianoRoll::mouseMoveEvent( QMouseEvent * _me ) -void pianoRoll::dragNotes( int x, int y, bool alt ) +void pianoRoll::dragNotes( int x, int y, bool alt, bool shift ) { // dragging one or more notes around @@ -2355,7 +2360,10 @@ void pianoRoll::dragNotes( int x, int y, bool alt ) off_key += 0 - (m_moveBoundaryBottom + off_key); } } - + + int shift_offset = 0; + int shift_ref_pos = -1; + // get note-vector of current pattern const NoteVector & notes = m_pattern->notes(); @@ -2363,6 +2371,19 @@ void pianoRoll::dragNotes( int x, int y, bool alt ) NoteVector::ConstIterator it = notes.begin(); while( it != notes.end() ) { + const int pos = ( *it )->pos().getTicks(); + // when resizing a note and holding shift: shift the following + // notes to preserve the melody + if( m_action == ActionResizeNote && shift ) + { + int shifted_pos = ( *it )->oldPos().getTicks() + shift_offset; + if( shifted_pos && pos == shift_ref_pos ) + { + shifted_pos -= off_ticks; + } + ( *it )->setPos( midiTime( shifted_pos ) ); + } + if( ( *it )->selected() ) { @@ -2399,6 +2420,16 @@ void pianoRoll::dragNotes( int x, int y, bool alt ) { ticks_new = 1; } + else if( shift ) + { + // when holding shift: update the offset used to shift + // the following notes + if( pos > shift_ref_pos ) + { + shift_offset += off_ticks; + shift_ref_pos = pos; + } + } ( *it )->setLength( midiTime( ticks_new ) ); m_lenOfNewNotes = ( *it )->length();