It may be used under the terms of the GNU General Public License. */\r
\r
using System;\r
+using System.Linq;\r
using System.Windows.Forms;\r
\r
namespace Handbrake.Controls\r
public AudioPanel()\r
{\r
InitializeComponent();\r
- drp_audioMix.SelectedIndex = 0;\r
+ drp_audioMix.SelectedItem = "Dolby Pro Logic II";\r
+ drp_audioSample.SelectedIndex = 1;\r
}\r
\r
- // Audio Track Options\r
- private void drp_audioTrack_SelectedIndexChanged(object sender, EventArgs e)\r
- {\r
- if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)\r
- {\r
- lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[1].Text = drp_audioTrack.Text;\r
- lv_audioList.Select();\r
- }\r
- }\r
- private void drp_audenc_SelectedIndexChanged(object sender, EventArgs e)\r
+ // Control and ListView\r
+ private void controlChanged(object sender, EventArgs e)\r
{\r
- // Setup the widgets with the correct avail options\r
- if (drp_audioEncoder.Text.Contains("AAC"))\r
- {\r
- setMixDown(true);\r
- setBitrate(160);\r
- }\r
- else\r
- {\r
- setMixDown(false);\r
- setBitrate(320);\r
- }\r
+ Control ctl = (Control)sender;\r
\r
- // Configure the widgets with values\r
- if (drp_audioEncoder.Text.Contains("AC3") || drp_audioEncoder.Text.Contains("DTS"))\r
+ switch (ctl.Name)\r
{\r
- drp_audioMix.Enabled = false;\r
- drp_audioBitrate.Enabled = false;\r
- drp_audioSample.Enabled = false;\r
- tb_drc.Enabled = false;\r
-\r
- lbl_bitrate.Enabled = false;\r
- lbl_drc.Enabled = false;\r
- lbl_drcHeader.Enabled = false;\r
- lbl_mixdown.Enabled = false;\r
- lbl_sampleRate.Enabled = false;\r
-\r
- drp_audioBitrate.SelectedIndex = 0;\r
- drp_audioSample.SelectedIndex = 0;\r
- drp_audioMix.Items.Add("AC3 Passthru");\r
- drp_audioMix.Items.Add("DTS Passthru");\r
-\r
- if (drp_audioEncoder.Text.Contains("AC3"))\r
- drp_audioMix.SelectedItem = "AC3 Passthru";\r
- else\r
- drp_audioMix.SelectedItem = "DTS Passthru";\r
+ case "drp_audioTrack":\r
+ if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)\r
+ lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[1].Text = drp_audioTrack.Text;\r
+ break;\r
+ case "drp_audioEncoder":\r
+ SetMixDown();\r
+ SetBitrate();\r
+\r
+ // Configure the widgets with values\r
+ if (drp_audioEncoder.Text.Contains("AC3") || drp_audioEncoder.Text.Contains("DTS"))\r
+ {\r
+ drp_audioMix.Enabled = drp_audioBitrate.Enabled = drp_audioSample.Enabled = tb_drc.Enabled = false;\r
+ lbl_bitrate.Enabled = lbl_drc.Enabled = lbl_drcHeader.Enabled = lbl_mixdown.Enabled = lbl_sampleRate.Enabled = false;\r
+ }\r
+ else\r
+ {\r
+ drp_audioMix.Enabled = drp_audioBitrate.Enabled = drp_audioSample.Enabled = tb_drc.Enabled = true;\r
+ lbl_bitrate.Enabled = lbl_drc.Enabled = lbl_drcHeader.Enabled = lbl_mixdown.Enabled = lbl_sampleRate.Enabled = true;\r
+ }\r
\r
- drp_audioBitrate.Items.Add("Auto");\r
- drp_audioBitrate.SelectedItem = "Auto";\r
- tb_drc.Value = 0;\r
- }\r
- else\r
- {\r
- drp_audioMix.Enabled = true;\r
- drp_audioBitrate.Enabled = true;\r
- drp_audioSample.Enabled = true;\r
- tb_drc.Enabled = true;\r
-\r
- lbl_bitrate.Enabled = true;\r
- lbl_drc.Enabled = true;\r
- lbl_drcHeader.Enabled = true;\r
- lbl_mixdown.Enabled = true;\r
- lbl_sampleRate.Enabled = true;\r
-\r
- drp_audioMix.Items.Remove("AC3 Passthru");\r
- drp_audioMix.Items.Remove("DTS Passthru");\r
- drp_audioBitrate.Items.Remove("Auto");\r
-\r
- drp_audioMix.SelectedIndex = 0;\r
- drp_audioBitrate.SelectedIndex = 9;\r
- drp_audioSample.SelectedIndex = 0;\r
- }\r
+ // Update an item in the Audio list if required.\r
+ if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)\r
+ lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[2].Text = drp_audioEncoder.Text;\r
+ break;\r
+ case "drp_audioMix":\r
+ SetBitrate();\r
+\r
+ if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)\r
+ lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[3].Text = drp_audioMix.Text;\r
+ break;\r
+ case "drp_audioSample":\r
+ if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)\r
+ lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[4].Text = drp_audioSample.Text;\r
+ break;\r
+ case "drp_audioBitrate":\r
+ // Update an item in the Audio list if required.\r
+ if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)\r
+ lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[5].Text = drp_audioBitrate.Text;\r
+ break;\r
+ case "tb_drc":\r
+ double value;\r
+ if (tb_drc.Value == 0) value = 0;\r
+ else\r
+ value = ((tb_drc.Value - 1) / 10.0) + 1;\r
\r
- // Update an item in the Audio list if required.\r
- if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)\r
- {\r
- lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[2].Text = drp_audioEncoder.Text;\r
- if (drp_audioEncoder.Text.Contains("AC3"))\r
- {\r
- lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[3].Text = "AC3 Passthru";\r
- lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[4].Text = "Auto";\r
- lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[5].Text = "Auto";\r
- lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[6].Text = "0.0";\r
- }\r
- lv_audioList.Select();\r
- }\r
- }\r
- private void drp_audmix_SelectedIndexChanged(object sender, EventArgs e)\r
- {\r
- if ((drp_audioEncoder.Text.Contains("AAC")) && (drp_audioMix.Text == "6 Channel Discrete"))\r
- setBitrate(384);\r
- else if ((drp_audioEncoder.Text.Contains("AAC")) && (drp_audioMix.Text != "6 Channel Discrete"))\r
- setBitrate(160);\r
+ lbl_drc.Text = value.ToString();\r
\r
- // Update an item in the Audio list if required.\r
- if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)\r
- {\r
- lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[3].Text = drp_audioMix.Text;\r
- lv_audioList.Select();\r
- }\r
- }\r
- private void drp_audsr_SelectedIndexChanged(object sender, EventArgs e)\r
- {\r
- // Update an item in the Audio list if required.\r
- if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)\r
- {\r
- lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[4].Text = drp_audioSample.Text;\r
- lv_audioList.Select();\r
+ // Update an item in the Audio list if required.\r
+ if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)\r
+ {\r
+ lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[6].Text = value.ToString();\r
+ lv_audioList.Select();\r
+ }\r
+ break;\r
}\r
+\r
+ lv_audioList.Select();\r
}\r
- private void drp_audbit_SelectedIndexChanged(object sender, EventArgs e)\r
+ private void lv_audioList_SelectedIndexChanged(object sender, EventArgs e)\r
{\r
- // Update an item in the Audio list if required.\r
+ // Set the dropdown controls based on the selected item in the Audio List.\r
if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)\r
{\r
- if (drp_audioEncoder.Text.Contains("AC3"))\r
- drp_audioBitrate.SelectedItem = "Auto";\r
- lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[5].Text = drp_audioBitrate.Text;\r
- lv_audioList.Select();\r
- }\r
- }\r
- private void tb_drc_Scroll(object sender, EventArgs e)\r
- {\r
- double value;\r
- if (tb_drc.Value == 0) value = 0;\r
- else\r
- value = ((tb_drc.Value - 1) / 10.0) + 1;\r
-\r
- lbl_drc.Text = value.ToString();\r
+ drp_audioTrack.SelectedItem = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[1].Text;\r
+ drp_audioEncoder.SelectedItem = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[2].Text;\r
+ drp_audioMix.SelectedItem = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[3].Text;\r
+ drp_audioSample.SelectedItem = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[4].Text;\r
+ drp_audioBitrate.SelectedItem = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[5].Text;\r
+ double drcValue; 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
+ 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
\r
- // Update an item in the Audio list if required.\r
- if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)\r
- {\r
- lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[6].Text = value.ToString();\r
- lv_audioList.Select();\r
+ AudioTrackGroup.Text = "Selected Track: " + lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[0].Text;\r
}\r
+ else\r
+ AudioTrackGroup.Text = "Selected Track: None (Click \"Add Track\" to add)";\r
}\r
\r
// Track Controls\r
}\r
private void btn_RemoveAudioTrack_Click(object sender, EventArgs e)\r
{\r
- RemoveAudioTrack();\r
+ RemoveTrack();\r
}\r
\r
// Audio List Menu\r
private void audioList_moveup_Click(object sender, EventArgs e)\r
{\r
- if (lv_audioList.SelectedIndices.Count != 0)\r
- {\r
- ListViewItem item = lv_audioList.SelectedItems[0];\r
- int index = item.Index;\r
- index--;\r
-\r
- if (lv_audioList.Items.Count > index && index >= 0)\r
- {\r
- lv_audioList.Items.Remove(item);\r
- lv_audioList.Items.Insert(index, item);\r
- item.Selected = true;\r
- lv_audioList.Focus();\r
- }\r
- }\r
+ MoveTrack(true);\r
}\r
private void audioList_movedown_Click(object sender, EventArgs e)\r
{\r
- if (lv_audioList.SelectedIndices.Count != 0)\r
- {\r
- ListViewItem item = lv_audioList.SelectedItems[0];\r
- int index = item.Index;\r
- index++;\r
-\r
- if (index < lv_audioList.Items.Count)\r
- {\r
- lv_audioList.Items.Remove(item);\r
- lv_audioList.Items.Insert(index, item);\r
- item.Selected = true;\r
- lv_audioList.Focus();\r
- }\r
- }\r
+ MoveTrack(false);\r
}\r
private void audioList_remove_Click(object sender, EventArgs e)\r
{\r
- RemoveAudioTrack();\r
- }\r
- private void RemoveAudioTrack()\r
- {\r
- // Remove the Item and reselect the control if the following conditions are met.\r
- if (lv_audioList.SelectedItems.Count != 0)\r
- {\r
- // The Audio List is about to change so raise the event.\r
- if (this.AudioListChanged != null)\r
- this.AudioListChanged(this, new EventArgs());\r
-\r
- // Record the current selected index.\r
- int currentPosition = lv_audioList.SelectedIndices[0];\r
-\r
- lv_audioList.Items.RemoveAt(lv_audioList.SelectedIndices[0]);\r
-\r
- // Now reslect the correct item and give focus to the audio list.\r
- if (lv_audioList.Items.Count != 0)\r
- {\r
- if (currentPosition <= (lv_audioList.Items.Count - 1))\r
- lv_audioList.Items[currentPosition].Selected = true;\r
- else if (currentPosition > (lv_audioList.Items.Count - 1))\r
- lv_audioList.Items[lv_audioList.Items.Count - 1].Selected = true;\r
-\r
- lv_audioList.Select();\r
- }\r
- // Regenerate the ID numers\r
- reGenerateListIDs();\r
- }\r
+ RemoveTrack();\r
}\r
\r
// Public Functions\r
}\r
public Boolean RequiresM4V()\r
{\r
- foreach (ListViewItem item in lv_audioList.Items)\r
+ return lv_audioList.Items.Cast<ListViewItem>().Any(item => item.SubItems[2].Text.Contains("AC3"));\r
+ }\r
+\r
+ // Helper Functions \r
+ private void RemoveTrack()\r
+ {\r
+ // Remove the Item and reselect the control if the following conditions are met.\r
+ if (lv_audioList.SelectedItems.Count != 0)\r
+ {\r
+ // The Audio List is about to change so raise the event.\r
+ if (this.AudioListChanged != null)\r
+ this.AudioListChanged(this, new EventArgs());\r
+\r
+ // Record the current selected index.\r
+ int currentPosition = lv_audioList.SelectedIndices[0];\r
+\r
+ lv_audioList.Items.RemoveAt(lv_audioList.SelectedIndices[0]);\r
+\r
+ // Now reslect the correct item and give focus to the audio list.\r
+ if (lv_audioList.Items.Count != 0)\r
+ {\r
+ if (currentPosition <= (lv_audioList.Items.Count - 1))\r
+ lv_audioList.Items[currentPosition].Selected = true;\r
+ else if (currentPosition > (lv_audioList.Items.Count - 1))\r
+ lv_audioList.Items[lv_audioList.Items.Count - 1].Selected = true;\r
+\r
+ lv_audioList.Select();\r
+ }\r
+ // Regenerate the ID numers\r
+ ReGenerateListIDs();\r
+ }\r
+ }\r
+ private void MoveTrack(bool up)\r
+ {\r
+ if (lv_audioList.SelectedIndices.Count == 0) return;\r
+\r
+ ListViewItem item = lv_audioList.SelectedItems[0];\r
+ int index = item.Index;\r
+\r
+ if (up) index--; else index++;\r
+\r
+ if (index < lv_audioList.Items.Count || (lv_audioList.Items.Count > index && index >= 0))\r
{\r
- if (item.SubItems[2].Text.Contains("AC3"))\r
- return true;\r
+ lv_audioList.Items.Remove(item);\r
+ lv_audioList.Items.Insert(index, item);\r
+ item.Selected = true;\r
+ lv_audioList.Focus();\r
}\r
- return false;\r
}\r
\r
- // Helper Functions \r
- private void reGenerateListIDs()\r
+ private void ReGenerateListIDs()\r
{\r
int i = 1;\r
foreach (ListViewItem item in lv_audioList.Items)\r
i++;\r
}\r
}\r
- private void setBitrate(int max)\r
+ private void SetBitrate()\r
{\r
+ int max = 0;\r
+ drp_audioBitrate.Items.Remove("Auto");\r
+ drp_audioBitrate.Items.Remove("192");\r
+ drp_audioBitrate.Items.Remove("224");\r
+ drp_audioBitrate.Items.Remove("256");\r
+ drp_audioBitrate.Items.Remove("320");\r
+\r
+ switch (drp_audioEncoder.Text)\r
+ {\r
+ case "AAC (faac)":\r
+ max = drp_audioMix.Text.Contains("6 Channel") ? 384 : 160;\r
+ break;\r
+ case "MP3 (lame)":\r
+ max = 320;\r
+ break;\r
+ case "Vorbis (vorbis)":\r
+ max = 384;\r
+ break;\r
+ case "AC3 Passthru":\r
+ drp_audioBitrate.Items.Add("Auto");\r
+ drp_audioBitrate.SelectedItem = "Auto";\r
+ drp_audioSample.SelectedItem = "Auto";\r
+ break;\r
+ case "DTS Passthru":\r
+ drp_audioBitrate.Items.Add("Auto");\r
+ drp_audioBitrate.SelectedItem = "Auto";\r
+ drp_audioSample.SelectedItem = "Auto";\r
+ break;\r
+ }\r
+\r
if (max > 160)\r
{\r
drp_audioBitrate.Items.Add("192");\r
drp_audioBitrate.Items.Remove("320");\r
drp_audioBitrate.Items.Remove("384");\r
}\r
+\r
if (drp_audioBitrate.SelectedItem == null)\r
drp_audioBitrate.SelectedIndex = drp_audioBitrate.Items.Count - 1;\r
}\r
- private void setMixDown(Boolean aac)\r
+ private void SetMixDown()\r
{\r
drp_audioMix.Items.Clear();\r
- drp_audioMix.Items.Add("Automatic");\r
- if (aac)\r
- drp_audioMix.Items.Add("Mono");\r
+ drp_audioMix.Items.Add("Mono");\r
drp_audioMix.Items.Add("Stereo");\r
drp_audioMix.Items.Add("Dolby Surround");\r
drp_audioMix.Items.Add("Dolby Pro Logic II");\r
- if (aac)\r
- drp_audioMix.Items.Add("6 Channel Discrete");\r
- }\r
- private void lv_audioList_SelectedIndexChanged(object sender, EventArgs e)\r
- {\r
- // Set the dropdown controls based on the selected item in the Audio List.\r
- if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)\r
- {\r
- drp_audioTrack.SelectedItem = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[1].Text;\r
- drp_audioEncoder.SelectedItem = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[2].Text;\r
- drp_audioMix.SelectedItem = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[3].Text;\r
- drp_audioSample.SelectedItem = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[4].Text;\r
- drp_audioBitrate.SelectedItem = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[5].Text;\r
- double drcValue; int drcCalculated;\r
- double.TryParse(lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[6].Text, out drcValue);\r
- if (drcValue == 0) drcCalculated = 0;\r
- else\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
+ drp_audioMix.Items.Add("6 Channel Discrete");\r
+ drp_audioMix.Items.Add("AC3 Passthru");\r
+ drp_audioMix.Items.Add("DTS Passthru");\r
\r
- AudioTrackGroup.Text = "Selected Track: " + lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[0].Text;\r
+ drp_audioMix.SelectedItem = "Dolby Pro Logic II";\r
+\r
+ switch (drp_audioEncoder.Text)\r
+ {\r
+ case "AAC (faac)":\r
+ drp_audioMix.Items.Remove("AC3 Passthru");\r
+ drp_audioMix.Items.Remove("DTS Passthru");\r
+ break;\r
+ case "MP3 (lame)":\r
+ drp_audioMix.Items.Remove("Mono");\r
+ drp_audioMix.Items.Remove("6 Channel Discrete");\r
+ drp_audioMix.Items.Remove("AC3 Passthru");\r
+ drp_audioMix.Items.Remove("DTS Passthru");\r
+ break;\r
+ case "Vorbis (vorbis)":\r
+ drp_audioMix.Items.Remove("AC3 Passthru");\r
+ drp_audioMix.Items.Remove("DTS Passthru");\r
+ break;\r
+ case "AC3 Passthru":\r
+ drp_audioMix.SelectedItem = "AC3 Passthru";\r
+ break;\r
+ case "DTS Passthru":\r
+ drp_audioMix.SelectedItem = "DTS Passthru";\r
+ break;\r
}\r
- else\r
- AudioTrackGroup.Text = "Selected Track: None (Click \"Add Track\" to add)";\r
}\r
}\r
}
\ No newline at end of file