2 using System.Windows.Forms;
\r
3 using System.Drawing;
\r
5 namespace Handbrake.Functions
\r
10 /// This function takes in a Query which has been parsed by QueryParser and
\r
11 /// set's all the GUI widgets correctly.
\r
13 /// <param name="mainWindow"></param>
\r
14 /// <param name="presetQuery">The Parsed CLI Query</param>
\r
15 /// <param name="name">Name of the preset</param>
\r
16 /// <param name="pictureSettings">Save picture settings in the preset</param>
\r
17 public static void presetLoader(frmMain mainWindow, QueryParser presetQuery, string name, Boolean pictureSettings)
\r
19 // ---------------------------
\r
21 // ---------------------------
\r
24 // Reset some vaules to stock first to prevent errors.
\r
25 mainWindow.check_iPodAtom.CheckState = CheckState.Unchecked;
\r
27 // Now load all the new settings onto the main window
\r
28 if (presetQuery.Format != null)
\r
30 string destination = mainWindow.text_destination.Text;
\r
31 destination = destination.Replace(".mp4", "." + presetQuery.Format);
\r
32 destination = destination.Replace(".m4v", "." + presetQuery.Format);
\r
33 destination = destination.Replace(".mkv", "." + presetQuery.Format);
\r
34 mainWindow.text_destination.Text = destination;
\r
41 mainWindow.drp_videoEncoder.Text = presetQuery.VideoEncoder;
\r
43 if (presetQuery.Format != null)
\r
45 if (presetQuery.Format == "mp4")
\r
46 mainWindow.drop_format.SelectedIndex = 0;
\r
47 else if (presetQuery.Format == "m4v")
\r
48 mainWindow.drop_format.SelectedIndex = 1;
\r
49 else if (presetQuery.Format == "mkv")
\r
50 mainWindow.drop_format.SelectedIndex = 2;
\r
52 if (presetQuery.ChapterMarkers && presetQuery.Format == "mp4")
\r
53 mainWindow.drop_format.SelectedIndex = 1;
\r
56 mainWindow.check_iPodAtom.CheckState = presetQuery.IpodAtom ? CheckState.Checked : CheckState.Unchecked;
\r
58 mainWindow.check_optimiseMP4.CheckState = presetQuery.OptimizeMP4 ? CheckState.Checked : CheckState.Unchecked;
\r
60 mainWindow.check_largeFile.CheckState = presetQuery.LargeMP4 ? CheckState.Checked : CheckState.Unchecked;
\r
62 mainWindow.setContainerOpts(); // select the container options according to the selected format
\r
67 mainWindow.check_autoCrop.Checked = true;
\r
68 if (presetQuery.CropBottom == "0" && presetQuery.CropTop == "0")
\r
69 if (presetQuery.CropLeft == "0" && presetQuery.CropRight == "0")
\r
70 mainWindow.check_customCrop.Checked = true;
\r
72 mainWindow.text_width.Text = "";
\r
73 mainWindow.text_height.Text = "";
\r
75 if (pictureSettings)
\r
77 if (presetQuery.CropTop != null)
\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
85 mainWindow.check_customCrop.Checked = true;
\r
86 mainWindow.text_top.Value = top;
\r
87 mainWindow.text_bottom.Value = bottom;
\r
88 mainWindow.text_left.Value = left;
\r
89 mainWindow.text_right.Value = right;
\r
92 if (presetQuery.Width != 0)
\r
93 mainWindow.text_width.Text = presetQuery.Width.ToString();
\r
95 if (presetQuery.Height != 0)
\r
96 mainWindow.text_height.Text = presetQuery.Height.ToString();
\r
99 mainWindow.drp_anamorphic.SelectedIndex = presetQuery.Anamorphic ? 1 : 0;
\r
101 if (presetQuery.LooseAnamorphic)
\r
102 mainWindow.drp_anamorphic.SelectedIndex = 2;
\r
105 if (presetQuery.Anamorphic != true)
\r
106 mainWindow.drp_anamorphic.SelectedIndex = 0;
\r
109 // Set the public max width and max height varibles in frmMain
\r
110 // These are used by the query generator to determine if it should use -X or -w / -Y or -h
\r
111 if (presetQuery.MaxWidth != 0)
\r
113 mainWindow.text_width.Text = presetQuery.MaxWidth.ToString();
\r
114 mainWindow.maxWidth = presetQuery.MaxWidth;
\r
117 if (presetQuery.MaxHeight != 0)
\r
119 mainWindow.text_height.Text = presetQuery.MaxHeight.ToString();
\r
120 mainWindow.maxHeight = presetQuery.MaxHeight;
\r
128 mainWindow.ctl_decomb.setOption(presetQuery.Decomb);
\r
130 if (mainWindow.ctl_decomb.getDropValue == "Off")
\r
131 mainWindow.ctl_deinterlace.setOption(presetQuery.DeInterlace);
\r
133 mainWindow.ctl_deinterlace.setOption("None"); // Don't want decomb and deinterlace on at the same time
\r
135 mainWindow.ctl_denoise.setOption(presetQuery.DeNoise);
\r
136 mainWindow.ctl_detelecine.setOption(presetQuery.DeTelecine);
\r
138 if (presetQuery.DeBlock != 0)
\r
140 mainWindow.slider_deblock.Value = presetQuery.DeBlock;
\r
141 mainWindow.lbl_deblockVal.Text = presetQuery.DeBlock.ToString();
\r
145 mainWindow.slider_deblock.Value = 4;
\r
146 mainWindow.lbl_deblockVal.Text = "Off";
\r
151 if (presetQuery.AverageVideoBitrate != null)
\r
153 mainWindow.radio_avgBitrate.Checked = true;
\r
154 mainWindow.text_bitrate.Text = presetQuery.AverageVideoBitrate;
\r
156 if (presetQuery.VideoTargetSize != null)
\r
158 mainWindow.radio_targetFilesize.Checked = true;
\r
159 mainWindow.text_filesize.Text = presetQuery.VideoTargetSize;
\r
163 if (presetQuery.VideoQuality != 0)
\r
165 mainWindow.radio_cq.Checked = true;
\r
166 if (presetQuery.VideoEncoder == "H.264 (x264)")
\r
169 System.Globalization.CultureInfo culture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
\r
172 double presetValue = presetQuery.VideoQuality;
\r
173 double.TryParse(Properties.Settings.Default.x264cqstep,
\r
174 System.Globalization.NumberStyles.Number,
\r
178 double x = 51 / x264step;
\r
180 double calculated = presetValue / x264step;
\r
181 calculated = x - calculated;
\r
183 int.TryParse(calculated.ToString(), out value);
\r
185 // This will sometimes occur when the preset was generated
\r
186 // with a different granularity, so, round and try again.
\r
189 double val = Math.Round(calculated, 0);
\r
190 int.TryParse(val.ToString(), out value);
\r
193 mainWindow.slider_videoQuality.Value = value;
\r
198 int.TryParse(presetQuery.VideoQuality.ToString(), out presetVal);
\r
199 mainWindow.slider_videoQuality.Value = presetVal;
\r
203 mainWindow.check_2PassEncode.CheckState = presetQuery.TwoPass ? CheckState.Checked : CheckState.Unchecked;
\r
205 mainWindow.check_grayscale.CheckState = presetQuery.Grayscale ? CheckState.Checked : CheckState.Unchecked;
\r
207 mainWindow.drp_videoFramerate.Text = presetQuery.VideoFramerate;
\r
209 mainWindow.check_turbo.CheckState = presetQuery.TurboFirstPass ? CheckState.Checked : CheckState.Unchecked;
\r
213 #region Chapter Markers
\r
215 if (presetQuery.ChapterMarkers)
\r
217 mainWindow.Check_ChapterMarkers.CheckState = CheckState.Checked;
\r
218 mainWindow.Check_ChapterMarkers.Enabled = true;
\r
221 mainWindow.Check_ChapterMarkers.CheckState = CheckState.Unchecked;
\r
226 // Clear the audio listing
\r
227 mainWindow.lv_audioList.Items.Clear();
\r
229 // Create a new row for the Audio list based on the currently selected items in the dropdown.
\r
230 ListViewItem newTrack;
\r
231 if (presetQuery.AudioTrack1 != "None")
\r
233 newTrack = new ListViewItem("Automatic");
\r
234 newTrack.SubItems.Add(presetQuery.AudioEncoder1);
\r
235 newTrack.SubItems.Add(presetQuery.AudioTrackMix1);
\r
236 newTrack.SubItems.Add(presetQuery.AudioSamplerate1);
\r
237 newTrack.SubItems.Add(presetQuery.AudioBitrate1);
\r
238 newTrack.SubItems.Add(presetQuery.DRC1.ToString());
\r
239 mainWindow.lv_audioList.Items.Add(newTrack);
\r
242 if (presetQuery.AudioTrack2 != "None")
\r
244 newTrack = new ListViewItem("Automatic");
\r
245 newTrack.SubItems.Add(presetQuery.AudioEncoder2);
\r
246 newTrack.SubItems.Add(presetQuery.AudioTrackMix2);
\r
247 newTrack.SubItems.Add(presetQuery.AudioSamplerate2);
\r
248 newTrack.SubItems.Add(presetQuery.AudioBitrate2);
\r
249 newTrack.SubItems.Add(presetQuery.DRC2.ToString());
\r
250 mainWindow.lv_audioList.Items.Add(newTrack);
\r
253 if (presetQuery.AudioTrack3 != "None")
\r
255 newTrack = new ListViewItem("Automatic");
\r
256 newTrack.SubItems.Add(presetQuery.AudioEncoder3);
\r
257 newTrack.SubItems.Add(presetQuery.AudioTrackMix3);
\r
258 newTrack.SubItems.Add(presetQuery.AudioSamplerate3);
\r
259 newTrack.SubItems.Add(presetQuery.AudioBitrate3);
\r
260 newTrack.SubItems.Add(presetQuery.DRC3.ToString());
\r
261 mainWindow.lv_audioList.Items.Add(newTrack);
\r
264 if (presetQuery.AudioTrack4 != "None")
\r
266 newTrack = new ListViewItem("Automatic");
\r
267 newTrack.SubItems.Add(presetQuery.AudioEncoder4);
\r
268 newTrack.SubItems.Add(presetQuery.AudioTrackMix4);
\r
269 newTrack.SubItems.Add(presetQuery.AudioSamplerate4);
\r
270 newTrack.SubItems.Add(presetQuery.AudioBitrate4);
\r
271 newTrack.SubItems.Add(presetQuery.DRC4.ToString());
\r
272 mainWindow.lv_audioList.Items.Add(newTrack);
\r
276 mainWindow.drp_subtitle.Text = presetQuery.Subtitles;
\r
278 if (presetQuery.ForcedSubtitles)
\r
280 mainWindow.check_forced.CheckState = CheckState.Checked;
\r
281 mainWindow.check_forced.Enabled = true;
\r
284 mainWindow.check_forced.CheckState = CheckState.Unchecked;
\r
289 mainWindow.x264Panel.x264Query = presetQuery.H264Query;
\r
291 // Set the preset name
\r
292 mainWindow.groupBox_output.Text = "Output Settings (Preset: " + name + ")";
\r