-
-
Notifications
You must be signed in to change notification settings - Fork 149
Expand file tree
/
Copy pathForm1.cs
More file actions
824 lines (667 loc) · 29.4 KB
/
Form1.cs
File metadata and controls
824 lines (667 loc) · 29.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
using Flowframes.Forms;
using Flowframes.IO;
using Flowframes.Main;
using Flowframes.Os;
using Flowframes.Ui;
using Microsoft.WindowsAPICodePack.Dialogs;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using HTAlt.WinForms;
using Flowframes.Data;
using Microsoft.WindowsAPICodePack.Taskbar;
using Flowframes.MiscUtils;
using System.Threading.Tasks;
using System.Linq;
using System.Runtime.InteropServices;
#pragma warning disable IDE1006
namespace Flowframes.Forms.Main
{
public partial class Form1 : Form
{
[Flags]
public enum EXECUTION_STATE : uint { ES_AWAYMODE_REQUIRED = 0x00000040, ES_CONTINUOUS = 0x80000000, ES_DISPLAY_REQUIRED = 0x00000002, ES_SYSTEM_REQUIRED = 0x00000001 }
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern EXECUTION_STATE SetThreadExecutionState(EXECUTION_STATE esFlags); // PREVENT WINDOWS FROM GOING TO SLEEP
private bool _initialized = false;
private bool _mainTabInitialized = false;
private bool _quickSettingsInitialized = false;
public Form1()
{
InitializeComponent();
}
private async void Form1_Load(object sender, EventArgs e)
{
CheckForIllegalCrossThreadCalls = false;
AutoScaleMode = AutoScaleMode.None;
}
private async void Form1_Shown(object sender, EventArgs e)
{
Refresh();
await Task.Delay(1);
StartupChecks.CheckOs();
// Main Tab
UiUtils.InitCombox(interpFactorCombox, 0);
UiUtils.InitCombox(outSpeedCombox, 0);
InitOutputUi();
UiUtils.InitCombox(aiModel, 2);
// Video Utils
UiUtils.InitCombox(trimCombox, 0);
Program.mainForm = this;
Logger.textbox = logBox;
NvApi.Init();
InterpolationProgress.preview = previewPicturebox;
RemovePreviewIfDisabled();
await Checks();
InitAis();
UpdateStepByStepControls();
Initialized();
HandleArgs();
if (Program.args.Contains("show-model-downloader"))
new ModelDownloadForm().ShowDialog();
if (Debugger.IsAttached)
{
Logger.Log("Debugger is attached - Flowframes seems to be running within VS.");
}
completionAction.SelectedIndex = 0;
}
private void InitOutputUi()
{
comboxOutputFormat.FillFromEnum<Enums.Output.Format>(Strings.OutputFormat, 0);
UpdateOutputUi();
}
private void UpdateOutputUi()
{
var outMode = ParseUtils.GetEnum<Enums.Output.Format>(comboxOutputFormat.Text, true, Strings.OutputFormat);
comboxOutputEncoder.FillFromEnum(OutputUtils.GetAvailableEncoders(outMode), Strings.Encoder, 0);
comboxOutputEncoder.Visible = comboxOutputEncoder.Items.Count > 0;
UpdateOutputEncodingUi();
}
private void UpdateOutputEncodingUi()
{
var infoStrings = new List<string>() { "Format" };
var encoder = ParseUtils.GetEnum<Enums.Encoding.Encoder>(comboxOutputEncoder.Text, true, Strings.Encoder);
bool hasEncoder = (int)encoder != -1;
comboxOutputQuality.Visible = hasEncoder;
comboxOutputColors.Visible = hasEncoder;
if (hasEncoder)
{
infoStrings.Add("Codec");
EncoderInfoVideo info = OutputUtils.GetEncoderInfoVideo(encoder);
bool adjustableQuality = !info.Lossless && info.QualityLevels != null && info.QualityLevels.Count > 0;
comboxOutputQuality.Visible = adjustableQuality;
comboxOutputQuality.Items.Clear();
if (info.QualityLevels.Count > 0)
{
infoStrings.Add("Quality");
comboxOutputQuality.FillFromEnum(info.QualityLevels, Strings.VideoQuality, info.QualityDefault);
}
var pixelFormats = info.PixelFormats;
comboxOutputColors.Visible = pixelFormats.Count > 0;
int defaultPixFmt = (int)info.PixelFormatDefault != -1 ? info.PixelFormats.IndexOf(info.PixelFormatDefault) : 0;
comboxOutputColors.FillFromEnum(pixelFormats, Strings.PixelFormat, defaultPixFmt);
comboxOutputColors.Width = adjustableQuality ? 117 : 223;
if (pixelFormats.Count > 0)
infoStrings.Add("Pixel Format");
}
labelOutput.Text = $"Set {string.Join(", ", infoStrings)}";
}
async Task Checks()
{
try
{
Task.Run(() => Updater.UpdateModelList());
Task.Run(() => Updater.AsyncUpdateCheck());
Task.Run(() => GetWebInfo.LoadNews(newsLabel));
Task.Run(() => GetWebInfo.LoadPatronListCsv(patronsLabel));
Task.Run(() => Servers.Init());
await Python.CheckCompression();
await StartupChecks.SymlinksCheck();
}
catch (Exception e)
{
Logger.Log("Non-critical error while performing online checks. See logs for details.");
Logger.Log($"{e.Message}\n{e.StackTrace}", true);
}
}
void HandleArgs()
{
if (Program.fileArgs.Length > 0)
DragDropHandler(Program.fileArgs.Where(x => IoUtils.IsFileValid(x)).ToArray());
foreach (string arg in Program.args)
{
if (arg.StartsWith("out="))
outputTbox.Text = arg.Split('=').Last().Trim();
if (arg.StartsWith("factor="))
interpFactorCombox.SelectedIndex = arg.Split('=').Last().GetInt();
if (arg.StartsWith("ai="))
aiCombox.SelectedIndex = arg.Split('=').Last().GetInt();
if (arg.StartsWith("model="))
aiModel.SelectedIndex = arg.Split('=').Last().GetInt();
if (arg.StartsWith("output-mode="))
comboxOutputFormat.SelectedIndex = arg.Split('=').Last().GetInt();
}
}
void RemovePreviewIfDisabled()
{
if (Config.GetBool(Config.Key.disablePreview))
mainTabControl.TabPages.Cast<TabPage>().Where(p => p.Name == previewTab.Name).ToList().ForEach(t => mainTabControl.TabPages.Remove(t));
}
public HTTabControl GetMainTabControl() { return mainTabControl; }
public TextBox GetInputFpsTextbox() { return fpsInTbox; }
public Button GetPauseBtn() { return pauseBtn; }
public bool IsInFocus() { return ActiveForm == this; }
public void SetTab(string tabName)
{
var targetTab = mainTabControl.TabPages.Cast<TabPage>().Where(p => p.Name == tabName).FirstOrDefault();
if (targetTab == null)
return;
mainTabControl.SelectedTab = targetTab;
mainTabControl.Refresh();
mainTabControl.Update();
}
public InterpSettings GetCurrentSettings()
{
SetTab(interpOptsTab.Name);
string inPath = inputTbox.Text.Trim();
string outPath = outputTbox.Text.Trim();
AI ai = GetAi();
float interpFactor = interpFactorCombox.GetFloat();
float itsScale = outSpeedCombox.GetInt().Clamp(1, 64);
return new InterpSettings(inPath, outPath, ai, currInFpsDetected, currInFps, interpFactor, itsScale, GetOutputSettings(), GetModel(ai));
}
public InterpSettings UpdateCurrentSettings(InterpSettings settings)
{
SetTab(interpOptsTab.Name);
string inPath = inputTbox.Text.Trim();
if (settings.inPath != inPath) // If path changed, get new instance
{
Logger.Log($"settings.inPath ({settings.inPath}) mismatches GUI inPath ({settings.inPath} - Returning fresh instance", true);
return GetCurrentSettings();
}
settings.inPath = inPath;
settings.ai = GetAi();
settings.inFpsDetected = currInFpsDetected;
settings.inFps = currInFps;
settings.interpFactor = interpFactorCombox.GetFloat();
settings.outFps = settings.inFps * settings.interpFactor;
settings.outSettings = GetOutputSettings();
settings.model = GetModel(GetAi());
return settings;
}
public void LoadBatchEntry(InterpSettings entry)
{
inputTbox.Text = entry.inPath;
MainUiFunctions.SetOutPath(outputTbox, entry.outPath);
fpsInTbox.Text = entry.inFps.ToString();
interpFactorCombox.Text = entry.interpFactor.ToString();
aiCombox.SelectedIndex = Implementations.NetworksAvailable.IndexOf(Implementations.NetworksAvailable.Where(x => x.NameInternal == entry.ai.NameInternal).FirstOrDefault());
SetFormat(entry.outSettings.Format);
}
public void SetStatus(string str)
{
Logger.Log(str, true);
statusLabel.Text = str;
}
public string GetStatus()
{
return statusLabel.Text;
}
public void SetProgress(int percent)
{
percent = percent.Clamp(0, 100);
TaskbarManager.Instance.SetProgressValue(percent, 100);
longProgBar.Value = percent;
longProgBar.Refresh();
}
public Size currInRes;
public Fraction currInFpsDetected;
public Fraction currInFps;
public int currInFrames;
public long currInDuration;
public long currInDurationCut;
public void UpdateInputInfo()
{
string str = $"Size: {(!currInRes.IsEmpty ? $"{currInRes.Width}x{currInRes.Height}" : "Unknown")} - ";
str += $"FPS: {(currInFpsDetected.GetFloat() > 0f ? $"{currInFpsDetected} ({currInFpsDetected.GetFloat().ToString("0.000")})" : "Unknown")} - ";
str += $"Frames: {(currInFrames > 0 ? $"{currInFrames}" : "Unknown")} - ";
str += $"Duration: {(currInDuration > 0 ? FormatUtils.MsToTimestamp(currInDuration) : "Unknown")}";
inputInfo.Text = str;
}
public void InterpolationDone()
{
SetStatus("Done interpolating!");
if (!BatchProcessing.busy)
CompletionAction();
}
public void CompletionAction()
{
if (Program.args.Contains("quit-when-done"))
Application.Exit();
if (completionAction.SelectedIndex == 1)
new TimeoutForm(completionAction.Text, Application.Exit).ShowDialog();
if (completionAction.SelectedIndex == 2)
new TimeoutForm(completionAction.Text, OsUtils.Sleep).ShowDialog();
if (completionAction.SelectedIndex == 3)
new TimeoutForm(completionAction.Text, OsUtils.Hibernate).ShowDialog();
if (completionAction.SelectedIndex == 4)
new TimeoutForm(completionAction.Text, OsUtils.Shutdown).ShowDialog();
}
public void ResetInputInfo()
{
currInRes = new Size();
currInFpsDetected = new Fraction();
currInFps = new Fraction();
currInFrames = 0;
currInDuration = 0;
currInDurationCut = 0;
UpdateInputInfo();
}
void InitAis()
{
bool pytorchAvailable = Python.IsPytorchReady();
foreach (AI ai in Implementations.NetworksAvailable)
aiCombox.Items.Add(GetAiComboboxName(ai));
string lastUsedAiName = Config.Get(Config.Key.lastUsedAiName);
aiCombox.SelectedIndex = Implementations.NetworksAvailable.IndexOf(Implementations.NetworksAvailable.Where(x => x.NameInternal == lastUsedAiName).FirstOrDefault());
if (aiCombox.SelectedIndex < 0) aiCombox.SelectedIndex = 0;
Config.Set(Config.Key.lastUsedAiName, GetAi().NameInternal);
}
private string GetAiComboboxName(AI ai)
{
return ai.FriendlyName + " - " + ai.Description;
}
private void InitializeMainTab ()
{
if (_mainTabInitialized)
return;
LoadOutputSettings();
_mainTabInitialized = true;
}
public void Initialized()
{
_initialized = true;
runBtn.Enabled = true;
SetStatus("Ready");
}
private void browseInputBtn_Click(object sender, EventArgs e)
{
CommonOpenFileDialog dialog = new CommonOpenFileDialog { InitialDirectory = inputTbox.Text.Trim(), IsFolderPicker = true };
if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
DragDropHandler(new string[] { dialog.FileName });
}
private void browseInputFileBtn_Click(object sender, EventArgs e)
{
CommonOpenFileDialog dialog = new CommonOpenFileDialog { InitialDirectory = inputTbox.Text.Trim(), IsFolderPicker = false };
if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
DragDropHandler(new string[] { dialog.FileName });
}
private void browseOutBtn_Click(object sender, EventArgs e)
{
CommonOpenFileDialog dialog = new CommonOpenFileDialog { InitialDirectory = outputTbox.Text.Trim(), IsFolderPicker = true };
if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
outputTbox.Text = dialog.FileName;
}
public async void runBtn_Click(object sender, EventArgs e)
{
if (Interpolate.currentMediaFile == null || !Interpolate.currentMediaFile.Initialized)
{
SetTab(interpOptsTab.Name);
return;
}
ValidateFactor();
if (!BatchProcessing.busy) // Don't load values from GUI if batch processing is used
Interpolate.currentSettings = GetCurrentSettings();
AiProcessSuspend.Reset();
SaveOutputSettings();
if (Interpolate.currentSettings.outSettings.Format == Enums.Output.Format.Realtime)
{
await Interpolate.Realtime();
SetProgress(0);
}
else
{
await Interpolate.Start();
}
}
private void SaveOutputSettings ()
{
var strings = new List<string>();
if (comboxOutputFormat.Visible) strings.Add(comboxOutputFormat.Text);
if (comboxOutputEncoder.Visible) strings.Add(comboxOutputEncoder.Text);
if (comboxOutputQuality.Visible) strings.Add(comboxOutputQuality.Text);
if (comboxOutputColors.Visible) strings.Add(comboxOutputColors.Text);
Config.Set(Config.Key.lastOutputSettings, string.Join(",", strings));
}
private void LoadOutputSettings()
{
string[] strings = Config.Get(Config.Key.lastOutputSettings).Split(',');
if (strings.Length < 4)
return;
if (comboxOutputFormat.Visible) comboxOutputFormat.Text = strings[0];
if (comboxOutputEncoder.Visible) comboxOutputEncoder.Text = strings[1];
if (comboxOutputQuality.Visible) comboxOutputQuality.Text = strings[2];
if (comboxOutputColors.Visible) comboxOutputColors.Text = strings[3];
}
public void SetFormat(Enums.Output.Format format)
{
comboxOutputFormat.Text = Strings.OutputFormat.Get(format.ToString());
}
void inputTbox_DragEnter(object sender, DragEventArgs e) { e.Effect = DragDropEffects.Copy; }
private void inputTbox_DragDrop(object sender, DragEventArgs e)
{
DragDropHandler((string[])e.Data.GetData(DataFormats.FileDrop));
}
void outputTbox_DragEnter(object sender, DragEventArgs e) { e.Effect = DragDropEffects.Copy; }
private void outputTbox_DragDrop(object sender, DragEventArgs e)
{
if (Program.busy) return;
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
outputTbox.Text = files[0];
}
private void fpsInTbox_TextChanged(object sender, EventArgs e)
{
UpdateUiFps();
}
public void UpdateUiFps()
{
if (fpsInTbox.Text.Contains("/")) // Parse fraction
{
string[] split = fpsInTbox.Text.Split('/');
Fraction frac = new Fraction(split[0].GetInt(), split[1].GetInt());
fpsOutTbox.Text = (frac * interpFactorCombox.GetFloat()).ToString() + " FPS";
if (!fpsInTbox.ReadOnly)
currInFps = frac;
}
else // Parse float
{
fpsInTbox.Text = fpsInTbox.Text.TrimNumbers(true);
fpsOutTbox.Text = (fpsInTbox.GetFloat() * interpFactorCombox.GetFloat()).ToString() + " FPS";
if (!fpsInTbox.ReadOnly)
currInFps = new Fraction(fpsInTbox.GetFloat());
}
}
private void interpFactorCombox_SelectedIndexChanged(object sender, EventArgs e)
{
UpdateUiFps();
}
public void ValidateFactor()
{
interpFactorCombox.Text = $"x{MainUiFunctions.ValidateInterpFactor(interpFactorCombox.GetFloat())}";
}
public void SetWorking(bool state, bool allowCancel = true)
{
Logger.Log($"SetWorking({state})", true);
SetProgress(-1);
Control[] controlsToDisable = new Control[] { runBtn, runStepBtn, stepSelector, settingsBtn };
Control[] controlsToHide = new Control[] { runBtn, runStepBtn, stepSelector };
progressCircle.Visible = state;
busyControlsPanel.Visible = state;
foreach (Control c in controlsToDisable)
c.Enabled = !state;
foreach (Control c in controlsToHide)
c.Visible = !state;
busyControlsPanel.Enabled = allowCancel;
Program.busy = state;
Program.mainForm.UpdateStepByStepControls();
}
string lastAiComboxStr = "";
private void aiCombox_SelectedIndexChanged(object sender, EventArgs e)
{
if (string.IsNullOrWhiteSpace(aiCombox.Text) || aiCombox.Text == lastAiComboxStr) return;
lastAiComboxStr = aiCombox.Text;
UpdateAiModelCombox();
interpFactorCombox.Items.Clear();
foreach (int factor in GetAi().SupportedFactors)
interpFactorCombox.Items.Add($"x{factor}");
interpFactorCombox.SelectedIndex = 0;
if (_initialized)
Config.Set(Config.Key.lastUsedAiName, GetAi().NameInternal);
interpFactorCombox_SelectedIndexChanged(null, null);
fpsOutTbox.ReadOnly = GetAi().FactorSupport != AI.InterpFactorSupport.AnyFloat;
}
public void UpdateAiModelCombox()
{
aiModel = UiUtils.LoadAiModelsIntoGui(aiModel, GetAi());
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (!Program.busy && !BackgroundTaskManager.IsBusy())
return;
string reason = "";
if (BackgroundTaskManager.IsBusy())
reason = "Some background tasks have not finished yet.";
if (Program.busy)
reason = "The program is still busy.";
DialogResult dialog = UiUtils.ShowMessageBox($"Are you sure you want to exit the program?\n\n{reason}", "Are you sure?", MessageBoxButtons.YesNo);
if (dialog == DialogResult.No)
e.Cancel = true;
Program.Cleanup();
}
private void licenseBtn_Click(object sender, EventArgs e)
{
Process.Start("explorer.exe", Path.Combine(Paths.GetPkgPath(), Paths.licensesDir));
}
private void Form1_DragEnter(object sender, DragEventArgs e) { e.Effect = DragDropEffects.Copy; }
private void Form1_DragDrop(object sender, DragEventArgs e)
{
DragDropHandler((string[])e.Data.GetData(DataFormats.FileDrop));
}
public void DragDropHandler(string[] files)
{
if (Program.busy) return;
bool start = Program.initialRun && Program.args.Contains("start");
if (files.Length > 1)
{
SetTab(interpOptsTab.Name);
queueBtn_Click(null, null);
if (BatchProcessing.currentBatchForm != null)
BatchProcessing.currentBatchForm.LoadDroppedPaths(files, start);
}
else
{
SetTab(interpOptsTab.Name);
Logger.Log("Selected video/directory: " + Path.GetFileName(files[0]), true);
inputTbox.Text = files[0];
bool resume = Directory.Exists(files[0]) && IoUtils.GetAmountOfFiles(Path.Combine(files[0], Paths.resumeDir), true, "*.json") > 0;
AutoEncodeResume.resumeNextRun = resume;
if (resume)
AutoEncodeResume.LoadTempFolder(files[0]);
trimCombox.SelectedIndex = 0;
MainUiFunctions.InitInput(outputTbox, inputTbox, fpsInTbox, start);
}
}
private void cancelBtn_Click(object sender, EventArgs e)
{
DialogResult dialog = UiUtils.ShowMessageBox($"Are you sure you want to cancel the interpolation?", "Are you sure?", MessageBoxButtons.YesNo);
if (dialog == DialogResult.Yes)
{
SetTab(interpOptsTab.Name);
Interpolate.Cancel();
}
}
private void discordBtn_Click(object sender, EventArgs e)
{
Process.Start("https://discord.gg/eJHD2NSJRe");
}
private void paypalBtn_Click(object sender, EventArgs e)
{
Process.Start("https://www.paypal.com/paypalme/nmkd/10");
}
private void patreonBtn_Click(object sender, EventArgs e)
{
Process.Start("https://patreon.com/n00mkrad");
}
private void settingsBtn_Click(object sender, EventArgs e)
{
new SettingsForm().ShowDialog();
}
private void queueBtn_Click(object sender, EventArgs e)
{
ValidateFactor();
if (BatchProcessing.currentBatchForm != null)
{
BatchProcessing.currentBatchForm.WindowState = FormWindowState.Normal;
BatchProcessing.currentBatchForm.BringToFront();
}
else
{
new BatchForm().Show();
}
}
private void previewPicturebox_MouseClick(object sender, MouseEventArgs e)
{
if (InterpolationProgress.bigPreviewForm == null)
{
InterpolationProgress.bigPreviewForm = new BigPreviewForm();
InterpolationProgress.bigPreviewForm.Show();
InterpolationProgress.bigPreviewForm.SetImage(previewPicturebox.Image);
}
}
private async void updateBtn_Click(object sender, EventArgs e)
{
new UpdaterForm().ShowDialog();
}
private void welcomeLabel2_Click(object sender, EventArgs e)
{
SetTab(interpOptsTab.Name);
}
public void UpdateStepByStepControls()
{
if (stepSelector.SelectedIndex < 0)
stepSelector.SelectedIndex = 0;
bool stepByStep = Config.GetInt(Config.Key.processingMode) == 1;
runBtn.Visible = !stepByStep && !Program.busy;
}
private async void runStepBtn_Click(object sender, EventArgs e)
{
ValidateFactor();
SetTab(interpOptsTab.Name);
await InterpolateSteps.Run(stepSelector.Text);
}
private void mainTabControl_SelectedIndexChanged(object sender, EventArgs e)
{
if (!_initialized) return;
if(mainTabControl.SelectedTab == interpOptsTab)
{
aiCombox_SelectedIndexChanged(null, null);
InitializeMainTab();
}
}
private void trimCombox_SelectedIndexChanged(object sender, EventArgs e)
{
QuickSettingsTab.trimEnabled = trimCombox.SelectedIndex > 0;
trimPanel.Visible = QuickSettingsTab.trimEnabled;
if (trimCombox.SelectedIndex == 1)
{
trimStartBox.Text = "00:00:00";
trimEndBox.Text = FormatUtils.MsToTimestamp(currInDuration);
}
}
private void trimResetBtn_Click(object sender, EventArgs e)
{
trimCombox_SelectedIndexChanged(null, null);
}
private void trimBox_TextChanged(object sender, EventArgs e)
{
QuickSettingsTab.UpdateTrim(trimStartBox, trimEndBox);
}
#region Quick Settings
public void SaveQuickSettings(object sender, EventArgs e)
{
if (!_quickSettingsInitialized) return;
if (Program.busy)
LoadQuickSettings(); // Discard any changes if busy
ConfigParser.SaveGuiElement(maxVidHeight, ConfigParser.StringMode.Int);
ConfigParser.SaveComboxIndex(dedupMode);
ConfigParser.SaveComboxIndex(mpdecimateMode);
ConfigParser.SaveGuiElement(dedupThresh);
ConfigParser.SaveGuiElement(enableLoop);
ConfigParser.SaveGuiElement(scnDetect);
ConfigParser.SaveGuiElement(scnDetectValue);
ConfigParser.SaveGuiElement(maxFps);
}
public void LoadQuickSettings(object sender = null, EventArgs e = null)
{
ConfigParser.LoadGuiElement(maxVidHeight);
ConfigParser.LoadComboxIndex(dedupMode);
ConfigParser.LoadComboxIndex(mpdecimateMode);
ConfigParser.LoadGuiElement(dedupThresh);
ConfigParser.LoadGuiElement(enableLoop);
ConfigParser.LoadGuiElement(scnDetect);
ConfigParser.LoadGuiElement(scnDetectValue);
ConfigParser.LoadGuiElement(maxFps);
_quickSettingsInitialized = true;
}
private void dedupMode_SelectedIndexChanged(object sender, EventArgs e)
{
dedupeSensLabel.Visible = dedupMode.SelectedIndex != 0;
magickDedupePanel.Visible = dedupMode.SelectedIndex == 1;
mpDedupePanel.Visible = dedupMode.SelectedIndex == 2;
SaveQuickSettings(null, null);
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
if (Program.busy) return;
new SettingsForm().ShowDialog();
}
#endregion
private void pauseBtn_Click(object sender, EventArgs e)
{
AiProcessSuspend.SuspendResumeAi(!AiProcessSuspend.aiProcFrozen);
}
private void debugBtn_Click(object sender, EventArgs e)
{
new DebugForm().ShowDialog();
}
private void fpsOutTbox_Leave(object sender, EventArgs e)
{
float inFps = fpsInTbox.GetFloat();
float outFps = fpsOutTbox.GetFloat();
var targetFactorRounded = Math.Round((Decimal)(outFps / inFps), 3, MidpointRounding.AwayFromZero);
interpFactorCombox.Text = $"{targetFactorRounded}";
ValidateFactor();
fpsOutTbox.Text = $"{inFps * interpFactorCombox.GetFloat()} FPS";
}
private void aiInfoBtn_Click(object sender, EventArgs e)
{
var ai = GetAi();
if (ai != null)
UiUtils.ShowMessageBox(ai.GetVerboseInfo(), UiUtils.MessageType.Message);
}
private void comboxOutputFormat_SelectedIndexChanged(object sender, EventArgs e)
{
UpdateOutputUi();
}
private void comboxOutputEncoder_SelectedIndexChanged(object sender, EventArgs e)
{
UpdateOutputEncodingUi();
}
private void queueBtn_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
menuStripQueue.Show(Cursor.Position);
}
private void addCurrentConfigurationToQueueToolStripMenuItem_Click(object sender, EventArgs e)
{
Program.batchQueue.Enqueue(Program.mainForm.GetCurrentSettings());
Application.OpenForms.Cast<Form>().Where(f => f is BatchForm).Select(f => (BatchForm)f).ToList().ForEach(f => f.RefreshGui());
}
private void comboxOutputQuality_SelectedIndexChanged(object sender, EventArgs e)
{
var qualityPreset = ParseUtils.GetEnum<Enums.Encoding.Quality.Common>(comboxOutputQuality.Text, true, Strings.VideoQuality);
bool cust = qualityPreset == Enums.Encoding.Quality.Common.Custom;
textboxOutputQualityCust.Visible = cust;
comboxOutputQuality.Margin = new System.Windows.Forms.Padding(0, 0, cust ? 0 : 6, 0);
comboxOutputQuality.Width = cust ? 70 : 100;
if (!cust)
textboxOutputQualityCust.Text = "";
else
textboxOutputQualityCust.Focus();
Refresh();
}
}
}