From 6337818dbcd937bf57a78c3981272738dbc77ed1 Mon Sep 17 00:00:00 2001 From: stax76 Date: Wed, 8 Jun 2022 10:16:40 +0200 Subject: [PATCH] New options `autofit-image` and `autofit-audio` --- docs/Changelog.md | 5 +++++ docs/Manual.md | 9 ++++++++ src/Misc/App.cs | 4 ++++ src/Misc/MainForm.cs | 7 ++++++ src/Misc/Misc.cs | 14 +++++++++++- src/Misc/Player.cs | 42 ++++++++++++++++++++++------------- src/Resources/editor_conf.txt | 12 ++++++++++ 7 files changed, 77 insertions(+), 16 deletions(-) diff --git a/docs/Changelog.md b/docs/Changelog.md index 7fb3f45..98f6b34 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -1,4 +1,9 @@ +- New options `autofit-image` and `autofit-audio`, like + autofit but used for image and audio files. Default 80. +- Fix long commands causing key bindings not visible in the + command palette. + # 6.0.0.0 Beta (2022-06-05) - The options `cache` and `demuxer-max-bytes`have been added diff --git a/docs/Manual.md b/docs/Manual.md index 98874ad..bf295e1 100644 --- a/docs/Manual.md +++ b/docs/Manual.md @@ -282,6 +282,9 @@ Registers the file associations. ### scale-window \ Decreases or increases the Window size. +### select-profile +Shows the command palette to select a profile. + ### shell-execute \ Shell executes a single file or URL. @@ -381,6 +384,12 @@ mpv.net specific options can be found in the conf editor searching for 'mpv.net' The options are saved in the mpvnet.conf file. +#### --autofit-audio \ +Initial window height in percent for audio files. Default: 80 + +#### --autofit-image \ +Initial window height in percent for image files. Default: 80 + #### --queue \ Adds files to the playlist, requires [--process-instance=single](#--process-instancevalue). diff --git a/src/Misc/App.cs b/src/Misc/App.cs index bfe7852..847d640 100644 --- a/src/Misc/App.cs +++ b/src/Misc/App.cs @@ -36,6 +36,8 @@ namespace mpvnet public static int StartThreshold { get; set; } = 1500; public static int RecentCount { get; set; } = 15; + public static float AutofitAudio { get; set; } = 0.8f; + public static float AutofitImage { get; set; } = 0.8f; public static float MinimumAspectRatio { get; set; } public static float QuickBookmark { get; set; } @@ -241,6 +243,8 @@ namespace mpvnet case "audio-file-extensions": CorePlayer.AudioTypes = value.Split(" ,;".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); return true; case "auto-load-folder": AutoLoadFolder = value == "yes"; return true; case "auto-play": AutoPlay = value == "yes"; return true; + case "autofit-image": AutofitImage = value.Trim('%').ToInt() / 100f; return true; + case "autofit-audio": AutofitAudio = value.Trim('%').ToInt() / 100f; return true; case "dark-mode": DarkMode = value; return true; case "dark-theme": DarkTheme = value.Trim('\'', '"'); return true; case "debug-mode": DebugMode = value == "yes"; return true; diff --git a/src/Misc/MainForm.cs b/src/Misc/MainForm.cs index 92090dd..7eef852 100644 --- a/src/Misc/MainForm.cs +++ b/src/Misc/MainForm.cs @@ -1,6 +1,7 @@  using System; using System.Collections.Generic; +using System.Diagnostics; using System.Drawing; using System.Globalization; using System.Linq; @@ -433,6 +434,12 @@ namespace mpvnet Screen screen = Screen.FromControl(this); int autoFitHeight = Convert.ToInt32(screen.WorkingArea.Height * Core.Autofit); + if (App.AutofitAudio > 1) App.AutofitAudio = 1; + if (App.AutofitImage > 1) App.AutofitImage = 1; + + if (Core.IsAudio) autoFitHeight = Convert.ToInt32(screen.WorkingArea.Height * App.AutofitAudio); + if (Core.IsImage) autoFitHeight = Convert.ToInt32(screen.WorkingArea.Height * App.AutofitImage); + if (Core.VideoSize.Height == 0 || Core.VideoSize.Width == 0 || Core.VideoSize.Width / (float)Core.VideoSize.Height < App.MinimumAspectRatio) diff --git a/src/Misc/Misc.cs b/src/Misc/Misc.cs index 55aedd6..11b032d 100644 --- a/src/Misc/Misc.cs +++ b/src/Misc/Misc.cs @@ -146,7 +146,19 @@ namespace mpvnet public string Path { get; set; } = ""; public string Command { get; set; } = ""; - public string Display { get { return string.IsNullOrEmpty(Path) ? Command : Path; } } + + public string Display { + get { + if (string.IsNullOrEmpty(Path)) + { + if (Command.Length > 50) + return Command.Substring(0, 50) + "..."; + return Command; + } + else + return Path; + } + } public CommandItem() { } diff --git a/src/Misc/Player.cs b/src/Misc/Player.cs index 4d0b306..7f640f1 100644 --- a/src/Misc/Player.cs +++ b/src/Misc/Player.cs @@ -21,8 +21,8 @@ namespace mpvnet public class CorePlayer { public static string[] VideoTypes { get; set; } = "264 265 asf avc avi avs dav flv h264 h265 hevc m2t m2ts m2v m4v mkv mov mp4 mpeg mpg mpv mts ts vob vpy webm wmv y4m".Split(' '); - public static string[] AudioTypes { get; set; } = "aac ac3 dts dtshd dtshr dtsma eac3 flac m4a mka mp2 mp3 mpa mpc ogg opus thd thd+ac3 w64 wav".Split(' '); - public static string[] ImageTypes { get; set; } = { "jpg", "bmp", "png", "gif" }; + public static string[] AudioTypes { get; set; } = "aac ac3 dts dtshd dtshr dtsma eac3 flac m4a mka mp2 mp3 mpa mpc ogg opus thd w64 wav".Split(' '); + public static string[] ImageTypes { get; set; } = { "jpg", "bmp", "png", "gif", "webp" }; public static string[] SubtitleTypes { get; } = { "srt", "ass", "idx", "sub", "sup", "ttxt", "txt", "ssa", "smi", "mks" }; public event Action LogMessageAsync; // log-message MPV_EVENT_LOG_MESSAGE @@ -56,9 +56,9 @@ namespace mpvnet public event Action InitializedAsync; public event Action Pause; public event Action ShowMenu; + public event Action WindowScaleMpv; public event Action ScaleWindow; public event Action WindowScaleNET; - public event Action WindowScaleMpv; public event Action PlaylistPosChanged; public event Action PlaylistPosChangedAsync; public event Action VideoSizeChanged; @@ -85,8 +85,9 @@ namespace mpvnet public string ConfPath { get => ConfigFolder + "mpv.conf"; } public string GPUAPI { get; set; } = "auto"; - public string VO { get; set; } = "gpu"; public string InputConfPath => ConfigFolder + "input.conf"; + public string Path { get; set; } = ""; + public string VO { get; set; } = "gpu"; public string VID { get; set; } = ""; public string AID { get; set; } = ""; @@ -173,6 +174,7 @@ namespace mpvnet SetPropertyString("idle", "yes"); ObservePropertyDouble("window-scale", value => WindowScaleMpv(value)); + ObservePropertyString("path", value => Path = value); ObservePropertyBool("pause", value => { Paused = value; @@ -251,16 +253,22 @@ namespace mpvnet switch (name) { case "autofit": - if (int.TryParse(value.Trim('%'), out int result)) - Autofit = result / 100f; + { + if (int.TryParse(value.Trim('%'), out int result)) + Autofit = result / 100f; + } break; case "autofit-smaller": - if (int.TryParse(value.Trim('%'), out int result2)) - AutofitSmaller = result2 / 100f; + { + if (int.TryParse(value.Trim('%'), out int result)) + AutofitSmaller = result / 100f; + } break; case "autofit-larger": - if (int.TryParse(value.Trim('%'), out int result3)) - AutofitLarger = result3 / 100f; + { + if (int.TryParse(value.Trim('%'), out int result)) + AutofitLarger = result / 100f; + } break; case "fs": case "fullscreen": Fullscreen = value == "yes"; break; @@ -333,7 +341,7 @@ namespace mpvnet { File.WriteAllText(_ConfigFolder + "input.conf", Properties.Resources.input_conf); - string scriptOptsPath = _ConfigFolder + "script-opts" + Path.DirectorySeparatorChar; + string scriptOptsPath = _ConfigFolder + "script-opts" + System.IO.Path.DirectorySeparatorChar; if (!Directory.Exists(scriptOptsPath)) { @@ -438,7 +446,7 @@ namespace mpvnet ps.Scripts.Add(eventCode); ps.Scripts.Add(propertyChangedCode); ps.Scripts.Add(File.ReadAllText(file)); - ps.Module = Path.GetFileName(file); + ps.Module = System.IO.Path.GetFileName(file); ps.Print = true; lock (PowerShell.References) @@ -1195,7 +1203,7 @@ namespace mpvnet LoadISO(file); else if(SubtitleTypes.Contains(file.Ext())) CommandV("sub-add", file); - else if (file.Ext().Length != 3 && File.Exists(Path.Combine(file, "BDMV\\index.bdmv"))) + else if (file.Ext().Length != 3 && File.Exists(System.IO.Path.Combine(file, "BDMV\\index.bdmv"))) { Command("stop"); Thread.Sleep(500); @@ -1284,7 +1292,7 @@ namespace mpvnet path = path.Replace("/", "\\"); if (path.Contains("\\")) - dir = Path.GetDirectoryName(path); + dir = System.IO.Path.GetDirectoryName(path); List files = Directory.GetFiles(dir).ToList(); @@ -1388,6 +1396,10 @@ namespace mpvnet void HideLogo() => Command("overlay-remove 0"); + public bool IsImage => ImageTypes.Contains(Path.Ext()); + + public bool IsAudio => AudioTypes.Contains(Path.Ext()); + string GetLanguage(string id) { foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.NeutralCultures)) @@ -1419,7 +1431,7 @@ namespace mpvnet } public void RaiseScaleWindow(float value) => ScaleWindow(value); - + public void RaiseWindowScaleNET(float value) => WindowScaleNET(value); public void RaiseShowMenu() => ShowMenu(); diff --git a/src/Resources/editor_conf.txt b/src/Resources/editor_conf.txt index ad35f15..427ca45 100644 --- a/src/Resources/editor_conf.txt +++ b/src/Resources/editor_conf.txt @@ -410,6 +410,18 @@ file = mpv filter = Screen help = Initial window height in percent. Default: 60 +[setting] +name = autofit-image +file = mpvnet +filter = Screen +help = Initial window height in percent for image files. Default: 80 + +[setting] +name = autofit-audio +file = mpvnet +filter = Screen +help = Initial window height in percent for audio files. Default: 80 + [setting] name = autofit-smaller file = mpv