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.Drawing;
\r
9 using System.Windows.Forms;
\r
10 using Handbrake.Model;
\r
12 namespace Handbrake.Functions
\r
17 /// This function takes in a Query which has been parsed by QueryParser and
\r
18 /// set's all the GUI widgets correctly.
\r
20 /// <param name="mainWindow"></param>
\r
21 /// <param name="presetQuery">The Parsed CLI Query</param>
\r
22 /// <param name="name">Name of the preset</param>
\r
23 /// <param name="pictureSettings">Save picture settings in the preset</param>
\r
24 public static void LoadPreset(frmMain mainWindow, QueryParser presetQuery, string name, Boolean pictureSettings)
\r
27 // Reset some vaules to stock first to prevent errors.
\r
28 mainWindow.check_iPodAtom.CheckState = CheckState.Unchecked;
\r
30 // Now load all the new settings onto the main window
\r
31 if (presetQuery.Format != null)
\r
33 string destination = mainWindow.text_destination.Text;
\r
34 destination = destination.Replace(".mp4", "." + presetQuery.Format);
\r
35 destination = destination.Replace(".m4v", "." + presetQuery.Format);
\r
36 destination = destination.Replace(".mkv", "." + presetQuery.Format);
\r
37 mainWindow.text_destination.Text = destination;
\r
42 #region Destination and Output Settings
\r
44 if (presetQuery.Format != null)
\r
46 if (presetQuery.Format == "mp4" || presetQuery.Format == "m4v")
\r
48 if (mainWindow.drop_format.SelectedIndex == 0)
\r
49 mainWindow.SetExtension(".mp4");
\r
51 mainWindow.drop_format.SelectedIndex = 0;
\r
53 else if (presetQuery.Format == "mkv")
\r
55 if (mainWindow.drop_format.SelectedIndex == 1)
\r
56 mainWindow.SetExtension(".mkv");
\r
58 mainWindow.drop_format.SelectedIndex = 1;
\r
62 mainWindow.check_iPodAtom.CheckState = presetQuery.IpodAtom ? CheckState.Checked : CheckState.Unchecked;
\r
64 mainWindow.check_optimiseMP4.CheckState = presetQuery.OptimizeMP4 ? CheckState.Checked : CheckState.Unchecked;
\r
66 mainWindow.check_largeFile.CheckState = presetQuery.LargeMP4 ? CheckState.Checked : CheckState.Unchecked;
\r
68 mainWindow.setContainerOpts(); // select the container options according to the selected format
\r
73 mainWindow.PictureSettings.check_autoCrop.Checked = true;
\r
74 if (pictureSettings) // only Load picture settings if the perset requires it
\r
76 if (presetQuery.CropValues != null)
\r
78 int top, bottom, left, right;
\r
79 int.TryParse(presetQuery.CropTop, out top);
\r
80 int.TryParse(presetQuery.CropBottom, out bottom);
\r
81 int.TryParse(presetQuery.CropLeft, out left);
\r
82 int.TryParse(presetQuery.CropRight, out right);
\r
84 mainWindow.PictureSettings.check_customCrop.Checked = true;
\r
85 mainWindow.PictureSettings.crop_top.Value = top;
\r
86 mainWindow.PictureSettings.crop_bottom.Value = bottom;
\r
87 mainWindow.PictureSettings.crop_left.Value = left;
\r
88 mainWindow.PictureSettings.crop_right.Value = right;
\r
92 // Set the anamorphic mode 0,1,2,3
\r
93 mainWindow.PictureSettings.drp_anamorphic.SelectedIndex = presetQuery.AnamorphicMode;
\r
95 // Keep Aspect Ration Anamorphic Setting.
\r
96 mainWindow.PictureSettings.check_KeepAR.CheckState = presetQuery.KeepDisplayAsect ? CheckState.Checked : CheckState.Unchecked;
\r
98 // Set the Width and height as Required.
\r
99 if (presetQuery.Width != 0)
\r
100 mainWindow.PictureSettings.text_width.Value = presetQuery.Width;
\r
102 if (presetQuery.Height != 0)
\r
103 mainWindow.PictureSettings.text_height.Value = presetQuery.Height;
\r
105 // Max Width/Height override Width/Height
\r
106 if (presetQuery.MaxWidth != 0)
\r
107 mainWindow.PictureSettings.text_width.Value = presetQuery.MaxWidth;
\r
109 if (presetQuery.MaxHeight != 0)
\r
110 mainWindow.PictureSettings.text_height.Value = presetQuery.MaxHeight;
\r
112 mainWindow.PictureSettings.PresetMaximumResolution = new Size(presetQuery.MaxWidth, presetQuery.MaxHeight);
\r
114 // Case where both height and max height are 0 - For built-in presets
\r
115 if (presetQuery.MaxHeight == 0 && presetQuery.Height == 0)
\r
116 mainWindow.PictureSettings.text_height.Value = 0;
\r
118 if (presetQuery.MaxWidth == 0 && presetQuery.Width == 0)
\r
119 if (mainWindow.selectedTitle != null && mainWindow.selectedTitle.Resolution.Width != 0)
\r
120 mainWindow.PictureSettings.text_width.Value = mainWindow.selectedTitle.Resolution.Width;
\r
122 // Aspect Ratio for non anamorphic sources
\r
123 if (presetQuery.AnamorphicMode == 0)
\r
124 mainWindow.PictureSettings.check_KeepAR.CheckState = presetQuery.Height == 0 ? CheckState.Checked : CheckState.Unchecked;
\r
126 // Custom Anamorphic Controls
\r
127 mainWindow.PictureSettings.updownDisplayWidth.Text = presetQuery.DisplayWidthValue.ToString();
\r
128 mainWindow.PictureSettings.updownParHeight.Text = presetQuery.PixelAspectWidth.ToString();
\r
129 mainWindow.PictureSettings.updownParWidth.Text = presetQuery.PixelAspectHeight.ToString();
\r
130 mainWindow.PictureSettings.drp_modulus.SelectedItem = presetQuery.AnamorphicModulus;
\r
135 mainWindow.Filters.setDecomb(presetQuery.Decomb);
\r
136 mainWindow.Filters.setDeInterlace(presetQuery.DeInterlace);
\r
137 mainWindow.Filters.setDeNoise(presetQuery.DeNoise);
\r
138 mainWindow.Filters.setDeTelecine(presetQuery.DeTelecine);
\r
139 mainWindow.Filters.setDeBlock(presetQuery.DeBlock);
\r
140 mainWindow.Filters.setGrayScale(presetQuery.Grayscale);
\r
144 mainWindow.drp_videoEncoder.Text = presetQuery.VideoEncoder;
\r
146 if (presetQuery.AverageVideoBitrate != null)
\r
148 mainWindow.radio_avgBitrate.Checked = true;
\r
149 mainWindow.text_bitrate.Text = presetQuery.AverageVideoBitrate;
\r
151 if (presetQuery.VideoTargetSize != null)
\r
153 mainWindow.radio_targetFilesize.Checked = true;
\r
154 mainWindow.text_filesize.Text = presetQuery.VideoTargetSize;
\r
159 if (presetQuery.VideoQuality != -1)
\r
161 mainWindow.radio_cq.Checked = true;
\r
162 if (presetQuery.VideoEncoder == "H.264 (x264)")
\r
164 double cqStep = Properties.Settings.Default.x264cqstep;
\r
166 double x264step = cqStep;
\r
167 double presetValue = presetQuery.VideoQuality;
\r
169 double x = 51 / x264step;
\r
171 double calculated = presetValue / x264step;
\r
172 calculated = x - calculated;
\r
174 int.TryParse(calculated.ToString(), out value);
\r
176 // This will sometimes occur when the preset was generated
\r
177 // with a different granularity, so, round and try again.
\r
180 double val = Math.Round(calculated, 0);
\r
181 int.TryParse(val.ToString(), out value);
\r
183 if (value <= mainWindow.slider_videoQuality.Maximum)
\r
184 mainWindow.slider_videoQuality.Value = value;
\r
189 int.TryParse(presetQuery.VideoQuality.ToString(), out presetVal);
\r
190 if (presetVal > mainWindow.slider_videoQuality.Minimum)
\r
191 mainWindow.slider_videoQuality.Value = presetVal;
\r
195 mainWindow.check_2PassEncode.CheckState = presetQuery.TwoPass ? CheckState.Checked : CheckState.Unchecked;
\r
197 mainWindow.drp_videoFramerate.Text = presetQuery.VideoFramerate;
\r
199 mainWindow.check_turbo.CheckState = presetQuery.TurboFirstPass ? CheckState.Checked : CheckState.Unchecked;
\r
203 #region Chapter Markers
\r
205 if (presetQuery.ChapterMarkers)
\r
207 mainWindow.Check_ChapterMarkers.CheckState = CheckState.Checked;
\r
208 mainWindow.Check_ChapterMarkers.Enabled = true;
\r
211 mainWindow.Check_ChapterMarkers.CheckState = CheckState.Unchecked;
\r
216 mainWindow.AudioSettings.LoadTracks(presetQuery.AudioInformation);
\r
220 mainWindow.x264Panel.x264Query = presetQuery.H264Query;
\r
222 // Set the preset name
\r
223 mainWindow.labelPreset.Text = "Output Settings (Preset: " + name + ")";
\r