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
7 namespace Handbrake.Controls
\r
10 using System.Collections;
\r
12 using System.Windows.Forms;
\r
14 using AudioTrack = Model.AudioTrack;
\r
16 public partial class AudioPanel : UserControl
\r
19 /// The audio list has changed
\r
21 public event EventHandler AudioListChanged;
\r
24 /// Initializes a new instance of the <see cref="AudioPanel"/> class.
\r
25 /// Create a new instance of the Audio Panel
\r
29 InitializeComponent();
\r
30 drp_audioMix.SelectedItem = "Dolby Pro Logic II";
\r
31 drp_audioSample.SelectedIndex = 1;
\r
35 /// Get the audio panel
\r
37 /// <returns>A listview containing the audio tracks</returns>
\r
38 public ListView GetAudioPanel()
\r
40 return lv_audioList;
\r
44 /// Set the File Container. This funciton is used to limit the available options for each file container.
\r
46 /// <param name="path"></param>
\r
47 public void SetContainer(string path)
\r
49 string oldval = drp_audioEncoder.Text;
\r
50 if ((path.Contains("MP4")) || (path.Contains("M4V")))
\r
52 drp_audioEncoder.Items.Clear();
\r
53 drp_audioEncoder.Items.Add("AAC (faac)");
\r
54 drp_audioEncoder.Items.Add("AC3 Passthru");
\r
55 if ((oldval != "AAC (faac)") && (oldval != "AC3 Passthru"))
\r
56 drp_audioEncoder.SelectedIndex = 0;
\r
58 drp_audioEncoder.SelectedItem = oldval;
\r
60 else if (path.Contains("MKV"))
\r
62 drp_audioEncoder.Items.Clear();
\r
63 drp_audioEncoder.Items.Add("AAC (faac)");
\r
64 drp_audioEncoder.Items.Add("MP3 (lame)");
\r
65 drp_audioEncoder.Items.Add("AC3 Passthru");
\r
66 drp_audioEncoder.Items.Add("DTS Passthru");
\r
67 drp_audioEncoder.Items.Add("Vorbis (vorbis)");
\r
68 drp_audioEncoder.SelectedItem = oldval;
\r
70 if (drp_audioEncoder.Text == string.Empty)
\r
71 drp_audioEncoder.SelectedIndex = 0;
\r
74 // Make sure the table is updated with new audio codecs
\r
75 foreach (ListViewItem row in lv_audioList.Items)
\r
77 if (!drp_audioEncoder.Items.Contains(row.SubItems[2].Text))
\r
78 row.SubItems[2].Text = drp_audioEncoder.Items[0].ToString();
\r
83 /// Checks if the settings used required the .m4v (rather than .mp4) extension
\r
85 /// <returns></returns>
\r
86 public bool RequiresM4V()
\r
88 return lv_audioList.Items.Cast<ListViewItem>().Any(item => item.SubItems[2].Text.Contains("AC3"));
\r
92 /// Load an arraylist of AudioTrack items into the list.
\r
94 /// <param name="audioTracks"></param>
\r
95 public void LoadTracks(ArrayList audioTracks)
\r
99 if (audioTracks == null)
\r
102 foreach (AudioTrack track in audioTracks)
\r
104 ListViewItem newTrack = new ListViewItem(GetNewID().ToString());
\r
106 newTrack.SubItems.Add("Automatic");
\r
107 newTrack.SubItems.Add(track.Encoder);
\r
108 newTrack.SubItems.Add(track.MixDown);
\r
109 newTrack.SubItems.Add(track.SampleRate);
\r
110 newTrack.SubItems.Add(track.Encoder.Contains("AC3") ? "Auto" : track.Bitrate);
\r
111 newTrack.SubItems.Add(track.DRC);
\r
112 AddTrackForPreset(newTrack);
\r
117 /// Set the Track list dropdown from the parsed title captured during the scan
\r
119 /// <param name="selectedTitle"></param>
\r
120 public void SetTrackList(Title selectedTitle)
\r
122 drp_audioTrack.Items.Clear();
\r
123 drp_audioTrack.Items.Add("Automatic");
\r
124 drp_audioTrack.Items.Add("None");
\r
125 drp_audioTrack.Items.AddRange(selectedTitle.AudioTracks.ToArray());
\r
127 // Handle Native Language and "Dub Foreign language audio" and "Use Foreign language audio and Subtitles" Options
\r
128 if (Properties.Settings.Default.NativeLanguage == "Any")
\r
129 drp_audioTrack.SelectedIndex = drp_audioTrack.Items.Count >= 3 ? 2 : 0;
\r
132 if (Properties.Settings.Default.DubAudio) // "Dub Foreign language audio"
\r
135 foreach (object item in drp_audioTrack.Items)
\r
137 if (item.ToString().Contains(Properties.Settings.Default.NativeLanguage))
\r
139 drp_audioTrack.SelectedIndex = i;
\r
146 if (drp_audioTrack.SelectedItem != null)
\r
147 foreach (ListViewItem item in lv_audioList.Items)
\r
148 item.SubItems[1].Text = drp_audioTrack.SelectedItem.ToString();
\r
151 drp_audioTrack.SelectedIndex = 0;
\r
152 if (drp_audioTrack.SelectedItem != null)
\r
153 foreach (ListViewItem item in lv_audioList.Items)
\r
154 item.SubItems[1].Text = drp_audioTrack.SelectedItem.ToString();
\r
158 drp_audioTrack.SelectedIndex = drp_audioTrack.Items.Count >= 3 ? 2 : 0;
\r
159 // "Use Foreign language audio and Subtitles"
\r
161 drp_audioMix.SelectedIndex = 0;
\r
164 // Control and ListView
\r
165 private void controlChanged(object sender, EventArgs e)
\r
167 Control ctl = (Control) sender;
\r
171 case "drp_audioTrack":
\r
172 if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)
\r
173 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[1].Text = drp_audioTrack.Text;
\r
175 case "drp_audioEncoder":
\r
179 // Configure the widgets with values
\r
180 if (drp_audioEncoder.Text.Contains("AC3") || drp_audioEncoder.Text.Contains("DTS"))
\r
182 drp_audioMix.Enabled =
\r
183 drp_audioBitrate.Enabled = drp_audioSample.Enabled = tb_drc.Enabled = false;
\r
184 lbl_bitrate.Enabled =
\r
186 lbl_drcHeader.Enabled = lbl_mixdown.Enabled = lbl_sampleRate.Enabled = false;
\r
190 drp_audioMix.Enabled =
\r
191 drp_audioBitrate.Enabled = drp_audioSample.Enabled = tb_drc.Enabled = true;
\r
192 lbl_bitrate.Enabled =
\r
194 lbl_drcHeader.Enabled = lbl_mixdown.Enabled = lbl_sampleRate.Enabled = true;
\r
197 // Update an item in the Audio list if required.
\r
198 if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)
\r
199 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[2].Text = drp_audioEncoder.Text;
\r
201 case "drp_audioMix":
\r
204 if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)
\r
205 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[3].Text = drp_audioMix.Text;
\r
207 case "drp_audioSample":
\r
208 if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)
\r
209 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[4].Text = drp_audioSample.Text;
\r
211 case "drp_audioBitrate":
\r
212 // Update an item in the Audio list if required.
\r
213 if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)
\r
214 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[5].Text = drp_audioBitrate.Text;
\r
218 if (tb_drc.Value == 0) value = 0;
\r
220 value = ((tb_drc.Value - 1)/10.0) + 1;
\r
222 lbl_drc.Text = value.ToString();
\r
224 // Update an item in the Audio list if required.
\r
225 if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)
\r
227 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[6].Text = value.ToString();
\r
228 lv_audioList.Select();
\r
233 lv_audioList.Select();
\r
236 private void lv_audioList_SelectedIndexChanged(object sender, EventArgs e)
\r
238 // Set the dropdown controls based on the selected item in the Audio List.
\r
239 if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)
\r
241 drp_audioTrack.SelectedItem = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[1].Text;
\r
242 drp_audioEncoder.SelectedItem = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[2].Text;
\r
243 drp_audioMix.SelectedItem = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[3].Text;
\r
244 drp_audioSample.SelectedItem = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[4].Text;
\r
245 drp_audioBitrate.SelectedItem = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[5].Text;
\r
248 double.TryParse(lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[6].Text, out drcValue);
\r
250 drcValue = ((drcValue*10) + 1) - 10;
\r
251 int.TryParse(drcValue.ToString(), out drcCalculated);
\r
252 tb_drc.Value = drcCalculated;
\r
253 lbl_drc.Text = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[6].Text;
\r
255 AudioTrackGroup.Text = "Selected Track: " +
\r
256 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[0].Text;
\r
259 AudioTrackGroup.Text = "Selected Track: None (Click \"Add Track\" to add)";
\r
263 private void btn_addAudioTrack_Click(object sender, EventArgs e)
\r
266 if (tb_drc.Value != 0)
\r
267 value = ((tb_drc.Value - 1)/10.0) + 1;
\r
269 // Create a new row for the Audio list based on the currently selected items in the dropdown.
\r
270 ListViewItem newTrack = new ListViewItem(GetNewID().ToString());
\r
271 newTrack.SubItems.Add(drp_audioTrack.Text);
\r
272 newTrack.SubItems.Add(drp_audioEncoder.Text);
\r
273 newTrack.SubItems.Add(drp_audioMix.Text);
\r
274 newTrack.SubItems.Add(drp_audioSample.Text);
\r
275 newTrack.SubItems.Add(drp_audioBitrate.Text);
\r
276 newTrack.SubItems.Add(value.ToString());
\r
277 lv_audioList.Items.Add(newTrack);
\r
279 // The Audio List has changed to raise the event.
\r
280 if (this.AudioListChanged != null)
\r
281 this.AudioListChanged(this, new EventArgs());
\r
283 // Select the newly added track and select the control
\r
284 lv_audioList.Items[lv_audioList.Items.Count - 1].Selected = true;
\r
285 lv_audioList.Select();
\r
288 private void btn_RemoveAudioTrack_Click(object sender, EventArgs e)
\r
294 private void audioList_moveup_Click(object sender, EventArgs e)
\r
299 private void audioList_movedown_Click(object sender, EventArgs e)
\r
304 private void audioList_remove_Click(object sender, EventArgs e)
\r
309 // Public Functions
\r
310 private void AddTrackForPreset(ListViewItem item)
\r
312 lv_audioList.Items.Add(item);
\r
313 if (this.AudioListChanged != null)
\r
314 this.AudioListChanged(this, new EventArgs());
\r
317 private void ClearAudioList()
\r
319 lv_audioList.Items.Clear();
\r
320 if (this.AudioListChanged != null)
\r
321 this.AudioListChanged(this, new EventArgs());
\r
324 private int GetNewID()
\r
326 return lv_audioList.Items.Count + 1;
\r
329 private void RemoveTrack()
\r
331 // Remove the Item and reselect the control if the following conditions are met.
\r
332 if (lv_audioList.SelectedItems.Count != 0)
\r
334 // The Audio List is about to change so raise the event.
\r
335 if (this.AudioListChanged != null)
\r
336 this.AudioListChanged(this, new EventArgs());
\r
338 // Record the current selected index.
\r
339 int currentPosition = lv_audioList.SelectedIndices[0];
\r
341 lv_audioList.Items.RemoveAt(lv_audioList.SelectedIndices[0]);
\r
343 // Now reslect the correct item and give focus to the audio list.
\r
344 if (lv_audioList.Items.Count != 0)
\r
346 if (currentPosition <= (lv_audioList.Items.Count - 1))
\r
347 lv_audioList.Items[currentPosition].Selected = true;
\r
348 else if (currentPosition > (lv_audioList.Items.Count - 1))
\r
349 lv_audioList.Items[lv_audioList.Items.Count - 1].Selected = true;
\r
351 lv_audioList.Select();
\r
353 // Regenerate the ID numers
\r
354 ReGenerateListIDs();
\r
358 private void MoveTrack(bool up)
\r
360 if (lv_audioList.SelectedIndices.Count == 0) return;
\r
362 ListViewItem item = lv_audioList.SelectedItems[0];
\r
363 int index = item.Index;
\r
368 if (index < lv_audioList.Items.Count || (lv_audioList.Items.Count > index && index >= 0))
\r
370 lv_audioList.Items.Remove(item);
\r
371 lv_audioList.Items.Insert(index, item);
\r
372 item.Selected = true;
\r
373 lv_audioList.Focus();
\r
377 private void ReGenerateListIDs()
\r
380 foreach (ListViewItem item in lv_audioList.Items)
\r
382 item.SubItems[0].Text = i.ToString();
\r
387 private void SetBitrate()
\r
390 drp_audioBitrate.Items.Remove("Auto");
\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
396 switch (drp_audioEncoder.Text)
\r
399 max = drp_audioMix.Text.Contains("6 Channel") ? 384 : 160;
\r
404 case "Vorbis (vorbis)":
\r
407 case "AC3 Passthru":
\r
408 drp_audioBitrate.Items.Add("Auto");
\r
409 drp_audioBitrate.SelectedItem = "Auto";
\r
410 drp_audioSample.SelectedItem = "Auto";
\r
412 case "DTS Passthru":
\r
413 drp_audioBitrate.Items.Add("Auto");
\r
414 drp_audioBitrate.SelectedItem = "Auto";
\r
415 drp_audioSample.SelectedItem = "Auto";
\r
421 drp_audioBitrate.Items.Add("192");
\r
422 drp_audioBitrate.Items.Add("224");
\r
423 drp_audioBitrate.Items.Add("256");
\r
424 drp_audioBitrate.Items.Add("320");
\r
426 drp_audioBitrate.Items.Add("384");
\r
428 drp_audioBitrate.Items.Remove("384");
\r
432 drp_audioBitrate.Items.Remove("192");
\r
433 drp_audioBitrate.Items.Remove("224");
\r
434 drp_audioBitrate.Items.Remove("256");
\r
435 drp_audioBitrate.Items.Remove("320");
\r
436 drp_audioBitrate.Items.Remove("384");
\r
439 if (drp_audioBitrate.SelectedItem == null)
\r
440 drp_audioBitrate.SelectedIndex = drp_audioBitrate.Items.Count - 1;
\r
443 private void SetMixDown()
\r
445 drp_audioMix.Items.Clear();
\r
446 drp_audioMix.Items.Add("Mono");
\r
447 drp_audioMix.Items.Add("Stereo");
\r
448 drp_audioMix.Items.Add("Dolby Surround");
\r
449 drp_audioMix.Items.Add("Dolby Pro Logic II");
\r
450 drp_audioMix.Items.Add("6 Channel Discrete");
\r
451 drp_audioMix.Items.Add("AC3 Passthru");
\r
452 drp_audioMix.Items.Add("DTS Passthru");
\r
454 drp_audioMix.SelectedItem = "Dolby Pro Logic II";
\r
456 switch (drp_audioEncoder.Text)
\r
459 drp_audioMix.Items.Remove("AC3 Passthru");
\r
460 drp_audioMix.Items.Remove("DTS Passthru");
\r
463 drp_audioMix.Items.Remove("Mono");
\r
464 drp_audioMix.Items.Remove("6 Channel Discrete");
\r
465 drp_audioMix.Items.Remove("AC3 Passthru");
\r
466 drp_audioMix.Items.Remove("DTS Passthru");
\r
468 case "Vorbis (vorbis)":
\r
469 drp_audioMix.Items.Remove("AC3 Passthru");
\r
470 drp_audioMix.Items.Remove("DTS Passthru");
\r
472 case "AC3 Passthru":
\r
473 drp_audioMix.SelectedItem = "AC3 Passthru";
\r
475 case "DTS Passthru":
\r
476 drp_audioMix.SelectedItem = "DTS Passthru";
\r