From a23cc80f1d592e5c92d53f5ae6d19042609ae4da Mon Sep 17 00:00:00 2001 From: OmrSi Date: Tue, 16 Aug 2022 18:34:33 +0300 Subject: [PATCH] Add shortcuts to play with 1.5 and 2.0 speed --- LanguageMaster.xml | 2 ++ src/libse/Common/Settings.cs | 16 +++++++++++ src/ui/Controls/VideoPlayerContainer.cs | 6 +++++ src/ui/Forms/Main.cs | 36 +++++++++++++++++++++---- src/ui/Forms/Options/Settings.cs | 2 ++ src/ui/Logic/Language.cs | 2 ++ src/ui/Logic/LanguageDeserializer.cs | 6 +++++ src/ui/Logic/LanguageStructure.cs | 2 ++ src/ui/Logic/MainShortcuts.cs | 4 +++ 9 files changed, 71 insertions(+), 5 deletions(-) diff --git a/LanguageMaster.xml b/LanguageMaster.xml index c94461de3..085cd6cc2 100644 --- a/LanguageMaster.xml +++ b/LanguageMaster.xml @@ -2459,6 +2459,8 @@ can edit in same subtitle file (collaboration) Go to next chapter Select next subtitle (from video position, keep video pos) Toggle play/pause + Play video with 1.5x speed + Play video with 2.0x speed Pause Fullscreen Play rate slower diff --git a/src/libse/Common/Settings.cs b/src/libse/Common/Settings.cs index 8b6ea0ae5..f4e477759 100644 --- a/src/libse/Common/Settings.cs +++ b/src/libse/Common/Settings.cs @@ -2255,6 +2255,8 @@ $HorzAlign = Center public string MainVideoPlayFromJustBefore { get; set; } public string MainVideoPlayFromBeginning { get; set; } public string MainVideoPlayPauseToggle { get; set; } + public string MainVideoPlay150Speed { get; set; } + public string MainVideoPlay200Speed { get; set; } public string MainVideoShowHideVideo { get; set; } public string MainVideoShowWaveform { get; set; } public string MainVideoFoucsSetVideoPosition { get; set; } @@ -8238,6 +8240,18 @@ $HorzAlign = Center shortcuts.MainVideoPlayPauseToggle = subNode.InnerText; } + subNode = node.SelectSingleNode("MainVideoPlay150Speed"); + if (subNode != null) + { + shortcuts.MainVideoPlay150Speed = subNode.InnerText; + } + + subNode = node.SelectSingleNode("MainVideoPlay200Speed"); + if (subNode != null) + { + shortcuts.MainVideoPlay200Speed = subNode.InnerText; + } + subNode = node.SelectSingleNode("MainVideoShowHideVideo"); if (subNode != null) { @@ -10665,6 +10679,8 @@ $HorzAlign = Center textWriter.WriteElementString("MainVideoPlayFromJustBefore", shortcuts.MainVideoPlayFromJustBefore); textWriter.WriteElementString("MainVideoPlayFromBeginning", shortcuts.MainVideoPlayFromBeginning); textWriter.WriteElementString("MainVideoPlayPauseToggle", shortcuts.MainVideoPlayPauseToggle); + textWriter.WriteElementString("MainVideoPlay150Speed", shortcuts.MainVideoPlay150Speed); + textWriter.WriteElementString("MainVideoPlay200Speed", shortcuts.MainVideoPlay200Speed); textWriter.WriteElementString("MainVideoShowHideVideo", shortcuts.MainVideoShowHideVideo); textWriter.WriteElementString("MainVideoShowWaveform", shortcuts.MainVideoShowWaveform); textWriter.WriteElementString("MainVideoFoucsSetVideoPosition", shortcuts.MainVideoFoucsSetVideoPosition); diff --git a/src/ui/Controls/VideoPlayerContainer.cs b/src/ui/Controls/VideoPlayerContainer.cs index 35819ff96..25196acf2 100644 --- a/src/ui/Controls/VideoPlayerContainer.cs +++ b/src/ui/Controls/VideoPlayerContainer.cs @@ -85,6 +85,7 @@ namespace Nikse.SubtitleEdit.Controls private bool _isMuted; private double? _muteOldVolume; + public bool PlayedWithCustomeSpeed; private readonly System.ComponentModel.ComponentResourceManager _resources; public int ControlsHeight = 47; private const int OriginalSubtitlesHeight = 57; @@ -1759,6 +1760,11 @@ namespace Nikse.SubtitleEdit.Controls _pictureBoxPlay.Visible = true; _pictureBoxPlay.BringToFront(); RefreshProgressBar(); + + if (PlayedWithCustomeSpeed) + { + VideoPlayer.PlayRate = 1.0; + } } } diff --git a/src/ui/Forms/Main.cs b/src/ui/Forms/Main.cs index 8b8689243..19e59b236 100644 --- a/src/ui/Forms/Main.cs +++ b/src/ui/Forms/Main.cs @@ -16739,6 +16739,22 @@ namespace Nikse.SubtitleEdit.Forms System.Threading.SynchronizationContext.Current.Post(TimeSpan.FromMilliseconds(1), () => mediaPlayer.TogglePlayPause()); } } + else if (e.KeyData == _shortcuts.VideoPlay150Speed) + { + if (mediaPlayer.VideoPlayer != null) + { + SetPlayRateAndPlay(150); + e.SuppressKeyPress = true; + } + } + else if (e.KeyData == _shortcuts.VideoPlay200Speed) + { + if (mediaPlayer.VideoPlayer != null) + { + SetPlayRateAndPlay(200); + e.SuppressKeyPress = true; + } + } else if (e.KeyData == _shortcuts.VideoPause) { if (mediaPlayer.VideoPlayer != null) @@ -24434,7 +24450,7 @@ namespace Nikse.SubtitleEdit.Forms var backColor = UiUtil.BackColor; for (int i = 30; i <= 300; i += 10) { - toolStripSplitButtonPlayRate.DropDownItems.Add(new ToolStripMenuItem(i + "%", null, SetPlayRate) { Checked = i == 100, BackColor = backColor, ForeColor = foreColor }); + toolStripSplitButtonPlayRate.DropDownItems.Add(new ToolStripMenuItem(i + "%", null, SetPlayRate, i.ToString()) { Checked = i == 100, BackColor = backColor, ForeColor = foreColor }); } } @@ -24446,12 +24462,18 @@ namespace Nikse.SubtitleEdit.Forms } } + private void SetPlayRateAndPlay(int playRate) + { + SetPlayRate(toolStripSplitButtonPlayRate.DropDownItems[playRate.ToString()], null, false, true); + mediaPlayer.Play(); + } + private void SetPlayRate(object sender, EventArgs e) { SetPlayRate(sender, e, false); } - private void SetPlayRate(object sender, EventArgs e, bool skipStatusMessage) + private void SetPlayRate(object sender, EventArgs e, bool skipStatusMessage, bool playedWithCustomeSpeed = false) { if (!(sender is ToolStripMenuItem playRateDropDownItem) || mediaPlayer == null || mediaPlayer.VideoPlayer == null) { @@ -24463,19 +24485,23 @@ namespace Nikse.SubtitleEdit.Forms item.Checked = false; } - playRateDropDownItem.Checked = true; var percentText = playRateDropDownItem.Text.TrimEnd('%'); + var factor = double.Parse(percentText) / 100.0; if (!skipStatusMessage) { ShowStatus(string.Format(_language.SetPlayRateX, percentText)); } - var factor = double.Parse(percentText) / 100.0; - toolStripSplitButtonPlayRate.Image = Math.Abs(factor - 1) < 0.01 ? imageListPlayRate.Images[0] : imageListPlayRate.Images[1]; + if (!playedWithCustomeSpeed) + { + playRateDropDownItem.Checked = true; + toolStripSplitButtonPlayRate.Image = Math.Abs(factor - 1) < 0.01 ? imageListPlayRate.Images[0] : imageListPlayRate.Images[1]; + } try { mediaPlayer.VideoPlayer.PlayRate = factor; + mediaPlayer.PlayedWithCustomeSpeed = playedWithCustomeSpeed; } catch { diff --git a/src/ui/Forms/Options/Settings.cs b/src/ui/Forms/Options/Settings.cs index c2d8a699b..7c8bb15dc 100644 --- a/src/ui/Forms/Options/Settings.cs +++ b/src/ui/Forms/Options/Settings.cs @@ -1340,6 +1340,8 @@ namespace Nikse.SubtitleEdit.Forms.Options AddNode(videoNode, LanguageSettings.Current.Main.Menu.Video.OpenVideo, nameof(Configuration.Settings.Shortcuts.MainVideoOpen), true); AddNode(videoNode, LanguageSettings.Current.Main.Menu.Video.CloseVideo, nameof(Configuration.Settings.Shortcuts.MainVideoClose), true); AddNode(videoNode, language.TogglePlayPause, nameof(Configuration.Settings.Shortcuts.MainVideoPlayPauseToggle)); + AddNode(videoNode, language.Play150Speed, nameof(Configuration.Settings.Shortcuts.MainVideoPlay150Speed)); + AddNode(videoNode, language.Play200Speed, nameof(Configuration.Settings.Shortcuts.MainVideoPlay200Speed)); AddNode(videoNode, language.Pause, nameof(Configuration.Settings.Shortcuts.MainVideoPause)); AddNode(videoNode, LanguageSettings.Current.Main.VideoControls.Stop, nameof(Configuration.Settings.Shortcuts.MainVideoStop)); AddNode(videoNode, LanguageSettings.Current.Main.VideoControls.PlayFromJustBeforeText, nameof(Configuration.Settings.Shortcuts.MainVideoPlayFromJustBefore)); diff --git a/src/ui/Logic/Language.cs b/src/ui/Logic/Language.cs index 62e5e5902..837f7fe41 100644 --- a/src/ui/Logic/Language.cs +++ b/src/ui/Logic/Language.cs @@ -2788,6 +2788,8 @@ can edit in same subtitle file (collaboration)", PlaySelectedLines = "Play selected lines", Pause = "Pause", TogglePlayPause = "Toggle play/pause", + Play150Speed = "Play video with 1.5x speed", + Play200Speed = "Play video with 2.0x speed", Fullscreen = "Fullscreen", PlayRateSlower = "Play rate slower", PlayRateFaster = "Play rate faster", diff --git a/src/ui/Logic/LanguageDeserializer.cs b/src/ui/Logic/LanguageDeserializer.cs index 4ad87baae..789c0650e 100644 --- a/src/ui/Logic/LanguageDeserializer.cs +++ b/src/ui/Logic/LanguageDeserializer.cs @@ -6742,6 +6742,12 @@ namespace Nikse.SubtitleEdit.Logic case "Settings/TogglePlayPause": language.Settings.TogglePlayPause = reader.Value; break; + case "Settings/Play150Speed": + language.Settings.Play150Speed = reader.Value; + break; + case "Settings/Play200Speed": + language.Settings.Play200Speed = reader.Value; + break; case "Settings/Pause": language.Settings.Pause = reader.Value; break; diff --git a/src/ui/Logic/LanguageStructure.cs b/src/ui/Logic/LanguageStructure.cs index a91017b2b..881dc5223 100644 --- a/src/ui/Logic/LanguageStructure.cs +++ b/src/ui/Logic/LanguageStructure.cs @@ -2641,6 +2641,8 @@ public string WaveformGoToNextChapter { get; set; } public string WaveformSelectNextSubtitle { get; set; } public string TogglePlayPause { get; set; } + public string Play150Speed { get; set; } + public string Play200Speed { get; set; } public string Pause { get; set; } public string Fullscreen { get; set; } public string PlayRateSlower { get; set; } diff --git a/src/ui/Logic/MainShortcuts.cs b/src/ui/Logic/MainShortcuts.cs index 77aa9702c..3a267e41a 100644 --- a/src/ui/Logic/MainShortcuts.cs +++ b/src/ui/Logic/MainShortcuts.cs @@ -39,6 +39,8 @@ namespace Nikse.SubtitleEdit.Logic public Keys VideoPause { get; set; } public Keys VideoStop { get; set; } public Keys VideoPlayPauseToggle { get; set; } + public Keys VideoPlay150Speed { get; set; } + public Keys VideoPlay200Speed { get; set; } public Keys MainVideoPlayFromJustBefore { get; set; } public Keys MainVideoPlayFromBeginning { get; set; } public Keys Video1FrameLeft { get; set; } @@ -270,6 +272,8 @@ namespace Nikse.SubtitleEdit.Logic MainVideoFocusSetVideoPosition = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainVideoFoucsSetVideoPosition); ToggleVideoDockUndock = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainVideoToggleVideoControls); VideoPlayPauseToggle = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainVideoPlayPauseToggle); + VideoPlay150Speed = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainVideoPlay150Speed); + VideoPlay200Speed = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainVideoPlay200Speed); Video1FrameLeft = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainVideo1FrameLeft); Video1FrameRight = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainVideo1FrameRight); Video1FrameLeftWithPlay = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainVideo1FrameLeftWithPlay);