Merge pull request #7907 from Flitskikker/feature/evenly-distribute-lines

Add subtitle list view option to evenly distribute selected lines (CPS)
This commit is contained in:
Nikolaj Olsson 2024-02-08 06:52:10 +01:00 committed by GitHub
commit 9b13ce51cd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 81 additions and 0 deletions

View File

@ -2701,6 +2701,7 @@ $HorzAlign = Center
public string MainMergeDialogWithNext { get; set; }
public string MainMergeDialogWithPrevious { get; set; }
public string MainAutoBalanceSelectedLines { get; set; }
public string MainEvenlyDistributeSelectedLines { get; set; }
public string MainToggleFocus { get; set; }
public string MainToggleFocusWaveform { get; set; }
public string MainToggleFocusWaveformTextBox { get; set; }
@ -11071,6 +11072,12 @@ $HorzAlign = Center
shortcuts.MainAutoBalanceSelectedLines = subNode.InnerText;
}
subNode = node.SelectSingleNode("MainEvenlyDistributeSelectedLines");
if (subNode != null)
{
shortcuts.MainEvenlyDistributeSelectedLines = subNode.InnerText;
}
subNode = node.SelectSingleNode("MainToggleFocus");
if (subNode != null)
{
@ -12853,6 +12860,7 @@ $HorzAlign = Center
textWriter.WriteElementString("MainMergeDialogWithNext", shortcuts.MainMergeDialogWithNext);
textWriter.WriteElementString("MainMergeDialogWithPrevious", shortcuts.MainMergeDialogWithPrevious);
textWriter.WriteElementString("MainAutoBalanceSelectedLines", shortcuts.MainAutoBalanceSelectedLines);
textWriter.WriteElementString("MainEvenlyDistributeSelectedLines", shortcuts.MainEvenlyDistributeSelectedLines);
textWriter.WriteElementString("MainToggleFocus", shortcuts.MainToggleFocus);
textWriter.WriteElementString("MainToggleFocusWaveform", shortcuts.MainToggleFocusWaveform);
textWriter.WriteElementString("MainToggleFocusWaveformTextBox", shortcuts.MainToggleFocusWaveformTextBox);

View File

@ -576,6 +576,7 @@ namespace Nikse.SubtitleEdit.Forms
this.timerOriginalTextUndo = new System.Windows.Forms.Timer(this.components);
this.contextMenuStripShowVideoControls = new System.Windows.Forms.ContextMenuStrip(this.components);
this.toolStripMenuItemShowVideoControls = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItemEvenlyDistributeLines = new System.Windows.Forms.ToolStripMenuItem();
this.statusStrip1.SuspendLayout();
this.toolStrip1.SuspendLayout();
this.menuStrip1.SuspendLayout();
@ -3146,6 +3147,7 @@ namespace Nikse.SubtitleEdit.Forms
this.toolStripMenuItemTranslateSelected,
this.toolStripMenuItemUnbreakLines,
this.toolStripMenuItemAutoBreakLines,
this.toolStripMenuItemEvenlyDistributeLines,
this.toolStripMenuItemSaveSelectedLines,
this.typeEffectToolStripMenuItem,
this.karaokeEffectToolStripMenuItem});
@ -5845,6 +5847,13 @@ namespace Nikse.SubtitleEdit.Forms
this.toolStripMenuItemShowVideoControls.Text = "Show video controls";
this.toolStripMenuItemShowVideoControls.Click += new System.EventHandler(this.ToolStripMenuItemShowVideoControlsClick);
//
// toolStripMenuItemEvenlyDistributeLines
//
this.toolStripMenuItemEvenlyDistributeLines.Name = "toolStripMenuItemEvenlyDistributeLines";
this.toolStripMenuItemEvenlyDistributeLines.Size = new System.Drawing.Size(275, 22);
this.toolStripMenuItemEvenlyDistributeLines.Text = "Evenly distribute lines (CPS)...";
this.toolStripMenuItemEvenlyDistributeLines.Click += new System.EventHandler(this.ToolStripMenuItemEvenlyDistributeLinesClick);
//
// Main
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -6460,5 +6469,6 @@ namespace Nikse.SubtitleEdit.Forms
private NikseLabel labelAutoDuration;
private System.Windows.Forms.ToolStripButton toolStripSplitButtonPlayRate;
private System.Windows.Forms.ToolStripMenuItem autotranslateNLLBToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemEvenlyDistributeLines;
}
}

View File

@ -1938,6 +1938,7 @@ namespace Nikse.SubtitleEdit.Forms
toolStripMenuItemFont.Text = _language.Menu.ContextMenu.FontName;
toolStripMenuItemAlignment.Text = _language.Menu.ContextMenu.Alignment;
toolStripMenuItemAutoBreakLines.Text = _language.Menu.ContextMenu.AutoBalanceSelectedLines;
toolStripMenuItemEvenlyDistributeLines.Text = _language.Menu.ContextMenu.EvenlyDistributeSelectedLines;
toolStripMenuItemUnbreakLines.Text = _language.Menu.ContextMenu.RemoveLineBreaksFromSelectedLines;
typeEffectToolStripMenuItem.Text = _language.Menu.ContextMenu.TypewriterEffect;
karaokeEffectToolStripMenuItem.Text = _language.Menu.ContextMenu.KaraokeEffect;
@ -9631,6 +9632,7 @@ namespace Nikse.SubtitleEdit.Forms
toolStripMenuItemGoogleMicrosoftTranslateSelLine.Visible = false;
toolStripMenuItemUnbreakLines.Visible = true;
toolStripMenuItemAutoBreakLines.Visible = true;
toolStripMenuItemEvenlyDistributeLines.Visible = true;
toolStripMenuItemSurroundWithMusicSymbols.Visible = IsUnicode || Configuration.Settings.Tools.MusicSymbol == "#" || Configuration.Settings.Tools.MusicSymbol == "*";
if (SubtitleListview1.SelectedItems.Count == 1)
{
@ -22010,6 +22012,57 @@ namespace Nikse.SubtitleEdit.Forms
}
}
private void ToolStripMenuItemEvenlyDistributeLinesClick(object sender, EventArgs e)
{
if (_subtitle.Paragraphs.Count <= 0 || SubtitleListview1.SelectedItems.Count <= 0)
{
return;
}
var firstParagraph = _subtitle.GetParagraphOrDefault(SubtitleListview1.SelectedIndices[0]);
var lastParagraph = _subtitle.GetParagraphOrDefault(SubtitleListview1.SelectedIndices[SubtitleListview1.SelectedItems.Count - 1]);
var totalDuration = lastParagraph.EndTime.TotalMilliseconds - firstParagraph.StartTime.TotalMilliseconds;
var totalDurationWithGaps = totalDuration - (MinGapBetweenLines * (SubtitleListview1.SelectedItems.Count - 1));
decimal totalLength = 0;
foreach (int index in SubtitleListview1.SelectedIndices)
{
var p = _subtitle.GetParagraphOrDefault(index);
if (p != null)
{
totalLength += p.Text.CountCharacters(true);
}
}
var previousParagraphEndTime = firstParagraph.StartTime.TotalMilliseconds - MinGapBetweenLines;
MakeHistoryForUndo(_language.BeforeEvenlyDistributeSelectedLines);
SubtitleListview1.BeginUpdate();
foreach (int index in SubtitleListview1.SelectedIndices)
{
var p = _subtitle.GetParagraphOrDefault(index);
if (p != null)
{
var length = p.Text.CountCharacters(true);
var lengthRatio = length / totalLength;
var newDuration = Convert.ToDouble(lengthRatio) * totalDurationWithGaps;
p.StartTime.TotalMilliseconds = previousParagraphEndTime + MinGapBetweenLines;
p.EndTime.TotalMilliseconds = p.StartTime.TotalMilliseconds + newDuration;
previousParagraphEndTime = p.EndTime.TotalMilliseconds;
}
}
SubtitleListview1.EndUpdate();
RefreshSelectedParagraphs();
UpdateSourceView();
UpdateListSyntaxColoring();
ShowStatus(string.Format(_language.NumberOfLinesEvenlyDistributedX, SubtitleListview1.SelectedItems.Count));
}
private void ToolStripMenuItemUnbreakLinesClick(object sender, EventArgs e)
{
if (!IsSubtitleLoaded)
@ -26243,6 +26296,7 @@ namespace Nikse.SubtitleEdit.Forms
setPositionToolStripMenuItem.ShortcutKeys = UiUtil.GetKeys(Configuration.Settings.Shortcuts.GeneralSetAssaPosition);
colorPickerToolStripMenuItem.ShortcutKeys = UiUtil.GetKeys(Configuration.Settings.Shortcuts.GeneralColorPicker);
toolStripMenuItemAutoBreakLines.ShortcutKeys = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainAutoBalanceSelectedLines);
toolStripMenuItemEvenlyDistributeLines.ShortcutKeys = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainEvenlyDistributeSelectedLines);
generateBackgroundBoxToolStripMenuItem.ShortcutKeys = UiUtil.GetKeys(Configuration.Settings.Shortcuts.GeneralSetAssaBgBox);
colorToolStripMenuItem.ShortcutKeys = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainListViewColorChoose);
colorToolStripMenuItem1.ShortcutKeys = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainListViewColorChoose);

View File

@ -1755,6 +1755,7 @@ namespace Nikse.SubtitleEdit.Forms.Options
AddNode(listViewNode, language.MergeDialogWithNext, nameof(Configuration.Settings.Shortcuts.MainMergeDialogWithNext));
AddNode(listViewNode, language.MergeDialogWithPrevious, nameof(Configuration.Settings.Shortcuts.MainMergeDialogWithPrevious));
AddNode(listViewNode, language.AutoBalanceSelectedLines, nameof(Configuration.Settings.Shortcuts.MainAutoBalanceSelectedLines), true);
AddNode(listViewNode, language.EvenlyDistributeSelectedLines, nameof(Configuration.Settings.Shortcuts.MainEvenlyDistributeSelectedLines), true);
AddNode(listViewNode, language.ToggleFocus, nameof(Configuration.Settings.Shortcuts.MainToggleFocus));
AddNode(listViewNode, language.ToggleFocusWaveform, nameof(Configuration.Settings.Shortcuts.MainToggleFocusWaveform));
AddNode(listViewNode, language.ToggleFocusWaveformTextBox, nameof(Configuration.Settings.Shortcuts.MainToggleFocusWaveformTextBox));

View File

@ -1759,6 +1759,8 @@ namespace Nikse.SubtitleEdit.Logic
SortedByX = "Sorted by: {0}",
BeforeAutoBalanceSelectedLines = "Before auto balance selected lines",
NumberOfLinesAutoBalancedX = "Number of auto balanced lines: {0}",
BeforeEvenlyDistributeSelectedLines = "Before evenly distribute selected lines",
NumberOfLinesEvenlyDistributedX = "Number of evenly distributed lines: {0}",
BeforeRemoveLineBreaksInSelectedLines = "Before remove line-breaks from selected lines",
NumberOfWithRemovedLineBreakX = "Number of lines with removed line-break: {0}",
BeforeMultipleReplace = "Before multiple replace",
@ -2159,6 +2161,7 @@ namespace Nikse.SubtitleEdit.Logic
Subscript = "Subscript",
Alignment = "Alignment...",
AutoBalanceSelectedLines = "Auto balance selected lines...",
EvenlyDistributeSelectedLines = "Evenly distribute selected lines (CPS)",
RemoveLineBreaksFromSelectedLines = "Remove line-breaks from selected lines...",
TypewriterEffect = "Typewriter effect...",
KaraokeEffect = "Karaoke effect...",
@ -2967,6 +2970,7 @@ can edit in same subtitle file (collaboration)",
MergeDialogWithNext = "Merge dialog with next (insert dashes)",
MergeDialogWithPrevious = "Merge dialog with previous (insert dashes)",
AutoBalanceSelectedLines = "Auto balance selected lines",
EvenlyDistributeSelectedLines = "Evenly distribute selected lines (CPS)",
GoToNext = "Go to next line",
GoToNextPlayTranslate = "Go to next line (and play in 'Translate mode')",
GoToNextCursorAtEnd = "Go to next line and set cursor at end",

View File

@ -1577,6 +1577,8 @@
public string SortedByX { get; set; }
public string BeforeAutoBalanceSelectedLines { get; set; }
public string NumberOfLinesAutoBalancedX { get; set; }
public string BeforeEvenlyDistributeSelectedLines { get; set; }
public string NumberOfLinesEvenlyDistributedX { get; set; }
public string BeforeRemoveLineBreaksInSelectedLines { get; set; }
public string NumberOfWithRemovedLineBreakX { get; set; }
public string BeforeMultipleReplace { get; set; }
@ -1968,6 +1970,7 @@
public string Subscript { get; set; }
public string Alignment { get; set; }
public string AutoBalanceSelectedLines { get; set; }
public string EvenlyDistributeSelectedLines { get; set; }
public string RemoveLineBreaksFromSelectedLines { get; set; }
public string TypewriterEffect { get; set; }
public string KaraokeEffect { get; set; }
@ -2784,6 +2787,7 @@
public string MergeDialogWithNext { get; set; }
public string MergeDialogWithPrevious { get; set; }
public string AutoBalanceSelectedLines { get; set; }
public string EvenlyDistributeSelectedLines { get; set; }
public string GoToNext { get; set; }
public string GoToNextPlayTranslate { get; set; }
public string GoToNextCursorAtEnd { get; set; }