This commit is contained in:
Nikolaj Olsson 2024-03-30 20:39:26 +01:00
parent 2479754ced
commit 758dcac3de
9 changed files with 73 additions and 12 deletions

View File

@ -1644,6 +1644,7 @@ To use an API key, go to "Options -> Settings -> Auto-translate" to enter
<StillTypingAutoContinueStopped>Still typing... auto continue stopped</StillTypingAutoContinueStopped>
<InsertNewSubtitleAtVideoPosition>Insert new subtitle at video pos</InsertNewSubtitleAtVideoPosition>
<InsertNewSubtitleAtVideoPositionNoTextBoxFocus>Insert new subtitle at video pos (no text box focus)</InsertNewSubtitleAtVideoPositionNoTextBoxFocus>
<InsertNewSubtitleAtVideoPositionMax>Insert new subtitle at video pos (as long as possible)</InsertNewSubtitleAtVideoPositionMax>
<Auto>Auto</Auto>
<PlayFromJustBeforeText>Play from just before text</PlayFromJustBeforeText>
<PlayFromBeginning>Play from beginning of video</PlayFromBeginning>

View File

@ -2648,6 +2648,7 @@ $HorzAlign = Center
public string MainTextBoxSelectionToRuby { get; set; }
public string MainTextBoxToggleAutoDuration { get; set; }
public string MainCreateInsertSubAtVideoPos { get; set; }
public string MainCreateInsertSubAtVideoPosMax { get; set; }
public string MainCreateInsertSubAtVideoPosNoTextBoxFocus { get; set; }
public string MainCreateSetStart { get; set; }
public string MainCreateSetEnd { get; set; }
@ -10831,6 +10832,12 @@ $HorzAlign = Center
shortcuts.MainCreateInsertSubAtVideoPos = subNode.InnerText;
}
subNode = node.SelectSingleNode("MainCreateInsertSubAtVideoPosMax");
if (subNode != null)
{
shortcuts.MainCreateInsertSubAtVideoPosMax = subNode.InnerText;
}
subNode = node.SelectSingleNode("MainCreateInsertSubAtVideoPosNoTextBoxFocus");
if (subNode != null)
{
@ -12986,6 +12993,7 @@ $HorzAlign = Center
textWriter.WriteElementString("MainTextBoxSelectionToRuby", shortcuts.MainTextBoxSelectionToRuby);
textWriter.WriteElementString("MainTextBoxToggleAutoDuration", shortcuts.MainTextBoxToggleAutoDuration);
textWriter.WriteElementString("MainCreateInsertSubAtVideoPos", shortcuts.MainCreateInsertSubAtVideoPos);
textWriter.WriteElementString("MainCreateInsertSubAtVideoPosMax", shortcuts.MainCreateInsertSubAtVideoPosMax);
textWriter.WriteElementString("MainCreateInsertSubAtVideoPosNoTextBoxFocus", shortcuts.MainCreateInsertSubAtVideoPosNoTextBoxFocus);
textWriter.WriteElementString("MainCreateSetStart", shortcuts.MainCreateSetStart);
textWriter.WriteElementString("MainCreateSetEnd", shortcuts.MainCreateSetEnd);

View File

@ -790,7 +790,7 @@ namespace Nikse.SubtitleEdit.Forms
private void AudioVisualizerInsertAtVideoPosition(object sender, EventArgs e)
{
InsertNewTextAtVideoPosition();
InsertNewTextAtVideoPosition(false);
}
private void AudioVisualizerPasteAtVideoPosition(object sender, EventArgs e)
@ -15081,7 +15081,7 @@ namespace Nikse.SubtitleEdit.Forms
Utilities.LoadMatroskaTextSubtitle(matroskaSubtitleInfo, matroska, sub, _subtitle);
Utilities.ParseMatroskaTextSt(matroskaSubtitleInfo, sub, _subtitle);
if (_networkSession == null)
{
SubtitleListview1.HideColumn(SubtitleListView.SubtitleColumn.Extra);
@ -18638,7 +18638,15 @@ namespace Nikse.SubtitleEdit.Forms
}
else if (_shortcuts.MainCreateInsertSubAtVideoPosNoTextBoxFocus == e.KeyData)
{
var p = InsertNewTextAtVideoPosition();
var p = InsertNewTextAtVideoPosition(false);
p.Text = string.Empty;
SubtitleListview1.SetText(_subtitle.GetIndex(p), p.Text);
textBoxListViewText.Text = p.Text;
e.SuppressKeyPress = true;
}
else if (_shortcuts.MainCreateInsertSubAtVideoPosMax == e.KeyData)
{
var p = InsertNewTextAtVideoPosition(true);
p.Text = string.Empty;
SubtitleListview1.SetText(_subtitle.GetIndex(p), p.Text);
textBoxListViewText.Text = p.Text;
@ -18704,7 +18712,7 @@ namespace Nikse.SubtitleEdit.Forms
SubtitleListview1.SetStartTimeAndDuration(index, _subtitle.Paragraphs[index], _subtitle.GetParagraphOrDefault(index + 1), _subtitle.GetParagraphOrDefault(index - 1));
SetDurationInSeconds(_subtitle.Paragraphs[index].DurationTotalSeconds);
var newP = InsertNewParagraphAtPosition(newEndTime.TotalMilliseconds + MinGapBetweenLines);
var newP = InsertNewParagraphAtPosition(newEndTime.TotalMilliseconds + MinGapBetweenLines, false);
if (audioVisualizer.WavePeaks != null && newP.EndTime.TotalSeconds >= audioVisualizer.EndPositionSeconds - 0.1)
{
audioVisualizer.StartPositionSeconds = Math.Max(0, newP.StartTime.TotalSeconds - 0.1);
@ -18721,7 +18729,7 @@ namespace Nikse.SubtitleEdit.Forms
{
if (_mainCreateStartDownEndUpParagraph == null)
{
_mainCreateStartDownEndUpParagraph = InsertNewTextAtVideoPosition();
_mainCreateStartDownEndUpParagraph = InsertNewTextAtVideoPosition(false);
}
e.SuppressKeyPress = true;
@ -24735,7 +24743,7 @@ namespace Nikse.SubtitleEdit.Forms
{
mediaPlayer.Pause();
var newParagraph = InsertNewTextAtVideoPosition();
var newParagraph = InsertNewTextAtVideoPosition(false);
if (!InSourceView)
{
@ -24749,7 +24757,7 @@ namespace Nikse.SubtitleEdit.Forms
ShowStatus(string.Format(_language.VideoControls.NewTextInsertAtX, newParagraph.StartTime.ToShortString()));
}
private Paragraph InsertNewTextAtVideoPosition()
private Paragraph InsertNewTextAtVideoPosition(bool maxDuration)
{
// current movie Position
double videoPositionInMilliseconds = mediaPlayer.CurrentPosition * TimeCode.BaseUnit;
@ -24761,16 +24769,16 @@ namespace Nikse.SubtitleEdit.Forms
var tc = new TimeCode(videoPositionInMilliseconds);
MakeHistoryForUndo(_language.BeforeInsertSubtitleAtVideoPosition + " " + tc);
return InsertNewParagraphAtPosition(videoPositionInMilliseconds);
return InsertNewParagraphAtPosition(videoPositionInMilliseconds, maxDuration);
}
private Paragraph InsertNewParagraphAtPosition(double PositionInMilliseconds)
private Paragraph InsertNewParagraphAtPosition(double positionInMilliseconds, bool maxDuration)
{
// find index where to insert
int index = 0;
foreach (var p in _subtitle.Paragraphs)
{
if (p.StartTime.TotalMilliseconds > PositionInMilliseconds)
if (p.StartTime.TotalMilliseconds > positionInMilliseconds)
{
break;
}
@ -24779,7 +24787,12 @@ namespace Nikse.SubtitleEdit.Forms
}
// prevent overlap
var endTotalMilliseconds = PositionInMilliseconds + Configuration.Settings.General.NewEmptyDefaultMs;
var endTotalMilliseconds = positionInMilliseconds + Configuration.Settings.General.NewEmptyDefaultMs;
if (maxDuration && mediaPlayer.VideoPlayer != null)
{
endTotalMilliseconds = mediaPlayer.Duration * 1000.0;
}
var next = _subtitle.GetParagraphOrDefault(index);
if (next != null)
{
@ -24790,7 +24803,7 @@ namespace Nikse.SubtitleEdit.Forms
}
// create and insert
var newParagraph = new Paragraph(string.Empty, PositionInMilliseconds, endTotalMilliseconds);
var newParagraph = new Paragraph(string.Empty, positionInMilliseconds, endTotalMilliseconds);
SetStyleForNewParagraph(newParagraph, index);
if (_networkSession != null)
{

View File

@ -1843,6 +1843,7 @@ namespace Nikse.SubtitleEdit.Forms.Options
var createAndAdjustNode = new ShortcutNode(LanguageSettings.Current.Main.VideoControls.CreateAndAdjust);
AddNode(createAndAdjustNode, LanguageSettings.Current.Main.VideoControls.InsertNewSubtitleAtVideoPosition, nameof(Configuration.Settings.Shortcuts.MainCreateInsertSubAtVideoPos));
AddNode(createAndAdjustNode, LanguageSettings.Current.Main.VideoControls.InsertNewSubtitleAtVideoPositionNoTextBoxFocus, nameof(Configuration.Settings.Shortcuts.MainCreateInsertSubAtVideoPosNoTextBoxFocus));
AddNode(createAndAdjustNode, LanguageSettings.Current.Main.VideoControls.InsertNewSubtitleAtVideoPositionMax, nameof(Configuration.Settings.Shortcuts.MainCreateInsertSubAtVideoPosMax));
AddNode(createAndAdjustNode, language.MainCreateStartDownEndUp, nameof(Configuration.Settings.Shortcuts.MainCreateStartDownEndUp));
AddNode(createAndAdjustNode, LanguageSettings.Current.Main.VideoControls.SetStartTime, nameof(Configuration.Settings.Shortcuts.MainCreateSetStart));
AddNode(createAndAdjustNode, language.AdjustSetStartTimeKeepDuration, nameof(Configuration.Settings.Shortcuts.MainAdjustSetStartKeepDuration));

View File

@ -123,6 +123,7 @@ namespace Nikse.SubtitleEdit.Forms.Translate
new LibreTranslate(),
new MyMemoryApi(),
new ChatGptTranslate(),
new AnthropicTranslate(),
new GeminiTranslate(),
new PapagoTranslate(),
new NoLanguageLeftBehindServe(),
@ -196,7 +197,10 @@ namespace Nikse.SubtitleEdit.Forms.Translate
if (engineType == typeof(DeepLTranslate))
{
labelFormality.Visible = true;
labelFormality.Text = LanguageSettings.Current.GoogleTranslate.Formality;
comboBoxFormality.Left = labelFormality.Right + 3;
comboBoxFormality.Visible = true;
comboBoxFormality.DropDownStyle = ComboBoxStyle.DropDownList;
FillUrls(new List<string>
{
@ -300,6 +304,27 @@ namespace Nikse.SubtitleEdit.Forms.Translate
return;
}
if (engineType == typeof(AnthropicTranslate))
{
FillUrls(new List<string>
{
Configuration.Settings.Tools.AnthropicApiUrl,
});
labelApiKey.Left = nikseComboBoxUrl.Right + 12;
nikseTextBoxApiKey.Text = Configuration.Settings.Tools.AnthropicApiKey;
nikseTextBoxApiKey.Left = labelApiKey.Right + 3;
labelApiKey.Visible = true;
nikseTextBoxApiKey.Visible = true;
labelFormality.Visible = true;
comboBoxFormality.Left = labelFormality.Right + 3;
comboBoxFormality.Visible = true;
comboBoxFormality.DropDownStyle = ComboBoxStyle.DropDown;
labelFormality.Text = LanguageSettings.Current.AudioToText.Model;
return;
}
if (engineType == typeof(GeminiTranslate))
{
@ -903,6 +928,12 @@ namespace Nikse.SubtitleEdit.Forms.Translate
Configuration.Settings.Tools.ChatGptApiKey = nikseTextBoxApiKey.Text.Trim();
}
if (engineType == typeof(AnthropicTranslate) && !string.IsNullOrWhiteSpace(nikseTextBoxApiKey.Text))
{
Configuration.Settings.Tools.AnthropicApiKey = nikseTextBoxApiKey.Text.Trim();
Configuration.Settings.Tools.AnthropicApiModel = comboBoxFormality.Text.Trim();
}
if (engineType == typeof(GeminiTranslate) && !string.IsNullOrWhiteSpace(nikseTextBoxApiKey.Text))
{
Configuration.Settings.Tools.GeminiProApiKey = nikseTextBoxApiKey.Text.Trim();

View File

@ -2246,6 +2246,7 @@ namespace Nikse.SubtitleEdit.Logic
InsertNewSubtitleAtVideoPosition = "Insert new subtitle at video pos",
InsertNewSubtitleAtVideoPositionNoTextBoxFocus = "Insert new subtitle at video pos (no text box focus)",
InsertNewSubtitleAtVideoPositionMax = "Insert new subtitle at video pos (as long as possible)",
Auto = "Auto",
PlayFromJustBeforeText = "Play from just before text",
PlayFromBeginning = "Play from beginning of video",

View File

@ -5251,6 +5251,9 @@ namespace Nikse.SubtitleEdit.Logic
case "Main/VideoControls/InsertNewSubtitleAtVideoPositionNoTextBoxFocus":
language.Main.VideoControls.InsertNewSubtitleAtVideoPositionNoTextBoxFocus = reader.Value;
break;
case "Main/VideoControls/InsertNewSubtitleAtVideoPositionMax":
language.Main.VideoControls.InsertNewSubtitleAtVideoPositionMax = reader.Value;
break;
case "Main/VideoControls/Auto":
language.Main.VideoControls.Auto = reader.Value;
break;

View File

@ -2069,6 +2069,7 @@
// create/adjust
public string InsertNewSubtitleAtVideoPosition { get; set; }
public string InsertNewSubtitleAtVideoPositionNoTextBoxFocus { get; set; }
public string InsertNewSubtitleAtVideoPositionMax { get; set; }
public string Auto { get; set; }
public string PlayFromJustBeforeText { get; set; }

View File

@ -136,6 +136,7 @@ namespace Nikse.SubtitleEdit.Logic
public Keys MainTextBoxToggleAutoDuration { get; set; }
public Keys MainCreateInsertSubAtVideoPos { get; set; }
public Keys MainCreateInsertSubAtVideoPosNoTextBoxFocus { get; set; }
public Keys MainCreateInsertSubAtVideoPosMax { get; set; }
public Keys MainCreateSetStart { get; set; }
public Keys MainCreateSetEnd { get; set; }
public Keys MainAdjustVideoSetStartForAppropriateLine { get; set; }
@ -453,6 +454,7 @@ namespace Nikse.SubtitleEdit.Logic
MainTextBoxToggleAutoDuration = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainTextBoxToggleAutoDuration);
MainCreateInsertSubAtVideoPos = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainCreateInsertSubAtVideoPos);
MainCreateInsertSubAtVideoPosNoTextBoxFocus = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainCreateInsertSubAtVideoPosNoTextBoxFocus);
MainCreateInsertSubAtVideoPosMax = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainCreateInsertSubAtVideoPosMax);
MainCreateSetStart = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainCreateSetStart);
MainCreateSetEnd = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainCreateSetEnd);
MainAdjustVideoSetStartForAppropriateLine = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainAdjustVideoSetStartForAppropriateLine);