2020-11-23 16:51:05 +01:00
using Flowframes.Forms ;
using Flowframes.IO ;
using Flowframes.Main ;
using Flowframes.OS ;
using Flowframes.UI ;
using Microsoft.WindowsAPICodePack.Dialogs ;
using System ;
2021-02-13 02:19:03 +01:00
using System.Collections.Generic ;
2020-11-23 16:51:05 +01:00
using System.Diagnostics ;
using System.Drawing ;
using System.IO ;
using System.Windows.Forms ;
using HTAlt.WinForms ;
using Flowframes.Data ;
2020-11-26 20:17:18 +01:00
using Microsoft.WindowsAPICodePack.Taskbar ;
2021-01-30 13:09:59 +01:00
using Flowframes.MiscUtils ;
2021-03-13 14:48:19 +01:00
using System.Threading.Tasks ;
2021-06-23 15:21:52 +02:00
using System.Linq ;
2020-11-23 16:51:05 +01:00
2021-07-25 23:22:54 +02:00
#pragma warning disable IDE1006
2020-11-23 16:51:05 +01:00
namespace Flowframes
{
public partial class Form1 : Form
{
public bool initialized = false ;
2021-02-24 15:12:49 +01:00
public bool quickSettingsInitialized = false ;
2020-11-23 16:51:05 +01:00
public Form1 ( )
{
InitializeComponent ( ) ;
}
2021-04-04 17:47:47 +02:00
private async void Form1_Load ( object sender , EventArgs e )
2020-11-23 16:51:05 +01:00
{
CheckForIllegalCrossThreadCalls = false ;
2021-01-15 16:20:25 +01:00
AutoScaleMode = AutoScaleMode . None ;
2021-02-18 14:30:56 +01:00
2021-04-04 17:47:47 +02:00
StartupChecks . CheckOs ( ) ;
2021-02-18 14:30:56 +01:00
2020-11-23 16:51:05 +01:00
// Main Tab
UIUtils . InitCombox ( interpFactorCombox , 0 ) ;
UIUtils . InitCombox ( outModeCombox , 0 ) ;
2021-01-13 23:05:23 +01:00
UIUtils . InitCombox ( aiModel , 2 ) ;
2020-11-23 16:51:05 +01:00
// Video Utils
2021-02-23 12:13:30 +01:00
UIUtils . InitCombox ( trimCombox , 0 ) ;
2020-11-23 16:51:05 +01:00
Program . mainForm = this ;
Logger . textbox = logBox ;
2021-02-24 14:56:47 +01:00
NvApi . Init ( ) ;
2020-11-23 16:51:05 +01:00
InitAis ( ) ;
2021-04-22 16:15:17 +02:00
InterpolationProgress . preview = previewPicturebox ;
2021-07-24 17:27:17 +02:00
RemovePreviewIfDisabled ( ) ;
2021-02-21 12:39:25 +01:00
UpdateStepByStepControls ( ) ;
2020-11-23 16:51:05 +01:00
Initialized ( ) ;
2021-08-02 15:08:19 +02:00
HandleArgs ( ) ;
2021-03-13 14:48:19 +01:00
Text = $"Flowframes" ;
2021-06-23 15:21:52 +02:00
if ( Program . args . Contains ( "show-model-downloader" ) )
new ModelDownloadForm ( ) . ShowDialog ( ) ;
2021-03-13 14:48:19 +01:00
}
2021-03-24 17:33:17 +01:00
private async void Form1_Shown ( object sender , EventArgs e )
2021-03-13 14:48:19 +01:00
{
2021-03-19 19:34:48 +01:00
if ( Debugger . IsAttached )
{
Logger . Log ( "Debugger is attached - Flowframes seems to be running within VS." ) ;
scnDetectTestBtn . Visible = true ;
}
2021-08-01 15:57:35 +02:00
completionAction . SelectedIndex = 0 ;
2021-03-24 17:33:17 +01:00
await Checks ( ) ;
2020-11-26 20:17:18 +01:00
}
2020-11-23 16:51:05 +01:00
2021-03-13 14:48:19 +01:00
async Task Checks ( )
2020-11-26 20:17:18 +01:00
{
2020-12-07 22:10:58 +01:00
try
{
2021-04-29 22:57:00 +02:00
Task . Run ( ( ) = > Updater . UpdateModelList ( ) ) ;
Task . Run ( ( ) = > Updater . AsyncUpdateCheck ( ) ) ;
Task . Run ( ( ) = > GetWebInfo . LoadNews ( newsLabel ) ) ;
Task . Run ( ( ) = > GetWebInfo . LoadPatronListCsv ( patronsLabel ) ) ;
2021-03-13 14:48:19 +01:00
await Python . CheckCompression ( ) ;
2021-04-29 22:57:00 +02:00
await StartupChecks . SymlinksCheck ( ) ;
2020-12-07 22:10:58 +01:00
}
catch ( Exception e )
{
Logger . Log ( "Non-critical error while performing online checks. See logs for details." ) ;
2021-02-13 02:29:00 +01:00
Logger . Log ( $"{e.Message}\n{e.StackTrace}" , true ) ;
2021-02-13 02:19:03 +01:00
}
}
2021-08-02 15:08:19 +02:00
void HandleArgs ( )
2021-02-13 02:19:03 +01:00
{
2021-08-02 15:08:19 +02:00
foreach ( string arg in Program . args )
2021-02-13 02:19:03 +01:00
{
2021-08-02 15:08:19 +02:00
if ( arg . StartsWith ( "factor=" ) )
{
int factor = arg . Split ( '=' ) . Last ( ) . GetInt ( ) ;
if ( factor = = 2 ) interpFactorCombox . SelectedIndex = 0 ;
if ( factor = = 4 ) interpFactorCombox . SelectedIndex = 1 ;
if ( factor = = 8 ) interpFactorCombox . SelectedIndex = 2 ;
}
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=" ) )
outModeCombox . SelectedIndex = arg . Split ( '=' ) . Last ( ) . GetInt ( ) ;
}
2021-02-13 02:36:09 +01:00
2021-08-02 15:08:19 +02:00
if ( Program . fileArgs . Length > 0 )
DragDropHandler ( Program . fileArgs . Where ( x = > IOUtils . IsFileValid ( x ) ) . ToArray ( ) ) ;
2021-02-13 02:36:09 +01:00
2020-11-23 16:51:05 +01:00
}
2021-07-24 17:27:17 +02:00
void RemovePreviewIfDisabled ( )
{
if ( ! Config . GetBool ( Config . Key . disablePreview ) )
return ;
foreach ( TabPage tab in mainTabControl . TabPages )
{
if ( tab . Text . Trim ( ) = = "Preview" )
mainTabControl . TabPages . Remove ( tab ) ;
}
}
2020-11-23 16:51:05 +01:00
public HTTabControl GetMainTabControl ( ) { return mainTabControl ; }
2021-02-27 14:59:50 +01:00
public TextBox GetInputFpsTextbox ( ) { return fpsInTbox ; }
2021-04-29 22:57:00 +02:00
public Button GetPauseBtn ( ) { return pauseBtn ; }
2020-11-23 16:51:05 +01:00
public bool IsInFocus ( ) { return ( ActiveForm = = this ) ; }
2020-12-03 22:06:58 +01:00
public void SetTab ( string tabName )
2020-11-25 20:31:21 +01:00
{
2020-12-03 22:06:58 +01:00
foreach ( TabPage tab in mainTabControl . TabPages )
2020-11-25 20:31:21 +01:00
{
if ( tab . Text . ToLower ( ) = = tabName . ToLower ( ) )
mainTabControl . SelectedTab = tab ;
}
2021-07-24 17:27:17 +02:00
2020-11-25 20:31:21 +01:00
mainTabControl . Refresh ( ) ;
mainTabControl . Update ( ) ;
}
2020-12-17 11:32:45 +01:00
public InterpSettings GetCurrentSettings ( )
2020-11-23 16:51:05 +01:00
{
2020-12-02 01:09:41 +01:00
SetTab ( "interpolate" ) ;
2021-05-17 16:09:19 +02:00
return new InterpSettings ( inputTbox . Text . Trim ( ) , outputTbox . Text . Trim ( ) , GetAi ( ) , currInFpsDetected , currInFps , interpFactorCombox . GetInt ( ) , GetOutMode ( ) , GetModel ( GetAi ( ) ) ) ;
2020-11-23 16:51:05 +01:00
}
2021-05-07 23:06:43 +02:00
public InterpSettings UpdateCurrentSettings ( InterpSettings settings )
{
SetTab ( "interpolate" ) ;
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 . GetInt ( ) ;
settings . outFps = settings . inFps * settings . interpFactor ;
settings . outMode = GetOutMode ( ) ;
2021-05-17 16:09:19 +02:00
settings . model = GetModel ( GetAi ( ) ) ;
2021-05-07 23:06:43 +02:00
return settings ;
}
2020-12-17 11:32:45 +01:00
public void LoadBatchEntry ( InterpSettings entry )
2020-11-23 16:51:05 +01:00
{
inputTbox . Text = entry . inPath ;
outputTbox . Text = entry . outPath ;
interpFactorCombox . Text = entry . interpFactor . ToString ( ) ;
aiCombox . SelectedIndex = Networks . networks . IndexOf ( entry . ai ) ;
SetOutMode ( entry . outMode ) ;
}
public void SetStatus ( string str )
{
Logger . Log ( str , true ) ;
statusLabel . Text = str ;
}
2021-03-19 19:48:16 +01:00
public string GetStatus ( )
{
return statusLabel . Text ;
}
2020-11-23 16:51:05 +01:00
public void SetProgress ( int percent )
{
2021-01-28 11:38:45 +01:00
percent = percent . Clamp ( 0 , 100 ) ;
TaskbarManager . Instance . SetProgressValue ( percent , 100 ) ;
longProgBar . Value = percent ;
2020-11-23 16:51:05 +01:00
longProgBar . Refresh ( ) ;
}
2021-01-18 12:32:01 +01:00
public Size currInRes ;
2021-04-19 19:26:58 +02:00
public Fraction currInFpsDetected ;
2021-04-02 14:36:08 +02:00
public Fraction currInFps ;
2021-01-18 12:32:01 +01:00
public int currInFrames ;
2021-01-30 13:09:59 +01:00
public long currInDuration ;
2021-02-23 12:13:30 +01:00
public long currInDurationCut ;
2021-02-27 14:59:50 +01:00
2021-01-18 12:32:01 +01:00
public void UpdateInputInfo ( )
{
2021-04-02 14:36:08 +02:00
string str = $"Size: {(!currInRes.IsEmpty ? $" { currInRes . Width } x { currInRes . Height } " : " Unknown ")} - " ;
2021-04-19 19:26:58 +02:00
str + = $"Rate: {(currInFpsDetected.GetFloat() > 0f ? $" { currInFpsDetected } ( { currInFpsDetected . GetFloat ( ) } ) " : " Unknown ")} - " ;
2021-04-02 14:36:08 +02:00
str + = $"Frames: {(currInFrames > 0 ? $" { currInFrames } " : " Unknown ")} - " ;
2021-02-23 12:13:30 +01:00
str + = $"Duration: {(currInDuration > 0 ? FormatUtils.MsToTimestamp(currInDuration) : " Unknown ")}" ;
2021-01-18 12:32:01 +01:00
inputInfo . Text = str ;
}
2021-08-01 15:57:35 +02:00
public void InterpolationDone ( )
{
SetStatus ( "Done interpolating!" ) ;
if ( ! BatchProcessing . busy )
CompletionAction ( ) ;
}
public void CompletionAction ( )
{
2021-08-02 15:08:19 +02:00
if ( Program . args . Contains ( "quit-when-done" ) )
Application . Exit ( ) ;
2021-08-01 15:57:35 +02:00
if ( completionAction . SelectedIndex = = 1 )
2021-08-02 12:39:44 +02:00
new TimeoutForm ( completionAction . Text , Application . Exit ) . ShowDialog ( ) ;
2021-08-01 15:57:35 +02:00
if ( completionAction . SelectedIndex = = 2 )
2021-08-02 12:39:44 +02:00
new TimeoutForm ( completionAction . Text , OSUtils . Sleep ) . ShowDialog ( ) ;
2021-08-01 15:57:35 +02:00
if ( completionAction . SelectedIndex = = 3 )
2021-08-02 12:39:44 +02:00
new TimeoutForm ( completionAction . Text , OSUtils . Hibernate ) . ShowDialog ( ) ;
if ( completionAction . SelectedIndex = = 4 )
2021-08-01 15:57:35 +02:00
new TimeoutForm ( completionAction . Text , OSUtils . Shutdown ) . ShowDialog ( ) ;
}
2021-01-28 20:04:08 +01:00
public void ResetInputInfo ( )
{
currInRes = new Size ( ) ;
2021-04-19 19:26:58 +02:00
currInFpsDetected = new Fraction ( ) ;
2021-04-02 14:36:08 +02:00
currInFps = new Fraction ( ) ;
2021-01-28 20:04:08 +01:00
currInFrames = 0 ;
2021-01-30 13:09:59 +01:00
currInDuration = 0 ;
2021-02-23 12:13:30 +01:00
currInDurationCut = 0 ;
2021-01-30 22:00:44 +01:00
UpdateInputInfo ( ) ;
2021-01-28 20:04:08 +01:00
}
2020-11-23 16:51:05 +01:00
void InitAis ( )
{
foreach ( AI ai in Networks . networks )
aiCombox . Items . Add ( ai . friendlyName + " - " + ai . description ) ;
2021-02-03 21:22:30 +01:00
ConfigParser . LoadComboxIndex ( aiCombox ) ;
2020-11-23 16:51:05 +01:00
}
public void Initialized ( )
{
initialized = true ;
runBtn . Enabled = true ;
}
private void browseInputBtn_Click ( object sender , EventArgs e )
{
2021-04-04 11:11:49 +02:00
CommonOpenFileDialog dialog = new CommonOpenFileDialog { InitialDirectory = inputTbox . Text . Trim ( ) , IsFolderPicker = true } ;
2020-11-23 16:51:05 +01:00
if ( dialog . ShowDialog ( ) = = CommonFileDialogResult . Ok )
2020-12-08 16:49:47 +01:00
DragDropHandler ( new string [ ] { dialog . FileName } ) ;
2020-11-23 16:51:05 +01:00
}
private void browseInputFileBtn_Click ( object sender , EventArgs e )
{
2021-04-04 11:11:49 +02:00
CommonOpenFileDialog dialog = new CommonOpenFileDialog { InitialDirectory = inputTbox . Text . Trim ( ) , IsFolderPicker = false } ;
2020-11-23 16:51:05 +01:00
if ( dialog . ShowDialog ( ) = = CommonFileDialogResult . Ok )
2020-12-08 16:49:47 +01:00
DragDropHandler ( new string [ ] { dialog . FileName } ) ;
2020-11-23 16:51:05 +01:00
}
private void browseOutBtn_Click ( object sender , EventArgs e )
{
2021-04-04 11:11:49 +02:00
CommonOpenFileDialog dialog = new CommonOpenFileDialog { InitialDirectory = inputTbox . Text . Trim ( ) , IsFolderPicker = true } ;
2020-11-23 16:51:05 +01:00
if ( dialog . ShowDialog ( ) = = CommonFileDialogResult . Ok )
outputTbox . Text = dialog . FileName ;
}
public void runBtn_Click ( object sender , EventArgs e )
{
2020-12-03 22:06:58 +01:00
if ( ! BatchProcessing . busy ) // Don't load values from gui if batch processing is used
2020-12-17 11:32:45 +01:00
Interpolate . current = GetCurrentSettings ( ) ;
2021-01-13 23:05:23 +01:00
2021-04-29 22:57:00 +02:00
AiProcessSuspend . Reset ( ) ;
2020-12-17 11:32:45 +01:00
Interpolate . Start ( ) ;
2020-12-02 23:11:27 +01:00
}
2021-05-17 16:09:19 +02:00
public ModelCollection . ModelInfo GetModel ( AI currentAi )
2020-12-02 23:11:27 +01:00
{
2021-05-17 16:09:19 +02:00
return AiModels . GetModels ( currentAi ) . models [ aiModel . SelectedIndex ] ;
2020-11-23 16:51:05 +01:00
}
Interpolate . OutMode GetOutMode ( )
{
Interpolate . OutMode outMode = Interpolate . OutMode . VidMp4 ;
2021-01-16 01:19:07 +01:00
if ( outModeCombox . Text . ToLower ( ) . Contains ( "mkv" ) ) outMode = Interpolate . OutMode . VidMkv ;
2020-12-23 16:13:04 +01:00
if ( outModeCombox . Text . ToLower ( ) . Contains ( "webm" ) ) outMode = Interpolate . OutMode . VidWebm ;
if ( outModeCombox . Text . ToLower ( ) . Contains ( "prores" ) ) outMode = Interpolate . OutMode . VidProRes ;
2021-01-16 01:19:07 +01:00
if ( outModeCombox . Text . ToLower ( ) . Contains ( "avi" ) ) outMode = Interpolate . OutMode . VidAvi ;
2020-11-23 16:51:05 +01:00
if ( outModeCombox . Text . ToLower ( ) . Contains ( "gif" ) ) outMode = Interpolate . OutMode . VidGif ;
2020-12-02 15:34:59 +01:00
if ( outModeCombox . Text . ToLower ( ) . Contains ( "image" ) ) outMode = Interpolate . OutMode . ImgPng ;
2020-11-23 16:51:05 +01:00
return outMode ;
}
public void SetOutMode ( Interpolate . OutMode mode )
{
2021-01-16 01:19:07 +01:00
int theIndex = 0 ;
for ( int i = 0 ; i < outModeCombox . Items . Count ; i + + )
{
string currentItem = outModeCombox . Items [ i ] . ToString ( ) . ToLower ( ) ;
if ( mode = = Interpolate . OutMode . VidMkv & & currentItem . Contains ( "mkv" ) ) theIndex = i ;
if ( mode = = Interpolate . OutMode . VidWebm & & currentItem . Contains ( "webm" ) ) theIndex = i ;
if ( mode = = Interpolate . OutMode . VidProRes & & currentItem . Contains ( "prores" ) ) theIndex = i ;
if ( mode = = Interpolate . OutMode . VidAvi & & currentItem . Contains ( "avi" ) ) theIndex = i ;
if ( mode = = Interpolate . OutMode . VidGif & & currentItem . Contains ( "gif" ) ) theIndex = i ;
if ( mode = = Interpolate . OutMode . ImgPng & & currentItem . Contains ( "image" ) ) theIndex = i ;
}
outModeCombox . SelectedIndex = theIndex ;
2020-11-23 16:51:05 +01:00
}
AI GetAi ( )
{
return Networks . networks [ aiCombox . SelectedIndex ] ;
}
void inputTbox_DragEnter ( object sender , DragEventArgs e ) { e . Effect = DragDropEffects . Copy ; }
private void inputTbox_DragDrop ( object sender , DragEventArgs e )
{
2020-12-03 22:21:44 +01:00
DragDropHandler ( ( string [ ] ) e . Data . GetData ( DataFormats . FileDrop ) ) ;
2020-11-23 16:51:05 +01:00
}
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 )
{
2021-04-05 11:58:07 +02:00
UpdateUiFps ( ) ;
2020-11-23 16:51:05 +01:00
}
2021-04-05 11:58:07 +02:00
public void UpdateUiFps ( )
2020-11-23 16:51:05 +01:00
{
2021-04-05 11:58:07 +02:00
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 ( ) ;
2021-04-04 21:54:26 +02:00
2021-04-05 11:58:07 +02:00
if ( ! fpsInTbox . ReadOnly )
currInFps = frac ;
}
else // Parse float
{
fpsInTbox . Text = fpsInTbox . Text . TrimNumbers ( true ) ;
fpsOutTbox . Text = ( fpsInTbox . GetFloat ( ) * interpFactorCombox . GetFloat ( ) ) . ToString ( ) ;
if ( ! fpsInTbox . ReadOnly )
currInFps = new Fraction ( fpsInTbox . GetFloat ( ) ) ;
}
2020-11-23 16:51:05 +01:00
}
private void interpFactorCombox_SelectedIndexChanged ( object sender , EventArgs e )
{
2021-04-05 11:58:07 +02:00
UpdateUiFps ( ) ;
2020-12-17 11:32:45 +01:00
int guiInterpFactor = interpFactorCombox . GetInt ( ) ;
2021-01-13 15:47:05 +01:00
if ( ! initialized )
return ;
string aiName = GetAi ( ) . aiName . Replace ( "_" , "-" ) ;
2021-05-18 14:37:16 +02:00
if ( ! Program . busy & & guiInterpFactor > 2 & & ! GetAi ( ) . supportsAnyExp & & Config . GetInt ( Config . Key . autoEncMode ) > 0 & & ! Logger . GetLastLine ( ) . Contains ( aiName ) )
2021-01-13 15:47:05 +01:00
Logger . Log ( $"Warning: {aiName} doesn't natively support 4x/8x and will run multiple times for {guiInterpFactor}x. Auto-Encode will only work on the last run." ) ;
2020-11-23 16:51:05 +01:00
}
2021-01-04 14:27:34 +01:00
public void SetWorking ( bool state , bool allowCancel = true )
2020-11-23 16:51:05 +01:00
{
2021-01-05 23:55:16 +01:00
Logger . Log ( $"SetWorking({state})" , true ) ;
2021-01-06 21:44:09 +01:00
SetProgress ( - 1 ) ;
2021-01-15 19:28:42 +01:00
Control [ ] controlsToDisable = new Control [ ] { runBtn , runStepBtn , stepSelector , settingsBtn } ;
2020-12-02 23:11:27 +01:00
Control [ ] controlsToHide = new Control [ ] { runBtn , runStepBtn , stepSelector } ;
progressCircle . Visible = state ;
2021-04-29 22:57:00 +02:00
busyControlsPanel . Visible = state ;
2020-11-23 16:51:05 +01:00
foreach ( Control c in controlsToDisable )
c . Enabled = ! state ;
2021-04-29 22:57:00 +02:00
2020-12-02 23:11:27 +01:00
foreach ( Control c in controlsToHide )
c . Visible = ! state ;
2021-04-29 22:57:00 +02:00
busyControlsPanel . Enabled = allowCancel ;
2020-12-02 23:11:27 +01:00
Program . busy = state ;
2021-02-21 12:39:25 +01:00
Program . mainForm . UpdateStepByStepControls ( ) ;
2020-11-23 16:51:05 +01:00
}
2021-01-14 00:39:49 +01:00
string lastAiComboxStr = "" ;
2020-11-23 16:51:05 +01:00
private void aiCombox_SelectedIndexChanged ( object sender , EventArgs e )
{
2021-01-14 00:39:49 +01:00
if ( string . IsNullOrWhiteSpace ( aiCombox . Text ) | | aiCombox . Text = = lastAiComboxStr ) return ;
lastAiComboxStr = aiCombox . Text ;
2021-02-28 11:56:09 +01:00
UpdateAiModelCombox ( ) ;
2021-02-03 21:22:30 +01:00
if ( initialized )
ConfigParser . SaveComboxIndex ( aiCombox ) ;
2021-02-28 11:56:09 +01:00
2020-11-23 16:51:05 +01:00
interpFactorCombox_SelectedIndexChanged ( null , null ) ;
}
2021-02-28 11:56:09 +01:00
public void UpdateAiModelCombox ( )
{
2021-05-17 11:46:49 +02:00
aiModel = UIUtils . LoadAiModelsIntoGui ( aiModel , GetAi ( ) ) ;
2021-02-28 11:56:09 +01:00
}
2020-11-23 16:51:05 +01:00
private void Form1_FormClosing ( object sender , FormClosingEventArgs e )
{
2021-05-17 16:09:19 +02:00
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 = MessageBox . Show ( $"Are you sure you want to exit the program?\n\n{reason}" , "Are you sure?" , MessageBoxButtons . YesNo ) ;
if ( dialog = = DialogResult . No )
e . Cancel = true ;
2020-11-23 16:51:05 +01:00
}
private void licenseBtn_Click ( object sender , EventArgs e )
{
2021-03-11 12:58:18 +01:00
Process . Start ( "explorer.exe" , Path . Combine ( Paths . GetPkgPath ( ) , Paths . licensesDir ) ) ;
2020-11-23 16:51:05 +01:00
}
private void Form1_DragEnter ( object sender , DragEventArgs e ) { e . Effect = DragDropEffects . Copy ; }
private void Form1_DragDrop ( object sender , DragEventArgs e )
2020-12-03 22:21:44 +01:00
{
DragDropHandler ( ( string [ ] ) e . Data . GetData ( DataFormats . FileDrop ) ) ;
}
public void DragDropHandler ( string [ ] files )
2020-11-23 16:51:05 +01:00
{
if ( Program . busy ) return ;
2020-12-03 22:21:44 +01:00
2021-08-02 15:08:19 +02:00
bool start = Program . initialRun & & Program . args . Contains ( "start" ) ;
if ( files . Length > 1 )
2020-12-03 22:21:44 +01:00
{
queueBtn_Click ( null , null ) ;
if ( BatchProcessing . currentBatchForm ! = null )
2021-08-02 15:08:19 +02:00
BatchProcessing . currentBatchForm . LoadDroppedPaths ( files , start ) ;
2020-12-03 22:21:44 +01:00
}
else
{
SetTab ( "interpolation" ) ;
2021-04-25 21:12:45 +02:00
Logger . Log ( "Selected video/directory: " + Path . GetFileName ( files [ 0 ] ) , true ) ;
2020-12-03 22:21:44 +01:00
inputTbox . Text = files [ 0 ] ;
2021-02-01 18:05:50 +01:00
2021-02-02 21:48:18 +01:00
bool resume = ( IOUtils . GetAmountOfFiles ( Path . Combine ( files [ 0 ] , Paths . resumeDir ) , true ) > 0 ) ;
ResumeUtils . resumeNextRun = resume ;
if ( resume )
2021-02-01 18:05:50 +01:00
ResumeUtils . LoadTempFolder ( files [ 0 ] ) ;
2021-02-23 12:13:30 +01:00
trimCombox . SelectedIndex = 0 ;
2021-08-02 15:08:19 +02:00
MainUiFunctions . InitInput ( outputTbox , inputTbox , fpsInTbox , start ) ;
2020-12-03 22:21:44 +01:00
}
2020-11-23 16:51:05 +01:00
}
private void cancelBtn_Click ( object sender , EventArgs e )
{
2021-04-29 22:57:00 +02:00
DialogResult dialog = MessageBox . Show ( $"Are you sure you want to cancel the interpolation?" , "Are you sure?" , MessageBoxButtons . YesNo ) ;
if ( dialog = = DialogResult . Yes )
{
SetTab ( "interpolation" ) ;
Interpolate . Cancel ( ) ;
}
2020-11-23 16:51:05 +01:00
}
private void discordBtn_Click ( object sender , EventArgs e )
{
2021-02-09 16:07:57 +01:00
Process . Start ( "https://discord.gg/eJHD2NSJRe" ) ;
2020-11-23 16:51:05 +01:00
}
private void paypalBtn_Click ( object sender , EventArgs e )
{
2021-02-09 16:07:57 +01:00
Process . Start ( "https://www.paypal.com/paypalme/nmkd/10" ) ;
2020-11-23 16:51:05 +01:00
}
private void patreonBtn_Click ( object sender , EventArgs e )
{
2021-02-09 16:07:57 +01:00
Process . Start ( "https://patreon.com/n00mkrad" ) ;
2020-11-23 16:51:05 +01:00
}
private void settingsBtn_Click ( object sender , EventArgs e )
{
new SettingsForm ( ) . ShowDialog ( ) ;
}
private void queueBtn_Click ( object sender , EventArgs e )
{
if ( BatchProcessing . currentBatchForm ! = null )
{
BatchProcessing . currentBatchForm . WindowState = FormWindowState . Normal ;
BatchProcessing . currentBatchForm . BringToFront ( ) ;
}
else
{
new BatchForm ( ) . Show ( ) ;
}
}
private void previewPicturebox_MouseClick ( object sender , MouseEventArgs e )
{
2021-04-22 16:15:17 +02:00
if ( InterpolationProgress . bigPreviewForm = = null )
2020-11-23 16:51:05 +01:00
{
2021-04-22 16:15:17 +02:00
InterpolationProgress . bigPreviewForm = new BigPreviewForm ( ) ;
InterpolationProgress . bigPreviewForm . Show ( ) ;
InterpolationProgress . bigPreviewForm . SetImage ( previewPicturebox . Image ) ;
2020-11-23 16:51:05 +01:00
}
}
private async void updateBtn_Click ( object sender , EventArgs e )
{
new UpdaterForm ( ) . ShowDialog ( ) ;
}
2020-11-25 17:27:15 +01:00
2020-11-27 14:35:32 +01:00
private void welcomeLabel2_Click ( object sender , EventArgs e )
{
SetTab ( "interpolation" ) ;
}
2020-11-29 16:10:31 +01:00
2021-02-21 12:39:25 +01:00
public void UpdateStepByStepControls ( )
2020-11-29 16:10:31 +01:00
{
2021-02-21 12:39:25 +01:00
if ( stepSelector . SelectedIndex < 0 )
2020-12-03 01:20:33 +01:00
stepSelector . SelectedIndex = 0 ;
2021-02-01 21:54:30 +01:00
2021-05-18 14:37:16 +02:00
bool stepByStep = Config . GetInt ( Config . Key . processingMode ) = = 1 ;
2021-02-01 22:06:50 +01:00
runBtn . Visible = ! stepByStep & & ! Program . busy ;
2020-11-29 16:10:31 +01:00
}
private async void runStepBtn_Click ( object sender , EventArgs e )
{
2020-12-02 01:09:41 +01:00
SetTab ( "interpolate" ) ;
2020-11-29 16:10:31 +01:00
await InterpolateSteps . Run ( stepSelector . Text ) ;
}
private void mainTabControl_SelectedIndexChanged ( object sender , EventArgs e )
{
if ( ! initialized ) return ;
aiCombox_SelectedIndexChanged ( null , null ) ;
}
2021-02-23 12:13:30 +01:00
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 ) ;
}
2021-02-23 15:53:32 +01:00
#region Quick Settings
public void SaveQuickSettings ( object sender , EventArgs e )
{
2021-02-24 15:12:49 +01:00
if ( ! quickSettingsInitialized ) return ;
2021-02-28 13:46:50 +01:00
if ( Program . busy )
LoadQuickSettings ( ) ; // Discard any changes if busy
2021-02-23 15:53:32 +01:00
ConfigParser . SaveGuiElement ( maxVidHeight , ConfigParser . StringMode . Int ) ;
ConfigParser . SaveComboxIndex ( dedupMode ) ;
ConfigParser . SaveComboxIndex ( mpdecimateMode ) ;
ConfigParser . SaveGuiElement ( dedupThresh ) ;
ConfigParser . SaveGuiElement ( enableLoop ) ;
ConfigParser . SaveGuiElement ( scnDetect ) ;
ConfigParser . SaveGuiElement ( scnDetectValue ) ;
2021-05-26 18:30:10 +02:00
ConfigParser . SaveGuiElement ( maxFps ) ;
2021-02-23 15:53:32 +01:00
}
2021-02-28 13:46:50 +01:00
public void LoadQuickSettings ( object sender = null , EventArgs e = null )
2021-02-23 15:53:32 +01:00
{
ConfigParser . LoadGuiElement ( maxVidHeight ) ;
ConfigParser . LoadComboxIndex ( dedupMode ) ;
ConfigParser . LoadComboxIndex ( mpdecimateMode ) ;
ConfigParser . LoadGuiElement ( dedupThresh ) ;
ConfigParser . LoadGuiElement ( enableLoop ) ;
ConfigParser . LoadGuiElement ( scnDetect ) ;
ConfigParser . LoadGuiElement ( scnDetectValue ) ;
2021-05-26 18:30:10 +02:00
ConfigParser . LoadGuiElement ( maxFps ) ;
2021-02-24 15:12:49 +01:00
quickSettingsInitialized = true ;
2021-02-23 15:53:32 +01:00
}
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 )
{
2021-02-28 13:46:50 +01:00
if ( Program . busy ) return ;
2021-02-23 15:53:32 +01:00
new SettingsForm ( ) . ShowDialog ( ) ;
}
#endregion
2021-03-19 19:34:48 +01:00
private void scnDetectTestBtn_Click ( object sender , EventArgs e )
{
Magick . SceneDetect . RunSceneDetection ( inputTbox . Text . Trim ( ) ) ;
}
2021-04-29 22:57:00 +02:00
private void pauseBtn_Click ( object sender , EventArgs e )
{
AiProcessSuspend . SuspendResumeAi ( ! AiProcessSuspend . aiProcFrozen ) ;
}
2021-05-04 00:20:31 +02:00
private void debugBtn_Click ( object sender , EventArgs e )
{
new DebugForm ( ) . ShowDialog ( ) ;
}
2021-07-14 10:58:07 +02:00
private void encodingSettingsBtn_Click ( object sender , EventArgs e )
{
new SettingsForm ( 4 ) . ShowDialog ( ) ;
}
2020-11-23 16:51:05 +01:00
}
2021-02-28 16:26:46 +01:00
}