Skip to content

Commit

Permalink
Fixed LMMS crash when pressing Q in not existing piano roll. (LMMS#3609)
Browse files Browse the repository at this point in the history
  • Loading branch information
karmux authored and zonkmachine committed Jun 7, 2017
1 parent 759e7d8 commit 0de93cd
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions src/gui/editors/PianoRoll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ void PianoRoll::setBackgroundShade( const QColor & c )



void PianoRoll::drawNoteRect( QPainter & p, int x, int y,
void PianoRoll::drawNoteRect( QPainter & p, int x, int y,
int width, const Note * n, const QColor & noteCol,
const QColor & selCol, const int noteOpc, const bool borders )
{
Expand Down Expand Up @@ -1918,7 +1918,7 @@ void PianoRoll::mouseReleaseEvent( QMouseEvent * me )
{
// select the notes within the selection rectangle and
// then destroy the selection rectangle
computeSelectedNotes(
computeSelectedNotes(
me->modifiers() & Qt::ShiftModifier );
}
else if( m_action == ActionMoveNote )
Expand Down Expand Up @@ -2463,15 +2463,15 @@ void PianoRoll::dragNotes( int x, int y, bool alt, bool shift, bool ctrl )
}
}
}
}
}
else if (m_action == ActionResizeNote)
{
// When resizing notes:
// If shift is not pressed, resize the selected notes but do not rearrange them
// If shift is pressed we resize and rearrange only the selected notes
// If shift + ctrl then we also rearrange all posterior notes (sticky)
// If shift is pressed but only one note is selected, apply sticky

if (shift)
{
// Algorithm:
Expand All @@ -2491,8 +2491,8 @@ void PianoRoll::dragNotes( int x, int y, bool alt, bool shift, bool ctrl )
const Note *posteriorNote = nullptr;
for (const Note *note : notes)
{
if (note->selected() && (posteriorNote == nullptr ||
note->oldPos().getTicks() + note->oldLength().getTicks() >
if (note->selected() && (posteriorNote == nullptr ||
note->oldPos().getTicks() + note->oldLength().getTicks() >
posteriorNote->oldPos().getTicks() + posteriorNote->oldLength().getTicks()))
{
posteriorNote = note;
Expand All @@ -2512,9 +2512,9 @@ void PianoRoll::dragNotes( int x, int y, bool alt, bool shift, bool ctrl )
if(note->selected())
{
// scale relative start and end positions by scaleFactor
int newStart = stretchStartTick + scaleFactor *
int newStart = stretchStartTick + scaleFactor *
(note->oldPos().getTicks() - stretchStartTick);
int newEnd = stretchStartTick + scaleFactor *
int newEnd = stretchStartTick + scaleFactor *
(note->oldPos().getTicks()+note->oldLength().getTicks() - stretchStartTick);
// if not holding alt, quantize the offsets
if(!alt)
Expand All @@ -2533,7 +2533,7 @@ void PianoRoll::dragNotes( int x, int y, bool alt, bool shift, bool ctrl )
int newLength = qMax(1, newEnd-newStart);
if (note == posteriorNote)
{
posteriorDeltaThisFrame = (newStart+newLength) -
posteriorDeltaThisFrame = (newStart+newLength) -
(note->pos().getTicks() + note->length().getTicks());
}
note->setLength( MidiTime(newLength) );
Expand Down Expand Up @@ -3918,27 +3918,32 @@ int PianoRoll::quantization() const

void PianoRoll::quantizeNotes()
{
if( ! hasValidPattern() )
{
return;
}

NoteVector notes = getSelectedNotes();

if (notes.empty())
if( notes.empty() )
{
for (Note* n : m_pattern->notes())
for( Note* n : m_pattern->notes() )
{
notes.push_back(n);
notes.push_back( n );
}
}

for (Note* n : notes)
for( Note* n : notes )
{
if (n->length() == MidiTime(0))
if( n->length() == MidiTime( 0 ) )
{
continue;
}

Note copy(*n);
m_pattern->removeNote(n);
copy.quantizePos(quantization());
m_pattern->addNote(copy);
m_pattern->removeNote( n );
copy.quantizePos( quantization() );
m_pattern->addNote( copy );
}

update();
Expand Down

0 comments on commit 0de93cd

Please sign in to comment.