Mercurial > hg > silvet
changeset 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 | cd61b43573bb |
files | src/Silvet.cpp |
diffstat | 1 files changed, 9 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/src/Silvet.cpp Mon Sep 07 14:45:19 2015 +0100 +++ b/src/Silvet.cpp Mon Sep 07 16:23:55 2015 +0100 @@ -1059,11 +1059,14 @@ if (width < durationThreshold + 1) { return { noteFeatures, onsetFeatures, onOffsetFeatures }; } + + // Make a copy of the latest column. We need a copy because it is + // possible we may erase from the "live" column within the loop. + map<int, double> latest = m_pianoRoll[width-1]; - for (map<int, double>::const_iterator ni = m_pianoRoll[width-1].begin(); - ni != m_pianoRoll[width-1].end(); ++ni) { + for (const auto &ni: latest) { - int note = ni->first; + int note = ni.first; int end = width; int start = end-1; @@ -1100,7 +1103,9 @@ m_current.erase(note); emitNoteAndOffset(start, end-1, note, noteFeatures, onOffsetFeatures); // and remove this so that we start counting the new - // note's duration from the current position + // note's duration from the current position. (This + // erase is why we needed to copy this column at the + // top of the loop.) m_pianoRoll[width-1].erase(note); } }