Fix invalidated iterator when removing notes in Piano Roll (#7080)
* Fix invalidated iterator when removing notes in Piano Roll * fixup - typo * Add MidiClip::removeNote(iterator) function * Use iterator version of remoteNote * Fix parameter name * Change variable name again
This commit is contained in:
@@ -63,7 +63,8 @@ public:
|
||||
// note management
|
||||
Note * addNote( const Note & _new_note, const bool _quant_pos = true );
|
||||
|
||||
void removeNote( Note * _note_to_del );
|
||||
NoteVector::const_iterator removeNote(NoteVector::const_iterator it);
|
||||
NoteVector::const_iterator removeNote(Note* note);
|
||||
|
||||
Note * noteAtStep( int _step );
|
||||
|
||||
|
||||
@@ -2646,7 +2646,7 @@ void PianoRoll::mouseMoveEvent( QMouseEvent * me )
|
||||
)
|
||||
{
|
||||
// delete this note
|
||||
m_midiClip->removeNote( note );
|
||||
it = m_midiClip->removeNote(it);
|
||||
Engine::getSong()->setModified();
|
||||
}
|
||||
else
|
||||
|
||||
@@ -208,16 +208,30 @@ Note * MidiClip::addNote( const Note & _new_note, const bool _quant_pos )
|
||||
|
||||
|
||||
|
||||
void MidiClip::removeNote( Note * _note_to_del )
|
||||
NoteVector::const_iterator MidiClip::removeNote(NoteVector::const_iterator it)
|
||||
{
|
||||
instrumentTrack()->lock();
|
||||
delete *it;
|
||||
auto new_it = m_notes.erase(it);
|
||||
instrumentTrack()->unlock();
|
||||
|
||||
checkType();
|
||||
updateLength();
|
||||
|
||||
emit dataChanged();
|
||||
return new_it;
|
||||
}
|
||||
|
||||
NoteVector::const_iterator MidiClip::removeNote(Note* note)
|
||||
{
|
||||
instrumentTrack()->lock();
|
||||
|
||||
m_notes.erase(std::remove_if(m_notes.begin(), m_notes.end(), [&](Note* note)
|
||||
auto it = std::find(m_notes.begin(), m_notes.end(), note);
|
||||
if (it != m_notes.end())
|
||||
{
|
||||
auto shouldRemove = note == _note_to_del;
|
||||
if (shouldRemove) { delete note; }
|
||||
return shouldRemove;
|
||||
}), m_notes.end());
|
||||
delete *it;
|
||||
it = m_notes.erase(it);
|
||||
}
|
||||
|
||||
instrumentTrack()->unlock();
|
||||
|
||||
@@ -225,6 +239,7 @@ void MidiClip::removeNote( Note * _note_to_del )
|
||||
updateLength();
|
||||
|
||||
emit dataChanged();
|
||||
return it;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user