diff --git a/Sources/VLMMAWriter.cpp b/Sources/VLMMAWriter.cpp index 122c9b2..5e1cefe 100644 --- a/Sources/VLMMAWriter.cpp +++ b/Sources/VLMMAWriter.cpp @@ -37,28 +37,23 @@ void VLMMAWriter::VisitMeasure(size_t m, VLProperties & p, VLMeasure & meas) // // Generate melody and account for ties // - bool setLastDur = false; fAccum.clear(); - fTied = meas.fMelody.front().fTied & VLNote::kTiedWithPrev; - if (fTied && meas.fMelody.size() == 1) { - VisitNotes(meas, p, true); - if (meas.fMelody.back().fTied & VLNote::kTiedWithNext) { - fAccum = "~<>~;"; - } else { - fAccum = "~<>;"; - } - } else { - VisitNotes(meas, p, true); - if (meas.fMelody.back().fTied & VLNote::kTiedWithNext) { - fAccum.replace(fAccum.find_last_of(';'), 0, "~", 1); - setLastDur = true; - } + bool tiedWithPrev = (meas.fMelody.front().fTied & VLNote::kTiedWithPrev) + || fSong->DoesTieWithPrevRepeat(m); + bool tiedWithNext = (meas.fMelody.back().fTied & VLNote::kTiedWithNext) + || fSong->DoesTieWithNextRepeat(m); + fTied = tiedWithPrev; + VisitNotes(meas, p, true); + if (fTied || fAccum == "~") { + fAccum = tiedWithNext ? "~<>~;" : "~<>;"; + } else if (tiedWithNext) { + fAccum.replace(fAccum.find_last_of(';'), 0, "~", 1); } std::string melody = fAccum; fMeasures += chords+"\t{ " + melody + " }\n"; - if (setLastDur) + if (!fTied && tiedWithNext) fLastDur = fMeasures.find_last_of("123468"); } @@ -123,18 +118,19 @@ void VLMMAWriter::VisitNote(VLLyricsNote & n) } else if (n.fDuration.fDenom == 24) { dur = "6"; // 16th note triplet } - if (n.fTied & VLNote::kTiedWithPrev) { - if (fTied) { - fMeasures.replace(fLastDur+1, 0, '+'+dur); - if (!(n.fTied & VLNote::kTiedWithNext)) - fAccum += "~"; - } else { - size_t d = fAccum.find_last_of("123468"); - fAccum.replace(d+1, 0, '+'+dur); + if (fTied) { + fMeasures.replace(fLastDur+1, 0, '+'+dur); + fLastDur += 1+dur.size(); + if (!(n.fTied & VLNote::kTiedWithNext)) { + fAccum += "~"; + fTied = false; } return; + } else if (n.fTied & VLNote::kTiedWithPrev) { + size_t d = fAccum.find_last_of("123468"); + fAccum.replace(d+1, 0, '+'+dur); + return; } - fTied = false; if (fAccum.size() > 1) fAccum += ' '; fAccum += dur+MMAPitchName(n.fPitch, fUseSharps, true)+MMAOctave(n.fPitch)+';'; diff --git a/Sources/VLModel.cpp b/Sources/VLModel.cpp index 7c7fa04..5be912e 100644 --- a/Sources/VLModel.cpp +++ b/Sources/VLModel.cpp @@ -1360,21 +1360,22 @@ void VLSong::SetWord(size_t stanza, size_t measure, VLFraction at, std::string w void VLSong::AddRepeat(size_t beginMeasure, size_t endMeasure, int times) { - for (size_t r=0; r= endMeasure + for (size_t r=0; r= endMeasure ) - if (fRepeats[r].fEndings[0].fEnd == endMeasure) { + if (rp.fEndings[0].fEnd == endMeasure) { // // Exact match, just change times // - size_t mask = ((1< times) - for (size_t e=0; e times) + for (size_t e=0; e= endMeasure + for (size_t r=0; r= endMeasure ) { fRepeats.erase(fRepeats.begin()+r); break; } + } } void VLSong::AddEnding(size_t beginMeasure, size_t endMeasure, size_t volta) { - for (size_t r=0; r= beginMeasure + for (size_t r=0; r= beginMeasure ) { - VLRepeat & repeat = fRepeats[r]; - for (size_t e=1; e(fRepeats[r].fEndings[0].fEnd, endMeasure); - fRepeats[r].fEndings.push_back( + volta &= rp.fEndings[0].fVolta; + rp.fEndings[0].fVolta &= ~volta; + rp.fEndings[0].fEnd = + std::max(rp.fEndings[0].fEnd, endMeasure); + rp.fEndings.push_back( VLRepeat::Ending(beginMeasure, endMeasure, volta)); return; } + } } void VLSong::DelEnding(size_t beginMeasure, size_t endMeasure) { - for (size_t r=0; r beginMeasure + for (size_t r=0; r beginMeasure ) - for (size_t e=1; e 1 && e == fRepeats[r].fEndings.size()-1) - fRepeats[r].fEndings[0].fEnd = fRepeats[r].fEndings[e].fBegin; - fRepeats[r].fEndings.erase(fRepeats[r].fEndings.begin()+e); + for (size_t e=1; e 1 && e == rp.fEndings.size()-1) + rp.fEndings[0].fEnd = rp.fEndings[e].fBegin; + rp.fEndings.erase(rp.fEndings.begin()+e); } + } } bool VLSong::CanBeRepeat(size_t beginMeasure, size_t endMeasure, int * times) { - for (size_t r=0; r 1) { - if (rep.fEndings[1].fBegin == endMeasure) + if (rp.fEndings.size() > 1) { + if (rp.fEndings[1].fBegin == endMeasure) return true; - if (rep.fEndings[1].fEnd == endMeasure) + if (rp.fEndings[1].fEnd == endMeasure) return true; } } @@ -1476,23 +1483,23 @@ bool VLSong::CanBeRepeat(size_t beginMeasure, size_t endMeasure, int * times) // Inclusions and surroundings are OK. Beginnings may match, but // endings must not. // - if (rep.fEndings[0].fBegin >= beginMeasure - && rep.fEndings[0].fEnd < endMeasure + if (rp.fEndings[0].fBegin >= beginMeasure + && rp.fEndings[0].fEnd < endMeasure ) continue; - if (rep.fEndings[0].fBegin <= beginMeasure - && rep.fEndings[0].fEnd > endMeasure + if (rp.fEndings[0].fBegin <= beginMeasure + && rp.fEndings[0].fEnd > endMeasure ) continue; // // Look for overlap and reject // - if (fRepeats[r].fEndings[0].fBegin >= beginMeasure - && fRepeats[r].fEndings[0].fBegin < endMeasure + if (rp.fEndings[0].fBegin >= beginMeasure + && rp.fEndings[0].fBegin < endMeasure ) return false; - if (fRepeats[r].fEndings[0].fEnd > beginMeasure - && fRepeats[r].fEndings[0].fEnd <= endMeasure + if (rp.fEndings[0].fEnd > beginMeasure + && rp.fEndings[0].fEnd <= endMeasure ) return false; } @@ -1507,19 +1514,18 @@ bool VLSong::CanBeRepeat(size_t beginMeasure, size_t endMeasure, int * times) bool VLSong::CanBeEnding(size_t beginMeasure, size_t endMeasure, size_t * volta, size_t * voltaOK) { - for (size_t r=0; r fRepeats[r].fEndings[0].fBegin - && beginMeasure <= fRepeats[r].fEndings[0].fEnd + for (size_t r=0; r rp.fEndings[0].fBegin + && beginMeasure <= rp.fEndings[0].fEnd ) { // // Found right repeat // - VLRepeat & repeat = fRepeats[r]; - // // Append new repeat, or carve out from ending // - if (beginMeasure == repeat.fEndings[0].fEnd) { + if (beginMeasure == rp.fEndings[0].fEnd) { for (size_t r2=0; r2= beginMeasure @@ -1527,89 +1533,96 @@ bool VLSong::CanBeEnding(size_t beginMeasure, size_t endMeasure, ) return false; // Overlap if (volta) - *volta = repeat.fEndings[0].fVolta; + *volta = rp.fEndings[0].fVolta; if (voltaOK) - *voltaOK = repeat.fEndings[0].fVolta; + *voltaOK = rp.fEndings[0].fVolta; return true; - } else if (repeat.fEndings.size() == 1 - && endMeasure >= repeat.fEndings[0].fEnd + } else if (rp.fEndings.size() == 1 + && endMeasure >= rp.fEndings[0].fEnd ) { if (volta) - *volta = repeat.fEndings[0].fVolta; + *volta = rp.fEndings[0].fVolta; if (voltaOK) - *voltaOK = repeat.fEndings[0].fVolta; + *voltaOK = rp.fEndings[0].fVolta; return true; } // // Otherwise must match existing // - for (size_t e=1; e= measure - && fRepeats[r].fEndings.size() > 1 + for (size_t r=0; r= measure + && rp.fEndings.size() > 1 ) { - size_t v = (1<= measure - && fRepeats[r].fEndings.size() > 1 + for (size_t r=0; r= measure + && rp.fEndings.size() > 1 ) { - size_t v = (1<= measure + && rp.fEndings.size() > 1 + ) { + size_t v = (1<= measure + && rp.fEndings.size() > 1 + ) { + for (size_t e=1; e= beginMeasure - && fRepeats[r].fEndings[0].fEnd <= endMeasure + for (size_t r=0; r= beginMeasure + && rp.fEndings[0].fEnd <= endMeasure ) { - VLRepeat repeat = fRepeats[r]; - for (size_t e=0; e