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             if (pictureSettings)\r
76             {\r
77                 if (presetQuery.CropTop != null)\r
78                 {\r
79                     int top, bottom, left, right;\r
80                     int.TryParse(presetQuery.CropTop, out top);\r
81                     int.TryParse(presetQuery.CropBottom, out bottom);\r
82                     int.TryParse(presetQuery.CropLeft, out left);\r
83                     int.TryParse(presetQuery.CropRight, out right);\r
84 \r
85                     mainWindow.pictureSettings.check_customCrop.Checked = true;\r
86                     mainWindow.pictureSettings.crop_top.Value = top;\r
87                     mainWindow.pictureSettings.crop_bottom.Value = bottom;\r
88                     mainWindow.pictureSettings.crop_left.Value = left;\r
89                     mainWindow.pictureSettings.crop_right.Value = right;\r
90                 }\r
91 \r
92                 if (presetQuery.Width != 0)\r
93                     mainWindow.pictureSettings.text_width.Text = presetQuery.Width.ToString();\r
94 \r
95                 if (presetQuery.Height != 0)\r
96                     mainWindow.pictureSettings.text_height.Text = presetQuery.Height.ToString();\r
97             }\r
98 \r
99             // Set the anamorphic mode 0,1,2,3\r
100             mainWindow.pictureSettings.drp_anamorphic.SelectedIndex = presetQuery.AnamorphicMode;\r
101 \r
102 \r
103             // Custom Anamorphic Controls\r
104             mainWindow.pictureSettings.check_KeepAR.CheckState = presetQuery.keepDisplayAsect ? CheckState.Checked : CheckState.Unchecked;\r
105 \r
106             mainWindow.pictureSettings.txt_displayWidth.Text = presetQuery.displayWidthValue.ToString();\r
107             mainWindow.pictureSettings.txt_parWidth.Text = presetQuery.pixelAspectWidth.ToString();\r
108             mainWindow.pictureSettings.txt_parHeight.Text = presetQuery.pixelAspectHeight.ToString();\r
109             mainWindow.pictureSettings.drop_modulus.SelectedItem = presetQuery.AnamorphicModulus;\r
110 \r
111  \r
112             // Set the public max width and max height varibles in frmMain\r
113             // These are used by the query generator to determine if it should use -X or -w  / -Y or -h\r
114             if (presetQuery.MaxWidth != 0)\r
115             {\r
116                 mainWindow.pictureSettings.text_width.Text = presetQuery.MaxWidth.ToString();\r
117                 mainWindow.maxWidth = presetQuery.MaxWidth;\r
118             }\r
119 \r
120             if (presetQuery.MaxHeight != 0)\r
121             {\r
122                 mainWindow.pictureSettings.text_height.Text = presetQuery.MaxHeight.ToString();\r
123                 mainWindow.maxHeight = presetQuery.MaxHeight;\r
124             }\r
125 \r
126 \r
127             #endregion\r
128 \r
129             #region Filters\r
130 \r
131             mainWindow.ctl_decomb.setOption(presetQuery.Decomb);\r
132 \r
133             if (mainWindow.ctl_decomb.getDropValue == "Off")\r
134                 mainWindow.ctl_deinterlace.setOption(presetQuery.DeInterlace);\r
135             else\r
136                 mainWindow.ctl_deinterlace.setOption("None"); // Don't want decomb and deinterlace on at the same time\r
137 \r
138             mainWindow.ctl_denoise.setOption(presetQuery.DeNoise);\r
139             mainWindow.ctl_detelecine.setOption(presetQuery.DeTelecine);\r
140 \r
141             if (presetQuery.DeBlock != 0)\r
142             {\r
143                 mainWindow.slider_deblock.Value = presetQuery.DeBlock;\r
144                 mainWindow.lbl_deblockVal.Text = presetQuery.DeBlock.ToString();\r
145             }\r
146             else\r
147             {\r
148                 mainWindow.slider_deblock.Value = 4;\r
149                 mainWindow.lbl_deblockVal.Text = "Off";\r
150             }\r
151             #endregion\r
152 \r
153             #region Video\r
154             mainWindow.drp_videoEncoder.Text = presetQuery.VideoEncoder;\r
155 \r
156             if (presetQuery.AverageVideoBitrate != null)\r
157             {\r
158                 mainWindow.radio_avgBitrate.Checked = true;\r
159                 mainWindow.text_bitrate.Text = presetQuery.AverageVideoBitrate;\r
160             }\r
161             if (presetQuery.VideoTargetSize != null)\r
162             {\r
163                 mainWindow.radio_targetFilesize.Checked = true;\r
164                 mainWindow.text_filesize.Text = presetQuery.VideoTargetSize;\r
165             }\r
166 \r
167             // Quality\r
168             if (presetQuery.VideoQuality != 0)\r
169             {\r
170                 mainWindow.radio_cq.Checked = true;\r
171                 if (presetQuery.VideoEncoder == "H.264 (x264)")\r
172                 {\r
173                     int value;\r
174                     System.Globalization.CultureInfo culture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");\r
175 \r
176                     double x264step;\r
177                     double presetValue = presetQuery.VideoQuality;\r
178                     double.TryParse(Properties.Settings.Default.x264cqstep,\r
179                                     System.Globalization.NumberStyles.Number,\r
180                                     culture,\r
181                                     out x264step);\r
182 \r
183                     double x = 51 / x264step;\r
184 \r
185                     double calculated = presetValue / x264step;\r
186                     calculated = x - calculated;\r
187 \r
188                     int.TryParse(calculated.ToString(), out value);\r
189 \r
190                     // This will sometimes occur when the preset was generated \r
191                     // with a different granularity, so, round and try again.\r
192                     if (value == 0)\r
193                     {\r
194                         double val = Math.Round(calculated, 0);\r
195                         int.TryParse(val.ToString(), out value);\r
196                     }\r
197 \r
198                     mainWindow.slider_videoQuality.Value = value;\r
199                 }\r
200                 else\r
201                 {\r
202                     int presetVal;\r
203                     int.TryParse(presetQuery.VideoQuality.ToString(), out presetVal);\r
204                     mainWindow.slider_videoQuality.Value = presetVal;\r
205                 }\r
206             }\r
207 \r
208             mainWindow.check_2PassEncode.CheckState = presetQuery.TwoPass ? CheckState.Checked : CheckState.Unchecked;\r
209 \r
210             mainWindow.check_grayscale.CheckState = presetQuery.Grayscale ? CheckState.Checked : CheckState.Unchecked;\r
211 \r
212             mainWindow.drp_videoFramerate.Text = presetQuery.VideoFramerate;\r
213 \r
214             mainWindow.check_turbo.CheckState = presetQuery.TurboFirstPass ? CheckState.Checked : CheckState.Unchecked;\r
215 \r
216             #endregion\r
217 \r
218             #region Chapter Markers\r
219 \r
220             if (presetQuery.ChapterMarkers)\r
221             {\r
222                 mainWindow.Check_ChapterMarkers.CheckState = CheckState.Checked;\r
223                 mainWindow.Check_ChapterMarkers.Enabled = true;\r
224             }\r
225             else\r
226                 mainWindow.Check_ChapterMarkers.CheckState = CheckState.Unchecked;\r
227 \r
228             #endregion\r
229 \r
230             #region Audio\r
231             // Clear the audio listing\r
232             mainWindow.audioPanel.clearAudioList();\r
233 \r
234             if (presetQuery.AudioInformation != null)\r
235                 foreach (AudioTrack track in presetQuery.AudioInformation)\r
236                 {\r
237                     ListViewItem newTrack = new ListViewItem(mainWindow.audioPanel.getNewID().ToString());\r
238 \r
239                     newTrack.SubItems.Add("Automatic");\r
240                     newTrack.SubItems.Add(track.Encoder);\r
241                     newTrack.SubItems.Add(track.MixDown);\r
242                     newTrack.SubItems.Add(track.SampleRate);\r
243                     newTrack.SubItems.Add(track.Bitrate);\r
244                     newTrack.SubItems.Add(track.DRC);\r
245                     mainWindow.audioPanel.addTrackForPreset(newTrack);\r
246                 }\r
247 \r
248             // Subtitle Stuff\r
249             mainWindow.drp_subtitle.Text = presetQuery.Subtitles;\r
250 \r
251             if (presetQuery.ForcedSubtitles)\r
252             {\r
253                 mainWindow.check_forced.CheckState = CheckState.Checked;\r
254                 mainWindow.check_forced.Enabled = true;\r
255             }\r
256             else\r
257                 mainWindow.check_forced.CheckState = CheckState.Unchecked;\r
258 \r
259             #endregion\r
260 \r
261             #region Other\r
262             mainWindow.x264Panel.x264Query = presetQuery.H264Query;\r
263 \r
264             // Set the preset name\r
265             mainWindow.groupBox_output.Text = "Output Settings (Preset: " + name + ")";\r
266             #endregion\r
267         }\r
268     }\r
269 }