Mercurial > hg > svcore
comparison data/fileio/MIDIFileReader.cpp @ 965:2d5a8219b4b0
Backed out changeset 6b5e1edd95fc. I had misunderstood, the container is a vector, not a map, so the fix doesn't work and the original code (although definitely flawed) actually does
author | Chris Cannam |
---|---|
date | Wed, 03 Sep 2014 10:56:59 +0100 |
parents | 6b5e1edd95fc |
children | 920699b6989d |
comparison
equal
deleted
inserted
replaced
964:6b5e1edd95fc | 965:2d5a8219b4b0 |
---|---|
659 { | 659 { |
660 bool notesOnTrack = false; | 660 bool notesOnTrack = false; |
661 bool noteOffFound; | 661 bool noteOffFound; |
662 | 662 |
663 for (MIDITrack::iterator i = m_midiComposition[track].begin(); | 663 for (MIDITrack::iterator i = m_midiComposition[track].begin(); |
664 i != m_midiComposition[track].end(); ) { | 664 i != m_midiComposition[track].end(); i++) { |
665 | |
666 MIDITrack::iterator nexti = i; | |
667 ++nexti; | |
668 | 665 |
669 if ((*i)->getMessageType() == MIDI_NOTE_ON && (*i)->getVelocity() > 0) { | 666 if ((*i)->getMessageType() == MIDI_NOTE_ON && (*i)->getVelocity() > 0) { |
670 | 667 |
671 notesOnTrack = true; | 668 notesOnTrack = true; |
672 noteOffFound = false; | 669 noteOffFound = false; |
679 ((*j)->getMessageType() == MIDI_NOTE_OFF || | 676 ((*j)->getMessageType() == MIDI_NOTE_OFF || |
680 ((*j)->getMessageType() == MIDI_NOTE_ON && | 677 ((*j)->getMessageType() == MIDI_NOTE_ON && |
681 (*j)->getVelocity() == 0x00))) { | 678 (*j)->getVelocity() == 0x00))) { |
682 | 679 |
683 (*i)->setDuration((*j)->getTime() - (*i)->getTime()); | 680 (*i)->setDuration((*j)->getTime() - (*i)->getTime()); |
684 | |
685 if (nexti == j) { | |
686 // we're about to erase j, invalidating nexti | |
687 // as well (but as this is a map, that is the | |
688 // only iterator to be invalidated) | |
689 ++nexti; | |
690 } | |
691 | 681 |
692 delete *j; | 682 delete *j; |
693 m_midiComposition[track].erase(j); | 683 m_midiComposition[track].erase(j); |
694 | 684 |
695 noteOffFound = true; | 685 noteOffFound = true; |
704 MIDITrack::iterator j = m_midiComposition[track].end(); | 694 MIDITrack::iterator j = m_midiComposition[track].end(); |
705 --j; | 695 --j; |
706 (*i)->setDuration((*j)->getTime() - (*i)->getTime()); | 696 (*i)->setDuration((*j)->getTime() - (*i)->getTime()); |
707 } | 697 } |
708 } | 698 } |
709 | |
710 i = nexti; | |
711 } | 699 } |
712 | 700 |
713 return notesOnTrack; | 701 return notesOnTrack; |
714 } | 702 } |
715 | 703 |