OSDN Git Service

import original 0.9.5 release
[handbrake-jp/handbrake-jp.git] / win / C# / Functions / PresetLoader.cs
index 3018b91..790d511 100644 (file)
@@ -1,32 +1,35 @@
 /*  PresetLoader.cs $\r
-       \r
-          This file is part of the HandBrake source code.\r
-          Homepage: <http://handbrake.fr>.\r
-          It may be used under the terms of the GNU General Public License. */\r
-\r
-using System;\r
-using System.Drawing;\r
-using System.Windows.Forms;\r
+    This file is part of the HandBrake source code.\r
+    Homepage: <http://handbrake.fr>.\r
+    It may be used under the terms of the GNU General Public License. */\r
 \r
 namespace Handbrake.Functions\r
 {\r
-    class PresetLoader\r
+    using System.Drawing;\r
+    using System.Windows.Forms;\r
+\r
+    /// <summary>\r
+    /// Load a preset into the main Window\r
+    /// </summary>\r
+    public class PresetLoader\r
     {\r
         /// <summary>\r
         /// This function takes in a Query which has been parsed by QueryParser and\r
         /// set's all the GUI widgets correctly.\r
         /// </summary>\r
-        /// <param name="mainWindow"></param>\r
-        /// <param name="presetQuery">The Parsed CLI Query</param>\r
-        /// <param name="name">Name of the preset</param>\r
-        /// <param name="pictureSettings">Save picture settings in the preset</param>\r
-        public static void presetLoader(frmMain mainWindow, QueryParser presetQuery, string name, Boolean pictureSettings)\r
+        /// <param name="mainWindow">\r
+        /// FrmMain window\r
+        /// </param>\r
+        /// <param name="presetQuery">\r
+        /// The Parsed CLI Query\r
+        /// </param>\r
+        /// <param name="name">\r
+        /// Name of the preset\r
+        /// </param>\r
+        public static void LoadPreset(frmMain mainWindow, QueryParser presetQuery, string name)\r
         {\r
-            // ---------------------------\r
-            // Setup the GUI\r
-            // ---------------------------\r
-\r
             #region Source\r
+\r
             // Reset some vaules to stock first to prevent errors.\r
             mainWindow.check_iPodAtom.CheckState = CheckState.Unchecked;\r
 \r
@@ -50,12 +53,12 @@ namespace Handbrake.Functions
                 {\r
                     if (mainWindow.drop_format.SelectedIndex == 0)\r
                         mainWindow.SetExtension(".mp4");\r
-                    else \r
+                    else\r
                         mainWindow.drop_format.SelectedIndex = 0;\r
                 }\r
                 else if (presetQuery.Format == "mkv")\r
                 {\r
-                    if(mainWindow.drop_format.SelectedIndex == 1)\r
+                    if (mainWindow.drop_format.SelectedIndex == 1)\r
                         mainWindow.SetExtension(".mkv");\r
                     else\r
                         mainWindow.drop_format.SelectedIndex = 1;\r
@@ -64,7 +67,9 @@ namespace Handbrake.Functions
 \r
             mainWindow.check_iPodAtom.CheckState = presetQuery.IpodAtom ? CheckState.Checked : CheckState.Unchecked;\r
 \r
-            mainWindow.check_optimiseMP4.CheckState = presetQuery.OptimizeMP4 ? CheckState.Checked : CheckState.Unchecked;\r
+            mainWindow.check_optimiseMP4.CheckState = presetQuery.OptimizeMP4\r
+                                                          ? CheckState.Checked\r
+                                                          : CheckState.Unchecked;\r
 \r
             mainWindow.check_largeFile.CheckState = presetQuery.LargeMP4 ? CheckState.Checked : CheckState.Unchecked;\r
 \r
@@ -73,31 +78,31 @@ namespace Handbrake.Functions
             #endregion\r
 \r
             #region Picture\r
+\r
             mainWindow.PictureSettings.check_autoCrop.Checked = true;\r
-            if (pictureSettings) // only Load picture settings if the perset requires it\r
+            if (presetQuery.CropValues != null)\r
             {\r
-                if (presetQuery.CropValues != null)\r
-                {\r
-                    int top, bottom, left, right;\r
-                    int.TryParse(presetQuery.CropTop, out top);\r
-                    int.TryParse(presetQuery.CropBottom, out bottom);\r
-                    int.TryParse(presetQuery.CropLeft, out left);\r
-                    int.TryParse(presetQuery.CropRight, out right);\r
-\r
-                    mainWindow.PictureSettings.check_customCrop.Checked = true;\r
-                    mainWindow.PictureSettings.crop_top.Value = top;\r
-                    mainWindow.PictureSettings.crop_bottom.Value = bottom;\r
-                    mainWindow.PictureSettings.crop_left.Value = left;\r
-                    mainWindow.PictureSettings.crop_right.Value = right;\r
-                }\r
+                int top, bottom, left, right;\r
+                int.TryParse(presetQuery.CropTop, out top);\r
+                int.TryParse(presetQuery.CropBottom, out bottom);\r
+                int.TryParse(presetQuery.CropLeft, out left);\r
+                int.TryParse(presetQuery.CropRight, out right);\r
+\r
+                mainWindow.PictureSettings.check_customCrop.Checked = true;\r
+                mainWindow.PictureSettings.crop_top.Value = top;\r
+                mainWindow.PictureSettings.crop_bottom.Value = bottom;\r
+                mainWindow.PictureSettings.crop_left.Value = left;\r
+                mainWindow.PictureSettings.crop_right.Value = right;\r
             }\r
-            \r
+\r
             // Set the anamorphic mode 0,1,2,3\r
             mainWindow.PictureSettings.drp_anamorphic.SelectedIndex = presetQuery.AnamorphicMode;\r
 \r
-            // Aspect Ratio\r
-            mainWindow.PictureSettings.check_KeepAR.CheckState = presetQuery.keepDisplayAsect ? CheckState.Checked : CheckState.Unchecked;\r
-                \r
+            // Keep Aspect Ration Anamorphic Setting.\r
+            mainWindow.PictureSettings.check_KeepAR.CheckState = presetQuery.KeepDisplayAsect\r
+                                                                     ? CheckState.Checked\r
+                                                                     : CheckState.Unchecked;\r
+\r
             // Set the Width and height as Required.\r
             if (presetQuery.Width != 0)\r
                 mainWindow.PictureSettings.text_width.Value = presetQuery.Width;\r
@@ -122,24 +127,33 @@ namespace Handbrake.Functions
                 if (mainWindow.selectedTitle != null && mainWindow.selectedTitle.Resolution.Width != 0)\r
                     mainWindow.PictureSettings.text_width.Value = mainWindow.selectedTitle.Resolution.Width;\r
 \r
+            // Aspect Ratio for non anamorphic sources\r
+            if (presetQuery.AnamorphicMode == 0)\r
+                mainWindow.PictureSettings.check_KeepAR.CheckState = presetQuery.Height == 0\r
+                                                                         ? CheckState.Checked\r
+                                                                         : CheckState.Unchecked;\r
+\r
             // Custom Anamorphic Controls\r
-            mainWindow.PictureSettings.updownDisplayWidth.Text = presetQuery.displayWidthValue.ToString();\r
-            mainWindow.PictureSettings.updownParHeight.Text = presetQuery.pixelAspectWidth.ToString();\r
-            mainWindow.PictureSettings.updownParWidth.Text = presetQuery.pixelAspectHeight.ToString();\r
-            mainWindow.PictureSettings.drp_modulus.SelectedItem = presetQuery.AnamorphicModulus;\r
+            mainWindow.PictureSettings.updownDisplayWidth.Text = presetQuery.DisplayWidthValue.ToString();\r
+            mainWindow.PictureSettings.updownParHeight.Text = presetQuery.PixelAspectHeight.ToString();\r
+            mainWindow.PictureSettings.updownParWidth.Text = presetQuery.PixelAspectWidth.ToString();\r
+            mainWindow.PictureSettings.drp_modulus.SelectedItem = presetQuery.AnamorphicModulus.ToString();\r
 \r
             #endregion\r
 \r
             #region Filters\r
-            mainWindow.Filters.setDecomb(presetQuery.Decomb);\r
-            mainWindow.Filters.setDeInterlace(presetQuery.DeInterlace);\r
-            mainWindow.Filters.setDeNoise(presetQuery.DeNoise);\r
-            mainWindow.Filters.setDeTelecine(presetQuery.DeTelecine);\r
-            mainWindow.Filters.setDeBlock(presetQuery.DeBlock);\r
-            mainWindow.Filters.setGrayScale(presetQuery.Grayscale);\r
+\r
+            mainWindow.Filters.SetDecomb(presetQuery.Decomb);\r
+            mainWindow.Filters.SetDeInterlace(presetQuery.DeInterlace);\r
+            mainWindow.Filters.SetDeNoise(presetQuery.DeNoise);\r
+            mainWindow.Filters.SetDeTelecine(presetQuery.DeTelecine);\r
+            mainWindow.Filters.SetDeBlock(presetQuery.DeBlock);\r
+            mainWindow.Filters.SetGrayScale(presetQuery.Grayscale);\r
+\r
             #endregion\r
 \r
             #region Video\r
+\r
             mainWindow.drp_videoEncoder.Text = presetQuery.VideoEncoder;\r
 \r
             if (presetQuery.AverageVideoBitrate != null)\r
@@ -154,44 +168,16 @@ namespace Handbrake.Functions
             }\r
 \r
             // Quality\r
-            if (presetQuery.VideoQuality != 0)\r
+            if (presetQuery.VideoQuality != -1)\r
             {\r
                 mainWindow.radio_cq.Checked = true;\r
-                if (presetQuery.VideoEncoder == "H.264 (x264)")\r
-                {\r
-                    double cqStep = Properties.Settings.Default.x264cqstep;\r
-                    int value;\r
-                    double x264step = cqStep;\r
-                    double presetValue = presetQuery.VideoQuality;\r
-\r
-                    double x = 51 / x264step;\r
-\r
-                    double calculated = presetValue / x264step;\r
-                    calculated = x - calculated;\r
-\r
-                    int.TryParse(calculated.ToString(), out value);\r
-\r
-                    // This will sometimes occur when the preset was generated \r
-                    // with a different granularity, so, round and try again.\r
-                    if (value == 0)\r
-                    {\r
-                        double val = Math.Round(calculated, 0);\r
-                        int.TryParse(val.ToString(), out value);\r
-                    }\r
-                    if (value < mainWindow.slider_videoQuality.Maximum)\r
-                        mainWindow.slider_videoQuality.Value = value;\r
-                }\r
-                else\r
-                {\r
-                    int presetVal;\r
-                    int.TryParse(presetQuery.VideoQuality.ToString(), out presetVal);\r
-                    mainWindow.slider_videoQuality.Value = presetVal;\r
-                }\r
+                mainWindow.slider_videoQuality.Value = QualityToSliderValue(presetQuery.VideoEncoder, presetQuery.VideoQuality);\r
             }\r
 \r
             mainWindow.check_2PassEncode.CheckState = presetQuery.TwoPass ? CheckState.Checked : CheckState.Unchecked;\r
 \r
             mainWindow.drp_videoFramerate.Text = presetQuery.VideoFramerate;\r
+            mainWindow.checkMaximumFramerate.Checked = presetQuery.Pfr;\r
 \r
             mainWindow.check_turbo.CheckState = presetQuery.TurboFirstPass ? CheckState.Checked : CheckState.Unchecked;\r
 \r
@@ -210,33 +196,45 @@ namespace Handbrake.Functions
             #endregion\r
 \r
             #region Audio\r
-            // Clear the audio listing\r
-            mainWindow.AudioSettings.ClearAudioList();\r
 \r
-            if (presetQuery.AudioInformation != null)\r
-                foreach (AudioTrack track in presetQuery.AudioInformation)\r
-                {\r
-                    ListViewItem newTrack = new ListViewItem(mainWindow.AudioSettings.GetNewID().ToString());\r
-\r
-                    newTrack.SubItems.Add("Automatic");\r
-                    newTrack.SubItems.Add(track.Encoder);\r
-                    newTrack.SubItems.Add(track.MixDown);\r
-                    newTrack.SubItems.Add(track.SampleRate);\r
-                    if (track.Encoder.Contains("AC3"))\r
-                        newTrack.SubItems.Add("Auto");\r
-                    else\r
-                        newTrack.SubItems.Add(track.Bitrate);\r
-                    newTrack.SubItems.Add(track.DRC);\r
-                    mainWindow.AudioSettings.AddTrackForPreset(newTrack);\r
-                }\r
+            mainWindow.AudioSettings.LoadTracks(presetQuery.AudioInformation);\r
+\r
             #endregion\r
 \r
             #region Other\r
-            mainWindow.x264Panel.x264Query = presetQuery.H264Query;\r
+\r
+            mainWindow.x264Panel.X264Query = presetQuery.H264Query;\r
 \r
             // Set the preset name\r
             mainWindow.labelPreset.Text = "Output Settings (Preset: " + name + ")";\r
+\r
             #endregion\r
         }\r
+\r
+        /// <summary>\r
+        /// Convert a Quality Value to a position value for the Video Quality slider\r
+        /// </summary>\r
+        /// <param name="videoEncoder">The selected video encoder</param>\r
+        /// <param name="value">The Quality value</param>\r
+        /// <returns>The position on the video quality slider</returns>\r
+        private static int QualityToSliderValue(string videoEncoder, float value)\r
+        {\r
+            int sliderValue = 0;\r
+            switch (videoEncoder)\r
+            {\r
+                case "MPEG-4 (FFmpeg)":\r
+                    sliderValue = 32 - (int)value;\r
+                    break;\r
+                case "H.264 (x264)":\r
+                    double cqStep = Properties.Settings.Default.x264cqstep;\r
+                    sliderValue = (int)((51.0 / cqStep) - (value / cqStep));\r
+                    break;\r
+                case "VP3 (Theora)":\r
+                    sliderValue = (int)value;\r
+                    break;\r
+            }\r
+\r
+            return sliderValue;\r
+        }\r
     }\r
 }
\ No newline at end of file