From b7856039aa27f6e2abf2df2c5b8bfa6528cdce53 Mon Sep 17 00:00:00 2001 From: OmrSi Date: Tue, 16 Aug 2022 22:20:08 +0300 Subject: [PATCH 1/2] Try looping all selected lines Add `Loop selected line` shortcut Fix --- LanguageMaster.xml | 1 + src/libse/Common/Settings.cs | 8 ++++ src/ui/Forms/Main.cs | 55 ++++++++++++++++++++-------- src/ui/Forms/Options/Settings.cs | 1 + src/ui/Logic/Language.cs | 1 + src/ui/Logic/LanguageDeserializer.cs | 3 ++ src/ui/Logic/LanguageStructure.cs | 1 + src/ui/Logic/MainShortcuts.cs | 2 + 8 files changed, 56 insertions(+), 16 deletions(-) diff --git a/LanguageMaster.xml b/LanguageMaster.xml index ca15ce95e..575e864dc 100644 --- a/LanguageMaster.xml +++ b/LanguageMaster.xml @@ -2453,6 +2453,7 @@ can edit in same subtitle file (collaboration) Set video pos to start of current subtitle Toggle video pos between start/end of current subtitle Play selected lines + Loop selected line Go to previous subtitle (from video position) Go to next subtitle (from video position) Go to previous chapter diff --git a/src/libse/Common/Settings.cs b/src/libse/Common/Settings.cs index fac7350f8..4a08d4628 100644 --- a/src/libse/Common/Settings.cs +++ b/src/libse/Common/Settings.cs @@ -2282,6 +2282,7 @@ $HorzAlign = Center public string MainVideoGoToStartCurrent { get; set; } public string MainVideoToggleStartEndCurrent { get; set; } public string MainVideoPlaySelectedLines { get; set; } + public string MainVideoLoopSelectedLines { get; set; } public string MainVideoGoToPrevSubtitle { get; set; } public string MainVideoGoToNextSubtitle { get; set; } public string MainVideoGoToPrevChapter { get; set; } @@ -8403,6 +8404,12 @@ $HorzAlign = Center shortcuts.MainVideoPlaySelectedLines = subNode.InnerText; } + subNode = node.SelectSingleNode("MainVideoLoopSelectedLines"); + if (subNode != null) + { + shortcuts.MainVideoLoopSelectedLines = subNode.InnerText; + } + subNode = node.SelectSingleNode("MainVideoGoToPrevSubtitle"); if (subNode != null) { @@ -10713,6 +10720,7 @@ $HorzAlign = Center textWriter.WriteElementString("MainVideoGoToStartCurrent", shortcuts.MainVideoGoToStartCurrent); textWriter.WriteElementString("MainVideoToggleStartEndCurrent", shortcuts.MainVideoToggleStartEndCurrent); textWriter.WriteElementString("MainVideoPlaySelectedLines", shortcuts.MainVideoPlaySelectedLines); + textWriter.WriteElementString("MainVideoLoopSelectedLines", shortcuts.MainVideoLoopSelectedLines); textWriter.WriteElementString("MainVideoGoToPrevSubtitle", shortcuts.MainVideoGoToPrevSubtitle); textWriter.WriteElementString("MainVideoGoToNextSubtitle", shortcuts.MainVideoGoToNextSubtitle); textWriter.WriteElementString("MainVideoGoToPrevChapter", shortcuts.MainVideoGoToPrevChapter); diff --git a/src/ui/Forms/Main.cs b/src/ui/Forms/Main.cs index 853066db1..a895cffd5 100644 --- a/src/ui/Forms/Main.cs +++ b/src/ui/Forms/Main.cs @@ -8748,7 +8748,7 @@ namespace Nikse.SubtitleEdit.Forms var audioToText = new ToolStripMenuItem(LanguageSettings.Current.Main.Menu.Video.VideoAudioToText); UiUtil.FixFonts(audioToText); audio.DropDownItems.Insert(0, audioClip); - + if (Configuration.IsRunningOnWindows) { audio.DropDownItems.Insert(0, audioToText); @@ -10178,6 +10178,13 @@ namespace Nikse.SubtitleEdit.Forms private void SubtitleListview1_SelectedIndexChanged(object sender, EventArgs e) { + if (_playSelectionIndexLoopStart >= 0) + { + _endSeconds = -1; + _playSelectionIndex = -1; + _playSelectionIndexLoopStart = -1; + } + if (SubtitleListview1.SelectedIndices.Count == 0) { _listViewTextUndoIndex = -1; @@ -16760,7 +16767,7 @@ namespace Nikse.SubtitleEdit.Forms mediaPlayer.Pause(); } - e.SuppressKeyPress = true; + e.SuppressKeyPress = true; } } else if (e.KeyData == _shortcuts.VideoPlay200Speed) @@ -16904,16 +16911,16 @@ namespace Nikse.SubtitleEdit.Forms { if (SubtitleListview1.SelectedItems.Count > 0 && _subtitle != null && mediaPlayer.VideoPlayer != null) { - var p = _subtitle.GetParagraphOrDefault(SubtitleListview1.SelectedItems[0].Index); - if (p != null) - { - mediaPlayer.CurrentPosition = p.StartTime.TotalSeconds; - ShowSubtitle(); - mediaPlayer.Play(); - _endSeconds = p.EndTime.TotalSeconds; - _playSelectionIndex = _subtitle.GetIndex(p); - _playSelectionIndexLoopStart = -1; - } + PlaySelectedLines(false); + } + + e.SuppressKeyPress = true; + } + else if (_shortcuts.MainVideoLoopSelectedLines == e.KeyData) + { + if (SubtitleListview1.SelectedItems.Count > 0 && _subtitle != null && mediaPlayer.VideoPlayer != null) + { + PlaySelectedLines(true); } e.SuppressKeyPress = true; @@ -22198,7 +22205,7 @@ namespace Nikse.SubtitleEdit.Forms { var first = _subtitle.GetParagraphOrDefault(_playSelectionIndexLoopStart); if (first != null) - { // nixe harboe debug + { _endSeconds = first.EndTime.TotalSeconds; mediaPlayer.CurrentPosition = first.StartTime.TotalSeconds; System.Threading.SynchronizationContext.Current.Post(TimeSpan.FromMilliseconds(151), () => @@ -22324,8 +22331,6 @@ namespace Nikse.SubtitleEdit.Forms } ShowSubtitleTimer.Start(); - - Text = "EndSeconds=" + _endSeconds + " startIdx=" + _playSelectionIndexLoopStart + " Idx=" + _playSelectionIndex; } private void AddTitleBarChangeAsterisk(bool currentChanged, bool originalChanged, bool originalActive) @@ -22953,6 +22958,24 @@ namespace Nikse.SubtitleEdit.Forms } } + private void PlaySelectedLines(bool loop) + { + var p = _subtitle.GetParagraphOrDefault(SubtitleListview1.SelectedItems[0].Index); + if (p != null) + { + mediaPlayer.CurrentPosition = p.StartTime.TotalSeconds; + ShowSubtitle(); + mediaPlayer.Play(); + _endSeconds = p.EndTime.TotalSeconds; + _playSelectionIndex = _subtitle.GetIndex(p); + + if (loop) + { + _playSelectionIndexLoopStart = SubtitleListview1.SelectedItems[0].Index; + } + } + } + private void buttonSetStartTime_Click(object sender, EventArgs e) { SetStartTime(false, mediaPlayer.CurrentPosition); @@ -23802,7 +23825,7 @@ namespace Nikse.SubtitleEdit.Forms { if (!string.IsNullOrEmpty(_fileName) && File.Exists(_fileName)) { - UiUtil.OpenFolderFromFileName(_fileName); + UiUtil.OpenFolderFromFileName(_fileName); } } diff --git a/src/ui/Forms/Options/Settings.cs b/src/ui/Forms/Options/Settings.cs index c62965a0e..3e83c3670 100644 --- a/src/ui/Forms/Options/Settings.cs +++ b/src/ui/Forms/Options/Settings.cs @@ -1371,6 +1371,7 @@ namespace Nikse.SubtitleEdit.Forms.Options AddNode(videoNode, language.GoToStartCurrent, nameof(Configuration.Settings.Shortcuts.MainVideoGoToStartCurrent)); AddNode(videoNode, language.ToggleStartEndCurrent, nameof(Configuration.Settings.Shortcuts.MainVideoToggleStartEndCurrent)); AddNode(videoNode, language.PlaySelectedLines, nameof(Configuration.Settings.Shortcuts.MainVideoPlaySelectedLines)); + 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.WaveformGoToPrevChapter, nameof(Configuration.Settings.Shortcuts.MainVideoGoToPrevChapter)); diff --git a/src/ui/Logic/Language.cs b/src/ui/Logic/Language.cs index 62b985c8a..fd85c602b 100644 --- a/src/ui/Logic/Language.cs +++ b/src/ui/Logic/Language.cs @@ -2786,6 +2786,7 @@ can edit in same subtitle file (collaboration)", GoToStartCurrent = "Set video pos to start of current subtitle", ToggleStartEndCurrent = "Toggle video pos between start/end of current subtitle", PlaySelectedLines = "Play selected lines", + LoopSelectedLines = "Loop selected line", Pause = "Pause", TogglePlayPause = "Toggle play/pause", Play150Speed = "Play video with 1.5x speed", diff --git a/src/ui/Logic/LanguageDeserializer.cs b/src/ui/Logic/LanguageDeserializer.cs index 789c0650e..a44fb6c26 100644 --- a/src/ui/Logic/LanguageDeserializer.cs +++ b/src/ui/Logic/LanguageDeserializer.cs @@ -6724,6 +6724,9 @@ namespace Nikse.SubtitleEdit.Logic case "Settings/PlaySelectedLines": language.Settings.PlaySelectedLines = reader.Value; break; + case "Settings/LoopSelectedLines": + language.Settings.LoopSelectedLines = reader.Value; + break; case "Settings/WaveformGoToPrevSubtitle": language.Settings.WaveformGoToPrevSubtitle = reader.Value; break; diff --git a/src/ui/Logic/LanguageStructure.cs b/src/ui/Logic/LanguageStructure.cs index 881dc5223..baea85db0 100644 --- a/src/ui/Logic/LanguageStructure.cs +++ b/src/ui/Logic/LanguageStructure.cs @@ -2634,6 +2634,7 @@ public string GoToStartCurrent { get; set; } public string ToggleStartEndCurrent { get; set; } public string PlaySelectedLines { get; set; } + public string LoopSelectedLines { get; set; } public string WaveformGoToPrevSubtitle { get; set; } public string WaveformGoToNextSubtitle { get; set; } diff --git a/src/ui/Logic/MainShortcuts.cs b/src/ui/Logic/MainShortcuts.cs index 3a267e41a..303c7888c 100644 --- a/src/ui/Logic/MainShortcuts.cs +++ b/src/ui/Logic/MainShortcuts.cs @@ -63,6 +63,7 @@ namespace Nikse.SubtitleEdit.Logic public Keys MainVideoGoToStartCurrent { get; set; } public Keys MainVideoToggleStartEndCurrent { get; set; } public Keys MainVideoPlaySelectedLines { get; set; } + public Keys MainVideoLoopSelectedLines { get; set; } public Keys VideoGoToPrevSubtitle { get; set; } public Keys VideoGoToNextSubtitle { get; set; } public Keys VideoGoToPrevChapter { get; set; } @@ -294,6 +295,7 @@ namespace Nikse.SubtitleEdit.Logic MainVideoGoToStartCurrent = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainVideoGoToStartCurrent); MainVideoToggleStartEndCurrent = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainVideoToggleStartEndCurrent); MainVideoPlaySelectedLines = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainVideoPlaySelectedLines); + MainVideoLoopSelectedLines = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainVideoLoopSelectedLines); VideoGoToPrevSubtitle = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainVideoGoToPrevSubtitle); VideoGoToNextSubtitle = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainVideoGoToNextSubtitle); VideoGoToPrevChapter = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainVideoGoToPrevChapter); From 7104e17de0be86ecb6231d31c1d709208b913efd Mon Sep 17 00:00:00 2001 From: OmrSi Date: Thu, 18 Aug 2022 01:39:39 +0300 Subject: [PATCH 2/2] Reset loop when paused via video click --- src/ui/Controls/VideoPlayerContainer.cs | 3 +++ src/ui/Forms/Main.cs | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/src/ui/Controls/VideoPlayerContainer.cs b/src/ui/Controls/VideoPlayerContainer.cs index 25196acf2..c685e2ff6 100644 --- a/src/ui/Controls/VideoPlayerContainer.cs +++ b/src/ui/Controls/VideoPlayerContainer.cs @@ -46,6 +46,7 @@ namespace Nikse.SubtitleEdit.Controls public event EventHandler OnButtonClicked; public event EventHandler OnEmptyPlayerClicked; + public event EventHandler OnPlayerClicked; public Panel PanelPlayer { get; private set; } private Panel _panelSubtitle; @@ -366,6 +367,7 @@ namespace Nikse.SubtitleEdit.Controls private void SubtitleTextBoxMouseClick(object sender, MouseEventArgs e) { TogglePlayPause(); + OnPlayerClicked?.Invoke(sender, e); } public Paragraph LastParagraph { get; set; } @@ -581,6 +583,7 @@ namespace Nikse.SubtitleEdit.Controls } TogglePlayPause(); + OnPlayerClicked?.Invoke(sender, e); } public void InitializeVolume(double defaultVolume) diff --git a/src/ui/Forms/Main.cs b/src/ui/Forms/Main.cs index a895cffd5..871a91a7f 100644 --- a/src/ui/Forms/Main.cs +++ b/src/ui/Forms/Main.cs @@ -24285,6 +24285,7 @@ namespace Nikse.SubtitleEdit.Forms LoadPlugins(); mediaPlayer.OnEmptyPlayerClicked += MediaPlayer_OnEmptyPlayerClicked; + mediaPlayer.OnPlayerClicked += MediaPlayer_OnPlayerClicked; SubtitleListview1.SelectIndexAndEnsureVisible(_subtitleListViewIndex, true); if (Configuration.Settings.General.StartInSourceView) { @@ -24548,6 +24549,13 @@ namespace Nikse.SubtitleEdit.Forms } } + private void MediaPlayer_OnPlayerClicked(object sender, EventArgs e) + { + _endSeconds = -1; + _playSelectionIndex = -1; + _playSelectionIndexLoopStart = -1; + } + private void SetPlayRateAndPlay(int playRate) { SetPlayRate(toolStripSplitButtonPlayRate.DropDownItems[playRate.ToString()], null, false, true);