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
18 /// The AudioPanel Control
\r
20 public partial class AudioPanel : UserControl
\r
23 /// Initializes a new instance of the <see cref="AudioPanel"/> class.
\r
24 /// Create a new instance of the Audio Panel
\r
28 InitializeComponent();
\r
29 drp_audioMix.SelectedItem = "Dolby Pro Logic II";
\r
30 drp_audioSample.SelectedIndex = 1;
\r
34 /// The audio list has changed
\r
36 public event EventHandler AudioListChanged;
\r
39 /// Get the audio panel
\r
41 /// <returns>A listview containing the audio tracks</returns>
\r
42 public ListView GetAudioPanel()
\r
44 return lv_audioList;
\r
48 /// Set the File Container. This funciton is used to limit the available options for each file container.
\r
50 /// <param name="path">
\r
53 public void SetContainer(string path)
\r
55 string oldval = drp_audioEncoder.Text;
\r
56 if ((path.Contains("MP4")) || (path.Contains("M4V")))
\r
58 drp_audioEncoder.Items.Clear();
\r
59 drp_audioEncoder.Items.Add("AAC (faac)");
\r
60 drp_audioEncoder.Items.Add("MP3 (lame)");
\r
61 drp_audioEncoder.Items.Add("AC3 Passthru");
\r
62 if ((oldval != "AAC (faac)") && (oldval != "AC3 Passthru"))
\r
63 drp_audioEncoder.SelectedIndex = 0;
\r
65 drp_audioEncoder.SelectedItem = oldval;
\r
67 else if (path.Contains("MKV"))
\r
69 drp_audioEncoder.Items.Clear();
\r
70 drp_audioEncoder.Items.Add("AAC (faac)");
\r
71 drp_audioEncoder.Items.Add("MP3 (lame)");
\r
72 drp_audioEncoder.Items.Add("AC3 Passthru");
\r
73 drp_audioEncoder.Items.Add("DTS Passthru");
\r
74 drp_audioEncoder.Items.Add("Vorbis (vorbis)");
\r
75 drp_audioEncoder.SelectedItem = oldval;
\r
77 if (drp_audioEncoder.Text == string.Empty)
\r
78 drp_audioEncoder.SelectedIndex = 0;
\r
81 // Make sure the table is updated with new audio codecs
\r
82 foreach (ListViewItem row in lv_audioList.Items)
\r
84 if (!drp_audioEncoder.Items.Contains(row.SubItems[2].Text))
\r
85 row.SubItems[2].Text = drp_audioEncoder.Items[0].ToString();
\r
90 /// Checks if the settings used required the .m4v (rather than .mp4) extension
\r
92 /// <returns>True if m4v is required</returns>
\r
93 public bool RequiresM4V()
\r
95 return lv_audioList.Items.Cast<ListViewItem>().Any(item => item.SubItems[2].Text.Contains("AC3"));
\r
99 /// Load an arraylist of AudioTrack items into the list.
\r
101 /// <param name="audioTracks">List of audio tracks</param>
\r
102 public void LoadTracks(ArrayList audioTracks)
\r
106 if (audioTracks == null)
\r
109 foreach (AudioTrack track in audioTracks)
\r
111 ListViewItem newTrack = new ListViewItem(GetNewID().ToString());
\r
113 newTrack.SubItems.Add("Automatic");
\r
114 newTrack.SubItems.Add(track.Encoder);
\r
115 newTrack.SubItems.Add(track.MixDown);
\r
116 newTrack.SubItems.Add(track.SampleRate);
\r
117 newTrack.SubItems.Add(track.Encoder.Contains("AC3") ? "Auto" : track.Bitrate);
\r
118 newTrack.SubItems.Add(track.DRC);
\r
119 AddTrackForPreset(newTrack);
\r
124 /// Set the Track list dropdown from the parsed title captured during the scan
\r
126 /// <param name="selectedTitle">The selected title</param>
\r
127 /// <param name="preset">A preset</param>
\r
128 public void SetTrackList(Title selectedTitle, Preset preset)
\r
130 if (selectedTitle.AudioTracks.Count == 0)
\r
132 lv_audioList.Items.Clear();
\r
133 drp_audioTrack.Items.Clear();
\r
134 drp_audioTrack.Items.Add("None Found");
\r
135 drp_audioTrack.SelectedIndex = 0;
\r
139 drp_audioTrack.Items.Clear();
\r
140 drp_audioTrack.Items.Add("Automatic");
\r
141 drp_audioTrack.Items.AddRange(selectedTitle.AudioTracks.ToArray());
\r
143 if (lv_audioList.Items.Count == 0 && preset != null)
\r
145 QueryParser parsed = QueryParser.Parse(preset.Query);
\r
146 foreach (AudioTrack audioTrack in parsed.AudioInformation)
\r
148 ListViewItem newTrack = new ListViewItem(GetNewID().ToString());
\r
149 newTrack.SubItems.Add(audioTrack.Track);
\r
150 newTrack.SubItems.Add(audioTrack.Encoder);
\r
151 newTrack.SubItems.Add(audioTrack.MixDown);
\r
152 newTrack.SubItems.Add(audioTrack.SampleRate);
\r
153 newTrack.SubItems.Add(audioTrack.Bitrate);
\r
154 newTrack.SubItems.Add(audioTrack.DRC);
\r
155 lv_audioList.Items.Add(newTrack);
\r
159 // Handle Native Language and "Dub Foreign language audio" and "Use Foreign language audio and Subtitles" Options
\r
160 if (Properties.Settings.Default.NativeLanguage == "Any")
\r
161 drp_audioTrack.SelectedIndex = drp_audioTrack.Items.Count >= 2 ? 1 : 0;
\r
164 if (Properties.Settings.Default.DubAudio) // "Dub Foreign language audio"
\r
167 foreach (object item in drp_audioTrack.Items)
\r
169 if (item.ToString().Contains(Properties.Settings.Default.NativeLanguage))
\r
171 drp_audioTrack.SelectedIndex = i;
\r
178 if (drp_audioTrack.SelectedItem != null)
\r
179 foreach (ListViewItem item in lv_audioList.Items)
\r
180 item.SubItems[1].Text = drp_audioTrack.SelectedItem.ToString();
\r
183 drp_audioTrack.SelectedIndex = 0;
\r
184 if (drp_audioTrack.SelectedItem != null)
\r
185 foreach (ListViewItem item in lv_audioList.Items)
\r
186 item.SubItems[1].Text = drp_audioTrack.SelectedItem.ToString();
\r
190 drp_audioTrack.SelectedIndex = drp_audioTrack.Items.Count >= 3 ? 2 : 0;
\r
191 // "Use Foreign language audio and Subtitles"
\r
195 // Control and ListView
\r
198 /// one of the controls has changed. Event handler
\r
200 /// <param name="sender">
\r
203 /// <param name="e">
\r
206 private void controlChanged(object sender, EventArgs e)
\r
208 Control ctl = (Control)sender;
\r
212 case "drp_audioTrack":
\r
213 if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)
\r
214 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[1].Text = drp_audioTrack.Text;
\r
216 case "drp_audioEncoder":
\r
220 // Configure the widgets with values
\r
221 if (drp_audioEncoder.Text.Contains("AC3") || drp_audioEncoder.Text.Contains("DTS"))
\r
223 drp_audioMix.Enabled =
\r
224 drp_audioBitrate.Enabled = drp_audioSample.Enabled = tb_drc.Enabled = false;
\r
225 lbl_bitrate.Enabled =
\r
227 lbl_drcHeader.Enabled = lbl_mixdown.Enabled = lbl_sampleRate.Enabled = false;
\r
231 drp_audioMix.Enabled =
\r
232 drp_audioBitrate.Enabled = drp_audioSample.Enabled = tb_drc.Enabled = true;
\r
233 lbl_bitrate.Enabled =
\r
235 lbl_drcHeader.Enabled = lbl_mixdown.Enabled = lbl_sampleRate.Enabled = true;
\r
238 // Update an item in the Audio list if required.
\r
239 if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)
\r
240 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[2].Text = drp_audioEncoder.Text;
\r
242 case "drp_audioMix":
\r
245 if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)
\r
246 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[3].Text = drp_audioMix.Text;
\r
248 case "drp_audioSample":
\r
249 if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)
\r
250 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[4].Text = drp_audioSample.Text;
\r
252 case "drp_audioBitrate":
\r
253 // Update an item in the Audio list if required.
\r
254 if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)
\r
255 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[5].Text = drp_audioBitrate.Text;
\r
259 if (tb_drc.Value == 0) value = 0;
\r
261 value = ((tb_drc.Value - 1) / 10.0) + 1;
\r
263 lbl_drc.Text = value.ToString();
\r
265 // Update an item in the Audio list if required.
\r
266 if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)
\r
268 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[6].Text = value.ToString();
\r
269 lv_audioList.Select();
\r
274 lv_audioList.Select();
\r
278 /// The Audio List selected index changed event handler
\r
280 /// <param name="sender">
\r
283 /// <param name="e">
\r
286 private void lv_audioList_SelectedIndexChanged(object sender, EventArgs e)
\r
288 // Set the dropdown controls based on the selected item in the Audio List.
\r
289 if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)
\r
291 drp_audioTrack.SelectedItem = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[1].Text;
\r
292 drp_audioEncoder.SelectedItem = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[2].Text;
\r
293 drp_audioMix.SelectedItem = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[3].Text;
\r
294 drp_audioSample.SelectedItem = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[4].Text;
\r
295 drp_audioBitrate.SelectedItem = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[5].Text;
\r
298 double.TryParse(lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[6].Text, out drcValue);
\r
300 drcValue = ((drcValue * 10) + 1) - 10;
\r
301 int.TryParse(drcValue.ToString(), out drcCalculated);
\r
302 tb_drc.Value = drcCalculated;
\r
303 lbl_drc.Text = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[6].Text;
\r
305 AudioTrackGroup.Text = "Selected Track: " +
\r
306 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[0].Text;
\r
309 AudioTrackGroup.Text = "Selected Track: None (Click \"Add Track\" to add)";
\r
315 /// The Add Audio Track button event handler
\r
317 /// <param name="sender">
\r
320 /// <param name="e">
\r
323 private void btn_addAudioTrack_Click(object sender, EventArgs e)
\r
325 if (drp_audioTrack.Text == "None Found")
\r
328 "Your source appears to have no audio tracks that HandBrake supports.",
\r
330 MessageBoxButtons.OK,
\r
331 MessageBoxIcon.Warning);
\r
336 if (tb_drc.Value != 0)
\r
337 value = ((tb_drc.Value - 1) / 10.0) + 1;
\r
339 // Create a new row for the Audio list based on the currently selected items in the dropdown.
\r
340 ListViewItem newTrack = new ListViewItem(GetNewID().ToString());
\r
341 newTrack.SubItems.Add(drp_audioTrack.Text);
\r
342 newTrack.SubItems.Add(drp_audioEncoder.Text);
\r
343 newTrack.SubItems.Add(drp_audioMix.Text);
\r
344 newTrack.SubItems.Add(drp_audioSample.Text);
\r
345 newTrack.SubItems.Add(drp_audioBitrate.Text);
\r
346 newTrack.SubItems.Add(value.ToString());
\r
347 lv_audioList.Items.Add(newTrack);
\r
349 // The Audio List has changed to raise the event.
\r
350 if (this.AudioListChanged != null)
\r
351 this.AudioListChanged(this, new EventArgs());
\r
353 // Select the newly added track and select the control
\r
354 lv_audioList.Items[lv_audioList.Items.Count - 1].Selected = true;
\r
355 lv_audioList.Select();
\r
359 /// The Remove Track button event handler
\r
361 /// <param name="sender">
\r
364 /// <param name="e">
\r
367 private void btn_RemoveAudioTrack_Click(object sender, EventArgs e)
\r
375 /// The Audio List Move Up menu item
\r
377 /// <param name="sender">
\r
380 /// <param name="e">
\r
383 private void audioList_moveup_Click(object sender, EventArgs e)
\r
389 /// The audio list move down menu item
\r
391 /// <param name="sender">
\r
394 /// <param name="e">
\r
397 private void audioList_movedown_Click(object sender, EventArgs e)
\r
403 /// The audio list remove menu item
\r
405 /// <param name="sender">
\r
408 /// <param name="e">
\r
411 private void audioList_remove_Click(object sender, EventArgs e)
\r
416 // Public Functions
\r
419 /// Add track for preset
\r
421 /// <param name="item">
\r
424 private void AddTrackForPreset(ListViewItem item)
\r
426 lv_audioList.Items.Add(item);
\r
427 if (this.AudioListChanged != null)
\r
428 this.AudioListChanged(this, new EventArgs());
\r
432 /// Clear the audio list
\r
434 private void ClearAudioList()
\r
436 lv_audioList.Items.Clear();
\r
437 if (this.AudioListChanged != null)
\r
438 this.AudioListChanged(this, new EventArgs());
\r
442 /// Get a new ID for the next audio track
\r
447 private int GetNewID()
\r
449 return lv_audioList.Items.Count + 1;
\r
453 /// Remove an audio track from the list
\r
455 private void RemoveTrack()
\r
457 // Remove the Item and reselect the control if the following conditions are met.
\r
458 if (lv_audioList.SelectedItems.Count != 0)
\r
460 // The Audio List is about to change so raise the event.
\r
461 if (this.AudioListChanged != null)
\r
462 this.AudioListChanged(this, new EventArgs());
\r
464 // Record the current selected index.
\r
465 int currentPosition = lv_audioList.SelectedIndices[0];
\r
467 lv_audioList.Items.RemoveAt(lv_audioList.SelectedIndices[0]);
\r
469 // Now reslect the correct item and give focus to the audio list.
\r
470 if (lv_audioList.Items.Count != 0)
\r
472 if (currentPosition <= (lv_audioList.Items.Count - 1))
\r
473 lv_audioList.Items[currentPosition].Selected = true;
\r
474 else if (currentPosition > (lv_audioList.Items.Count - 1))
\r
475 lv_audioList.Items[lv_audioList.Items.Count - 1].Selected = true;
\r
477 lv_audioList.Select();
\r
479 // Regenerate the ID numers
\r
480 ReGenerateListIDs();
\r
485 /// Move an audio track up or down the audio list
\r
487 /// <param name="up">
\r
490 private void MoveTrack(bool up)
\r
492 if (lv_audioList.SelectedIndices.Count == 0) return;
\r
494 ListViewItem item = lv_audioList.SelectedItems[0];
\r
495 int index = item.Index;
\r
500 if (index < lv_audioList.Items.Count || (lv_audioList.Items.Count > index && index >= 0))
\r
502 lv_audioList.Items.Remove(item);
\r
503 lv_audioList.Items.Insert(index, item);
\r
504 item.Selected = true;
\r
505 lv_audioList.Focus();
\r
510 /// Regenerate all the audio track id's on the audio list
\r
512 private void ReGenerateListIDs()
\r
515 foreach (ListViewItem item in lv_audioList.Items)
\r
517 item.SubItems[0].Text = i.ToString();
\r
523 /// Set the bitrate dropdown
\r
525 private void SetBitrate()
\r
528 drp_audioBitrate.Items.Remove("Auto");
\r
529 drp_audioBitrate.Items.Remove("192");
\r
530 drp_audioBitrate.Items.Remove("224");
\r
531 drp_audioBitrate.Items.Remove("256");
\r
532 drp_audioBitrate.Items.Remove("320");
\r
533 drp_audioBitrate.Items.Remove("384");
\r
534 drp_audioBitrate.Items.Remove("448");
\r
535 drp_audioBitrate.Items.Remove("768");
\r
537 switch (drp_audioEncoder.Text)
\r
540 max = drp_audioMix.Text.Contains("6 Channel") ? 768 : 320;
\r
545 case "Vorbis (vorbis)":
\r
548 case "AC3 Passthru":
\r
549 drp_audioBitrate.Items.Add("Auto");
\r
550 drp_audioBitrate.SelectedItem = "Auto";
\r
551 drp_audioSample.SelectedItem = "Auto";
\r
553 case "DTS Passthru":
\r
554 drp_audioBitrate.Items.Add("Auto");
\r
555 drp_audioBitrate.SelectedItem = "Auto";
\r
556 drp_audioSample.SelectedItem = "Auto";
\r
562 drp_audioBitrate.Items.Add("192");
\r
563 drp_audioBitrate.Items.Add("224");
\r
564 drp_audioBitrate.Items.Add("256");
\r
565 drp_audioBitrate.Items.Add("320");
\r
570 drp_audioBitrate.Items.Add("384");
\r
575 drp_audioBitrate.Items.Add("448");
\r
576 drp_audioBitrate.Items.Add("768");
\r
579 if (drp_audioBitrate.SelectedItem == null)
\r
580 drp_audioBitrate.SelectedIndex = drp_audioBitrate.Items.Count - 1;
\r
584 /// Set the mixdown dropdown
\r
586 private void SetMixDown()
\r
588 drp_audioMix.Items.Clear();
\r
589 drp_audioMix.Items.Add("Mono");
\r
590 drp_audioMix.Items.Add("Stereo");
\r
591 drp_audioMix.Items.Add("Dolby Surround");
\r
592 drp_audioMix.Items.Add("Dolby Pro Logic II");
\r
593 drp_audioMix.Items.Add("6 Channel Discrete");
\r
594 drp_audioMix.Items.Add("AC3 Passthru");
\r
595 drp_audioMix.Items.Add("DTS Passthru");
\r
597 drp_audioMix.SelectedItem = "Dolby Pro Logic II";
\r
599 switch (drp_audioEncoder.Text)
\r
602 drp_audioMix.Items.Remove("AC3 Passthru");
\r
603 drp_audioMix.Items.Remove("DTS Passthru");
\r
606 drp_audioMix.Items.Remove("Mono");
\r
607 drp_audioMix.Items.Remove("6 Channel Discrete");
\r
608 drp_audioMix.Items.Remove("AC3 Passthru");
\r
609 drp_audioMix.Items.Remove("DTS Passthru");
\r
611 case "Vorbis (vorbis)":
\r
612 drp_audioMix.Items.Remove("AC3 Passthru");
\r
613 drp_audioMix.Items.Remove("DTS Passthru");
\r
615 case "AC3 Passthru":
\r
616 drp_audioMix.SelectedItem = "AC3 Passthru";
\r
618 case "DTS Passthru":
\r
619 drp_audioMix.SelectedItem = "DTS Passthru";
\r