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("AC3 Passthru");
\r
56 if ((oldval != "AAC (faac)") && (oldval != "AC3 Passthru"))
\r
57 drp_audioEncoder.SelectedIndex = 0;
\r
59 drp_audioEncoder.SelectedItem = oldval;
\r
61 else if (path.Contains("MKV"))
\r
63 drp_audioEncoder.Items.Clear();
\r
64 drp_audioEncoder.Items.Add("AAC (faac)");
\r
65 drp_audioEncoder.Items.Add("MP3 (lame)");
\r
66 drp_audioEncoder.Items.Add("AC3 Passthru");
\r
67 drp_audioEncoder.Items.Add("DTS Passthru");
\r
68 drp_audioEncoder.Items.Add("Vorbis (vorbis)");
\r
69 drp_audioEncoder.SelectedItem = oldval;
\r
71 if (drp_audioEncoder.Text == string.Empty)
\r
72 drp_audioEncoder.SelectedIndex = 0;
\r
75 // Make sure the table is updated with new audio codecs
\r
76 foreach (ListViewItem row in lv_audioList.Items)
\r
78 if (!drp_audioEncoder.Items.Contains(row.SubItems[2].Text))
\r
79 row.SubItems[2].Text = drp_audioEncoder.Items[0].ToString();
\r
84 /// Checks if the settings used required the .m4v (rather than .mp4) extension
\r
86 /// <returns></returns>
\r
87 public bool RequiresM4V()
\r
89 return lv_audioList.Items.Cast<ListViewItem>().Any(item => item.SubItems[2].Text.Contains("AC3"));
\r
93 /// Load an arraylist of AudioTrack items into the list.
\r
95 /// <param name="audioTracks"></param>
\r
96 public void LoadTracks(ArrayList audioTracks)
\r
100 if (audioTracks == null)
\r
103 foreach (AudioTrack track in audioTracks)
\r
105 ListViewItem newTrack = new ListViewItem(GetNewID().ToString());
\r
107 newTrack.SubItems.Add("Automatic");
\r
108 newTrack.SubItems.Add(track.Encoder);
\r
109 newTrack.SubItems.Add(track.MixDown);
\r
110 newTrack.SubItems.Add(track.SampleRate);
\r
111 newTrack.SubItems.Add(track.Encoder.Contains("AC3") ? "Auto" : track.Bitrate);
\r
112 newTrack.SubItems.Add(track.DRC);
\r
113 AddTrackForPreset(newTrack);
\r
118 /// Set the Track list dropdown from the parsed title captured during the scan
\r
120 /// <param name="selectedTitle"></param>
\r
121 public void SetTrackList(Title selectedTitle, Preset preset)
\r
123 if (selectedTitle.AudioTracks.Count == 0)
\r
125 lv_audioList.Items.Clear();
\r
126 drp_audioTrack.Items.Clear();
\r
127 drp_audioTrack.Items.Add("None Found");
\r
128 drp_audioTrack.SelectedIndex = 0;
\r
133 drp_audioTrack.Items.Clear();
\r
134 drp_audioTrack.Items.Add("Automatic");
\r
135 drp_audioTrack.Items.AddRange(selectedTitle.AudioTracks.ToArray());
\r
137 if (lv_audioList.Items.Count == 0 && preset != null)
\r
139 QueryParser parsed = QueryParser.Parse(preset.Query);
\r
140 foreach (AudioTrack audioTrack in parsed.AudioInformation)
\r
142 ListViewItem newTrack = new ListViewItem(GetNewID().ToString());
\r
143 newTrack.SubItems.Add(audioTrack.Track);
\r
144 newTrack.SubItems.Add(audioTrack.Encoder);
\r
145 newTrack.SubItems.Add(audioTrack.MixDown);
\r
146 newTrack.SubItems.Add(audioTrack.SampleRate);
\r
147 newTrack.SubItems.Add(audioTrack.Bitrate);
\r
148 newTrack.SubItems.Add(audioTrack.DRC.ToString());
\r
149 lv_audioList.Items.Add(newTrack);
\r
155 // Handle Native Language and "Dub Foreign language audio" and "Use Foreign language audio and Subtitles" Options
\r
156 if (Properties.Settings.Default.NativeLanguage == "Any")
\r
157 drp_audioTrack.SelectedIndex = drp_audioTrack.Items.Count >= 2 ? 1 : 0;
\r
160 if (Properties.Settings.Default.DubAudio) // "Dub Foreign language audio"
\r
163 foreach (object item in drp_audioTrack.Items)
\r
165 if (item.ToString().Contains(Properties.Settings.Default.NativeLanguage))
\r
167 drp_audioTrack.SelectedIndex = i;
\r
174 if (drp_audioTrack.SelectedItem != null)
\r
175 foreach (ListViewItem item in lv_audioList.Items)
\r
176 item.SubItems[1].Text = drp_audioTrack.SelectedItem.ToString();
\r
179 drp_audioTrack.SelectedIndex = 0;
\r
180 if (drp_audioTrack.SelectedItem != null)
\r
181 foreach (ListViewItem item in lv_audioList.Items)
\r
182 item.SubItems[1].Text = drp_audioTrack.SelectedItem.ToString();
\r
186 drp_audioTrack.SelectedIndex = drp_audioTrack.Items.Count >= 3 ? 2 : 0;
\r
187 // "Use Foreign language audio and Subtitles"
\r
191 // Control and ListView
\r
192 private void controlChanged(object sender, EventArgs e)
\r
194 Control ctl = (Control)sender;
\r
198 case "drp_audioTrack":
\r
199 if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)
\r
200 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[1].Text = drp_audioTrack.Text;
\r
202 case "drp_audioEncoder":
\r
206 // Configure the widgets with values
\r
207 if (drp_audioEncoder.Text.Contains("AC3") || drp_audioEncoder.Text.Contains("DTS"))
\r
209 drp_audioMix.Enabled =
\r
210 drp_audioBitrate.Enabled = drp_audioSample.Enabled = tb_drc.Enabled = false;
\r
211 lbl_bitrate.Enabled =
\r
213 lbl_drcHeader.Enabled = lbl_mixdown.Enabled = lbl_sampleRate.Enabled = false;
\r
217 drp_audioMix.Enabled =
\r
218 drp_audioBitrate.Enabled = drp_audioSample.Enabled = tb_drc.Enabled = true;
\r
219 lbl_bitrate.Enabled =
\r
221 lbl_drcHeader.Enabled = lbl_mixdown.Enabled = lbl_sampleRate.Enabled = true;
\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
226 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[2].Text = drp_audioEncoder.Text;
\r
228 case "drp_audioMix":
\r
231 if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)
\r
232 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[3].Text = drp_audioMix.Text;
\r
234 case "drp_audioSample":
\r
235 if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)
\r
236 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[4].Text = drp_audioSample.Text;
\r
238 case "drp_audioBitrate":
\r
239 // Update an item in the Audio list if required.
\r
240 if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)
\r
241 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[5].Text = drp_audioBitrate.Text;
\r
245 if (tb_drc.Value == 0) value = 0;
\r
247 value = ((tb_drc.Value - 1) / 10.0) + 1;
\r
249 lbl_drc.Text = value.ToString();
\r
251 // Update an item in the Audio list if required.
\r
252 if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)
\r
254 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[6].Text = value.ToString();
\r
255 lv_audioList.Select();
\r
260 lv_audioList.Select();
\r
263 private void lv_audioList_SelectedIndexChanged(object sender, EventArgs e)
\r
265 // Set the dropdown controls based on the selected item in the Audio List.
\r
266 if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)
\r
268 drp_audioTrack.SelectedItem = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[1].Text;
\r
269 drp_audioEncoder.SelectedItem = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[2].Text;
\r
270 drp_audioMix.SelectedItem = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[3].Text;
\r
271 drp_audioSample.SelectedItem = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[4].Text;
\r
272 drp_audioBitrate.SelectedItem = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[5].Text;
\r
275 double.TryParse(lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[6].Text, out drcValue);
\r
277 drcValue = ((drcValue * 10) + 1) - 10;
\r
278 int.TryParse(drcValue.ToString(), out drcCalculated);
\r
279 tb_drc.Value = drcCalculated;
\r
280 lbl_drc.Text = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[6].Text;
\r
282 AudioTrackGroup.Text = "Selected Track: " +
\r
283 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[0].Text;
\r
286 AudioTrackGroup.Text = "Selected Track: None (Click \"Add Track\" to add)";
\r
290 private void btn_addAudioTrack_Click(object sender, EventArgs e)
\r
292 if (drp_audioTrack.Text == "None Found")
\r
294 MessageBox.Show("Your source appears to have no audio tracks that HandBrake supports.", "Warning",
\r
295 MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
300 if (tb_drc.Value != 0)
\r
301 value = ((tb_drc.Value - 1) / 10.0) + 1;
\r
303 // Create a new row for the Audio list based on the currently selected items in the dropdown.
\r
304 ListViewItem newTrack = new ListViewItem(GetNewID().ToString());
\r
305 newTrack.SubItems.Add(drp_audioTrack.Text);
\r
306 newTrack.SubItems.Add(drp_audioEncoder.Text);
\r
307 newTrack.SubItems.Add(drp_audioMix.Text);
\r
308 newTrack.SubItems.Add(drp_audioSample.Text);
\r
309 newTrack.SubItems.Add(drp_audioBitrate.Text);
\r
310 newTrack.SubItems.Add(value.ToString());
\r
311 lv_audioList.Items.Add(newTrack);
\r
313 // The Audio List has changed to raise the event.
\r
314 if (this.AudioListChanged != null)
\r
315 this.AudioListChanged(this, new EventArgs());
\r
317 // Select the newly added track and select the control
\r
318 lv_audioList.Items[lv_audioList.Items.Count - 1].Selected = true;
\r
319 lv_audioList.Select();
\r
322 private void btn_RemoveAudioTrack_Click(object sender, EventArgs e)
\r
328 private void audioList_moveup_Click(object sender, EventArgs e)
\r
333 private void audioList_movedown_Click(object sender, EventArgs e)
\r
338 private void audioList_remove_Click(object sender, EventArgs e)
\r
343 // Public Functions
\r
344 private void AddTrackForPreset(ListViewItem item)
\r
346 lv_audioList.Items.Add(item);
\r
347 if (this.AudioListChanged != null)
\r
348 this.AudioListChanged(this, new EventArgs());
\r
351 private void ClearAudioList()
\r
353 lv_audioList.Items.Clear();
\r
354 if (this.AudioListChanged != null)
\r
355 this.AudioListChanged(this, new EventArgs());
\r
358 private int GetNewID()
\r
360 return lv_audioList.Items.Count + 1;
\r
363 private void RemoveTrack()
\r
365 // Remove the Item and reselect the control if the following conditions are met.
\r
366 if (lv_audioList.SelectedItems.Count != 0)
\r
368 // The Audio List is about to change so raise the event.
\r
369 if (this.AudioListChanged != null)
\r
370 this.AudioListChanged(this, new EventArgs());
\r
372 // Record the current selected index.
\r
373 int currentPosition = lv_audioList.SelectedIndices[0];
\r
375 lv_audioList.Items.RemoveAt(lv_audioList.SelectedIndices[0]);
\r
377 // Now reslect the correct item and give focus to the audio list.
\r
378 if (lv_audioList.Items.Count != 0)
\r
380 if (currentPosition <= (lv_audioList.Items.Count - 1))
\r
381 lv_audioList.Items[currentPosition].Selected = true;
\r
382 else if (currentPosition > (lv_audioList.Items.Count - 1))
\r
383 lv_audioList.Items[lv_audioList.Items.Count - 1].Selected = true;
\r
385 lv_audioList.Select();
\r
387 // Regenerate the ID numers
\r
388 ReGenerateListIDs();
\r
392 private void MoveTrack(bool up)
\r
394 if (lv_audioList.SelectedIndices.Count == 0) return;
\r
396 ListViewItem item = lv_audioList.SelectedItems[0];
\r
397 int index = item.Index;
\r
402 if (index < lv_audioList.Items.Count || (lv_audioList.Items.Count > index && index >= 0))
\r
404 lv_audioList.Items.Remove(item);
\r
405 lv_audioList.Items.Insert(index, item);
\r
406 item.Selected = true;
\r
407 lv_audioList.Focus();
\r
411 private void ReGenerateListIDs()
\r
414 foreach (ListViewItem item in lv_audioList.Items)
\r
416 item.SubItems[0].Text = i.ToString();
\r
421 private void SetBitrate()
\r
424 drp_audioBitrate.Items.Remove("Auto");
\r
425 drp_audioBitrate.Items.Remove("192");
\r
426 drp_audioBitrate.Items.Remove("224");
\r
427 drp_audioBitrate.Items.Remove("256");
\r
428 drp_audioBitrate.Items.Remove("320");
\r
430 switch (drp_audioEncoder.Text)
\r
433 max = drp_audioMix.Text.Contains("6 Channel") ? 384 : 160;
\r
438 case "Vorbis (vorbis)":
\r
441 case "AC3 Passthru":
\r
442 drp_audioBitrate.Items.Add("Auto");
\r
443 drp_audioBitrate.SelectedItem = "Auto";
\r
444 drp_audioSample.SelectedItem = "Auto";
\r
446 case "DTS Passthru":
\r
447 drp_audioBitrate.Items.Add("Auto");
\r
448 drp_audioBitrate.SelectedItem = "Auto";
\r
449 drp_audioSample.SelectedItem = "Auto";
\r
455 drp_audioBitrate.Items.Add("192");
\r
456 drp_audioBitrate.Items.Add("224");
\r
457 drp_audioBitrate.Items.Add("256");
\r
458 drp_audioBitrate.Items.Add("320");
\r
460 drp_audioBitrate.Items.Add("384");
\r
462 drp_audioBitrate.Items.Remove("384");
\r
466 drp_audioBitrate.Items.Remove("192");
\r
467 drp_audioBitrate.Items.Remove("224");
\r
468 drp_audioBitrate.Items.Remove("256");
\r
469 drp_audioBitrate.Items.Remove("320");
\r
470 drp_audioBitrate.Items.Remove("384");
\r
473 if (drp_audioBitrate.SelectedItem == null)
\r
474 drp_audioBitrate.SelectedIndex = drp_audioBitrate.Items.Count - 1;
\r
477 private void SetMixDown()
\r
479 drp_audioMix.Items.Clear();
\r
480 drp_audioMix.Items.Add("Mono");
\r
481 drp_audioMix.Items.Add("Stereo");
\r
482 drp_audioMix.Items.Add("Dolby Surround");
\r
483 drp_audioMix.Items.Add("Dolby Pro Logic II");
\r
484 drp_audioMix.Items.Add("6 Channel Discrete");
\r
485 drp_audioMix.Items.Add("AC3 Passthru");
\r
486 drp_audioMix.Items.Add("DTS Passthru");
\r
488 drp_audioMix.SelectedItem = "Dolby Pro Logic II";
\r
490 switch (drp_audioEncoder.Text)
\r
493 drp_audioMix.Items.Remove("AC3 Passthru");
\r
494 drp_audioMix.Items.Remove("DTS Passthru");
\r
497 drp_audioMix.Items.Remove("Mono");
\r
498 drp_audioMix.Items.Remove("6 Channel Discrete");
\r
499 drp_audioMix.Items.Remove("AC3 Passthru");
\r
500 drp_audioMix.Items.Remove("DTS Passthru");
\r
502 case "Vorbis (vorbis)":
\r
503 drp_audioMix.Items.Remove("AC3 Passthru");
\r
504 drp_audioMix.Items.Remove("DTS Passthru");
\r
506 case "AC3 Passthru":
\r
507 drp_audioMix.SelectedItem = "AC3 Passthru";
\r
509 case "DTS Passthru":
\r
510 drp_audioMix.SelectedItem = "DTS Passthru";
\r