mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-10-27 22:42:38 +01:00
Now loads spectrogram bitmaps in background, will be displayed when ready
git-svn-id: https://subtitleedit.googlecode.com/svn/trunk@464 99eadd0c-20b8-1223-b5c4-2a2b2df33de2
This commit is contained in:
parent
cc9d9bde71
commit
cce271875e
@ -2,8 +2,8 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
using Nikse.SubtitleEdit.Logic;
|
||||
using System.Xml;
|
||||
using Nikse.SubtitleEdit.Logic;
|
||||
|
||||
namespace Nikse.SubtitleEdit.Controls
|
||||
{
|
||||
@ -37,6 +37,7 @@ namespace Nikse.SubtitleEdit.Controls
|
||||
private bool _noClear = false;
|
||||
|
||||
private List<Bitmap> _spectrumBitmaps = new List<Bitmap>();
|
||||
private string _spectrogramDirectory;
|
||||
private double _sampleDuration = 0;
|
||||
private double _totalDuration = 0;
|
||||
private const int SpectrumBitmapWidth = 1024;
|
||||
@ -1067,24 +1068,34 @@ namespace Nikse.SubtitleEdit.Controls
|
||||
public void InitializeSpectrogram(string spectrogramDirectory)
|
||||
{
|
||||
_spectrumBitmaps = new List<Bitmap>();
|
||||
int count = 0;
|
||||
ShowSpectrogram = false;
|
||||
if (System.IO.Directory.Exists(spectrogramDirectory))
|
||||
{
|
||||
while (System.IO.File.Exists(System.IO.Path.Combine(spectrogramDirectory, count + ".gif")))
|
||||
{
|
||||
Bitmap bmp = new Bitmap(System.IO.Path.Combine(spectrogramDirectory, count + ".gif"));
|
||||
_spectrumBitmaps.Add(bmp);
|
||||
count++;
|
||||
}
|
||||
XmlDocument doc = new XmlDocument();
|
||||
doc.Load(System.IO.Path.Combine(spectrogramDirectory, "Info.xml"));
|
||||
_sampleDuration = Convert.ToDouble(doc.DocumentElement.SelectSingleNode("SampleDuration").InnerText);
|
||||
_totalDuration = Convert.ToDouble(doc.DocumentElement.SelectSingleNode("TotalDuration").InnerText);
|
||||
ShowSpectrogram = true;
|
||||
_spectrogramDirectory = spectrogramDirectory;
|
||||
var bw = new System.ComponentModel.BackgroundWorker();
|
||||
bw.DoWork += new System.ComponentModel.DoWorkEventHandler(LoadSpectrogramBitmapsAsync);
|
||||
bw.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(LoadSpectrogramBitmapsCompleted);
|
||||
bw.RunWorkerAsync();
|
||||
}
|
||||
else
|
||||
}
|
||||
|
||||
void LoadSpectrogramBitmapsCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
|
||||
{
|
||||
XmlDocument doc = new XmlDocument();
|
||||
doc.Load(System.IO.Path.Combine(_spectrogramDirectory, "Info.xml"));
|
||||
_sampleDuration = Convert.ToDouble(doc.DocumentElement.SelectSingleNode("SampleDuration").InnerText);
|
||||
_totalDuration = Convert.ToDouble(doc.DocumentElement.SelectSingleNode("TotalDuration").InnerText);
|
||||
ShowSpectrogram = true;
|
||||
}
|
||||
|
||||
void LoadSpectrogramBitmapsAsync(object sender, System.ComponentModel.DoWorkEventArgs e)
|
||||
{
|
||||
int count = 0;
|
||||
while (System.IO.File.Exists(System.IO.Path.Combine(_spectrogramDirectory, count + ".gif")))
|
||||
{
|
||||
ShowSpectrogram = false;
|
||||
Bitmap bmp = new Bitmap(System.IO.Path.Combine(_spectrogramDirectory, count + ".gif"));
|
||||
_spectrumBitmaps.Add(bmp);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -63,6 +63,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||
new AbcIViewer(),
|
||||
new Csv(),
|
||||
new TimeXml(),
|
||||
new ZeroG(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
108
src/Logic/SubtitleFormats/ZeroG.cs
Normal file
108
src/Logic/SubtitleFormats/ZeroG.cs
Normal file
@ -0,0 +1,108 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||
{
|
||||
class ZeroG : SubtitleFormat
|
||||
{
|
||||
|
||||
public override string Extension
|
||||
{
|
||||
get { return ".zeg"; }
|
||||
}
|
||||
|
||||
public override string Name
|
||||
{
|
||||
get { return "Zero G"; }
|
||||
}
|
||||
|
||||
public override bool HasLineNumber
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public override bool IsTimeBased
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public override bool IsMine(List<string> lines, string fileName)
|
||||
{
|
||||
Subtitle subtitle = new Subtitle();
|
||||
LoadSubtitle(subtitle, lines, fileName);
|
||||
return subtitle.Paragraphs.Count > _errorCount;
|
||||
}
|
||||
|
||||
public override string ToText(Subtitle subtitle, string title)
|
||||
{
|
||||
//% Zero G 1.0
|
||||
|
||||
//E 1 0:50:20.22 0:50:21.38 Default NTP Die Frage ist:
|
||||
//E 1 0:50:21.54 0:50:25.86 Default NTP Wieso habe ich überlebt?
|
||||
//E 1 0:50:27.30 0:50:30.78 Default NTP Was habe ich richtig gemacht? \n Ich weiß es nicht.
|
||||
const string paragraphWriteFormat = "E 1 {0} {1} Default NTP {2}";
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.AppendLine("% Zero G 1.0");
|
||||
sb.AppendLine();
|
||||
foreach (Paragraph p in subtitle.Paragraphs)
|
||||
{
|
||||
string text = p.Text.Replace(Environment.NewLine, " \\n ");
|
||||
sb.AppendLine(string.Format(paragraphWriteFormat, EncodeTimeCode(p.StartTime), EncodeTimeCode(p.EndTime), text));
|
||||
}
|
||||
return sb.ToString().Trim();
|
||||
}
|
||||
|
||||
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
|
||||
{
|
||||
_errorCount = 0;
|
||||
var regexTimeCode = new Regex(@"^E 1 \d:\d\d:\d\d.\d\d \d:\d\d:\d\d.\d\d Default NTP ", RegexOptions.Compiled);
|
||||
//E 1 0:50:05.42 0:50:10.06 Default NTP
|
||||
|
||||
subtitle.Paragraphs.Clear();
|
||||
foreach (string line in lines)
|
||||
{
|
||||
if (regexTimeCode.IsMatch(line))
|
||||
{
|
||||
try
|
||||
{
|
||||
string timePart = line.Substring(4, 10).Trim();
|
||||
var start = DecodeTimeCode(timePart);
|
||||
timePart = line.Substring(15, 10).Trim();
|
||||
var end = DecodeTimeCode(timePart);
|
||||
var paragraph = new Paragraph();
|
||||
paragraph.StartTime = start;
|
||||
paragraph.EndTime = end;
|
||||
paragraph.Text = line.Substring(38).Replace(" \\n ", Environment.NewLine).Replace("\\n", Environment.NewLine);
|
||||
subtitle.Paragraphs.Add(paragraph);
|
||||
}
|
||||
catch
|
||||
{
|
||||
_errorCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
subtitle.Renumber(1);
|
||||
}
|
||||
|
||||
private string EncodeTimeCode(TimeCode time)
|
||||
{
|
||||
//0:50:05.42
|
||||
return string.Format("{0:0}:{1:00}:{2:00}.{3:00}", time.Hours, time.Minutes, time.Seconds, time.Milliseconds / 10);
|
||||
}
|
||||
|
||||
private TimeCode DecodeTimeCode(string timePart)
|
||||
{
|
||||
string[] parts = timePart.Split(":.".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
|
||||
int hours = int.Parse(parts[0]);
|
||||
int minutes = int.Parse(parts[1]);
|
||||
int seconds = int.Parse(parts[2]);
|
||||
int milliseconds = int.Parse(parts[3]) * 10;
|
||||
TimeSpan ts = new TimeSpan(0, hours, minutes, seconds, milliseconds);
|
||||
return new TimeCode(ts);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -591,6 +591,7 @@
|
||||
<Compile Include="Logic\SubtitleFormats\UnknownSubtitle2.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\UnknownSubtitle3.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\UnknownSubtitle4.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\ZeroG.cs" />
|
||||
<Compile Include="Logic\TimeCode.cs" />
|
||||
<Compile Include="Logic\Utilities.cs" />
|
||||
<Compile Include="Logic\VideoFormats\AviRiffData.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user