OSDN Git Service

WinGui:
[handbrake-jp/handbrake-jp-git.git] / win / C# / Controls / x264Panel.cs
1 /*  x264Panel.cs $\r
2     This file is part of the HandBrake source code.\r
3     Homepage: <http://handbrake.fr>.\r
4     It may be used under the terms of the GNU General Public License. */\r
5 \r
6 namespace Handbrake.Controls\r
7 {\r
8     using System;\r
9     using System.Windows.Forms;\r
10 \r
11     /// <summary>\r
12     /// The Advanced Panel\r
13     /// </summary>\r
14     public partial class x264Panel : UserControl\r
15     {\r
16         /* \r
17          * TODO This code was ported from the obj-c MacGUI code. It's really messy and could really do with being cleaned up\r
18          * at some point.\r
19          */\r
20 \r
21         /// <summary>\r
22         /// Initializes a new instance of the <see cref="x264Panel"/> class. \r
23         /// Initializes a new instance of the x264 panel user control\r
24         /// </summary>\r
25         public x264Panel()\r
26         {\r
27             InitializeComponent();\r
28 \r
29             if (Properties.Settings.Default.tooltipEnable)\r
30                 ToolTip.Active = true;\r
31 \r
32             Reset2Defaults();\r
33         }\r
34 \r
35         /// <summary>\r
36         /// Gets or sets the X264 query string\r
37         /// </summary>\r
38         public string X264Query\r
39         {\r
40             get\r
41             {\r
42                 return rtf_x264Query.Text;\r
43             }\r
44             set\r
45             {\r
46                 rtf_x264Query.Text = value;\r
47             }\r
48         }\r
49 \r
50         /// <summary>\r
51         /// Reset all components to defaults and clears the x264 rtf box\r
52         /// </summary>\r
53         public void Reset2Defaults()\r
54         {\r
55             check_8x8DCT.CheckState = CheckState.Checked;\r
56             check_Cabac.CheckState = CheckState.Checked;\r
57             check_weightp.CheckState = CheckState.Checked;\r
58             check_noDCTDecimate.CheckState = CheckState.Unchecked;\r
59             combo_pyrmidalBFrames.SelectedIndex = 0;\r
60             drop_analysis.SelectedIndex = 0;\r
61             drop_bFrames.SelectedIndex = 0;\r
62             drop_deblockAlpha.SelectedIndex = 0;\r
63             drop_deblockBeta.SelectedIndex = 0;\r
64             drop_directPrediction.SelectedIndex = 0;\r
65             drop_MotionEstimationMethod.SelectedIndex = 0;\r
66             drop_MotionEstimationRange.SelectedIndex = 0;\r
67             drop_refFrames.SelectedIndex = 0;\r
68             drop_subpixelMotionEstimation.SelectedIndex = 0;\r
69             drop_trellis.SelectedIndex = 0;\r
70             slider_psyrd.Value = 10;\r
71             slider_psytrellis.Value = 0;\r
72             drop_adaptBFrames.SelectedIndex = 0;\r
73 \r
74             rtf_x264Query.Text = string.Empty;\r
75         }\r
76 \r
77         #region Standardize Option String\r
78         /// <summary>\r
79         /// Iterate over every x264 option, standardize it, write the full string to the x264 rtf box\r
80         /// </summary>\r
81         public void StandardizeOptString()\r
82         {\r
83             /* Set widgets depending on the opt string in field */\r
84             string thisOpt; // The separated option such as "bframes=3"\r
85             string optName; // The option name such as "bframes"\r
86             string optValue; // The option value such as "3"\r
87             string changedOptString = string.Empty;\r
88             string[] currentOptsArray;\r
89 \r
90             /*First, we get an opt string to process */\r
91             string currentOptString = rtf_x264Query.Text;\r
92 \r
93             /*verify there is an opt string to process */\r
94             if (currentOptString.Contains("="))\r
95             {\r
96                 /*Put individual options into an array based on the ":" separator for processing, result is "<opt>=<value>"*/\r
97                 currentOptsArray = currentOptString.Split(':');\r
98 \r
99                 /*iterate through the array and get <opts> and <values*/\r
100                 int loopcounter;\r
101                 int currentOptsArrayCount = currentOptsArray.Length;\r
102                 for (loopcounter = 0; loopcounter < currentOptsArrayCount; loopcounter++)\r
103                 {\r
104                     thisOpt = currentOptsArray[loopcounter];\r
105                     if (currentOptsArray[currentOptsArrayCount - 1] == string.Empty)\r
106                         break;\r
107 \r
108                     string[] splitOptRange = thisOpt.Split('=');\r
109                     if (thisOpt != string.Empty)\r
110                     {\r
111                         if (thisOpt.Contains("="))\r
112                         {\r
113                             optName = splitOptRange[0];\r
114                             optValue = splitOptRange[1];\r
115 \r
116                             /* Standardize the names here depending on whats in the string */\r
117                             optName = StandardizeOptName(optName);\r
118                             thisOpt = optName + "=" + optValue;\r
119                         }\r
120                         else // No value given so we use a default of "1"\r
121                         {\r
122                             optName = thisOpt;\r
123                             /* Standardize the names here depending on whats in the string */\r
124                             optName = StandardizeOptName(optName);\r
125                             thisOpt = optName + "=1";\r
126                         }\r
127                     }\r
128 \r
129                     /* Construct New String for opts here */\r
130                     if (thisOpt == string.Empty)\r
131                         changedOptString = changedOptString + thisOpt;\r
132                     else\r
133                     {\r
134                         if (changedOptString == string.Empty)\r
135                             changedOptString = thisOpt;\r
136                         else\r
137                             changedOptString = changedOptString + ":" + thisOpt;\r
138                     }\r
139                 }\r
140             }\r
141 \r
142             /* Change the option string to reflect the new standardized option string */\r
143             if (changedOptString != string.Empty)\r
144                 rtf_x264Query.Text = changedOptString;\r
145         }\r
146 \r
147         /// <summary>\r
148         /// Take a single option and standardize it. Returns as a String\r
149         /// Input: String. - Single X264 Option. Name only\r
150         /// Output: String - Single X264 Option. Name only. Changed to standard format\r
151         /// </summary>\r
152         /// <param name="cleanOptNameString">a string of x264 options to clean</param>\r
153         /// <returns>A string containing standardized x264 option names</returns>\r
154         private static string StandardizeOptName(string cleanOptNameString)\r
155         {\r
156             string input = cleanOptNameString;\r
157 \r
158             /* Reference Frames */\r
159             if (input.Equals("ref") || input.Equals("frameref"))\r
160                 cleanOptNameString = "ref";\r
161 \r
162             /*No Dict Decimate*/\r
163             if (input.Equals("no-dct-decimate") || input.Equals("no_dct_decimate") || input.Equals("nodct_decimate"))\r
164                 cleanOptNameString = "no-dct-decimate";\r
165 \r
166             /*Subme*/\r
167             if (input.Equals("subme"))\r
168                 cleanOptNameString = "subq";\r
169 \r
170             /*ME Range*/\r
171             if (input.Equals("me-range") || input.Equals("me_range"))\r
172                 cleanOptNameString = "merange";\r
173 \r
174             /*B Pyramid*/\r
175             if (input.Equals("b_pyramid"))\r
176                 cleanOptNameString = "b-pyramid";\r
177 \r
178             /*Direct Prediction*/\r
179             if (input.Equals("direct-pred") || input.Equals("direct_pred"))\r
180                 cleanOptNameString = "direct";\r
181 \r
182             /*Deblocking*/\r
183             if (input.Equals("filter"))\r
184                 cleanOptNameString = "deblock";\r
185 \r
186             /*Analysis*/\r
187             if (input.Equals("partitions"))\r
188                 cleanOptNameString = "analyse";\r
189 \r
190             return cleanOptNameString;\r
191         }\r
192         #endregion\r
193 \r
194         /// <summary>\r
195         /// Resets the GUI widgets to the contents of the option string.\r
196         /// </summary>\r
197         public void SetCurrentSettingsInPanel()\r
198         {\r
199             /* Set widgets depending on the opt string in field */\r
200             string thisOpt; // The separated option such as "bframes=3"\r
201             string optName; // The option name such as "bframes"\r
202             string optValue; // The option value such as "3"\r
203             string[] currentOptsArray;\r
204 \r
205             // Set currentOptString to the contents of the text box.\r
206             string currentOptString = rtf_x264Query.Text.Replace("\n", string.Empty);\r
207 \r
208             /*verify there is an opt string to process */\r
209             if (currentOptString.Contains("="))\r
210             {\r
211                 /*Put individual options into an array based on the ":" separator for processing, result is "<opt>=<value>"*/\r
212                 currentOptsArray = currentOptString.Split(':');\r
213 \r
214                 /*iterate through the array and get <opts> and <values*/\r
215                 int loopcounter;\r
216                 int currentOptsArrayCount = currentOptsArray.Length;\r
217 \r
218                 /*iterate through the array and get <opts> and <values*/\r
219                 for (loopcounter = 0; loopcounter < currentOptsArrayCount; loopcounter++)\r
220                 {\r
221                     thisOpt = currentOptsArray[loopcounter];\r
222                     string[] splitOptRange = thisOpt.Split('=');\r
223 \r
224                     if (thisOpt.Contains("="))\r
225                     {\r
226                         optName = splitOptRange[0];\r
227                         optValue = splitOptRange[1];\r
228 \r
229                         /*Run through the available widgets for x264 opts and set them, as you add widgets, \r
230                             they need to be added here. This should be moved to its own method probably*/\r
231                         switch (optName)\r
232                         {\r
233                             case "bframes":\r
234                                 drop_bFrames.SelectedItem = optValue;\r
235                                 continue;\r
236                             case "ref":\r
237                                 drop_refFrames.SelectedItem = optValue;\r
238                                 continue;\r
239                             case "weightp":\r
240                                 this.check_weightp.CheckState = optValue == "0" ? CheckState.Unchecked : CheckState.Checked;\r
241                                 continue;\r
242                             case "no-dct-decimate":\r
243                                 check_noDCTDecimate.CheckState = CheckState.Checked;\r
244                                 continue;\r
245                             case "subq":\r
246                                 int subqValue;\r
247                                 if (int.TryParse(optValue, out subqValue))\r
248                                 {\r
249                                     drop_subpixelMotionEstimation.SelectedIndex = subqValue + 1;\r
250                                 }\r
251                                 continue;\r
252                             case "trellis":\r
253                                 switch (optValue)\r
254                                 {\r
255                                     case "0":\r
256                                         drop_trellis.SelectedIndex = 1;\r
257                                         break;\r
258                                     case "1":\r
259                                          drop_trellis.SelectedIndex = 2;\r
260                                         break;\r
261                                     case "2":\r
262                                         drop_trellis.SelectedIndex = 3;\r
263                                         break;\r
264                                 }\r
265                                 continue;\r
266                             case "me":\r
267                                 if (optValue.Equals("dia"))\r
268                                     drop_MotionEstimationMethod.SelectedItem = "Diamond";\r
269                                 else if (optValue.Equals("hex"))\r
270                                     drop_MotionEstimationMethod.SelectedItem = "Hexagon";\r
271                                 else if (optValue.Equals("umh"))\r
272                                     drop_MotionEstimationMethod.SelectedItem = "Uneven Multi-Hexagon";\r
273                                 else if (optValue.Equals("esa"))\r
274                                     drop_MotionEstimationMethod.SelectedItem = "Exhaustive";\r
275                                 else if (optValue.Equals("tesa"))\r
276                                     drop_MotionEstimationMethod.SelectedItem = "Transformed Exhaustive";\r
277                                 continue;\r
278                             case "merange":\r
279                                 drop_MotionEstimationRange.SelectedItem = optValue;\r
280                                 continue;\r
281                             case "b-adapt":\r
282                                 int badapt;\r
283                                 int.TryParse(optValue, out badapt);\r
284                                 drop_adaptBFrames.SelectedIndex = (badapt + 1);\r
285                                 continue;\r
286                             case "b-pyramid":\r
287                                 switch (optValue)\r
288                                 {\r
289                                     case "normal":\r
290                                         combo_pyrmidalBFrames.SelectedIndex = 0;\r
291                                         break;\r
292                                     case "strict":\r
293                                         combo_pyrmidalBFrames.SelectedIndex = 2;\r
294                                         break;\r
295                                     case "none":\r
296                                         combo_pyrmidalBFrames.SelectedIndex = 1;\r
297                                         break;\r
298                                 }\r
299                                 continue;\r
300                             case "direct":\r
301                                 if (optValue == "auto")\r
302                                     optValue = "Automatic";\r
303 \r
304                                 if (optValue != string.Empty)\r
305                                 {\r
306                                     char[] letters = optValue.ToCharArray();\r
307                                     letters[0] = Char.ToUpper(letters[0]);\r
308                                     optValue = new string(letters);\r
309                                 }\r
310 \r
311                                 drop_directPrediction.SelectedItem = optValue;\r
312                                 continue;\r
313                             case "deblock":\r
314                                 string[] splitDeblock = optValue.Split(',');\r
315                                 string alphaDeblock = splitDeblock[0];\r
316                                 string betaDeblock = splitDeblock[1];\r
317 \r
318                                 if (alphaDeblock.Equals("0") && betaDeblock.Replace("\n", string.Empty).Equals("0"))\r
319                                 {\r
320                                     drop_deblockAlpha.SelectedItem = "Default (0)";\r
321                                     drop_deblockBeta.SelectedItem = "Default (0)";\r
322                                 }\r
323                                 else\r
324                                 {\r
325                                     drop_deblockAlpha.SelectedItem = !alphaDeblock.Equals("0") ? alphaDeblock : "0";\r
326 \r
327                                     drop_deblockBeta.SelectedItem = !betaDeblock.Replace("\n", string.Empty).Equals("0")\r
328                                                                         ? betaDeblock.Replace("\n", string.Empty)\r
329                                                                         : "0";\r
330                                 }\r
331                                 continue;\r
332                             case "analyse":\r
333                                 if (optValue.Equals("p8x8,b8x8,i8x8,i4x4"))\r
334                                     drop_analysis.SelectedItem = "Default (most)";\r
335                                 if (optValue.Equals("none"))\r
336                                     drop_analysis.SelectedItem = "None";\r
337                                 if (optValue.Equals("i4x4,i8x8"))\r
338                                     drop_analysis.SelectedItem = "Some";\r
339                                 if (optValue.Equals("all"))\r
340                                     drop_analysis.SelectedItem = "All";\r
341                                 continue;\r
342                             case "8x8dct":\r
343                                 check_8x8DCT.CheckState = optValue == "1" ? CheckState.Checked : CheckState.Unchecked;\r
344                                 continue;\r
345                             case "aq-strength":\r
346                                 float value;\r
347                                 float.TryParse(optValue, out value);\r
348                                 int sliderValue;\r
349                                 int.TryParse((value * 10).ToString(), out sliderValue);\r
350                                 slider_adaptiveQuantStrength.Value = sliderValue;\r
351                                 continue;\r
352                             case "cabac":\r
353                                 check_Cabac.CheckState = CheckState.Unchecked;\r
354                                 continue;\r
355                             case "psy-rd":\r
356                                 string[] x = optValue.Split(',');\r
357 \r
358                                 double psyrd, psytrellis;\r
359                                 int val, val2;\r
360 \r
361                                 // default psy-rd = 1 (10 for the slider)\r
362                                 psyrd = double.TryParse(x[0], out psyrd) ? psyrd * 10 : 10.0;\r
363                                 // default psy-trellis = 0\r
364                                 psytrellis = double.TryParse(x[1], out psytrellis) ? psytrellis * 20 : 0.0;\r
365 \r
366                                 int.TryParse(psyrd.ToString(), out val);\r
367                                 int.TryParse(psytrellis.ToString(), out val2);\r
368 \r
369                                 slider_psyrd.Value = val;\r
370                                 slider_psytrellis.Value = val2;\r
371                                 continue;\r
372                         }\r
373                     }\r
374                 }\r
375             }\r
376         }\r
377 \r
378         /// <summary>\r
379         /// This function will update the X264 Query when one of the GUI widgets changes.\r
380         /// </summary>\r
381         /// <param name="sender">\r
382         /// The sender.\r
383         /// </param>\r
384         private void OnX264WidgetChange(string sender)\r
385         {\r
386             Animate(sender);\r
387             string optNameToChange = sender;\r
388             string currentOptString = rtf_x264Query.Text;\r
389 \r
390             /*First, we create a pattern to check for ":"optNameToChange"=" to modify the option if the name falls after\r
391                 the first character of the opt string (hence the ":") */\r
392             string checkOptNameToChange = ":" + optNameToChange + "=";\r
393             string checkOptNameToChangeBegin = optNameToChange + "=";\r
394 \r
395             // IF the current H264 Option String Contains Multiple Items or Just 1 Item\r
396             if ((currentOptString.Contains(checkOptNameToChange)) || (currentOptString.StartsWith(checkOptNameToChangeBegin)))\r
397                 HasOptions(currentOptString, optNameToChange);\r
398             else // IF there is no options in the rich text box!\r
399                 HasNoOptions(optNameToChange);\r
400         }\r
401 \r
402         /// <summary>\r
403         /// Called when the current x264 option string contains multiple (or a single) item(s) in it seperated by :\r
404         /// it updates the current option that the widget corrosponds to, if it is already in thes string.\r
405         /// </summary>\r
406         /// <param name="currentOptString">The Current Option String</param>\r
407         /// <param name="optNameToChange">Name of the option to change</param>\r
408         private void HasOptions(string currentOptString, string optNameToChange)\r
409         {\r
410             string thisOpt; // The separated option such as "bframes=3"\r
411             string optName; // The option name such as "bframes"\r
412             string[] currentOptsArray;\r
413 \r
414             /* Create new empty opt string*/\r
415             string changedOptString = string.Empty;\r
416 \r
417             /*Put individual options into an array based on the ":" separator for processing, result is "<opt>=<value>"*/\r
418             currentOptsArray = currentOptString.Split(':');\r
419 \r
420             /*iterate through the array and get <opts> and <values*/\r
421             for (int loopcounter = 0; loopcounter < currentOptsArray.Length; loopcounter++)\r
422             {\r
423                 thisOpt = currentOptsArray[loopcounter];\r
424 \r
425                 if (thisOpt.Contains("="))\r
426                 {\r
427                     string[] splitOptRange = thisOpt.Split('=');\r
428 \r
429                     optName = splitOptRange[0]; // e.g bframes\r
430 \r
431                     /* \r
432                      * Run through the available widgets for x264 opts and set them, as you add widgets,\r
433                      * they need to be added here. This should be moved to its own method probably\r
434                      * If the optNameToChange is found, appropriately change the value or delete it if\r
435                      * "unspecified" is set.\r
436                      */\r
437                     if (optName.Equals(optNameToChange))\r
438                     {\r
439                         if (optNameToChange.Equals("deblock"))\r
440                         {\r
441                             string da = drop_deblockAlpha.SelectedItem.ToString();\r
442                             string db = drop_deblockBeta.SelectedItem.ToString();\r
443 \r
444                             if (((da.Contains("Default")) && (db.Contains("Default"))) ||\r
445                                 ((da.Contains("0")) && (db.Contains("0"))))\r
446                             {\r
447                                 drop_deblockBeta.SelectedItem = "Default (0)";\r
448                                 drop_deblockAlpha.SelectedItem = "Default (0)";\r
449                                 thisOpt = string.Empty;\r
450                             }\r
451                             else if ((!da.Contains("Default")) && (db.Contains("Default")))\r
452                             {\r
453                                 drop_deblockBeta.SelectedItem = "0";\r
454                                 thisOpt = "deblock=" + da + ",0";\r
455                             }\r
456                             else if ((da.Contains("Default")) && (!db.Contains("Default")))\r
457                             {\r
458                                 drop_deblockAlpha.SelectedItem = "0";\r
459                                 thisOpt = "deblock=0," + db;\r
460                             }\r
461                             else if ((!da.Contains("Default")) && (!db.Contains("Default")))\r
462                                 thisOpt = "deblock=" + da + "," + db;\r
463                         }\r
464                         else if (optNameToChange.Equals("aq-strength"))\r
465                         {\r
466                             if (slider_adaptiveQuantStrength.Value == 10)\r
467                                 thisOpt = string.Empty;\r
468                             else\r
469                             {\r
470                                 double value = slider_adaptiveQuantStrength.Value * 0.1;\r
471                                 string aqs = value.ToString("f1");\r
472                                 thisOpt = "aq-strength=" + aqs;\r
473                             }\r
474                         }\r
475                         else if (optNameToChange.Equals("psy-rd"))\r
476                         {\r
477                             if (slider_psyrd.Value == 10 && slider_psytrellis.Value == 0)\r
478                                 thisOpt = string.Empty;\r
479                             else\r
480                             {\r
481                                 double psyrd = slider_psyrd.Value * 0.1;\r
482                                 double psytre = slider_psytrellis.Value * 0.05;\r
483 \r
484                                 string rd = psyrd.ToString("f2");\r
485                                 string rt = psytre.ToString("f2");\r
486 \r
487                                 thisOpt = "psy-rd=" + rd + "," + rt;\r
488                             }\r
489                         }\r
490                         else if (optNameToChange.Equals("b-pyramid"))\r
491                         {\r
492                             switch (combo_pyrmidalBFrames.SelectedIndex)\r
493                             {\r
494                                 case 0: // Default\r
495                                     thisOpt = string.Empty;\r
496                                     break;\r
497                                 case 1: // Off\r
498                                     thisOpt = "b-pyramid=none";\r
499                                     break;\r
500                                 case 2: // Strict\r
501                                     thisOpt = "b-pyramid=strict";\r
502                                     break;\r
503                             }\r
504                         }\r
505                         else if (optNameToChange.Equals("no-dct-decimate"))\r
506                             thisOpt = check_noDCTDecimate.CheckState == CheckState.Checked ? "no-dct-decimate=1" : string.Empty;\r
507                         else if (optNameToChange.Equals("8x8dct"))\r
508                             thisOpt = check_8x8DCT.CheckState == CheckState.Unchecked ? "8x8dct=0" : string.Empty;\r
509                         else if (optNameToChange.Equals("cabac"))\r
510                             thisOpt = check_Cabac.CheckState == CheckState.Checked ? string.Empty : "cabac=0";\r
511                         else if (optNameToChange.Equals("weightp"))\r
512                             thisOpt = check_weightp.CheckState == CheckState.Checked ? string.Empty : "weightp=0";\r
513                         else if (optNameToChange.Equals("me"))\r
514                         {\r
515                             switch (drop_MotionEstimationMethod.SelectedIndex)\r
516                             {\r
517                                 case 1:\r
518                                     thisOpt = "me=dia";\r
519                                     break;\r
520 \r
521                                 case 2:\r
522                                     thisOpt = "me=hex";\r
523                                     break;\r
524 \r
525                                 case 3:\r
526                                     thisOpt = "me=umh";\r
527                                     break;\r
528 \r
529                                 case 4:\r
530                                     thisOpt = "me=esa";\r
531                                     break;\r
532 \r
533                                 case 5:\r
534                                     thisOpt = "me=tesa";\r
535                                     break;\r
536 \r
537                                 default:\r
538                                     thisOpt = string.Empty;\r
539                                     break;\r
540                             }\r
541                         }\r
542                         else if (optNameToChange.Equals("direct"))\r
543                         {\r
544                             switch (drop_directPrediction.SelectedIndex)\r
545                             {\r
546                                 case 1:\r
547                                     thisOpt = "direct=none";\r
548                                     break;\r
549 \r
550                                 case 2:\r
551                                     thisOpt = "direct=spatial";\r
552                                     break;\r
553 \r
554                                 case 3:\r
555                                     thisOpt = "direct=temporal";\r
556                                     break;\r
557 \r
558                                 case 4:\r
559                                     thisOpt = "direct=auto";\r
560                                     break;\r
561 \r
562                                 default:\r
563                                     thisOpt = string.Empty;\r
564                                     break;\r
565                             }\r
566                         }\r
567                         else if (optNameToChange.Equals("analyse"))\r
568                         {\r
569                             switch (drop_analysis.SelectedIndex)\r
570                             {\r
571                                 case 1:\r
572                                     thisOpt = "analyse=none";\r
573                                     break;\r
574 \r
575                                 case 2:\r
576                                     thisOpt = "analyse=some";\r
577                                     break;\r
578 \r
579                                 case 3:\r
580                                     thisOpt = "analyse=all";\r
581                                     break;\r
582 \r
583                                 default:\r
584                                     thisOpt = string.Empty;\r
585                                     break;\r
586                             }\r
587                         }\r
588                         else if (optNameToChange.Equals("merange"))\r
589                         {\r
590                             thisOpt = !drop_MotionEstimationRange.SelectedItem.ToString().Contains("Default")\r
591                                           ? "merange=" + drop_MotionEstimationRange.SelectedItem\r
592                                           : string.Empty;\r
593                         }\r
594                         else if (optNameToChange.Equals("b-adapt"))\r
595                         {\r
596                             thisOpt = !drop_adaptBFrames.SelectedItem.ToString().Contains("Default")\r
597                                           ? "b-adapt=" + (drop_adaptBFrames.SelectedIndex - 1)\r
598                                           : string.Empty;\r
599                         }\r
600                         else if (optNameToChange.Equals("ref"))\r
601                         {\r
602                             thisOpt = !drop_refFrames.SelectedItem.ToString().Contains("Default")\r
603                                           ? "ref=" + drop_refFrames.SelectedItem\r
604                                           : string.Empty;\r
605                         }\r
606                         else if (optNameToChange.Equals("bframes"))\r
607                         {\r
608                             string value = drop_bFrames.SelectedItem.ToString();\r
609                             thisOpt = !drop_bFrames.SelectedItem.ToString().Contains("Default")\r
610                                           ? "bframes=" + value\r
611                                           : string.Empty;\r
612                         }\r
613                         else if (optNameToChange.Equals("subq"))\r
614                         {\r
615                             string value = drop_subpixelMotionEstimation.SelectedItem.ToString();\r
616                             string[] val = value.Split(':');\r
617                             thisOpt = !drop_subpixelMotionEstimation.SelectedItem.ToString().Contains("Default")\r
618                                           ? "subq=" + val[0]\r
619                                           : string.Empty;\r
620                         }\r
621                         else if (optNameToChange.Equals("trellis"))\r
622                         {\r
623                             switch (drop_trellis.SelectedIndex)\r
624                             {\r
625                                 case 1: // Off\r
626                                     thisOpt = "trellis=0";\r
627                                     break;\r
628                                 case 2: // Encode Only\r
629                                     thisOpt = "trellis=1";\r
630                                     break;\r
631                                 case 3: // Always\r
632                                     thisOpt = "trellis=2";\r
633                                     break;\r
634                                 default:\r
635                                     thisOpt = string.Empty;\r
636                                     break;\r
637                             }\r
638                         }\r
639                     }\r
640                 }\r
641 \r
642                 /* Construct New String for opts here */\r
643                 if (!thisOpt.Equals(string.Empty))\r
644                     changedOptString = changedOptString.Equals(string.Empty) ? thisOpt : changedOptString + ":" + thisOpt;\r
645             }\r
646 \r
647             /* Change the option string to reflect the new mod settings */\r
648             rtf_x264Query.Text = changedOptString;\r
649         }\r
650 \r
651         /// <summary>\r
652         /// Add's an option to the x264 query string.\r
653         /// Handles 2 cases.  1 Where rtf_x264Query.Text is empty, and one where there is an option with no value,\r
654         /// e.g no-fast-pskip\r
655         /// </summary>\r
656         /// <param name="optNameToChange">The Option Name to Change</param>\r
657         private void HasNoOptions(IEquatable<string> optNameToChange)\r
658         {\r
659             string colon = string.Empty;\r
660             if (rtf_x264Query.Text != string.Empty)\r
661                 colon = ":";\r
662 \r
663             string query = rtf_x264Query.Text;\r
664             if (optNameToChange.Equals("me"))\r
665             {\r
666                 switch (drop_MotionEstimationMethod.SelectedIndex)\r
667                 {\r
668                     case 1:\r
669                         query = query + colon + "me=dia";\r
670                         break;\r
671 \r
672                     case 2:\r
673                         query = query + colon + "me=hex";\r
674                         break;\r
675 \r
676                     case 3:\r
677                         query = query + colon + "me=umh";\r
678                         break;\r
679 \r
680                     case 4:\r
681                         query = query + colon + "me=esa";\r
682                         break;\r
683 \r
684                     case 5:\r
685                         query = query + colon + "me=tesa";\r
686                         break;\r
687 \r
688                     default:\r
689                         break;\r
690                 }\r
691             }\r
692             else if (optNameToChange.Equals("direct"))\r
693             {\r
694                 switch (drop_directPrediction.SelectedIndex)\r
695                 {\r
696                     case 1:\r
697                         query = query + colon + "direct=none";\r
698                         break;\r
699 \r
700                     case 2:\r
701                         query = query + colon + "direct=spatial";\r
702                         break;\r
703 \r
704                     case 3:\r
705                         query = query + colon + "direct=temporal";\r
706                         break;\r
707 \r
708                     case 4:\r
709                         query = query + colon + "direct=auto";\r
710                         break;\r
711 \r
712                     default:\r
713                         break;\r
714                 }\r
715             }\r
716             else if (optNameToChange.Equals("analyse"))\r
717             {\r
718                 switch (drop_analysis.SelectedIndex)\r
719                 {\r
720                     case 1:\r
721                         query = query + colon + "analyse=none";\r
722                         break;\r
723 \r
724                     case 2:\r
725                         query = query + colon + "analyse=some";\r
726                         break;\r
727 \r
728                     case 3:\r
729                         query = query + colon + "analyse=all";\r
730                         break;\r
731 \r
732                     default:\r
733                         break;\r
734                 }\r
735             }\r
736             else if (optNameToChange.Equals("merange"))\r
737             {\r
738                 int value = drop_MotionEstimationRange.SelectedIndex + 3;\r
739                 query = query + colon + "merange=" + value;\r
740             }\r
741             else if (optNameToChange.Equals("b-adapt"))\r
742             {\r
743                 int value = drop_adaptBFrames.SelectedIndex - 1;\r
744                 query = query + colon + "b-adapt=" + value;\r
745             }\r
746             else if (optNameToChange.Equals("deblock"))\r
747             {\r
748                 string da = drop_deblockAlpha.SelectedItem.ToString();\r
749                 string db = drop_deblockBeta.Text;\r
750 \r
751                 if (((da.Contains("Default")) && (db.Contains("Default"))) || ((da.Contains("0")) && (db.Contains("0"))))\r
752                 {\r
753                     drop_deblockBeta.SelectedItem = "Default (0)";\r
754                     drop_deblockAlpha.SelectedItem = "Default (0)";\r
755                 }\r
756                 else\r
757                 {\r
758                     if (db.Contains("Default"))\r
759                         db = "0";\r
760 \r
761                     if (da.Contains("Default"))\r
762                         da = "0";\r
763 \r
764                     query = query + colon + "deblock=" + da + "," + db;\r
765                 }\r
766             }\r
767             else if (optNameToChange.Equals("aq-strength"))\r
768             {\r
769                 if (slider_adaptiveQuantStrength.Value == 10)\r
770                     query = string.Empty;\r
771                 else\r
772                 {\r
773                     double value = slider_adaptiveQuantStrength.Value * 0.1;\r
774                     string aqs = value.ToString("f1");\r
775                     query += colon + "aq-strength=" + aqs;\r
776                 }\r
777             }\r
778             else if (optNameToChange.Equals("psy-rd"))\r
779             {\r
780                 if (slider_psyrd.Value == 10 && slider_psytrellis.Value == 0)\r
781                     query += string.Empty;\r
782                 else\r
783                 {\r
784                     double psyrd = slider_psyrd.Value * 0.1;\r
785                     double psytre = slider_psytrellis.Value * 0.05;\r
786 \r
787                     string rd = psyrd.ToString("f1");\r
788                     string rt = psytre.ToString("f2");\r
789 \r
790                     query += colon + "psy-rd=" + rd + "," + rt;\r
791                 }\r
792             }\r
793             else if (optNameToChange.Equals("b-pyramid"))\r
794             {\r
795                 switch (combo_pyrmidalBFrames.SelectedIndex)\r
796                 {\r
797                     case 0:\r
798                         break;\r
799                     case 1:\r
800                         query = query + colon + "b-pyramid=none";\r
801                         break;\r
802                     case 2:\r
803                         query = query + colon + "b-pyramid=strict";\r
804                         break;\r
805                 }\r
806             }\r
807             else if (optNameToChange.Equals("no-dct-decimate"))\r
808             {\r
809                 if (check_noDCTDecimate.CheckState == CheckState.Checked)\r
810                     query = query + colon + "no-dct-decimate=1";\r
811             }\r
812             else if (optNameToChange.Equals("8x8dct"))\r
813             {\r
814                 if (check_8x8DCT.CheckState == CheckState.Unchecked)\r
815                     query = query + colon + "8x8dct=0";\r
816             }\r
817             else if (optNameToChange.Equals("cabac"))\r
818             {\r
819                 if (check_Cabac.CheckState != CheckState.Checked)\r
820                     query = query + colon + "cabac=0";\r
821             }\r
822             else if (optNameToChange.Equals("weightp"))\r
823             {\r
824                 if (check_weightp.CheckState == CheckState.Unchecked)\r
825                     query = query + colon + "weightp=0";\r
826             }\r
827             else if (optNameToChange.Equals("ref"))\r
828             {\r
829                 if (!drop_refFrames.SelectedItem.ToString().Contains("Default"))\r
830                     query = query + colon + "ref=" + drop_refFrames.SelectedItem;\r
831             }\r
832             else if (optNameToChange.Equals("bframes"))\r
833             {\r
834                 string value = drop_bFrames.SelectedItem.ToString();\r
835                 if (!drop_bFrames.SelectedItem.ToString().Contains("Default"))\r
836                     query = query + colon + "bframes=" + value;\r
837             }\r
838             else if (optNameToChange.Equals("subq"))\r
839             {\r
840                 string value = drop_subpixelMotionEstimation.SelectedItem.ToString();\r
841                 if (!drop_subpixelMotionEstimation.SelectedItem.ToString().Contains("Default"))\r
842                 {\r
843                     string[] val = value.Split(':');\r
844                     query = query + colon + "subq=" + val[0];\r
845                 }\r
846             }\r
847             else if (optNameToChange.Equals("trellis"))\r
848             {\r
849                 switch (drop_trellis.SelectedIndex)\r
850                 {\r
851                     case 1: // Off\r
852                         query = query + colon + "trellis=0";\r
853                         break;\r
854                     case 2: // Encode Only\r
855                         query = query + colon + "trellis=1";\r
856                         break;\r
857                     case 3: // Always\r
858                         query = query + colon + "trellis=2";\r
859                         break;\r
860                     default:\r
861                         break;\r
862                 }\r
863             }\r
864 \r
865             rtf_x264Query.Text = query;\r
866         }\r
867 \r
868         /// <summary>\r
869         /// Shows and hides controls based on the values of other controls.\r
870         /// </summary>\r
871         /// <param name="sender">The Sender</param>\r
872         private void Animate(string sender)\r
873         {\r
874             /* Lots of situations to cover.\r
875                - B-frames (when 0 turn of b-frame specific stuff, when < 2 disable b-pyramid)\r
876                - CABAC (when 0 turn off trellis and psy-trel\r
877                - subme (if under 6, turn off psy-rd and psy-trel)\r
878                - trellis (if 0, turn off psy-trel)\r
879              */\r
880 \r
881             switch (sender)\r
882             {\r
883                 case "bframes":\r
884                     if (drop_bFrames.SelectedIndex == 1)\r
885                     {\r
886                         /* If the b-frame widget is at 1, the user has chosen\r
887                            not to use b-frames at all. So disable the options\r
888                            that can only be used when b-frames are enabled.        */\r
889                         combo_pyrmidalBFrames.Visible = false;\r
890                         lbl_prymidalBframes.Visible = false;\r
891                         drop_directPrediction.Visible = false;\r
892                         lbl_direct_prediction.Visible = false;\r
893 \r
894                         combo_pyrmidalBFrames.SelectedIndex = 0;\r
895                         drop_directPrediction.SelectedIndex = 0;\r
896 \r
897                         drop_adaptBFrames.Visible = false;\r
898                         lbl_adaptBFrames.Visible = false;\r
899                         drop_adaptBFrames.SelectedIndex = 0;\r
900                     }\r
901                     else if (drop_bFrames.SelectedIndex == 2)\r
902                     {\r
903                         /* Only 1 b-frame? Disable b-pyramid. */\r
904                         combo_pyrmidalBFrames.Visible = false;\r
905                         lbl_prymidalBframes.Visible = false;\r
906                         combo_pyrmidalBFrames.SelectedIndex = 0;\r
907 \r
908                         drop_directPrediction.Visible = true;\r
909                         lbl_direct_prediction.Visible = true;\r
910 \r
911                         drop_adaptBFrames.Visible = true;\r
912                         lbl_adaptBFrames.Visible = true;\r
913                     }\r
914                     else\r
915                     {\r
916                         combo_pyrmidalBFrames.Visible = true;\r
917                         lbl_prymidalBframes.Visible = true;\r
918                         drop_directPrediction.Visible = true;\r
919                         lbl_direct_prediction.Visible = true;\r
920 \r
921                         drop_adaptBFrames.Visible = true;\r
922                         lbl_adaptBFrames.Visible = true;\r
923                     }\r
924                     break;\r
925                 case "cabac":\r
926                     if (check_Cabac.Checked == false)\r
927                     {\r
928                         /* Without CABAC entropy coding, trellis doesn't run. */\r
929                         drop_trellis.Visible = false;\r
930                         drop_trellis.SelectedIndex = 0;\r
931                         lbl_trellis.Visible = false;\r
932 \r
933                         slider_psytrellis.Visible = false;\r
934                         lbl_psytrellis.Visible = false;\r
935                         slider_psytrellis.Value = 0;\r
936                     }\r
937                     else\r
938                     {\r
939                         drop_trellis.Visible = true;\r
940                         lbl_trellis.Visible = true;\r
941 \r
942                         slider_psytrellis.Visible = true;\r
943                         lbl_psytrellis.Visible = true;\r
944                     }\r
945                     break;\r
946                 case "me": // Motion Estimation\r
947                     if (drop_MotionEstimationMethod.SelectedIndex < 3)\r
948                     {\r
949                         drop_MotionEstimationRange.Visible = false;\r
950                         lbl_merange.Visible = false;\r
951                         drop_MotionEstimationRange.SelectedIndex = 0;\r
952                     }\r
953                     else\r
954                     {\r
955                         drop_MotionEstimationRange.Visible = true;\r
956                         lbl_merange.Visible = true;\r
957                     }\r
958                     break;\r
959                 case "subq": // subme\r
960                     if (drop_subpixelMotionEstimation.SelectedIndex != 0 &&\r
961                         drop_subpixelMotionEstimation.SelectedIndex < 7)\r
962                     {\r
963                         slider_psyrd.Visible = false;\r
964                         slider_psyrd.Value = 10;\r
965                         lbl_psyrd.Visible = false;\r
966 \r
967                         slider_psytrellis.Visible = false;\r
968                         slider_psytrellis.Value = 0;\r
969                         lbl_psytrellis.Visible = false;\r
970                     }\r
971                     else\r
972                     {\r
973                         slider_psyrd.Visible = true;\r
974                         lbl_psyrd.Visible = true;\r
975 \r
976                         if (drop_trellis.SelectedIndex >= 2 && check_Cabac.Checked && slider_psytrellis.Visible == false)\r
977                         {\r
978                             slider_psytrellis.Visible = true;\r
979                             lbl_psytrellis.Visible = true;\r
980                         }\r
981                     }\r
982                     break;\r
983                 case "trellis": // subme\r
984                     if (drop_trellis.SelectedIndex > 0 && drop_trellis.SelectedIndex < 2)\r
985                     {\r
986                         slider_psytrellis.Visible = false;\r
987                         slider_psytrellis.Value = 0;\r
988                         lbl_psytrellis.Visible = false;\r
989                     }\r
990                     else\r
991                     {\r
992                         if ((drop_subpixelMotionEstimation.SelectedIndex == 0 ||\r
993                              drop_subpixelMotionEstimation.SelectedIndex >= 7) && check_Cabac.Checked &&\r
994                             slider_psytrellis.Visible == false)\r
995                         {\r
996                             slider_psytrellis.Visible = true;\r
997                             lbl_psytrellis.Visible = true;\r
998                         }\r
999                     }\r
1000                     break;\r
1001             }\r
1002         }\r
1003 \r
1004         /* UI Events */\r
1005 \r
1006         private void widgetControlChanged(object sender, EventArgs e)\r
1007         {\r
1008             Control changedControlName = (Control)sender;\r
1009             string controlName = string.Empty;\r
1010 \r
1011             switch (changedControlName.Name.Trim())\r
1012             {\r
1013                 case "drop_refFrames":\r
1014                     controlName = "ref";\r
1015                     break;\r
1016                 case "drop_bFrames":\r
1017                     controlName = "bframes";\r
1018                     break;\r
1019                 case "drop_directPrediction":\r
1020                     controlName = "direct";\r
1021                     break;\r
1022                 case "check_weightp":\r
1023                     controlName = "weightp";\r
1024                     break;\r
1025                 case "combo_pyrmidalBFrames":\r
1026                     controlName = "b-pyramid";\r
1027                     break;\r
1028                 case "drop_MotionEstimationMethod":\r
1029                     controlName = "me";\r
1030                     break;\r
1031                 case "drop_MotionEstimationRange":\r
1032                     controlName = "merange";\r
1033                     break;\r
1034                 case "drop_subpixelMotionEstimation":\r
1035                     controlName = "subq";\r
1036                     break;\r
1037                 case "drop_analysis":\r
1038                     controlName = "analyse";\r
1039                     break;\r
1040                 case "check_8x8DCT":\r
1041                     controlName = "8x8dct";\r
1042                     break;\r
1043                 case "drop_deblockAlpha":\r
1044                     controlName = "deblock";\r
1045                     break;\r
1046                 case "drop_deblockBeta":\r
1047                     controlName = "deblock";\r
1048                     break;\r
1049                 case "drop_trellis":\r
1050                     controlName = "trellis";\r
1051                     break;\r
1052                 case "check_noDCTDecimate":\r
1053                     controlName = "no-dct-decimate";\r
1054                     break;\r
1055                 case "check_Cabac":\r
1056                     controlName = "cabac";\r
1057                     break;\r
1058                 case "slider_psyrd":\r
1059                     controlName = "psy-rd";\r
1060                     break;\r
1061                 case "slider_psytrellis":\r
1062                     controlName = "psy-rd";\r
1063                     break;\r
1064                 case "slider_adaptiveQuantStrength":\r
1065                     controlName = "aq-strength";\r
1066                     break;\r
1067                 case "drop_adaptBFrames":\r
1068                     controlName = "b-adapt";\r
1069                     break;\r
1070             }\r
1071             OnX264WidgetChange(controlName);\r
1072         }\r
1073 \r
1074         private void rtf_x264Query_TextChanged(object sender, EventArgs e)\r
1075         {\r
1076             if (rtf_x264Query.Text.EndsWith("\n"))\r
1077             {\r
1078                 string query = rtf_x264Query.Text.Replace("\n", string.Empty);\r
1079                 Reset2Defaults();\r
1080                 rtf_x264Query.Text = query;\r
1081                 this.StandardizeOptString();\r
1082                 this.SetCurrentSettingsInPanel();\r
1083 \r
1084                 if (rtf_x264Query.Text == string.Empty)\r
1085                     Reset2Defaults();\r
1086             }\r
1087         }\r
1088 \r
1089         private void btn_reset_Click(object sender, EventArgs e)\r
1090         {\r
1091             rtf_x264Query.Text = string.Empty;\r
1092             Reset2Defaults();\r
1093         }\r
1094     }\r
1095 }