From 1657117a279e9e52eea3c35c0962fa11809dcbbd Mon Sep 17 00:00:00 2001 From: N00MKRAD <61149547+n00mkrad@users.noreply.github.com> Date: Mon, 25 Nov 2024 18:51:43 +0100 Subject: [PATCH] Unify mpdecimate variables, also show settings tooltips on click (not just hover) --- CodeLegacy/Data/Enums.cs | 5 +++ CodeLegacy/Extensions/ExtensionMethods.cs | 7 ++-- CodeLegacy/Forms/Main/Form1.Designer.cs | 5 --- CodeLegacy/Forms/Main/Form1.cs | 2 + CodeLegacy/Forms/SettingsForm.cs | 50 +++++++++++++++++++---- CodeLegacy/Magick/Dedupe.cs | 2 +- CodeLegacy/Media/FfmpegCommands.cs | 16 ++++---- CodeLegacy/Ui/UiUtils.cs | 10 +++++ 8 files changed, 72 insertions(+), 25 deletions(-) diff --git a/CodeLegacy/Data/Enums.cs b/CodeLegacy/Data/Enums.cs index e614d9f..a6f7a81 100644 --- a/CodeLegacy/Data/Enums.cs +++ b/CodeLegacy/Data/Enums.cs @@ -29,5 +29,10 @@ public enum ExrPrecision { Float, Half } } } + + public class Interpolation + { + public enum MpDecimateSens { Normal, High, VeryHigh, Extreme } + } } } \ No newline at end of file diff --git a/CodeLegacy/Extensions/ExtensionMethods.cs b/CodeLegacy/Extensions/ExtensionMethods.cs index dcf8e31..af08e67 100644 --- a/CodeLegacy/Extensions/ExtensionMethods.cs +++ b/CodeLegacy/Extensions/ExtensionMethods.cs @@ -12,6 +12,7 @@ using System.Drawing; using Flowframes.MiscUtils; using Newtonsoft.Json.Converters; using Newtonsoft.Json; +using Flowframes.Ui; namespace Flowframes { @@ -299,7 +300,7 @@ namespace Flowframes if (key == null) key = ""; - for (int i = 0; i < dict.Count; i++) + for (int i = 0; i < (dict == null ? 0 : dict.Count); i++) { if (ignoreCase) { @@ -319,13 +320,13 @@ namespace Flowframes return ""; } - public static void FillFromEnum(this ComboBox comboBox, Dictionary stringMap = null, int defaultIndex = -1, List exclusionList = null) where TEnum : Enum + public static void FillFromEnum(this ComboBox comboBox, Dictionary stringMap = null, int defaultIndex = -1, List exclusionList = null, bool useKeyNames = false) where TEnum : Enum { if (exclusionList == null) exclusionList = new List(); var entriesToAdd = Enum.GetValues(typeof(TEnum)).Cast().Except(exclusionList); - var strings = entriesToAdd.Select(x => stringMap.Get(x.ToString(), true)); + var strings = useKeyNames ? entriesToAdd.Select(x => UiUtils.PascalCaseToText($"{x}")) : entriesToAdd.Select(x => stringMap.Get($"{x}", true)); comboBox.FillFromStrings(strings, stringMap, defaultIndex); } diff --git a/CodeLegacy/Forms/Main/Form1.Designer.cs b/CodeLegacy/Forms/Main/Form1.Designer.cs index abb3d9e..0de553d 100644 --- a/CodeLegacy/Forms/Main/Form1.Designer.cs +++ b/CodeLegacy/Forms/Main/Form1.Designer.cs @@ -1265,11 +1265,6 @@ this.mpdecimateMode.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.mpdecimateMode.ForeColor = System.Drawing.Color.White; this.mpdecimateMode.FormattingEnabled = true; - this.mpdecimateMode.Items.AddRange(new object[] { - "Normal", - "High", - "Very High", - "Extreme"}); this.mpdecimateMode.Location = new System.Drawing.Point(0, 0); this.mpdecimateMode.Margin = new System.Windows.Forms.Padding(3, 3, 8, 3); this.mpdecimateMode.Name = "mpdecimateMode"; diff --git a/CodeLegacy/Forms/Main/Form1.cs b/CodeLegacy/Forms/Main/Form1.cs index fb22a81..ec07563 100644 --- a/CodeLegacy/Forms/Main/Form1.cs +++ b/CodeLegacy/Forms/Main/Form1.cs @@ -79,6 +79,8 @@ namespace Flowframes.Forms.Main UiUtils.InitCombox(outSpeedCombox, 0); // Video Utils UiUtils.InitCombox(trimCombox, 0); + // Quick Settings + mpdecimateMode.FillFromEnum(useKeyNames: true); Program.mainForm = this; Logger.textbox = logBox; diff --git a/CodeLegacy/Forms/SettingsForm.cs b/CodeLegacy/Forms/SettingsForm.cs index cf0177d..efdab58 100644 --- a/CodeLegacy/Forms/SettingsForm.cs +++ b/CodeLegacy/Forms/SettingsForm.cs @@ -1,6 +1,5 @@ using Flowframes.Data; using Flowframes.IO; -using Flowframes.Media; using Flowframes.MiscUtils; using Flowframes.Os; using Flowframes.Ui; @@ -30,15 +29,17 @@ namespace Flowframes.Forms { MinimumSize = new Size(Width, Height); MaximumSize = new Size(Width, (Height * 1.5f).RoundToInt()); + mpdecimateMode.FillFromEnum(useKeyNames: true); InitGpus(); InitServers(); LoadSettings(); + AddTooltipClickFunction(); initialized = true; Task.Run(() => CheckModelCacheSize()); } - private void InitGpus () + private void InitGpus() { string tooltipTorch = ""; string tooltipNcnn = ""; @@ -49,7 +50,7 @@ namespace Flowframes.Forms tooltipTorch += $"{i} = {NvApi.NvGpus[i].FullName} ({NvApi.NvGpus[i].GetVramGb().ToString("0.")} GB)\n"; } - foreach(var vkGpu in VulkanUtils.VkDevices) + foreach (var vkGpu in VulkanUtils.VkDevices) { ncnnGpus.Items.Add(vkGpu.Id); tooltipNcnn += $"{vkGpu.Id} = {vkGpu.Name}\n"; @@ -70,7 +71,7 @@ namespace Flowframes.Forms serverCombox.SelectedIndex = 0; } - public async Task CheckModelCacheSize () + public async Task CheckModelCacheSize() { await Task.Delay(200); @@ -97,7 +98,7 @@ namespace Flowframes.Forms Program.mainForm.LoadQuickSettings(); } - void SaveSettings () + void SaveSettings() { // Remove spaces... torchGpus.Text = torchGpus.Text.Replace(" ", ""); @@ -183,7 +184,7 @@ namespace Flowframes.Forms ConfigParser.LoadGuiElement(dainNcnnTilesize); // Export ConfigParser.LoadGuiElement(minOutVidLength); - ConfigParser.LoadGuiElement(maxFps); + ConfigParser.LoadGuiElement(maxFps); ConfigParser.LoadComboxIndex(loopMode); ConfigParser.LoadGuiElement(fixOutputDuration); // Debugging @@ -193,7 +194,7 @@ namespace Flowframes.Forms ConfigParser.LoadGuiElement(ffEncArgs); } - private void SetVisibility () + private void SetVisibility() { // Dev options List devOptions = new List { panKeepTempFolder, }; @@ -215,6 +216,39 @@ namespace Flowframes.Forms panRifeCudaHalfPrec.SetVisible(NvApi.NvGpus.Count > 0 && availAis.Contains(Implementations.rifeCuda)); } + private static List GetAllControls(Control parent) + { + var controls = new List(); + + foreach (Control ctrl in parent.Controls) + { + controls.Add(ctrl); + + if (ctrl.HasChildren) + { + controls.AddRange(GetAllControls(ctrl)); + } + } + + return controls; + } + + private void AddTooltipClickFunction() + { + foreach (Control control in GetAllControls(this)) + { + if(!(control is PictureBox)) + continue; + + string tooltipText = toolTip1.GetToolTip(control); + + if (tooltipText.IsEmpty()) + continue; + + control.Click += (sender, e) => { MessageBox.Show(tooltipText, "Tooltip", MessageBoxButtons.OK, MessageBoxIcon.Information); }; + } + } + private void tempFolderLoc_SelectedIndexChanged(object sender, EventArgs e) { tempDirBrowseBtn.Visible = tempFolderLoc.SelectedIndex == 4; @@ -230,7 +264,7 @@ namespace Flowframes.Forms private void tempDirBrowseBtn_Click(object sender, EventArgs e) { CommonOpenFileDialog dialog = new CommonOpenFileDialog { InitialDirectory = tempDirCustom.Text.Trim(), IsFolderPicker = true }; - + if (dialog.ShowDialog() == CommonFileDialogResult.Ok) tempDirCustom.Text = dialog.FileName; diff --git a/CodeLegacy/Magick/Dedupe.cs b/CodeLegacy/Magick/Dedupe.cs index e501032..8802491 100644 --- a/CodeLegacy/Magick/Dedupe.cs +++ b/CodeLegacy/Magick/Dedupe.cs @@ -269,7 +269,7 @@ namespace Flowframes.Magick Process ffmpeg = OsUtils.NewProcess(true); string baseCmd = $"/C cd /D {Path.Combine(IO.Paths.GetPkgPath(), IO.Paths.audioVideoDir).Wrap()}"; - string mpDec = FfmpegCommands.GetMpdecimate((int)FfmpegCommands.MpDecSensitivity.Normal, false); + string mpDec = FfmpegCommands.GetMpdecimate(wrap: false); // FfmpegCommands.GetMpdecimate((int)FfmpegCommands.MpDecSensitivity.Normal, false); ffmpeg.StartInfo.Arguments = $"{baseCmd} & ffmpeg -loglevel debug -y -i {videoPath.Wrap()} -fps_mode vfr -vf {mpDec} -f null NUL 2>&1 | findstr keep_count:"; List ffmpegOutputLines = (await Task.Run(() => OsUtils.GetProcStdOut(ffmpeg, true))).SplitIntoLines().Where(l => l.IsNotEmpty()).ToList(); diff --git a/CodeLegacy/Media/FfmpegCommands.cs b/CodeLegacy/Media/FfmpegCommands.cs index 0076593..e7c3cfa 100644 --- a/CodeLegacy/Media/FfmpegCommands.cs +++ b/CodeLegacy/Media/FfmpegCommands.cs @@ -16,19 +16,19 @@ namespace Flowframes public static string hdrFilter = @"-vf zscale=t=linear:npl=100,format=gbrpf32le,zscale=p=bt709,tonemap=tonemap=hable:desat=0,zscale=t=bt709:m=bt709:r=tv,format=yuv420p"; public static string pngCompr = "-compression_level 3"; - public enum MpDecSensitivity { Normal = 4, High = 20, VeryHigh = 32, Extreme = 40 } - - public static string GetMpdecimate(int sensitivity = 4, bool wrap = true) + public static Dictionary MpDecSensLookup = new Dictionary { - string mpd = $"mpdecimate=hi=64*1024:lo=64*{sensitivity}:frac=1.0"; - return wrap ? mpd.Wrap() : mpd; - } + { Enums.Interpolation.MpDecimateSens.Normal, 4 }, + { Enums.Interpolation.MpDecimateSens.High, 20 }, + { Enums.Interpolation.MpDecimateSens.VeryHigh, 32 }, + { Enums.Interpolation.MpDecimateSens.Extreme, 40 } + }; public static string GetMpdecimate(bool wrap = true) { int mpdValIndex = Config.GetInt(Config.Key.mpdecimateMode); - var mpdVal = ((MpDecSensitivity[])Enum.GetValues(typeof(MpDecSensitivity)))[mpdValIndex]; - string mpd = $"mpdecimate=hi=64*1024:lo=64*{(int)mpdVal}:frac=1.0"; + int mpdVal = MpDecSensLookup[(Enums.Interpolation.MpDecimateSens)mpdValIndex]; + string mpd = $"mpdecimate=hi=64*1024:lo=64*{mpdVal}:frac=1.0"; return wrap ? mpd.Wrap() : mpd; } diff --git a/CodeLegacy/Ui/UiUtils.cs b/CodeLegacy/Ui/UiUtils.cs index 61d65bd..36c52c1 100644 --- a/CodeLegacy/Ui/UiUtils.cs +++ b/CodeLegacy/Ui/UiUtils.cs @@ -4,6 +4,7 @@ using Flowframes.IO; using Flowframes.Main; using Flowframes.Os; using System; +using System.Text.RegularExpressions; using System.Windows.Forms; namespace Flowframes.Ui @@ -148,5 +149,14 @@ namespace Flowframes.Ui } } } + + // TODO: Move to NmkdUtils once implemented + public static string PascalCaseToText(string s) + { + if (s.IsEmpty()) + return ""; + + return Regex.Replace(s, "([A-Z])", " $1").Trim(); + } } }