OSDN Git Service

7f6ece4ead9e683e44cabbe198a4001399b4bc23
[handbrake-jp/handbrake-jp-git.git] / win / C# / frmMain.cs
1 using System;\r
2 using System.Collections.Generic;\r
3 using System.ComponentModel;\r
4 using System.Data;\r
5 using System.Drawing;\r
6 using System.Text;\r
7 using System.Windows.Forms;\r
8 using System.Net;\r
9 using System.IO;\r
10 using System.Diagnostics;\r
11 using System.Threading;\r
12 \r
13 namespace Handbrake\r
14 {\r
15     public partial class frmMain : Form\r
16     {\r
17         private Process hbProc;\r
18         private Parsing.DVD thisDVD;\r
19 \r
20         // --------------------------------------------------------------\r
21         // Some windows that require only 1 instance.\r
22         // --------------------------------------------------------------\r
23         private frmDvdInfo dvdInfoWindow = new frmDvdInfo();\r
24         private frmQueue queueWindow = new frmQueue();\r
25 \r
26         public frmMain()\r
27         {\r
28             InitializeComponent();\r
29 \r
30             // Set the Version number lable to the corect version.\r
31             Version.Text = "Version " + Properties.Settings.Default.GuiVersion;\r
32 \r
33             // Run the update checker.\r
34             updateCheck();\r
35 \r
36             // Now load the users default if required.\r
37             loadUserDefaults();\r
38         }\r
39 \r
40         public void loadUserDefaults()\r
41         { \r
42             try\r
43             {\r
44                 if (Properties.Settings.Default.defaultSettings == "Checked")\r
45                 {\r
46                     // Source\r
47                     text_source.Text = Properties.Settings.Default.DVDSource;\r
48                     drp_dvdtitle.Text = Properties.Settings.Default.DVDTitle;\r
49                     drop_chapterStart.Text = Properties.Settings.Default.ChapterStart;\r
50                     drop_chapterFinish.Text = Properties.Settings.Default.ChapterFinish;\r
51 \r
52                     // Destination\r
53                     text_destination.Text = Properties.Settings.Default.VideoDest;\r
54                     drp_videoEncoder.Text = Properties.Settings.Default.VideoEncoder;\r
55                     drp_audioCodec.Text = Properties.Settings.Default.AudioEncoder;\r
56                     text_width.Text = Properties.Settings.Default.Width;\r
57                     text_height.Text = Properties.Settings.Default.Height;\r
58 \r
59                     // Picture Settings Tab\r
60                     drp_crop.Text = Properties.Settings.Default.CroppingOption;\r
61                     text_top.Text = Properties.Settings.Default.CropTop;\r
62                     text_bottom.Text = Properties.Settings.Default.CropBottom;\r
63                     text_left.Text = Properties.Settings.Default.CropLeft;\r
64                     text_right.Text = Properties.Settings.Default.CropRight;\r
65                     drp_subtitle.Text = Properties.Settings.Default.Subtitles;\r
66 \r
67                     // Video Settings Tab\r
68                     text_bitrate.Text = Properties.Settings.Default.VideoBitrate;\r
69                     text_filesize.Text = Properties.Settings.Default.VideoFilesize;\r
70                     slider_videoQuality.Value = Properties.Settings.Default.VideoQuality;\r
71 \r
72                     if (Properties.Settings.Default.TwoPass == "Checked")\r
73                     {\r
74                         check_2PassEncode.CheckState = CheckState.Checked;\r
75                     }\r
76                     if (Properties.Settings.Default.DeInterlace == "Checked")\r
77                     {\r
78                         check_DeInterlace.CheckState = CheckState.Checked;\r
79                     }\r
80                     if (Properties.Settings.Default.Grayscale == "Checked")\r
81                     {\r
82                         check_grayscale.CheckState = CheckState.Checked;\r
83                     }\r
84 \r
85                     drp_videoFramerate.Text = Properties.Settings.Default.Framerate;\r
86 \r
87                     if (Properties.Settings.Default.PixelRatio == "Checked")\r
88                     {\r
89                         CheckPixelRatio.CheckState = CheckState.Checked;\r
90                     }\r
91                     if (Properties.Settings.Default.turboFirstPass == "Checked")\r
92                     {\r
93                         check_turbo.CheckState = CheckState.Checked;\r
94                     }\r
95                     if (Properties.Settings.Default.largeFile == "Checked")\r
96                     {\r
97                         check_largeFile.CheckState = CheckState.Checked;\r
98                     }\r
99                     // Audio Settings Tab\r
100                     drp_audioBitrate.Text = Properties.Settings.Default.AudioBitrate;\r
101                     drp_audioSampleRate.Text = Properties.Settings.Default.AudioSampleRate;\r
102                     drp_audioChannels.Text = Properties.Settings.Default.AudioChannels;\r
103 \r
104                     // H264 Tab\r
105                     if (Properties.Settings.Default.CRF == "Checked")\r
106                     {\r
107                         CheckCRF.CheckState = CheckState.Checked;\r
108                     }\r
109                     rtf_h264advanced.Text = Properties.Settings.Default.H264;\r
110                 }\r
111             }\r
112             catch (Exception)\r
113             {\r
114                 // No real need to alert the user. Try/Catch only in just incase there is a problem reading the settings xml file.\r
115             }\r
116         }\r
117 \r
118         public void updateCheck()\r
119         {\r
120             if (Properties.Settings.Default.updateStatus == "Checked")\r
121             {\r
122 \r
123                 try\r
124                 {\r
125                     String updateFile = Properties.Settings.Default.updateFile;\r
126                     WebClient client = new WebClient();\r
127                     String data = client.DownloadString(updateFile);\r
128                     String[] versionData = data.Split('\n');\r
129 \r
130                     if ((versionData[0] != Properties.Settings.Default.GuiVersion) || (versionData[1] != Properties.Settings.Default.CliVersion))\r
131                     {\r
132                         lbl_update.Visible = true;\r
133                     }\r
134                 }\r
135                 // else fail displaying an error message.\r
136                 catch (Exception)\r
137                 {\r
138                     // Silently ignore the error\r
139                 }\r
140             }\r
141         }\r
142 \r
143         #region The Menu Bar\r
144         #region File Menu\r
145 \r
146         private void mnu_open_Click(object sender, EventArgs e)\r
147         {\r
148             string filename;\r
149             File_Open.ShowDialog();\r
150             filename = File_Open.FileName;\r
151             if (filename != "")\r
152             {\r
153                 try\r
154                 {\r
155                     // Create StreamReader & open file\r
156                     StreamReader line = new StreamReader(filename);\r
157                     string temporyLine; // Used for reading the line into a varible before processing on the checkState items below.\r
158                     \r
159                     // Read in the data and set the correct GUI component with the setting.\r
160                     text_source.Text = line.ReadLine();\r
161                     drp_dvdtitle.Text = line.ReadLine();\r
162                     drop_chapterStart.Text = line.ReadLine();\r
163                     drop_chapterFinish.Text = line.ReadLine();\r
164                     text_destination.Text = line.ReadLine();\r
165                     drp_videoEncoder.Text = line.ReadLine();\r
166                     drp_audioCodec.Text = line.ReadLine();\r
167                     text_width.Text = line.ReadLine();\r
168                     text_height.Text = line.ReadLine();\r
169                     text_top.Text = line.ReadLine();\r
170                     text_bottom.Text = line.ReadLine();\r
171                     text_left.Text = line.ReadLine();\r
172                     text_right.Text = line.ReadLine();\r
173                     drp_subtitle.Text = line.ReadLine();\r
174                     text_bitrate.Text = line.ReadLine();\r
175                     text_filesize.Text = line.ReadLine();\r
176                     slider_videoQuality.Value = int.Parse(line.ReadLine());\r
177 \r
178                     temporyLine = line.ReadLine();\r
179                     if (temporyLine == "Checked")\r
180                     {\r
181                         check_2PassEncode.CheckState = CheckState.Checked;\r
182                     }\r
183 \r
184                     temporyLine = line.ReadLine();\r
185                     if (temporyLine == "Checked")\r
186                     {\r
187                         check_DeInterlace.CheckState = CheckState.Checked;\r
188                     }\r
189 \r
190                     temporyLine = line.ReadLine();\r
191                     if (temporyLine == "Checked")\r
192                     {\r
193                         check_grayscale.CheckState = CheckState.Checked;\r
194                     }\r
195 \r
196                     drp_videoFramerate.Text = line.ReadLine();\r
197 \r
198                     temporyLine = line.ReadLine();\r
199                     if (temporyLine == "Checked")\r
200                     {\r
201                         Check_ChapterMarkers.CheckState = CheckState.Checked;\r
202                     }\r
203 \r
204                     temporyLine = line.ReadLine();\r
205                     if (temporyLine == "Checked")\r
206                     {\r
207                         CheckPixelRatio.CheckState = CheckState.Checked;\r
208                     }\r
209 \r
210                     temporyLine = line.ReadLine();\r
211                     if (temporyLine == "Checked")\r
212                     {\r
213                         check_turbo.CheckState = CheckState.Checked;\r
214                     }\r
215 \r
216                     temporyLine = line.ReadLine();\r
217                     if (temporyLine == "Checked")\r
218                     {\r
219                         check_largeFile.CheckState = CheckState.Checked;\r
220                     }\r
221    \r
222                     drp_audioBitrate.Text = line.ReadLine();\r
223                     drp_audioSampleRate.Text = line.ReadLine();\r
224                     drp_audioChannels.Text = line.ReadLine();\r
225                     drp_audioMixDown.Text = line.ReadLine();\r
226                     \r
227                     // Advanced H264 Options\r
228                     temporyLine = line.ReadLine();\r
229                     if (temporyLine == "Checked")\r
230                     {\r
231                         CheckCRF.CheckState = CheckState.Checked;\r
232                     }\r
233                     rtf_h264advanced.Text = line.ReadLine();\r
234 \r
235                     // Close the stream\r
236                     line.Close();\r
237 \r
238 \r
239                     // Fix for SliderValue not appearing when Opening saved file\r
240                     SliderValue.Text = slider_videoQuality.Value + "%";\r
241 \r
242                 } catch (Exception){\r
243                     MessageBox.Show("Unable to load profile.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);\r
244                 }\r
245             }\r
246         }\r
247 \r
248         private void mnu_save_Click(object sender, EventArgs e)\r
249         {\r
250 \r
251             string filename;\r
252             File_Save.ShowDialog();\r
253             filename = File_Save.FileName;\r
254             if (filename != "")\r
255             {\r
256                 try\r
257                 {\r
258                     // Create a StreamWriter and open the file\r
259                     StreamWriter line = new StreamWriter(filename);\r
260 \r
261                     //Source\r
262                     line.WriteLine(text_source.Text);\r
263                     line.WriteLine(drp_dvdtitle.Text);\r
264                     line.WriteLine(drop_chapterStart.Text);\r
265                     line.WriteLine(drop_chapterFinish.Text);\r
266                     //Destination\r
267                     line.WriteLine(text_destination.Text);\r
268                     line.WriteLine(drp_videoEncoder.Text);\r
269                     line.WriteLine(drp_audioCodec.Text);\r
270                     line.WriteLine(text_width.Text);\r
271                     line.WriteLine(text_height.Text);\r
272                     //Picture Settings Tab\r
273                     line.WriteLine(text_top.Text);\r
274                     line.WriteLine(text_bottom.Text);\r
275                     line.WriteLine(text_left.Text);\r
276                     line.WriteLine(text_right.Text);\r
277                     line.WriteLine(drp_subtitle.Text);\r
278                     //Video Settings Tab\r
279                     line.WriteLine(text_bitrate.Text);\r
280                     line.WriteLine(text_filesize.Text);\r
281                     line.WriteLine(slider_videoQuality.Value.ToString());\r
282                     line.WriteLine(check_2PassEncode.CheckState.ToString());\r
283                     line.WriteLine(check_DeInterlace.CheckState.ToString());\r
284                     line.WriteLine(check_grayscale.CheckState.ToString());\r
285                     line.WriteLine(drp_videoFramerate.Text);\r
286                     line.WriteLine(Check_ChapterMarkers.CheckState.ToString());\r
287                     line.WriteLine(CheckPixelRatio.CheckState.ToString());\r
288                     line.WriteLine(check_turbo.CheckState.ToString());\r
289                     line.WriteLine(check_largeFile.CheckState.ToString());\r
290                     //Audio Settings Tab\r
291                     line.WriteLine(drp_audioBitrate.Text);\r
292                     line.WriteLine(drp_audioSampleRate.Text);\r
293                     line.WriteLine(drp_audioChannels.Text);\r
294                     line.WriteLine(drp_audioMixDown.Text);\r
295                     //H264 Tab\r
296                     line.WriteLine(CheckCRF.CheckState.ToString());\r
297                     line.WriteLine(rtf_h264advanced.Text);\r
298                     // close the stream\r
299                     line.Close();\r
300                     MessageBox.Show("Your profile has been sucessfully saved.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);\r
301                 }\r
302                 catch(Exception)\r
303                 {\r
304                     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
305                 }\r
306                 \r
307             }\r
308         }\r
309 \r
310         private void mnu_update_Click(object sender, EventArgs e)\r
311         {\r
312             Form Update = new frmUpdate();\r
313             Update.ShowDialog();\r
314         }\r
315 \r
316         private void mnu_exit_Click(object sender, EventArgs e)\r
317         {\r
318             this.Close();\r
319         }\r
320 \r
321         #endregion\r
322 \r
323         #region Tools Menu\r
324 \r
325         private void mnu_encode_Click(object sender, EventArgs e)\r
326         {\r
327             showQueue();\r
328         }\r
329 \r
330         private void mnu_viewDVDdata_Click(object sender, EventArgs e)\r
331         {\r
332             dvdInfoWindow.Show();\r
333         }\r
334 \r
335         private void mnu_options_Click(object sender, EventArgs e)\r
336         {\r
337             Form Options = new frmOptions();\r
338             Options.ShowDialog();\r
339         }\r
340 \r
341         #endregion\r
342 \r
343         #region Presets Menu\r
344 \r
345         private void mnu_preset_ipod133_Click(object sender, EventArgs e)\r
346         {\r
347             CheckPixelRatio.CheckState = CheckState.Unchecked;\r
348             text_width.Text = "640";\r
349             text_height.Text = "480";\r
350             drp_videoEncoder.Text = "H.264 (iPod)";\r
351             text_bitrate.Text = "1000";\r
352             text_filesize.Text = "";\r
353             slider_videoQuality.Value = 0;\r
354             SliderValue.Text = "0%";\r
355             drp_audioBitrate.Text = "160";\r
356             rtf_h264advanced.Text = "";\r
357             drp_crop.Text = "No Crop";\r
358         }\r
359 \r
360         private void mnu_preset_ipod178_Click(object sender, EventArgs e)\r
361         {\r
362             CheckPixelRatio.CheckState = CheckState.Unchecked;\r
363             text_width.Text = "640";\r
364             text_height.Text = "352";\r
365             drp_videoEncoder.Text = "H.264 (iPod)";\r
366             text_bitrate.Text = "1000";\r
367             text_filesize.Text = "";\r
368             slider_videoQuality.Value = 0;\r
369             SliderValue.Text = "0%";\r
370             drp_audioBitrate.Text = "160";\r
371             rtf_h264advanced.Text = "";\r
372             drp_crop.Text = "No Crop";\r
373         }\r
374 \r
375         private void mnu_preset_ipod235_Click(object sender, EventArgs e)\r
376         {\r
377             CheckPixelRatio.CheckState = CheckState.Unchecked;\r
378             text_width.Text = "640";\r
379             text_height.Text = "272";\r
380             drp_videoEncoder.Text = "H.264 (iPod)";\r
381             text_bitrate.Text = "1000";\r
382             text_filesize.Text = "";\r
383             slider_videoQuality.Value = 0;\r
384             SliderValue.Text = "0%";\r
385             drp_audioBitrate.Text = "160";\r
386             rtf_h264advanced.Text = "";\r
387             drp_crop.Text = "No Crop";\r
388         }\r
389 \r
390         private void mnu_appleTv_Click(object sender, EventArgs e)\r
391         {\r
392             text_width.Text = "";\r
393             text_height.Text = "";\r
394             drp_videoEncoder.Text = "H.264";\r
395             text_bitrate.Text = "3000";\r
396             text_filesize.Text = "";\r
397             slider_videoQuality.Value = 0;\r
398             SliderValue.Text = "0%";\r
399             drp_audioBitrate.Text = "160";\r
400             CheckPixelRatio.CheckState = CheckState.Checked;\r
401             drp_audioSampleRate.Text = "48";\r
402             rtf_h264advanced.Text = "bframes=3:ref=1:subme=5:me=umh:no-fast-pskip=1:no-dct-decimate=1:trellis=2";\r
403             drp_crop.Text = "No Crop";\r
404             \r
405         }\r
406 \r
407         private void mnu_presetPS3_Click(object sender, EventArgs e)\r
408         {\r
409             CheckPixelRatio.CheckState = CheckState.Unchecked;\r
410             text_width.Text = "";\r
411             text_height.Text = "";\r
412             drp_videoEncoder.Text = "H.264";\r
413             text_bitrate.Text = "3000";\r
414             text_filesize.Text = "";\r
415             slider_videoQuality.Value = 0;\r
416             SliderValue.Text = "0%";\r
417             drp_audioBitrate.Text = "160";\r
418             CheckPixelRatio.CheckState = CheckState.Checked;\r
419             drp_audioSampleRate.Text = "48";\r
420             rtf_h264advanced.Text = "level=41";\r
421             drp_crop.Text = "No Crop";\r
422         }\r
423 \r
424         private void mnu_ProgramDefaultOptions_Click(object sender, EventArgs e)\r
425         {\r
426             //Source\r
427             Properties.Settings.Default.DVDSource = text_source.Text;\r
428             Properties.Settings.Default.DVDTitle = drp_dvdtitle.Text;\r
429             Properties.Settings.Default.ChapterStart = drop_chapterStart.Text;\r
430             Properties.Settings.Default.ChapterFinish = drop_chapterFinish.Text;\r
431             //Destination\r
432             Properties.Settings.Default.VideoDest = text_destination.Text;\r
433             Properties.Settings.Default.VideoEncoder = drp_videoEncoder.Text;\r
434             Properties.Settings.Default.AudioEncoder = drp_audioCodec.Text;\r
435             Properties.Settings.Default.Width = text_width.Text;\r
436             Properties.Settings.Default.Height = text_height.Text;\r
437             //Picture Settings Tab\r
438             Properties.Settings.Default.CroppingOption = drp_crop.Text;\r
439             Properties.Settings.Default.CropTop = text_top.Text;\r
440             Properties.Settings.Default.CropBottom = text_bottom.Text;\r
441             Properties.Settings.Default.CropLeft = text_left.Text;\r
442             Properties.Settings.Default.CropRight = text_right.Text;\r
443             Properties.Settings.Default.Subtitles = drp_subtitle.Text;\r
444             //Video Settings Tab\r
445             Properties.Settings.Default.VideoBitrate = text_bitrate.Text;\r
446             Properties.Settings.Default.VideoFilesize = text_filesize.Text;\r
447             Properties.Settings.Default.VideoQuality = slider_videoQuality.Value;\r
448             Properties.Settings.Default.TwoPass = check_2PassEncode.CheckState.ToString();\r
449             Properties.Settings.Default.DeInterlace = check_DeInterlace.CheckState.ToString();\r
450             Properties.Settings.Default.Grayscale = check_grayscale.CheckState.ToString();\r
451             Properties.Settings.Default.Framerate = drp_videoFramerate.Text;\r
452             Properties.Settings.Default.PixelRatio = CheckPixelRatio.CheckState.ToString();\r
453             Properties.Settings.Default.turboFirstPass = check_turbo.CheckState.ToString();\r
454             Properties.Settings.Default.largeFile = check_largeFile.CheckState.ToString();\r
455             //Audio Settings Tab\r
456             Properties.Settings.Default.AudioBitrate = drp_audioBitrate.Text;\r
457             Properties.Settings.Default.AudioSampleRate = drp_audioSampleRate.Text;\r
458             Properties.Settings.Default.AudioChannels = drp_audioChannels.Text;\r
459             //H264 Tab\r
460             Properties.Settings.Default.CRF = CheckCRF.CheckState.ToString();\r
461             Properties.Settings.Default.H264 = rtf_h264advanced.Text;\r
462             Properties.Settings.Default.Save();\r
463         }\r
464 \r
465         #endregion\r
466 \r
467         #region Help Menu\r
468 \r
469         private void mnu_wiki_Click(object sender, EventArgs e)\r
470         {\r
471            Process.Start("http://handbrake.m0k.org/trac");\r
472         }\r
473 \r
474         private void mnu_onlineDocs_Click(object sender, EventArgs e)\r
475         {\r
476             Process.Start("http://handbrake.m0k.org/?page_id=11");\r
477         }\r
478 \r
479         private void mnu_faq_Click(object sender, EventArgs e)\r
480         {\r
481             Process.Start("http://handbrake.m0k.org/trac/wiki/WindowsGuiFaq");\r
482         }\r
483 \r
484         private void mnu_homepage_Click(object sender, EventArgs e)\r
485         {\r
486            Process.Start("http://handbrake.m0k.org");\r
487         }\r
488 \r
489         private void mnu_forum_Click(object sender, EventArgs e)\r
490         {\r
491             Process.Start("http://handbrake.m0k.org/forum");\r
492         }\r
493 \r
494         private void mnu_about_Click(object sender, EventArgs e)\r
495         {\r
496                         Form About = new frmAbout();\r
497             About.ShowDialog();\r
498         }\r
499 \r
500         #endregion\r
501         #endregion\r
502 \r
503         // -------------------------------------------------------------- \r
504         // Buttons on the main Window\r
505         // --------------------------------------------------------------\r
506         private void btn_Browse_Click(object sender, EventArgs e)\r
507         {\r
508             \r
509             String filename ="";\r
510             text_source.Text = "";\r
511 \r
512             if (RadioDVD.Checked)\r
513             {\r
514                 DVD_Open.ShowDialog();\r
515                 filename = DVD_Open.SelectedPath;\r
516                 if (filename != "")\r
517                 {\r
518                     text_source.Text = filename;\r
519                     Form frmReadDVD = new frmReadDVD(filename, this, dvdInfoWindow);\r
520                     frmReadDVD.ShowDialog();\r
521                 }\r
522             }\r
523             else\r
524             {\r
525                 ISO_Open.ShowDialog();\r
526                 filename = ISO_Open.FileName;\r
527                 if (filename != "")\r
528                 {\r
529                     text_source.Text = filename;\r
530                     Form frmReadDVD = new frmReadDVD(filename, this, dvdInfoWindow);\r
531                     frmReadDVD.ShowDialog();\r
532                 }\r
533             }  \r
534 \r
535             // Quick check to make sure some titles were found.\r
536             if (filename != "")\r
537             {\r
538                 if (drp_dvdtitle.Items.Count == 0)\r
539                 {\r
540                     MessageBox.Show("No Title(s) found. Please make sure you have selected a valid, non-copy protected source.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);\r
541                 }\r
542             }\r
543             else\r
544             {\r
545                 text_source.Text = "Click 'Browse' to continue";\r
546             }\r
547 \r
548         }\r
549 \r
550         private void btn_destBrowse_Click(object sender, EventArgs e)\r
551         {\r
552             // TODO: Need to write some code to check if there is a reasonable amount of disk space left.\r
553 \r
554             DVD_Save.ShowDialog();\r
555             text_destination.Text = DVD_Save.FileName;\r
556 \r
557             if (Check_ChapterMarkers.Checked)\r
558             {\r
559                 string destination = text_destination.Text;\r
560                 destination = destination.Replace(".mp4", ".m4v");\r
561                 text_destination.Text = destination;\r
562             }\r
563         }\r
564 \r
565         private void btn_h264Clear_Click(object sender, EventArgs e)\r
566         {\r
567             rtf_h264advanced.Text = "";\r
568         }\r
569 \r
570         private void GenerateQuery_Click(object sender, EventArgs e)\r
571         {\r
572             String query = GenerateTheQuery();\r
573             QueryEditorText.Text = query;\r
574         }\r
575 \r
576         private void btn_ClearQuery_Click(object sender, EventArgs e)\r
577         {\r
578             QueryEditorText.Text = "";\r
579         }\r
580 \r
581         private void btn_queue_Click(object sender, EventArgs e)\r
582         {\r
583             String query = GenerateTheQuery();\r
584             queueWindow.list_queue.Items.Add(query);\r
585             queueWindow.Show();\r
586         }\r
587 \r
588         private void showQueue()\r
589         {\r
590             queueWindow.Show();\r
591         }\r
592 \r
593         private void btn_encode_Click(object sender, EventArgs e)\r
594         {\r
595             String query = "";\r
596  \r
597             if (QueryEditorText.Text == "")\r
598             {\r
599                 query = GenerateTheQuery();\r
600             }\r
601             else\r
602             {\r
603                 query = QueryEditorText.Text;\r
604             }\r
605 \r
606             Functions.CLI process = new Functions.CLI();\r
607             hbProc = process.runCli(this, query, false, false, false, false);\r
608           \r
609             ThreadPool.QueueUserWorkItem(procMonitor);\r
610         }\r
611 \r
612         private void procMonitor(object state)\r
613         {\r
614             MessageBox.Show("The encode process has now started.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);\r
615             hbProc.WaitForExit();\r
616             hbProc.Close();\r
617             hbProc.Dispose();\r
618             MessageBox.Show("The encode process has now ended.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);\r
619         }\r
620 \r
621 \r
622         //---------------------------------------------------\r
623         //  Items that require actions on frmMain\r
624         //---------------------------------------------------\r
625 \r
626         private void drop_chapterStart_SelectedIndexChanged(object sender, EventArgs e)\r
627         {\r
628             lbl_chptWarn.Visible = false;\r
629             QueryEditorText.Text = "";\r
630             if ((drop_chapterFinish.Text != "Auto") && (drop_chapterStart.Text != "Auto"))\r
631             {\r
632                 try\r
633                 {\r
634                     int chapterFinish = int.Parse(drop_chapterFinish.Text);\r
635                     int chapterStart = int.Parse(drop_chapterStart.Text);\r
636 \r
637                     if (chapterFinish < chapterStart)\r
638                     {\r
639                         lbl_chptWarn.Visible = true;\r
640                         lbl_chptWarn.Text = "Invalid Chapter Range!";\r
641                     }\r
642                 }\r
643                 catch (Exception)\r
644                 {\r
645                     lbl_chptWarn.Visible = true;\r
646                     lbl_chptWarn.Text = "Invalid Chapter Range!";\r
647                 }\r
648             }\r
649 \r
650             \r
651         }\r
652 \r
653         private void drop_chapterFinish_SelectedIndexChanged(object sender, EventArgs e)\r
654         {\r
655             lbl_chptWarn.Visible = false;\r
656             QueryEditorText.Text = "";\r
657             if ((drop_chapterFinish.Text != "Auto") && (drop_chapterStart.Text != "Auto"))\r
658             {\r
659                 try\r
660                 {\r
661                     int chapterFinish = int.Parse(drop_chapterFinish.Text);\r
662                     int chapterStart = int.Parse(drop_chapterStart.Text);\r
663 \r
664                     if (chapterFinish < chapterStart)\r
665                     {\r
666                         lbl_chptWarn.Visible = true;\r
667                         lbl_chptWarn.Text = "Invalid Chapter Range!";\r
668                     }\r
669                 }\r
670                 catch (Exception)\r
671                 {\r
672                     lbl_chptWarn.Visible = true;\r
673                     lbl_chptWarn.Text = "Invalid Chapter Range!";\r
674                 }\r
675             }\r
676         }\r
677 \r
678         private void text_bitrate_TextChanged(object sender, EventArgs e)\r
679         {\r
680             text_filesize.Text = "";\r
681             slider_videoQuality.Value = 0;\r
682             SliderValue.Text = "0%";\r
683             CheckCRF.CheckState = CheckState.Unchecked;\r
684         }\r
685 \r
686         private void text_filesize_TextChanged(object sender, EventArgs e)\r
687         {\r
688             text_bitrate.Text = "";\r
689             slider_videoQuality.Value = 0;\r
690             SliderValue.Text = "0%";\r
691             CheckCRF.CheckState = CheckState.Unchecked;\r
692         }\r
693 \r
694         private void slider_videoQuality_Scroll(object sender, EventArgs e)\r
695         {\r
696             SliderValue.Text = slider_videoQuality.Value.ToString() + "%";\r
697             text_bitrate.Text = "";\r
698             text_filesize.Text = "";\r
699         }\r
700 \r
701         private void label_h264_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)\r
702         {\r
703             Process.Start("http://handbrake.m0k.org/trac/wiki/x264Options");\r
704         }\r
705 \r
706         private void text_width_TextChanged(object sender, EventArgs e)\r
707         {\r
708 \r
709             try\r
710             {\r
711                 if (CheckPixelRatio.Checked)\r
712                 {\r
713                     text_width.Text = "";\r
714                 }\r
715                 else\r
716                 {\r
717                     if ((int.Parse(text_width.Text) % 16) != 0)\r
718                     {\r
719                         text_width.BackColor = Color.LightCoral;\r
720                     }\r
721                     else\r
722                     {\r
723                         text_width.BackColor = Color.LightGreen;\r
724                     }\r
725                 }\r
726 \r
727                 if (lbl_Aspect.Text != "Select a Title")\r
728                 {\r
729                     double height = int.Parse(text_width.Text) / double.Parse(lbl_Aspect.Text);\r
730                     double mod16 = height % 16;\r
731                     height = height - mod16;\r
732 \r
733                     if (text_width.Text == "")\r
734                     {\r
735                         text_height.Text = "";\r
736                         text_width.BackColor = Color.White;\r
737                     }\r
738                     else\r
739                     {\r
740                         text_height.Text = height.ToString();\r
741                     }\r
742                 }\r
743             }\r
744             catch (Exception)\r
745             {\r
746                 // No need to throw an error here.\r
747             }\r
748                \r
749           \r
750         }\r
751 \r
752         private void text_height_TextChanged(object sender, EventArgs e)\r
753         {\r
754             try\r
755             {\r
756                 if (CheckPixelRatio.Checked)\r
757                 {\r
758                     text_height.Text = "";\r
759                 }\r
760                 else\r
761                 {\r
762                     if ((int.Parse(text_height.Text) % 16) != 0)\r
763                     {\r
764                         text_height.BackColor = Color.LightCoral;\r
765                     }\r
766                     else\r
767                     {\r
768                         text_height.BackColor = Color.LightGreen;\r
769                     }\r
770                 }\r
771             } catch(Exception){\r
772                 // No need to alert the user.\r
773             }\r
774         }\r
775 \r
776         private void drp_crop_SelectedIndexChanged(object sender, EventArgs e)\r
777         {\r
778             if ((string)drp_crop.SelectedItem == "Manual")\r
779             {\r
780             text_left.Enabled = true;\r
781             text_right.Enabled = true;\r
782             text_top.Enabled = true;\r
783             text_bottom.Enabled = true;\r
784             }\r
785 \r
786             if ((string)drp_crop.SelectedItem == "Auto Crop")\r
787             {\r
788                 text_left.Enabled = false;\r
789                 text_right.Enabled = false;\r
790                 text_top.Enabled = false;\r
791                 text_bottom.Enabled = false;\r
792                 text_left.Text = "";\r
793                 text_right.Text = "";\r
794                 text_top.Text = "";\r
795                 text_bottom.Text = "";\r
796 \r
797                 if (lbl_RecomendedCrop.Text != "Select a Title")\r
798                 {\r
799                     string[] temp = new string[4];\r
800                     temp = lbl_RecomendedCrop.Text.Split('/');\r
801                     text_left.Text = temp[2];\r
802                     text_right.Text = temp[3];\r
803                     text_top.Text = temp[0];\r
804                     text_bottom.Text = temp[1];\r
805                 }\r
806             }\r
807 \r
808             if ((string)drp_crop.SelectedItem == "No Crop")\r
809             {\r
810                 text_left.Enabled = false;\r
811                 text_right.Enabled = false;\r
812                 text_top.Enabled = false;\r
813                 text_bottom.Enabled = false;\r
814                 text_left.Text = "0";\r
815                 text_right.Text = "0";\r
816                 text_top.Text = "0";\r
817                 text_bottom.Text = "0";\r
818 \r
819             }\r
820         }\r
821         \r
822         private void CheckPixelRatio_CheckedChanged(object sender, EventArgs e)\r
823         {\r
824             text_width.Text = "";\r
825             text_height.Text = "";\r
826             text_width.BackColor = Color.White;\r
827             text_height.BackColor = Color.White;\r
828         }\r
829 \r
830         private void drp_dvdtitle_Click(object sender, EventArgs e)\r
831         {\r
832             if (drp_dvdtitle.Items.Count == 1)\r
833             {\r
834                 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
835             }\r
836         }\r
837 \r
838         private void drp_audioCodec_SelectedIndexChanged(object sender, EventArgs e)\r
839         {\r
840 \r
841             //CLI Audio mixdown Names: mono stereo dpl1 dpl2 6ch\r
842 \r
843             drp_audioMixDown.Items.Clear();\r
844 \r
845             if (drp_audioCodec.Text == "AAC")\r
846             {\r
847                 drp_audioMixDown.Items.Clear();\r
848                 drp_audioMixDown.Items.Add("Mono");\r
849                 drp_audioMixDown.Items.Add("Stereo");\r
850                 drp_audioMixDown.Items.Add("Dolby Surround");\r
851                 drp_audioMixDown.Items.Add("Dolby Pro Logic II");\r
852                 drp_audioMixDown.Items.Add("6 Channel Discrete");\r
853                 \r
854                 drp_audioBitrate.Items.Clear();\r
855                 drp_audioBitrate.Items.Add("32");\r
856                 drp_audioBitrate.Items.Add("40");\r
857                 drp_audioBitrate.Items.Add("48");\r
858                 drp_audioBitrate.Items.Add("56");\r
859                 drp_audioBitrate.Items.Add("64");\r
860                 drp_audioBitrate.Items.Add("80");\r
861                 drp_audioBitrate.Items.Add("86");\r
862                 drp_audioBitrate.Items.Add("112");\r
863                 drp_audioBitrate.Items.Add("128");\r
864                 drp_audioBitrate.Items.Add("160");\r
865 \r
866             }\r
867             else\r
868             {\r
869                 drp_audioMixDown.Items.Clear();\r
870                 drp_audioMixDown.Items.Add("Stereo");\r
871                 drp_audioMixDown.Items.Add("Dolby Surround");\r
872                 drp_audioMixDown.Items.Add("Dolby Pro Logic II");\r
873 \r
874                 drp_audioBitrate.Items.Clear();\r
875                 drp_audioBitrate.Items.Add("32");\r
876                 drp_audioBitrate.Items.Add("40");\r
877                 drp_audioBitrate.Items.Add("48");\r
878                 drp_audioBitrate.Items.Add("56");\r
879                 drp_audioBitrate.Items.Add("64");\r
880                 drp_audioBitrate.Items.Add("80");\r
881                 drp_audioBitrate.Items.Add("86");\r
882                 drp_audioBitrate.Items.Add("112");\r
883                 drp_audioBitrate.Items.Add("128");\r
884                 drp_audioBitrate.Items.Add("160");\r
885                 drp_audioBitrate.Items.Add("192");\r
886                 drp_audioBitrate.Items.Add("224");\r
887                 drp_audioBitrate.Items.Add("256");\r
888                 drp_audioBitrate.Items.Add("320");\r
889                 drp_audioBitrate.Items.Add("384");\r
890             }\r
891         }\r
892 \r
893         private void drp_audioMixDown_SelectedIndexChanged(object sender, EventArgs e)\r
894         {\r
895             if (drp_audioCodec.Text == "AAC")\r
896             {\r
897                 if (drp_audioMixDown.Text == "6 Channel Discrete")\r
898                 {\r
899 \r
900                     drp_audioBitrate.Items.Clear();\r
901                     drp_audioBitrate.Items.Add("32");\r
902                     drp_audioBitrate.Items.Add("40");\r
903                     drp_audioBitrate.Items.Add("48");\r
904                     drp_audioBitrate.Items.Add("56");\r
905                     drp_audioBitrate.Items.Add("64");\r
906                     drp_audioBitrate.Items.Add("80");\r
907                     drp_audioBitrate.Items.Add("86");\r
908                     drp_audioBitrate.Items.Add("112");\r
909                     drp_audioBitrate.Items.Add("128");\r
910                     drp_audioBitrate.Items.Add("160");\r
911                     drp_audioBitrate.Items.Add("192");\r
912                     drp_audioBitrate.Items.Add("224");\r
913                     drp_audioBitrate.Items.Add("256");\r
914                     drp_audioBitrate.Items.Add("320");\r
915                     drp_audioBitrate.Items.Add("384");\r
916                 }\r
917             }\r
918         }\r
919 \r
920         private void Check_ChapterMarkers_CheckedChanged(object sender, EventArgs e)\r
921         {\r
922             if (Check_ChapterMarkers.Checked)\r
923             {\r
924                 string destination = text_destination.Text;\r
925                 destination = destination.Replace(".mp4", ".m4v");\r
926                 text_destination.Text = destination;\r
927             }\r
928         }\r
929 \r
930         private void check_largeFile_CheckedChanged(object sender, EventArgs e)\r
931         {\r
932             if (!text_destination.Text.Contains(".mp4"))\r
933             {\r
934                 MessageBox.Show("This option is only compatible with the mp4 file container.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
935                 check_largeFile.CheckState = CheckState.Unchecked;\r
936             }\r
937         }\r
938 \r
939         private void check_turbo_CheckedChanged(object sender, EventArgs e)\r
940         {\r
941             if (!drp_videoEncoder.Text.Contains("H.264"))\r
942             {\r
943                 MessageBox.Show("This option is only compatible with the H.264 encoder's", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
944                 check_turbo.CheckState = CheckState.Unchecked;\r
945             }\r
946         }\r
947 \r
948         private void drp_videoEncoder_SelectedIndexChanged(object sender, EventArgs e)\r
949         {\r
950             //Turn off some options which are H.264 only when the user selects a non h.264 encoder\r
951             if (!drp_videoEncoder.Text.Contains("H.264"))\r
952             {\r
953                 check_turbo.CheckState = CheckState.Unchecked;\r
954                 CheckCRF.CheckState = CheckState.Unchecked;\r
955             }\r
956         }\r
957 \r
958         private void CheckCRF_CheckedChanged(object sender, EventArgs e)\r
959         {\r
960             if (slider_videoQuality.Value == 0)\r
961             {\r
962                 MessageBox.Show("This option is can only be used with the 'Video Quality' slider.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
963                 CheckCRF.CheckState = CheckState.Unchecked;\r
964             }\r
965         }\r
966 \r
967         public void setStreamReader(Parsing.DVD dvd)\r
968         {\r
969             this.thisDVD = dvd;\r
970         }\r
971 \r
972         private void drp_dvdtitle_SelectedIndexChanged(object sender, EventArgs e)\r
973         {\r
974             // Reset some values on the form\r
975             lbl_Aspect.Text = "Select a Title";\r
976             lbl_RecomendedCrop.Text = "Select a Title";\r
977             drop_chapterStart.Items.Clear();\r
978             drop_chapterFinish.Items.Clear();\r
979             QueryEditorText.Text = "";\r
980 \r
981             // If the dropdown is set to automatic nothing else needs to be done.\r
982             // Otheriwse if its not, title data has to be loased from parsing.\r
983             if (drp_dvdtitle.Text != "Automatic")\r
984             {\r
985                 Parsing.Title selectedTitle = drp_dvdtitle.SelectedItem as Parsing.Title;\r
986                 lbl_Aspect.Text = selectedTitle.AspectRatio.ToString();\r
987                 lbl_RecomendedCrop.Text = string.Format("{0}/{1}/{2}/{3}", selectedTitle.AutoCropDimensions[0], selectedTitle.AutoCropDimensions[1], selectedTitle.AutoCropDimensions[2], selectedTitle.AutoCropDimensions[3]);\r
988 \r
989                 drop_chapterStart.Items.Clear();\r
990                 drop_chapterStart.Items.AddRange(selectedTitle.Chapters.ToArray());\r
991                 if (drop_chapterStart.Items.Count > 0)\r
992                 {\r
993                     drop_chapterStart.Text = drop_chapterStart.Items[0].ToString();\r
994                 }\r
995 \r
996                 drop_chapterFinish.Items.Clear();\r
997                 drop_chapterFinish.Items.AddRange(selectedTitle.Chapters.ToArray());\r
998                 if (drop_chapterFinish.Items.Count > 0)\r
999                 {\r
1000                     drop_chapterFinish.Text = drop_chapterFinish.Items[drop_chapterFinish.Items.Count - 1].ToString();\r
1001                 }\r
1002 \r
1003                 drp_audioChannels.Items.Clear();\r
1004                 drp_audioChannels.Items.Add("Automatic");\r
1005                 drp_audioChannels.Items.AddRange(selectedTitle.AudioTracks.ToArray());\r
1006                 if (drp_audioChannels.Items.Count > 0)\r
1007                 {\r
1008                     drp_audioChannels.Text = drp_audioChannels.Items[0].ToString();\r
1009                 }\r
1010 \r
1011                 drp_subtitle.Items.Clear();\r
1012                 drp_subtitle.Items.Add("None");\r
1013                 drp_subtitle.Items.AddRange(selectedTitle.Subtitles.ToArray());\r
1014                 if (drp_subtitle.Items.Count > 0)\r
1015                 {\r
1016                     drp_subtitle.Text = drp_subtitle.Items[0].ToString();\r
1017                 }\r
1018             }\r
1019         } \r
1020 \r
1021         // The Query Generation Function\r
1022         public string GenerateTheQuery()\r
1023         {\r
1024             string source = text_source.Text;\r
1025             string dvdTitle = drp_dvdtitle.Text;\r
1026             string chapterStart = drop_chapterStart.Text;\r
1027             string chapterFinish = drop_chapterFinish.Text;\r
1028             int totalChapters = drop_chapterFinish.Items.Count - 1;\r
1029             string dvdChapter = "";\r
1030 \r
1031             if (source ==  "")\r
1032                 MessageBox.Show("No Source has been selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
1033             else\r
1034             {\r
1035                 source = " -i " + '"' + source+ '"'; //'"'+\r
1036             }\r
1037 \r
1038             if (dvdTitle ==  "Automatic")\r
1039                 dvdTitle = "";\r
1040             else\r
1041             {\r
1042                 string[] titleInfo = dvdTitle.Split(' ');\r
1043                 dvdTitle = " -t "+ titleInfo[0];\r
1044             }\r
1045 \r
1046             if (chapterFinish.Equals("Auto") && chapterStart.Equals("Auto"))\r
1047                 dvdChapter = "";\r
1048             else if (chapterFinish == chapterStart)\r
1049                 dvdChapter = " -c " + chapterStart;\r
1050             else\r
1051                 dvdChapter = " -c " + chapterStart + "-" + chapterFinish;\r
1052 \r
1053             string querySource = source+ dvdTitle+ dvdChapter;\r
1054             // ----------------------------------------------------------------------\r
1055 \r
1056             // Destination\r
1057 \r
1058             string destination = text_destination.Text;\r
1059             string videoEncoder = drp_videoEncoder.Text;\r
1060             string audioEncoder = drp_audioCodec.Text;\r
1061             string width = text_width.Text;\r
1062             string height = text_height.Text;\r
1063 \r
1064             if (destination ==  "")\r
1065                 MessageBox.Show("No destination has been selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
1066             else\r
1067                 destination = " -o " + '"' + destination + '"'; //'"'+ \r
1068 \r
1069 \r
1070             switch (videoEncoder)\r
1071             {\r
1072                 case "Mpeg 4":\r
1073                     videoEncoder = " -e ffmpeg";\r
1074                     break;\r
1075                 case "Xvid":\r
1076                     videoEncoder = " -e xvid";\r
1077                     break;\r
1078                 case "H.264":\r
1079                     videoEncoder = " -e x264";\r
1080                     break;\r
1081                 case "H.264 Baseline 1.3":\r
1082                     videoEncoder = " -e x264b13";\r
1083                     break;\r
1084                 case "H.264 (iPod)":\r
1085                     videoEncoder = " -e x264b30";\r
1086                     break;\r
1087                 default:\r
1088                     videoEncoder = " -e x264";\r
1089                     break;\r
1090             }\r
1091            \r
1092             switch (audioEncoder)\r
1093             {\r
1094                 case "AAC":\r
1095                     audioEncoder = " -E faac";\r
1096                     break;\r
1097                 case "MP3":\r
1098                     audioEncoder = " -E lame";\r
1099                     break;\r
1100                 case "Vorbis":\r
1101                     audioEncoder = " -E vorbis";\r
1102                     break;\r
1103                 case "AC3":\r
1104                     audioEncoder = " -E ac3";\r
1105                     break;\r
1106                 default:\r
1107                     audioEncoder = " -E faac";\r
1108                     break;\r
1109             }\r
1110 \r
1111             if (width !=  "")\r
1112                 width = " -w "+ width;\r
1113             \r
1114 \r
1115             if (height !=  "")\r
1116                 height = " -l "+ height;\r
1117             \r
1118 \r
1119             string queryDestination = destination+ videoEncoder+ audioEncoder+ width+ height;\r
1120             // ----------------------------------------------------------------------\r
1121 \r
1122             // Picture Settings Tab\r
1123 \r
1124             string cropSetting = drp_crop.Text;\r
1125             string cropTop = text_top.Text;\r
1126             string cropBottom = text_bottom.Text;\r
1127             string cropLeft = text_left.Text;\r
1128             string cropRight = text_right.Text;\r
1129             string subtitles = drp_subtitle.Text;\r
1130             string cropOut = "";\r
1131             // Returns Crop Query\r
1132 \r
1133             if (cropSetting == "Auto Crop")\r
1134                 cropOut = "";\r
1135             else if (cropSetting == "No Crop")\r
1136                 cropOut = " --crop 0:0:0:0 ";\r
1137             else\r
1138                 cropOut = " --crop " + cropTop + ":" + cropBottom + ":" + cropLeft + ":" + cropRight;\r
1139 \r
1140             if (subtitles ==  "None")\r
1141                 subtitles = "";\r
1142             else if (subtitles ==  "")\r
1143                 subtitles = "";\r
1144             else\r
1145             {\r
1146                 string[] tempSub;\r
1147                 tempSub = subtitles.Split(' ');\r
1148                 subtitles = " -s "+ tempSub[0];\r
1149             }\r
1150 \r
1151             string queryPictureSettings = cropOut+ subtitles;\r
1152             // ----------------------------------------------------------------------\r
1153 \r
1154             // Video Settings Tab\r
1155 \r
1156             string videoBitrate = text_bitrate.Text;\r
1157             string videoFilesize = text_filesize.Text;\r
1158             int videoQuality = slider_videoQuality.Value;\r
1159             string vidQSetting = "";\r
1160             string twoPassEncoding = "";\r
1161             string deinterlace = "";\r
1162             string grayscale = "";\r
1163             string videoFramerate = drp_videoFramerate.Text;\r
1164             string pixelRatio = "";\r
1165             string ChapterMarkers = "";\r
1166             string turboH264 = "";\r
1167             string largeFile = "";\r
1168 \r
1169             if (videoBitrate !=  "")\r
1170                 videoBitrate = " -b "+ videoBitrate;\r
1171 \r
1172             if (videoFilesize !=  "")\r
1173                 videoFilesize = " -S "+ videoFilesize;\r
1174 \r
1175             // Video Quality Setting\r
1176 \r
1177             if ((videoQuality ==  0))\r
1178                 vidQSetting = "";\r
1179             else\r
1180             {\r
1181                 videoQuality = videoQuality/ 100;\r
1182                 if (videoQuality ==  1)\r
1183                 {\r
1184                     vidQSetting = "1.0";\r
1185                 }\r
1186 \r
1187                 vidQSetting = " -q " + videoQuality.ToString();\r
1188             }\r
1189 \r
1190             if (check_2PassEncode.Checked)\r
1191                 twoPassEncoding = " -2 ";\r
1192 \r
1193             if (check_DeInterlace.Checked)\r
1194                 deinterlace = " -d ";\r
1195 \r
1196             if (check_grayscale.Checked)\r
1197                 grayscale = " -g ";\r
1198 \r
1199             if (videoFramerate ==  "Automatic")\r
1200                 videoFramerate = "";\r
1201             else\r
1202                 videoFramerate = " -r "+ videoFramerate;\r
1203 \r
1204             if (CheckPixelRatio.Checked)\r
1205                 pixelRatio = " -p ";\r
1206 \r
1207             if (Check_ChapterMarkers.Checked)\r
1208                 ChapterMarkers = " -m ";\r
1209 \r
1210             if (check_turbo.Checked)\r
1211                 turboH264 = " -T ";\r
1212 \r
1213             if (check_largeFile.Checked)\r
1214                 largeFile = " -4 ";\r
1215 \r
1216             string queryVideoSettings = videoBitrate + videoFilesize + vidQSetting + twoPassEncoding + deinterlace + grayscale + videoFramerate + pixelRatio + ChapterMarkers + turboH264 + largeFile;\r
1217             // ----------------------------------------------------------------------\r
1218 \r
1219             // Audio Settings Tab\r
1220 \r
1221             string audioBitrate = drp_audioBitrate.Text;\r
1222             string audioSampleRate = drp_audioSampleRate.Text;\r
1223             string audioChannels = drp_audioChannels.Text;\r
1224             string Mixdown = drp_audioMixDown.Text;\r
1225             string SixChannelAudio = "";\r
1226 \r
1227             if (audioBitrate !=  "")\r
1228                 audioBitrate = " -B "+ audioBitrate;\r
1229 \r
1230             if (audioSampleRate !=  "")\r
1231                 audioSampleRate = " -R "+ audioSampleRate;\r
1232 \r
1233             if (audioChannels ==  "Automatic")\r
1234                 audioChannels = "";\r
1235             else if (audioChannels ==  "")\r
1236                 audioChannels = "";\r
1237             else\r
1238             {\r
1239                 string[] tempSub;\r
1240                 tempSub = audioChannels.Split(' ');\r
1241                 audioChannels = " -a "+ tempSub[0];\r
1242             }\r
1243 \r
1244             switch (Mixdown)\r
1245             {\r
1246                 case "Automatic":\r
1247                     Mixdown = "";\r
1248                     break;\r
1249                 case "Mono":\r
1250                     Mixdown = "mono";\r
1251                     break;\r
1252                 case "Stereo":\r
1253                     Mixdown = "stereo";\r
1254                     break;\r
1255                 case "Dolby Surround":\r
1256                     Mixdown = "dpl1";\r
1257                     break;\r
1258                 case "Dolby Pro Logic II":\r
1259                     Mixdown = "dpl2";\r
1260                     break;\r
1261                 case "6 Channel Discrete":\r
1262                     Mixdown = "6ch";\r
1263                     break;\r
1264                 default:\r
1265                     Mixdown = "stero";\r
1266                     break;\r
1267             }\r
1268 \r
1269             if (Mixdown !=  "")\r
1270                 SixChannelAudio = " -6 "+ Mixdown;\r
1271             else\r
1272                 SixChannelAudio = "";\r
1273 \r
1274             string queryAudioSettings = audioBitrate+ audioSampleRate+ audioChannels+ SixChannelAudio;\r
1275             // ----------------------------------------------------------------------\r
1276 \r
1277             //  H.264 Tab\r
1278 \r
1279             string CRF = CheckCRF.CheckState.ToString();\r
1280             string h264Advanced = rtf_h264advanced.Text;\r
1281             if ((CRF ==  "1"))\r
1282                 CRF = " -Q ";\r
1283             else\r
1284                 CRF = "";\r
1285 \r
1286             if ((h264Advanced ==  ""))\r
1287                 h264Advanced = "";\r
1288             else\r
1289                 h264Advanced = " -x "+ h264Advanced;\r
1290     \r
1291 \r
1292             string h264Settings = CRF+ h264Advanced;\r
1293             // ----------------------------------------------------------------------\r
1294 \r
1295             // Processors (Program Settings)\r
1296 \r
1297             string processors = Properties.Settings.Default.Processors;\r
1298             //  Number of Processors Handler\r
1299 \r
1300             if (processors ==  "Automatic")\r
1301                 processors = "";\r
1302             else\r
1303                 processors = " -C "+ processors+ " ";\r
1304 \r
1305 \r
1306             string queryAdvancedSettings = processors;\r
1307             // ----------------------------------------------------------------------\r
1308 \r
1309             //  Verbose option (Program Settings)\r
1310 \r
1311             string verbose = "";\r
1312             if (Properties.Settings.Default.verbose ==  "Checked")\r
1313                 verbose = " -v ";\r
1314 \r
1315             // ----------------------------------------------------------------------\r
1316 \r
1317             return querySource+ queryDestination+ queryPictureSettings+ queryVideoSettings+ h264Settings+ queryAudioSettings+ queryAdvancedSettings+ verbose;\r
1318         }\r
1319 \r
1320 \r
1321 \r
1322         // This is the END of the road ------------------------------------------------------------------------------\r
1323     }\r
1324 }