Fix note extending

This commit is contained in:
Matthias Neeracher 2007-04-27 03:57:14 +00:00
parent d5af21ff96
commit c42e5faa30

View File

@ -850,6 +850,16 @@ void VLSong::swap(VLSong & other)
std::swap(fCoda, other.fCoda); std::swap(fCoda, other.fCoda);
} }
void VLSong::clear()
{
fProperties.resize(1);
fMeasures.clear();
fRepeats.clear();
fGoToCoda = -1;
fCoda = -1;
}
// //
// Deal with chords - a bit simpler // Deal with chords - a bit simpler
// //
@ -1024,63 +1034,56 @@ void VLSong::DelNote(size_t measure, VLFraction at)
void VLSong::ExtendNote(size_t measure, VLFraction at) void VLSong::ExtendNote(size_t measure, VLFraction at)
{ {
VLNoteList::iterator i = fMeasures[measure].fMelody.begin(); VLNoteList::iterator i = fMeasures[measure].fMelody.begin();
VLFraction t(0); VLNoteList::iterator end= fMeasures[measure].fMelody.end();
for (VLFraction t(0); i != end && t+i->fDuration <= at; ++i)
t += i->fDuration;
if (i == end)
--i;
if (i->fPitch == VLNote::kNoPitch)
return; // Don't extend rests
for (;;) { for (;;) {
if (t == at) { VLNoteList::iterator j=i;
if (i->fPitch == VLNote::kNoPitch) ++j;
return; // Don't extend rests if (j != fMeasures[measure].fMelody.end()) {
do { //
VLNoteList::iterator j=i; // Extend across next note/rest
++j; //
if (j != fMeasures[measure].fMelody.end()) { i->fDuration += j->fDuration;
fMeasures[measure].fMelody.erase(j);
} else if (++measure < fMeasures.size()) {
//
// Extend into next measure
//
VLNoteList::iterator k = fMeasures[measure].fMelody.begin();
if (k->fTied & VLNote::kTiedWithPrev) {
//
// Already extended, extend further
//
i = k;
continue; // Go for another spin
} else {
for (;;) {
bool wasTied = k->fTied & VLNote::kTiedWithNext;
// //
// Extend across next note/rest // Extend previous note
// //
i->fDuration += j->fDuration; k->fPitch = i->fPitch;
fMeasures[measure].fMelody.erase(j); k->fTied = VLNote::kTiedWithPrev;
} else if (++measure < fMeasures.size()) { i->fTied |= VLNote::kTiedWithNext;
// k->fLyrics.clear();
// Extend into next measure if (!wasTied)
// break;
VLNoteList::iterator k = fMeasures[measure].fMelody.begin(); i = k;
if (k->fTied & VLNote::kTiedWithPrev) { k = fMeasures[++measure].fMelody.begin();
//
// Already extended, extend further
//
i = k;
continue; // Go for another spin
} else {
bool wasTied = k->fTied & VLNote::kTiedWithNext;
//
// Extend previous note
//
k->fPitch = i->fPitch;
k->fTied = VLNote::kTiedWithPrev;
i->fTied |= VLNote::kTiedWithNext;
k->fLyrics.clear();
if (wasTied) {
//
// Extend further
//
i = k;
continue;
}
}
} }
} while (0); }
//
// Finished extending
//
return;
} }
VLFraction tEnd = t+i->fDuration; break;
if (tEnd > at) }
break; // Past the point, quit
t = tEnd;
++i;
}
} }
static void TransposePinned(int8_t & pitch, int semi) static void TransposePinned(int8_t & pitch, int semi)