Much more convenient lyrics editing

This commit is contained in:
Matthias Neeracher 2007-04-13 04:26:35 +00:00
parent 54ae06ae81
commit 7c5f28ede9
4 changed files with 70 additions and 21 deletions

View File

@ -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,23 +1347,52 @@ 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()<stanza)
note->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;
if (type == '-')
kind |= VLSyllable::kHasPrev;
}
now += note->fDuration;
@ -1371,6 +1400,10 @@ void VLSong::SetWord(size_t stanza, size_t measure, VLFraction at, std::string w
}
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)

View File

@ -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,

View File

@ -14,6 +14,8 @@
size_t fStanza;
size_t fMeasure;
VLFract fAt;
size_t fNextMeas;
VLFract fNextAt;
}
- (VLLyricsEditable *)initWithView:(VLSheetView *)view

View File

@ -26,8 +26,10 @@
fView = view;
fSong = song;
fStanza = stanza;
fMeasure= measure;
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,6 +60,12 @@
- (void) moveToNext
{
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;
@ -65,6 +73,9 @@
fSong->FindWord(fStanza, fMeasure, 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