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
18 using AudioTrack = HandBrake.ApplicationServices.Model.Encoding.AudioTrack;
\r
21 /// The AudioPanel Control
\r
23 public partial class AudioPanel : UserControl
\r
26 private const string AC3Passthru = "AC3 Passthru";
\r
28 private const string DTSPassthru = "DTS Passthru";
\r
31 /// Initializes a new instance of the <see cref="AudioPanel"/> class.
\r
32 /// Create a new instance of the Audio Panel
\r
36 InitializeComponent();
\r
37 drp_audioMix.SelectedItem = "Dolby Pro Logic II";
\r
38 drp_audioSample.SelectedIndex = 1;
\r
42 /// The audio list has changed
\r
44 public event EventHandler AudioListChanged;
\r
47 /// Get the audio panel
\r
49 /// <returns>A listview containing the audio tracks</returns>
\r
50 public DataGridView GetAudioPanel()
\r
56 /// Set the File Container. This funciton is used to limit the available options for each file container.
\r
58 /// <param name="path">
\r
61 public void SetContainer(string path)
\r
63 string oldval = drp_audioEncoder.Text;
\r
65 drp_audioEncoder.Items.Clear();
\r
66 drp_audioEncoder.Items.Add("AAC (faac)");
\r
67 drp_audioEncoder.Items.Add("MP3 (lame)");
\r
68 drp_audioEncoder.Items.Add(AC3Passthru);
\r
69 drp_audioEncoder.Items.Add("AC3 (ffmpeg)");
\r
71 if (path.Contains("MKV"))
\r
73 drp_audioEncoder.Items.Add(DTSPassthru);
\r
74 drp_audioEncoder.Items.Add("Vorbis (vorbis)");
\r
77 if (!drp_audioEncoder.Text.Contains(oldval))
\r
78 drp_audioEncoder.SelectedIndex = 0;
\r
80 drp_audioEncoder.SelectedItem = oldval;
\r
82 // Make sure the table is updated with new audio codecs
\r
83 // Defaults to AAC encoding.
\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(AC3Passthru) || track.Encoder.Contains(DTSPassthru) ? "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 // Add any tracks the preset has, if there is a preset and no audio tracks in the list currently
\r
149 if (audioList.Rows.Count == 0 && preset != null)
\r
151 QueryParser parsed = QueryParser.Parse(preset.Query);
\r
152 foreach (AudioTrack audioTrack in parsed.AudioInformation)
\r
154 DataGridViewRow newTrack = new DataGridViewRow();
\r
155 newTrack.CreateCells(audioList);
\r
156 newTrack.Cells[0].Value = GetNewID().ToString();
\r
157 newTrack.Cells[1].Value = (audioTrack.Track);
\r
158 newTrack.Cells[2].Value = (audioTrack.Encoder);
\r
159 newTrack.Cells[3].Value = (audioTrack.MixDown);
\r
160 newTrack.Cells[4].Value = (audioTrack.SampleRate);
\r
161 newTrack.Cells[5].Value = (audioTrack.Bitrate);
\r
162 newTrack.Cells[6].Value = (audioTrack.DRC);
\r
163 audioList.Rows.Add(newTrack);
\r
167 this.AutomaticTrackSelection();
\r
170 private void AutomaticTrackSelection()
\r
172 // Handle Native Language and "Dub Foreign language audio" and "Use Foreign language audio and Subtitles" Options
\r
173 if (Properties.Settings.Default.NativeLanguage == "Any")
\r
175 drp_audioTrack.SelectedIndex = 0;
\r
176 foreach (DataGridViewRow item in audioList.Rows)
\r
178 if (this.drp_audioTrack.SelectedItem != null)
\r
180 item.Cells[1].Value = this.drp_audioTrack.SelectedItem.ToString();
\r
186 int mode = Properties.Settings.Default.DubMode;
\r
191 // Dub Foreign Language Audio
\r
192 // Select the prefered language audio, or the first track if it doesn't exist.
\r
194 foreach (object item in drp_audioTrack.Items)
\r
196 if (item.ToString().Contains(Properties.Settings.Default.NativeLanguage))
\r
198 drp_audioTrack.SelectedIndex = i;
\r
205 if (drp_audioTrack.SelectedItem != null)
\r
206 foreach (DataGridViewRow item in audioList.Rows)
\r
207 item.Cells[1].Value = drp_audioTrack.SelectedItem.ToString();
\r
210 drp_audioTrack.SelectedIndex = 0;
\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
219 // Select the first track which is hopefully the default and foreign track.
\r
220 drp_audioTrack.SelectedIndex = 0;
\r
222 if (drp_audioTrack.SelectedItem != null)
\r
223 foreach (DataGridViewRow item in audioList.Rows)
\r
224 item.Cells[1].Value = drp_audioTrack.SelectedItem.ToString();
\r
230 // Control and ListView
\r
233 /// one of the controls has changed. Event handler
\r
235 /// <param name="sender">
\r
238 /// <param name="e">
\r
241 private void ControlChanged(object sender, EventArgs e)
\r
243 Control ctl = (Control)sender;
\r
247 case "drp_audioTrack":
\r
248 if (audioList.Rows.Count != 0 && audioList.SelectedRows.Count != 0)
\r
250 audioList.SelectedRows[0].Cells[1].Value = drp_audioTrack.Text;
\r
252 // If the track isn't AC3, and the encoder is, change it.
\r
253 if (audioList.SelectedRows[0].Cells[2].Value.ToString().Contains(AC3Passthru) && !audioList.SelectedRows[0].Cells[1].Value.ToString().Contains("(AC3)"))
\r
256 drp_audioEncoder.SelectedIndex = 0;
\r
259 // If the track isn't DTS, and the encoder is, change it.
\r
260 if (audioList.SelectedRows[0].Cells[2].Value.ToString().Contains(DTSPassthru) && !audioList.SelectedRows[0].Cells[1].Value.ToString().Contains("DTS"))
\r
263 drp_audioEncoder.SelectedIndex = 0;
\r
267 case "drp_audioEncoder":
\r
271 // Configure the widgets with values
\r
272 if (drp_audioEncoder.Text.Contains(AC3Passthru) || drp_audioEncoder.Text.Contains(DTSPassthru))
\r
274 drp_audioMix.Enabled =
\r
275 drp_audioBitrate.Enabled = drp_audioSample.Enabled = tb_drc.Enabled = false;
\r
276 lbl_bitrate.Enabled =
\r
278 lbl_drcHeader.Enabled = lbl_mixdown.Enabled = lbl_sampleRate.Enabled = false;
\r
282 drp_audioMix.Enabled =
\r
283 drp_audioBitrate.Enabled = drp_audioSample.Enabled = tb_drc.Enabled = true;
\r
284 lbl_bitrate.Enabled =
\r
286 lbl_drcHeader.Enabled = lbl_mixdown.Enabled = lbl_sampleRate.Enabled = true;
\r
289 // Update an item in the Audio list if required.
\r
290 if (audioList.Rows.Count != 0 && audioList.SelectedRows.Count != 0)
\r
291 audioList.SelectedRows[0].Cells[2].Value = drp_audioEncoder.Text;
\r
293 case "drp_audioMix":
\r
296 if (audioList.Rows.Count != 0 && audioList.SelectedRows.Count != 0)
\r
297 audioList.SelectedRows[0].Cells[3].Value = drp_audioMix.Text;
\r
299 case "drp_audioSample":
\r
300 if (audioList.Rows.Count != 0 && audioList.SelectedRows.Count != 0)
\r
301 audioList.SelectedRows[0].Cells[4].Value = drp_audioSample.Text;
\r
303 case "drp_audioBitrate":
\r
304 // Update an item in the Audio list if required.
\r
305 if (audioList.Rows.Count != 0 && audioList.SelectedRows.Count != 0)
\r
306 audioList.SelectedRows[0].Cells[5].Value = drp_audioBitrate.Text;
\r
310 if (tb_drc.Value == 0) value = 0;
\r
312 value = ((tb_drc.Value - 1) / 10.0) + 1;
\r
314 lbl_drc.Text = value.ToString();
\r
316 // Update an item in the Audio list if required.
\r
317 if (audioList.Rows.Count != 0 && audioList.SelectedRows.Count != 0)
\r
319 audioList.SelectedRows[0].Cells[6].Value = value.ToString();
\r
320 audioList.Select();
\r
325 audioList.Select();
\r
329 /// The Audio List selected index changed event handler
\r
331 /// <param name="sender">
\r
334 /// <param name="e">
\r
337 private void audioList_SelectionChanged(object sender, EventArgs e)
\r
339 // Set the dropdown controls based on the selected item in the Audio List.
\r
340 if (audioList.Rows.Count != 0 && audioList.SelectedRows.Count != 0)
\r
342 drp_audioTrack.SelectedItem = audioList.SelectedRows[0].Cells[1].Value;
\r
343 drp_audioEncoder.SelectedItem = audioList.SelectedRows[0].Cells[2].Value;
\r
344 drp_audioMix.SelectedItem = audioList.SelectedRows[0].Cells[3].Value;
\r
345 drp_audioSample.SelectedItem = audioList.SelectedRows[0].Cells[4].Value;
\r
346 drp_audioBitrate.SelectedItem = audioList.SelectedRows[0].Cells[5].Value;
\r
349 double.TryParse(audioList.SelectedRows[0].Cells[6].Value.ToString(), out drcValue);
\r
351 drcValue = ((drcValue * 10) + 1) - 10;
\r
352 int.TryParse(drcValue.ToString(), out drcCalculated);
\r
353 tb_drc.Value = drcCalculated;
\r
354 lbl_drc.Text = audioList.SelectedRows[0].Cells[6].Value.ToString();
\r
356 AudioTrackGroup.Text = "Selected Track: " + audioList.SelectedRows[0].Cells[0].Value;
\r
359 AudioTrackGroup.Text = "Selected Track: None (Click \"Add Track\" to add)";
\r
365 /// The Add Audio Track button event handler
\r
367 /// <param name="sender">
\r
370 /// <param name="e">
\r
373 private void btn_addAudioTrack_Click(object sender, EventArgs e)
\r
375 if (drp_audioTrack.Text == "None Found")
\r
378 "Your source appears to have no audio tracks that HandBrake supports.",
\r
380 MessageBoxButtons.OK,
\r
381 MessageBoxIcon.Warning);
\r
386 if (tb_drc.Value != 0)
\r
387 value = ((tb_drc.Value - 1) / 10.0) + 1;
\r
389 // Create a new row for the Audio list based on the currently selected items in the dropdown.
\r
390 DataGridViewRow newTrack = new DataGridViewRow();
\r
391 newTrack.CreateCells(audioList);
\r
392 newTrack.Cells[0].Value = GetNewID().ToString();
\r
393 newTrack.Cells[1].Value = drp_audioTrack.Text;
\r
394 newTrack.Cells[2].Value = drp_audioEncoder.Text;
\r
395 newTrack.Cells[3].Value = drp_audioMix.Text;
\r
396 newTrack.Cells[4].Value = drp_audioSample.Text;
\r
397 newTrack.Cells[5].Value = drp_audioBitrate.Text;
\r
398 newTrack.Cells[6].Value = value.ToString();
\r
399 audioList.Rows.Add(newTrack);
\r
401 // The Audio List has changed to raise the event.
\r
402 if (this.AudioListChanged != null)
\r
403 this.AudioListChanged(this, new EventArgs());
\r
405 // Select the newly added track and select the control
\r
406 audioList.ClearSelection();
\r
407 audioList.Rows[audioList.Rows.Count - 1].Selected = true;
\r
408 audioList.Select();
\r
412 /// The Remove Track button event handler
\r
414 /// <param name="sender">
\r
417 /// <param name="e">
\r
420 private void btn_RemoveAudioTrack_Click(object sender, EventArgs e)
\r
428 /// The Audio List Move Up menu item
\r
430 /// <param name="sender">
\r
433 /// <param name="e">
\r
436 private void audioList_moveup_Click(object sender, EventArgs e)
\r
442 /// The audio list move down menu item
\r
444 /// <param name="sender">
\r
447 /// <param name="e">
\r
450 private void audioList_movedown_Click(object sender, EventArgs e)
\r
456 /// The audio list remove menu item
\r
458 /// <param name="sender">
\r
461 /// <param name="e">
\r
464 private void audioList_remove_Click(object sender, EventArgs e)
\r
469 // Private Functions
\r
472 /// Add track for preset
\r
474 /// <param name="item">
\r
477 private void AddTrackForPreset(DataGridViewRow item)
\r
479 audioList.Rows.Add(item);
\r
480 if (this.AudioListChanged != null)
\r
481 this.AudioListChanged(this, new EventArgs());
\r
485 /// Clear the audio list
\r
487 private void ClearAudioList()
\r
489 audioList.Rows.Clear();
\r
490 if (this.AudioListChanged != null)
\r
491 this.AudioListChanged(this, new EventArgs());
\r
495 /// Get a new ID for the next audio track
\r
500 private int GetNewID()
\r
502 return audioList.Rows.Count + 1;
\r
506 /// Remove an audio track from the list
\r
508 private void RemoveTrack()
\r
510 // Remove the Item and reselect the control if the following conditions are met.
\r
511 if (audioList.SelectedRows.Count != 0)
\r
513 // The Audio List is about to change so raise the event.
\r
514 if (this.AudioListChanged != null)
\r
515 this.AudioListChanged(this, new EventArgs());
\r
517 // Record the current selected index.
\r
518 int currentPosition = audioList.SelectedRows[0].Index;
\r
520 audioList.Rows.Remove(audioList.SelectedRows[0]);
\r
522 // Now reslect the correct item and give focus to the audio list.
\r
523 if (audioList.Rows.Count != 0)
\r
525 audioList.ClearSelection();
\r
526 if (currentPosition <= (audioList.Rows.Count - 1))
\r
527 audioList.Rows[currentPosition].Selected = true;
\r
528 else if (currentPosition > (audioList.Rows.Count - 1))
\r
529 audioList.Rows[audioList.Rows.Count - 1].Selected = true;
\r
531 audioList.Select();
\r
533 // Regenerate the ID numers
\r
534 ReGenerateListIDs();
\r
539 /// Move an audio track up or down the audio list
\r
541 /// <param name="up">
\r
544 private void MoveTrack(bool up)
\r
546 if (audioList.SelectedRows.Count == 0) return;
\r
548 DataGridViewRow item = audioList.SelectedRows[0];
\r
549 int index = item.Index;
\r
554 if (index < audioList.Rows.Count || (audioList.Rows.Count > index && index >= 0))
\r
556 audioList.Rows.Remove(item);
\r
557 audioList.Rows.Insert(index, item);
\r
558 audioList.ClearSelection();
\r
559 item.Selected = true;
\r
564 /// Regenerate all the audio track id's on the audio list
\r
566 private void ReGenerateListIDs()
\r
569 foreach (DataGridViewRow item in audioList.Rows)
\r
571 item.Cells[0].Value = i.ToString();
\r
577 /// Set the bitrate dropdown
\r
579 private void SetBitrate()
\r
582 drp_audioBitrate.Items.Remove("Auto");
\r
583 drp_audioBitrate.Items.Remove("192");
\r
584 drp_audioBitrate.Items.Remove("224");
\r
585 drp_audioBitrate.Items.Remove("256");
\r
586 drp_audioBitrate.Items.Remove("320");
\r
587 drp_audioBitrate.Items.Remove("384");
\r
588 drp_audioBitrate.Items.Remove("448");
\r
589 drp_audioBitrate.Items.Remove("640");
\r
590 drp_audioBitrate.Items.Remove("768");
\r
592 switch (drp_audioEncoder.Text)
\r
595 max = drp_audioMix.Text.Contains("6 Channel") ? 768 : 320;
\r
600 case "Vorbis (vorbis)":
\r
603 case "AC3 (ffmpeg)":
\r
607 drp_audioBitrate.Items.Add("Auto");
\r
608 drp_audioBitrate.SelectedItem = "Auto";
\r
609 drp_audioSample.SelectedItem = "Auto";
\r
612 drp_audioBitrate.Items.Add("Auto");
\r
613 drp_audioBitrate.SelectedItem = "Auto";
\r
614 drp_audioSample.SelectedItem = "Auto";
\r
620 drp_audioBitrate.Items.Add("192");
\r
621 drp_audioBitrate.Items.Add("224");
\r
622 drp_audioBitrate.Items.Add("256");
\r
623 drp_audioBitrate.Items.Add("320");
\r
628 drp_audioBitrate.Items.Add("384");
\r
633 drp_audioBitrate.Items.Add("448");
\r
634 drp_audioBitrate.Items.Add("640");
\r
639 drp_audioBitrate.Items.Add("768");
\r
642 if (drp_audioBitrate.SelectedItem == null && audioList.SelectedRows.Count == 0)
\r
643 drp_audioBitrate.SelectedIndex = drp_audioBitrate.Items.Count - 1;
\r
645 if (drp_audioBitrate.SelectedItem == null && audioList.SelectedRows.Count != 0 && (string)this.audioList.SelectedRows[0].Cells[5].Value == "Auto")
\r
647 drp_audioBitrate.SelectedItem = "160";
\r
652 /// Set the mixdown dropdown
\r
654 private void SetMixDown()
\r
656 drp_audioMix.Items.Clear();
\r
657 drp_audioMix.Items.Add("Mono");
\r
658 drp_audioMix.Items.Add("Stereo");
\r
659 drp_audioMix.Items.Add("Dolby Surround");
\r
660 drp_audioMix.Items.Add("Dolby Pro Logic II");
\r
661 drp_audioMix.Items.Add("6 Channel Discrete");
\r
662 drp_audioMix.Items.Add(AC3Passthru);
\r
663 drp_audioMix.Items.Add(DTSPassthru);
\r
665 drp_audioMix.SelectedItem = "Dolby Pro Logic II";
\r
667 switch (drp_audioEncoder.Text)
\r
670 drp_audioMix.Items.Remove(AC3Passthru);
\r
671 drp_audioMix.Items.Remove(DTSPassthru);
\r
674 drp_audioMix.Items.Remove("6 Channel Discrete");
\r
675 drp_audioMix.Items.Remove(AC3Passthru);
\r
676 drp_audioMix.Items.Remove(DTSPassthru);
\r
678 case "Vorbis (vorbis)":
\r
679 drp_audioMix.Items.Remove(AC3Passthru);
\r
680 drp_audioMix.Items.Remove(DTSPassthru);
\r
682 case "AC3 (ffmpeg)":
\r
683 drp_audioMix.Items.Remove(AC3Passthru);
\r
684 drp_audioMix.Items.Remove(DTSPassthru);
\r
686 case "AC3 Passthru":
\r
687 drp_audioMix.SelectedItem = AC3Passthru;
\r
689 case "DTS Passthru":
\r
690 drp_audioMix.SelectedItem = DTSPassthru;
\r