Advertisement
ivandrofly

SubtitleEdit: RecalculateDisplayTime (Optimized)

Feb 22nd, 2019
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.30 KB | None | 0 0
  1.  public void RecalculateDisplayTime(double maxCharactersPerSecond, int index, double optimalCharactersPerSeconds)
  2.         {
  3.             Paragraph p = GetParagraphOrDefault(index);
  4.             if (p == null)
  5.             {
  6.                 return;
  7.             }
  8.  
  9.             double displayChars = p.Text.CountCharacters(Configuration.Settings.General.CharactersPerSecondsIgnoreWhiteSpace);
  10.             double optimalCharsPerSec = Math.Min(displayChars / Utilities.GetOptimalDisplayMilliseconds(p.Text, optimalCharactersPerSeconds) / TimeCode.BaseUnit, maxCharactersPerSecond);
  11.             double optimalDuratoinInSec = displayChars / optimalCharsPerSec;
  12.  
  13.             p.EndTime.TotalMilliseconds = p.StartTime.TotalMilliseconds + optimalDuratoinInSec * TimeCode.BaseUnit;
  14.  
  15.             Paragraph next = GetParagraphOrDefault(index + 1);
  16.             // p is last paragraph or next is null
  17.             if (next == null)
  18.             {
  19.                 return;
  20.             }
  21.  
  22.             double optimalEndTime = next.StartTime.TotalMilliseconds - Configuration.Settings.General.MinimumMillisecondsBetweenLines;
  23.             if (optimalEndTime < p.EndTime.TotalMilliseconds)
  24.             {
  25.                 p.EndTime.TotalMilliseconds = Math.Max(p.StartTime.TotalMilliseconds + 1, optimalEndTime);
  26.             }
  27.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement