From 7c5f28ede93350298ce8948783292d5f8a3c6f23 Mon Sep 17 00:00:00 2001 From: Matthias Neeracher Date: Fri, 13 Apr 2007 04:26:35 +0000 Subject: [PATCH] Much more convenient lyrics editing --- Sources/VLModel.cpp | 49 ++++++++++++++++++++++++++++++------ Sources/VLModel.h | 3 ++- Sources/VLSheetViewLyrics.h | 2 ++ Sources/VLSheetViewLyrics.mm | 37 ++++++++++++++++++--------- 4 files changed, 70 insertions(+), 21 deletions(-) diff --git a/Sources/VLModel.cpp b/Sources/VLModel.cpp index 31da39f..d0768ed 100644 --- a/Sources/VLModel.cpp +++ b/Sources/VLModel.cpp @@ -1326,7 +1326,7 @@ std::string VLSong::GetWord(size_t stanza, size_t measure, VLFraction at) return word; } -void VLSong::SetWord(size_t stanza, size_t measure, VLFraction at, std::string word) +void VLSong::SetWord(size_t stanza, size_t measure, VLFraction at, std::string word, size_t * nextMeas, VLFract * nextAt) { uint8_t kind = 0; bool cleanup = false; @@ -1347,30 +1347,63 @@ void VLSong::SetWord(size_t stanza, size_t measure, VLFraction at, std::string w if (note->fLyrics.size() >= stanza) note->fLyrics[stanza-1].fKind &= ~VLSyllable::kHasPrev; + if (nextMeas) + *nextMeas = measure; + if (nextAt) + *nextAt = now; + return; } if (note->fLyrics.size()fLyrics.resize(stanza); - size_t root = word.find('-'); + size_t sep = word.find_first_of(" \t-"); + size_t esp; std::string syll; - if (root == std::string::npos) { - syll = word; + char type= 0; + if (sep == std::string::npos) { + esp = sep; + syll= word; + } else { + esp = word.find_first_not_of(" \t-", sep); + syll= word.substr(0, sep); + if (esp != std::string::npos) { + size_t tpos = word.substr(sep, esp-sep).find('-'); + type = (tpos != std::string::npos) ? '-' : ' '; + word.erase(0, esp); + } + } + switch (type) { + default: + // + // Last syllable in text + // kind &= ~VLSyllable::kHasNext; cleanup = true; - } else { - syll = word.substr(0, root); - word.erase(0, root+1); + break; + case ' ': + // + // Last syllable in word + // + kind &= ~VLSyllable::kHasNext; + break; + case '-': kind |= VLSyllable::kHasNext; + break; } note->fLyrics[stanza-1].fText = syll; note->fLyrics[stanza-1].fKind = kind; - kind |= VLSyllable::kHasPrev; + if (type == '-') + kind |= VLSyllable::kHasPrev; } now += note->fDuration; ++note; } at = 0; } while (++measure < fMeasures.size()); + if (nextMeas) + *nextMeas = 0; + if (nextAt) + *nextAt = VLFraction(0); } void VLSong::AddRepeat(size_t beginMeasure, size_t endMeasure, int times) diff --git a/Sources/VLModel.h b/Sources/VLModel.h index a9833b1..7cf626c 100644 --- a/Sources/VLModel.h +++ b/Sources/VLModel.h @@ -333,7 +333,8 @@ struct VLSong { bool PrevWord(size_t stanza, size_t & measure, VLFraction & at); bool NextWord(size_t stanza, size_t & measure, VLFraction & at); std::string GetWord(size_t stanza, size_t measure, VLFraction at); - void SetWord(size_t stanza, size_t measure, VLFraction at, std::string word); + void SetWord(size_t stanza, size_t measure, VLFraction at, std::string word, + size_t * nextMeas=0, VLFract * nextAt=0); enum { kInsert, diff --git a/Sources/VLSheetViewLyrics.h b/Sources/VLSheetViewLyrics.h index b807cc8..d583297 100644 --- a/Sources/VLSheetViewLyrics.h +++ b/Sources/VLSheetViewLyrics.h @@ -14,6 +14,8 @@ size_t fStanza; size_t fMeasure; VLFract fAt; + size_t fNextMeas; + VLFract fNextAt; } - (VLLyricsEditable *)initWithView:(VLSheetView *)view diff --git a/Sources/VLSheetViewLyrics.mm b/Sources/VLSheetViewLyrics.mm index 373de77..38b7efd 100644 --- a/Sources/VLSheetViewLyrics.mm +++ b/Sources/VLSheetViewLyrics.mm @@ -22,12 +22,14 @@ measure:(int)measure at:(VLFract)at { - self = [super init]; - fView = view; - fSong = song; - fStanza = stanza; - fMeasure= measure; - fAt = at; + self = [super init]; + fView = view; + fSong = song; + fStanza = stanza; + fMeasure = measure; + fAt = at; + fNextMeas = fMeasure; + fNextAt = fAt; VLFraction At = fAt; fSong->FindWord(fStanza, fMeasure, At); @@ -47,7 +49,7 @@ - (void) setStringValue:(NSString *)val { [[fView document] willChangeSong]; - fSong->SetWord(fStanza, fMeasure, fAt, [val UTF8String]); + fSong->SetWord(fStanza, fMeasure, fAt, [val UTF8String], &fNextMeas, &fNextAt); [[fView document] didChangeSong]; } @@ -58,13 +60,22 @@ - (void) moveToNext { - VLFraction at = fAt; - if (!fSong->NextWord(fStanza, fMeasure, at)) { - fMeasure = 0; - at = 0; + if (fNextMeas != fMeasure || fNextAt != fAt) { + fMeasure = fNextMeas; + VLFraction at = fNextAt; fSong->FindWord(fStanza, fMeasure, at); + fAt = at; + } else { + VLFraction at = fAt; + if (!fSong->NextWord(fStanza, fMeasure, at)) { + fMeasure = 0; + at = 0; + fSong->FindWord(fStanza, fMeasure, at); + } + fAt = at; } - fAt = at; + fNextMeas = fMeasure; + fNextAt = fAt; } - (void) moveToPrev @@ -76,6 +87,8 @@ fSong->PrevWord(fStanza, fMeasure, at); } fAt = at; + fNextMeas = fMeasure; + fNextAt = fAt; } - (void) highlightCursor