OSDN Git Service

WinGUI:
[handbrake-jp/handbrake-jp-git.git] / win / C# / frmMain.cs
1 using System;\r
2 using System.Collections.Generic;\r
3 using System.Collections.Specialized;\r
4 using System.ComponentModel;\r
5 using System.Data;\r
6 using System.Drawing;\r
7 using System.Text;\r
8 using System.Windows.Forms;\r
9 using System.Net;\r
10 using System.IO;\r
11 using System.Diagnostics;\r
12 using System.Threading;\r
13 using System.Runtime.InteropServices;\r
14 \r
15 \r
16 namespace Handbrake\r
17 {\r
18 \r
19     public partial class frmMain : Form\r
20     {\r
21         // -------------------------------------------------------------- \r
22         // Applicaiton Startup Stuff\r
23         // --------------------------------------------------------------\r
24 \r
25         #region Application Startup\r
26 \r
27         private Process hbProc;\r
28         private Parsing.DVD thisDVD;        \r
29         private frmQueue queueWindow = new frmQueue();  \r
30         //private frmDvdInfo dvdInfoWindow = new frmDvdInfo();\r
31 \r
32  \r
33         public frmMain()\r
34         {\r
35 \r
36             ThreadPool.QueueUserWorkItem(showSplash);\r
37             Thread.Sleep(1000);\r
38 \r
39             InitializeComponent();\r
40 \r
41             // This is a quick Hack fix for the cross-thread problem with frmDvdIndo ************************\r
42             //dvdInfoWindow.Show();\r
43             //dvdInfoWindow.Hide();\r
44             // **********************************************************************************************\r
45 \r
46             // System Requirements Check\r
47             systemCheck();\r
48 \r
49             // Set the Version number lable to the corect version.\r
50             Version.Text = "Version " + Properties.Settings.Default.GuiVersion;\r
51 \r
52             // Run the update checker.\r
53             updateCheck();\r
54 \r
55             // Now load the users default if required. (Will overide the above setting)\r
56             loadUserDefaults();\r
57 \r
58             // Display the quick start window if required.\r
59             quickStart();\r
60 \r
61             // Enable or disable tooltips\r
62             tooltip();\r
63 \r
64 \r
65             // Hide the presets part of the window\r
66             this.Width = 590;\r
67 \r
68             // Create and initializes a new StringCollection.\r
69             StringCollection myCol = new StringCollection();\r
70             // Add a range of elements from an array to the end of the StringCollection.\r
71             String[] myArr = new String[] { "RED", "orange", "yellow", "RED", "green", "blue", "RED", "indigo", "violet", "RED" };\r
72             myCol.AddRange(myArr);\r
73 \r
74             Properties.Settings.Default.BuiltInPresets = myCol;\r
75   \r
76 \r
77         }\r
78 \r
79         // Functions to preform tasks required on startup.\r
80         #region Initializeation Functions\r
81         \r
82         private void showSplash(object sender)\r
83         {\r
84             Form splash = new frmSplashScreen();\r
85             splash.Show();\r
86             Thread.Sleep(1500);  // Display splash screen for 1.5 Seconds\r
87             splash.Close(); // Then close.\r
88         }\r
89 \r
90         private void loadUserDefaults()\r
91         { \r
92             try\r
93             {\r
94                 if (Properties.Settings.Default.defaultSettings == "Checked")\r
95                 {\r
96                     // Source\r
97                     text_source.Text = Properties.Settings.Default.DVDSource;\r
98                     drp_dvdtitle.Text = Properties.Settings.Default.DVDTitle;\r
99                     drop_chapterStart.Text = Properties.Settings.Default.ChapterStart;\r
100                     drop_chapterFinish.Text = Properties.Settings.Default.ChapterFinish;\r
101 \r
102                     // Destination\r
103                     text_destination.Text = Properties.Settings.Default.VideoDest;\r
104                     drp_videoEncoder.Text = Properties.Settings.Default.VideoEncoder;\r
105                     drp_audioCodec.Text = Properties.Settings.Default.AudioEncoder;\r
106                     text_width.Text = Properties.Settings.Default.Width;\r
107                     text_height.Text = Properties.Settings.Default.Height;\r
108 \r
109                     // Picture Settings Tab\r
110                     drp_crop.Text = Properties.Settings.Default.CroppingOption;\r
111                     text_top.Text = Properties.Settings.Default.CropTop;\r
112                     text_bottom.Text = Properties.Settings.Default.CropBottom;\r
113                     text_left.Text = Properties.Settings.Default.CropLeft;\r
114                     text_right.Text = Properties.Settings.Default.CropRight;\r
115                     drp_subtitle.Text = Properties.Settings.Default.Subtitles;\r
116 \r
117                     // Video Settings Tab\r
118                     text_bitrate.Text = Properties.Settings.Default.VideoBitrate;\r
119                     text_filesize.Text = Properties.Settings.Default.VideoFilesize;\r
120                     slider_videoQuality.Value = Properties.Settings.Default.VideoQuality;\r
121 \r
122                     if (Properties.Settings.Default.TwoPass == "Checked")\r
123                     {\r
124                         check_2PassEncode.CheckState = CheckState.Checked;\r
125                     }\r
126 \r
127                     drp_deInterlace_option.Text = Properties.Settings.Default.DeInterlace;\r
128                     drp_deNoise.Text = Properties.Settings.Default.denoise;\r
129 \r
130                     if (Properties.Settings.Default.detelecine == "Checked")\r
131                     {\r
132                         check_detelecine.CheckState = CheckState.Checked;\r
133                     }\r
134 \r
135                     if (Properties.Settings.Default.detelecine == "Checked")\r
136                     {\r
137                         check_deblock.CheckState = CheckState.Checked;\r
138                     }\r
139 \r
140 \r
141                     if (Properties.Settings.Default.Grayscale == "Checked")\r
142                     {\r
143                         check_grayscale.CheckState = CheckState.Checked;\r
144                     }\r
145 \r
146                     drp_videoFramerate.Text = Properties.Settings.Default.Framerate;\r
147 \r
148                     if (Properties.Settings.Default.PixelRatio == "Checked")\r
149                     {\r
150                         CheckPixelRatio.CheckState = CheckState.Checked;\r
151                     }\r
152                     if (Properties.Settings.Default.turboFirstPass == "Checked")\r
153                     {\r
154                         check_turbo.CheckState = CheckState.Checked;\r
155                     }\r
156                     if (Properties.Settings.Default.largeFile == "Checked")\r
157                     {\r
158                         check_largeFile.CheckState = CheckState.Checked;\r
159                     }\r
160                     // Audio Settings Tab\r
161                     drp_audioBitrate.Text = Properties.Settings.Default.AudioBitrate;\r
162                     drp_audioSampleRate.Text = Properties.Settings.Default.AudioSampleRate;\r
163                     drp_audioChannels.Text = Properties.Settings.Default.AudioChannels;\r
164 \r
165                     // H264 Tab\r
166                     if (Properties.Settings.Default.CRF == "Checked")\r
167                     {\r
168                         CheckCRF.CheckState = CheckState.Checked;\r
169                     }\r
170                     rtf_h264advanced.Text = Properties.Settings.Default.H264;\r
171 \r
172                     groupBox_output.Text = "Output Settings (Preset: " + Properties.Settings.Default.SelectedPreset + ")";\r
173                 }\r
174                 else\r
175                 {\r
176                     // Load the default preset on lauch\r
177                     ListBox_Presets.SelectedItem = "Normal";\r
178                 }\r
179             }\r
180             catch (Exception)\r
181             {\r
182                 // No real need to alert the user. Try/Catch only in just incase there is a problem reading the settings xml file.\r
183             }\r
184         }\r
185 \r
186         private int updateCheck()\r
187         {\r
188             try\r
189             {\r
190                 String updateFile = Properties.Settings.Default.updateFile;\r
191                 WebClient client = new WebClient();\r
192                 String data = client.DownloadString(updateFile);\r
193                 String[] versionData = data.Split('\n');\r
194 \r
195                 if ((versionData[0] != Properties.Settings.Default.GuiVersion) || (versionData[1] != Properties.Settings.Default.CliVersion))\r
196                 {\r
197                     lbl_update.Visible = true;\r
198                     return 1;\r
199                 }\r
200                 else\r
201                 {\r
202                     return 0;\r
203                 }\r
204             }\r
205             catch (Exception)\r
206             {\r
207                 // Silently ignore the error\r
208                 return 0;\r
209             }\r
210         }\r
211 \r
212         private void quickStart()\r
213         {\r
214             if ((Properties.Settings.Default.QuickStartWindow == "Checked") || (Properties.Settings.Default.QuickStartWindow == ""))\r
215             {\r
216                 frmQuickStart quickstart = new frmQuickStart();\r
217                 quickstart.ShowDialog();\r
218             }\r
219         }\r
220 \r
221         private void tooltip()\r
222         {\r
223             if (Properties.Settings.Default.tooltipEnable == "Checked")\r
224             {\r
225                 ToolTip.Active = true;\r
226             }\r
227         }\r
228 \r
229         #region Memory Check\r
230 \r
231         public struct MEMORYSTATUS\r
232         {\r
233             public UInt32 dwLength;\r
234             public UInt32 dwMemoryLoad;\r
235             public UInt32 dwTotalPhys; // Used\r
236             public UInt32 dwAvailPhys;\r
237             public UInt32 dwTotalPageFile;\r
238             public UInt32 dwAvailPageFile;\r
239             public UInt32 dwTotalVirtual;\r
240             public UInt32 dwAvailVirtual;\r
241             // Aditional Varibles left in for future usage (JIC)\r
242         }\r
243 \r
244         [DllImport("kernel32.dll")]\r
245         public static extern void GlobalMemoryStatus\r
246         (\r
247             ref MEMORYSTATUS lpBuffer\r
248         );\r
249 \r
250         public uint CheckMemeory()\r
251         {\r
252             // Call the native GlobalMemoryStatus method\r
253             // with the defined structure.\r
254             MEMORYSTATUS memStatus = new MEMORYSTATUS();\r
255             GlobalMemoryStatus(ref memStatus);\r
256 \r
257             // Use a StringBuilder for the message box string.\r
258             uint MemoryInfo = memStatus.dwTotalPhys;\r
259 \r
260             // Return the Ram Information\r
261             return MemoryInfo;\r
262 \r
263         }\r
264 \r
265 \r
266         #endregion\r
267         Boolean preventLaunch = false;\r
268         private void systemCheck()\r
269         {\r
270             try\r
271             {\r
272                 // Make sure the screen resolution is not below 1024x768\r
273                 System.Windows.Forms.Screen scr = System.Windows.Forms.Screen.PrimaryScreen;\r
274                 if ((scr.Bounds.Width < 1024) || (scr.Bounds.Height < 768))\r
275                 {\r
276                     MessageBox.Show("Your system does not meet the minimum requirements for HandBrake. \n Screen resolution is too Low. Must be 1024x768 or greater", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
277                     preventLaunch = true;\r
278                 }\r
279 \r
280                 // Make sure the system has enough RAM. 384MB or greater\r
281                 uint memory = CheckMemeory();\r
282 \r
283                 if (memory < 319) // Set to 319 to allow for 64MB dedicated to video Memory and Windows returnig the memory figure slightly out.\r
284                 {\r
285                     MessageBox.Show("Your system does not meet the minimum requirements for HandBrake. \n Insufficient Memory. 384MB or greater required.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
286                     preventLaunch = true;\r
287                 }\r
288             }\r
289             catch (Exception exc)\r
290             {\r
291                 if (Properties.Settings.Default.GuiDebug == "Checked")\r
292                 {\r
293                     MessageBox.Show("frmMain.cs - systemCheck() " + exc.ToString());\r
294                 }\r
295             }\r
296         }\r
297 \r
298         #endregion\r
299 \r
300         // Close the Application on main window load if required by the system Check\r
301         #region Form Load\r
302             private void frmMain_Load(object sender, EventArgs e)\r
303         {\r
304             if (preventLaunch == true)\r
305             {\r
306                 Application.Exit();\r
307             }\r
308         }\r
309         #endregion\r
310 \r
311         #endregion\r
312 \r
313         // -------------------------------------------------------------- \r
314         // The main Menu bar.\r
315         // -------------------------------------------------------------- \r
316 \r
317         #region File Menu\r
318 \r
319         private void mnu_open_Click(object sender, EventArgs e)\r
320         {\r
321             string filename;\r
322             File_Open.ShowDialog();\r
323             filename = File_Open.FileName;\r
324             if (filename != "")\r
325             {\r
326                 try\r
327                 {\r
328                     // Create StreamReader & open file\r
329                     StreamReader line = new StreamReader(filename);\r
330                     string temporyLine; // Used for reading the line into a varible before processing on the checkState items below.\r
331                     \r
332                     // Read in the data and set the correct GUI component with the setting.\r
333                     text_source.Text = line.ReadLine();\r
334                     drp_dvdtitle.Text = line.ReadLine();\r
335                     drop_chapterStart.Text = line.ReadLine();\r
336                     drop_chapterFinish.Text = line.ReadLine();\r
337                     text_destination.Text = line.ReadLine();\r
338                     drp_videoEncoder.Text = line.ReadLine();\r
339                     drp_audioCodec.Text = line.ReadLine();\r
340                     text_width.Text = line.ReadLine();\r
341                     text_height.Text = line.ReadLine();\r
342                     text_top.Text = line.ReadLine();\r
343                     text_bottom.Text = line.ReadLine();\r
344                     text_left.Text = line.ReadLine();\r
345                     text_right.Text = line.ReadLine();\r
346                     drp_subtitle.Text = line.ReadLine();\r
347                     text_bitrate.Text = line.ReadLine();\r
348                     text_filesize.Text = line.ReadLine();\r
349                     slider_videoQuality.Value = int.Parse(line.ReadLine());\r
350 \r
351                     temporyLine = line.ReadLine();\r
352                     if (temporyLine == "Checked")\r
353                     {\r
354                         check_2PassEncode.CheckState = CheckState.Checked;\r
355                     }\r
356 \r
357                     drp_deInterlace_option.Text = line.ReadLine();\r
358 \r
359                     temporyLine = line.ReadLine();\r
360                     if (temporyLine == "Checked")\r
361                     {\r
362                         check_grayscale.CheckState = CheckState.Checked;\r
363                     }\r
364 \r
365                     drp_videoFramerate.Text = line.ReadLine();\r
366 \r
367                     temporyLine = line.ReadLine();\r
368                     if (temporyLine == "Checked")\r
369                     {\r
370                         Check_ChapterMarkers.CheckState = CheckState.Checked;\r
371                     }\r
372 \r
373                     temporyLine = line.ReadLine();\r
374                     if (temporyLine == "Checked")\r
375                     {\r
376                         CheckPixelRatio.CheckState = CheckState.Checked;\r
377                     }\r
378 \r
379                     temporyLine = line.ReadLine();\r
380                     if (temporyLine == "Checked")\r
381                     {\r
382                         check_turbo.CheckState = CheckState.Checked;\r
383                     }\r
384 \r
385                     temporyLine = line.ReadLine();\r
386                     if (temporyLine == "Checked")\r
387                     {\r
388                         check_largeFile.CheckState = CheckState.Checked;\r
389                     }\r
390    \r
391                     drp_audioBitrate.Text = line.ReadLine();\r
392                     drp_audioSampleRate.Text = line.ReadLine();\r
393                     drp_audioChannels.Text = line.ReadLine();\r
394                     drp_audioMixDown.Text = line.ReadLine();\r
395                     \r
396                     // Advanced H264 Options\r
397                     temporyLine = line.ReadLine();\r
398                     if (temporyLine == "Checked")\r
399                     {\r
400                         CheckCRF.CheckState = CheckState.Checked;\r
401                     }\r
402                     rtf_h264advanced.Text = line.ReadLine();\r
403 \r
404                     // Close the stream\r
405                     line.Close();\r
406 \r
407 \r
408                     // Fix for SliderValue not appearing when Opening saved file\r
409                     SliderValue.Text = slider_videoQuality.Value + "%";\r
410 \r
411                 } catch (Exception){\r
412                     MessageBox.Show("Unable to load profile.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);\r
413                 }\r
414             }\r
415         }\r
416 \r
417         private void mnu_save_Click(object sender, EventArgs e)\r
418         {\r
419 \r
420             string filename;\r
421             File_Save.ShowDialog();\r
422             filename = File_Save.FileName;\r
423             if (filename != "")\r
424             {\r
425                 try\r
426                 {\r
427                     // Create a StreamWriter and open the file\r
428                     StreamWriter line = new StreamWriter(filename);\r
429 \r
430                     //Source\r
431                     line.WriteLine(text_source.Text);\r
432                     line.WriteLine(drp_dvdtitle.Text);\r
433                     line.WriteLine(drop_chapterStart.Text);\r
434                     line.WriteLine(drop_chapterFinish.Text);\r
435                     //Destination\r
436                     line.WriteLine(text_destination.Text);\r
437                     line.WriteLine(drp_videoEncoder.Text);\r
438                     line.WriteLine(drp_audioCodec.Text);\r
439                     line.WriteLine(text_width.Text);\r
440                     line.WriteLine(text_height.Text);\r
441                     //Picture Settings Tab\r
442                     line.WriteLine(text_top.Text);\r
443                     line.WriteLine(text_bottom.Text);\r
444                     line.WriteLine(text_left.Text);\r
445                     line.WriteLine(text_right.Text);\r
446                     line.WriteLine(drp_subtitle.Text);\r
447                     //Video Settings Tab\r
448                     line.WriteLine(text_bitrate.Text);\r
449                     line.WriteLine(text_filesize.Text);\r
450                     line.WriteLine(slider_videoQuality.Value.ToString());\r
451                     line.WriteLine(check_2PassEncode.CheckState.ToString());\r
452                     line.WriteLine(drp_deInterlace_option.Text);\r
453                     line.WriteLine(check_grayscale.CheckState.ToString());\r
454                     line.WriteLine(drp_videoFramerate.Text);\r
455                     line.WriteLine(Check_ChapterMarkers.CheckState.ToString());\r
456                     line.WriteLine(CheckPixelRatio.CheckState.ToString());\r
457                     line.WriteLine(check_turbo.CheckState.ToString());\r
458                     line.WriteLine(check_largeFile.CheckState.ToString());\r
459                     //Audio Settings Tab\r
460                     line.WriteLine(drp_audioBitrate.Text);\r
461                     line.WriteLine(drp_audioSampleRate.Text);\r
462                     line.WriteLine(drp_audioChannels.Text);\r
463                     line.WriteLine(drp_audioMixDown.Text);\r
464                     //H264 Tab\r
465                     line.WriteLine(CheckCRF.CheckState.ToString());\r
466                     line.WriteLine(rtf_h264advanced.Text);\r
467                     // close the stream\r
468                     line.Close();\r
469                     MessageBox.Show("Your profile has been sucessfully saved.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);\r
470                 }\r
471                 catch(Exception)\r
472                 {\r
473                     MessageBox.Show("Unable to write to the file. Please make sure the location has the correct permissions for file writing.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);\r
474                 }\r
475                 \r
476             }\r
477         }\r
478 \r
479         private void mnu_update_Click(object sender, EventArgs e)\r
480         {\r
481             int update = updateCheck();\r
482             if (update == 1)\r
483             {\r
484                 MessageBox.Show("There is a new update available. Please visit http://handbrake.m0k.org for details!", "Update Check", MessageBoxButtons.OK, MessageBoxIcon.Information);\r
485             }\r
486             else\r
487             {\r
488                 MessageBox.Show("There are no new updates at this time.", "Update Check", MessageBoxButtons.OK, MessageBoxIcon.Information);\r
489             }\r
490         }\r
491 \r
492         private void mnu_exit_Click(object sender, EventArgs e)\r
493         {\r
494             Application.Exit();\r
495         }\r
496 \r
497         #endregion\r
498 \r
499         #region Tools Menu\r
500 \r
501         private void mnu_encode_Click(object sender, EventArgs e)\r
502         {\r
503             showQueue();\r
504         }\r
505    \r
506         private void mnu_viewDVDdata_Click(object sender, EventArgs e)\r
507         {\r
508             frmDvdInfo dvdInfoWindow = new frmDvdInfo();\r
509             dvdInfoWindow.Show();\r
510         }\r
511 \r
512         private void mnu_options_Click(object sender, EventArgs e)\r
513         {\r
514             Form Options = new frmOptions();\r
515             Options.ShowDialog();\r
516         }\r
517 \r
518         #endregion\r
519 \r
520         #region Presets Menu\r
521 \r
522         private void mnu_presetReset_Click(object sender, EventArgs e)\r
523         {\r
524             ListBox_Presets.Items.Clear();\r
525             ListBox_Presets.Items.Add("Animation");\r
526             ListBox_Presets.Items.Add("AppleTV");\r
527             ListBox_Presets.Items.Add("Bedlam");\r
528             ListBox_Presets.Items.Add("Blind");\r
529             ListBox_Presets.Items.Add("Broke");\r
530             ListBox_Presets.Items.Add("Classic");\r
531             ListBox_Presets.Items.Add("Constant Quality Rate");\r
532             ListBox_Presets.Items.Add("Deux Six Quatre");\r
533             ListBox_Presets.Items.Add("Film");\r
534             ListBox_Presets.Items.Add("iPhone");\r
535             ListBox_Presets.Items.Add("iPod High-Rez");\r
536             ListBox_Presets.Items.Add("iPod Low-Rez");\r
537             ListBox_Presets.Items.Add("Normal");\r
538             ListBox_Presets.Items.Add("PS3");\r
539             ListBox_Presets.Items.Add("PSP");\r
540             ListBox_Presets.Items.Add("QuickTime");\r
541             ListBox_Presets.Items.Add("Television");\r
542 \r
543             if (presetStatus == false)\r
544             {\r
545                 this.Width = 881;\r
546                 presetStatus = true;\r
547                 btn_presets.Text = "Hide Presets";\r
548             }\r
549         }\r
550 \r
551         private void mnu_SelectDefault_Click(object sender, EventArgs e)\r
552         {\r
553             ListBox_Presets.SelectedItem = "Normal";\r
554             if (presetStatus == false)\r
555             {\r
556                 this.Width = 881;\r
557                 presetStatus = true;\r
558                 btn_presets.Text = "Hide Presets";\r
559             }\r
560         }\r
561 \r
562         #endregion\r
563 \r
564         #region Help Menu\r
565 \r
566         private void mnu_wiki_Click(object sender, EventArgs e)\r
567         {\r
568            Process.Start("http://handbrake.m0k.org/trac");\r
569         }\r
570 \r
571         private void mnu_faq_Click(object sender, EventArgs e)\r
572         {\r
573             Process.Start("http://handbrake.m0k.org/trac/wiki/WindowsGuiFaq");\r
574         }\r
575 \r
576         private void mnu_onlineDocs_Click(object sender, EventArgs e)\r
577         {\r
578             Process.Start("http://handbrake.m0k.org/?page_id=11");\r
579         }\r
580 \r
581         private void mnu_homepage_Click(object sender, EventArgs e)\r
582         {\r
583            Process.Start("http://handbrake.m0k.org");\r
584         }\r
585 \r
586         private void mnu_forum_Click(object sender, EventArgs e)\r
587         {\r
588             Process.Start("http://handbrake.m0k.org/forum");\r
589         }\r
590 \r
591         private void mnu_about_Click(object sender, EventArgs e)\r
592         {\r
593                         Form About = new frmAbout();\r
594             About.ShowDialog();\r
595         }\r
596 \r
597         #endregion\r
598 \r
599         // -------------------------------------------------------------- \r
600         // Buttons on the main Window\r
601         // --------------------------------------------------------------\r
602 \r
603         #region Buttons\r
604         private void btn_Browse_Click(object sender, EventArgs e)\r
605         {\r
606             String filename =""; \r
607                     text_source.Text = "";\r
608             frmDvdInfo dvdInfoWindow = new frmDvdInfo();                 \r
609                     if (RadioDVD.Checked) \r
610                     { \r
611                         DVD_Open.ShowDialog(); \r
612                         filename = DVD_Open.SelectedPath; \r
613                         if (filename != "") \r
614                         { \r
615                             Form frmRD = new frmReadDVD(filename, this, dvdInfoWindow); \r
616                             text_source.Text = filename; \r
617                             frmRD.ShowDialog(); \r
618                         } \r
619                      } \r
620                      else \r
621                      { \r
622                         ISO_Open.ShowDialog(); \r
623                         filename = ISO_Open.FileName; \r
624                         if (filename != "") \r
625                         { \r
626                             Form frmRD = new frmReadDVD(filename, this, dvdInfoWindow); \r
627                             text_source.Text = filename; \r
628                             frmRD.ShowDialog(); \r
629                         } \r
630                      }   \r
631                  \r
632                      // Check if there was titles in the dvd title dropdown \r
633                      if (filename == "") \r
634                      { \r
635                         text_source.Text = "Click 'Browse' to continue"; \r
636                      } \r
637                  \r
638                      if (drp_dvdtitle.Items.Count == 0) \r
639                      { \r
640                         MessageBox.Show("No Title(s) found. Please make sure you have selected a valid, non-copy protected source. Please refer to the FAQ (see Help Menu).", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand); \r
641                      }                  \r
642         }\r
643 \r
644         private void btn_destBrowse_Click(object sender, EventArgs e)\r
645         {\r
646             // TODO: Need to write some code to check if there is a reasonable amount of disk space left.\r
647 \r
648             DVD_Save.ShowDialog();\r
649             text_destination.Text = DVD_Save.FileName;\r
650 \r
651             if (Check_ChapterMarkers.Checked)\r
652             {\r
653                 string destination = text_destination.Text;\r
654                 destination = destination.Replace(".mp4", ".m4v");\r
655                 text_destination.Text = destination;\r
656             }\r
657         }\r
658 \r
659         private void btn_h264Clear_Click(object sender, EventArgs e)\r
660         {\r
661             rtf_h264advanced.Text = "";\r
662         }\r
663 \r
664         private void GenerateQuery_Click(object sender, EventArgs e)\r
665         {\r
666             String query = GenerateTheQuery();\r
667             QueryEditorText.Text = query;\r
668         }\r
669 \r
670         private void btn_ClearQuery_Click(object sender, EventArgs e)\r
671         {\r
672             QueryEditorText.Text = "";\r
673         }\r
674 \r
675         private void btn_queue_Click(object sender, EventArgs e)\r
676         {\r
677             if (text_destination.Text != "" && text_source.Text != "")\r
678             {\r
679                 string query;\r
680                 if (QueryEditorText.Text == "")\r
681                 {\r
682                     query = GenerateTheQuery();\r
683                 }\r
684                 else\r
685                 {\r
686                     query = QueryEditorText.Text;\r
687                 }\r
688                 queueWindow.list_queue.Items.Add(query);\r
689                 queueWindow.Show();\r
690             } \r
691             else \r
692             {\r
693                 MessageBox.Show("No Source OR destination selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
694             }\r
695         }\r
696 \r
697         private void showQueue()\r
698         {\r
699             queueWindow.Show();\r
700         }\r
701 \r
702         #endregion\r
703 \r
704         // -------------------------------------------------------------- \r
705         // Main Window Preset System\r
706         // --------------------------------------------------------------\r
707 \r
708         #region Preset System\r
709 \r
710         // Varibles\r
711         private Boolean presetStatus = false;\r
712 \r
713         // Buttons\r
714         private void btn_presets_Click(object sender, EventArgs e)\r
715         {\r
716             if (presetStatus == false)\r
717             {\r
718                 this.Width = 881;\r
719                 presetStatus = true;\r
720                 btn_presets.Text = "Hide Presets";\r
721             }\r
722             else\r
723             {\r
724                 this.Width = 590;\r
725                 presetStatus = false;\r
726                 btn_presets.Text = "Show Presets";\r
727             }\r
728 \r
729         }\r
730 \r
731         private void btn_addPreset_Click(object sender, EventArgs e)\r
732         {\r
733 \r
734         }\r
735 \r
736         private void btn_removePreset_Click(object sender, EventArgs e)\r
737         {\r
738             ListBox_Presets.Items.Remove(ListBox_Presets.SelectedItem);\r
739         }\r
740 \r
741         private void btn_setDefault_Click(object sender, EventArgs e)\r
742         {\r
743             //Source\r
744             Properties.Settings.Default.DVDSource = text_source.Text;\r
745             Properties.Settings.Default.DVDTitle = drp_dvdtitle.Text;\r
746             Properties.Settings.Default.ChapterStart = drop_chapterStart.Text;\r
747             Properties.Settings.Default.ChapterFinish = drop_chapterFinish.Text;\r
748             //Destination\r
749             Properties.Settings.Default.VideoDest = text_destination.Text;\r
750             Properties.Settings.Default.VideoEncoder = drp_videoEncoder.Text;\r
751             Properties.Settings.Default.AudioEncoder = drp_audioCodec.Text;\r
752             Properties.Settings.Default.Width = text_width.Text;\r
753             Properties.Settings.Default.Height = text_height.Text;\r
754             //Picture Settings Tab\r
755             Properties.Settings.Default.CroppingOption = drp_crop.Text;\r
756             Properties.Settings.Default.CropTop = text_top.Text;\r
757             Properties.Settings.Default.CropBottom = text_bottom.Text;\r
758             Properties.Settings.Default.CropLeft = text_left.Text;\r
759             Properties.Settings.Default.CropRight = text_right.Text;\r
760             Properties.Settings.Default.Subtitles = drp_subtitle.Text;\r
761             //Video Settings Tab\r
762             Properties.Settings.Default.VideoBitrate = text_bitrate.Text;\r
763             Properties.Settings.Default.VideoFilesize = text_filesize.Text;\r
764             Properties.Settings.Default.VideoQuality = slider_videoQuality.Value;\r
765             Properties.Settings.Default.TwoPass = check_2PassEncode.CheckState.ToString();\r
766             Properties.Settings.Default.DeInterlace = drp_deInterlace_option.Text;\r
767             Properties.Settings.Default.Grayscale = check_grayscale.CheckState.ToString();\r
768             Properties.Settings.Default.Framerate = drp_videoFramerate.Text;\r
769             Properties.Settings.Default.PixelRatio = CheckPixelRatio.CheckState.ToString();\r
770             Properties.Settings.Default.turboFirstPass = check_turbo.CheckState.ToString();\r
771             Properties.Settings.Default.largeFile = check_largeFile.CheckState.ToString();\r
772             Properties.Settings.Default.detelecine = check_detelecine.CheckState.ToString();\r
773             Properties.Settings.Default.denoise = drp_deNoise.Text;\r
774             Properties.Settings.Default.deblock = check_deblock.CheckState.ToString();\r
775             //Audio Settings Tab\r
776             Properties.Settings.Default.AudioBitrate = drp_audioBitrate.Text;\r
777             Properties.Settings.Default.AudioSampleRate = drp_audioSampleRate.Text;\r
778             Properties.Settings.Default.AudioChannels = drp_audioChannels.Text;\r
779             //H264 Tab\r
780             Properties.Settings.Default.CRF = CheckCRF.CheckState.ToString();\r
781             Properties.Settings.Default.H264 = rtf_h264advanced.Text;\r
782             Properties.Settings.Default.SelectedPreset = ListBox_Presets.SelectedItem.ToString();\r
783             Properties.Settings.Default.Save();\r
784         }\r
785 \r
786 \r
787         // Preset Seleciton\r
788         private void ListBox_Presets_SelectedIndexChanged(object sender, EventArgs e)\r
789         {\r
790             string selectedPreset = null;\r
791             if (ListBox_Presets.SelectedItem != null)\r
792             {\r
793                 selectedPreset = ListBox_Presets.SelectedItem.ToString();\r
794             }\r
795             else\r
796             {\r
797                 selectedPreset = "";\r
798             }\r
799 \r
800             switch (selectedPreset)\r
801             {\r
802                 case "Animation":\r
803                     setGuiSetttings(CheckState.Checked, "", "", "H.264", "1000", "", 0, "0%", "160", CheckState.Checked, "48", "ref=5:mixed-refs:bframes=6:bime:weightb:b-rdo:direct=auto:b-pyramid:me=umh:subme=5:analyse=all:8x8dct:trellis=1:nr=150:no-fast-pskip:filter=2,2", "Origional (Fast)", CheckState.Checked, "No Crop", CheckState.Checked, "AAC", "Output Settings (Preset: Apple Animation)");\r
804                     setMkv();\r
805                     break;\r
806                 case "AppleTV":\r
807                     setGuiSetttings(CheckState.Checked, "", "", "H.264", "2500", "", 0, "0%", "160", CheckState.Checked, "48", "bframes=3:ref=1:subme=5:me=umh:no-fast-pskip=1:trellis=2", "None", CheckState.Unchecked, "No Crop", CheckState.Unchecked, "AAC", "Output Settings (Preset: Apple TV)");\r
808                     break;\r
809                 case "Bedlam":\r
810                     setGuiSetttings(CheckState.Checked, "", "", "H.264", "1800", "", 0, "0%", "160", CheckState.Checked, "48", "ref=16:mixed-refs:bframes=6:bime:weightb:b-rdo:direct=auto:b-pyramid:me=umh:subme=7:me-range=64:analyse=all:8x8dct:trellis=2:no-fast-pskip:no-dct-decimate:filter=-2,-1", "None", CheckState.Checked, "No Crop", CheckState.Checked, "AAC", "Output Settings (Preset: Bedlam)");\r
811                     setMkv();\r
812                     break;\r
813                 case "Blind":\r
814                     setGuiSetttings(CheckState.Unchecked, "512", "", "H.264", "512", "", 0, "0%", "128", CheckState.Checked, "48", "", "None", CheckState.Unchecked, "No Crop", CheckState.Unchecked, "AAC", "Output Settings (Preset: Blind)");\r
815                     break;\r
816                 case "Broke":\r
817                     setGuiSetttings(CheckState.Unchecked, "640", "", "H.264", "", "695", 0, "0%", "128", CheckState.Checked, "48", "ref=3:mixed-refs:bframes=6:bime:weightb:b-rdo:b-pyramid::direct=auto:me=umh:subme=6:trellis=1:analyse=all:8x8dct:no-fast-pskip", "None", CheckState.Checked, "No Crop", CheckState.Checked, "AAC", "Output Settings (Preset: Broke)");\r
818                     break;\r
819                 case "Classic":\r
820                     setGuiSetttings(CheckState.Unchecked, "", "", "H.264", "1000", "", 0, "0%", "160", CheckState.Unchecked, "48", "", "None", CheckState.Unchecked, "No Crop", CheckState.Unchecked, "AAC", "Output Settings (Preset: Classic)");\r
821                     break;\r
822                 case "Constant Quality Rate":\r
823                     setGuiSetttings(CheckState.Checked, "", "", "H.264", "", "", 64, "64%", "160", CheckState.Checked, "48", "ref=3:mixed-refs:bframes=3:b-pyramid:b-rdo:bime:weightb:filter=-2,-1:subme=6:trellis=1:analyse=all:8x8dct:me=umh", "None", CheckState.Unchecked, "No Crop", CheckState.Unchecked, "AC3", "Output Settings (Preset: CQR)");\r
824                     setMkv();\r
825                     break;\r
826                 case "Deux Six Quatre":\r
827                     setGuiSetttings(CheckState.Checked, "", "", "H.264", "1600", "", 0, "0%", "160", CheckState.Checked, "48", "ref=5:mixed-refs:bframes=3:bime:weightb:b-rdo:b-pyramid:me=umh:subme=7:trellis=1:analyse=all:8x8dct:no-fast-pskip", "None", CheckState.Checked, "No Crop", CheckState.Checked, "AC3", "Output Settings (Preset: DSQ)");\r
828                     setMkv();\r
829                     break;\r
830                 case "Film":\r
831                     setGuiSetttings(CheckState.Checked, "", "", "H.264", "2000", "", 0, "0%", "160", CheckState.Checked, "48", "ref=3:mixed-refs:bframes=3:bime:weightb:b-rdo:direct=auto:b-pyramid:me=umh:subme=6:analyse=all:8x8dct:trellis=1:no-fast-pskip", "None", CheckState.Checked, "No Crop", CheckState.Checked, "AC3", "Output Settings (Preset: Film)");\r
832                     setMkv();\r
833                     break;\r
834                 case "iPhone":\r
835                     setGuiSetttings(CheckState.Unchecked, "480", "", "H.264", "960", "", 0, "0%", "128", CheckState.Checked, "48", "cabac=0:ref=1:analyse=all:me=umh:subme=6:no-fast-pskip=1:trellis=1", "None", CheckState.Unchecked, "No Crop", CheckState.Unchecked, "AAC", "Output Settings (Preset: iPhone)");\r
836                     break;\r
837                 case "iPod High-Rez":\r
838                     setGuiSetttings(CheckState.Unchecked, "640", "", "H.264", "1500", "", 0, "0%", "160", CheckState.Checked, "48", "keyint=300:keyint-min=30:bframes=0:cabac=0:ref=1:vbv-maxrate=1500:vbv-bufsize=2000:analyse=all:me=umh:subme=6:no-fast-pskip=1", "None", CheckState.Unchecked, "No Crop", CheckState.Unchecked, "AAC", "Output Settings (Preset: iPod High Rez)");\r
839                     break;\r
840                 case "iPod Low-Rez":\r
841                     setGuiSetttings(CheckState.Unchecked, "320", "", "H.264", "700", "", 0, "0%", "160", CheckState.Checked, "48", "keyint=300:keyint-min=30:bframes=0:cabac=0:ref=1:vbv-maxrate=768:vbv-bufsize=2000:analyse=all:me=umh:subme=6:no-fast-pskip=1", "None", CheckState.Unchecked, "No Crop", CheckState.Unchecked, "AAC", "Output Settings (Preset: iPod Low Rez)");\r
842                     break;\r
843                 case "Normal":\r
844                     setGuiSetttings(CheckState.Checked, "", "", "H.264", "1500", "", 0, "0%", "160", CheckState.Checked, "48", "ref=2:bframes=2:subme=5:me=umh", "None", CheckState.Checked, "No Crop", CheckState.Checked, "AAC", "Output Settings (Preset: Normal)");\r
845                     break;\r
846                 case "PS3":\r
847                     setGuiSetttings(CheckState.Checked, "", "", "H.264", "2500", "", 0, "0%", "160", CheckState.Checked, "48", "level=41:subme=5:me=umh", "None", CheckState.Unchecked, "No Crop", CheckState.Unchecked, "AAC", "Output Settings (Preset: PS3)");\r
848                     break;\r
849                 case "PSP":\r
850                     setGuiSetttings(CheckState.Unchecked, "368", "208", "Mpeg 4", "1024", "", 0, "0%", "160", CheckState.Unchecked, "48", "", "None", CheckState.Unchecked, "No Crop", CheckState.Unchecked, "AAC", "Output Settings (Preset: PSP)");\r
851                     break;\r
852                 case "QuickTime":\r
853                     setGuiSetttings(CheckState.Checked, "", "", "H.264", "2000", "", 0, "0%", "160", CheckState.Checked, "48", "ref=3:mixed-refs:bframes=3:bime:weightb:b-rdo:direct-auto:me=umh:subme=5:analyse=all:8x8dct:trellis=1:no-fast-pskip", "None", CheckState.Checked, "No Crop", CheckState.Checked, "AAC", "Output Settings (Preset: Quicktime)");\r
854                     break;\r
855                 case "Television":\r
856                     setGuiSetttings(CheckState.Unchecked, "", "", "H.264", "1300", "", 0, "0%", "160", CheckState.Checked, "48", "ref=3:mixed-refs:bframes=6:bime:weightb:direct=auto:b-pyramid:me=umh:subme=6:analyse=all:8x8dct:trellis=1:nr=150:no-fast-pskip", "Origional (Fast)", CheckState.Checked, "No Crop", CheckState.Checked, "AAC", "Output Settings (Preset: Television)");\r
857                     setMkv();\r
858                     break;\r
859                 default:\r
860                     break;\r
861             }\r
862         }\r
863 \r
864 \r
865 \r
866 \r
867 \r
868         // Functions - It's a bit dirty but i'll sort this out later. Simply done to reduce the amount of code above.\r
869         private void setGuiSetttings(CheckState anamorphic, string width, string height, string vencoder, string bitrate, string filesize, int quality, string qpercent, string audioBit, CheckState chpt, string audioSample, string h264, string deinterlace, CheckState twopass, string crop, CheckState turbo, string audioCodec, string preset)\r
870         {\r
871             CheckPixelRatio.CheckState = anamorphic;\r
872             text_width.Text = width;\r
873             text_height.Text = height;\r
874             drp_videoEncoder.Text = vencoder;\r
875             text_bitrate.Text = bitrate;\r
876             text_filesize.Text = filesize;\r
877             slider_videoQuality.Value = quality;\r
878             SliderValue.Text = qpercent;\r
879             drp_audioBitrate.Text = audioBit;\r
880             Check_ChapterMarkers.CheckState = chpt;\r
881             drp_audioSampleRate.Text = audioSample;\r
882             rtf_h264advanced.Text = h264;\r
883             drp_deInterlace_option.Text = deinterlace;\r
884             check_2PassEncode.CheckState = twopass;\r
885             drp_crop.Text = crop;\r
886             check_turbo.CheckState = turbo;\r
887             drp_audioCodec.Text = audioCodec;\r
888 \r
889             groupBox_output.Text = preset;\r
890         }\r
891 \r
892         private void setMkv()\r
893         {\r
894             // Set file extension to MKV\r
895             string destination = text_destination.Text;\r
896             destination = destination.Replace(".mp4", ".mkv");\r
897             destination = destination.Replace(".avi", ".mkv");\r
898             destination = destination.Replace(".m4v", ".mkv");\r
899             destination = destination.Replace(".ogm", ".mkv");\r
900             text_destination.Text = destination;\r
901         }\r
902 \r
903         #endregion\r
904 \r
905         //---------------------------------------------------\r
906         // Encode / Cancel Buttons\r
907         // Encode Progress Text Handler\r
908         //---------------------------------------------------\r
909 \r
910         #region Encode/CLI\r
911 \r
912         Functions.CLI process = new Functions.CLI();\r
913 \r
914         private void btn_encode_Click(object sender, EventArgs e)\r
915         {\r
916             //btn_eCancel.Enabled = true;\r
917             String query = "";            \r
918             if (QueryEditorText.Text == "")\r
919             {\r
920                 query = GenerateTheQuery();\r
921             }\r
922             else\r
923             {\r
924                 query = QueryEditorText.Text;\r
925             }\r
926 \r
927             ThreadPool.QueueUserWorkItem(procMonitor, query);\r
928             lbl_encode.Visible = true;\r
929             lbl_encode.Text = "Encoding in Progress";\r
930         }\r
931 \r
932         private void btn_eCancel_Click(object sender, EventArgs e)\r
933         {\r
934             process.killCLI();\r
935             process.setNull();\r
936             lbl_encode.Text = "Encoding Canceled";\r
937         }\r
938 \r
939 \r
940         [DllImport("user32.dll")]\r
941         public static extern void LockWorkStation();\r
942         [DllImport("user32.dll")]\r
943         public static extern int ExitWindowsEx(int uFlags, int dwReason); \r
944 \r
945         private void procMonitor(object state)\r
946         {\r
947             // Make sure we are not already encoding and if we are then display an error.\r
948             if (hbProc != null)\r
949             {\r
950                 MessageBox.Show("Handbrake is already encoding a video!", "Status", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
951             }\r
952             else\r
953             {\r
954                 hbProc = process.runCli(this, (string)state, false, false, false, false);\r
955                 hbProc.WaitForExit();\r
956 \r
957                 try\r
958                 {\r
959 \r
960                     //*****************************************************************************************\r
961                     // BUG!\r
962                     // When the below code is used and standard error is set to true, hbcli is outputing a\r
963                     // video stream which has mild corruption issues every few seconds.\r
964                     // Maybe an issue with the Parser cauing the CLI to hickup/pause?\r
965                     //*****************************************************************************************\r
966 \r
967                     \r
968                     /*Parsing.Parser encode = new Parsing.Parser(hbProc.StandardError.BaseStream);\r
969                     encode.OnEncodeProgress += encode_OnEncodeProgress;\r
970                     while (!encode.EndOfStream)\r
971                     {\r
972                         encode.ReadLine();\r
973                     }\r
974 \r
975                     hbProc.WaitForExit();\r
976                     process.closeCLI();\r
977                     */\r
978                 }\r
979                 catch (Exception)\r
980                 {\r
981                     // Do nothing\r
982                 }\r
983 \r
984 \r
985                 setEncodeLabel();\r
986                 hbProc = null;\r
987 \r
988                 // Do something whent he encode ends.\r
989                 switch (Properties.Settings.Default.CompletionOption)\r
990                 {\r
991                     case "Shutdown":\r
992                         System.Diagnostics.Process.Start("Shutdown", "-s -t 60");\r
993                         break;\r
994                     case "Log Off":\r
995                         ExitWindowsEx(0, 0); \r
996                         break;\r
997                     case "Suspend":\r
998                         Application.SetSuspendState(PowerState.Suspend, true, true);\r
999                         break;\r
1000                     case "Hibernate":\r
1001                         Application.SetSuspendState(PowerState.Hibernate, true, true);\r
1002                         break;\r
1003                     case "Lock System":\r
1004                         LockWorkStation();\r
1005                         break;\r
1006                     case "Quit HandBrake":\r
1007                         Application.Exit();\r
1008                         break;\r
1009                     default:\r
1010                         break;\r
1011                 }\r
1012             }\r
1013         }\r
1014 \r
1015         private delegate void UpdateUIHandler();\r
1016 \r
1017         private void setEncodeLabel()\r
1018         {\r
1019             if (this.InvokeRequired)\r
1020             {\r
1021                 this.BeginInvoke(new UpdateUIHandler(setEncodeLabel));\r
1022                 return;\r
1023             }\r
1024             lbl_encode.Text = "Encoding Finished";\r
1025         }\r
1026 \r
1027         /*private void encode_OnEncodeProgress(object Sender, int CurrentTask, int TaskCount, float PercentComplete, float CurrentFps, float AverageFps, TimeSpan TimeRemaining)\r
1028         {\r
1029             \r
1030             if (this.InvokeRequired)\r
1031             {\r
1032                 this.BeginInvoke(new Parsing.EncodeProgressEventHandler(encode_OnEncodeProgress),\r
1033                     new object[] { Sender, CurrentTask, TaskCount, PercentComplete, CurrentFps, AverageFps, TimeRemaining });\r
1034                 return;\r
1035             }\r
1036             lbl_encode.Text = string.Format("Encode Progress: {0}%,       FPS: {1},       Avg FPS: {2},       Time Remaining: {3} ", PercentComplete, CurrentFps, AverageFps, TimeRemaining);\r
1037         }*/\r
1038 \r
1039         #endregion\r
1040 \r
1041         //---------------------------------------------------\r
1042         //  Items that require actions on frmMain\r
1043         //---------------------------------------------------\r
1044 \r
1045         #region frmMain Actions\r
1046 \r
1047         private void drop_chapterStart_SelectedIndexChanged(object sender, EventArgs e)\r
1048         {\r
1049             drop_chapterStart.BackColor = Color.White;\r
1050             QueryEditorText.Text = "";\r
1051             if ((drop_chapterFinish.Text != "Auto") && (drop_chapterStart.Text != "Auto"))\r
1052             {\r
1053                 try\r
1054                 {\r
1055                     int chapterFinish = int.Parse(drop_chapterFinish.Text);\r
1056                     int chapterStart = int.Parse(drop_chapterStart.Text);\r
1057 \r
1058                     if (chapterFinish < chapterStart)\r
1059                     {\r
1060                         drop_chapterStart.BackColor = Color.LightCoral;\r
1061                     }\r
1062                 }\r
1063                 catch (Exception)\r
1064                 {\r
1065                     drop_chapterStart.BackColor = Color.LightCoral;\r
1066                 }\r
1067             }\r
1068 \r
1069             \r
1070         }\r
1071 \r
1072         private void drop_chapterFinish_SelectedIndexChanged(object sender, EventArgs e)\r
1073         {\r
1074             drop_chapterFinish.BackColor = Color.White;\r
1075             QueryEditorText.Text = "";\r
1076             if ((drop_chapterFinish.Text != "Auto") && (drop_chapterStart.Text != "Auto"))\r
1077             {\r
1078                 try\r
1079                 {\r
1080                     int chapterFinish = int.Parse(drop_chapterFinish.Text);\r
1081                     int chapterStart = int.Parse(drop_chapterStart.Text);\r
1082 \r
1083                     if (chapterFinish < chapterStart)\r
1084                     {\r
1085                         drop_chapterFinish.BackColor = Color.LightCoral;\r
1086                     }\r
1087                 }\r
1088                 catch (Exception)\r
1089                 {\r
1090                     drop_chapterFinish.BackColor = Color.LightCoral;\r
1091                 }\r
1092             }\r
1093         }\r
1094 \r
1095         private void text_bitrate_TextChanged(object sender, EventArgs e)\r
1096         {\r
1097             text_filesize.Text = "";\r
1098             slider_videoQuality.Value = 0;\r
1099             SliderValue.Text = "0%";\r
1100             CheckCRF.CheckState = CheckState.Unchecked;\r
1101             CheckCRF.Enabled = false;\r
1102         }\r
1103 \r
1104         private void text_filesize_TextChanged(object sender, EventArgs e)\r
1105         {\r
1106             text_bitrate.Text = "";\r
1107             slider_videoQuality.Value = 0;\r
1108             SliderValue.Text = "0%";\r
1109             CheckCRF.CheckState = CheckState.Unchecked;\r
1110             CheckCRF.Enabled = false;\r
1111         }\r
1112 \r
1113         private void slider_videoQuality_Scroll(object sender, EventArgs e)\r
1114         {\r
1115             SliderValue.Text = slider_videoQuality.Value.ToString() + "%";\r
1116             text_bitrate.Text = "";\r
1117             text_filesize.Text = "";\r
1118             CheckCRF.Enabled = true;\r
1119         }\r
1120 \r
1121         private void label_h264_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)\r
1122         {\r
1123             Process.Start("http://handbrake.m0k.org/trac/wiki/x264Options");\r
1124         }\r
1125 \r
1126         private void text_width_TextChanged(object sender, EventArgs e)\r
1127         {\r
1128 \r
1129             try\r
1130             {\r
1131                 if (CheckPixelRatio.Checked)\r
1132                 {\r
1133                     text_width.Text = "";\r
1134                     text_width.BackColor = Color.White;\r
1135                 }\r
1136                 else\r
1137                 {\r
1138                     if ((int.Parse(text_width.Text) % 16) != 0)\r
1139                     {\r
1140                         text_width.BackColor = Color.LightCoral;\r
1141                     }\r
1142                     else\r
1143                     {\r
1144                         text_width.BackColor = Color.LightGreen;\r
1145                     }\r
1146                 }\r
1147 \r
1148                 if (lbl_Aspect.Text != "Select a Title")\r
1149                 {\r
1150                     double height = int.Parse(text_width.Text) / double.Parse(lbl_Aspect.Text);\r
1151                     double mod16 = height % 16;\r
1152                     height = height - mod16;\r
1153 \r
1154                     if (text_width.Text == "")\r
1155                     {\r
1156                         text_height.Text = "";\r
1157                         text_width.BackColor = Color.White;\r
1158                     }\r
1159                     else\r
1160                     {\r
1161                         text_height.Text = height.ToString();\r
1162                     }\r
1163                 }\r
1164             }\r
1165             catch (Exception)\r
1166             {\r
1167                 // No need to throw an error here.\r
1168                 // Note on non english systems, this will throw an error because of double.Parse(lbl_Aspect.Text); not working.\r
1169             }\r
1170                \r
1171           \r
1172         }\r
1173 \r
1174         private void text_height_TextChanged(object sender, EventArgs e)\r
1175         {\r
1176             try\r
1177             {\r
1178                 if (text_height.Text != "Auto")\r
1179                 {\r
1180                     if (CheckPixelRatio.Checked)\r
1181                     {\r
1182                         text_height.Text = "";\r
1183                         text_width.BackColor = Color.White;\r
1184                     }\r
1185                     else\r
1186                     {\r
1187                         if ((int.Parse(text_height.Text) % 16) != 0)\r
1188                         {\r
1189                             text_height.BackColor = Color.LightCoral;\r
1190                         }\r
1191                         else\r
1192                         {\r
1193                             text_height.BackColor = Color.LightGreen;\r
1194                         }\r
1195                     }\r
1196                 }\r
1197             } catch(Exception){\r
1198                 // No need to alert the user.\r
1199             }\r
1200         }\r
1201 \r
1202         private void drp_crop_SelectedIndexChanged(object sender, EventArgs e)\r
1203         {\r
1204             if ((string)drp_crop.SelectedItem == "Manual")\r
1205             {\r
1206             text_left.Enabled = true;\r
1207             text_right.Enabled = true;\r
1208             text_top.Enabled = true;\r
1209             text_bottom.Enabled = true;\r
1210             }\r
1211 \r
1212             if ((string)drp_crop.SelectedItem == "Auto Crop")\r
1213             {\r
1214                 text_left.Enabled = false;\r
1215                 text_right.Enabled = false;\r
1216                 text_top.Enabled = false;\r
1217                 text_bottom.Enabled = false;\r
1218                 text_left.Text = "";\r
1219                 text_right.Text = "";\r
1220                 text_top.Text = "";\r
1221                 text_bottom.Text = "";\r
1222 \r
1223                 if (lbl_RecomendedCrop.Text != "Select a Title")\r
1224                 {\r
1225                     string[] temp = new string[4];\r
1226                     temp = lbl_RecomendedCrop.Text.Split('/');\r
1227                     text_left.Text = temp[2];\r
1228                     text_right.Text = temp[3];\r
1229                     text_top.Text = temp[0];\r
1230                     text_bottom.Text = temp[1];\r
1231                 }\r
1232             }\r
1233 \r
1234             if ((string)drp_crop.SelectedItem == "No Crop")\r
1235             {\r
1236                 text_left.Enabled = false;\r
1237                 text_right.Enabled = false;\r
1238                 text_top.Enabled = false;\r
1239                 text_bottom.Enabled = false;\r
1240                 text_left.Text = "0";\r
1241                 text_right.Text = "0";\r
1242                 text_top.Text = "0";\r
1243                 text_bottom.Text = "0";\r
1244 \r
1245             }\r
1246         }\r
1247         \r
1248         private void CheckPixelRatio_CheckedChanged(object sender, EventArgs e)\r
1249         {\r
1250             text_width.Text = "";\r
1251             text_height.Text = "";\r
1252             text_width.BackColor = Color.White;\r
1253             text_height.BackColor = Color.White;\r
1254         }\r
1255 \r
1256         private void drp_dvdtitle_Click(object sender, EventArgs e)\r
1257         {\r
1258             if (drp_dvdtitle.Items.Count == 0)\r
1259             {\r
1260                 MessageBox.Show("There are no titles to select. Please scan the DVD by clicking the 'browse' button above before trying to select a title.", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);\r
1261             }\r
1262         }\r
1263 \r
1264         private void drp_audioCodec_SelectedIndexChanged(object sender, EventArgs e)\r
1265         {\r
1266 \r
1267             //CLI Audio mixdown Names: mono stereo dpl1 dpl2 6ch\r
1268 \r
1269             drp_audioMixDown.Items.Clear();\r
1270 \r
1271             if (drp_audioCodec.Text == "AAC")\r
1272             {\r
1273                 drp_audioMixDown.Items.Clear();\r
1274                 drp_audioMixDown.Items.Add("Mono");\r
1275                 drp_audioMixDown.Items.Add("Stereo");\r
1276                 drp_audioMixDown.Items.Add("Dolby Surround");\r
1277                 drp_audioMixDown.Items.Add("Dolby Pro Logic II");\r
1278                 drp_audioMixDown.Items.Add("6 Channel Discrete");\r
1279                 \r
1280                 drp_audioBitrate.Items.Clear();\r
1281                 drp_audioBitrate.Items.Add("32");\r
1282                 drp_audioBitrate.Items.Add("40");\r
1283                 drp_audioBitrate.Items.Add("48");\r
1284                 drp_audioBitrate.Items.Add("56");\r
1285                 drp_audioBitrate.Items.Add("64");\r
1286                 drp_audioBitrate.Items.Add("80");\r
1287                 drp_audioBitrate.Items.Add("86");\r
1288                 drp_audioBitrate.Items.Add("112");\r
1289                 drp_audioBitrate.Items.Add("128");\r
1290                 drp_audioBitrate.Items.Add("160");\r
1291 \r
1292             }\r
1293             else\r
1294             {\r
1295                 drp_audioMixDown.Items.Clear();\r
1296                 drp_audioMixDown.Items.Add("Stereo");\r
1297                 drp_audioMixDown.Items.Add("Dolby Surround");\r
1298                 drp_audioMixDown.Items.Add("Dolby Pro Logic II");\r
1299 \r
1300                 drp_audioBitrate.Items.Clear();\r
1301                 drp_audioBitrate.Items.Add("32");\r
1302                 drp_audioBitrate.Items.Add("40");\r
1303                 drp_audioBitrate.Items.Add("48");\r
1304                 drp_audioBitrate.Items.Add("56");\r
1305                 drp_audioBitrate.Items.Add("64");\r
1306                 drp_audioBitrate.Items.Add("80");\r
1307                 drp_audioBitrate.Items.Add("86");\r
1308                 drp_audioBitrate.Items.Add("112");\r
1309                 drp_audioBitrate.Items.Add("128");\r
1310                 drp_audioBitrate.Items.Add("160");\r
1311                 drp_audioBitrate.Items.Add("192");\r
1312                 drp_audioBitrate.Items.Add("224");\r
1313                 drp_audioBitrate.Items.Add("256");\r
1314                 drp_audioBitrate.Items.Add("320");\r
1315             }\r
1316         }\r
1317 \r
1318         private void drp_audioMixDown_SelectedIndexChanged(object sender, EventArgs e)\r
1319         {\r
1320             if (drp_audioCodec.Text == "AAC")\r
1321             {\r
1322                 if (drp_audioMixDown.Text == "6 Channel Discrete")\r
1323                 {\r
1324 \r
1325                     drp_audioBitrate.Items.Clear();\r
1326                     drp_audioBitrate.Items.Add("32");\r
1327                     drp_audioBitrate.Items.Add("40");\r
1328                     drp_audioBitrate.Items.Add("48");\r
1329                     drp_audioBitrate.Items.Add("56");\r
1330                     drp_audioBitrate.Items.Add("64");\r
1331                     drp_audioBitrate.Items.Add("80");\r
1332                     drp_audioBitrate.Items.Add("86");\r
1333                     drp_audioBitrate.Items.Add("112");\r
1334                     drp_audioBitrate.Items.Add("128");\r
1335                     drp_audioBitrate.Items.Add("160");\r
1336                     drp_audioBitrate.Items.Add("192");\r
1337                     drp_audioBitrate.Items.Add("224");\r
1338                     drp_audioBitrate.Items.Add("256");\r
1339                     drp_audioBitrate.Items.Add("320");\r
1340                     drp_audioBitrate.Items.Add("384");\r
1341                 }\r
1342             }\r
1343         }\r
1344 \r
1345         private void Check_ChapterMarkers_CheckedChanged(object sender, EventArgs e)\r
1346         {\r
1347             if (Check_ChapterMarkers.Checked)\r
1348             {\r
1349                 string destination = text_destination.Text;\r
1350                 destination = destination.Replace(".mp4", ".m4v");\r
1351                 text_destination.Text = destination;\r
1352             }\r
1353             else\r
1354             {\r
1355                 string destination = text_destination.Text;\r
1356                 destination = destination.Replace(".m4v", ".mp4");\r
1357                 text_destination.Text = destination;\r
1358             }\r
1359         }\r
1360 \r
1361         private void check_largeFile_CheckedChanged(object sender, EventArgs e)\r
1362         {\r
1363             if (!text_destination.Text.Contains(".mp4"))\r
1364             {\r
1365                 MessageBox.Show("This option is only compatible with the mp4 file container.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
1366                 check_largeFile.CheckState = CheckState.Unchecked;\r
1367             }\r
1368         }\r
1369 \r
1370         private void drp_videoEncoder_SelectedIndexChanged(object sender, EventArgs e)\r
1371         {\r
1372             //Turn off some options which are H.264 only when the user selects a non h.264 encoder\r
1373             if (!drp_videoEncoder.Text.Contains("H.264"))\r
1374             {\r
1375                 check_turbo.CheckState = CheckState.Unchecked;\r
1376                 CheckCRF.CheckState = CheckState.Unchecked;\r
1377                 CheckCRF.Enabled = false;\r
1378                 check_turbo.Enabled = false;\r
1379                 h264Tab.Enabled = false;\r
1380             }\r
1381             else\r
1382             {\r
1383                 CheckCRF.Enabled = true;\r
1384                 check_turbo.Enabled = true;\r
1385                 h264Tab.Enabled = true;\r
1386             }\r
1387 \r
1388         }\r
1389 \r
1390         public void setStreamReader(Parsing.DVD dvd)\r
1391         {\r
1392             this.thisDVD = dvd;\r
1393         }\r
1394 \r
1395         private void drp_dvdtitle_SelectedIndexChanged(object sender, EventArgs e)\r
1396         {\r
1397             // Reset some values on the form\r
1398             lbl_Aspect.Text = "Select a Title";\r
1399             lbl_RecomendedCrop.Text = "Select a Title";\r
1400             drop_chapterStart.Items.Clear();\r
1401             drop_chapterFinish.Items.Clear();\r
1402             QueryEditorText.Text = "";\r
1403 \r
1404             // If the dropdown is set to automatic nothing else needs to be done.\r
1405             // Otheriwse if its not, title data has to be loased from parsing.\r
1406             if (drp_dvdtitle.Text != "Automatic")\r
1407             {\r
1408                 Parsing.Title selectedTitle = drp_dvdtitle.SelectedItem as Parsing.Title;\r
1409 \r
1410                 // Set the Aspect Ratio\r
1411                 lbl_Aspect.Text = selectedTitle.AspectRatio.ToString();\r
1412 \r
1413                 // Set the Recommended Cropping values\r
1414                 lbl_RecomendedCrop.Text = string.Format("{0}/{1}/{2}/{3}", selectedTitle.AutoCropDimensions[0], selectedTitle.AutoCropDimensions[1], selectedTitle.AutoCropDimensions[2], selectedTitle.AutoCropDimensions[3]);\r
1415                 \r
1416                 // Populate the Start chapter Dropdown\r
1417                 drop_chapterStart.Items.Clear();\r
1418                 drop_chapterStart.Items.AddRange(selectedTitle.Chapters.ToArray());\r
1419                 if (drop_chapterStart.Items.Count > 0)\r
1420                 {\r
1421                     drop_chapterStart.Text = drop_chapterStart.Items[0].ToString();\r
1422                 }\r
1423 \r
1424                 // Populate the Final Chapter Dropdown\r
1425                 drop_chapterFinish.Items.Clear();\r
1426                 drop_chapterFinish.Items.AddRange(selectedTitle.Chapters.ToArray());\r
1427                 if (drop_chapterFinish.Items.Count > 0)\r
1428                 {\r
1429                     drop_chapterFinish.Text = drop_chapterFinish.Items[drop_chapterFinish.Items.Count - 1].ToString();\r
1430                 }\r
1431 \r
1432                 // Populate the Audio Channels Dropdown\r
1433                 drp_audioChannels.Items.Clear();\r
1434                 drp_audioChannels.Items.Add("Automatic");\r
1435                 drp_audioChannels.Items.AddRange(selectedTitle.AudioTracks.ToArray());\r
1436                 if (drp_audioChannels.Items.Count > 0)\r
1437                 {\r
1438                     drp_audioChannels.Text = drp_audioChannels.Items[0].ToString();\r
1439                 }\r
1440 \r
1441                 // Populate the Subtitles dropdown\r
1442                 drp_subtitle.Items.Clear();\r
1443                 drp_subtitle.Items.Add("None");\r
1444                 drp_subtitle.Items.AddRange(selectedTitle.Subtitles.ToArray());\r
1445                 if (drp_subtitle.Items.Count > 0)\r
1446                 {\r
1447                     drp_subtitle.Text = drp_subtitle.Items[0].ToString();\r
1448                 }\r
1449             }\r
1450         }\r
1451 \r
1452         #endregion\r
1453 \r
1454         //---------------------------------------------------\r
1455         //  Some Functions\r
1456         //  - Query Generation\r
1457         //---------------------------------------------------\r
1458 \r
1459         #region Program Functions\r
1460 \r
1461         public string GenerateTheQuery()\r
1462         {\r
1463             string source = text_source.Text;\r
1464             string dvdTitle = drp_dvdtitle.Text;\r
1465             string chapterStart = drop_chapterStart.Text;\r
1466             string chapterFinish = drop_chapterFinish.Text;\r
1467             int totalChapters = drop_chapterFinish.Items.Count - 1;\r
1468             string dvdChapter = "";\r
1469 \r
1470             if (source ==  "")\r
1471                 MessageBox.Show("No Source has been selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
1472             else\r
1473             {\r
1474                 source = " -i " + '"' + source+ '"'; //'"'+\r
1475             }\r
1476 \r
1477             if (dvdTitle ==  "Automatic")\r
1478                 dvdTitle = "";\r
1479             else\r
1480             {\r
1481                 string[] titleInfo = dvdTitle.Split(' ');\r
1482                 dvdTitle = " -t "+ titleInfo[0];\r
1483             }\r
1484 \r
1485             if (chapterFinish.Equals("Auto") && chapterStart.Equals("Auto"))\r
1486                 dvdChapter = "";\r
1487             else if (chapterFinish == chapterStart)\r
1488                 dvdChapter = " -c " + chapterStart;\r
1489             else\r
1490                 dvdChapter = " -c " + chapterStart + "-" + chapterFinish;\r
1491 \r
1492             string querySource = source+ dvdTitle+ dvdChapter;\r
1493             // ----------------------------------------------------------------------\r
1494 \r
1495             // Destination\r
1496 \r
1497             string destination = text_destination.Text;\r
1498             string videoEncoder = drp_videoEncoder.Text;\r
1499             string audioEncoder = drp_audioCodec.Text;\r
1500             string width = text_width.Text;\r
1501             string height = text_height.Text;\r
1502 \r
1503             if (destination ==  "")\r
1504                 MessageBox.Show("No destination has been selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
1505             else\r
1506                 destination = " -o " + '"' + destination + '"'; //'"'+ \r
1507 \r
1508 \r
1509             switch (videoEncoder)\r
1510             {\r
1511                 case "Mpeg 4":\r
1512                     videoEncoder = " -e ffmpeg";\r
1513                     break;\r
1514                 case "Xvid":\r
1515                     videoEncoder = " -e xvid";\r
1516                     break;\r
1517                 case "H.264":\r
1518                     videoEncoder = " -e x264";\r
1519                     break;\r
1520                 case "H.264 Baseline 1.3":\r
1521                     videoEncoder = " -e x264b13";\r
1522                     break;\r
1523                 case "H.264 (iPod)":\r
1524                     videoEncoder = " -e x264b30";\r
1525                     break;\r
1526                 default:\r
1527                     videoEncoder = " -e x264";\r
1528                     break;\r
1529             }\r
1530            \r
1531             switch (audioEncoder)\r
1532             {\r
1533                 case "AAC":\r
1534                     audioEncoder = " -E faac";\r
1535                     break;\r
1536                 case "MP3":\r
1537                     audioEncoder = " -E lame";\r
1538                     break;\r
1539                 case "Vorbis":\r
1540                     audioEncoder = " -E vorbis";\r
1541                     break;\r
1542                 case "AC3":\r
1543                     audioEncoder = " -E ac3";\r
1544                     break;\r
1545                 default:\r
1546                     audioEncoder = " -E faac";\r
1547                     break;\r
1548             }\r
1549 \r
1550             if (width !=  "")\r
1551                 width = " -w "+ width;\r
1552 \r
1553 \r
1554             if (height == "Auto")\r
1555             {\r
1556                 height = "";\r
1557             }\r
1558             else if (height != "")\r
1559             {\r
1560                 height = " -l " + height;\r
1561             }\r
1562             \r
1563 \r
1564             string queryDestination = destination+ videoEncoder+ audioEncoder+ width+ height;\r
1565             // ----------------------------------------------------------------------\r
1566 \r
1567             // Picture Settings Tab\r
1568 \r
1569             string cropSetting = drp_crop.Text;\r
1570             string cropTop = text_top.Text;\r
1571             string cropBottom = text_bottom.Text;\r
1572             string cropLeft = text_left.Text;\r
1573             string cropRight = text_right.Text;\r
1574             string subtitles = drp_subtitle.Text;\r
1575             string cropOut = "";\r
1576             string deInterlace_Option = drp_deInterlace_option.Text;\r
1577             string deinterlace = "";\r
1578             string grayscale = "";\r
1579             string pixelRatio = "";\r
1580             string ChapterMarkers = "";\r
1581             // Returns Crop Query\r
1582 \r
1583             if (cropSetting == "Auto Crop")\r
1584                 cropOut = "";\r
1585             else if (cropSetting == "No Crop")\r
1586                 cropOut = " --crop 0:0:0:0 ";\r
1587             else\r
1588             {\r
1589                 if (text_top.Text == "")\r
1590                     cropTop = "0";\r
1591                 if (text_bottom.Text == "")\r
1592                     cropBottom = "0";\r
1593                 if (text_left.Text == "")\r
1594                     cropLeft = "0";\r
1595                 if (text_right.Text == "")\r
1596                     cropRight = "0";\r
1597 \r
1598                 cropOut = " --crop " + cropTop + ":" + cropBottom + ":" + cropLeft + ":" + cropRight;\r
1599             }\r
1600 \r
1601             if (subtitles ==  "None")\r
1602                 subtitles = "";\r
1603             else if (subtitles ==  "")\r
1604                 subtitles = "";\r
1605             else\r
1606             {\r
1607                 string[] tempSub;\r
1608                 tempSub = subtitles.Split(' ');\r
1609                 subtitles = " -s "+ tempSub[0];\r
1610             }\r
1611 \r
1612             switch (deInterlace_Option)\r
1613             {\r
1614                 case "None":\r
1615                     deinterlace = "";\r
1616                     break;\r
1617                 case "Origional (Fast)":\r
1618                     deinterlace = " --deinterlace=1";\r
1619                     break;\r
1620                 case "yadif (Slow)":\r
1621                     deinterlace = " --deinterlace=" + '"' + "0" + '"';\r
1622                     break;\r
1623                 case "yadif + mcdeint (Slower)":\r
1624                     deinterlace = " --deinterlace=" + '"' + "2:-1:1" + '"';\r
1625                     break;\r
1626                 case "yadif + mcdeint (Slowest)":\r
1627                     deinterlace = " --deinterlace=" + '"' + "1:-1:1" + '"';\r
1628                     break;\r
1629                 default:\r
1630                     deinterlace = "";\r
1631                     break;\r
1632             }\r
1633 \r
1634             if (check_grayscale.Checked)\r
1635                 grayscale = " -g ";\r
1636 \r
1637             if (CheckPixelRatio.Checked)\r
1638                 pixelRatio = " -p ";\r
1639 \r
1640             if (Check_ChapterMarkers.Checked)\r
1641                 ChapterMarkers = " -m ";\r
1642 \r
1643             string queryPictureSettings = cropOut + subtitles + deinterlace + grayscale + pixelRatio + ChapterMarkers;\r
1644             // ----------------------------------------------------------------------\r
1645 \r
1646             // Video Settings Tab\r
1647 \r
1648             string videoBitrate = text_bitrate.Text;\r
1649             string videoFilesize = text_filesize.Text;\r
1650             double videoQuality = slider_videoQuality.Value;\r
1651             string vidQSetting = "";\r
1652             string twoPassEncoding = "";\r
1653             string videoFramerate = drp_videoFramerate.Text;\r
1654             string turboH264 = "";\r
1655             string largeFile = "";\r
1656             string deblock = "";\r
1657             string detelecine = "";\r
1658             string denoise = "";\r
1659             string CRF = CheckCRF.CheckState.ToString();\r
1660 \r
1661 \r
1662             if ((CRF == "Checked"))\r
1663                 CRF = " -Q ";\r
1664             else\r
1665                 CRF = "";\r
1666 \r
1667             if (videoBitrate !=  "")\r
1668                 videoBitrate = " -b "+ videoBitrate;\r
1669 \r
1670             if (videoFilesize !=  "")\r
1671                 videoFilesize = " -S "+ videoFilesize;\r
1672 \r
1673             // Video Quality Setting\r
1674 \r
1675             if ((videoQuality ==  0))\r
1676                 vidQSetting = "";\r
1677             else\r
1678             {\r
1679                 videoQuality = videoQuality / 100;\r
1680                 if (videoQuality ==  1)\r
1681                 {\r
1682                     vidQSetting = "1.0";\r
1683                 }\r
1684 \r
1685                 vidQSetting = " -q " + videoQuality.ToString();\r
1686             }\r
1687 \r
1688             if (check_2PassEncode.Checked)\r
1689                 twoPassEncoding = " -2 ";\r
1690 \r
1691             if (videoFramerate ==  "Automatic")\r
1692                 videoFramerate = "";\r
1693             else\r
1694                 videoFramerate = " -r "+ videoFramerate;\r
1695 \r
1696             if (check_turbo.Checked)\r
1697                 turboH264 = " -T ";\r
1698 \r
1699             if (check_largeFile.Checked)\r
1700                 largeFile = " -4 ";\r
1701 \r
1702             if (check_deblock.Checked)\r
1703                 deblock = " --deblock";\r
1704 \r
1705             if (check_detelecine.Checked)\r
1706                 detelecine = " --detelecine";\r
1707 \r
1708             switch (drp_deNoise.Text)\r
1709             {\r
1710                 case "None":\r
1711                     denoise = "";\r
1712                     break;\r
1713                 case "Weak":\r
1714                     denoise = " --denoise=2:1:2:3";\r
1715                     break;\r
1716                 case "Medium":\r
1717                     denoise = " --denoise=3:2:2:3";\r
1718                     break;\r
1719                 case "Strong":\r
1720                     denoise = " --denoise=7:7:5:5";\r
1721                     break;\r
1722                 default:\r
1723                     denoise = "";\r
1724                     break;\r
1725             }\r
1726 \r
1727             string queryVideoSettings = videoBitrate + videoFilesize + vidQSetting + twoPassEncoding + videoFramerate + turboH264 + largeFile + deblock + detelecine + denoise;\r
1728             // ----------------------------------------------------------------------\r
1729 \r
1730             // Audio Settings Tab\r
1731 \r
1732             string audioBitrate = drp_audioBitrate.Text;\r
1733             string audioSampleRate = drp_audioSampleRate.Text;\r
1734             string audioChannels = drp_audioChannels.Text;\r
1735             string Mixdown = drp_audioMixDown.Text;\r
1736             string SixChannelAudio = "";\r
1737 \r
1738             if (audioBitrate !=  "")\r
1739                 audioBitrate = " -B "+ audioBitrate;\r
1740 \r
1741             if (audioSampleRate !=  "")\r
1742                 audioSampleRate = " -R "+ audioSampleRate;\r
1743 \r
1744             if (audioChannels ==  "Automatic")\r
1745                 audioChannels = "";\r
1746             else if (audioChannels ==  "")\r
1747                 audioChannels = "";\r
1748             else\r
1749             {\r
1750                 string[] tempSub;\r
1751                 tempSub = audioChannels.Split(' ');\r
1752                 audioChannels = " -a "+ tempSub[0];\r
1753             }\r
1754 \r
1755             switch (Mixdown)\r
1756             {\r
1757                 case "Automatic":\r
1758                     Mixdown = "";\r
1759                     break;\r
1760                 case "Mono":\r
1761                     Mixdown = "mono";\r
1762                     break;\r
1763                 case "Stereo":\r
1764                     Mixdown = "stereo";\r
1765                     break;\r
1766                 case "Dolby Surround":\r
1767                     Mixdown = "dpl1";\r
1768                     break;\r
1769                 case "Dolby Pro Logic II":\r
1770                     Mixdown = "dpl2";\r
1771                     break;\r
1772                 case "6 Channel Discrete":\r
1773                     Mixdown = "6ch";\r
1774                     break;\r
1775                 default:\r
1776                     Mixdown = "stero";\r
1777                     break;\r
1778             }\r
1779 \r
1780             if (Mixdown !=  "")\r
1781                 SixChannelAudio = " -6 "+ Mixdown;\r
1782             else\r
1783                 SixChannelAudio = "";\r
1784 \r
1785             string queryAudioSettings = audioBitrate+ audioSampleRate+ audioChannels+ SixChannelAudio;\r
1786             // ----------------------------------------------------------------------\r
1787 \r
1788             //  H.264 Tab\r
1789 \r
1790             \r
1791             string h264Advanced = rtf_h264advanced.Text;\r
1792             \r
1793             if ((h264Advanced ==  ""))\r
1794                 h264Advanced = "";\r
1795             else\r
1796                 h264Advanced = " -x "+ h264Advanced;\r
1797     \r
1798 \r
1799             string h264Settings = h264Advanced;\r
1800             // ----------------------------------------------------------------------\r
1801 \r
1802             // Processors (Program Settings)\r
1803 \r
1804             string processors = Properties.Settings.Default.Processors;\r
1805             //  Number of Processors Handler\r
1806 \r
1807             if (processors ==  "Automatic")\r
1808                 processors = "";\r
1809             else\r
1810                 processors = " -C "+ processors+ " ";\r
1811 \r
1812 \r
1813             string queryAdvancedSettings = processors;\r
1814             // ----------------------------------------------------------------------\r
1815 \r
1816             //  Verbose option (Program Settings)\r
1817 \r
1818             string verbose = "";\r
1819             if (Properties.Settings.Default.verbose ==  "Checked")\r
1820                 verbose = " -v ";\r
1821 \r
1822             // ----------------------------------------------------------------------\r
1823 \r
1824             return querySource+ queryDestination+ queryPictureSettings+ queryVideoSettings+ h264Settings+ queryAudioSettings+ queryAdvancedSettings+ verbose;\r
1825         }\r
1826 \r
1827         #endregion\r
1828 \r
1829         // This is the END of the road ------------------------------------------------------------------------------\r
1830     }\r
1831 }\r