mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2025-01-31 21:11:39 +01:00
Add go to time code from video pos shortcuts - thx faon-92 :)
Work on #6729
This commit is contained in:
parent
64e34abab7
commit
f0c10c443c
@ -2523,6 +2523,8 @@ can edit in same subtitle file (collaboration)</Information>
|
||||
<LoopSelectedLines>Loop selected lines</LoopSelectedLines>
|
||||
<WaveformGoToPrevSubtitle>Go to previous subtitle (from video position)</WaveformGoToPrevSubtitle>
|
||||
<WaveformGoToNextSubtitle>Go to next subtitle (from video position)</WaveformGoToNextSubtitle>
|
||||
<WaveformGoToPrevTimeCode>Go to previous time code (from video position)</WaveformGoToPrevTimeCode>
|
||||
<WaveformGoToNextTimeCode>Go to next time code (from video position)</WaveformGoToNextTimeCode>
|
||||
<WaveformGoToPrevChapter>Go to previous chapter</WaveformGoToPrevChapter>
|
||||
<WaveformGoToNextChapter>Go to next chapter</WaveformGoToNextChapter>
|
||||
<WaveformSelectNextSubtitle>Select next subtitle (from video position, keep video pos)</WaveformSelectNextSubtitle>
|
||||
|
@ -2366,6 +2366,8 @@ $HorzAlign = Center
|
||||
public string MainVideoLoopSelectedLines { get; set; }
|
||||
public string MainVideoGoToPrevSubtitle { get; set; }
|
||||
public string MainVideoGoToNextSubtitle { get; set; }
|
||||
public string MainVideoGoToPrevTimeCode { get; set; }
|
||||
public string MainVideoGoToNextTimeCode { get; set; }
|
||||
public string MainVideoGoToPrevChapter { get; set; }
|
||||
public string MainVideoGoToNextChapter { get; set; }
|
||||
public string MainVideoSelectNextSubtitle { get; set; }
|
||||
@ -8818,6 +8820,18 @@ $HorzAlign = Center
|
||||
shortcuts.MainVideoGoToNextSubtitle = subNode.InnerText;
|
||||
}
|
||||
|
||||
subNode = node.SelectSingleNode("MainVideoGoToPrevTimeCode");
|
||||
if (subNode != null)
|
||||
{
|
||||
shortcuts.MainVideoGoToPrevTimeCode = subNode.InnerText;
|
||||
}
|
||||
|
||||
subNode = node.SelectSingleNode("MainVideoGoToNextTimeCode");
|
||||
if (subNode != null)
|
||||
{
|
||||
shortcuts.MainVideoGoToNextTimeCode = subNode.InnerText;
|
||||
}
|
||||
|
||||
subNode = node.SelectSingleNode("MainVideoGoToPrevChapter");
|
||||
if (subNode != null)
|
||||
{
|
||||
@ -11226,6 +11240,8 @@ $HorzAlign = Center
|
||||
textWriter.WriteElementString("MainVideoLoopSelectedLines", shortcuts.MainVideoLoopSelectedLines);
|
||||
textWriter.WriteElementString("MainVideoGoToPrevSubtitle", shortcuts.MainVideoGoToPrevSubtitle);
|
||||
textWriter.WriteElementString("MainVideoGoToNextSubtitle", shortcuts.MainVideoGoToNextSubtitle);
|
||||
textWriter.WriteElementString("MainVideoGoToPrevTimeCode", shortcuts.MainVideoGoToPrevTimeCode);
|
||||
textWriter.WriteElementString("MainVideoGoToNextTimeCode", shortcuts.MainVideoGoToNextTimeCode);
|
||||
textWriter.WriteElementString("MainVideoGoToPrevChapter", shortcuts.MainVideoGoToPrevChapter);
|
||||
textWriter.WriteElementString("MainVideoGoToNextChapter", shortcuts.MainVideoGoToNextChapter);
|
||||
textWriter.WriteElementString("MainVideoSelectNextSubtitle", shortcuts.MainVideoSelectNextSubtitle);
|
||||
|
@ -1836,7 +1836,8 @@ namespace Nikse.SubtitleEdit.Forms.Assa
|
||||
_lastFormWindowState = WindowState;
|
||||
return;
|
||||
}
|
||||
else if (WindowState == FormWindowState.Normal && _lastFormWindowState == FormWindowState.Maximized)
|
||||
|
||||
if (WindowState == FormWindowState.Normal && _lastFormWindowState == FormWindowState.Maximized)
|
||||
{
|
||||
System.Threading.SynchronizationContext.Current.Post(TimeSpan.FromMilliseconds(25), () =>
|
||||
{
|
||||
|
@ -526,7 +526,6 @@ namespace Nikse.SubtitleEdit.Forms.BinaryEdit
|
||||
_extra.Add(new Extra { IsForced = x.IsForced, X = x.GetPosition().Left, Y = x.GetPosition().Top });
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
_subtitle = new Subtitle(sub);
|
||||
|
@ -17379,6 +17379,16 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
GoToNextSubtitle(mediaPlayer.CurrentPosition * TimeCode.BaseUnit);
|
||||
e.SuppressKeyPress = true;
|
||||
}
|
||||
else if (e.KeyData == _shortcuts.VideoGoToPrevTimeCode)
|
||||
{
|
||||
GoToNearestTimeCode(mediaPlayer.CurrentPosition * TimeCode.BaseUnit, false);
|
||||
e.SuppressKeyPress = true;
|
||||
}
|
||||
else if (e.KeyData == _shortcuts.VideoGoToNextTimeCode)
|
||||
{
|
||||
GoToNearestTimeCode(mediaPlayer.CurrentPosition * TimeCode.BaseUnit, true);
|
||||
e.SuppressKeyPress = true;
|
||||
}
|
||||
else if (e.KeyData == _shortcuts.VideoSelectNextSubtitle)
|
||||
{
|
||||
var cp = mediaPlayer.CurrentPosition * TimeCode.BaseUnit;
|
||||
@ -18622,6 +18632,67 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
}
|
||||
}
|
||||
|
||||
private void GoToNearestTimeCode(double currentPosition, bool forward)
|
||||
{
|
||||
var paragraphsStart = forward
|
||||
? _subtitle.Paragraphs.Where(p => p.StartTime.TotalMilliseconds > currentPosition)
|
||||
: _subtitle.Paragraphs.Where(p => p.StartTime.TotalMilliseconds < currentPosition);
|
||||
|
||||
var paragraphsEnd = forward
|
||||
? _subtitle.Paragraphs.Where(p => p.EndTime.TotalMilliseconds > currentPosition)
|
||||
: _subtitle.Paragraphs.Where(p => p.EndTime.TotalMilliseconds < currentPosition);
|
||||
|
||||
var closestStart = paragraphsStart
|
||||
.Select(p => new { Paragraph = p, Distance = Math.Abs(p.StartTime.TotalMilliseconds - currentPosition) })
|
||||
.OrderBy(p => p.Distance)
|
||||
.FirstOrDefault().Paragraph;
|
||||
|
||||
var closestEnd = paragraphsEnd
|
||||
.Select(p => new { Paragraph = p, Distance = Math.Abs(p.EndTime.TotalMilliseconds - currentPosition) })
|
||||
.OrderBy(p => p.Distance)
|
||||
.FirstOrDefault().Paragraph;
|
||||
|
||||
Paragraph found = null;
|
||||
double foundSeconds = 0d;
|
||||
|
||||
if (closestStart != null && (closestEnd == null || Math.Abs(closestStart.StartTime.TotalMilliseconds - currentPosition) <
|
||||
Math.Abs(closestEnd.EndTime.TotalMilliseconds - currentPosition)))
|
||||
{
|
||||
if (closestStart.StartTime.IsMaxTime)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
found = closestStart;
|
||||
foundSeconds = closestStart.StartTime.TotalSeconds;
|
||||
}
|
||||
else if (closestEnd != null && (closestStart == null || Math.Abs(closestStart.StartTime.TotalMilliseconds - currentPosition) >
|
||||
Math.Abs(closestEnd.EndTime.TotalMilliseconds - currentPosition)))
|
||||
{
|
||||
if (closestEnd.EndTime.IsMaxTime)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
found = closestEnd;
|
||||
foundSeconds = closestEnd.EndTime.TotalSeconds;
|
||||
}
|
||||
|
||||
if (found == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
mediaPlayer.CurrentPosition = foundSeconds;
|
||||
SelectListViewIndexAndEnsureVisible(_subtitle.Paragraphs.IndexOf(found));
|
||||
|
||||
Application.DoEvents();
|
||||
if (audioVisualizer.WavePeaks != null && foundSeconds < audioVisualizer.StartPositionSeconds + 0.15)
|
||||
{
|
||||
audioVisualizer.StartPositionSeconds -= 0.15;
|
||||
}
|
||||
}
|
||||
|
||||
private void AutoGuessStartTime(int index)
|
||||
{
|
||||
var p = _subtitle.GetParagraphOrDefault(index);
|
||||
|
@ -1432,6 +1432,8 @@ namespace Nikse.SubtitleEdit.Forms.Options
|
||||
AddNode(videoNode, language.LoopSelectedLines, nameof(Configuration.Settings.Shortcuts.MainVideoLoopSelectedLines));
|
||||
AddNode(videoNode, language.WaveformGoToPrevSubtitle, nameof(Configuration.Settings.Shortcuts.MainVideoGoToPrevSubtitle));
|
||||
AddNode(videoNode, language.WaveformGoToNextSubtitle, nameof(Configuration.Settings.Shortcuts.MainVideoGoToNextSubtitle));
|
||||
AddNode(videoNode, language.WaveformGoToPrevTimeCode, nameof(Configuration.Settings.Shortcuts.MainVideoGoToPrevTimeCode));
|
||||
AddNode(videoNode, language.WaveformGoToNextTimeCode, nameof(Configuration.Settings.Shortcuts.MainVideoGoToNextTimeCode));
|
||||
AddNode(videoNode, language.WaveformGoToPrevChapter, nameof(Configuration.Settings.Shortcuts.MainVideoGoToPrevChapter));
|
||||
AddNode(videoNode, language.WaveformGoToNextChapter, nameof(Configuration.Settings.Shortcuts.MainVideoGoToNextChapter));
|
||||
AddNode(videoNode, language.WaveformSelectNextSubtitle, nameof(Configuration.Settings.Shortcuts.MainVideoSelectNextSubtitle));
|
||||
|
@ -2832,6 +2832,8 @@ can edit in same subtitle file (collaboration)",
|
||||
WaveformPlayFirstSelectedSubtitle = "Play first selected subtitle",
|
||||
WaveformGoToPrevSubtitle = "Go to previous subtitle (from video position)",
|
||||
WaveformGoToNextSubtitle = "Go to next subtitle (from video position)",
|
||||
WaveformGoToPrevTimeCode = "Go to previous time code (from video position)",
|
||||
WaveformGoToNextTimeCode = "Go to next time code (from video position)",
|
||||
WaveformGoToPrevChapter = "Go to previous chapter",
|
||||
WaveformGoToNextChapter = "Go to next chapter",
|
||||
WaveformSelectNextSubtitle = "Select next subtitle (from video position, keep video pos)",
|
||||
|
@ -6910,6 +6910,12 @@ namespace Nikse.SubtitleEdit.Logic
|
||||
case "Settings/WaveformGoToNextSubtitle":
|
||||
language.Settings.WaveformGoToNextSubtitle = reader.Value;
|
||||
break;
|
||||
case "Settings/WaveformGoToPrevTimeCode":
|
||||
language.Settings.WaveformGoToPrevTimeCode = reader.Value;
|
||||
break;
|
||||
case "Settings/WaveformGoToNextTimeCode":
|
||||
language.Settings.WaveformGoToNextTimeCode = reader.Value;
|
||||
break;
|
||||
case "Settings/WaveformGoToPrevChapter":
|
||||
language.Settings.WaveformGoToPrevChapter = reader.Value;
|
||||
break;
|
||||
|
@ -2711,6 +2711,8 @@ namespace Nikse.SubtitleEdit.Logic
|
||||
|
||||
public string WaveformGoToPrevSubtitle { get; set; }
|
||||
public string WaveformGoToNextSubtitle { get; set; }
|
||||
public string WaveformGoToPrevTimeCode { get; set; }
|
||||
public string WaveformGoToNextTimeCode { get; set; }
|
||||
public string WaveformGoToPrevChapter { get; set; }
|
||||
public string WaveformGoToNextChapter { get; set; }
|
||||
public string WaveformSelectNextSubtitle { get; set; }
|
||||
|
@ -68,6 +68,8 @@ namespace Nikse.SubtitleEdit.Logic
|
||||
public Keys MainVideoLoopSelectedLines { get; set; }
|
||||
public Keys VideoGoToPrevSubtitle { get; set; }
|
||||
public Keys VideoGoToNextSubtitle { get; set; }
|
||||
public Keys VideoGoToPrevTimeCode { get; set; }
|
||||
public Keys VideoGoToNextTimeCode { get; set; }
|
||||
public Keys VideoGoToPrevChapter { get; set; }
|
||||
public Keys VideoGoToNextChapter { get; set; }
|
||||
public Keys VideoSelectNextSubtitle { get; set; }
|
||||
@ -308,6 +310,8 @@ namespace Nikse.SubtitleEdit.Logic
|
||||
MainVideoLoopSelectedLines = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainVideoLoopSelectedLines);
|
||||
VideoGoToPrevSubtitle = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainVideoGoToPrevSubtitle);
|
||||
VideoGoToNextSubtitle = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainVideoGoToNextSubtitle);
|
||||
VideoGoToPrevTimeCode = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainVideoGoToPrevTimeCode);
|
||||
VideoGoToNextTimeCode = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainVideoGoToNextTimeCode);
|
||||
VideoGoToPrevChapter = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainVideoGoToPrevChapter);
|
||||
VideoGoToNextChapter = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainVideoGoToNextChapter);
|
||||
VideoSelectNextSubtitle = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainVideoSelectNextSubtitle);
|
||||
|
Loading…
x
Reference in New Issue
Block a user