Fixed auto-splitting of karaoke (#597)

Originally committed to SVN as r1772.
This commit is contained in:
Rodrigo Braz Monteiro 2008-01-19 00:48:47 +00:00
parent 52d47c32e2
commit dca02bd76d
1 changed files with 22 additions and 8 deletions

View File

@ -185,7 +185,7 @@ void AudioKaraoke::AutoSplit() {
wxLogDebug(_T("AudioKaraoke::AutoSplit"));
// Get lengths
int timelen = (diag->End.GetMS() - diag->Start.GetMS())/10;
int timeLen = (diag->End.GetMS() - diag->Start.GetMS())/10;
int letterlen = diag->Text.Length();
int round = letterlen / 2;
int curlen;
@ -194,20 +194,34 @@ void AudioKaraoke::AutoSplit() {
// Parse words
wxStringTokenizer tkz(diag->Text,_T(" "),wxTOKEN_RET_DELIMS);
wxArrayString words;
while (tkz.HasMoreTokens()) {
wxString token = tkz.GetNextToken();
curlen = (token.Length() * timelen + round) / letterlen;
acumLen += curlen;
if (acumLen > timelen) {
curlen -= acumLen - timelen;
acumLen = timelen;
words.Add(tkz.GetNextToken());
}
newText += wxString::Format(_T("{\\k%i}"),curlen) + token;
// Process words
for (size_t i=0;i<words.Count();i++) {
curlen = (words[i].Length() * timeLen + round) / letterlen;
acumLen += curlen;
// Don't let it accumulate over total length
if (acumLen > timeLen) {
curlen -= acumLen - timeLen;
acumLen = timeLen;
}
// Ensure that it accumulates all of it
if (i == words.Count()-1 && acumLen < timeLen) {
curlen += timeLen - acumLen;
acumLen = timeLen;
}
newText += wxString::Format(_T("{\\k%i}"),curlen) + words[i];
}
// Workaround for bug #503
// Make the line one blank syllable if it's completely blank
if (newText == _T("")) newText = wxString::Format(_T("{\\k%d}"), timelen);
if (newText == _T("")) newText = wxString::Format(_T("{\\k%d}"), timeLen);
// Load
must_rebuild = true;