我的代码中有这个多图:
multimap<long, Note> noteList;
// notes are added with this method. measureNumber is minimum `1` and doesn't go very high
void Track::addNote(Note ¬e) {
long key = note.measureNumber * 1000000 + note.startTime;
this->noteList.insert(make_pair(key, note));
}
当我尝试阅读最后一个小节的注释时遇到了问题。在这种情况下,这首歌只有 8 个小节,而导致问题的是第 8 个小节。如果我达到 16 项措施,则导致问题的措施是 16 项,依此类推。
// (when adding notes I use as key the measureNumber * 1000000. This searches for notes within the same measure)
for(noteIT = trackIT->noteList.lower_bound(this->curMsr * 1000000); noteIT->first < (this->curMsr + 1) * 1000000; noteIT++){
if(this->curMsr == 8){
cout << "_______________________________________________________" << endl;
cout << "ID:" << noteIT->first << endl;
noteIT->second.toString();
int blah = 0;
}
// code left out here that processes the notes
}
我只在第 8 小节中添加了一个注释,但这是我在控制台中得到的结果:
_______________________________________________________
ID:8000001
note toString()
Duration: 8
Start Time: 1
Frequency: 880
_______________________________________________________
ID:1
note toString()
Duration: 112103488
Start Time: 44
Frequency: 0
_______________________________________________________
ID:8000001
note toString()
Duration: 8
Start Time: 1
Frequency: 880
_______________________________________________________
ID:1
note toString()
Duration: 112103488
Start Time: 44
Frequency: 0
这不断重复。第一个结果是我自己添加的正确注释,但我不知道注释ID: 1
来自哪里。
任何想法如何避免这种情况?这个循环卡住了重复相同的两个结果,我无法摆脱它。即使小节 8 中有多个音符(这意味着多重映射中以8xxxxxx
它开头的多个值仅重复第一个音符和不存在的音符。