From b4204dd0e8ec831838918c06a43ff15a4bfbf281 Mon Sep 17 00:00:00 2001 From: Matthias Neeracher Date: Sun, 29 Jul 2007 20:12:02 +0000 Subject: [PATCH] Merge adjacent rests --- Sources/VLModel.cpp | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/Sources/VLModel.cpp b/Sources/VLModel.cpp index c8f1b97..4ddbbfb 100644 --- a/Sources/VLModel.cpp +++ b/Sources/VLModel.cpp @@ -706,6 +706,26 @@ void VLSong::AddNote(VLLyricsNote note, size_t measure, VLFraction at) i->fDuration = at-t; i = fMeasures[measure].fMelody.insert(++i, note); } + if (i->fPitch == VLNote::kNoPitch) { + // + // Merge with adjacent rests + // + if (i != fMeasures[measure].fMelody.begin()) { + VLNoteList::iterator j = i; + --j; + if (j->fPitch == VLNote::kNoPitch) { + j->fDuration += i->fDuration; + fMeasures[measure].fMelody.erase(i); + i = j; + } + } + VLNoteList::iterator j = i; + ++j; + if (j != fMeasures[measure].fMelody.end() && j->fPitch == VLNote::kNoPitch) { + i->fDuration += j->fDuration; + fMeasures[measure].fMelody.erase(j); + } + } break; // Exit here } t = tEnd; @@ -750,11 +770,17 @@ void VLSong::DelNote(size_t measure, VLFraction at) fMeasures[measure].fMelody.erase(i); } else { // - // Turn into rest + // Merge with next if it's a rest, otherwise, just turn into rest // + VLNoteList::iterator j = i; + ++j; + if (j != fMeasures[measure].fMelody.end() && j->fPitch == VLNote::kNoPitch) { + i->fDuration += j->fDuration; + fMeasures[measure].fMelody.erase(j); + } i->fPitch = VLNote::kNoPitch; - i->fTied = 0; - } + i->fTied = 0; + } break; } VLFraction tEnd = t+i->fDuration;