diff --git a/mscore/importmidi_lrhand.cpp b/mscore/importmidi_lrhand.cpp index ce72065c967fc..d4a13e4d878cf 100644 --- a/mscore/importmidi_lrhand.cpp +++ b/mscore/importmidi_lrhand.cpp @@ -40,7 +40,7 @@ void splitByFixedPitch(std::multimap &tracks, + (int)trackOpers.LHRH.splitPitchNote; std::multimap leftHandChords; - for (auto i = srcTrack.chords.begin(); i != srcTrack.chords.end(); ++i) { + for (auto i = srcTrack.chords.begin(); i != srcTrack.chords.end(); ) { auto ¬es = i->second.notes; QList leftHandNotes; for (auto j = notes.begin(); j != notes.end(); ) { @@ -54,6 +54,11 @@ void splitByFixedPitch(std::multimap &tracks, } if (!leftHandNotes.empty()) addNewLeftHandChord(leftHandChords, leftHandNotes, i); + if (notes.isEmpty()) { + i = srcTrack.chords.erase(i); + continue; + } + ++i; } if (!leftHandChords.empty()) insertNewLeftHandTrack(tracks, it, leftHandChords); @@ -67,7 +72,7 @@ void splitByHandWidth(std::multimap &tracks, const int octave = 12; std::multimap leftHandChords; // chords after MIDI import are sorted by onTime values - for (auto i = srcTrack.chords.begin(); i != srcTrack.chords.end(); ++i) { + for (auto i = srcTrack.chords.begin(); i != srcTrack.chords.end(); ) { auto ¬es = i->second.notes; QList leftHandNotes; const int minPitch = notes.front().pitch; @@ -97,6 +102,11 @@ void splitByHandWidth(std::multimap &tracks, } if (!leftHandNotes.empty()) addNewLeftHandChord(leftHandChords, leftHandNotes, i); + if (notes.isEmpty()) { + i = srcTrack.chords.erase(i); + continue; + } + ++i; } if (!leftHandChords.empty()) insertNewLeftHandTrack(tracks, it, leftHandChords);