[TimeCode] - Add default constructor.

The new default constructor will return new instance of TimeCode with all properties zeroed-out.
This commit is contained in:
Ivandro Ismael 2016-10-29 15:56:39 +01:00
parent 1af652aba9
commit c2c715c288
35 changed files with 54 additions and 50 deletions

View File

@ -94,8 +94,8 @@ namespace Nikse.SubtitleEdit.Core
public Paragraph(int startFrame, int endFrame, string text)
{
StartTime = new TimeCode(0, 0, 0, 0);
EndTime = new TimeCode(0, 0, 0, 0);
StartTime = new TimeCode();
EndTime = new TimeCode();
StartFrame = startFrame;
EndFrame = endFrame;
Text = text;

View File

@ -121,7 +121,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
return new TimeCode(hours, minutes, seconds, FramesToMillisecondsMax999(frames));
}
}
return new TimeCode(0);
return new TimeCode();
}
public TimeCode GetStartTime()
@ -133,7 +133,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
{
string trimmed = EraseTiming.Trim();
if (trimmed == "F" || trimmed == "0" || trimmed.Length == 0)
return new TimeCode(0);
return new TimeCode();
return GetTime(EraseTiming, SpecifiedTimingUnit);
}

View File

@ -127,7 +127,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
catch (Exception exception)
{
System.Diagnostics.Debug.WriteLine(exception.Message);
return new TimeCode(0, 0, 0, 0);
return new TimeCode();
}
}

View File

@ -73,8 +73,8 @@ LICENSE=
_errorCount = 0;
bool textOn = false;
string text = string.Empty;
TimeCode start = new TimeCode(0);
TimeCode end = new TimeCode(0);
TimeCode start = new TimeCode();
TimeCode end = new TimeCode();
foreach (string line in lines)
{
if (textOn)
@ -89,8 +89,8 @@ LICENSE=
subtitle.Paragraphs.Add(p);
text = string.Empty;
start = new TimeCode(0);
end = new TimeCode(0);
start = new TimeCode();
end = new TimeCode();
textOn = false;
}
else

View File

@ -141,7 +141,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
}
catch
{
return new TimeCode(0, 0, 0, 0);
return new TimeCode();
}
}

View File

@ -136,7 +136,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
private TimeCode DecodeTimeCode(string[] parts)
{
var tc = new TimeCode(0, 0, 0, 0);
var tc = new TimeCode();
try
{
int hour = int.Parse(parts[0]);

View File

@ -149,7 +149,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
return TimeCode.FromSeconds(float.Parse(arr[0]));
}
}
return new TimeCode(0, 0, 0, 0);
return new TimeCode();
}
}

View File

@ -183,7 +183,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
return TimeCode.FromSeconds(float.Parse(arr[0]));
}
}
return new TimeCode(0, 0, 0, 0);
return new TimeCode();
}
}

View File

@ -203,7 +203,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
return TimeCode.FromSeconds(float.Parse(arr[0]));
}
}
return new TimeCode(0, 0, 0, 0);
return new TimeCode();
}
}

View File

@ -189,7 +189,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
return TimeCode.FromSeconds(float.Parse(arr[0]));
}
}
return new TimeCode(0, 0, 0, 0);
return new TimeCode();
}
}

View File

@ -191,7 +191,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
return TimeCode.FromSeconds(float.Parse(arr[0]));
}
}
return new TimeCode(0, 0, 0, 0);
return new TimeCode();
}
}

View File

@ -155,7 +155,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
return TimeCode.FromSeconds(float.Parse(arr[0]));
}
}
return new TimeCode(0, 0, 0, 0);
return new TimeCode();
}
}

View File

@ -87,9 +87,9 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
subtitle.Paragraphs.Add(p);
string[] arr = s.Split('\t');
if (arr.Length > 2)
p = new Paragraph(DecodeTimeCodeFrames(arr[1], splitChars), new TimeCode(0, 0, 0, 0), arr[2].Trim());
p = new Paragraph(DecodeTimeCodeFrames(arr[1], splitChars), new TimeCode(), arr[2].Trim());
else
p = new Paragraph(DecodeTimeCodeFrames(arr[1], splitChars), new TimeCode(0, 0, 0, 0), string.Empty);
p = new Paragraph(DecodeTimeCodeFrames(arr[1], splitChars), new TimeCode(), string.Empty);
}
catch
{

View File

@ -101,7 +101,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
int milliseconds = int.Parse(parts[2]) * 10;
string text = line.Remove(0, 9).Trim().TrimStart(']').Trim();
var start = new TimeCode(0, minutes, seconds, milliseconds);
var p = new Paragraph(start, new TimeCode(0, 0, 0, 0), text);
var p = new Paragraph(start, new TimeCode(), text);
subtitle.Paragraphs.Add(p);
}
catch
@ -173,7 +173,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
int milliseconds = int.Parse(parts[2]) * 10;
string text = GetTextAfterTimeCodes(p.Text);
var start = new TimeCode(0, minutes, seconds, milliseconds);
var newParagraph = new Paragraph(start, new TimeCode(0, 0, 0, 0), text);
var newParagraph = new Paragraph(start, new TimeCode(), text);
subtitle.Paragraphs.Add(newParagraph);
}
catch

View File

@ -1796,7 +1796,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
return new TimeCode(hours, minutes, seconds, FramesToMillisecondsMax999(frames));
}
return new TimeCode(0, 0, 0, 0);
return new TimeCode();
}
}

View File

@ -417,7 +417,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
protected TimeCode DecodeTimeCodeFramesTwoParts(string[] parts)
{
if (parts == null)
return new TimeCode(0);
return new TimeCode();
if (parts.Length != 2)
throw new InvalidOperationException();
// 00:00
@ -427,7 +427,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
protected TimeCode DecodeTimeCodeFramesThreeParts(string[] parts)
{
if (parts == null)
return new TimeCode(0);
return new TimeCode();
if (parts.Length != 3)
throw new InvalidOperationException();
// 00:00:00
@ -437,7 +437,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
protected TimeCode DecodeTimeCodeFramesFourParts(string[] parts)
{
if (parts == null)
return new TimeCode(0);
return new TimeCode();
if (parts.Length != 4)
throw new InvalidOperationException();
// 00:00:00:00

View File

@ -140,7 +140,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
private static TimeCode DecodeTimeCode(XmlNode node)
{
var tc = new TimeCode(0, 0, 0, 0);
var tc = new TimeCode();
if (node != null)
{
string[] arr = node.InnerText.Split(new[] { ':', '.', ',', ';' }, StringSplitOptions.RemoveEmptyEntries);

View File

@ -93,7 +93,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
{
if (p != null)
subtitle.Paragraphs.Add(p);
p = new Paragraph(DecodeTimeCodeFrames(s.Substring(5, 11), SplitCharColon), new TimeCode(0, 0, 0, 0), s.Remove(0, 37).Trim());
p = new Paragraph(DecodeTimeCodeFrames(s.Substring(5, 11), SplitCharColon), new TimeCode(), s.Remove(0, 37).Trim());
}
catch
{
@ -107,7 +107,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
{
if (p != null)
subtitle.Paragraphs.Add(p);
p = new Paragraph(DecodeTimeCodeFrames(s.Substring(5, 11), SplitCharColon), new TimeCode(0, 0, 0, 0), string.Empty);
p = new Paragraph(DecodeTimeCodeFrames(s.Substring(5, 11), SplitCharColon), new TimeCode(), string.Empty);
}
catch
{

View File

@ -87,9 +87,9 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
subtitle.Paragraphs.Add(p);
string[] arr = s.Split('\t');
if (arr.Length > 2)
p = new Paragraph(DecodeTimeCodeFrames(arr[1], splitChar), new TimeCode(0, 0, 0, 0), arr[2].Trim());
p = new Paragraph(DecodeTimeCodeFrames(arr[1], splitChar), new TimeCode(), arr[2].Trim());
else
p = new Paragraph(DecodeTimeCodeFrames(arr[1], splitChar), new TimeCode(0, 0, 0, 0), string.Empty);
p = new Paragraph(DecodeTimeCodeFrames(arr[1], splitChar), new TimeCode(), string.Empty);
}
catch
{

View File

@ -79,7 +79,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
{
string text = s.Remove(0, 10).Trim();
text = text.Replace(" ", Environment.NewLine);
p = new Paragraph(DecodeTimeCode(startParts), new TimeCode(0, 0, 0, 0), text);
p = new Paragraph(DecodeTimeCode(startParts), new TimeCode(), text);
subtitle.Paragraphs.Add(p);
}
catch (Exception exception)

View File

@ -100,7 +100,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
{
try
{
p = new Paragraph(DecodeTimeCodeFramesFourParts(startParts), new TimeCode(0, 0, 0, 0), text);
p = new Paragraph(DecodeTimeCodeFramesFourParts(startParts), new TimeCode(), text);
subtitle.Paragraphs.Add(p);
}
catch (Exception exception)

View File

@ -121,7 +121,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
TimeCode start = DecodeTimeCodeFrames(timeParts[0].Substring(0, 11), splitChars);
if (p != null && Math.Abs(p.EndTime.TotalMilliseconds) < 0.001)
p.EndTime.TotalMilliseconds = start.TotalMilliseconds - Configuration.Settings.General.MinimumMillisecondsBetweenLines;
TimeCode end = new TimeCode(0, 0, 0, 0);
TimeCode end = new TimeCode();
p = MakeTextParagraph(text, p, start, end);
subtitle.Paragraphs.Add(p);
text = new StringBuilder();

View File

@ -146,8 +146,8 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
<Type>0</Type>
</ActionOut>";
var xml = new XmlDocument();
var firstTimeCode = new TimeCode(0);
var lastTimeCode = new TimeCode(0);
var firstTimeCode = new TimeCode();
var lastTimeCode = new TimeCode();
if (subtitle.Paragraphs.Count > 0)
{
firstTimeCode = subtitle.Paragraphs[0].StartTime;

View File

@ -105,7 +105,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
</ContentBlock>";
var xml = new XmlDocument();
var lastTimeCode = new TimeCode(0);
var lastTimeCode = new TimeCode();
if (subtitle.Paragraphs.Count > 0)
{
lastTimeCode = subtitle.Paragraphs[subtitle.Paragraphs.Count - 1].StartTime;

View File

@ -60,7 +60,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
{
if (RegexTimeCodes.IsMatch(line))
{
p = new Paragraph(DecodeTimeCode(line), new TimeCode(0, 0, 0, 0), string.Empty);
p = new Paragraph(DecodeTimeCode(line), new TimeCode(), string.Empty);
subtitle.Paragraphs.Add(p);
}
else if (string.IsNullOrWhiteSpace(line))

View File

@ -63,7 +63,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
{
int splitter = line.IndexOf(':') + 3;
string text = line.Remove(0, splitter);
var p = new Paragraph(DecodeTimeCode(line.Substring(0, splitter)), new TimeCode(0, 0, 0, 0), text);
var p = new Paragraph(DecodeTimeCode(line.Substring(0, splitter)), new TimeCode(), text);
subtitle.Paragraphs.Add(p);
text = text.Trim().Trim(trimChars).Trim();
if (text.Length > 0 && char.IsDigit(text[0]))

View File

@ -58,6 +58,10 @@ namespace Nikse.SubtitleEdit.Core
return 0;
}
public TimeCode() : this(0)
{
}
public TimeCode(TimeSpan timeSpan)
{
_totalMilliseconds = timeSpan.TotalMilliseconds;

View File

@ -705,7 +705,7 @@ namespace Nikse.SubtitleEdit.Core
}
catch
{
return new TimeCode(0, 0, 0, 0);
return new TimeCode();
}
}

View File

@ -2158,7 +2158,7 @@ namespace Nikse.SubtitleEdit.Core
if (int.TryParse(arr[0], out hour) && int.TryParse(arr[1], out min) &&
int.TryParse(arr[2], out sec) && int.TryParse(arr[3], out ms))
{
comments.Paragraphs.Add(new Paragraph(new TimeCode(hour, min, sec, ms * 10), new TimeCode(0, 0, 0, 0), line));
comments.Paragraphs.Add(new Paragraph(new TimeCode(hour, min, sec, ms * 10), new TimeCode(), line));
}
}
}

View File

@ -203,7 +203,7 @@ namespace Nikse.SubtitleEdit.Forms
}
catch (Exception)
{
timeUpDownStartTime.TimeCode = new TimeCode(0);
timeUpDownStartTime.TimeCode = new TimeCode();
}
int number;

View File

@ -1536,7 +1536,7 @@ $DROP=[DROPVALUE]" + Environment.NewLine + Environment.NewLine +
fullSize.Save(fileName2, ImageFormat.Png);
fullSize.Dispose();
string line = string.Format("{0:000} {1} V C {2} {3} {4} {5}", i, fileName1, new TimeCode(0).ToHHMMSSFF(), param.P.Duration.ToHHMMSSFF(), param.P.StartTime.ToHHMMSSFF(), param.P.EndTime.ToHHMMSSFF());
string line = string.Format("{0:000} {1} V C {2} {3} {4} {5}", i, fileName1, new TimeCode().ToHHMMSSFF(), param.P.Duration.ToHHMMSSFF(), param.P.StartTime.ToHHMMSSFF(), param.P.EndTime.ToHHMMSSFF());
sb.AppendLine(line);
sb.AppendLine();

View File

@ -20,7 +20,7 @@ namespace Nikse.SubtitleEdit.Forms
InitializeComponent();
comboBoxDateTimeFormats.SelectedIndex = 0;
labelVideoFileName.Text = string.Empty;
timeUpDownStartTime.TimeCode = new TimeCode(0, 0, 0, 0);
timeUpDownStartTime.TimeCode = new TimeCode();
timeUpDownDuration.TimeCode = new TimeCode(1, 0, 0, 0);
comboBoxDateTimeFormats.Items.Clear();
buttonCancel.Text = Configuration.Settings.Language.General.Cancel;

View File

@ -333,7 +333,7 @@ namespace Nikse.SubtitleEdit.Forms
labelVideoInfo.Text = string.Empty;
labelSingleLine.Text = string.Empty;
Text = Title;
timeUpDownStartTime.TimeCode = new TimeCode(0, 0, 0, 0);
timeUpDownStartTime.TimeCode = new TimeCode();
timeUpDownStartTime.UseVideoOffset = true;
timeUpDownVideoPosition.UseVideoOffset = true;
timeUpDownVideoPositionAdjust.UseVideoOffset = true;
@ -422,8 +422,8 @@ namespace Nikse.SubtitleEdit.Forms
labelAutoDuration.Visible = false;
mediaPlayer.SubtitleText = string.Empty;
comboBoxAutoContinue.SelectedIndex = 2;
timeUpDownVideoPosition.TimeCode = new TimeCode(0, 0, 0, 0);
timeUpDownVideoPositionAdjust.TimeCode = new TimeCode(0, 0, 0, 0);
timeUpDownVideoPosition.TimeCode = new TimeCode();
timeUpDownVideoPositionAdjust.TimeCode = new TimeCode();
timeUpDownVideoPosition.TimeCodeChanged += VideoPositionChanged;
timeUpDownVideoPositionAdjust.TimeCodeChanged += VideoPositionChanged;
timeUpDownVideoPosition.Enabled = false;
@ -8744,7 +8744,7 @@ namespace Nikse.SubtitleEdit.Forms
{
tc = tc.Substring(0, 13);
var timeCode = tc.Split(new[] { ':', '.', ',' }, StringSplitOptions.RemoveEmptyEntries);
var realTC = new TimeCode(0, 0, 0, 0);
var realTC = new TimeCode();
try
{
realTC = new TimeCode(int.Parse(timeCode[1]), int.Parse(timeCode[2]), int.Parse(timeCode[3]), int.Parse(timeCode[4]) * 10);

View File

@ -29,7 +29,7 @@ namespace Nikse.SubtitleEdit.Forms
public SetVideoOffset()
{
InitializeComponent();
_videoOffset = new TimeCode(0);
_videoOffset = new TimeCode();
checkBoxKeepTimeCodes.Checked = Configuration.Settings.Tools.VideoOffsetKeepTimeCodes;
Text = Configuration.Settings.Language.SetVideoOffset.Title;
labelDescription.Text = Configuration.Settings.Language.SetVideoOffset.Description;
@ -56,7 +56,7 @@ namespace Nikse.SubtitleEdit.Forms
private void buttonReset_Click(object sender, EventArgs e)
{
VideoOffset = new TimeCode(0);
VideoOffset = new TimeCode();
DoNotaddVideoOffsetToTimeCodes = checkBoxKeepTimeCodes.Checked;
Reset = true;
DialogResult = DialogResult.OK;

View File

@ -56,7 +56,7 @@ namespace Test.Logic
[TestMethod]
public void TestAdjust3()
{
var p = new Paragraph { Text = string.Empty, StartTime = new TimeCode(0, 0, 0, 0) };
var p = new Paragraph { Text = string.Empty, StartTime = new TimeCode() };
p.Adjust(1, 1);
Assert.AreEqual(1, p.StartTime.TotalSeconds);
}