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.Windows.Forms;
\r
10 namespace Handbrake.Controls
\r
12 public partial class AudioPanel : UserControl
\r
14 public event EventHandler AudioListChanged;
\r
18 InitializeComponent();
\r
19 drp_audioMix.SelectedIndex = 0;
\r
22 // Audio Track Options
\r
23 private void drp_audioTrack_SelectedIndexChanged(object sender, EventArgs e)
\r
25 if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)
\r
27 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[1].Text = drp_audioTrack.Text;
\r
28 lv_audioList.Select();
\r
31 private void drp_audenc_SelectedIndexChanged(object sender, EventArgs e)
\r
33 // Setup the widgets with the correct avail options
\r
34 if (drp_audioEncoder.Text.Contains("AAC"))
\r
45 // Configure the widgets with values
\r
46 if (drp_audioEncoder.Text.Contains("AC3") || drp_audioEncoder.Text.Contains("DTS"))
\r
48 drp_audioMix.Enabled = false;
\r
49 drp_audioBitrate.Enabled = false;
\r
50 drp_audioSample.Enabled = false;
\r
51 tb_drc.Enabled = false;
\r
53 lbl_bitrate.Enabled = false;
\r
54 lbl_drc.Enabled = false;
\r
55 lbl_drcHeader.Enabled = false;
\r
56 lbl_mixdown.Enabled = false;
\r
57 lbl_sampleRate.Enabled = false;
\r
59 drp_audioBitrate.SelectedIndex = 0;
\r
60 drp_audioSample.SelectedIndex = 0;
\r
61 drp_audioMix.Items.Add("AC3 Passthru");
\r
62 drp_audioMix.Items.Add("DTS Passthru");
\r
64 if (drp_audioEncoder.Text.Contains("AC3"))
\r
65 drp_audioMix.SelectedItem = "AC3 Passthru";
\r
67 drp_audioMix.SelectedItem = "DTS Passthru";
\r
69 drp_audioBitrate.Items.Add("Auto");
\r
70 drp_audioBitrate.SelectedItem = "Auto";
\r
75 drp_audioMix.Enabled = true;
\r
76 drp_audioBitrate.Enabled = true;
\r
77 drp_audioSample.Enabled = true;
\r
78 tb_drc.Enabled = true;
\r
80 lbl_bitrate.Enabled = true;
\r
81 lbl_drc.Enabled = true;
\r
82 lbl_drcHeader.Enabled = true;
\r
83 lbl_mixdown.Enabled = true;
\r
84 lbl_sampleRate.Enabled = true;
\r
86 drp_audioMix.Items.Remove("AC3 Passthru");
\r
87 drp_audioMix.Items.Remove("DTS Passthru");
\r
88 drp_audioBitrate.Items.Remove("Auto");
\r
90 drp_audioMix.SelectedIndex = 0;
\r
91 drp_audioBitrate.SelectedIndex = 9;
\r
92 drp_audioSample.SelectedIndex = 0;
\r
95 // Update an item in the Audio list if required.
\r
96 if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)
\r
98 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[2].Text = drp_audioEncoder.Text;
\r
99 if (drp_audioEncoder.Text.Contains("AC3"))
\r
101 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[3].Text = "AC3 Passthru";
\r
102 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[4].Text = "Auto";
\r
103 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[5].Text = "Auto";
\r
104 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[6].Text = "0.0";
\r
106 lv_audioList.Select();
\r
109 private void drp_audmix_SelectedIndexChanged(object sender, EventArgs e)
\r
111 if ((drp_audioEncoder.Text.Contains("AAC")) && (drp_audioMix.Text == "6 Channel Discrete"))
\r
113 else if ((drp_audioEncoder.Text.Contains("AAC")) && (drp_audioMix.Text != "6 Channel Discrete"))
\r
116 // Update an item in the Audio list if required.
\r
117 if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)
\r
119 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[3].Text = drp_audioMix.Text;
\r
120 lv_audioList.Select();
\r
123 private void drp_audsr_SelectedIndexChanged(object sender, EventArgs e)
\r
125 // Update an item in the Audio list if required.
\r
126 if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)
\r
128 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[4].Text = drp_audioSample.Text;
\r
129 lv_audioList.Select();
\r
132 private void drp_audbit_SelectedIndexChanged(object sender, EventArgs e)
\r
134 // Update an item in the Audio list if required.
\r
135 if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)
\r
137 if (drp_audioEncoder.Text.Contains("AC3"))
\r
138 drp_audioBitrate.SelectedItem = "Auto";
\r
139 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[5].Text = drp_audioBitrate.Text;
\r
140 lv_audioList.Select();
\r
143 private void tb_drc_Scroll(object sender, EventArgs e)
\r
146 if (tb_drc.Value == 0) value = 0;
\r
148 value = ((tb_drc.Value - 1) / 10.0) + 1;
\r
150 lbl_drc.Text = value.ToString();
\r
152 // Update an item in the Audio list if required.
\r
153 if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)
\r
155 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[6].Text = value.ToString();
\r
156 lv_audioList.Select();
\r
161 private void btn_addAudioTrack_Click(object sender, EventArgs e)
\r
164 if (tb_drc.Value != 0)
\r
165 value = ((tb_drc.Value - 1) / 10.0) + 1;
\r
167 // Create a new row for the Audio list based on the currently selected items in the dropdown.
\r
168 ListViewItem newTrack = new ListViewItem(GetNewID().ToString());
\r
169 newTrack.SubItems.Add(drp_audioTrack.Text);
\r
170 newTrack.SubItems.Add(drp_audioEncoder.Text);
\r
171 newTrack.SubItems.Add(drp_audioMix.Text);
\r
172 newTrack.SubItems.Add(drp_audioSample.Text);
\r
173 newTrack.SubItems.Add(drp_audioBitrate.Text);
\r
174 newTrack.SubItems.Add(value.ToString());
\r
175 lv_audioList.Items.Add(newTrack);
\r
177 // The Audio List has changed to raise the event.
\r
178 if (this.AudioListChanged != null)
\r
179 this.AudioListChanged(this, new EventArgs());
\r
181 // Select the newly added track and select the control
\r
182 lv_audioList.Items[lv_audioList.Items.Count - 1].Selected = true;
\r
183 lv_audioList.Select();
\r
185 private void btn_RemoveAudioTrack_Click(object sender, EventArgs e)
\r
187 RemoveAudioTrack();
\r
191 private void audioList_moveup_Click(object sender, EventArgs e)
\r
193 if (lv_audioList.SelectedIndices.Count != 0)
\r
195 ListViewItem item = lv_audioList.SelectedItems[0];
\r
196 int index = item.Index;
\r
199 if (lv_audioList.Items.Count > index && index >= 0)
\r
201 lv_audioList.Items.Remove(item);
\r
202 lv_audioList.Items.Insert(index, item);
\r
203 item.Selected = true;
\r
204 lv_audioList.Focus();
\r
208 private void audioList_movedown_Click(object sender, EventArgs e)
\r
210 if (lv_audioList.SelectedIndices.Count != 0)
\r
212 ListViewItem item = lv_audioList.SelectedItems[0];
\r
213 int index = item.Index;
\r
216 if (index < lv_audioList.Items.Count)
\r
218 lv_audioList.Items.Remove(item);
\r
219 lv_audioList.Items.Insert(index, item);
\r
220 item.Selected = true;
\r
221 lv_audioList.Focus();
\r
225 private void audioList_remove_Click(object sender, EventArgs e)
\r
227 RemoveAudioTrack();
\r
229 private void RemoveAudioTrack()
\r
231 // Remove the Item and reselect the control if the following conditions are met.
\r
232 if (lv_audioList.SelectedItems.Count != 0)
\r
234 // The Audio List is about to change so raise the event.
\r
235 if (this.AudioListChanged != null)
\r
236 this.AudioListChanged(this, new EventArgs());
\r
238 // Record the current selected index.
\r
239 int currentPosition = lv_audioList.SelectedIndices[0];
\r
241 lv_audioList.Items.RemoveAt(lv_audioList.SelectedIndices[0]);
\r
243 // Now reslect the correct item and give focus to the audio list.
\r
244 if (lv_audioList.Items.Count != 0)
\r
246 if (currentPosition <= (lv_audioList.Items.Count - 1))
\r
247 lv_audioList.Items[currentPosition].Selected = true;
\r
248 else if (currentPosition > (lv_audioList.Items.Count - 1))
\r
249 lv_audioList.Items[lv_audioList.Items.Count - 1].Selected = true;
\r
251 lv_audioList.Select();
\r
253 // Regenerate the ID numers
\r
254 reGenerateListIDs();
\r
258 // Public Functions
\r
259 public void SetTrackList(Parsing.Title selectedTitle)
\r
261 drp_audioTrack.Items.Clear();
\r
262 drp_audioTrack.Items.Add("Automatic");
\r
263 drp_audioTrack.Items.Add("None");
\r
264 drp_audioTrack.Items.AddRange(selectedTitle.AudioTracks.ToArray());
\r
266 // Handle Native Language and "Dub Foreign language audio" and "Use Foreign language audio and Subtitles" Options
\r
267 if (Properties.Settings.Default.NativeLanguage == "Any")
\r
268 drp_audioTrack.SelectedIndex = drp_audioTrack.Items.Count >= 3 ? 2 : 0;
\r
271 if (Properties.Settings.Default.DubAudio) // "Dub Foreign language audio"
\r
274 foreach (object item in drp_audioTrack.Items)
\r
276 if (item.ToString().Contains(Properties.Settings.Default.NativeLanguage))
\r
278 drp_audioTrack.SelectedIndex = i;
\r
285 if (drp_audioTrack.SelectedItem != null)
\r
286 foreach (ListViewItem item in lv_audioList.Items)
\r
287 item.SubItems[1].Text = drp_audioTrack.SelectedItem.ToString();
\r
290 drp_audioTrack.SelectedIndex = 0;
\r
291 if (drp_audioTrack.SelectedItem != null)
\r
292 foreach (ListViewItem item in lv_audioList.Items)
\r
293 item.SubItems[1].Text = drp_audioTrack.SelectedItem.ToString();
\r
297 drp_audioTrack.SelectedIndex = drp_audioTrack.Items.Count >= 3 ? 2 : 0; // "Use Foreign language audio and Subtitles"
\r
299 drp_audioMix.SelectedIndex = 0;
\r
301 public ListView GetAudioPanel()
\r
303 return lv_audioList;
\r
305 public void SetContainer(String path)
\r
307 string oldval = drp_audioEncoder.Text;
\r
308 if ((path.Contains("MP4")) || (path.Contains("M4V")))
\r
310 drp_audioEncoder.Items.Clear();
\r
311 drp_audioEncoder.Items.Add("AAC (faac)");
\r
312 drp_audioEncoder.Items.Add("AC3 Passthru");
\r
313 if ((oldval != "AAC (faac)") && (oldval != "AC3 Passthru"))
\r
314 drp_audioEncoder.SelectedIndex = 0;
\r
316 drp_audioEncoder.SelectedItem = oldval;
\r
319 else if (path.Contains("MKV"))
\r
321 drp_audioEncoder.Items.Clear();
\r
322 drp_audioEncoder.Items.Add("AAC (faac)");
\r
323 drp_audioEncoder.Items.Add("MP3 (lame)");
\r
324 drp_audioEncoder.Items.Add("AC3 Passthru");
\r
325 drp_audioEncoder.Items.Add("DTS Passthru");
\r
326 drp_audioEncoder.Items.Add("Vorbis (vorbis)");
\r
327 drp_audioEncoder.SelectedItem = oldval;
\r
329 if (drp_audioEncoder.Text == string.Empty)
\r
330 drp_audioEncoder.SelectedIndex = 0;
\r
333 // Make sure the table is updated with new audio codecs
\r
334 foreach (ListViewItem row in lv_audioList.Items)
\r
336 if (!drp_audioEncoder.Items.Contains(row.SubItems[2].Text))
\r
337 row.SubItems[2].Text = drp_audioEncoder.Items[0].ToString();
\r
340 public void AddTrackForPreset(ListViewItem item)
\r
342 lv_audioList.Items.Add(item);
\r
343 if (this.AudioListChanged != null)
\r
344 this.AudioListChanged(this, new EventArgs());
\r
346 public void ClearAudioList()
\r
348 lv_audioList.Items.Clear();
\r
349 if (this.AudioListChanged != null)
\r
350 this.AudioListChanged(this, new EventArgs());
\r
352 public int GetNewID()
\r
354 return lv_audioList.Items.Count + 1;
\r
356 public Boolean RequiresM4V()
\r
358 foreach (ListViewItem item in lv_audioList.Items)
\r
360 if (item.SubItems[2].Text.Contains("AC3"))
\r
366 // Helper Functions
\r
367 private void reGenerateListIDs()
\r
370 foreach (ListViewItem item in lv_audioList.Items)
\r
372 item.SubItems[0].Text = i.ToString();
\r
376 private void setBitrate(int max)
\r
380 drp_audioBitrate.Items.Add("192");
\r
381 drp_audioBitrate.Items.Add("224");
\r
382 drp_audioBitrate.Items.Add("256");
\r
383 drp_audioBitrate.Items.Add("320");
\r
385 drp_audioBitrate.Items.Add("384");
\r
387 drp_audioBitrate.Items.Remove("384");
\r
391 drp_audioBitrate.Items.Remove("192");
\r
392 drp_audioBitrate.Items.Remove("224");
\r
393 drp_audioBitrate.Items.Remove("256");
\r
394 drp_audioBitrate.Items.Remove("320");
\r
395 drp_audioBitrate.Items.Remove("384");
\r
397 if (drp_audioBitrate.SelectedItem == null)
\r
398 drp_audioBitrate.SelectedIndex = drp_audioBitrate.Items.Count - 1;
\r
400 private void setMixDown(Boolean aac)
\r
402 drp_audioMix.Items.Clear();
\r
403 drp_audioMix.Items.Add("Automatic");
\r
405 drp_audioMix.Items.Add("Mono");
\r
406 drp_audioMix.Items.Add("Stereo");
\r
407 drp_audioMix.Items.Add("Dolby Surround");
\r
408 drp_audioMix.Items.Add("Dolby Pro Logic II");
\r
410 drp_audioMix.Items.Add("6 Channel Discrete");
\r
412 private void lv_audioList_SelectedIndexChanged(object sender, EventArgs e)
\r
414 // Set the dropdown controls based on the selected item in the Audio List.
\r
415 if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)
\r
417 drp_audioTrack.SelectedItem = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[1].Text;
\r
418 drp_audioEncoder.SelectedItem = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[2].Text;
\r
419 drp_audioMix.SelectedItem = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[3].Text;
\r
420 drp_audioSample.SelectedItem = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[4].Text;
\r
421 drp_audioBitrate.SelectedItem = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[5].Text;
\r
422 double drcValue; int drcCalculated;
\r
423 double.TryParse(lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[6].Text, out drcValue);
\r
424 if (drcValue == 0) drcCalculated = 0;
\r
426 drcValue = ((drcValue * 10) + 1) - 10;
\r
427 int.TryParse(drcValue.ToString(), out drcCalculated);
\r
428 tb_drc.Value = drcCalculated;
\r
429 lbl_drc.Text = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[6].Text;
\r
431 AudioTrackGroup.Text = "Selected Track: " + lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[0].Text;
\r
434 AudioTrackGroup.Text = "Selected Track: None (Click \"Add Track\" to add)";
\r