diff --git a/aegisub/src/ass_karaoke.cpp b/aegisub/src/ass_karaoke.cpp index 3439a4441..8a31a1d0b 100644 --- a/aegisub/src/ass_karaoke.cpp +++ b/aegisub/src/ass_karaoke.cpp @@ -53,13 +53,13 @@ wxString AssKaraoke::Syllable::GetText(bool k_tag) const { } -AssKaraoke::AssKaraoke(AssDialogue *line, bool auto_split) +AssKaraoke::AssKaraoke(AssDialogue *line, bool auto_split, bool normalize) : no_announce(false) { - if (line) SetLine(line, auto_split); + if (line) SetLine(line, auto_split, normalize); } -void AssKaraoke::SetLine(AssDialogue *line, bool auto_split) { +void AssKaraoke::SetLine(AssDialogue *line, bool auto_split, bool normalize) { active_line = line; line->ParseASSTags(); @@ -133,26 +133,28 @@ void AssKaraoke::SetLine(AssDialogue *line, bool auto_split) { line->ClearBlocks(); - // Normalize the syllables so that the total duration is equal to the line length - int end_time = active_line->End; - int last_end = syl.start_time + syl.duration; + if (normalize) { + // Normalize the syllables so that the total duration is equal to the line length + int end_time = active_line->End; + int last_end = syl.start_time + syl.duration; - // Total duration is shorter than the line length so just extend the last - // syllable; this has no effect on rendering but is easier to work with - if (last_end < end_time) - syls.back().duration += end_time - last_end; - else if (last_end > end_time) { - // Shrink each syllable proportionately - int start_time = active_line->Start; - double scale_factor = double(end_time - start_time) / (last_end - start_time); + // Total duration is shorter than the line length so just extend the last + // syllable; this has no effect on rendering but is easier to work with + if (last_end < end_time) + syls.back().duration += end_time - last_end; + else if (last_end > end_time) { + // Shrink each syllable proportionately + int start_time = active_line->Start; + double scale_factor = double(end_time - start_time) / (last_end - start_time); - for (size_t i = 0; i < size(); ++i) { - syls[i].start_time = start_time + scale_factor * (syls[i].start_time - start_time); - } + for (size_t i = 0; i < size(); ++i) { + syls[i].start_time = start_time + scale_factor * (syls[i].start_time - start_time); + } - for (int i = size() - 1; i > 0; --i) { - syls[i].duration = end_time - syls[i].start_time; - end_time = syls[i].start_time; + for (int i = size() - 1; i > 0; --i) { + syls[i].duration = end_time - syls[i].start_time; + end_time = syls[i].start_time; + } } } diff --git a/aegisub/src/ass_karaoke.h b/aegisub/src/ass_karaoke.h index b91d02c35..93288c3eb 100644 --- a/aegisub/src/ass_karaoke.h +++ b/aegisub/src/ass_karaoke.h @@ -65,10 +65,11 @@ public: /// Constructor /// @param line Initial line /// @param auto_split Should the line automatically be split on spaces if there are no k tags? - AssKaraoke(AssDialogue *line = 0, bool auto_split = false); + /// @param normalize Should the total duration of the syllables be forced to equal the line duration? + AssKaraoke(AssDialogue *line = 0, bool auto_split = false, bool normalize = true); /// Parse a dialogue line - void SetLine(AssDialogue *line, bool auto_split = false); + void SetLine(AssDialogue *line, bool auto_split = false, bool normalize = true); /// Add a split before character pos in syllable syl_idx void AddSplit(size_t syl_idx, size_t pos); diff --git a/aegisub/src/auto4_lua_assfile.cpp b/aegisub/src/auto4_lua_assfile.cpp index b5f5fa85a..6229b6d75 100644 --- a/aegisub/src/auto4_lua_assfile.cpp +++ b/aegisub/src/auto4_lua_assfile.cpp @@ -642,7 +642,7 @@ namespace Automation4 { set_field(L, "text_stripped", ""); lua_rawseti(L, -2, idx++); - AssKaraoke kara(dia); + AssKaraoke kara(dia, false, false); for (AssKaraoke::iterator it = kara.begin(); it != kara.end(); ++it) { lua_newtable(L); set_field(L, "duration", it->duration);