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
14 using HandBrake.ApplicationServices.Parsing;
\r
17 using AudioTrack = Model.AudioTrack;
\r
20 /// The AudioPanel Control
\r
22 public partial class AudioPanel : UserControl
\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 /// The audio list has changed
\r
38 public event EventHandler AudioListChanged;
\r
41 /// Get the audio panel
\r
43 /// <returns>A listview containing the audio tracks</returns>
\r
44 public DataGridView GetAudioPanel()
\r
50 /// Set the File Container. This funciton is used to limit the available options for each file container.
\r
52 /// <param name="path">
\r
55 public void SetContainer(string path)
\r
57 string oldval = drp_audioEncoder.Text;
\r
58 if ((path.Contains("MP4")) || (path.Contains("M4V")))
\r
60 drp_audioEncoder.Items.Clear();
\r
61 drp_audioEncoder.Items.Add("AAC (faac)");
\r
62 drp_audioEncoder.Items.Add("MP3 (lame)");
\r
63 drp_audioEncoder.Items.Add("AC3 Passthru");
\r
64 if ((oldval != "AAC (faac)") && (oldval != "AC3 Passthru"))
\r
65 drp_audioEncoder.SelectedIndex = 0;
\r
67 drp_audioEncoder.SelectedItem = oldval;
\r
69 else if (path.Contains("MKV"))
\r
71 drp_audioEncoder.Items.Clear();
\r
72 drp_audioEncoder.Items.Add("AAC (faac)");
\r
73 drp_audioEncoder.Items.Add("MP3 (lame)");
\r
74 drp_audioEncoder.Items.Add("AC3 Passthru");
\r
75 drp_audioEncoder.Items.Add("DTS Passthru");
\r
76 drp_audioEncoder.Items.Add("Vorbis (vorbis)");
\r
77 drp_audioEncoder.SelectedItem = oldval;
\r
79 if (drp_audioEncoder.Text == string.Empty)
\r
80 drp_audioEncoder.SelectedIndex = 0;
\r
83 // Make sure the table is updated with new audio codecs
\r
84 foreach (DataGridViewRow row in audioList.Rows)
\r
86 if (!drp_audioEncoder.Items.Contains(row.Cells[2].Value))
\r
87 row.Cells[2].Value = drp_audioEncoder.Items[0].ToString();
\r
92 /// Checks if the settings used required the .m4v (rather than .mp4) extension
\r
94 /// <returns>True if m4v is required</returns>
\r
95 public bool RequiresM4V()
\r
97 return this.audioList.Rows.Cast<DataGridViewRow>().Any(row => row.Cells[2].Value.ToString().Contains("AC3"));
\r
101 /// Load an arraylist of AudioTrack items into the list.
\r
103 /// <param name="audioTracks">List of audio tracks</param>
\r
104 public void LoadTracks(ArrayList audioTracks)
\r
108 if (audioTracks == null)
\r
111 foreach (AudioTrack track in audioTracks)
\r
113 DataGridViewRow newTrack = new DataGridViewRow();
\r
114 newTrack.CreateCells(audioList);
\r
115 newTrack.Cells[0].Value = GetNewID().ToString();
\r
116 newTrack.Cells[1].Value = "Automatic";
\r
117 newTrack.Cells[2].Value = track.Encoder;
\r
118 newTrack.Cells[3].Value = track.MixDown;
\r
119 newTrack.Cells[4].Value = track.SampleRate;
\r
120 newTrack.Cells[5].Value = track.Encoder.Contains("AC3") || track.Encoder.Contains("DTS") ? "Auto" : track.Bitrate;
\r
121 newTrack.Cells[6].Value = track.DRC;
\r
122 AddTrackForPreset(newTrack);
\r
125 this.AutomaticTrackSelection();
\r
129 /// Set the Track list dropdown from the parsed title captured during the scan
\r
131 /// <param name="selectedTitle">The selected title</param>
\r
132 /// <param name="preset">A preset</param>
\r
133 public void SetTrackListFromPreset(Title selectedTitle, Preset preset)
\r
135 if (selectedTitle.AudioTracks.Count == 0)
\r
137 audioList.Rows.Clear();
\r
138 drp_audioTrack.Items.Clear();
\r
139 drp_audioTrack.Items.Add("None Found");
\r
140 drp_audioTrack.SelectedIndex = 0;
\r
144 // Setup the Audio track source dropdown with the new audio tracks.
\r
145 drp_audioTrack.Items.Clear();
\r
146 drp_audioTrack.Items.AddRange(selectedTitle.AudioTracks.ToArray());
\r
148 // Reset the Audio Track Selection to the first audio track of the source, or Audiomatic if that fails
\r
149 foreach (DataGridViewRow row in this.audioList.Rows)
\r
151 row.Cells[1].Value = "Automatic";
\r
154 // Add any tracks the preset has, if there is a preset and no audio tracks in the list currently
\r
155 if (audioList.Rows.Count == 0 && preset != null)
\r
157 QueryParser parsed = QueryParser.Parse(preset.Query);
\r
158 foreach (AudioTrack audioTrack in parsed.AudioInformation)
\r
160 DataGridViewRow newTrack = new DataGridViewRow();
\r
161 newTrack.CreateCells(audioList);
\r
162 newTrack.Cells[0].Value = GetNewID().ToString();
\r
163 newTrack.Cells[1].Value = (audioTrack.Track);
\r
164 newTrack.Cells[2].Value = (audioTrack.Encoder);
\r
165 newTrack.Cells[3].Value = (audioTrack.MixDown);
\r
166 newTrack.Cells[4].Value = (audioTrack.SampleRate);
\r
167 newTrack.Cells[5].Value = (audioTrack.Bitrate);
\r
168 newTrack.Cells[6].Value = (audioTrack.DRC);
\r
169 audioList.Rows.Add(newTrack);
\r
173 this.AutomaticTrackSelection();
\r
176 private void AutomaticTrackSelection()
\r
178 // Handle Native Language and "Dub Foreign language audio" and "Use Foreign language audio and Subtitles" Options
\r
179 if (Properties.Settings.Default.NativeLanguage == "Any")
\r
181 drp_audioTrack.SelectedIndex = 0;
\r
182 foreach (DataGridViewRow item in audioList.Rows)
\r
184 if (this.drp_audioTrack.SelectedItem != null)
\r
186 item.Cells[1].Value = this.drp_audioTrack.SelectedItem.ToString();
\r
192 int mode = Properties.Settings.Default.DubMode;
\r
197 // Dub Foreign Language Audio
\r
198 // Select the prefered language audio, or the first track if it doesn't exist.
\r
200 foreach (object item in drp_audioTrack.Items)
\r
202 if (item.ToString().Contains(Properties.Settings.Default.NativeLanguage))
\r
204 drp_audioTrack.SelectedIndex = i;
\r
211 if (drp_audioTrack.SelectedItem != null)
\r
212 foreach (DataGridViewRow item in audioList.Rows)
\r
213 item.Cells[1].Value = drp_audioTrack.SelectedItem.ToString();
\r
216 drp_audioTrack.SelectedIndex = 0;
\r
217 if (drp_audioTrack.SelectedItem != null)
\r
218 foreach (DataGridViewRow item in audioList.Rows)
\r
219 item.Cells[1].Value = drp_audioTrack.SelectedItem.ToString();
\r
225 // Select the first track which is hopefully the default and foreign track.
\r
226 drp_audioTrack.SelectedIndex = 0;
\r
228 if (drp_audioTrack.SelectedItem != null)
\r
229 foreach (DataGridViewRow item in audioList.Rows)
\r
230 item.Cells[1].Value = drp_audioTrack.SelectedItem.ToString();
\r
236 // Control and ListView
\r
239 /// one of the controls has changed. Event handler
\r
241 /// <param name="sender">
\r
244 /// <param name="e">
\r
247 private void controlChanged(object sender, EventArgs e)
\r
249 Control ctl = (Control)sender;
\r
253 case "drp_audioTrack":
\r
254 if (audioList.Rows.Count != 0 && audioList.SelectedRows.Count != 0)
\r
256 audioList.SelectedRows[0].Cells[1].Value = drp_audioTrack.Text;
\r
258 // If the track isn't AC3, and the encoder is, change it.
\r
259 if (audioList.SelectedRows[0].Cells[2].Value.ToString().Contains("AC3") && !audioList.SelectedRows[0].Cells[1].Value.ToString().Contains("AC3"))
\r
262 drp_audioEncoder.SelectedIndex = 0;
\r
265 // If the track isn't DTS, and the encoder is, change it.
\r
266 if (audioList.SelectedRows[0].Cells[2].Value.ToString().Contains("DTS") && !audioList.SelectedRows[0].Cells[1].Value.ToString().Contains("DTS"))
\r
269 drp_audioEncoder.SelectedIndex = 0;
\r
273 case "drp_audioEncoder":
\r
277 // Configure the widgets with values
\r
278 if (drp_audioEncoder.Text.Contains("AC3") || drp_audioEncoder.Text.Contains("DTS"))
\r
280 drp_audioMix.Enabled =
\r
281 drp_audioBitrate.Enabled = drp_audioSample.Enabled = tb_drc.Enabled = false;
\r
282 lbl_bitrate.Enabled =
\r
284 lbl_drcHeader.Enabled = lbl_mixdown.Enabled = lbl_sampleRate.Enabled = false;
\r
288 drp_audioMix.Enabled =
\r
289 drp_audioBitrate.Enabled = drp_audioSample.Enabled = tb_drc.Enabled = true;
\r
290 lbl_bitrate.Enabled =
\r
292 lbl_drcHeader.Enabled = lbl_mixdown.Enabled = lbl_sampleRate.Enabled = true;
\r
295 // Update an item in the Audio list if required.
\r
296 if (audioList.Rows.Count != 0 && audioList.SelectedRows.Count != 0)
\r
297 audioList.SelectedRows[0].Cells[2].Value = drp_audioEncoder.Text;
\r
299 case "drp_audioMix":
\r
302 if (audioList.Rows.Count != 0 && audioList.SelectedRows.Count != 0)
\r
303 audioList.SelectedRows[0].Cells[3].Value = drp_audioMix.Text;
\r
305 case "drp_audioSample":
\r
306 if (audioList.Rows.Count != 0 && audioList.SelectedRows.Count != 0)
\r
307 audioList.SelectedRows[0].Cells[4].Value = drp_audioSample.Text;
\r
309 case "drp_audioBitrate":
\r
310 // Update an item in the Audio list if required.
\r
311 if (audioList.Rows.Count != 0 && audioList.SelectedRows.Count != 0)
\r
312 audioList.SelectedRows[0].Cells[5].Value = drp_audioBitrate.Text;
\r
316 if (tb_drc.Value == 0) value = 0;
\r
318 value = ((tb_drc.Value - 1) / 10.0) + 1;
\r
320 lbl_drc.Text = value.ToString();
\r
322 // Update an item in the Audio list if required.
\r
323 if (audioList.Rows.Count != 0 && audioList.SelectedRows.Count != 0)
\r
325 audioList.SelectedRows[0].Cells[6].Value = value.ToString();
\r
326 audioList.Select();
\r
331 audioList.Select();
\r
335 /// The Audio List selected index changed event handler
\r
337 /// <param name="sender">
\r
340 /// <param name="e">
\r
343 private void audioList_SelectionChanged(object sender, EventArgs e)
\r
345 // Set the dropdown controls based on the selected item in the Audio List.
\r
346 if (audioList.Rows.Count != 0 && audioList.SelectedRows.Count != 0)
\r
348 drp_audioTrack.SelectedItem = audioList.SelectedRows[0].Cells[1].Value;
\r
349 drp_audioEncoder.SelectedItem = audioList.SelectedRows[0].Cells[2].Value;
\r
350 drp_audioMix.SelectedItem = audioList.SelectedRows[0].Cells[3].Value;
\r
351 drp_audioSample.SelectedItem = audioList.SelectedRows[0].Cells[4].Value;
\r
352 drp_audioBitrate.SelectedItem = audioList.SelectedRows[0].Cells[5].Value;
\r
355 double.TryParse(audioList.SelectedRows[0].Cells[6].Value.ToString(), out drcValue);
\r
357 drcValue = ((drcValue * 10) + 1) - 10;
\r
358 int.TryParse(drcValue.ToString(), out drcCalculated);
\r
359 tb_drc.Value = drcCalculated;
\r
360 lbl_drc.Text = audioList.SelectedRows[0].Cells[6].Value.ToString();
\r
362 AudioTrackGroup.Text = "Selected Track: " + audioList.SelectedRows[0].Cells[0].Value;
\r
365 AudioTrackGroup.Text = "Selected Track: None (Click \"Add Track\" to add)";
\r
371 /// The Add Audio Track button event handler
\r
373 /// <param name="sender">
\r
376 /// <param name="e">
\r
379 private void btn_addAudioTrack_Click(object sender, EventArgs e)
\r
381 if (drp_audioTrack.Text == "None Found")
\r
384 "Your source appears to have no audio tracks that HandBrake supports.",
\r
386 MessageBoxButtons.OK,
\r
387 MessageBoxIcon.Warning);
\r
392 if (tb_drc.Value != 0)
\r
393 value = ((tb_drc.Value - 1) / 10.0) + 1;
\r
395 // Create a new row for the Audio list based on the currently selected items in the dropdown.
\r
396 DataGridViewRow newTrack = new DataGridViewRow();
\r
397 newTrack.CreateCells(audioList);
\r
398 newTrack.Cells[0].Value = GetNewID().ToString();
\r
399 newTrack.Cells[1].Value = drp_audioTrack.Text;
\r
400 newTrack.Cells[2].Value = drp_audioEncoder.Text;
\r
401 newTrack.Cells[3].Value = drp_audioMix.Text;
\r
402 newTrack.Cells[4].Value = drp_audioSample.Text;
\r
403 newTrack.Cells[5].Value = drp_audioBitrate.Text;
\r
404 newTrack.Cells[6].Value = value.ToString();
\r
405 audioList.Rows.Add(newTrack);
\r
407 // The Audio List has changed to raise the event.
\r
408 if (this.AudioListChanged != null)
\r
409 this.AudioListChanged(this, new EventArgs());
\r
411 // Select the newly added track and select the control
\r
412 audioList.ClearSelection();
\r
413 audioList.Rows[audioList.Rows.Count - 1].Selected = true;
\r
414 audioList.Select();
\r
418 /// The Remove Track button event handler
\r
420 /// <param name="sender">
\r
423 /// <param name="e">
\r
426 private void btn_RemoveAudioTrack_Click(object sender, EventArgs e)
\r
434 /// The Audio List Move Up menu item
\r
436 /// <param name="sender">
\r
439 /// <param name="e">
\r
442 private void audioList_moveup_Click(object sender, EventArgs e)
\r
448 /// The audio list move down menu item
\r
450 /// <param name="sender">
\r
453 /// <param name="e">
\r
456 private void audioList_movedown_Click(object sender, EventArgs e)
\r
462 /// The audio list remove menu item
\r
464 /// <param name="sender">
\r
467 /// <param name="e">
\r
470 private void audioList_remove_Click(object sender, EventArgs e)
\r
475 // Private Functions
\r
478 /// Add track for preset
\r
480 /// <param name="item">
\r
483 private void AddTrackForPreset(DataGridViewRow item)
\r
485 audioList.Rows.Add(item);
\r
486 if (this.AudioListChanged != null)
\r
487 this.AudioListChanged(this, new EventArgs());
\r
491 /// Clear the audio list
\r
493 private void ClearAudioList()
\r
495 audioList.Rows.Clear();
\r
496 if (this.AudioListChanged != null)
\r
497 this.AudioListChanged(this, new EventArgs());
\r
501 /// Get a new ID for the next audio track
\r
506 private int GetNewID()
\r
508 return audioList.Rows.Count + 1;
\r
512 /// Remove an audio track from the list
\r
514 private void RemoveTrack()
\r
516 // Remove the Item and reselect the control if the following conditions are met.
\r
517 if (audioList.SelectedRows.Count != 0)
\r
519 // The Audio List is about to change so raise the event.
\r
520 if (this.AudioListChanged != null)
\r
521 this.AudioListChanged(this, new EventArgs());
\r
523 // Record the current selected index.
\r
524 int currentPosition = audioList.SelectedRows[0].Index;
\r
526 audioList.Rows.Remove(audioList.SelectedRows[0]);
\r
528 // Now reslect the correct item and give focus to the audio list.
\r
529 if (audioList.Rows.Count != 0)
\r
531 audioList.ClearSelection();
\r
532 if (currentPosition <= (audioList.Rows.Count - 1))
\r
533 audioList.Rows[currentPosition].Selected = true;
\r
534 else if (currentPosition > (audioList.Rows.Count - 1))
\r
535 audioList.Rows[audioList.Rows.Count - 1].Selected = true;
\r
537 audioList.Select();
\r
539 // Regenerate the ID numers
\r
540 ReGenerateListIDs();
\r
545 /// Move an audio track up or down the audio list
\r
547 /// <param name="up">
\r
550 private void MoveTrack(bool up)
\r
552 if (audioList.SelectedRows.Count == 0) return;
\r
554 DataGridViewRow item = audioList.SelectedRows[0];
\r
555 int index = item.Index;
\r
560 if (index < audioList.Rows.Count || (audioList.Rows.Count > index && index >= 0))
\r
562 audioList.Rows.Remove(item);
\r
563 audioList.Rows.Insert(index, item);
\r
564 audioList.ClearSelection();
\r
565 item.Selected = true;
\r
570 /// Regenerate all the audio track id's on the audio list
\r
572 private void ReGenerateListIDs()
\r
575 foreach (DataGridViewRow item in audioList.Rows)
\r
577 item.Cells[0].Value = i.ToString();
\r
583 /// Set the bitrate dropdown
\r
585 private void SetBitrate()
\r
588 drp_audioBitrate.Items.Remove("Auto");
\r
589 drp_audioBitrate.Items.Remove("192");
\r
590 drp_audioBitrate.Items.Remove("224");
\r
591 drp_audioBitrate.Items.Remove("256");
\r
592 drp_audioBitrate.Items.Remove("320");
\r
593 drp_audioBitrate.Items.Remove("384");
\r
594 drp_audioBitrate.Items.Remove("448");
\r
595 drp_audioBitrate.Items.Remove("768");
\r
597 switch (drp_audioEncoder.Text)
\r
600 max = drp_audioMix.Text.Contains("6 Channel") ? 768 : 320;
\r
605 case "Vorbis (vorbis)":
\r
608 case "AC3 Passthru":
\r
609 drp_audioBitrate.Items.Add("Auto");
\r
610 drp_audioBitrate.SelectedItem = "Auto";
\r
611 drp_audioSample.SelectedItem = "Auto";
\r
613 case "DTS Passthru":
\r
614 drp_audioBitrate.Items.Add("Auto");
\r
615 drp_audioBitrate.SelectedItem = "Auto";
\r
616 drp_audioSample.SelectedItem = "Auto";
\r
622 drp_audioBitrate.Items.Add("192");
\r
623 drp_audioBitrate.Items.Add("224");
\r
624 drp_audioBitrate.Items.Add("256");
\r
625 drp_audioBitrate.Items.Add("320");
\r
630 drp_audioBitrate.Items.Add("384");
\r
635 drp_audioBitrate.Items.Add("448");
\r
636 drp_audioBitrate.Items.Add("768");
\r
639 if (drp_audioBitrate.SelectedItem == null)
\r
640 drp_audioBitrate.SelectedIndex = drp_audioBitrate.Items.Count - 1;
\r
644 /// Set the mixdown dropdown
\r
646 private void SetMixDown()
\r
648 drp_audioMix.Items.Clear();
\r
649 drp_audioMix.Items.Add("Mono");
\r
650 drp_audioMix.Items.Add("Stereo");
\r
651 drp_audioMix.Items.Add("Dolby Surround");
\r
652 drp_audioMix.Items.Add("Dolby Pro Logic II");
\r
653 drp_audioMix.Items.Add("6 Channel Discrete");
\r
654 drp_audioMix.Items.Add("AC3 Passthru");
\r
655 drp_audioMix.Items.Add("DTS Passthru");
\r
657 drp_audioMix.SelectedItem = "Dolby Pro Logic II";
\r
659 switch (drp_audioEncoder.Text)
\r
662 drp_audioMix.Items.Remove("AC3 Passthru");
\r
663 drp_audioMix.Items.Remove("DTS Passthru");
\r
666 drp_audioMix.Items.Remove("6 Channel Discrete");
\r
667 drp_audioMix.Items.Remove("AC3 Passthru");
\r
668 drp_audioMix.Items.Remove("DTS Passthru");
\r
670 case "Vorbis (vorbis)":
\r
671 drp_audioMix.Items.Remove("AC3 Passthru");
\r
672 drp_audioMix.Items.Remove("DTS Passthru");
\r
674 case "AC3 Passthru":
\r
675 drp_audioMix.SelectedItem = "AC3 Passthru";
\r
677 case "DTS Passthru":
\r
678 drp_audioMix.SelectedItem = "DTS Passthru";
\r