OSDN Git Service

WinGui:
[handbrake-jp/handbrake-jp-git.git] / win / C# / Functions / PresetLoader.cs
1 /*  PresetLoader.cs $\r
2         \r
3            This file is part of the HandBrake source code.\r
4            Homepage: <http://handbrake.fr>.\r
5            It may be used under the terms of the GNU General Public License. */\r
6 \r
7 using System;\r
8 using System.Windows.Forms;\r
9 \r
10 namespace Handbrake.Functions\r
11 {\r
12     class PresetLoader\r
13     {\r
14         /// <summary>\r
15         /// This function takes in a Query which has been parsed by QueryParser and\r
16         /// set's all the GUI widgets correctly.\r
17         /// </summary>\r
18         /// <param name="mainWindow"></param>\r
19         /// <param name="presetQuery">The Parsed CLI Query</param>\r
20         /// <param name="name">Name of the preset</param>\r
21         /// <param name="pictureSettings">Save picture settings in the preset</param>\r
22         public static void presetLoader(frmMain mainWindow, QueryParser presetQuery, string name, Boolean pictureSettings)\r
23         {\r
24             // ---------------------------\r
25             // Setup the GUI\r
26             // ---------------------------\r
27 \r
28             #region Source\r
29             // Reset some vaules to stock first to prevent errors.\r
30             mainWindow.check_iPodAtom.CheckState = CheckState.Unchecked;\r
31 \r
32             // Now load all the new settings onto the main window\r
33             if (presetQuery.Format != null)\r
34             {\r
35                 string destination = mainWindow.text_destination.Text;\r
36                 destination = destination.Replace(".mp4", "." + presetQuery.Format);\r
37                 destination = destination.Replace(".m4v", "." + presetQuery.Format);\r
38                 destination = destination.Replace(".mkv", "." + presetQuery.Format);\r
39                 mainWindow.text_destination.Text = destination;\r
40             }\r
41 \r
42             #endregion\r
43 \r
44             #region Destination and Output Settings\r
45 \r
46             if (presetQuery.Format != null)\r
47             {\r
48                 if (presetQuery.Format == "mp4")\r
49                     mainWindow.drop_format.SelectedIndex = 0;\r
50                 else if (presetQuery.Format == "m4v")\r
51                     mainWindow.drop_format.SelectedIndex = 1;\r
52                 else if (presetQuery.Format == "mkv")\r
53                     mainWindow.drop_format.SelectedIndex = 2;\r
54 \r
55                 if (presetQuery.ChapterMarkers && presetQuery.Format == "mp4")\r
56                     mainWindow.drop_format.SelectedIndex = 1;\r
57             }\r
58 \r
59             mainWindow.check_iPodAtom.CheckState = presetQuery.IpodAtom ? CheckState.Checked : CheckState.Unchecked;\r
60 \r
61             mainWindow.check_optimiseMP4.CheckState = presetQuery.OptimizeMP4 ? CheckState.Checked : CheckState.Unchecked;\r
62 \r
63             mainWindow.check_largeFile.CheckState = presetQuery.LargeMP4 ? CheckState.Checked : CheckState.Unchecked;\r
64 \r
65             mainWindow.setContainerOpts(); // select the container options according to the selected format\r
66 \r
67             #endregion\r
68 \r
69             #region Picture\r
70             mainWindow.pictureSettings.check_autoCrop.Checked = true;\r
71             if (presetQuery.CropBottom == "0" && presetQuery.CropTop == "0")\r
72                 if (presetQuery.CropLeft == "0" && presetQuery.CropRight == "0")\r
73                     mainWindow.pictureSettings.check_customCrop.Checked = true;\r
74 \r
75             mainWindow.pictureSettings.text_width.Text = "";\r
76             mainWindow.pictureSettings.text_height.Text = "";\r
77 \r
78             if (pictureSettings)\r
79             {\r
80                 if (presetQuery.CropTop != null)\r
81                 {\r
82                     int top, bottom, left, right;\r
83                     int.TryParse(presetQuery.CropTop, out top);\r
84                     int.TryParse(presetQuery.CropBottom, out bottom);\r
85                     int.TryParse(presetQuery.CropLeft, out left);\r
86                     int.TryParse(presetQuery.CropRight, out right);\r
87 \r
88                     mainWindow.pictureSettings.check_customCrop.Checked = true;\r
89                     mainWindow.pictureSettings.crop_top.Value = top;\r
90                     mainWindow.pictureSettings.crop_bottom.Value = bottom;\r
91                     mainWindow.pictureSettings.crop_left.Value = left;\r
92                     mainWindow.pictureSettings.crop_right.Value = right;\r
93                 }\r
94 \r
95                 if (presetQuery.Width != 0)\r
96                     mainWindow.pictureSettings.text_width.Text = presetQuery.Width.ToString();\r
97 \r
98                 if (presetQuery.Height != 0)\r
99                     mainWindow.pictureSettings.text_height.Text = presetQuery.Height.ToString();\r
100             }\r
101 \r
102             // Set the anamorphic mode 0,1,2,3\r
103             mainWindow.pictureSettings.drp_anamorphic.SelectedIndex = presetQuery.AnamorphicMode;\r
104 \r
105 \r
106             // Custom Anamorphic Controls\r
107             mainWindow.pictureSettings.check_KeepAR.CheckState = presetQuery.keepDisplayAsect ? CheckState.Checked : CheckState.Unchecked;\r
108 \r
109             mainWindow.pictureSettings.txt_displayWidth.Text = presetQuery.displayWidthValue.ToString();\r
110             mainWindow.pictureSettings.txt_parWidth.Text = presetQuery.pixelAspectWidth.ToString();\r
111             mainWindow.pictureSettings.txt_parHeight.Text = presetQuery.pixelAspectHeight.ToString();\r
112             mainWindow.pictureSettings.drop_modulus.SelectedItem = presetQuery.AnamorphicModulus;\r
113 \r
114  \r
115             // Set the public max width and max height varibles in frmMain\r
116             // These are used by the query generator to determine if it should use -X or -w  / -Y or -h\r
117             if (presetQuery.MaxWidth != 0)\r
118             {\r
119                 mainWindow.pictureSettings.text_width.Text = presetQuery.MaxWidth.ToString();\r
120                 mainWindow.maxWidth = presetQuery.MaxWidth;\r
121             }\r
122 \r
123             if (presetQuery.MaxHeight != 0)\r
124             {\r
125                 mainWindow.pictureSettings.text_height.Text = presetQuery.MaxHeight.ToString();\r
126                 mainWindow.maxHeight = presetQuery.MaxHeight;\r
127             }\r
128 \r
129 \r
130             #endregion\r
131 \r
132             #region Filters\r
133 \r
134             mainWindow.ctl_decomb.setOption(presetQuery.Decomb);\r
135 \r
136             if (mainWindow.ctl_decomb.getDropValue == "Off")\r
137                 mainWindow.ctl_deinterlace.setOption(presetQuery.DeInterlace);\r
138             else\r
139                 mainWindow.ctl_deinterlace.setOption("None"); // Don't want decomb and deinterlace on at the same time\r
140 \r
141             mainWindow.ctl_denoise.setOption(presetQuery.DeNoise);\r
142             mainWindow.ctl_detelecine.setOption(presetQuery.DeTelecine);\r
143 \r
144             if (presetQuery.DeBlock != 0)\r
145             {\r
146                 mainWindow.slider_deblock.Value = presetQuery.DeBlock;\r
147                 mainWindow.lbl_deblockVal.Text = presetQuery.DeBlock.ToString();\r
148             }\r
149             else\r
150             {\r
151                 mainWindow.slider_deblock.Value = 4;\r
152                 mainWindow.lbl_deblockVal.Text = "Off";\r
153             }\r
154             #endregion\r
155 \r
156             #region Video\r
157             mainWindow.drp_videoEncoder.Text = presetQuery.VideoEncoder;\r
158 \r
159             if (presetQuery.AverageVideoBitrate != null)\r
160             {\r
161                 mainWindow.radio_avgBitrate.Checked = true;\r
162                 mainWindow.text_bitrate.Text = presetQuery.AverageVideoBitrate;\r
163             }\r
164             if (presetQuery.VideoTargetSize != null)\r
165             {\r
166                 mainWindow.radio_targetFilesize.Checked = true;\r
167                 mainWindow.text_filesize.Text = presetQuery.VideoTargetSize;\r
168             }\r
169 \r
170             // Quality\r
171             if (presetQuery.VideoQuality != 0)\r
172             {\r
173                 mainWindow.radio_cq.Checked = true;\r
174                 if (presetQuery.VideoEncoder == "H.264 (x264)")\r
175                 {\r
176                     int value;\r
177                     System.Globalization.CultureInfo culture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");\r
178 \r
179                     double x264step;\r
180                     double presetValue = presetQuery.VideoQuality;\r
181                     double.TryParse(Properties.Settings.Default.x264cqstep,\r
182                                     System.Globalization.NumberStyles.Number,\r
183                                     culture,\r
184                                     out x264step);\r
185 \r
186                     double x = 51 / x264step;\r
187 \r
188                     double calculated = presetValue / x264step;\r
189                     calculated = x - calculated;\r
190 \r
191                     int.TryParse(calculated.ToString(), out value);\r
192 \r
193                     // This will sometimes occur when the preset was generated \r
194                     // with a different granularity, so, round and try again.\r
195                     if (value == 0)\r
196                     {\r
197                         double val = Math.Round(calculated, 0);\r
198                         int.TryParse(val.ToString(), out value);\r
199                     }\r
200 \r
201                     mainWindow.slider_videoQuality.Value = value;\r
202                 }\r
203                 else\r
204                 {\r
205                     int presetVal;\r
206                     int.TryParse(presetQuery.VideoQuality.ToString(), out presetVal);\r
207                     mainWindow.slider_videoQuality.Value = presetVal;\r
208                 }\r
209             }\r
210 \r
211             mainWindow.check_2PassEncode.CheckState = presetQuery.TwoPass ? CheckState.Checked : CheckState.Unchecked;\r
212 \r
213             mainWindow.check_grayscale.CheckState = presetQuery.Grayscale ? CheckState.Checked : CheckState.Unchecked;\r
214 \r
215             mainWindow.drp_videoFramerate.Text = presetQuery.VideoFramerate;\r
216 \r
217             mainWindow.check_turbo.CheckState = presetQuery.TurboFirstPass ? CheckState.Checked : CheckState.Unchecked;\r
218 \r
219             #endregion\r
220 \r
221             #region Chapter Markers\r
222 \r
223             if (presetQuery.ChapterMarkers)\r
224             {\r
225                 mainWindow.Check_ChapterMarkers.CheckState = CheckState.Checked;\r
226                 mainWindow.Check_ChapterMarkers.Enabled = true;\r
227             }\r
228             else\r
229                 mainWindow.Check_ChapterMarkers.CheckState = CheckState.Unchecked;\r
230 \r
231             #endregion\r
232 \r
233             #region Audio\r
234             // Clear the audio listing\r
235             mainWindow.audioPanel.clearAudioList();\r
236 \r
237             if (presetQuery.AudioInformation != null)\r
238                 foreach (AudioTrack track in presetQuery.AudioInformation)\r
239                 {\r
240                     ListViewItem newTrack = new ListViewItem(mainWindow.audioPanel.getNewID().ToString());\r
241 \r
242                     newTrack.SubItems.Add("Automatic");\r
243                     newTrack.SubItems.Add(track.Encoder);\r
244                     newTrack.SubItems.Add(track.MixDown);\r
245                     newTrack.SubItems.Add(track.SampleRate);\r
246                     newTrack.SubItems.Add(track.Bitrate);\r
247                     newTrack.SubItems.Add(track.DRC);\r
248                     mainWindow.audioPanel.addTrackForPreset(newTrack);\r
249                 }\r
250 \r
251             // Subtitle Stuff\r
252             mainWindow.drp_subtitle.Text = presetQuery.Subtitles;\r
253 \r
254             if (presetQuery.ForcedSubtitles)\r
255             {\r
256                 mainWindow.check_forced.CheckState = CheckState.Checked;\r
257                 mainWindow.check_forced.Enabled = true;\r
258             }\r
259             else\r
260                 mainWindow.check_forced.CheckState = CheckState.Unchecked;\r
261 \r
262             #endregion\r
263 \r
264             #region Other\r
265             mainWindow.x264Panel.x264Query = presetQuery.H264Query;\r
266 \r
267             // Set the preset name\r
268             mainWindow.groupBox_output.Text = "Output Settings (Preset: " + name + ")";\r
269             #endregion\r
270         }\r
271     }\r
272 }