|
From: Lasse Kärkkäi. <tr...@us...> - 2011-02-28 19:50:35
|
Author: Lasse Kärkkäinen <tronic+ndrm at trn.iki.fi> Date: Mon Feb 28 20:47:30 2011 +0100 Proper handling of sentence breaks for midparse. Allow either lineBreak or sleep notes to be used by all parsers. --- songparser-ini.cc | 4 ++++ songparser.cc | 13 ++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/songparser-ini.cc b/songparser-ini.cc index 81d8fe8..97e6455 100644 --- a/songparser-ini.cc +++ b/songparser-ini.cc @@ -70,18 +70,22 @@ void SongParser::midParse() { while (++track, reader.startTrack()) { VocalTrack vt(""); unsigned timecode = 0; + bool newSentence = true; std::string trackName, lyric; for (Event ev; reader.parseEvent(ev); ) { + ev.print(); timecode += ev.timecode; if (ev.type == Event::NOTE_ON && ev.arg2 == 0) ev.type = Event::NOTE_OFF; // Note on with velocity 0 actually means off. // Process any interesting events if (ev.type == Event::NOTE_ON) { + if (ev.arg1 == 105) newSentence = true; // New sentence begins at next note if (ev.arg1 >= 100) continue; // Skip control signals vt.notes.push_back(Note(strConv(lyric))); lyric.clear(); Note& n = vt.notes.back(); n.begin = n.end = tsTime(timecode); n.note = ev.arg1; + n.lineBreak = newSentence; newSentence = false; vt.noteMin = std::min(vt.noteMin, n.note); vt.noteMax = std::max(vt.noteMax, n.note); continue; diff --git a/songparser.cc b/songparser.cc index 97e633c..a01e013 100644 --- a/songparser.cc +++ b/songparser.cc @@ -140,12 +140,15 @@ void SongParser::finalize() { if (vocal.notes.empty()) continue; // Set begin/end times vocal.beginTime = vocal.notes.front().begin, vocal.endTime = vocal.notes.back().end; - // Setup sentence start indicators + // Setup sentence start indicators and remove sleep notes bool sentenceStart = true; - for (Notes::iterator it = vocal.notes.begin(); it != vocal.notes.end(); ++it) { - it->lineBreak = sentenceStart; - if (it->type == Note::SLEEP) sentenceStart = true; - else sentenceStart = false; + for (Notes::iterator it = vocal.notes.begin(); it != vocal.notes.end();) { + if (sentenceStart) it->lineBreak = true; + sentenceStart = false; + if (it->type == Note::SLEEP) { + sentenceStart = true; + it = vocal.notes.erase(it); + } else ++it; } // Note normalization const int limLow = 1, limHigh = 47; |