static void removeDuplicates(std::vector<RprMidiNote *> &midiNotes) { for(int noteOffset = 0; (midiNotes.begin() + noteOffset) != midiNotes.end(); noteOffset++) { std::vector<RprMidiNote *>::iterator i = midiNotes.begin() + noteOffset; RprMidiNote *lhs = *i; for(std::vector<RprMidiNote *>::iterator j = i + 1; j != midiNotes.end(); j++) { RprMidiNote *rhs = *j; if (rhs->getItemPosition() > lhs->getItemPosition()) { break; } if(lhs->getItemPosition() != rhs->getItemPosition()) { continue; } if(lhs->getPitch() != rhs->getPitch()) { continue; } if(lhs->getChannel() != rhs->getChannel()) { continue; } if(lhs->getItemLength() > rhs->getItemLength()) { delete rhs; j = midiNotes.erase(j); if (noteOffset+1 >= (int)midiNotes.size()) break; } else { delete lhs; i = midiNotes.erase(i); noteOffset--; break; } } } }
static void removeOverlaps(std::vector<RprMidiNote *> &midiNotes) { for(int noteOffset = 0; (midiNotes.begin() + noteOffset) != midiNotes.end(); ++noteOffset) { std::vector<RprMidiNote *>::iterator i = midiNotes.begin() + noteOffset; RprMidiNote *lhs = *i; for(std::vector<RprMidiNote *>::iterator j = i + 1; j != midiNotes.end(); j++) { RprMidiNote *rhs = *j; if(rhs->getItemPosition() >= lhs->getItemPosition() + lhs->getItemLength()) { break; } if(lhs->getPitch() != rhs->getPitch()) { continue; } if(lhs->getChannel() != rhs->getChannel()) { continue; } if(lhs->getItemPosition() + lhs->getItemLength() >= rhs->getItemPosition()) { int lhsLength = rhs->getItemPosition() - lhs->getItemPosition(); if(lhsLength <= 0) { delete lhs; i = midiNotes.erase(i); noteOffset--; } else { lhs->setItemLength(lhsLength); } break; } } } }