comparison src/Silvet.cpp @ 357:0af00da90a40

Copy the column before potentially erasing while iterating through it
author Chris Cannam
date Mon, 07 Sep 2015 16:23:55 +0100
parents 7dcff010d9cd
children 78ed74fa177b
comparison
equal deleted inserted replaced
356:7dcff010d9cd 357:0af00da90a40
1057 FeatureList noteFeatures, onsetFeatures, onOffsetFeatures; 1057 FeatureList noteFeatures, onsetFeatures, onOffsetFeatures;
1058 1058
1059 if (width < durationThreshold + 1) { 1059 if (width < durationThreshold + 1) {
1060 return { noteFeatures, onsetFeatures, onOffsetFeatures }; 1060 return { noteFeatures, onsetFeatures, onOffsetFeatures };
1061 } 1061 }
1062 1062
1063 for (map<int, double>::const_iterator ni = m_pianoRoll[width-1].begin(); 1063 // Make a copy of the latest column. We need a copy because it is
1064 ni != m_pianoRoll[width-1].end(); ++ni) { 1064 // possible we may erase from the "live" column within the loop.
1065 1065 map<int, double> latest = m_pianoRoll[width-1];
1066 int note = ni->first; 1066
1067 for (const auto &ni: latest) {
1068
1069 int note = ni.first;
1067 1070
1068 int end = width; 1071 int end = width;
1069 int start = end-1; 1072 int start = end-1;
1070 1073
1071 while (m_pianoRoll[start].find(note) != m_pianoRoll[start].end()) { 1074 while (m_pianoRoll[start].find(note) != m_pianoRoll[start].end()) {
1098 (active.find(note)->second > 1101 (active.find(note)->second >
1099 restartFactor * m_pianoRoll[width-1][note])) { 1102 restartFactor * m_pianoRoll[width-1][note])) {
1100 m_current.erase(note); 1103 m_current.erase(note);
1101 emitNoteAndOffset(start, end-1, note, noteFeatures, onOffsetFeatures); 1104 emitNoteAndOffset(start, end-1, note, noteFeatures, onOffsetFeatures);
1102 // and remove this so that we start counting the new 1105 // and remove this so that we start counting the new
1103 // note's duration from the current position 1106 // note's duration from the current position. (This
1107 // erase is why we needed to copy this column at the
1108 // top of the loop.)
1104 m_pianoRoll[width-1].erase(note); 1109 m_pianoRoll[width-1].erase(note);
1105 } 1110 }
1106 } 1111 }
1107 } 1112 }
1108 1113