Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void AdjustDisplayTimeUsingMilliseconds(int idx, double ms, List<double> shotChanges = null, bool enforceDurationLimits = true)
- {
- var p = Paragraphs[idx];
- var nextStartTimeInMs = GetNextStartTimeInMs(idx);
- var newEndTimeInMs = p.EndTime.TotalMilliseconds + ms;
- if (enforceDurationLimits)
- {
- newEndTimeInMs = FixShortDuration(p, newEndTimeInMs);
- }
- // handle overlap with next
- newEndTimeInMs = HandleOverlapWithNext(newEndTimeInMs, nextStartTimeInMs);
- // handle shot change if supplied -- keep earliest time
- if (shotChanges != null)
- {
- newEndTimeInMs = HandleShotChange(shotChanges, newEndTimeInMs, p);
- }
- // max duration
- if (enforceDurationLimits)
- {
- newEndTimeInMs = HandleMaximumDuration(p, newEndTimeInMs);
- }
- // do not adjust wrong way
- if (!(ms > 0 && newEndTimeInMs < p.EndTime.TotalMilliseconds) && !(ms < 0 && newEndTimeInMs > p.EndTime.TotalMilliseconds))
- {
- p.EndTime.TotalMilliseconds = newEndTimeInMs;
- }
- }
- private double GetNextStartTimeInMs(int idx) => (idx + 1) < Paragraphs.Count ? Paragraphs[idx + 1].StartTime.TotalMilliseconds : double.MaxValue;
- private double FixShortDuration(Paragraph p, double endTime)
- {
- var minDur = Math.Max(Configuration.Settings.General.SubtitleMinimumDisplayMilliseconds, 100);
- return Math.Max(p.StartTime.TotalMilliseconds + minDur, endTime);
- }
- private double HandleOverlapWithNext(double endTime, double nextStartTime)
- {
- return Math.Min(nextStartTime - Configuration.Settings.General.MinimumMillisecondsBetweenLines, endTime);
- }
- private double HandleShotChange(List<double> shotChanges, double endTime, Paragraph p)
- {
- return Math.Min(endTime, ShotChangeHelper.GetNextShotChangeMinusGapInMs(shotChanges, p.EndTime) ?? double.MaxValue);
- }
- private double HandleMaximumDuration(Paragraph p, double endTime)
- {
- var duration = endTime - p.StartTime.TotalMilliseconds;
- return duration > Configuration.Settings.General.SubtitleMaximumDisplayMilliseconds ? p.StartTime.TotalMilliseconds + Configuration.Settings.General.SubtitleMaximumDisplayMilliseconds : endTime;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement