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