From 8dececc3cbf221f6c14170c70e865a16dae77ae2 Mon Sep 17 00:00:00 2001 From: wangqr Date: Sat, 4 Jul 2020 05:22:14 -0400 Subject: [PATCH] Use millisecond in Make Adjacent step in Timing Post-Processor Fix wangqr/Aegisub#57 --- libaegisub/include/libaegisub/ass/time.h | 3 +++ src/dialog_timing_processor.cpp | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/libaegisub/include/libaegisub/ass/time.h b/libaegisub/include/libaegisub/ass/time.h index 622052cea..fc04e254f 100644 --- a/libaegisub/include/libaegisub/ass/time.h +++ b/libaegisub/include/libaegisub/ass/time.h @@ -31,6 +31,9 @@ public: // Always round up for 5ms because the range is [start, stop) operator int() const { return (time + 5) - (time + 5) % 10; } + /// Get millisecond, without centisecond round + int GetMillisecond() const noexcept { return time; } + /// Return the time as a string /// @param ms Use milliseconds precision, for non-ASS formats std::string GetAssFormatted(bool ms=false) const; diff --git a/src/dialog_timing_processor.cpp b/src/dialog_timing_processor.cpp index 78fe1d878..6f551e2a2 100644 --- a/src/dialog_timing_processor.cpp +++ b/src/dialog_timing_processor.cpp @@ -407,9 +407,12 @@ void DialogTimingProcessor::Process() { AssDialogue *prev = sorted[i - 1]; AssDialogue *cur = sorted[i]; - int dist = cur->Start - prev->End; + // Raw millisecond values are used in this step instead of the typical centisecond. + // In this step, we need to distinguish between gap and overlap, as they have different thresholds. + // A small gap / overlap less than 1 centisecond may not be distinguishable using rounded centisecond values. + int dist = cur->Start.GetMillisecond() - prev->End.GetMillisecond(); if ((dist < 0 && -dist <= adjOverlap) || (dist > 0 && dist <= adjGap)) { - int setPos = prev->End + int(dist * bias); + int setPos = prev->End.GetMillisecond() + int(dist * bias + 0.5); cur->Start = setPos; prev->End = setPos; }