Merge pull request #7116 from Flitskikker/feature/beautify-timecodes-improvements-20230717

Some new "Beautify time codes" improvements
This commit is contained in:
Nikolaj Olsson 2023-07-18 00:01:10 -04:00 committed by GitHub
commit 12b4208938
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 348 additions and 47 deletions

View File

@ -142,5 +142,199 @@ namespace Test.Logic
result = ShotChangeHelper.IsCueOnShotChange(shotChangesSeconds, paragraph.EndTime, false);
Assert.AreEqual(false, result);
}
[TestMethod]
public void TestGetPreviousShotChange()
{
Configuration.Settings.General.CurrentFrameRate = 25;
var shotChangesSeconds = new List<double>() { 1, 10, 20 };
var paragraph = new Paragraph("Test.", 1000, 3000); // On shot
var result = ShotChangeHelper.GetPreviousShotChange(shotChangesSeconds, paragraph.StartTime);
Assert.AreEqual(1.0, result);
paragraph = new Paragraph("Test.", 1500, 3000); // Away from shot
result = ShotChangeHelper.GetPreviousShotChange(shotChangesSeconds, paragraph.StartTime);
Assert.AreEqual(1.0, result);
paragraph = new Paragraph("Test.", 990, 3000); // On shot after rounding
result = ShotChangeHelper.GetPreviousShotChange(shotChangesSeconds, paragraph.StartTime);
Assert.AreEqual(1.0, result);
paragraph = new Paragraph("Test.", 1010, 3000); // Tiny bit from shot
result = ShotChangeHelper.GetPreviousShotChange(shotChangesSeconds, paragraph.StartTime);
Assert.AreEqual(1.0, result);
paragraph = new Paragraph("Test.", 500, 3000); // No more shots
result = ShotChangeHelper.GetPreviousShotChange(shotChangesSeconds, paragraph.StartTime);
Assert.AreEqual(null, result);
paragraph = new Paragraph("Test.", 20500, 30000); // Other shot
result = ShotChangeHelper.GetPreviousShotChange(shotChangesSeconds, paragraph.StartTime);
Assert.AreEqual(20.0, result);
}
[TestMethod]
public void TestGetPreviousShotChangeInMs()
{
Configuration.Settings.General.CurrentFrameRate = 25;
var shotChangesSeconds = new List<double>() { 1, 10, 20 };
var paragraph = new Paragraph("Test.", 1000, 3000); // On shot
var result = ShotChangeHelper.GetPreviousShotChangeInMs(shotChangesSeconds, paragraph.StartTime);
Assert.AreEqual(1000, result);
paragraph = new Paragraph("Test.", 1500, 3000); // Away from shot
result = ShotChangeHelper.GetPreviousShotChangeInMs(shotChangesSeconds, paragraph.StartTime);
Assert.AreEqual(1000, result);
paragraph = new Paragraph("Test.", 990, 3000); // On shot after rounding
result = ShotChangeHelper.GetPreviousShotChangeInMs(shotChangesSeconds, paragraph.StartTime);
Assert.AreEqual(1000, result);
paragraph = new Paragraph("Test.", 1010, 3000); // Tiny bit from shot
result = ShotChangeHelper.GetPreviousShotChangeInMs(shotChangesSeconds, paragraph.StartTime);
Assert.AreEqual(1000, result);
paragraph = new Paragraph("Test.", 500, 3000); // No more shots
result = ShotChangeHelper.GetPreviousShotChangeInMs(shotChangesSeconds, paragraph.StartTime);
Assert.AreEqual(null, result);
paragraph = new Paragraph("Test.", 20500, 30000); // Other shot
result = ShotChangeHelper.GetPreviousShotChangeInMs(shotChangesSeconds, paragraph.StartTime);
Assert.AreEqual(20000, result);
}
[TestMethod]
public void TestGetPreviousShotChangePlusGapInMs()
{
Configuration.Settings.General.CurrentFrameRate = 25;
Configuration.Settings.BeautifyTimeCodes.Profile.InCuesGap = 2;
var shotChangesSeconds = new List<double>() { 1, 10, 20 };
var paragraph = new Paragraph("Test.", 1000, 3000); // On shot
var result = ShotChangeHelper.GetPreviousShotChangePlusGapInMs(shotChangesSeconds, paragraph.StartTime);
Assert.AreEqual(1080, result);
paragraph = new Paragraph("Test.", 1500, 3000); // Away from shot
result = ShotChangeHelper.GetPreviousShotChangePlusGapInMs(shotChangesSeconds, paragraph.StartTime);
Assert.AreEqual(1080, result);
paragraph = new Paragraph("Test.", 990, 3000); // On shot after rounding
result = ShotChangeHelper.GetPreviousShotChangePlusGapInMs(shotChangesSeconds, paragraph.StartTime);
Assert.AreEqual(1080, result);
paragraph = new Paragraph("Test.", 1010, 3000); // Tiny bit from shot
result = ShotChangeHelper.GetPreviousShotChangePlusGapInMs(shotChangesSeconds, paragraph.StartTime);
Assert.AreEqual(1080, result);
paragraph = new Paragraph("Test.", 500, 3000); // No more shots
result = ShotChangeHelper.GetPreviousShotChangePlusGapInMs(shotChangesSeconds, paragraph.StartTime);
Assert.AreEqual(null, result);
paragraph = new Paragraph("Test.", 20500, 30000); // Other shot
result = ShotChangeHelper.GetPreviousShotChangePlusGapInMs(shotChangesSeconds, paragraph.StartTime);
Assert.AreEqual(20080, result);
}
[TestMethod]
public void TestGetNextShotChange()
{
Configuration.Settings.General.CurrentFrameRate = 25;
var shotChangesSeconds = new List<double>() { 1, 10, 20 };
var paragraph = new Paragraph("Test.", 8000, 10000); // On shot
var result = ShotChangeHelper.GetNextShotChange(shotChangesSeconds, paragraph.EndTime);
Assert.AreEqual(10.0, result);
paragraph = new Paragraph("Test.", 8000, 9500); // Away from shot
result = ShotChangeHelper.GetNextShotChange(shotChangesSeconds, paragraph.EndTime);
Assert.AreEqual(10.0, result);
paragraph = new Paragraph("Test.", 8000, 10010); // On shot after rounding
result = ShotChangeHelper.GetNextShotChange(shotChangesSeconds, paragraph.EndTime);
Assert.AreEqual(10.0, result);
paragraph = new Paragraph("Test.", 8000, 9990); // Tiny bit from shot
result = ShotChangeHelper.GetNextShotChange(shotChangesSeconds, paragraph.EndTime);
Assert.AreEqual(10.0, result);
paragraph = new Paragraph("Test.", 30000, 32000); // No more shots
result = ShotChangeHelper.GetNextShotChange(shotChangesSeconds, paragraph.EndTime);
Assert.AreEqual(null, result);
paragraph = new Paragraph("Test.", 0, 800); // Other shot
result = ShotChangeHelper.GetNextShotChange(shotChangesSeconds, paragraph.EndTime);
Assert.AreEqual(1.0, result);
}
[TestMethod]
public void TestGetNextShotChangeInMs()
{
Configuration.Settings.General.CurrentFrameRate = 25;
var shotChangesSeconds = new List<double>() { 1, 10, 20 };
var paragraph = new Paragraph("Test.", 8000, 10000); // On shot
var result = ShotChangeHelper.GetNextShotChangeInMs(shotChangesSeconds, paragraph.EndTime);
Assert.AreEqual(10000, result);
paragraph = new Paragraph("Test.", 8000, 9500); // Away from shot
result = ShotChangeHelper.GetNextShotChangeInMs(shotChangesSeconds, paragraph.EndTime);
Assert.AreEqual(10000, result);
paragraph = new Paragraph("Test.", 8000, 10010); // On shot after rounding
result = ShotChangeHelper.GetNextShotChangeInMs(shotChangesSeconds, paragraph.EndTime);
Assert.AreEqual(10000, result);
paragraph = new Paragraph("Test.", 8000, 9990); // Tiny bit from shot
result = ShotChangeHelper.GetNextShotChangeInMs(shotChangesSeconds, paragraph.EndTime);
Assert.AreEqual(10000, result);
paragraph = new Paragraph("Test.", 30000, 32000); // No more shots
result = ShotChangeHelper.GetNextShotChangeInMs(shotChangesSeconds, paragraph.EndTime);
Assert.AreEqual(null, result);
paragraph = new Paragraph("Test.", 0, 800); // Other shot
result = ShotChangeHelper.GetNextShotChangeInMs(shotChangesSeconds, paragraph.EndTime);
Assert.AreEqual(1000, result);
}
[TestMethod]
public void TestGetNextShotChangeMinusGapInMs()
{
Configuration.Settings.General.CurrentFrameRate = 25;
Configuration.Settings.BeautifyTimeCodes.Profile.OutCuesGap = 2;
var shotChangesSeconds = new List<double>() { 1, 10, 20 };
var paragraph = new Paragraph("Test.", 8000, 10000); // On shot
var result = ShotChangeHelper.GetNextShotChangeMinusGapInMs(shotChangesSeconds, paragraph.EndTime);
Assert.AreEqual(9920, result);
paragraph = new Paragraph("Test.", 8000, 9500); // Away from shot
result = ShotChangeHelper.GetNextShotChangeMinusGapInMs(shotChangesSeconds, paragraph.EndTime);
Assert.AreEqual(9920, result);
paragraph = new Paragraph("Test.", 8000, 10010); // On shot after rounding
result = ShotChangeHelper.GetNextShotChangeMinusGapInMs(shotChangesSeconds, paragraph.EndTime);
Assert.AreEqual(9920, result);
paragraph = new Paragraph("Test.", 8000, 9990); // Tiny bit from shot
result = ShotChangeHelper.GetNextShotChangeMinusGapInMs(shotChangesSeconds, paragraph.EndTime);
Assert.AreEqual(9920, result);
paragraph = new Paragraph("Test.", 30000, 32000); // No more shots
result = ShotChangeHelper.GetNextShotChangeMinusGapInMs(shotChangesSeconds, paragraph.EndTime);
Assert.AreEqual(null, result);
paragraph = new Paragraph("Test.", 0, 800); // Other shot
result = ShotChangeHelper.GetNextShotChangeMinusGapInMs(shotChangesSeconds, paragraph.EndTime);
Assert.AreEqual(920, result);
}
}
}

View File

@ -87,11 +87,11 @@ namespace Nikse.SubtitleEdit.Core.Common
// Util functions
public static double? GetPreviousShotChangeInMs(List<double> shotChanges, TimeCode currentTime)
public static double? GetPreviousShotChange(List<double> shotChanges, TimeCode currentTime)
{
try
{
return shotChanges.Last(x => SubtitleFormat.MillisecondsToFrames(x * 1000) <= SubtitleFormat.MillisecondsToFrames(currentTime.TotalMilliseconds)) * 1000;
return shotChanges.Last(x => SubtitleFormat.MillisecondsToFrames(x * 1000) <= SubtitleFormat.MillisecondsToFrames(currentTime.TotalMilliseconds));
}
catch (InvalidOperationException)
{
@ -99,6 +99,17 @@ namespace Nikse.SubtitleEdit.Core.Common
}
}
public static double? GetPreviousShotChangeInMs(List<double> shotChanges, TimeCode currentTime)
{
var previousShotChange = GetPreviousShotChange(shotChanges, currentTime);
if (previousShotChange != null)
{
return previousShotChange * 1000;
}
return null;
}
public static double? GetPreviousShotChangePlusGapInMs(List<double> shotChanges, TimeCode currentTime)
{
var previousShotChangeInMs = GetPreviousShotChangeInMs(shotChanges, currentTime);
@ -110,11 +121,11 @@ namespace Nikse.SubtitleEdit.Core.Common
return null;
}
public static double? GetNextShotChangeInMs(List<double> shotChanges, TimeCode currentTime)
public static double? GetNextShotChange(List<double> shotChanges, TimeCode currentTime)
{
try
{
return shotChanges.First(x => SubtitleFormat.MillisecondsToFrames(x * 1000) >= SubtitleFormat.MillisecondsToFrames(currentTime.TotalMilliseconds)) * 1000;
return shotChanges.First(x => SubtitleFormat.MillisecondsToFrames(x * 1000) >= SubtitleFormat.MillisecondsToFrames(currentTime.TotalMilliseconds));
}
catch (InvalidOperationException)
{
@ -122,6 +133,17 @@ namespace Nikse.SubtitleEdit.Core.Common
}
}
public static double? GetNextShotChangeInMs(List<double> shotChanges, TimeCode currentTime)
{
var nextShotChange = GetNextShotChange(shotChanges, currentTime);
if (nextShotChange != null)
{
return nextShotChange * 1000;
}
return null;
}
public static double? GetNextShotChangeMinusGapInMs(List<double> shotChanges, TimeCode currentTime)
{
var nextShotChangeInMs = GetNextShotChangeInMs(shotChanges, currentTime);

View File

@ -327,6 +327,8 @@ namespace Nikse.SubtitleEdit.Controls
_subtitle = new Subtitle();
_noClear = false;
_wavePeaks = value;
UpdateSnappingDistance();
}
}
@ -1732,7 +1734,7 @@ namespace Nikse.SubtitleEdit.Controls
if (Configuration.Settings.VideoControls.WaveformSnapToShotChanges && ModifierKeys != Keys.Shift)
{
var nearestShotChange = _shotChanges.Count > 0 ? _shotChanges.Aggregate((x, y) => Math.Abs((x * 1000) - milliseconds) < Math.Abs((y * 1000) - milliseconds) ? x : y) : -9999;
var nearestShotChange = ShotChangeHelper.GetClosestShotChange(_shotChanges, new TimeCode(milliseconds)) ?? double.MinValue;
if (Math.Abs(e.X - SecondsToXPosition(nearestShotChange - _startPositionSeconds)) < ShotChangeSnapPixels)
{
_mouseDownParagraph.StartTime.TotalMilliseconds = (nearestShotChange * 1000) + TimeCodesBeautifierUtils.GetInCuesGapMs();
@ -1750,7 +1752,7 @@ namespace Nikse.SubtitleEdit.Controls
if (Configuration.Settings.VideoControls.WaveformSnapToShotChanges && ModifierKeys != Keys.Shift)
{
var nearestShotChange = _shotChanges.Count > 0 ? _shotChanges.Aggregate((x, y) => Math.Abs((x * 1000) - milliseconds) < Math.Abs((y * 1000) - milliseconds) ? x : y) : -9999;
var nearestShotChange = ShotChangeHelper.GetClosestShotChange(_shotChanges, new TimeCode(milliseconds)) ?? double.MinValue;
if (Math.Abs(e.X - SecondsToXPosition(nearestShotChange - _startPositionSeconds)) < ShotChangeSnapPixels)
{
NewSelectionParagraph.StartTime.TotalMilliseconds = (nearestShotChange * 1000) + TimeCodesBeautifierUtils.GetInCuesGapMs();
@ -1789,7 +1791,7 @@ namespace Nikse.SubtitleEdit.Controls
if (Configuration.Settings.VideoControls.WaveformSnapToShotChanges && ModifierKeys != Keys.Shift)
{
var nearestShotChange = _shotChanges.Count > 0 ? _shotChanges.Aggregate((x, y) => Math.Abs((x * 1000) - milliseconds) < Math.Abs((y * 1000) - milliseconds) ? x : y) : -9999;
var nearestShotChange = ShotChangeHelper.GetClosestShotChange(_shotChanges, new TimeCode(milliseconds)) ?? double.MinValue;
if (Math.Abs(e.X - SecondsToXPosition(nearestShotChange - _startPositionSeconds)) < ShotChangeSnapPixels)
{
_mouseDownParagraph.EndTime.TotalMilliseconds = (nearestShotChange * 1000) - TimeCodesBeautifierUtils.GetOutCuesGapMs();
@ -1807,7 +1809,7 @@ namespace Nikse.SubtitleEdit.Controls
if (Configuration.Settings.VideoControls.WaveformSnapToShotChanges && ModifierKeys != Keys.Shift)
{
var nearestShotChange = _shotChanges.Count > 0 ? _shotChanges.Aggregate((x, y) => Math.Abs((x * 1000) - milliseconds) < Math.Abs((y * 1000) - milliseconds) ? x : y) : -9999;
var nearestShotChange = ShotChangeHelper.GetClosestShotChange(_shotChanges, new TimeCode(milliseconds)) ?? double.MinValue;
if (Math.Abs(e.X - SecondsToXPosition(nearestShotChange - _startPositionSeconds)) < ShotChangeSnapPixels)
{
NewSelectionParagraph.EndTime.TotalMilliseconds = (nearestShotChange * 1000) - TimeCodesBeautifierUtils.GetOutCuesGapMs();
@ -1838,8 +1840,8 @@ namespace Nikse.SubtitleEdit.Controls
if (Configuration.Settings.VideoControls.WaveformSnapToShotChanges && ModifierKeys != Keys.Shift)
{
var nearestShotChangeInFront = _shotChanges.Count > 0 ? _shotChanges.Aggregate((x, y) => Math.Abs((x * 1000) - _mouseDownParagraph.StartTime.TotalMilliseconds) < Math.Abs((y * 1000) - _mouseDownParagraph.StartTime.TotalMilliseconds) ? x : y) : -9999;
var nearestShotChangeInBack = _shotChanges.Count > 0 ? _shotChanges.Aggregate((x, y) => Math.Abs((x * 1000) - _mouseDownParagraph.EndTime.TotalMilliseconds) < Math.Abs((y * 1000) - _mouseDownParagraph.EndTime.TotalMilliseconds) ? x : y) : -9999;
var nearestShotChangeInFront = ShotChangeHelper.GetClosestShotChange(_shotChanges, _mouseDownParagraph.StartTime) ?? double.MinValue;
var nearestShotChangeInBack = ShotChangeHelper.GetClosestShotChange(_shotChanges, _mouseDownParagraph.EndTime) ?? double.MinValue;
if (Math.Abs(SecondsToXPosition(_mouseDownParagraph.StartTime.TotalSeconds - _startPositionSeconds) - SecondsToXPosition(nearestShotChangeInFront - _startPositionSeconds)) < ShotChangeSnapPixels)
{
@ -1902,8 +1904,8 @@ namespace Nikse.SubtitleEdit.Controls
if (Configuration.Settings.VideoControls.WaveformSnapToShotChanges && ModifierKeys != Keys.Shift)
{
var nearestShotChangeInFront = _shotChanges.Count > 0 ? _shotChanges.Aggregate((x, y) => Math.Abs(x - startTotalSeconds) < Math.Abs(y - startTotalSeconds) ? x : y) : -9999;
var nearestShotChangeInBack = _shotChanges.Count > 0 ? _shotChanges.Aggregate((x, y) => Math.Abs(x - endTotalSeconds) < Math.Abs(y - endTotalSeconds) ? x : y) : -9999;
var nearestShotChangeInFront = ShotChangeHelper.GetClosestShotChange(_shotChanges, TimeCode.FromSeconds(startTotalSeconds)) ?? double.MinValue;
var nearestShotChangeInBack = ShotChangeHelper.GetClosestShotChange(_shotChanges, TimeCode.FromSeconds(endTotalSeconds)) ?? double.MinValue;
if (Math.Abs(SecondsToXPosition(NewSelectionParagraph.StartTime.TotalSeconds - _startPositionSeconds) - SecondsToXPosition(nearestShotChangeInFront - _startPositionSeconds)) < ShotChangeSnapPixels)
{

View File

@ -276,7 +276,7 @@ namespace Nikse.SubtitleEdit.Forms.BeautifyTimeCodes
buttonOK.Enabled = false;
// Actual processing
FixedSubtitle = new Subtitle(_subtitle);
FixedSubtitle = new Subtitle(_subtitle, false);
TimeCodesBeautifier timeCodesBeautifier = new TimeCodesBeautifier(
FixedSubtitle,

View File

@ -344,6 +344,7 @@
this.changeCasingForSelectedLinesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.fixCommonErrorsInSelectedLinesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.visualSyncSelectedLinesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.beautifyTimeCodesOfSelectedLinesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.showSelectedLinesEarlierlaterToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItemTranslateSelected = new System.Windows.Forms.ToolStripMenuItem();
this.genericTranslateToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
@ -3142,6 +3143,7 @@
this.changeCasingForSelectedLinesToolStripMenuItem,
this.fixCommonErrorsInSelectedLinesToolStripMenuItem,
this.visualSyncSelectedLinesToolStripMenuItem,
this.beautifyTimeCodesOfSelectedLinesToolStripMenuItem,
this.showSelectedLinesEarlierlaterToolStripMenuItem,
this.toolStripMenuItemTranslateSelected,
this.toolStripMenuItemUnbreakLines,
@ -3181,6 +3183,13 @@
this.visualSyncSelectedLinesToolStripMenuItem.Text = "Visual sync selected lines...";
this.visualSyncSelectedLinesToolStripMenuItem.Click += new System.EventHandler(this.VisualSyncSelectedLinesToolStripMenuItemClick);
//
// beautifyTimeCodesOfSelectedLinesToolStripMenuItem
//
this.beautifyTimeCodesOfSelectedLinesToolStripMenuItem.Name = "beautifyTimeCodesOfSelectedLinesToolStripMenuItem";
this.beautifyTimeCodesOfSelectedLinesToolStripMenuItem.Size = new System.Drawing.Size(275, 22);
this.beautifyTimeCodesOfSelectedLinesToolStripMenuItem.Text = "Beautify time codes of selected lines...";
this.beautifyTimeCodesOfSelectedLinesToolStripMenuItem.Click += new System.EventHandler(this.beautifyTimeCodesOfSelectedLinesToolStripMenuItem_Click);
//
// showSelectedLinesEarlierlaterToolStripMenuItem
//
this.showSelectedLinesEarlierlaterToolStripMenuItem.Name = "showSelectedLinesEarlierlaterToolStripMenuItem";
@ -6378,5 +6387,6 @@
private Nikse.SubtitleEdit.Controls.NikseUpDown numericUpDownLayer;
private System.Windows.Forms.Label labelLayer;
private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemWebVttStyle;
private System.Windows.Forms.ToolStripMenuItem beautifyTimeCodesOfSelectedLinesToolStripMenuItem;
}
}

View File

@ -1913,6 +1913,7 @@ namespace Nikse.SubtitleEdit.Forms
karaokeEffectToolStripMenuItem.Text = _language.Menu.ContextMenu.KaraokeEffect;
showSelectedLinesEarlierlaterToolStripMenuItem.Text = _language.Menu.ContextMenu.ShowSelectedLinesEarlierLater;
visualSyncSelectedLinesToolStripMenuItem.Text = _language.Menu.ContextMenu.VisualSyncSelectedLines;
beautifyTimeCodesOfSelectedLinesToolStripMenuItem.Text = _language.Menu.ContextMenu.BeautifyTimeCodesOfSelectedLines;
toolStripMenuItemGoogleMicrosoftTranslateSelLine.Text = _language.Menu.ContextMenu.GoogleAndMicrosoftTranslateSelectedLine;
toolStripMenuItemSelectedLines.Text = _language.Menu.ContextMenu.SelectedLines;
@ -34483,39 +34484,7 @@ namespace Nikse.SubtitleEdit.Forms
private void toolStripMenuItemBeautifyTimeCodes_Click(object sender, EventArgs e)
{
if (!IsSubtitleLoaded)
{
DisplaySubtitleNotLoadedMessage();
return;
}
using (var form = new BeautifyTimeCodes.BeautifyTimeCodes(_subtitle, _videoInfo, _videoFileName, audioVisualizer.ShotChanges))
{
var result = form.ShowDialog(this);
if (form.ShotChangesInSeconds.Count > 0)
{
audioVisualizer.ShotChanges = form.ShotChangesInSeconds;
}
if (result == DialogResult.OK)
{
int index = FirstSelectedIndex;
if (index < 0)
{
index = 0;
}
MakeHistoryForUndo(_language.BeforeBeautifyTimeCodes);
SaveSubtitleListviewIndices();
_subtitle.Paragraphs.Clear();
_subtitle.Paragraphs.AddRange(form.FixedSubtitle.Paragraphs);
SubtitleListview1.Fill(_subtitle, _subtitleOriginal);
SubtitleListview1.SelectIndexAndEnsureVisible(index, true);
RestoreSubtitleListviewIndices();
}
}
BeautifyTimeCodes(SubtitleListview1.GetSelectedIndices().Length > 1);
}
private void toolStripButtonBeautifyTimeCodes_Click(object sender, EventArgs e)
@ -35442,5 +35411,101 @@ namespace Nikse.SubtitleEdit.Forms
RefreshSelectedParagraph();
}
private void beautifyTimeCodesOfSelectedLinesToolStripMenuItem_Click(object sender, EventArgs e)
{
BeautifyTimeCodes(true);
}
private void BeautifyTimeCodes(bool onlySelectedLines)
{
if (!IsSubtitleLoaded)
{
DisplaySubtitleNotLoadedMessage();
return;
}
if (onlySelectedLines)
{
var selectedIndices = SubtitleListview1.GetSelectedIndices();
var selectedLines = new Subtitle();
foreach (int index in selectedIndices)
{
selectedLines.Paragraphs.Add(_subtitle.Paragraphs[index]);
}
using (var form = new BeautifyTimeCodes.BeautifyTimeCodes(selectedLines, _videoInfo, _videoFileName, audioVisualizer.ShotChanges))
{
form.Text = string.Format(LanguageSettings.Current.BeautifyTimeCodes.TitleSelectedLines, selectedIndices.Length);
var result = form.ShowDialog(this);
if (form.ShotChangesInSeconds.Count > 0)
{
audioVisualizer.ShotChanges = form.ShotChangesInSeconds;
}
if (result == DialogResult.OK)
{
int index = FirstSelectedIndex;
if (index < 0)
{
index = 0;
}
MakeHistoryForUndo(_language.BeforeBeautifyTimeCodesSelectedLines);
SaveSubtitleListviewIndices();
foreach (int idx in selectedIndices)
{
var pOld = _subtitle.Paragraphs[idx];
var p = form.FixedSubtitle.GetParagraphOrDefaultById(pOld.Id);
if (p != null)
{
_subtitle.Paragraphs[idx] = p;
}
}
SubtitleListview1.Fill(_subtitle, _subtitleOriginal);
SubtitleListview1.SelectIndexAndEnsureVisible(index, true);
RestoreSubtitleListviewIndices();
ShowStatus(_language.BeautifiedTimeCodesSelectedLines);
}
}
}
else
{
using (var form = new BeautifyTimeCodes.BeautifyTimeCodes(_subtitle, _videoInfo, _videoFileName, audioVisualizer.ShotChanges))
{
var result = form.ShowDialog(this);
if (form.ShotChangesInSeconds.Count > 0)
{
audioVisualizer.ShotChanges = form.ShotChangesInSeconds;
}
if (result == DialogResult.OK)
{
int index = FirstSelectedIndex;
if (index < 0)
{
index = 0;
}
MakeHistoryForUndo(_language.BeforeBeautifyTimeCodes);
SaveSubtitleListviewIndices();
_subtitle.Paragraphs.Clear();
_subtitle.Paragraphs.AddRange(form.FixedSubtitle.Paragraphs);
SubtitleListview1.Fill(_subtitle, _subtitleOriginal);
SubtitleListview1.SelectIndexAndEnsureVisible(index, true);
RestoreSubtitleListviewIndices();
ShowStatus(_language.BeautifiedTimeCodes);
}
}
}
}
}
}

View File

@ -539,6 +539,7 @@ namespace Nikse.SubtitleEdit.Logic
BeautifyTimeCodes = new LanguageStructure.BeautifyTimeCodes
{
Title = "Beautify time codes",
TitleSelectedLines = "Beautify time codes ({0} selected lines)",
GroupTimeCodes = "Time codes",
AlignTimeCodes = "Align time codes to frame time codes",
ExtractExactTimeCodes = "Use ffprobe to extract exact frame time codes",
@ -1615,7 +1616,9 @@ namespace Nikse.SubtitleEdit.Logic
BeforeRenumbering = "Before renumbering",
RenumberedStartingFromX = "Renumbered starting from: {0}",
BeforeBeautifyTimeCodes = "Before beautifying time codes",
BeforeBeautifyTimeCodesSelectedLines = "Before beautifying time codes of selected lines",
BeautifiedTimeCodes = "Time codes beautified",
BeautifiedTimeCodesSelectedLines = "Time codes of selected lines beautified",
BeforeRemovalOfTextingForHearingImpaired = "Before removal of texting for hearing impaired",
TextingForHearingImpairedRemovedOneLine = "Texting for hearing impaired removed: One line",
TextingForHearingImpairedRemovedXLines = "Texting for hearing impaired removed: {0} lines",
@ -2128,6 +2131,7 @@ namespace Nikse.SubtitleEdit.Logic
KaraokeEffect = "Karaoke effect...",
ShowSelectedLinesEarlierLater = "Show selected lines earlier/later...",
VisualSyncSelectedLines = "Visual sync selected lines...",
BeautifyTimeCodesOfSelectedLines = "Beautify time codes of selected lines...",
GoogleAndMicrosoftTranslateSelectedLine = "Google/Microsoft translate original line",
SelectedLines = "Selected lines",
TranslateSelectedLines = "Translate selected lines...",

View File

@ -392,6 +392,7 @@ namespace Nikse.SubtitleEdit.Logic
public class BeautifyTimeCodes
{
public string Title { get; set; }
public string TitleSelectedLines { get; set; }
public string GroupTimeCodes { get; set; }
public string AlignTimeCodes { get; set; }
public string ExtractExactTimeCodes { get; set; }
@ -1439,7 +1440,9 @@ namespace Nikse.SubtitleEdit.Logic
public string BeforeRenumbering { get; set; }
public string RenumberedStartingFromX { get; set; }
public string BeforeBeautifyTimeCodes { get; set; }
public string BeforeBeautifyTimeCodesSelectedLines { get; set; }
public string BeautifiedTimeCodes { get; set; }
public string BeautifiedTimeCodesSelectedLines { get; set; }
public string BeforeRemovalOfTextingForHearingImpaired { get; set; }
public string TextingForHearingImpairedRemovedOneLine { get; set; }
public string TextingForHearingImpairedRemovedXLines { get; set; }
@ -1941,6 +1944,7 @@ namespace Nikse.SubtitleEdit.Logic
public string KaraokeEffect { get; set; }
public string ShowSelectedLinesEarlierLater { get; set; }
public string VisualSyncSelectedLines { get; set; }
public string BeautifyTimeCodesOfSelectedLines { get; set; }
public string GoogleAndMicrosoftTranslateSelectedLine { get; set; }
public string SelectedLines { get; set; }
public string TranslateSelectedLines { get; set; }