using System.Collections;\r
using System.Linq;\r
using System.Windows.Forms;\r
+ using Functions;\r
using Parsing;\r
+ using Presets;\r
using AudioTrack = Model.AudioTrack;\r
\r
public partial class AudioPanel : UserControl\r
/// Set the Track list dropdown from the parsed title captured during the scan\r
/// </summary>\r
/// <param name="selectedTitle"></param>\r
- public void SetTrackList(Title selectedTitle)\r
+ public void SetTrackList(Title selectedTitle, Preset preset)\r
{\r
- drp_audioTrack.Items.Clear();\r
- drp_audioTrack.Items.Add("Automatic");\r
- drp_audioTrack.Items.Add("None");\r
- drp_audioTrack.Items.AddRange(selectedTitle.AudioTracks.ToArray());\r
+ if (selectedTitle.AudioTracks.Count == 0)\r
+ {\r
+ lv_audioList.Items.Clear();\r
+ drp_audioTrack.Items.Clear();\r
+ drp_audioTrack.Items.Add("None Found");\r
+ drp_audioTrack.SelectedIndex = 0;\r
+ return;\r
+ }\r
+ else\r
+ {\r
+ drp_audioTrack.Items.Clear();\r
+ drp_audioTrack.Items.Add("Automatic");\r
+ drp_audioTrack.Items.AddRange(selectedTitle.AudioTracks.ToArray());\r
+\r
+ if (lv_audioList.Items.Count == 0 && preset != null)\r
+ {\r
+ QueryParser parsed = QueryParser.Parse(preset.Query);\r
+ foreach (AudioTrack audioTrack in parsed.AudioInformation)\r
+ {\r
+ ListViewItem newTrack = new ListViewItem(GetNewID().ToString());\r
+ newTrack.SubItems.Add(audioTrack.Track);\r
+ newTrack.SubItems.Add(audioTrack.Encoder);\r
+ newTrack.SubItems.Add(audioTrack.MixDown);\r
+ newTrack.SubItems.Add(audioTrack.SampleRate);\r
+ newTrack.SubItems.Add(audioTrack.Bitrate);\r
+ newTrack.SubItems.Add(audioTrack.DRC.ToString());\r
+ lv_audioList.Items.Add(newTrack);\r
+ }\r
+ }\r
+\r
+ }\r
\r
// Handle Native Language and "Dub Foreign language audio" and "Use Foreign language audio and Subtitles" Options\r
if (Properties.Settings.Default.NativeLanguage == "Any")\r
- drp_audioTrack.SelectedIndex = drp_audioTrack.Items.Count >= 3 ? 2 : 0;\r
+ drp_audioTrack.SelectedIndex = drp_audioTrack.Items.Count >= 2 ? 1 : 0;\r
else\r
{\r
if (Properties.Settings.Default.DubAudio) // "Dub Foreign language audio" \r
}\r
else\r
drp_audioTrack.SelectedIndex = drp_audioTrack.Items.Count >= 3 ? 2 : 0;\r
- // "Use Foreign language audio and Subtitles"\r
+ // "Use Foreign language audio and Subtitles"\r
}\r
}\r
\r
// Control and ListView\r
private void controlChanged(object sender, EventArgs e)\r
{\r
- Control ctl = (Control) sender;\r
+ Control ctl = (Control)sender;\r
\r
switch (ctl.Name)\r
{\r
double value;\r
if (tb_drc.Value == 0) value = 0;\r
else\r
- value = ((tb_drc.Value - 1)/10.0) + 1;\r
+ value = ((tb_drc.Value - 1) / 10.0) + 1;\r
\r
lbl_drc.Text = value.ToString();\r
\r
int drcCalculated;\r
double.TryParse(lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[6].Text, out drcValue);\r
if (drcValue != 0)\r
- drcValue = ((drcValue*10) + 1) - 10;\r
+ drcValue = ((drcValue * 10) + 1) - 10;\r
int.TryParse(drcValue.ToString(), out drcCalculated);\r
tb_drc.Value = drcCalculated;\r
lbl_drc.Text = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[6].Text;\r
// Track Controls\r
private void btn_addAudioTrack_Click(object sender, EventArgs e)\r
{\r
+ if (drp_audioTrack.Text == "None Found")\r
+ {\r
+ MessageBox.Show("Your source appears to have no audio tracks that HandBrake supports.", "Warning",\r
+ MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
+ return;\r
+ }\r
+\r
double value = 0;\r
if (tb_drc.Value != 0)\r
- value = ((tb_drc.Value - 1)/10.0) + 1;\r
+ value = ((tb_drc.Value - 1) / 10.0) + 1;\r
\r
// Create a new row for the Audio list based on the currently selected items in the dropdown.\r
ListViewItem newTrack = new ListViewItem(GetNewID().ToString());\r
if (!root.HasChildNodes)\r
{\r
MessageBox.Show(\r
- "The Preset file you selected appears to be invlaid or from an older version of HandBrake", \r
- "Error", \r
+ "The Preset file you selected appears to be invlaid or from an older version of HandBrake",\r
+ "Error",\r
MessageBoxButtons.OK, MessageBoxIcon.Error);\r
return null;\r
}\r
catch (Exception)\r
{\r
MessageBox.Show(\r
- "The Preset file you selected appears to be invlaid or from an older version of HandBrake.\n\n Please note, if you are exporting from the MacGui you may need to rebuild your preset so that it uses the current preset plist format.\n The MacGui does not currently update user presets automatically.", \r
- "Error", \r
+ "The Preset file you selected appears to be invlaid or from an older version of HandBrake.\n\n Please note, if you are exporting from the MacGui you may need to rebuild your preset so that it uses the current preset plist format.\n The MacGui does not currently update user presets automatically.",\r
+ "Error",\r
MessageBoxButtons.OK, MessageBoxIcon.Error);\r
}\r
\r
// We'll query a query parser object and use it's public var structures to store all the data.\r
// This will allow the preset loader logic to be used instead of writing custom logic just for this file.\r
QueryParser queryParsed = new QueryParser();\r
-\r
+ string QualityMode = string.Empty;\r
/***** Get the Audio Tracks *****/\r
XmlNode audioListDict = root.ChildNodes[2].ChildNodes[0].FirstChild.ChildNodes[1];\r
ArrayList AudioInfo = new ArrayList();\r
/***** Get the rest of the settings. *****/\r
XmlNode presetSettings = root.ChildNodes[2].ChildNodes[0].FirstChild;\r
for (int i = 2; i < presetSettings.ChildNodes.Count; i += 2)\r
- // Start from 2 to avoid the audio settings which we don't need.\r
+ // Start from 2 to avoid the audio settings which we don't need.\r
{\r
string key = presetSettings.ChildNodes[i].InnerText;\r
string value = presetSettings.ChildNodes[i + 1].InnerText;\r
\r
switch (key)\r
{\r
- // Output Settings\r
+ // Output Settings\r
case "FileFormat":\r
queryParsed.Format = value;\r
break;\r
queryParsed.IpodAtom = value == "1";\r
break;\r
\r
- // Picture Settings\r
+ // Picture Settings\r
case "PictureAutoCrop":\r
break;\r
case "PictureTopCrop":\r
break;\r
\r
\r
- // Filters\r
+ // Filters\r
case "PictureDeblock":\r
queryParsed.DeBlock = int.Parse(value);\r
break;\r
queryParsed.DeTelecine = value;\r
break;\r
\r
- // Video Tab\r
+ // Video Tab\r
case "VideoAvgBitrate":\r
- queryParsed.Width = int.Parse(value);\r
+ queryParsed.AverageVideoBitrate = value;\r
break;\r
case "VideoEncoder":\r
queryParsed.VideoEncoder = value;\r
case "VideoQualitySlider":\r
queryParsed.VideoQuality = float.Parse(value);\r
break;\r
- case "VideoQualityType":\r
+ case "VideoQualityType": // The Type of Quality Mode used\r
+ QualityMode = value;\r
break;\r
case "VideoTargetSize":\r
queryParsed.VideoTargetSize = value;\r
queryParsed.TwoPass = value == "1";\r
break;\r
\r
- // Chapter Markers Tab\r
+ // Chapter Markers Tab\r
case "ChapterMarkers":\r
queryParsed.ChapterMarkers = value == "1";\r
break;\r
\r
- // Advanced x264 tab\r
+ // Advanced x264 tab\r
case "x264Option":\r
queryParsed.H264Query = value;\r
break;\r
\r
- // Preset Information\r
+ // Preset Information\r
case "PresetBuildNumber":\r
queryParsed.PresetBuildNumber = int.Parse(value);\r
break;\r
break;\r
}\r
}\r
+\r
+ // Kill any Quality values we don't need.\r
+ switch (QualityMode)\r
+ {\r
+ case "0": // FileSize\r
+ queryParsed.VideoQuality = -1;\r
+ queryParsed.AverageVideoBitrate = null;\r
+ break;\r
+ case "1": // Avg Bitrate\r
+ queryParsed.VideoQuality = -1;\r
+ queryParsed.VideoTargetSize = null;\r
+ break;\r
+ case "2": // CQ\r
+ queryParsed.AverageVideoBitrate = null;\r
+ queryParsed.VideoTargetSize = null;\r
+ break;\r
+ }\r
+\r
return queryParsed;\r
}\r
\r
\r
// Header\r
Writer.WriteStartDocument();\r
- Writer.WriteDocType("plist", "-//Apple//DTD PLIST 1.0//EN", \r
+ Writer.WriteDocType("plist", "-//Apple//DTD PLIST 1.0//EN",\r
@"http://www.apple.com/DTDs/PropertyList-1.0.dtd", null);\r
\r
Writer.WriteStartElement("plist");\r
\r
private void mnu_importMacPreset_Click(object sender, EventArgs e)\r
{\r
- importPreset();\r
+ ImportPreset();\r
}\r
\r
private void btn_new_preset_Click(object sender, EventArgs e)\r
\r
private void pmnu_import_Click(object sender, EventArgs e)\r
{\r
- importPreset();\r
+ ImportPreset();\r
}\r
\r
private void pmnu_saveChanges_Click(object sender, EventArgs e)\r
}\r
}\r
\r
- private void importPreset()\r
+ private void ImportPreset()\r
{\r
if (openPreset.ShowDialog() == DialogResult.OK)\r
{\r
else\r
{\r
PresetLoader.LoadPreset(this, parsed, parsed.PresetName, parsed.UsesPictureSettings);\r
- presetHandler.Add(parsed.PresetName,\r
- QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null),\r
- parsed.UsesPictureSettings);\r
-\r
if (presetHandler.Add(parsed.PresetName + " (Imported)",\r
QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null),\r
parsed.UsesPictureSettings))\r
drop_chapterFinish.Items.Clear();\r
\r
// If the dropdown is set to automatic nothing else needs to be done.\r
- // Otheriwse if its not, title data has to be loased from parsing.\r
+ // Otheriwse if its not, title data has to be loaded from parsing.\r
if (drp_dvdtitle.Text != "Automatic")\r
{\r
selectedTitle = drp_dvdtitle.SelectedItem as Title;\r
drop_chapterFinish.Text = drop_chapterFinish.Items[drop_chapterFinish.Items.Count - 1].ToString();\r
\r
// Populate the Audio Channels Dropdown\r
- AudioSettings.SetTrackList(selectedTitle);\r
+ AudioSettings.SetTrackList(selectedTitle, CurrentlySelectedPreset);\r
\r
// Populate the Subtitles dropdown\r
Subtitles.SetSubtitleTrackAuto(selectedTitle.Subtitles.ToArray());\r