From dae0c05061e904bda042d783ac9da6c0b3002bf8 Mon Sep 17 00:00:00 2001 From: Amadeus Folego Date: Wed, 28 Jan 2015 23:22:29 -0200 Subject: [PATCH] Change Shift+Resize selected notes on Piano Roll Selected notes: when resized would offset posterior, non-selected notes to mantain some kind of melodic structure. This is referred to as *sticky* behaviour. It also assumes some kind of intention that may not be the case. Also adds complexity to a simple feature. This commit makes only the the selected notes be offset. It also adds a new shortcut to the old behaviour . Fixes #1666 --- include/PianoRoll.h | 2 +- src/gui/editors/PianoRoll.cpp | 39 +++++++++++++++++++++-------------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/include/PianoRoll.h b/include/PianoRoll.h index 6260eaa7e..f4f313174 100644 --- a/include/PianoRoll.h +++ b/include/PianoRoll.h @@ -231,7 +231,7 @@ private: inline int noteEditRight() const; inline int noteEditLeft() const; - void dragNotes( int x, int y, bool alt, bool shift ); + void dragNotes( int x, int y, bool alt, bool shift, bool ctrl ); static const int cm_scrollAmtHoriz = 10; static const int cm_scrollAmtVert = 1; diff --git a/src/gui/editors/PianoRoll.cpp b/src/gui/editors/PianoRoll.cpp index 0d3540975..c14b6b930 100644 --- a/src/gui/editors/PianoRoll.cpp +++ b/src/gui/editors/PianoRoll.cpp @@ -949,7 +949,8 @@ void PianoRoll::keyPressEvent(QKeyEvent* ke ) { dragNotes( m_lastMouseX, m_lastMouseY, ke->modifiers() & Qt::AltModifier, - ke->modifiers() & Qt::ShiftModifier ); + ke->modifiers() & Qt::ShiftModifier, + ke->modifiers() & Qt::ControlModifier ); } } ke->accept(); @@ -981,7 +982,8 @@ void PianoRoll::keyPressEvent(QKeyEvent* ke ) { dragNotes( m_lastMouseX, m_lastMouseY, ke->modifiers() & Qt::AltModifier, - ke->modifiers() & Qt::ShiftModifier ); + ke->modifiers() & Qt::ShiftModifier, + ke->modifiers() & Qt::ControlModifier ); } } ke->accept(); @@ -1022,7 +1024,8 @@ void PianoRoll::keyPressEvent(QKeyEvent* ke ) { dragNotes( m_lastMouseX, m_lastMouseY, ke->modifiers() & Qt::AltModifier, - ke->modifiers() & Qt::ShiftModifier ); + ke->modifiers() & Qt::ShiftModifier, + ke->modifiers() & Qt::ControlModifier ); } } @@ -1063,7 +1066,8 @@ void PianoRoll::keyPressEvent(QKeyEvent* ke ) { dragNotes( m_lastMouseX, m_lastMouseY, ke->modifiers() & Qt::AltModifier, - ke->modifiers() & Qt::ShiftModifier ); + ke->modifiers() & Qt::ShiftModifier, + ke->modifiers() & Qt::ControlModifier ); } } @@ -1120,7 +1124,11 @@ void PianoRoll::keyPressEvent(QKeyEvent* ke ) } case Qt::Key_Control: - if ( isActiveWindow() ) + // Enter selection mode if: + // -> this window is active + // -> shift is not pressed + // ( is shortcut for sticky note resize) + if ( !( ke->modifiers() & Qt::ShiftModifier ) && isActiveWindow() ) { m_ctrlMode = m_editMode; m_editMode = ModeSelect; @@ -1265,7 +1273,7 @@ void PianoRoll::mousePressEvent(QMouseEvent * me ) return; } - // if holding control, go to selection mode + // if holding control, go to selection mode unless shift is also pressed if( me->modifiers() & Qt::ControlModifier && m_editMode != ModeSelect ) { m_ctrlMode = m_editMode; @@ -1991,12 +1999,10 @@ void PianoRoll::mouseMoveEvent( QMouseEvent * me ) pauseTestNotes(); } - dragNotes( - me->x(), - me->y(), + dragNotes( me->x(), me->y(), me->modifiers() & Qt::AltModifier, - me->modifiers() & Qt::ShiftModifier - ); + me->modifiers() & Qt::ShiftModifier, + me->modifiers() & Qt::ControlModifier ); if( replay_note && m_action == ActionMoveNote && ! ( ( me->modifiers() & Qt::ShiftModifier ) && ! m_startedWithShift ) ) { @@ -2408,7 +2414,7 @@ void PianoRoll::mouseMoveEvent( QMouseEvent * me ) -void PianoRoll::dragNotes( int x, int y, bool alt, bool shift ) +void PianoRoll::dragNotes( int x, int y, bool alt, bool shift, bool ctrl ) { // dragging one or more notes around @@ -2458,9 +2464,12 @@ void PianoRoll::dragNotes( int x, int y, bool alt, bool shift ) { Note *note = *it; const int pos = note->pos().getTicks(); - // when resizing a note and holding shift: shift the following - // notes to preserve the melody - if( m_action == ActionResizeNote && shift ) + + // When resizing notes: + // If shift is pressed we resize and rearrange only the selected notes + // If shift + ctrl then we also rearrange all posterior notes (sticky) + if( m_action == ActionResizeNote && shift && + ( note->selected() || ctrl ) ) { int shifted_pos = note->oldPos().getTicks() + shift_offset; if( shifted_pos && pos == shift_ref_pos )