1 /* PresetLoader.cs $
\r
2 This file is part of the HandBrake source code.
\r
3 Homepage: <http://handbrake.fr>.
\r
4 It may be used under the terms of the GNU General Public License. */
\r
6 namespace Handbrake.Functions
\r
8 using System.Drawing;
\r
9 using System.Windows.Forms;
\r
12 /// Load a preset into the main Window
\r
14 public class PresetLoader
\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">
\r
23 /// <param name="presetQuery">
\r
24 /// The Parsed CLI Query
\r
26 /// <param name="name">
\r
27 /// Name of the preset
\r
29 /// <param name="pictureSettings">
\r
30 /// Save picture settings in the preset
\r
32 public static void LoadPreset(frmMain mainWindow, QueryParser presetQuery, string name)
\r
36 // Reset some vaules to stock first to prevent errors.
\r
37 mainWindow.check_iPodAtom.CheckState = CheckState.Unchecked;
\r
39 // Now load all the new settings onto the main window
\r
40 if (presetQuery.Format != null)
\r
42 string destination = mainWindow.text_destination.Text;
\r
43 destination = destination.Replace(".mp4", "." + presetQuery.Format);
\r
44 destination = destination.Replace(".m4v", "." + presetQuery.Format);
\r
45 destination = destination.Replace(".mkv", "." + presetQuery.Format);
\r
46 mainWindow.text_destination.Text = destination;
\r
51 #region Destination and Output Settings
\r
53 if (presetQuery.Format != null)
\r
55 if (presetQuery.Format == "mp4" || presetQuery.Format == "m4v")
\r
57 if (mainWindow.drop_format.SelectedIndex == 0)
\r
58 mainWindow.SetExtension(".mp4");
\r
60 mainWindow.drop_format.SelectedIndex = 0;
\r
62 else if (presetQuery.Format == "mkv")
\r
64 if (mainWindow.drop_format.SelectedIndex == 1)
\r
65 mainWindow.SetExtension(".mkv");
\r
67 mainWindow.drop_format.SelectedIndex = 1;
\r
71 mainWindow.check_iPodAtom.CheckState = presetQuery.IpodAtom ? CheckState.Checked : CheckState.Unchecked;
\r
73 mainWindow.check_optimiseMP4.CheckState = presetQuery.OptimizeMP4
\r
74 ? CheckState.Checked
\r
75 : CheckState.Unchecked;
\r
77 mainWindow.check_largeFile.CheckState = presetQuery.LargeMP4 ? CheckState.Checked : CheckState.Unchecked;
\r
79 mainWindow.setContainerOpts(); // select the container options according to the selected format
\r
85 mainWindow.PictureSettings.check_autoCrop.Checked = true;
\r
86 if (presetQuery.CropValues != null)
\r
88 int top, bottom, left, right;
\r
89 int.TryParse(presetQuery.CropTop, out top);
\r
90 int.TryParse(presetQuery.CropBottom, out bottom);
\r
91 int.TryParse(presetQuery.CropLeft, out left);
\r
92 int.TryParse(presetQuery.CropRight, out right);
\r
94 mainWindow.PictureSettings.check_customCrop.Checked = true;
\r
95 mainWindow.PictureSettings.crop_top.Value = top;
\r
96 mainWindow.PictureSettings.crop_bottom.Value = bottom;
\r
97 mainWindow.PictureSettings.crop_left.Value = left;
\r
98 mainWindow.PictureSettings.crop_right.Value = right;
\r
101 // Set the anamorphic mode 0,1,2,3
\r
102 mainWindow.PictureSettings.drp_anamorphic.SelectedIndex = presetQuery.AnamorphicMode;
\r
104 // Keep Aspect Ration Anamorphic Setting.
\r
105 mainWindow.PictureSettings.check_KeepAR.CheckState = presetQuery.KeepDisplayAsect
\r
106 ? CheckState.Checked
\r
107 : CheckState.Unchecked;
\r
109 // Set the Width and height as Required.
\r
110 if (presetQuery.Width != 0)
\r
111 mainWindow.PictureSettings.text_width.Value = presetQuery.Width;
\r
113 if (presetQuery.Height != 0)
\r
114 mainWindow.PictureSettings.text_height.Value = presetQuery.Height;
\r
116 // Max Width/Height override Width/Height
\r
117 if (presetQuery.MaxWidth != 0)
\r
118 mainWindow.PictureSettings.text_width.Value = presetQuery.MaxWidth;
\r
120 if (presetQuery.MaxHeight != 0)
\r
121 mainWindow.PictureSettings.text_height.Value = presetQuery.MaxHeight;
\r
123 mainWindow.PictureSettings.PresetMaximumResolution = new Size(presetQuery.MaxWidth, presetQuery.MaxHeight);
\r
125 // Case where both height and max height are 0 - For built-in presets
\r
126 if (presetQuery.MaxHeight == 0 && presetQuery.Height == 0)
\r
127 mainWindow.PictureSettings.text_height.Value = 0;
\r
129 if (presetQuery.MaxWidth == 0 && presetQuery.Width == 0)
\r
130 if (mainWindow.selectedTitle != null && mainWindow.selectedTitle.Resolution.Width != 0)
\r
131 mainWindow.PictureSettings.text_width.Value = mainWindow.selectedTitle.Resolution.Width;
\r
133 // Aspect Ratio for non anamorphic sources
\r
134 if (presetQuery.AnamorphicMode == 0)
\r
135 mainWindow.PictureSettings.check_KeepAR.CheckState = presetQuery.Height == 0
\r
136 ? CheckState.Checked
\r
137 : CheckState.Unchecked;
\r
139 // Custom Anamorphic Controls
\r
140 mainWindow.PictureSettings.updownDisplayWidth.Text = presetQuery.DisplayWidthValue.ToString();
\r
141 mainWindow.PictureSettings.updownParHeight.Text = presetQuery.PixelAspectHeight.ToString();
\r
142 mainWindow.PictureSettings.updownParWidth.Text = presetQuery.PixelAspectWidth.ToString();
\r
143 mainWindow.PictureSettings.drp_modulus.SelectedItem = presetQuery.AnamorphicModulus.ToString();
\r
149 mainWindow.Filters.SetDecomb(presetQuery.Decomb);
\r
150 mainWindow.Filters.SetDeInterlace(presetQuery.DeInterlace);
\r
151 mainWindow.Filters.SetDeNoise(presetQuery.DeNoise);
\r
152 mainWindow.Filters.SetDeTelecine(presetQuery.DeTelecine);
\r
153 mainWindow.Filters.SetDeBlock(presetQuery.DeBlock);
\r
154 mainWindow.Filters.SetGrayScale(presetQuery.Grayscale);
\r
160 mainWindow.drp_videoEncoder.Text = presetQuery.VideoEncoder;
\r
162 if (presetQuery.AverageVideoBitrate != null)
\r
164 mainWindow.radio_avgBitrate.Checked = true;
\r
165 mainWindow.text_bitrate.Text = presetQuery.AverageVideoBitrate;
\r
167 if (presetQuery.VideoTargetSize != null)
\r
169 mainWindow.radio_targetFilesize.Checked = true;
\r
170 mainWindow.text_filesize.Text = presetQuery.VideoTargetSize;
\r
174 if (presetQuery.VideoQuality != -1)
\r
176 mainWindow.radio_cq.Checked = true;
\r
177 mainWindow.slider_videoQuality.Value = QualityToSliderValue(presetQuery.VideoEncoder, presetQuery.VideoQuality);
\r
180 mainWindow.check_2PassEncode.CheckState = presetQuery.TwoPass ? CheckState.Checked : CheckState.Unchecked;
\r
182 mainWindow.drp_videoFramerate.Text = presetQuery.VideoFramerate;
\r
183 mainWindow.checkMaximumFramerate.Checked = presetQuery.Pfr;
\r
185 mainWindow.check_turbo.CheckState = presetQuery.TurboFirstPass ? CheckState.Checked : CheckState.Unchecked;
\r
189 #region Chapter Markers
\r
191 if (presetQuery.ChapterMarkers)
\r
193 mainWindow.Check_ChapterMarkers.CheckState = CheckState.Checked;
\r
194 mainWindow.Check_ChapterMarkers.Enabled = true;
\r
197 mainWindow.Check_ChapterMarkers.CheckState = CheckState.Unchecked;
\r
203 mainWindow.AudioSettings.LoadTracks(presetQuery.AudioInformation);
\r
209 mainWindow.x264Panel.X264Query = presetQuery.H264Query;
\r
211 // Set the preset name
\r
212 mainWindow.labelPreset.Text = "Output Settings (Preset: " + name + ")";
\r
218 /// Convert a Quality Value to a position value for the Video Quality slider
\r
220 /// <param name="videoEncoder">The selected video encoder</param>
\r
221 /// <param name="value">The Quality value</param>
\r
222 /// <returns>The position on the video quality slider</returns>
\r
223 private static int QualityToSliderValue(string videoEncoder, float value)
\r
225 int sliderValue = 0;
\r
226 switch (videoEncoder)
\r
228 case "MPEG-4 (FFmpeg)":
\r
229 sliderValue = 32 - (int)value;
\r
231 case "H.264 (x264)":
\r
232 double cqStep = Properties.Settings.Default.x264cqstep;
\r
233 sliderValue = (int)((51.0 / cqStep) - (value / cqStep));
\r
235 case "VP3 (Theora)":
\r
236 sliderValue = (int)value;
\r
240 return sliderValue;
\r