Don't normalize syllable durations when parsing karaoke for automation

Originally committed to SVN as r6478.
This commit is contained in:
Thomas Goyne 2012-02-16 05:21:00 +00:00
parent 6339df3521
commit fc64bcaa36
3 changed files with 26 additions and 23 deletions

View file

@ -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) : 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; active_line = line;
line->ParseASSTags(); line->ParseASSTags();
@ -133,26 +133,28 @@ void AssKaraoke::SetLine(AssDialogue *line, bool auto_split) {
line->ClearBlocks(); line->ClearBlocks();
// Normalize the syllables so that the total duration is equal to the line length if (normalize) {
int end_time = active_line->End; // Normalize the syllables so that the total duration is equal to the line length
int last_end = syl.start_time + syl.duration; 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 // 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 // syllable; this has no effect on rendering but is easier to work with
if (last_end < end_time) if (last_end < end_time)
syls.back().duration += end_time - last_end; syls.back().duration += end_time - last_end;
else if (last_end > end_time) { else if (last_end > end_time) {
// Shrink each syllable proportionately // Shrink each syllable proportionately
int start_time = active_line->Start; int start_time = active_line->Start;
double scale_factor = double(end_time - start_time) / (last_end - start_time); double scale_factor = double(end_time - start_time) / (last_end - start_time);
for (size_t i = 0; i < size(); ++i) { for (size_t i = 0; i < size(); ++i) {
syls[i].start_time = start_time + scale_factor * (syls[i].start_time - start_time); syls[i].start_time = start_time + scale_factor * (syls[i].start_time - start_time);
} }
for (int i = size() - 1; i > 0; --i) { for (int i = size() - 1; i > 0; --i) {
syls[i].duration = end_time - syls[i].start_time; syls[i].duration = end_time - syls[i].start_time;
end_time = syls[i].start_time; end_time = syls[i].start_time;
}
} }
} }

View file

@ -65,10 +65,11 @@ public:
/// Constructor /// Constructor
/// @param line Initial line /// @param line Initial line
/// @param auto_split Should the line automatically be split on spaces if there are no k tags? /// @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 /// 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 /// Add a split before character pos in syllable syl_idx
void AddSplit(size_t syl_idx, size_t pos); void AddSplit(size_t syl_idx, size_t pos);

View file

@ -642,7 +642,7 @@ namespace Automation4 {
set_field(L, "text_stripped", ""); set_field(L, "text_stripped", "");
lua_rawseti(L, -2, idx++); lua_rawseti(L, -2, idx++);
AssKaraoke kara(dia); AssKaraoke kara(dia, false, false);
for (AssKaraoke::iterator it = kara.begin(); it != kara.end(); ++it) { for (AssKaraoke::iterator it = kara.begin(); it != kara.end(); ++it) {
lua_newtable(L); lua_newtable(L);
set_field(L, "duration", it->duration); set_field(L, "duration", it->duration);