Merge pull request #14563 from alexpavlov96/gp5_freetext_lyrics

gp-import: fixed lyrics import of gp5
This commit is contained in:
Alexander Pavlov 2022-12-12 16:47:47 +02:00 committed by GitHub
commit 1813d3f2c9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 67 additions and 18 deletions

View file

@ -674,33 +674,86 @@ void GuitarPro5::readMeasures(int /*startingTempo*/)
}
}
}
} else {
} else if (gpLyrics.lyricTrack != 0) {
int counter = 0;
// int index = 0;
//TODO-ws ??? gpLyrics.lyricTrack -= 1;
auto mes = score->firstMeasure();
auto beg = mes->first();
int index = 0;
gpLyrics.lyricTrack -= 1;
Measure* mes = score->firstMeasure();
if (!mes) {
return;
}
Segment* beg = mes->first();
do {
if (beg->isChordRestType() && beg->cr(gpLyrics.lyricTrack)) {
if (beg->segmentType() == SegmentType::ChordRest && beg->cr(gpLyrics.lyricTrack)) {
ChordRest* cr = beg->cr(gpLyrics.lyricTrack);
assert(cr);
++counter;
if (!cr->isChord()) {
if (cr->type() != ElementType::CHORD) {
continue;
}
bool is_tied = false;
bool isTied = false;
Chord* chord = toChord(cr);
for (auto n : chord->notes()) {
if (n->tiedNotes().size() > 1 && n->tiedNotes()[0] != n) {
is_tied = true;
for (Note* n : chord->notes()) {
const auto& tiedNotes = n->tiedNotes();
if (tiedNotes.size() > 1 && tiedNotes.front() != n) {
isTied = true;
break;
}
}
if (is_tied) {
if (isTied) {
continue;
}
if (counter >= gpLyrics.fromBeat) {
if (gpLyrics.lyricPos.size() == index) {
gpLyrics.lyricPos.push_back(0);
}
String& lyricsInIndex = gpLyrics.lyrics[index];
if (lyricsInIndex[0] != u'-') {
Lyrics* lyr = mu::engraving::Factory::createLyrics(cr);
String text;
size_t pos = lyricsInIndex.indexOf(u'-', gpLyrics.lyricPos[index]);
size_t pos2 = lyricsInIndex.indexOf(u'\n', gpLyrics.lyricPos[index]);
if (pos2 < pos) {
pos = pos2;
}
if (pos != std::string::npos && (pos + 1 < lyricsInIndex.size())) {
const char16_t* c = &lyricsInIndex[pos + 1];
if (*c == 0) {
pos = std::string::npos;
text = lyricsInIndex;
} else {
text = lyricsInIndex.mid(gpLyrics.lyricPos[index], pos + 1 - gpLyrics.lyricPos[index]);
gpLyrics.lyricPos[index] = pos + 1;
}
} else {
text = lyricsInIndex.mid(gpLyrics.lyricPos[index]);
}
if (pos == std::string::npos) {
++index;
}
lyr->setPlainText(text);
cr->add(lyr);
if (index >= gpLyrics.lyrics.size()) {
break;
}
} else if (lyricsInIndex.size() >= 2) {
lyricsInIndex = lyricsInIndex.mid(1);
}
}
}
} while ((beg = beg->next()) || ((mes = toMeasure(mes->next())) && (beg = mes->first())));
} while ((beg = beg->next())
|| (mes->next() && mes->next()->type() == ElementType::MEASURE && (mes = toMeasure(mes->next())) && (beg = mes->first())));
}
}

View file

@ -789,11 +789,6 @@ void GuitarPro::readLyrics()
lyrics.replace(u'\r', u' ');
auto sl = lyrics.split(u' ', KeepEmptyParts);
for (auto& str : sl) {
/*while (str[0] == '-')
{
gpLyrics.lyrics.push_back("aa");
str = str.substr(1);
}*/
gpLyrics.lyrics.push_back(str);
}

View file

@ -91,6 +91,7 @@ struct GPFermata {
struct GPLyrics {
StringList lyrics;
std::vector<Segment*> segments;
std::vector<size_t> lyricPos;
int fromBeat;
int beatCounter;
int lyricTrack;