1 /* PresetLoader.cs $
\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
8 using System.Windows.Forms;
\r
10 namespace Handbrake.Functions
\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
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
24 // ---------------------------
\r
26 // ---------------------------
\r
29 // Reset some vaules to stock first to prevent errors.
\r
30 mainWindow.check_iPodAtom.CheckState = CheckState.Unchecked;
\r
32 // Now load all the new settings onto the main window
\r
33 if (presetQuery.Format != null)
\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
44 #region Destination and Output Settings
\r
46 if (presetQuery.Format != null)
\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
55 if (presetQuery.ChapterMarkers && presetQuery.Format == "mp4")
\r
56 mainWindow.drop_format.SelectedIndex = 1;
\r
59 mainWindow.check_iPodAtom.CheckState = presetQuery.IpodAtom ? CheckState.Checked : CheckState.Unchecked;
\r
61 mainWindow.check_optimiseMP4.CheckState = presetQuery.OptimizeMP4 ? CheckState.Checked : CheckState.Unchecked;
\r
63 mainWindow.check_largeFile.CheckState = presetQuery.LargeMP4 ? CheckState.Checked : CheckState.Unchecked;
\r
65 mainWindow.setContainerOpts(); // select the container options according to the selected format
\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
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.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
92 if (presetQuery.Width != 0)
\r
93 mainWindow.pictureSettings.text_width.Text = presetQuery.Width.ToString();
\r
95 if (presetQuery.Height != 0)
\r
96 mainWindow.pictureSettings.text_height.Text = presetQuery.Height.ToString();
\r
99 // Set the anamorphic mode 0,1,2,3
\r
100 mainWindow.pictureSettings.drp_anamorphic.SelectedIndex = presetQuery.AnamorphicMode;
\r
103 // Custom Anamorphic Controls
\r
104 mainWindow.pictureSettings.check_KeepAR.CheckState = presetQuery.keepDisplayAsect ? CheckState.Checked : CheckState.Unchecked;
\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
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
116 mainWindow.pictureSettings.text_width.Text = presetQuery.MaxWidth.ToString();
\r
117 mainWindow.maxWidth = presetQuery.MaxWidth;
\r
120 if (presetQuery.MaxHeight != 0)
\r
122 mainWindow.pictureSettings.text_height.Text = presetQuery.MaxHeight.ToString();
\r
123 mainWindow.maxHeight = presetQuery.MaxHeight;
\r
131 mainWindow.ctl_decomb.setOption(presetQuery.Decomb);
\r
133 if (mainWindow.ctl_decomb.getDropValue == "Off")
\r
134 mainWindow.ctl_deinterlace.setOption(presetQuery.DeInterlace);
\r
136 mainWindow.ctl_deinterlace.setOption("None"); // Don't want decomb and deinterlace on at the same time
\r
138 mainWindow.ctl_denoise.setOption(presetQuery.DeNoise);
\r
139 mainWindow.ctl_detelecine.setOption(presetQuery.DeTelecine);
\r
141 if (presetQuery.DeBlock != 0)
\r
143 mainWindow.slider_deblock.Value = presetQuery.DeBlock;
\r
144 mainWindow.lbl_deblockVal.Text = presetQuery.DeBlock.ToString();
\r
148 mainWindow.slider_deblock.Value = 4;
\r
149 mainWindow.lbl_deblockVal.Text = "Off";
\r
154 mainWindow.drp_videoEncoder.Text = presetQuery.VideoEncoder;
\r
156 if (presetQuery.AverageVideoBitrate != null)
\r
158 mainWindow.radio_avgBitrate.Checked = true;
\r
159 mainWindow.text_bitrate.Text = presetQuery.AverageVideoBitrate;
\r
161 if (presetQuery.VideoTargetSize != null)
\r
163 mainWindow.radio_targetFilesize.Checked = true;
\r
164 mainWindow.text_filesize.Text = presetQuery.VideoTargetSize;
\r
168 if (presetQuery.VideoQuality != 0)
\r
170 mainWindow.radio_cq.Checked = true;
\r
171 if (presetQuery.VideoEncoder == "H.264 (x264)")
\r
174 System.Globalization.CultureInfo culture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
\r
177 double presetValue = presetQuery.VideoQuality;
\r
178 double.TryParse(Properties.Settings.Default.x264cqstep,
\r
179 System.Globalization.NumberStyles.Number,
\r
183 double x = 51 / x264step;
\r
185 double calculated = presetValue / x264step;
\r
186 calculated = x - calculated;
\r
188 int.TryParse(calculated.ToString(), out value);
\r
190 // This will sometimes occur when the preset was generated
\r
191 // with a different granularity, so, round and try again.
\r
194 double val = Math.Round(calculated, 0);
\r
195 int.TryParse(val.ToString(), out value);
\r
198 mainWindow.slider_videoQuality.Value = value;
\r
203 int.TryParse(presetQuery.VideoQuality.ToString(), out presetVal);
\r
204 mainWindow.slider_videoQuality.Value = presetVal;
\r
208 mainWindow.check_2PassEncode.CheckState = presetQuery.TwoPass ? CheckState.Checked : CheckState.Unchecked;
\r
210 mainWindow.check_grayscale.CheckState = presetQuery.Grayscale ? CheckState.Checked : CheckState.Unchecked;
\r
212 mainWindow.drp_videoFramerate.Text = presetQuery.VideoFramerate;
\r
214 mainWindow.check_turbo.CheckState = presetQuery.TurboFirstPass ? CheckState.Checked : CheckState.Unchecked;
\r
218 #region Chapter Markers
\r
220 if (presetQuery.ChapterMarkers)
\r
222 mainWindow.Check_ChapterMarkers.CheckState = CheckState.Checked;
\r
223 mainWindow.Check_ChapterMarkers.Enabled = true;
\r
226 mainWindow.Check_ChapterMarkers.CheckState = CheckState.Unchecked;
\r
231 // Clear the audio listing
\r
232 mainWindow.audioPanel.clearAudioList();
\r
234 if (presetQuery.AudioInformation != null)
\r
235 foreach (AudioTrack track in presetQuery.AudioInformation)
\r
237 ListViewItem newTrack = new ListViewItem(mainWindow.audioPanel.getNewID().ToString());
\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
249 mainWindow.drp_subtitle.Text = presetQuery.Subtitles;
\r
251 if (presetQuery.ForcedSubtitles)
\r
253 mainWindow.check_forced.CheckState = CheckState.Checked;
\r
254 mainWindow.check_forced.Enabled = true;
\r
257 mainWindow.check_forced.CheckState = CheckState.Unchecked;
\r
262 mainWindow.x264Panel.x264Query = presetQuery.H264Query;
\r
264 // Set the preset name
\r
265 mainWindow.groupBox_output.Text = "Output Settings (Preset: " + name + ")";
\r