From 0cd0effb46552c02ef809bdac31bdbe7f4113b7b Mon Sep 17 00:00:00 2001 From: Matthias Neeracher Date: Mon, 12 Sep 2011 16:29:14 +0200 Subject: [PATCH] Fix skipping of rests in pickup measures --- Sources/VLLilypondWriter.cpp | 6 ++++-- Sources/VLModel.cpp | 16 ++++++++++++++++ Sources/VLModel.h | 1 + 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Sources/VLLilypondWriter.cpp b/Sources/VLLilypondWriter.cpp index 2cc19f5..42c561c 100644 --- a/Sources/VLLilypondWriter.cpp +++ b/Sources/VLLilypondWriter.cpp @@ -50,8 +50,10 @@ void VLLilypondWriter::VisitMeasure(size_t m, VLProperties & p, VLMeasure & meas measNo[0] = 0; fUseSharps = p.fKey > 0; - if (fInPickup && !m && meas.NoChords()) + fInPickup = fInPickup && !m && meas.NoChords(); + if (fInPickup) ++fPrevBreak; + fInPickup = fInPickup && meas.CanSkipRests(); // // Generate chords @@ -251,7 +253,7 @@ void VLLilypondWriter::VisitNote(VLLyricsNote & n) for (int commas = -1-octave; commas>0; --commas) nm += ','; fInPickup = false; - } else if (fInPickup) { + } else if (fInPickup && n.fDuration.IsPowerOfTwo()) { nm = "s"; } const char * space = fAccum.size() ? " " : ""; diff --git a/Sources/VLModel.cpp b/Sources/VLModel.cpp index 8fa14ae..a8de82d 100644 --- a/Sources/VLModel.cpp +++ b/Sources/VLModel.cpp @@ -222,6 +222,22 @@ bool VLMeasure::NoChords() const && fChords.front().fPitch == VLNote::kNoPitch; } +bool VLMeasure::CanSkipRests() const +{ + VLFraction restDur(0); + VLFraction totalDur(0); + bool initialRest = true; + + for (VLNoteList::const_iterator n = fMelody.begin(); n != fMelody.end(); ++n) { + if (n->fPitch != VLNote::kNoPitch) + initialRest = false; + totalDur += n->fDuration; + if (initialRest) + restDur += n->fDuration; + } + return 2*restDur >= totalDur; +} + void VLMeasure::DecomposeNotes(const VLProperties & prop, VLNoteList & decomposed) const { decomposed.clear(); diff --git a/Sources/VLModel.h b/Sources/VLModel.h index c7500cc..f12f695 100644 --- a/Sources/VLModel.h +++ b/Sources/VLModel.h @@ -341,6 +341,7 @@ struct VLMeasure { bool IsEmpty() const; bool NoChords() const; + bool CanSkipRests() const; void DecomposeNotes(const VLProperties & prop, VLNoteList & decomposed) const; };