From dca02bd76dff880e4c63f2596ccfdf77ef86f84d Mon Sep 17 00:00:00 2001 From: Rodrigo Braz Monteiro Date: Sat, 19 Jan 2008 00:48:47 +0000 Subject: [PATCH] Fixed auto-splitting of karaoke (#597) Originally committed to SVN as r1772. --- aegisub/audio_karaoke.cpp | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/aegisub/audio_karaoke.cpp b/aegisub/audio_karaoke.cpp index 4b2c22a3f..886c90262 100644 --- a/aegisub/audio_karaoke.cpp +++ b/aegisub/audio_karaoke.cpp @@ -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; + words.Add(tkz.GetNextToken()); + } + + // Process words + for (size_t i=0;i timelen) { - curlen -= acumLen - timelen; - acumLen = timelen; + + // Don't let it accumulate over total length + if (acumLen > timeLen) { + curlen -= acumLen - timeLen; + acumLen = timeLen; } - newText += wxString::Format(_T("{\\k%i}"),curlen) + token; + + // 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;