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
11 namespace Handbrake.Functions
\r
16 /// This function takes in a Query which has been parsed by QueryParser and
\r
17 /// set's all the GUI widgets correctly.
\r
19 /// <param name="mainWindow"></param>
\r
20 /// <param name="presetQuery">The Parsed CLI Query</param>
\r
21 /// <param name="name">Name of the preset</param>
\r
22 /// <param name="pictureSettings">Save picture settings in the preset</param>
\r
23 public static void presetLoader(frmMain mainWindow, QueryParser presetQuery, string name, Boolean pictureSettings)
\r
25 // ---------------------------
\r
27 // ---------------------------
\r
30 // Reset some vaules to stock first to prevent errors.
\r
31 mainWindow.check_iPodAtom.CheckState = CheckState.Unchecked;
\r
33 // Now load all the new settings onto the main window
\r
34 if (presetQuery.Format != null)
\r
36 string destination = mainWindow.text_destination.Text;
\r
37 destination = destination.Replace(".mp4", "." + presetQuery.Format);
\r
38 destination = destination.Replace(".m4v", "." + presetQuery.Format);
\r
39 destination = destination.Replace(".mkv", "." + presetQuery.Format);
\r
40 mainWindow.text_destination.Text = destination;
\r
45 #region Destination and Output Settings
\r
47 if (presetQuery.Format != null)
\r
49 if (presetQuery.Format == "mp4" || presetQuery.Format == "m4v")
\r
51 if (mainWindow.drop_format.SelectedIndex == 0)
\r
52 mainWindow.SetExtension(".mp4");
\r
54 mainWindow.drop_format.SelectedIndex = 0;
\r
56 else if (presetQuery.Format == "mkv")
\r
58 if (mainWindow.drop_format.SelectedIndex == 1)
\r
59 mainWindow.SetExtension(".mkv");
\r
61 mainWindow.drop_format.SelectedIndex = 1;
\r
65 mainWindow.check_iPodAtom.CheckState = presetQuery.IpodAtom ? CheckState.Checked : CheckState.Unchecked;
\r
67 mainWindow.check_optimiseMP4.CheckState = presetQuery.OptimizeMP4 ? CheckState.Checked : CheckState.Unchecked;
\r
69 mainWindow.check_largeFile.CheckState = presetQuery.LargeMP4 ? CheckState.Checked : CheckState.Unchecked;
\r
71 mainWindow.setContainerOpts(); // select the container options according to the selected format
\r
76 mainWindow.PictureSettings.check_autoCrop.Checked = true;
\r
77 if (pictureSettings) // only Load picture settings if the perset requires it
\r
79 if (presetQuery.CropValues != null)
\r
81 int top, bottom, left, right;
\r
82 int.TryParse(presetQuery.CropTop, out top);
\r
83 int.TryParse(presetQuery.CropBottom, out bottom);
\r
84 int.TryParse(presetQuery.CropLeft, out left);
\r
85 int.TryParse(presetQuery.CropRight, out right);
\r
87 mainWindow.PictureSettings.check_customCrop.Checked = true;
\r
88 mainWindow.PictureSettings.crop_top.Value = top;
\r
89 mainWindow.PictureSettings.crop_bottom.Value = bottom;
\r
90 mainWindow.PictureSettings.crop_left.Value = left;
\r
91 mainWindow.PictureSettings.crop_right.Value = right;
\r
95 // Set the anamorphic mode 0,1,2,3
\r
96 mainWindow.PictureSettings.drp_anamorphic.SelectedIndex = presetQuery.AnamorphicMode;
\r
98 // Keep Aspect Ration Anamorphic Setting.
\r
99 mainWindow.PictureSettings.check_KeepAR.CheckState = presetQuery.keepDisplayAsect ? CheckState.Checked : CheckState.Unchecked;
\r
101 // Set the Width and height as Required.
\r
102 if (presetQuery.Width != 0)
\r
103 mainWindow.PictureSettings.text_width.Value = presetQuery.Width;
\r
105 if (presetQuery.Height != 0)
\r
106 mainWindow.PictureSettings.text_height.Value = presetQuery.Height;
\r
108 // Max Width/Height override Width/Height
\r
109 if (presetQuery.MaxWidth != 0)
\r
110 mainWindow.PictureSettings.text_width.Value = presetQuery.MaxWidth;
\r
112 if (presetQuery.MaxHeight != 0)
\r
113 mainWindow.PictureSettings.text_height.Value = presetQuery.MaxHeight;
\r
115 mainWindow.PictureSettings.PresetMaximumResolution = new Size(presetQuery.MaxWidth, presetQuery.MaxHeight);
\r
117 // Case where both height and max height are 0 - For built-in presets
\r
118 if (presetQuery.MaxHeight == 0 && presetQuery.Height == 0)
\r
119 mainWindow.PictureSettings.text_height.Value = 0;
\r
121 if (presetQuery.MaxWidth == 0 && presetQuery.Width == 0)
\r
122 if (mainWindow.selectedTitle != null && mainWindow.selectedTitle.Resolution.Width != 0)
\r
123 mainWindow.PictureSettings.text_width.Value = mainWindow.selectedTitle.Resolution.Width;
\r
125 // Aspect Ratio for non anamorphic sources
\r
126 if (presetQuery.AnamorphicMode == 0)
\r
127 mainWindow.PictureSettings.check_KeepAR.CheckState = presetQuery.Height == 0 ? CheckState.Checked : CheckState.Unchecked;
\r
129 // Custom Anamorphic Controls
\r
130 mainWindow.PictureSettings.updownDisplayWidth.Text = presetQuery.displayWidthValue.ToString();
\r
131 mainWindow.PictureSettings.updownParHeight.Text = presetQuery.pixelAspectWidth.ToString();
\r
132 mainWindow.PictureSettings.updownParWidth.Text = presetQuery.pixelAspectHeight.ToString();
\r
133 mainWindow.PictureSettings.drp_modulus.SelectedItem = presetQuery.AnamorphicModulus;
\r
138 mainWindow.Filters.setDecomb(presetQuery.Decomb);
\r
139 mainWindow.Filters.setDeInterlace(presetQuery.DeInterlace);
\r
140 mainWindow.Filters.setDeNoise(presetQuery.DeNoise);
\r
141 mainWindow.Filters.setDeTelecine(presetQuery.DeTelecine);
\r
142 mainWindow.Filters.setDeBlock(presetQuery.DeBlock);
\r
143 mainWindow.Filters.setGrayScale(presetQuery.Grayscale);
\r
147 mainWindow.drp_videoEncoder.Text = presetQuery.VideoEncoder;
\r
149 if (presetQuery.AverageVideoBitrate != null)
\r
151 mainWindow.radio_avgBitrate.Checked = true;
\r
152 mainWindow.text_bitrate.Text = presetQuery.AverageVideoBitrate;
\r
154 if (presetQuery.VideoTargetSize != null)
\r
156 mainWindow.radio_targetFilesize.Checked = true;
\r
157 mainWindow.text_filesize.Text = presetQuery.VideoTargetSize;
\r
162 if (presetQuery.VideoQuality != -1)
\r
164 mainWindow.radio_cq.Checked = true;
\r
165 if (presetQuery.VideoEncoder == "H.264 (x264)")
\r
167 double cqStep = Properties.Settings.Default.x264cqstep;
\r
169 double x264step = cqStep;
\r
170 double presetValue = presetQuery.VideoQuality;
\r
172 double x = 51 / x264step;
\r
174 double calculated = presetValue / x264step;
\r
175 calculated = x - calculated;
\r
177 int.TryParse(calculated.ToString(), out value);
\r
179 // This will sometimes occur when the preset was generated
\r
180 // with a different granularity, so, round and try again.
\r
183 double val = Math.Round(calculated, 0);
\r
184 int.TryParse(val.ToString(), out value);
\r
186 if (value <= mainWindow.slider_videoQuality.Maximum)
\r
187 mainWindow.slider_videoQuality.Value = value;
\r
192 int.TryParse(presetQuery.VideoQuality.ToString(), out presetVal);
\r
193 if (presetVal > mainWindow.slider_videoQuality.Minimum)
\r
194 mainWindow.slider_videoQuality.Value = presetVal;
\r
198 mainWindow.check_2PassEncode.CheckState = presetQuery.TwoPass ? CheckState.Checked : CheckState.Unchecked;
\r
200 mainWindow.drp_videoFramerate.Text = presetQuery.VideoFramerate;
\r
202 mainWindow.check_turbo.CheckState = presetQuery.TurboFirstPass ? CheckState.Checked : CheckState.Unchecked;
\r
206 #region Chapter Markers
\r
208 if (presetQuery.ChapterMarkers)
\r
210 mainWindow.Check_ChapterMarkers.CheckState = CheckState.Checked;
\r
211 mainWindow.Check_ChapterMarkers.Enabled = true;
\r
214 mainWindow.Check_ChapterMarkers.CheckState = CheckState.Unchecked;
\r
219 // Clear the audio listing
\r
220 mainWindow.AudioSettings.ClearAudioList();
\r
222 if (presetQuery.AudioInformation != null)
\r
223 foreach (AudioTrack track in presetQuery.AudioInformation)
\r
225 ListViewItem newTrack = new ListViewItem(mainWindow.AudioSettings.GetNewID().ToString());
\r
227 newTrack.SubItems.Add("Automatic");
\r
228 newTrack.SubItems.Add(track.Encoder);
\r
229 newTrack.SubItems.Add(track.MixDown);
\r
230 newTrack.SubItems.Add(track.SampleRate);
\r
231 newTrack.SubItems.Add(track.Encoder.Contains("AC3") ? "Auto" : track.Bitrate);
\r
232 newTrack.SubItems.Add(track.DRC);
\r
233 mainWindow.AudioSettings.AddTrackForPreset(newTrack);
\r
238 mainWindow.x264Panel.x264Query = presetQuery.H264Query;
\r
240 // Set the preset name
\r
241 mainWindow.labelPreset.Text = "Output Settings (Preset: " + name + ")";
\r