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