本文整理汇总了C#中Nikse.SubtitleEdit.Logic.TimeCode类的典型用法代码示例。如果您正苦于以下问题:C# TimeCode类的具体用法?C# TimeCode怎么用?C# TimeCode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TimeCode类属于Nikse.SubtitleEdit.Logic命名空间,在下文中一共展示了TimeCode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Constructor
public Paragraph Constructor(TimeCode startTime, TimeCode endTime, string text)
{
Paragraph target = new Paragraph(startTime, endTime, text);
return target;
// TODO: add assertions to method ParagraphTest.Constructor(TimeCode, TimeCode, String)
}
示例2: Paragraph
public Paragraph(TimeCode startTime, TimeCode endTime, string text)
{
StartTime = startTime;
EndTime = endTime;
Text = text;
ID = Guid.NewGuid().ToString();
}
示例3: TimeCodeAddTime2
public void TimeCodeAddTime2()
{
var tc = new TimeCode(1000);
tc.AddTime(-1000);
Assert.AreEqual(tc.TotalMilliseconds, 0);
}
示例4: TimeCodeAddTime5
public void TimeCodeAddTime5()
{
var tc = new TimeCode(1000);
tc.AddTime(0, 1, 0, 0);
Assert.AreEqual(tc.TotalMilliseconds, 60000 + 1000);
}
示例5: Paragraph
public Paragraph(string text, double startTotalMilliseconds, double endTotalMilliseconds)
{
StartTime = new TimeCode(startTotalMilliseconds);
EndTime = new TimeCode(endTotalMilliseconds);
Text = text;
Id = GenerateId();
}
示例6: Paragraph
public Paragraph(string text, double startTotalMilliseconds, double endTotalMilliseconds)
{
StartTime = new TimeCode(startTotalMilliseconds);
EndTime = new TimeCode(endTotalMilliseconds);
Text = text;
ID = Guid.NewGuid().ToString();
}
示例7: TimeCodeGetTotalMilliseconds
public void TimeCodeGetTotalMilliseconds()
{
var tc = new TimeCode(1, 2, 3, 4);
Assert.AreEqual(tc.TotalMilliseconds, 3723004);
Assert.IsTrue(Math.Abs(tc.TotalMilliseconds - (tc.TotalSeconds * 1000.0)) < 0.001);
}
示例8: TimeCodeAddTime6
public void TimeCodeAddTime6()
{
var tc = new TimeCode(1000);
tc.AddTime(TimeSpan.FromMilliseconds(1000));
Assert.AreEqual(tc.TotalMilliseconds, 2000);
}
示例9: listBoxTracks_SelectedIndexChanged
private void listBoxTracks_SelectedIndexChanged(object sender, EventArgs e)
{
int idx = listBoxTracks.SelectedIndex;
if (idx < 0)
return;
listBoxSubtitles.Items.Clear();
int pid = _tsParser.SubtitlePacketIds[idx];
var list = _tsParser.GetDvbSubtitles(pid);
int i = 0;
foreach (var sub in list)
{
i++;
var start = new TimeCode(sub.StartMilliseconds);
var end = new TimeCode(sub.EndMilliseconds);
listBoxSubtitles.Items.Add(string.Format(Configuration.Settings.Language.TransportStreamSubtitleChooser.SubLine, i, start, end, sub.NumberOfImages));
}
if (list.Count > 0)
listBoxSubtitles.SelectedIndex = 0;
}
示例10: InitializeBatch
internal void InitializeBatch(List<Nikse.SubtitleEdit.Logic.BluRaySup.BluRaySupParser.PcsData> subtitles, VobSubOcrSettings vobSubOcrSettings, string fileName)
{
Initialize(subtitles, vobSubOcrSettings, fileName);
FormVobSubOcr_Shown(null, null);
checkBoxPromptForUnknownWords.Checked = false;
int max = GetSubtitleCount();
if (comboBoxOcrMethod.SelectedIndex == 0 && _tesseractAsyncStrings == null)
{
_tesseractAsyncStrings = new string[max];
_tesseractAsyncIndex = (int)numericUpDownStartNumber.Value + 5;
_tesseractThread = new BackgroundWorker();
_tesseractThread.DoWork += TesseractThreadDoWork;
_tesseractThread.RunWorkerCompleted += TesseractThreadRunWorkerCompleted;
_tesseractThread.WorkerSupportsCancellation = true;
if (_tesseractAsyncIndex >= 0 && _tesseractAsyncIndex < max)
_tesseractThread.RunWorkerAsync(GetSubtitleBitmap(_tesseractAsyncIndex));
}
System.Threading.Thread.Sleep(1000);
subtitleListView1.SelectedIndexChanged -= SubtitleListView1SelectedIndexChanged;
for (int i = 0; i < max; i++)
{
var startTime = new TimeCode(TimeSpan.FromMilliseconds(GetSubtitleStartTimeMilliseconds(i)));
var endTime = new TimeCode(TimeSpan.FromMilliseconds(GetSubtitleEndTimeMilliseconds(i)));
Application.DoEvents();
if (_abort)
{
SetButtonsEnabledAfterOcrDone();
return;
}
subtitleListView1.SelectIndexAndEnsureVisible(i);
string text = OcrViaTesseract(GetSubtitleBitmap(i), i);
_lastLine = text;
text = text.Replace("<i>-</i>", "-");
text = text.Replace("<i>a</i>", "a");
text = text.Replace(" ", " ");
text = text.Trim();
text = text.Replace(" " + Environment.NewLine, Environment.NewLine);
text = text.Replace(Environment.NewLine + " ", Environment.NewLine);
// max allow 2 lines
if (checkBoxAutoBreakLines.Checked && text.Replace(Environment.NewLine, "*").Length + 2 <= text.Length)
{
text = text.Replace(" " + Environment.NewLine, Environment.NewLine);
text = text.Replace(Environment.NewLine + " ", Environment.NewLine);
while (text.Contains(Environment.NewLine + Environment.NewLine))
text = text.Replace(Environment.NewLine + Environment.NewLine, Environment.NewLine);
if (text.Replace(Environment.NewLine, "*").Length + 2 <= text.Length)
text = Utilities.AutoBreakLine(text);
}
Application.DoEvents();
if (_abort)
{
textBoxCurrentText.Text = text;
SetButtonsEnabledAfterOcrDone();
return;
}
text = text.Trim();
text = text.Replace(" ", " ");
text = text.Replace(Environment.NewLine + Environment.NewLine, Environment.NewLine);
text = text.Replace(" ", " ");
text = text.Replace(Environment.NewLine + Environment.NewLine, Environment.NewLine);
Paragraph p = _subtitle.GetParagraphOrDefault(i);
if (p != null)
p.Text = text;
if (subtitleListView1.SelectedItems.Count == 1 && subtitleListView1.SelectedItems[0].Index == i)
textBoxCurrentText.Text = text;
else
subtitleListView1.SetText(i, text);
}
SetButtonsEnabledAfterOcrDone();
}
示例11: LoadBluRaySubFromMatroska
private void LoadBluRaySubFromMatroska(MatroskaSubtitleInfo matroskaSubtitleInfo, string fileName)
{
if (matroskaSubtitleInfo.ContentEncodingType == 1)
{
MessageBox.Show("Encrypted vobsub content not supported");
}
bool isValid;
var matroska = new Matroska();
ShowStatus(_language.ParsingMatroskaFile);
Refresh();
Cursor.Current = Cursors.WaitCursor;
List<SubtitleSequence> sub = matroska.GetMatroskaSubtitle(fileName, (int)matroskaSubtitleInfo.TrackNumber, out isValid, MatroskaProgress);
Cursor.Current = Cursors.Default;
int noOfErrors = 0;
string lastError = string.Empty;
if (isValid)
{
MakeHistoryForUndo(_language.BeforeImportFromMatroskaFile);
_subtitleListViewIndex = -1;
_subtitle.Paragraphs.Clear();
var subtitles = new List<Nikse.SubtitleEdit.Logic.BluRaySup.BluRaySupParser.PcsData>();
StringBuilder log = new StringBuilder();
foreach (SubtitleSequence p in sub)
{
byte[] buffer = null;
if (matroskaSubtitleInfo.ContentEncodingType == 0) // compressed with zlib
{
MemoryStream outStream = new MemoryStream();
ComponentAce.Compression.Libs.zlib.ZOutputStream outZStream = new ComponentAce.Compression.Libs.zlib.ZOutputStream(outStream);
MemoryStream inStream = new MemoryStream(p.BinaryData);
try
{
CopyStream(inStream, outZStream);
buffer = new byte[outZStream.TotalOut];
outStream.Position = 0;
outStream.Read(buffer, 0, buffer.Length);
}
catch (Exception exception)
{
TimeCode tc = new TimeCode(TimeSpan.FromMilliseconds(p.StartMilliseconds));
lastError = tc.ToString() + ": " + exception.Message + ": " + exception.StackTrace;
noOfErrors++;
}
finally
{
outStream.Close();
outZStream.Close();
inStream.Close();
}
}
else
{
buffer = p.BinaryData;
}
if (buffer != null && buffer.Length > 100)
{
MemoryStream ms = new MemoryStream(buffer);
var list = BluRaySupParser.ParseBluRaySup(ms, log, true);
foreach (var sup in list)
{
sup.StartTime = (long)((p.StartMilliseconds - 45) * 90.0);
sup.EndTime = (long)((p.EndMilliseconds - 45) * 90.0);
subtitles.Add(sup);
// fix overlapping
if (subtitles.Count > 1 && sub[subtitles.Count - 2].EndMilliseconds > sub[subtitles.Count - 1].StartMilliseconds)
subtitles[subtitles.Count - 2].EndTime = subtitles[subtitles.Count - 1].StartTime - 1;
}
ms.Close();
}
}
if (noOfErrors > 0)
{
MessageBox.Show(string.Format("{0} errror(s) occured during extraction of bdsup\r\n\r\n{1}", noOfErrors, lastError));
}
var formSubOcr = new VobSubOcr();
_formPositionsAndSizes.SetPositionAndSize(formSubOcr);
formSubOcr.Initialize(subtitles, Configuration.Settings.VobSubOcr, fileName);
if (_loading)
{
formSubOcr.Icon = (Icon)this.Icon.Clone();
formSubOcr.ShowInTaskbar = true;
formSubOcr.ShowIcon = true;
}
if (formSubOcr.ShowDialog(this) == DialogResult.OK)
{
MakeHistoryForUndo(_language.BeforeImportingDvdSubtitle);
_subtitle.Paragraphs.Clear();
SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
_subtitle.WasLoadedWithFrameNumbers = false;
_subtitle.CalculateFrameNumbersFromTimeCodes(CurrentFrameRate);
foreach (Paragraph p in formSubOcr.SubtitleFromOcr.Paragraphs)
{
_subtitle.Paragraphs.Add(p);
//.........这里部分代码省略.........
示例12: TabControlSubtitleSelectedIndexChanged
private void TabControlSubtitleSelectedIndexChanged(object sender, EventArgs e)
{
var format = GetCurrentSubtitleFormat();
if (tabControlSubtitle.SelectedIndex == TabControlSourceView)
{
ShowSource();
ShowSourceLineNumber();
if (textBoxSource.CanFocus)
textBoxSource.Focus();
// go to correct line in source view
if (SubtitleListview1.SelectedItems.Count > 0)
{
if (format.GetType() == typeof(SubRip))
{
Paragraph p = _subtitle.GetParagraphOrDefault(FirstSelectedIndex);
if (p != null)
{
string tc = p.StartTime.ToString() + " --> " + p.EndTime.ToString();
int start = textBoxSource.Text.IndexOf(tc);
if (start > 0)
{
textBoxSource.SelectionStart = start + tc.Length + Environment.NewLine.Length;
textBoxSource.SelectionLength = 0;
textBoxSource.ScrollToCaret();
}
}
}
else if (format.GetType() == typeof(SubStationAlpha) || format.GetType() == typeof(AdvancedSubStationAlpha))
{
Paragraph p = _subtitle.GetParagraphOrDefault(FirstSelectedIndex);
if (p != null)
{
const string timeCodeFormat = "{0}:{1:00}:{2:00}.{3:00}"; // h:mm:ss.cc
string startTC = string.Format(timeCodeFormat, p.StartTime.Hours, p.StartTime.Minutes, p.StartTime.Seconds, p.StartTime.Milliseconds / 10);
string endTC = string.Format(timeCodeFormat, p.EndTime.Hours, p.EndTime.Minutes, p.EndTime.Seconds, p.EndTime.Milliseconds / 10);
string tc = startTC + "," + endTC;
int start = textBoxSource.Text.IndexOf(tc);
if (start > 0)
{
int start2 = textBoxSource.Text.LastIndexOf("Dialogue:", start);
if (start2 > 0)
start2 = (textBoxSource.Text + Environment.NewLine).IndexOf(Environment.NewLine, start2);
if (start2 > 0)
start = start2;
textBoxSource.SelectionStart = start;
textBoxSource.SelectionLength = 0;
textBoxSource.ScrollToCaret();
}
}
}
}
}
else
{
ReloadFromSourceView();
ShowLineInformationListView();
if (SubtitleListview1.CanFocus)
SubtitleListview1.Focus();
// go to (select + focus) correct line in list view
if (textBoxSource.SelectionStart > 0 && textBoxSource.TextLength > 30)
{
if (format.GetType() == typeof(SubRip))
{
int pos = textBoxSource.SelectionStart;
if (pos + 35 < textBoxSource.TextLength)
pos += 35;
string s = textBoxSource.Text.Substring(0, pos);
int lastTimeCode = s.LastIndexOf(" --> "); // 00:02:26,407 --> 00:02:31,356
if (lastTimeCode > 14 && lastTimeCode + 16 >= s.Length)
{
s = s.Substring(0, lastTimeCode - 5);
lastTimeCode = s.LastIndexOf(" --> ");
}
if (lastTimeCode > 14 && lastTimeCode + 16 < s.Length)
{
string tc = s.Substring(lastTimeCode - 13, 30).Trim();
int index = 0;
foreach (Paragraph p in _subtitle.Paragraphs)
{
if (tc == p.StartTime.ToString() + " --> " + p.EndTime.ToString())
{
SubtitleListview1.SelectIndexAndEnsureVisible(index, true);
break;
}
index++;
}
}
}
else if (format.GetType() == typeof(SubStationAlpha) || format.GetType() == typeof(AdvancedSubStationAlpha))
{
int pos = textBoxSource.SelectionStart;
string s = textBoxSource.Text;
if (pos > 0)
pos--;
while (pos > 0 && pos + 3 < s.Length && !s.Substring(pos, 3).StartsWith(Environment.NewLine))
pos--;
s = s.Substring(pos).Trim();
//.........这里部分代码省略.........
示例13: UpdateOverlapErrors
private void UpdateOverlapErrors(TimeCode startTime)
{
labelStartTimeWarning.Text = string.Empty;
labelDurationWarning.Text = string.Empty;
if (_subtitle.Paragraphs.Count > 0 && SubtitleListview1.SelectedItems.Count > 0 && startTime != null)
{
int firstSelectedIndex = SubtitleListview1.SelectedItems[0].Index;
Paragraph prevParagraph = _subtitle.GetParagraphOrDefault(firstSelectedIndex - 1);
if (prevParagraph != null && prevParagraph.EndTime.TotalMilliseconds > startTime.TotalMilliseconds && Configuration.Settings.Tools.ListViewSyntaxColorOverlap)
labelStartTimeWarning.Text = string.Format(_languageGeneral.OverlapPreviousLineX, prevParagraph.EndTime.TotalSeconds - startTime.TotalSeconds);
Paragraph nextParagraph = _subtitle.GetParagraphOrDefault(firstSelectedIndex + 1);
if (nextParagraph != null)
{
double durationMilliSeconds = GetDurationInMilliseconds();
if (startTime.TotalMilliseconds + durationMilliSeconds > nextParagraph.StartTime.TotalMilliseconds && Configuration.Settings.Tools.ListViewSyntaxColorOverlap)
{
labelDurationWarning.Text = string.Format(_languageGeneral.OverlapX, ((startTime.TotalMilliseconds + durationMilliSeconds) - nextParagraph.StartTime.TotalMilliseconds) / 1000.0);
}
if (labelStartTimeWarning.Text.Length == 0 &&
startTime.TotalMilliseconds > nextParagraph.StartTime.TotalMilliseconds && Configuration.Settings.Tools.ListViewSyntaxColorOverlap)
{
double di = (startTime.TotalMilliseconds - nextParagraph.StartTime.TotalMilliseconds) / 1000.0;
labelStartTimeWarning.Text = string.Format(_languageGeneral.OverlapNextX, di);
}
else if (numericUpDownDuration.Value < 0)
{
labelDurationWarning.Text = _languageGeneral.Negative;
}
}
}
}
示例14: UpdateStartTimeInfo
private void UpdateStartTimeInfo(TimeCode startTime)
{
if (_subtitle.Paragraphs.Count > 0 && SubtitleListview1.SelectedItems.Count > 0 && startTime != null)
{
UpdateOverlapErrors(startTime);
// update _subtitle + listview
Paragraph p = _subtitle.Paragraphs[_subtitleListViewIndex];
p.EndTime.TotalMilliseconds += (startTime.TotalMilliseconds - p.StartTime.TotalMilliseconds);
p.StartTime = startTime;
SubtitleListview1.SetStartTime(_subtitleListViewIndex, p);
if (GetCurrentSubtitleFormat().IsFrameBased)
{
p.CalculateFrameNumbersFromTimeCodes(CurrentFrameRate);
p.CalculateTimeCodesFromFrameNumbers(CurrentFrameRate);
}
StartUpdateListSyntaxColoring();
}
}
示例15: SetCurrentViaEndPositionAndGotoNext
public void SetCurrentViaEndPositionAndGotoNext(int index)
{
Paragraph p = _subtitle.GetParagraphOrDefault(index);
if (p == null)
return;
if (mediaPlayer.VideoPlayer == null || string.IsNullOrEmpty(_videoFileName))
{
MessageBox.Show(Configuration.Settings.Language.General.NoVideoLoaded);
return;
}
//if (autoDuration)
//{
// //TODO: auto duration
// //TODO: search for start via wave file (must only be minor adjustment)
//}
// current movie pos
double durationTotalMilliseconds = p.Duration.TotalMilliseconds;
double totalMillisecondsEnd = mediaPlayer.CurrentPosition * 1000.0;
var tc = new TimeCode(TimeSpan.FromMilliseconds(totalMillisecondsEnd - durationTotalMilliseconds));
MakeHistoryForUndo(_language.BeforeSetEndAndVideoPosition + " " + tc.ToString());
_makeHistoryPaused = true;
if (p.StartTime.IsMaxTime)
{
p.EndTime.TotalSeconds = mediaPlayer.CurrentPosition;
p.StartTime.TotalMilliseconds = p.EndTime.TotalMilliseconds - Utilities.GetOptimalDisplayMilliseconds(p.Text);
}
else
{
p.StartTime.TotalMilliseconds = totalMillisecondsEnd - durationTotalMilliseconds;
p.EndTime.TotalMilliseconds = totalMillisecondsEnd;
}
timeUpDownStartTime.TimeCode = p.StartTime;
var durationInSeconds = (decimal)(p.Duration.TotalSeconds);
if (durationInSeconds >= numericUpDownDuration.Minimum && durationInSeconds <= numericUpDownDuration.Maximum)
SetDurationInSeconds((double)durationInSeconds);
SubtitleListview1.SelectIndexAndEnsureVisible(index+1);
ShowStatus(string.Format(_language.VideoControls.AdjustedViaEndTime, p.StartTime.ToShortString()));
audioVisualizer.Invalidate();
_makeHistoryPaused = false;
}