From 4492a423b458562bf4e19b6a20ccf3f8479ebfdd Mon Sep 17 00:00:00 2001 From: Frank Skare Date: Sat, 6 Apr 2019 16:03:46 +0200 Subject: [PATCH] - --- README.md | 8 ++- mpv.net/Command.cs | 31 +++++++++++ mpv.net/MainForm.Designer.cs | 2 +- mpv.net/MainForm.cs | 55 +++++++++++++------ mpv.net/Properties/AssemblyInfo.cs | 4 +- mpv.net/Resources/input.conf.txt | 4 ++ mpv.net/mp.cs | 20 +++++-- mpvConfEdit/MainWindow.xaml.cs | 4 -- mpvInputEdit/MainWindow.xaml | 2 +- mpvInputEdit/MainWindow.xaml.cs | 6 +- mpvInputEdit/SearchTextBoxUserControl.xaml.cs | 2 +- 11 files changed, 100 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index 60bd598..5688ff5 100644 --- a/README.md +++ b/README.md @@ -70,12 +70,16 @@ https://github.com/stax76/mpv.net/wiki/Scripting-(CSharp,-Python,-JavaScript,-Lu ### Changelog -### 2.4 (2019-0?-??) +### 2.4 (2019-04-06) - new options added to the conf GUI editor: gpu-context, gpu-api, scale, cscale, dscale, dither-depth, correct-downscaling, sigmoid-upscaling, deband - the conf edit GUI has a 'Apply' feature added to write the conf to mpv.conf without the need to close the conf edit GUI -- the input edit GUI shows a message box when a duplicate is detected and it has a new feature to narrow the filter scope to eather of input, menu or command and the editor writes always the same help on top of input.conf as it is found in the defaults +- the input edit GUI shows a message box when a duplicate is detected and it has a new feature to reduce the filter scope to eather of input, menu or command and the editor writes always the same help on top of input.conf as it is found in the defaults - the conf edit GUI was often starting out of working area bounds and is now starting with center screen +- the startup size was reduced and a issue was fixed that when the screen property was defined for a screen that isn't connected the startup size wasn't applied +- added feature to load external audio and subtitle files in the menu under: Open > Load external audio|subtitle files (default binding at: [input.conf](https://github.com/stax76/mpv.net/blob/master/mpv.net/Resources/input.conf.txt)) +- previously the conf edit GUI removed settings from the conf file if the setting was set to the default, the new behavior is not to remove anything +- the autofit mpv property was partly implemented, you can use 'autofit = 50%' in mpv.conf or '--autofit=50%' on the command line, WxH isn't implemented and only percent values are accepted. There is a new wiki page explaining limitations compared to the original mpv: ### 2.3 (2019-04-04) diff --git a/mpv.net/Command.cs b/mpv.net/Command.cs index b08f41f..24246e8 100644 --- a/mpv.net/Command.cs +++ b/mpv.net/Command.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; +using System.Threading.Tasks; using System.Windows.Forms; namespace mpvnet @@ -187,5 +188,35 @@ namespace mpvnet mp.LoadURL(command); })); } + + public static void load_sub(string[] args) + { + MainForm.Instance.BeginInvoke(new Action(() => { + using (var d = new OpenFileDialog()) + { + d.InitialDirectory = Path.GetDirectoryName(mp.get_property_string("path", false)); + d.Multiselect = true; + + if (d.ShowDialog() == DialogResult.OK) + foreach (string i in d.FileNames) + mp.commandv("sub-add", i); + } + })); + } + + public static void load_audio(string[] args) + { + MainForm.Instance.BeginInvoke(new Action(() => { + using (var d = new OpenFileDialog()) + { + d.InitialDirectory = Path.GetDirectoryName(mp.get_property_string("path", false)); + d.Multiselect = true; + + if (d.ShowDialog() == DialogResult.OK) + foreach (string i in d.FileNames) + mp.commandv("audio-add", i); + } + })); + } } } \ No newline at end of file diff --git a/mpv.net/MainForm.Designer.cs b/mpv.net/MainForm.Designer.cs index 9df65ec..3719edb 100644 --- a/mpv.net/MainForm.Designer.cs +++ b/mpv.net/MainForm.Designer.cs @@ -45,7 +45,7 @@ this.AutoScaleDimensions = new System.Drawing.SizeF(288F, 288F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; this.BackColor = System.Drawing.Color.Black; - this.ClientSize = new System.Drawing.Size(1012, 615); + this.ClientSize = new System.Drawing.Size(606, 368); this.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); diff --git a/mpv.net/MainForm.cs b/mpv.net/MainForm.cs index 366359b..853b854 100644 --- a/mpv.net/MainForm.cs +++ b/mpv.net/MainForm.cs @@ -14,8 +14,11 @@ namespace mpvnet public static IntPtr Hwnd; private Point LastCursorPosChanged; - private int LastCursorChangedTickCount; - private bool IgnoreDpiChanged = true; + private int LastCursorChangedTickCount; + private bool IgnoreDpiChanged = true; + private float mpvAutofit = 0.42f; + private bool mpvFullscreen; + private int mpvScreen = -1; public ContextMenuStripEx CMS; @@ -32,15 +35,15 @@ namespace mpvnet MinimumSize = new Size(FontHeight * 16, FontHeight * 9); Text += " " + Application.ProductVersion; - if (mp.mpvConf.ContainsKey("screen")) - SetScreen(Convert.ToInt32(mp.mpvConf["screen"])); - else - SetScreen(Screen.PrimaryScreen); - - ChangeFullscreen((mp.mpvConf.ContainsKey("fullscreen") && mp.mpvConf["fullscreen"] == "yes") || - (mp.mpvConf.ContainsKey("fs") && mp.mpvConf["fs"] == "yes")); + foreach (var i in mp.mpvConf) + ProcessMpvProperty(i.Key, i.Value); ProcessCommandLineEarly(); + + if (mpvScreen == -1) mpvScreen = Array.IndexOf(Screen.AllScreens, Screen.PrimaryScreen); + SetScreen(mpvScreen); + + ChangeFullscreen(mpvFullscreen); } catch (Exception e) { @@ -51,7 +54,8 @@ namespace mpvnet protected void SetScreen(int targetIndex) { Screen[] screens = Screen.AllScreens; - if (targetIndex < 0 || targetIndex > screens.Length - 1) return; + if (targetIndex < 0) targetIndex = 0; + if (targetIndex > screens.Length - 1) targetIndex = screens.Length - 1; SetScreen(screens[Array.IndexOf(screens, screens[targetIndex])]); } @@ -67,7 +71,7 @@ namespace mpvnet { if (IsFullscreen || mp.VideoSize.Width == 0) return; Screen screen = Screen.FromControl(this); - int height = Convert.ToInt32(screen.Bounds.Height * 0.6); + int height = Convert.ToInt32(screen.Bounds.Height * mpvAutofit); int width = Convert.ToInt32(height * mp.VideoSize.Width / (double)mp.VideoSize.Height); Point middlePos = new Point(Left + Width / 2, Top + Height / 2); var rect = new Native.RECT(new Rectangle(screen.Bounds.X, screen.Bounds.Y, width, height)); @@ -82,7 +86,7 @@ namespace mpvnet if (IsFullscreen || mp.VideoSize.Width == 0) return; Screen screen = Screen.FromControl(this); int height = ClientSize.Height; - if (height > screen.Bounds.Height * 0.8) height = Convert.ToInt32(screen.Bounds.Height * 0.6); + if (height > screen.Bounds.Height * 0.9) height = Convert.ToInt32(screen.Bounds.Height * mpvAutofit); int width = Convert.ToInt32(height * mp.VideoSize.Width / (double)mp.VideoSize.Height); Point middlePos = new Point(Left + Width / 2, Top + Height / 2); var rect = new Native.RECT(new Rectangle(screen.Bounds.X, screen.Bounds.Y, width, height)); @@ -108,11 +112,7 @@ namespace mpvnet { string left = i.Substring(2, i.IndexOf("=") - 2); string right = i.Substring(left.Length + 3); - - if (left == "screen") - SetScreen(Convert.ToInt32(right)); - - ChangeFullscreen((left == "fs" || left == "fullscreen") && right == "yes"); + ProcessMpvProperty(left, right); } else { @@ -122,7 +122,7 @@ namespace mpvnet { case "fs": case "fullscreen": - ChangeFullscreen(true); + mpvFullscreen = true; break; } } @@ -130,6 +130,25 @@ namespace mpvnet } } + void ProcessMpvProperty(string name, string value) + { + switch (name) + { + case "autofit": + if (value.Length == 3 && value.EndsWith("%")) + if (int.TryParse(value.Substring(0, 2), out int result)) + mpvAutofit = result / 100f; + break; + case "fs": + case "fullscreen": + mpvFullscreen = value == "yes"; + break; + case "screen": + mpvScreen = Convert.ToInt32(value); + break; + } + } + public void BuildMenu() { foreach (var i in File.ReadAllText(mp.InputConfPath).Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)) diff --git a/mpv.net/Properties/AssemblyInfo.cs b/mpv.net/Properties/AssemblyInfo.cs index d56f1df..bda9886 100644 --- a/mpv.net/Properties/AssemblyInfo.cs +++ b/mpv.net/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.3.0.0")] -[assembly: AssemblyFileVersion("2.3.0.0")] +[assembly: AssemblyVersion("2.4.0.0")] +[assembly: AssemblyFileVersion("2.4.0.0")] diff --git a/mpv.net/Resources/input.conf.txt b/mpv.net/Resources/input.conf.txt index e3bd301..6b060fd 100644 --- a/mpv.net/Resources/input.conf.txt +++ b/mpv.net/Resources/input.conf.txt @@ -26,6 +26,10 @@ o script-message mpv.net open-files #menu: Open > Open Files... u script-message mpv.net open-url #menu: Open > Open URL... + _ ignore #menu: Open > - + Alt+a script-message mpv.net load-audio #menu: Open > Load external audio files... + Alt+s script-message mpv.net load-sub #menu: Open > Load external subtitle files... + _ ignore #menu: - Space cycle pause #menu: Play/Pause s stop #menu: Stop diff --git a/mpv.net/mp.cs b/mpv.net/mp.cs index 615a2ea..59e885d 100644 --- a/mpv.net/mp.cs +++ b/mpv.net/mp.cs @@ -360,15 +360,23 @@ namespace mpvnet public static string get_property_string(string name, bool throwOnException = false) { - int err = mpv_get_property(MpvHandle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_STRING, out IntPtr lpBuffer); + try + { + int err = mpv_get_property(MpvHandle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_STRING, out IntPtr lpBuffer); - if (err < 0 && throwOnException) - throw new Exception($"{name}: {(mpv_error)err}"); + if (err < 0 && throwOnException) + throw new Exception($"{name}: {(mpv_error)err}"); - var ret = StringFromNativeUtf8(lpBuffer); - mpv_free(lpBuffer); + var ret = StringFromNativeUtf8(lpBuffer); + mpv_free(lpBuffer); - return ret; + return ret; + } + catch (Exception ex) + { + if (throwOnException) throw ex; + return ""; + } } public static int get_property_int(string name, bool throwOnException = false) diff --git a/mpvConfEdit/MainWindow.xaml.cs b/mpvConfEdit/MainWindow.xaml.cs index 2e50fb3..a889a2d 100644 --- a/mpvConfEdit/MainWindow.xaml.cs +++ b/mpvConfEdit/MainWindow.xaml.cs @@ -91,14 +91,10 @@ namespace mpvConfEdit case StringSetting s: if ((s.Value ?? "") != s.Default) mpvConf[s.Name] = s.Value; - else - mpvConf.Remove(s.Name); break; case OptionSetting s: if ((s.Value ?? "") != s.Default) mpvConf[s.Name] = s.Value; - else - mpvConf.Remove(s.Name); break; } } diff --git a/mpvInputEdit/MainWindow.xaml b/mpvInputEdit/MainWindow.xaml index 00dc1c4..fdf76fb 100644 --- a/mpvInputEdit/MainWindow.xaml +++ b/mpvInputEdit/MainWindow.xaml @@ -14,7 +14,7 @@ - + diff --git a/mpvInputEdit/MainWindow.xaml.cs b/mpvInputEdit/MainWindow.xaml.cs index 05635dc..d81d9c1 100644 --- a/mpvInputEdit/MainWindow.xaml.cs +++ b/mpvInputEdit/MainWindow.xaml.cs @@ -37,7 +37,7 @@ namespace mpvInputEdit string searchText = SearchControl.SearchTextBox.Text.ToLower(); if (searchText == "") return true; - if (searchText.StartsWith("i ")) + if (searchText.StartsWith("i ") || searchText.StartsWith("i:")) { searchText = searchText.Substring(2).Trim(); @@ -45,9 +45,9 @@ namespace mpvInputEdit return item.Input.ToLower().Replace("ctrl+", "").Replace("shift+", "").Replace("alt+", "").Contains(searchText); else return item.Input.ToLower().Contains(searchText); - } else if (searchText.StartsWith("m ")) + } else if (searchText.StartsWith("m ") || searchText.StartsWith("m:")) return item.Menu.ToLower().Contains(searchText.Substring(2).Trim()); - else if (searchText.StartsWith("c ")) + else if (searchText.StartsWith("c ") || searchText.StartsWith("c:")) return item.Command.ToLower().Contains(searchText.Substring(2).Trim()); else if (item.Command.ToLower().Contains(searchText) || item.Menu.ToLower().Contains(searchText) || diff --git a/mpvInputEdit/SearchTextBoxUserControl.xaml.cs b/mpvInputEdit/SearchTextBoxUserControl.xaml.cs index c4b3596..41e55fe 100644 --- a/mpvInputEdit/SearchTextBoxUserControl.xaml.cs +++ b/mpvInputEdit/SearchTextBoxUserControl.xaml.cs @@ -29,7 +29,7 @@ namespace Controls SearchClearButton.Visibility = Visibility.Visible; if (SearchTextBox.Text == "?") - MessageBox.Show("Use i, m or c to set the filter scope to Input, Menu or Command.", "Filter", MessageBoxButton.OK, MessageBoxImage.Information); + MessageBox.Show("Filtering works by searching in the Input, Menu and Command but it's possible to reduce the filter scope to either of Input, Menu or Command by prefixing as follows:\n\ni \ni: \n\nm \nm: \n\nc \nc: ", "Filtering", MessageBoxButton.OK, MessageBoxImage.Information); } } } \ No newline at end of file