Fix invalid use of iterators in piano roll (#6869)

This commit is contained in:
Rossmaxx
2023-09-18 22:14:08 +05:30
committed by GitHub
parent e9125d3ad3
commit 733e0a1e54

View File

@@ -1719,10 +1719,10 @@ void PianoRoll::mousePressEvent(QMouseEvent * me )
const NoteVector & notes = m_midiClip->notes();
// will be our iterator in the following loop
auto it = notes.begin() + notes.size() - 1;
auto it = notes.rbegin();
// loop through whole note-vector...
for( int i = 0; i < notes.size(); ++i )
while (it != notes.rend())
{
Note *note = *it;
TimePos len = note->length();
@@ -1747,7 +1747,7 @@ void PianoRoll::mousePressEvent(QMouseEvent * me )
{
break;
}
--it;
++it;
}
// first check whether the user clicked in note-edit-
@@ -1769,7 +1769,7 @@ void PianoRoll::mousePressEvent(QMouseEvent * me )
Note * created_new_note = nullptr;
// did it reach end of vector because
// there's no note??
if( it == notes.begin()-1 )
if (it == notes.rend())
{
is_new_note = true;
m_midiClip->addJournalCheckPoint();
@@ -1816,8 +1816,8 @@ void PianoRoll::mousePressEvent(QMouseEvent * me )
// reset it so that it can be used for
// ops (move, resize) after this
// code-block
it = notes.begin();
while( it != notes.end() && *it != created_new_note )
it = notes.rbegin();
while (it != notes.rend() && *it != created_new_note)
{
++it;
}
@@ -1933,7 +1933,7 @@ void PianoRoll::mousePressEvent(QMouseEvent * me )
{
// erase single note
m_mouseDownRight = true;
if( it != notes.begin()-1 )
if (it != notes.rend())
{
m_midiClip->addJournalCheckPoint();
m_midiClip->removeNote( *it );
@@ -2513,7 +2513,7 @@ void PianoRoll::mouseMoveEvent( QMouseEvent * me )
bool altPressed = me->modifiers() & Qt::AltModifier;
// We iterate from last note in MIDI clip to the first,
// chronologically
auto it = notes.begin() + notes.size() - 1;
auto it = notes.rbegin();
for( int i = 0; i < notes.size(); ++i )
{
Note* n = *it;
@@ -2556,7 +2556,7 @@ void PianoRoll::mouseMoveEvent( QMouseEvent * me )
}
--it;
++it;
}
// Emit MIDI clip has changed
@@ -2575,10 +2575,10 @@ void PianoRoll::mouseMoveEvent( QMouseEvent * me )
const NoteVector & notes = m_midiClip->notes();
// will be our iterator in the following loop
auto it = notes.begin() + notes.size() - 1;
auto it = notes.rbegin();
// loop through whole note-vector...
for( int i = 0; i < notes.size(); ++i )
while (it != notes.rend())
{
Note *note = *it;
// and check whether the cursor is over an
@@ -2591,12 +2591,12 @@ void PianoRoll::mouseMoveEvent( QMouseEvent * me )
{
break;
}
--it;
++it;
}
// did it reach end of vector because there's
// no note??
if( it != notes.begin()-1 )
if (it != notes.rend())
{
Note *note = *it;
// x coordinate of the right edge of the note