Add CPS option to modify selection - thx uckthis :)

Work on #8148
This commit is contained in:
Nikolaj Olsson 2024-04-26 06:53:15 +02:00
parent c9ba8b7873
commit ecdcb7fe7e
6 changed files with 82 additions and 19 deletions

View File

@ -4,6 +4,7 @@
* NEW:
* Add "Text To Speech" - thx darnn/cvrle77/msjsc001
* Add burn-in batch mode - thx Leon/David
* Add new LRC with milliseconds format - thx eadmaster
* IMPROVED:
* Update Portuguese translation - thx hugok79
* Update Bulgarian translation - thx Калин
@ -20,6 +21,7 @@
* Fix possible crash in teletext reading - thx yellobyte
* Fix unwanted text boxes background color change - thx Leon
* Fix Whisper on selection in waveform in "translation mode" - thx rRobis
* Fix image export shadow when border is zero - thx pixelhunterX
4.0.5 (13th April 2024)

View File

@ -2129,6 +2129,8 @@ Download and continue?</VideoFromUrlRequirements>
<EvenLines>Even-numbered lines</EvenLines>
<DurationLessThan>Duration less than</DurationLessThan>
<DurationGreaterThan>Duration greater than</DurationGreaterThan>
<CpsLessThan>CPS less than</CpsLessThan>
<CpsGreaterThan>CPS greater than</CpsGreaterThan>
<ExactlyOneLine>Exactly one line</ExactlyOneLine>
<ExactlyTwoLines>Exactly two lines</ExactlyTwoLines>
<MoreThanTwoLines>More than two lines</MoreThanTwoLines>

View File

@ -28,13 +28,15 @@ namespace Nikse.SubtitleEdit.Forms
private const int FunctionEven = 7;
private const int FunctionDurationLessThan = 8;
private const int FunctionDurationGreaterThan = 9;
private const int FunctionExactlyOneLine = 10;
private const int FunctionExactlyTwoLines = 11;
private const int FunctionMoreThanTwoLines = 12;
private const int FunctionBookmarked = 13;
private const int FunctionBlankLines = 14;
private const int FunctionStyle = 15;
private const int FunctionActor = 16;
private const int FunctionCpsLessThan = 10;
private const int FunctionCpsGreaterThan = 11;
private const int FunctionExactlyOneLine = 12;
private const int FunctionExactlyTwoLines = 13;
private const int FunctionMoreThanTwoLines = 14;
private const int FunctionBookmarked = 15;
private const int FunctionBlankLines = 16;
private const int FunctionStyle = 17;
private const int FunctionActor = 18;
private const string ContainsString = "Contains";
private const string StartsWith = "Starts with";
@ -46,6 +48,8 @@ namespace Nikse.SubtitleEdit.Forms
private const string Even = "Even";
private const string DurationLessThan = "Duration <";
private const string DurationGreaterThan = "Duration >";
private const string CpsLessThan = "CPS <";
private const string CpsGreaterThan = "CPS >";
private const string ExactlyOneLine = "Exactly one line";
private const string ExactlyTwoLines = "Exactly two lines";
private const string MoreThanTwoLines = "More than two lines";
@ -97,6 +101,8 @@ namespace Nikse.SubtitleEdit.Forms
comboBoxRule.Items.Add(LanguageSettings.Current.ModifySelection.EvenLines);
comboBoxRule.Items.Add(LanguageSettings.Current.ModifySelection.DurationLessThan);
comboBoxRule.Items.Add(LanguageSettings.Current.ModifySelection.DurationGreaterThan);
comboBoxRule.Items.Add(LanguageSettings.Current.ModifySelection.CpsLessThan);
comboBoxRule.Items.Add(LanguageSettings.Current.ModifySelection.CpsGreaterThan);
comboBoxRule.Items.Add(LanguageSettings.Current.ModifySelection.ExactlyOneLine);
comboBoxRule.Items.Add(LanguageSettings.Current.ModifySelection.ExactlyTwoLines);
comboBoxRule.Items.Add(LanguageSettings.Current.ModifySelection.MoreThanTwoLines);
@ -142,6 +148,12 @@ namespace Nikse.SubtitleEdit.Forms
case DurationGreaterThan:
comboBoxRule.SelectedIndex = FunctionDurationGreaterThan;
break;
case CpsLessThan:
comboBoxRule.SelectedIndex = FunctionCpsLessThan;
break;
case CpsGreaterThan:
comboBoxRule.SelectedIndex = FunctionCpsGreaterThan;
break;
case ExactlyOneLine:
comboBoxRule.SelectedIndex = FunctionExactlyOneLine;
break;
@ -226,6 +238,12 @@ namespace Nikse.SubtitleEdit.Forms
case FunctionDurationGreaterThan:
Configuration.Settings.Tools.ModifySelectionRule = DurationGreaterThan;
break;
case FunctionCpsLessThan:
Configuration.Settings.Tools.ModifySelectionRule = CpsLessThan;
break;
case FunctionCpsGreaterThan:
Configuration.Settings.Tools.ModifySelectionRule = CpsGreaterThan;
break;
case FunctionExactlyOneLine:
Configuration.Settings.Tools.ModifySelectionRule = ExactlyOneLine;
break;
@ -311,7 +329,7 @@ namespace Nikse.SubtitleEdit.Forms
}
}
for (int i = 0; i < _subtitle.Paragraphs.Count; i++)
for (var i = 0; i < _subtitle.Paragraphs.Count; i++)
{
if ((radioButtonSubtractFromSelection.Checked || radioButtonIntersect.Checked) && _subtitleListView.Items[i].Selected ||
!radioButtonSubtractFromSelection.Checked && !radioButtonIntersect.Checked)
@ -397,6 +415,20 @@ namespace Nikse.SubtitleEdit.Forms
listViewItems.Add(MakeListViewItem(p, i));
}
}
else if (comboBoxRule.SelectedIndex == FunctionCpsLessThan) // Cps less than
{
if (Utilities.GetCharactersPerSecond(p) < (double)numericUpDownDuration.Value)
{
listViewItems.Add(MakeListViewItem(p, i));
}
}
else if (comboBoxRule.SelectedIndex == FunctionCpsGreaterThan) // Cps greater than
{
if (Utilities.GetCharactersPerSecond(p) > (double)numericUpDownDuration.Value)
{
listViewItems.Add(MakeListViewItem(p, i));
}
}
else if (comboBoxRule.SelectedIndex == FunctionExactlyOneLine)
{
if (p.Text.SplitToLines().Count == 1)
@ -504,28 +536,37 @@ namespace Nikse.SubtitleEdit.Forms
{
textBoxText.Visible = true;
listViewStyles.Visible = false;
numericUpDownDuration.Visible = comboBoxRule.SelectedIndex == FunctionDurationLessThan || comboBoxRule.SelectedIndex == FunctionDurationGreaterThan;
numericUpDownDuration.Visible =
comboBoxRule.SelectedIndex == FunctionDurationLessThan ||
comboBoxRule.SelectedIndex == FunctionDurationGreaterThan ||
comboBoxRule.SelectedIndex == FunctionCpsLessThan ||
comboBoxRule.SelectedIndex == FunctionCpsGreaterThan;
if (comboBoxRule.SelectedIndex == FunctionRegEx) // RegEx
{
// creat new context menu only if textBoxText doesn't already has one, this will prevent unnecessary
// create new context menu only if textBoxText doesn't already has one, this will prevent unnecessary
// allocation regex option is already selected and user re-select it
textBoxText.ContextMenuStrip = textBoxText.ContextMenuStrip ??
textBoxText.ContextMenuStrip = textBoxText.ContextMenuStrip ??
FindReplaceDialogHelper.GetRegExContextMenu(new NativeTextBoxAdapter(textBoxText));
checkBoxCaseSensitive.Enabled = false;
}
else if (comboBoxRule.SelectedIndex == FunctionOdd ||
comboBoxRule.SelectedIndex == FunctionEven ||
comboBoxRule.SelectedIndex == FunctionExactlyOneLine ||
comboBoxRule.SelectedIndex == FunctionExactlyTwoLines ||
comboBoxRule.SelectedIndex == FunctionMoreThanTwoLines ||
comboBoxRule.SelectedIndex == FunctionBookmarked ||
else if (comboBoxRule.SelectedIndex == FunctionOdd ||
comboBoxRule.SelectedIndex == FunctionEven ||
comboBoxRule.SelectedIndex == FunctionExactlyOneLine ||
comboBoxRule.SelectedIndex == FunctionExactlyTwoLines ||
comboBoxRule.SelectedIndex == FunctionMoreThanTwoLines ||
comboBoxRule.SelectedIndex == FunctionBookmarked ||
comboBoxRule.SelectedIndex == FunctionBlankLines)
{
checkBoxCaseSensitive.Enabled = false;
textBoxText.ContextMenuStrip = null;
textBoxText.Visible = false;
}
else if (comboBoxRule.SelectedIndex == FunctionDurationLessThan || comboBoxRule.SelectedIndex == FunctionDurationGreaterThan || comboBoxRule.SelectedIndex == FunctionAllUppercase)
else if (comboBoxRule.SelectedIndex == FunctionDurationLessThan ||
comboBoxRule.SelectedIndex == FunctionDurationGreaterThan ||
comboBoxRule.SelectedIndex == FunctionCpsLessThan ||
comboBoxRule.SelectedIndex == FunctionCpsGreaterThan ||
comboBoxRule.SelectedIndex == FunctionAllUppercase)
{
checkBoxCaseSensitive.Enabled = false;
listViewStyles.Visible = false;
@ -539,7 +580,7 @@ namespace Nikse.SubtitleEdit.Forms
numericUpDownDuration.Value = Configuration.Settings.General.SubtitleMinimumDisplayMilliseconds;
}
}
else
else if (comboBoxRule.SelectedIndex == FunctionDurationGreaterThan)
{
if (numericUpDownDuration.Value == 0 &&
Configuration.Settings.General.SubtitleMaximumDisplayMilliseconds >= numericUpDownDuration.Minimum &&
@ -548,6 +589,14 @@ namespace Nikse.SubtitleEdit.Forms
numericUpDownDuration.Value = Configuration.Settings.General.SubtitleMaximumDisplayMilliseconds;
}
}
else if (comboBoxRule.SelectedIndex == FunctionCpsLessThan)
{
numericUpDownDuration.Value = (int)Math.Round(Math.Max(10, Configuration.Settings.General.SubtitleOptimalCharactersPerSeconds - 5), MidpointRounding.AwayFromZero);
}
else if (comboBoxRule.SelectedIndex == FunctionCpsGreaterThan)
{
numericUpDownDuration.Value = (int)Math.Round(Configuration.Settings.General.SubtitleMaximumCharactersPerSeconds, MidpointRounding.AwayFromZero);
}
}
else if (comboBoxRule.SelectedIndex == FunctionStyle)
{

View File

@ -2461,6 +2461,8 @@ namespace Nikse.SubtitleEdit.Logic
EvenLines = "Even-numbered lines",
DurationLessThan = "Duration less than",
DurationGreaterThan = "Duration greater than",
CpsLessThan = "CPS less than",
CpsGreaterThan = "CPS greater than",
ExactlyOneLine = "Exactly one line",
ExactlyTwoLines = "Exactly two lines",
MoreThanTwoLines = "More than two lines",

View File

@ -5770,6 +5770,12 @@ namespace Nikse.SubtitleEdit.Logic
case "ModifySelection/DurationGreaterThan":
language.ModifySelection.DurationGreaterThan = reader.Value;
break;
case "ModifySelection/CpsLessThan":
language.ModifySelection.CpsLessThan = reader.Value;
break;
case "ModifySelection/CpsGreaterThan":
language.ModifySelection.CpsGreaterThan = reader.Value;
break;
case "ModifySelection/ExactlyOneLine":
language.ModifySelection.ExactlyOneLine = reader.Value;
break;

View File

@ -2271,6 +2271,8 @@
public string EvenLines { get; set; }
public string DurationLessThan { get; set; }
public string DurationGreaterThan { get; set; }
public string CpsLessThan { get; set; }
public string CpsGreaterThan { get; set; }
public string ExactlyOneLine { get; set; }
public string ExactlyTwoLines { get; set; }
public string MoreThanTwoLines { get; set; }