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) // only Load picture settings if the perset requires it
\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
93 // Set the anamorphic mode 0,1,2,3
\r
94 mainWindow.pictureSettings.drp_anamorphic.SelectedIndex = presetQuery.AnamorphicMode;
\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
103 // Reset maxWidth and MaxHeight to 0
\r
104 mainWindow.pictureSettings.maxWidth = 0;
\r
105 mainWindow.pictureSettings.maxHeight = 0;
\r
107 // Set the width and height
\r
108 if (presetQuery.Width != 0)
\r
109 mainWindow.pictureSettings.text_width.Value = presetQuery.Width;
\r
111 if (presetQuery.Height != 0)
\r
112 mainWindow.pictureSettings.text_height.Value = presetQuery.Height;
\r
114 mainWindow.pictureSettings.text_height.Value = 0;
\r
116 // Max Width/Height override Width/Height
\r
117 if (presetQuery.MaxWidth != 0)
\r
119 mainWindow.pictureSettings.text_width.Value = presetQuery.MaxWidth;
\r
120 mainWindow.pictureSettings.maxWidth = presetQuery.MaxWidth;
\r
123 if (presetQuery.MaxHeight != 0)
\r
125 mainWindow.pictureSettings.text_height.Value = presetQuery.MaxHeight;
\r
126 mainWindow.pictureSettings.maxHeight = presetQuery.MaxHeight;
\r
128 mainWindow.pictureSettings.setMax();
\r
135 mainWindow.ctl_decomb.setOption(presetQuery.Decomb);
\r
137 if (mainWindow.ctl_decomb.getDropValue == "Off")
\r
138 mainWindow.ctl_deinterlace.setOption(presetQuery.DeInterlace);
\r
140 mainWindow.ctl_deinterlace.setOption("None"); // Don't want decomb and deinterlace on at the same time
\r
142 mainWindow.ctl_denoise.setOption(presetQuery.DeNoise);
\r
143 mainWindow.ctl_detelecine.setOption(presetQuery.DeTelecine);
\r
145 if (presetQuery.DeBlock != 0)
\r
147 mainWindow.slider_deblock.Value = presetQuery.DeBlock;
\r
148 mainWindow.lbl_deblockVal.Text = presetQuery.DeBlock.ToString();
\r
152 mainWindow.slider_deblock.Value = 4;
\r
153 mainWindow.lbl_deblockVal.Text = "Off";
\r
158 mainWindow.drp_videoEncoder.Text = presetQuery.VideoEncoder;
\r
160 if (presetQuery.AverageVideoBitrate != null)
\r
162 mainWindow.radio_avgBitrate.Checked = true;
\r
163 mainWindow.text_bitrate.Text = presetQuery.AverageVideoBitrate;
\r
165 if (presetQuery.VideoTargetSize != null)
\r
167 mainWindow.radio_targetFilesize.Checked = true;
\r
168 mainWindow.text_filesize.Text = presetQuery.VideoTargetSize;
\r
172 if (presetQuery.VideoQuality != 0)
\r
174 mainWindow.radio_cq.Checked = true;
\r
175 if (presetQuery.VideoEncoder == "H.264 (x264)")
\r
178 System.Globalization.CultureInfo culture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
\r
181 double presetValue = presetQuery.VideoQuality;
\r
182 double.TryParse(Properties.Settings.Default.x264cqstep,
\r
183 System.Globalization.NumberStyles.Number,
\r
187 double x = 51 / x264step;
\r
189 double calculated = presetValue / x264step;
\r
190 calculated = x - calculated;
\r
192 int.TryParse(calculated.ToString(), out value);
\r
194 // This will sometimes occur when the preset was generated
\r
195 // with a different granularity, so, round and try again.
\r
198 double val = Math.Round(calculated, 0);
\r
199 int.TryParse(val.ToString(), out value);
\r
202 mainWindow.slider_videoQuality.Value = value;
\r
207 int.TryParse(presetQuery.VideoQuality.ToString(), out presetVal);
\r
208 mainWindow.slider_videoQuality.Value = presetVal;
\r
212 mainWindow.check_2PassEncode.CheckState = presetQuery.TwoPass ? CheckState.Checked : CheckState.Unchecked;
\r
214 mainWindow.check_grayscale.CheckState = presetQuery.Grayscale ? CheckState.Checked : CheckState.Unchecked;
\r
216 mainWindow.drp_videoFramerate.Text = presetQuery.VideoFramerate;
\r
218 mainWindow.check_turbo.CheckState = presetQuery.TurboFirstPass ? CheckState.Checked : CheckState.Unchecked;
\r
222 #region Chapter Markers
\r
224 if (presetQuery.ChapterMarkers)
\r
226 mainWindow.Check_ChapterMarkers.CheckState = CheckState.Checked;
\r
227 mainWindow.Check_ChapterMarkers.Enabled = true;
\r
230 mainWindow.Check_ChapterMarkers.CheckState = CheckState.Unchecked;
\r
235 // Clear the audio listing
\r
236 mainWindow.audioPanel.clearAudioList();
\r
238 if (presetQuery.AudioInformation != null)
\r
239 foreach (AudioTrack track in presetQuery.AudioInformation)
\r
241 ListViewItem newTrack = new ListViewItem(mainWindow.audioPanel.getNewID().ToString());
\r
243 newTrack.SubItems.Add("Automatic");
\r
244 newTrack.SubItems.Add(track.Encoder);
\r
245 newTrack.SubItems.Add(track.MixDown);
\r
246 newTrack.SubItems.Add(track.SampleRate);
\r
247 newTrack.SubItems.Add(track.Bitrate);
\r
248 newTrack.SubItems.Add(track.DRC);
\r
249 mainWindow.audioPanel.addTrackForPreset(newTrack);
\r
253 mainWindow.drp_subtitle.Text = presetQuery.Subtitles;
\r
255 if (presetQuery.ForcedSubtitles)
\r
257 mainWindow.check_forced.CheckState = CheckState.Checked;
\r
258 mainWindow.check_forced.Enabled = true;
\r
261 mainWindow.check_forced.CheckState = CheckState.Unchecked;*/
\r
266 mainWindow.x264Panel.x264Query = presetQuery.H264Query;
\r
268 // Set the preset name
\r
269 mainWindow.groupBox_output.Text = "Output Settings (Preset: " + name + ")";
\r