2 This file is part of the HandBrake source code.
\r
3 Homepage: <http://handbrake.fr>.
\r
4 It may be used under the terms of the GNU General Public License. */
\r
6 namespace Handbrake.Controls
\r
9 using System.Collections;
\r
11 using System.Windows.Forms;
\r
15 using AudioTrack = Model.AudioTrack;
\r
17 public partial class AudioPanel : UserControl
\r
20 /// The audio list has changed
\r
22 public event EventHandler AudioListChanged;
\r
25 /// Initializes a new instance of the <see cref="AudioPanel"/> class.
\r
26 /// Create a new instance of the Audio Panel
\r
30 InitializeComponent();
\r
31 drp_audioMix.SelectedItem = "Dolby Pro Logic II";
\r
32 drp_audioSample.SelectedIndex = 1;
\r
36 /// Get the audio panel
\r
38 /// <returns>A listview containing the audio tracks</returns>
\r
39 public ListView GetAudioPanel()
\r
41 return lv_audioList;
\r
45 /// Set the File Container. This funciton is used to limit the available options for each file container.
\r
47 /// <param name="path"></param>
\r
48 public void SetContainer(string path)
\r
50 string oldval = drp_audioEncoder.Text;
\r
51 if ((path.Contains("MP4")) || (path.Contains("M4V")))
\r
53 drp_audioEncoder.Items.Clear();
\r
54 drp_audioEncoder.Items.Add("AAC (faac)");
\r
55 drp_audioEncoder.Items.Add("MP3 (lame)");
\r
56 drp_audioEncoder.Items.Add("AC3 Passthru");
\r
57 if ((oldval != "AAC (faac)") && (oldval != "AC3 Passthru"))
\r
58 drp_audioEncoder.SelectedIndex = 0;
\r
60 drp_audioEncoder.SelectedItem = oldval;
\r
62 else if (path.Contains("MKV"))
\r
64 drp_audioEncoder.Items.Clear();
\r
65 drp_audioEncoder.Items.Add("AAC (faac)");
\r
66 drp_audioEncoder.Items.Add("MP3 (lame)");
\r
67 drp_audioEncoder.Items.Add("AC3 Passthru");
\r
68 drp_audioEncoder.Items.Add("DTS Passthru");
\r
69 drp_audioEncoder.Items.Add("Vorbis (vorbis)");
\r
70 drp_audioEncoder.SelectedItem = oldval;
\r
72 if (drp_audioEncoder.Text == string.Empty)
\r
73 drp_audioEncoder.SelectedIndex = 0;
\r
76 // Make sure the table is updated with new audio codecs
\r
77 foreach (ListViewItem row in lv_audioList.Items)
\r
79 if (!drp_audioEncoder.Items.Contains(row.SubItems[2].Text))
\r
80 row.SubItems[2].Text = drp_audioEncoder.Items[0].ToString();
\r
85 /// Checks if the settings used required the .m4v (rather than .mp4) extension
\r
87 /// <returns></returns>
\r
88 public bool RequiresM4V()
\r
90 return lv_audioList.Items.Cast<ListViewItem>().Any(item => item.SubItems[2].Text.Contains("AC3"));
\r
94 /// Load an arraylist of AudioTrack items into the list.
\r
96 /// <param name="audioTracks"></param>
\r
97 public void LoadTracks(ArrayList audioTracks)
\r
101 if (audioTracks == null)
\r
104 foreach (AudioTrack track in audioTracks)
\r
106 ListViewItem newTrack = new ListViewItem(GetNewID().ToString());
\r
108 newTrack.SubItems.Add("Automatic");
\r
109 newTrack.SubItems.Add(track.Encoder);
\r
110 newTrack.SubItems.Add(track.MixDown);
\r
111 newTrack.SubItems.Add(track.SampleRate);
\r
112 newTrack.SubItems.Add(track.Encoder.Contains("AC3") ? "Auto" : track.Bitrate);
\r
113 newTrack.SubItems.Add(track.DRC);
\r
114 AddTrackForPreset(newTrack);
\r
119 /// Set the Track list dropdown from the parsed title captured during the scan
\r
121 /// <param name="selectedTitle"></param>
\r
122 public void SetTrackList(Title selectedTitle, Preset preset)
\r
124 if (selectedTitle.AudioTracks.Count == 0)
\r
126 lv_audioList.Items.Clear();
\r
127 drp_audioTrack.Items.Clear();
\r
128 drp_audioTrack.Items.Add("None Found");
\r
129 drp_audioTrack.SelectedIndex = 0;
\r
134 drp_audioTrack.Items.Clear();
\r
135 drp_audioTrack.Items.Add("Automatic");
\r
136 drp_audioTrack.Items.AddRange(selectedTitle.AudioTracks.ToArray());
\r
138 if (lv_audioList.Items.Count == 0 && preset != null)
\r
140 QueryParser parsed = QueryParser.Parse(preset.Query);
\r
141 foreach (AudioTrack audioTrack in parsed.AudioInformation)
\r
143 ListViewItem newTrack = new ListViewItem(GetNewID().ToString());
\r
144 newTrack.SubItems.Add(audioTrack.Track);
\r
145 newTrack.SubItems.Add(audioTrack.Encoder);
\r
146 newTrack.SubItems.Add(audioTrack.MixDown);
\r
147 newTrack.SubItems.Add(audioTrack.SampleRate);
\r
148 newTrack.SubItems.Add(audioTrack.Bitrate);
\r
149 newTrack.SubItems.Add(audioTrack.DRC.ToString());
\r
150 lv_audioList.Items.Add(newTrack);
\r
156 // Handle Native Language and "Dub Foreign language audio" and "Use Foreign language audio and Subtitles" Options
\r
157 if (Properties.Settings.Default.NativeLanguage == "Any")
\r
158 drp_audioTrack.SelectedIndex = drp_audioTrack.Items.Count >= 2 ? 1 : 0;
\r
161 if (Properties.Settings.Default.DubAudio) // "Dub Foreign language audio"
\r
164 foreach (object item in drp_audioTrack.Items)
\r
166 if (item.ToString().Contains(Properties.Settings.Default.NativeLanguage))
\r
168 drp_audioTrack.SelectedIndex = i;
\r
175 if (drp_audioTrack.SelectedItem != null)
\r
176 foreach (ListViewItem item in lv_audioList.Items)
\r
177 item.SubItems[1].Text = drp_audioTrack.SelectedItem.ToString();
\r
180 drp_audioTrack.SelectedIndex = 0;
\r
181 if (drp_audioTrack.SelectedItem != null)
\r
182 foreach (ListViewItem item in lv_audioList.Items)
\r
183 item.SubItems[1].Text = drp_audioTrack.SelectedItem.ToString();
\r
187 drp_audioTrack.SelectedIndex = drp_audioTrack.Items.Count >= 3 ? 2 : 0;
\r
188 // "Use Foreign language audio and Subtitles"
\r
192 // Control and ListView
\r
193 private void controlChanged(object sender, EventArgs e)
\r
195 Control ctl = (Control)sender;
\r
199 case "drp_audioTrack":
\r
200 if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)
\r
201 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[1].Text = drp_audioTrack.Text;
\r
203 case "drp_audioEncoder":
\r
207 // Configure the widgets with values
\r
208 if (drp_audioEncoder.Text.Contains("AC3") || drp_audioEncoder.Text.Contains("DTS"))
\r
210 drp_audioMix.Enabled =
\r
211 drp_audioBitrate.Enabled = drp_audioSample.Enabled = tb_drc.Enabled = false;
\r
212 lbl_bitrate.Enabled =
\r
214 lbl_drcHeader.Enabled = lbl_mixdown.Enabled = lbl_sampleRate.Enabled = false;
\r
218 drp_audioMix.Enabled =
\r
219 drp_audioBitrate.Enabled = drp_audioSample.Enabled = tb_drc.Enabled = true;
\r
220 lbl_bitrate.Enabled =
\r
222 lbl_drcHeader.Enabled = lbl_mixdown.Enabled = lbl_sampleRate.Enabled = true;
\r
225 // Update an item in the Audio list if required.
\r
226 if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)
\r
227 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[2].Text = drp_audioEncoder.Text;
\r
229 case "drp_audioMix":
\r
232 if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)
\r
233 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[3].Text = drp_audioMix.Text;
\r
235 case "drp_audioSample":
\r
236 if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)
\r
237 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[4].Text = drp_audioSample.Text;
\r
239 case "drp_audioBitrate":
\r
240 // Update an item in the Audio list if required.
\r
241 if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)
\r
242 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[5].Text = drp_audioBitrate.Text;
\r
246 if (tb_drc.Value == 0) value = 0;
\r
248 value = ((tb_drc.Value - 1) / 10.0) + 1;
\r
250 lbl_drc.Text = value.ToString();
\r
252 // Update an item in the Audio list if required.
\r
253 if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)
\r
255 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[6].Text = value.ToString();
\r
256 lv_audioList.Select();
\r
261 lv_audioList.Select();
\r
264 private void lv_audioList_SelectedIndexChanged(object sender, EventArgs e)
\r
266 // Set the dropdown controls based on the selected item in the Audio List.
\r
267 if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)
\r
269 drp_audioTrack.SelectedItem = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[1].Text;
\r
270 drp_audioEncoder.SelectedItem = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[2].Text;
\r
271 drp_audioMix.SelectedItem = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[3].Text;
\r
272 drp_audioSample.SelectedItem = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[4].Text;
\r
273 drp_audioBitrate.SelectedItem = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[5].Text;
\r
276 double.TryParse(lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[6].Text, out drcValue);
\r
278 drcValue = ((drcValue * 10) + 1) - 10;
\r
279 int.TryParse(drcValue.ToString(), out drcCalculated);
\r
280 tb_drc.Value = drcCalculated;
\r
281 lbl_drc.Text = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[6].Text;
\r
283 AudioTrackGroup.Text = "Selected Track: " +
\r
284 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[0].Text;
\r
287 AudioTrackGroup.Text = "Selected Track: None (Click \"Add Track\" to add)";
\r
291 private void btn_addAudioTrack_Click(object sender, EventArgs e)
\r
293 if (drp_audioTrack.Text == "None Found")
\r
295 MessageBox.Show("Your source appears to have no audio tracks that HandBrake supports.", "Warning",
\r
296 MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
301 if (tb_drc.Value != 0)
\r
302 value = ((tb_drc.Value - 1) / 10.0) + 1;
\r
304 // Create a new row for the Audio list based on the currently selected items in the dropdown.
\r
305 ListViewItem newTrack = new ListViewItem(GetNewID().ToString());
\r
306 newTrack.SubItems.Add(drp_audioTrack.Text);
\r
307 newTrack.SubItems.Add(drp_audioEncoder.Text);
\r
308 newTrack.SubItems.Add(drp_audioMix.Text);
\r
309 newTrack.SubItems.Add(drp_audioSample.Text);
\r
310 newTrack.SubItems.Add(drp_audioBitrate.Text);
\r
311 newTrack.SubItems.Add(value.ToString());
\r
312 lv_audioList.Items.Add(newTrack);
\r
314 // The Audio List has changed to raise the event.
\r
315 if (this.AudioListChanged != null)
\r
316 this.AudioListChanged(this, new EventArgs());
\r
318 // Select the newly added track and select the control
\r
319 lv_audioList.Items[lv_audioList.Items.Count - 1].Selected = true;
\r
320 lv_audioList.Select();
\r
323 private void btn_RemoveAudioTrack_Click(object sender, EventArgs e)
\r
329 private void audioList_moveup_Click(object sender, EventArgs e)
\r
334 private void audioList_movedown_Click(object sender, EventArgs e)
\r
339 private void audioList_remove_Click(object sender, EventArgs e)
\r
344 // Public Functions
\r
345 private void AddTrackForPreset(ListViewItem item)
\r
347 lv_audioList.Items.Add(item);
\r
348 if (this.AudioListChanged != null)
\r
349 this.AudioListChanged(this, new EventArgs());
\r
352 private void ClearAudioList()
\r
354 lv_audioList.Items.Clear();
\r
355 if (this.AudioListChanged != null)
\r
356 this.AudioListChanged(this, new EventArgs());
\r
359 private int GetNewID()
\r
361 return lv_audioList.Items.Count + 1;
\r
364 private void RemoveTrack()
\r
366 // Remove the Item and reselect the control if the following conditions are met.
\r
367 if (lv_audioList.SelectedItems.Count != 0)
\r
369 // The Audio List is about to change so raise the event.
\r
370 if (this.AudioListChanged != null)
\r
371 this.AudioListChanged(this, new EventArgs());
\r
373 // Record the current selected index.
\r
374 int currentPosition = lv_audioList.SelectedIndices[0];
\r
376 lv_audioList.Items.RemoveAt(lv_audioList.SelectedIndices[0]);
\r
378 // Now reslect the correct item and give focus to the audio list.
\r
379 if (lv_audioList.Items.Count != 0)
\r
381 if (currentPosition <= (lv_audioList.Items.Count - 1))
\r
382 lv_audioList.Items[currentPosition].Selected = true;
\r
383 else if (currentPosition > (lv_audioList.Items.Count - 1))
\r
384 lv_audioList.Items[lv_audioList.Items.Count - 1].Selected = true;
\r
386 lv_audioList.Select();
\r
388 // Regenerate the ID numers
\r
389 ReGenerateListIDs();
\r
393 private void MoveTrack(bool up)
\r
395 if (lv_audioList.SelectedIndices.Count == 0) return;
\r
397 ListViewItem item = lv_audioList.SelectedItems[0];
\r
398 int index = item.Index;
\r
403 if (index < lv_audioList.Items.Count || (lv_audioList.Items.Count > index && index >= 0))
\r
405 lv_audioList.Items.Remove(item);
\r
406 lv_audioList.Items.Insert(index, item);
\r
407 item.Selected = true;
\r
408 lv_audioList.Focus();
\r
412 private void ReGenerateListIDs()
\r
415 foreach (ListViewItem item in lv_audioList.Items)
\r
417 item.SubItems[0].Text = i.ToString();
\r
422 private void SetBitrate()
\r
425 drp_audioBitrate.Items.Remove("Auto");
\r
426 drp_audioBitrate.Items.Remove("192");
\r
427 drp_audioBitrate.Items.Remove("224");
\r
428 drp_audioBitrate.Items.Remove("256");
\r
429 drp_audioBitrate.Items.Remove("320");
\r
430 drp_audioBitrate.Items.Remove("384");
\r
431 drp_audioBitrate.Items.Remove("448");
\r
432 drp_audioBitrate.Items.Remove("768");
\r
434 switch (drp_audioEncoder.Text)
\r
437 max = drp_audioMix.Text.Contains("6 Channel") ? 768 : 320;
\r
442 case "Vorbis (vorbis)":
\r
445 case "AC3 Passthru":
\r
446 drp_audioBitrate.Items.Add("Auto");
\r
447 drp_audioBitrate.SelectedItem = "Auto";
\r
448 drp_audioSample.SelectedItem = "Auto";
\r
450 case "DTS Passthru":
\r
451 drp_audioBitrate.Items.Add("Auto");
\r
452 drp_audioBitrate.SelectedItem = "Auto";
\r
453 drp_audioSample.SelectedItem = "Auto";
\r
459 drp_audioBitrate.Items.Add("192");
\r
460 drp_audioBitrate.Items.Add("224");
\r
461 drp_audioBitrate.Items.Add("256");
\r
462 drp_audioBitrate.Items.Add("320");
\r
467 drp_audioBitrate.Items.Add("384");
\r
472 drp_audioBitrate.Items.Add("448");
\r
473 drp_audioBitrate.Items.Add("768");
\r
476 if (drp_audioBitrate.SelectedItem == null)
\r
477 drp_audioBitrate.SelectedIndex = drp_audioBitrate.Items.Count - 1;
\r
480 private void SetMixDown()
\r
482 drp_audioMix.Items.Clear();
\r
483 drp_audioMix.Items.Add("Mono");
\r
484 drp_audioMix.Items.Add("Stereo");
\r
485 drp_audioMix.Items.Add("Dolby Surround");
\r
486 drp_audioMix.Items.Add("Dolby Pro Logic II");
\r
487 drp_audioMix.Items.Add("6 Channel Discrete");
\r
488 drp_audioMix.Items.Add("AC3 Passthru");
\r
489 drp_audioMix.Items.Add("DTS Passthru");
\r
491 drp_audioMix.SelectedItem = "Dolby Pro Logic II";
\r
493 switch (drp_audioEncoder.Text)
\r
496 drp_audioMix.Items.Remove("AC3 Passthru");
\r
497 drp_audioMix.Items.Remove("DTS Passthru");
\r
500 drp_audioMix.Items.Remove("Mono");
\r
501 drp_audioMix.Items.Remove("6 Channel Discrete");
\r
502 drp_audioMix.Items.Remove("AC3 Passthru");
\r
503 drp_audioMix.Items.Remove("DTS Passthru");
\r
505 case "Vorbis (vorbis)":
\r
506 drp_audioMix.Items.Remove("AC3 Passthru");
\r
507 drp_audioMix.Items.Remove("DTS Passthru");
\r
509 case "AC3 Passthru":
\r
510 drp_audioMix.SelectedItem = "AC3 Passthru";
\r
512 case "DTS Passthru":
\r
513 drp_audioMix.SelectedItem = "DTS Passthru";
\r