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") ? "Auto" : track.Bitrate;
\r
121 newTrack.Cells[6].Value = track.DRC;
\r
122 AddTrackForPreset(newTrack);
\r
127 /// Set the Track list dropdown from the parsed title captured during the scan
\r
129 /// <param name="selectedTitle">The selected title</param>
\r
130 /// <param name="preset">A preset</param>
\r
131 public void SetTrackList(Title selectedTitle, Preset preset)
\r
133 if (selectedTitle.AudioTracks.Count == 0)
\r
135 audioList.Rows.Clear();
\r
136 drp_audioTrack.Items.Clear();
\r
137 drp_audioTrack.Items.Add("None Found");
\r
138 drp_audioTrack.SelectedIndex = 0;
\r
142 // The Source Information for the title will have changed, so set all the tracks to Automatic.
\r
143 foreach (DataGridViewRow row in this.audioList.Rows)
\r
145 row.Cells[1].Value = "Automatic";
\r
148 // Setup the Audio track source dropdown with the new audio tracks.
\r
149 drp_audioTrack.Items.Clear();
\r
150 drp_audioTrack.Items.Add("Automatic");
\r
151 drp_audioTrack.Items.AddRange(selectedTitle.AudioTracks.ToArray());
\r
153 // Re-add any audio tracks that the preset has.
\r
154 if (audioList.Rows.Count == 0 && preset != null)
\r
156 QueryParser parsed = QueryParser.Parse(preset.Query);
\r
157 foreach (AudioTrack audioTrack in parsed.AudioInformation)
\r
159 DataGridViewRow newTrack = new DataGridViewRow();
\r
160 newTrack.CreateCells(audioList);
\r
161 newTrack.Cells[0].Value = GetNewID().ToString();
\r
162 newTrack.Cells[1].Value = (audioTrack.Track);
\r
163 newTrack.Cells[2].Value = (audioTrack.Encoder);
\r
164 newTrack.Cells[3].Value = (audioTrack.MixDown);
\r
165 newTrack.Cells[4].Value = (audioTrack.SampleRate);
\r
166 newTrack.Cells[5].Value = (audioTrack.Bitrate);
\r
167 newTrack.Cells[6].Value = (audioTrack.DRC);
\r
168 audioList.Rows.Add(newTrack);
\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
174 drp_audioTrack.SelectedIndex = drp_audioTrack.Items.Count >= 2 ? 1 : 0;
\r
177 if (Properties.Settings.Default.DubMode > 1) // "Dub Foreign language audio"
\r
180 foreach (object item in drp_audioTrack.Items)
\r
182 if (item.ToString().Contains(Properties.Settings.Default.NativeLanguage))
\r
184 drp_audioTrack.SelectedIndex = i;
\r
191 if (drp_audioTrack.SelectedItem != null)
\r
192 foreach (DataGridViewRow item in audioList.Rows)
\r
193 item.Cells[1].Value = drp_audioTrack.SelectedItem.ToString();
\r
196 drp_audioTrack.SelectedIndex = 0;
\r
197 if (drp_audioTrack.SelectedItem != null)
\r
198 foreach (DataGridViewRow item in audioList.Rows)
\r
199 item.Cells[1].Value = drp_audioTrack.SelectedItem.ToString();
\r
203 drp_audioTrack.SelectedIndex = drp_audioTrack.Items.Count >= 3 ? 2 : 0;
\r
204 // "Use Foreign language audio and Subtitles"
\r
208 // Control and ListView
\r
211 /// one of the controls has changed. Event handler
\r
213 /// <param name="sender">
\r
216 /// <param name="e">
\r
219 private void controlChanged(object sender, EventArgs e)
\r
221 Control ctl = (Control)sender;
\r
225 case "drp_audioTrack":
\r
226 if (audioList.Rows.Count != 0 && audioList.SelectedRows.Count != 0)
\r
228 audioList.SelectedRows[0].Cells[1].Value = drp_audioTrack.Text;
\r
230 // If the track isn't AC3, and the encoder is, change it.
\r
231 if (audioList.SelectedRows[0].Cells[2].Value.ToString().Contains("AC3") && !audioList.SelectedRows[0].Cells[1].Value.ToString().Contains("AC3"))
\r
234 drp_audioEncoder.SelectedIndex = 0;
\r
237 // If the track isn't DTS, and the encoder is, change it.
\r
238 if (audioList.SelectedRows[0].Cells[2].Value.ToString().Contains("DTS") && !audioList.SelectedRows[0].Cells[1].Value.ToString().Contains("DTS"))
\r
241 drp_audioEncoder.SelectedIndex = 0;
\r
245 case "drp_audioEncoder":
\r
249 // Configure the widgets with values
\r
250 if (drp_audioEncoder.Text.Contains("AC3") || drp_audioEncoder.Text.Contains("DTS"))
\r
252 drp_audioMix.Enabled =
\r
253 drp_audioBitrate.Enabled = drp_audioSample.Enabled = tb_drc.Enabled = false;
\r
254 lbl_bitrate.Enabled =
\r
256 lbl_drcHeader.Enabled = lbl_mixdown.Enabled = lbl_sampleRate.Enabled = false;
\r
260 drp_audioMix.Enabled =
\r
261 drp_audioBitrate.Enabled = drp_audioSample.Enabled = tb_drc.Enabled = true;
\r
262 lbl_bitrate.Enabled =
\r
264 lbl_drcHeader.Enabled = lbl_mixdown.Enabled = lbl_sampleRate.Enabled = true;
\r
267 // Update an item in the Audio list if required.
\r
268 if (audioList.Rows.Count != 0 && audioList.SelectedRows.Count != 0)
\r
269 audioList.SelectedRows[0].Cells[2].Value = drp_audioEncoder.Text;
\r
271 case "drp_audioMix":
\r
274 if (audioList.Rows.Count != 0 && audioList.SelectedRows.Count != 0)
\r
275 audioList.SelectedRows[0].Cells[3].Value = drp_audioMix.Text;
\r
277 case "drp_audioSample":
\r
278 if (audioList.Rows.Count != 0 && audioList.SelectedRows.Count != 0)
\r
279 audioList.SelectedRows[0].Cells[4].Value = drp_audioSample.Text;
\r
281 case "drp_audioBitrate":
\r
282 // Update an item in the Audio list if required.
\r
283 if (audioList.Rows.Count != 0 && audioList.SelectedRows.Count != 0)
\r
284 audioList.SelectedRows[0].Cells[5].Value = drp_audioBitrate.Text;
\r
288 if (tb_drc.Value == 0) value = 0;
\r
290 value = ((tb_drc.Value - 1) / 10.0) + 1;
\r
292 lbl_drc.Text = value.ToString();
\r
294 // Update an item in the Audio list if required.
\r
295 if (audioList.Rows.Count != 0 && audioList.SelectedRows.Count != 0)
\r
297 audioList.SelectedRows[0].Cells[6].Value = value.ToString();
\r
298 audioList.Select();
\r
303 audioList.Select();
\r
307 /// The Audio List selected index changed event handler
\r
309 /// <param name="sender">
\r
312 /// <param name="e">
\r
315 private void audioList_SelectionChanged(object sender, EventArgs e)
\r
317 // Set the dropdown controls based on the selected item in the Audio List.
\r
318 if (audioList.Rows.Count != 0 && audioList.SelectedRows.Count != 0)
\r
320 drp_audioTrack.SelectedItem = audioList.SelectedRows[0].Cells[1].Value;
\r
321 drp_audioEncoder.SelectedItem = audioList.SelectedRows[0].Cells[2].Value;
\r
322 drp_audioMix.SelectedItem = audioList.SelectedRows[0].Cells[3].Value;
\r
323 drp_audioSample.SelectedItem = audioList.SelectedRows[0].Cells[4].Value;
\r
324 drp_audioBitrate.SelectedItem = audioList.SelectedRows[0].Cells[5].Value;
\r
327 double.TryParse(audioList.SelectedRows[0].Cells[6].Value.ToString(), out drcValue);
\r
329 drcValue = ((drcValue * 10) + 1) - 10;
\r
330 int.TryParse(drcValue.ToString(), out drcCalculated);
\r
331 tb_drc.Value = drcCalculated;
\r
332 lbl_drc.Text = audioList.SelectedRows[0].Cells[6].Value.ToString();
\r
334 AudioTrackGroup.Text = "Selected Track: " + audioList.SelectedRows[0].Cells[0].Value;
\r
337 AudioTrackGroup.Text = "Selected Track: None (Click \"Add Track\" to add)";
\r
343 /// The Add Audio Track button event handler
\r
345 /// <param name="sender">
\r
348 /// <param name="e">
\r
351 private void btn_addAudioTrack_Click(object sender, EventArgs e)
\r
353 if (drp_audioTrack.Text == "None Found")
\r
356 "Your source appears to have no audio tracks that HandBrake supports.",
\r
358 MessageBoxButtons.OK,
\r
359 MessageBoxIcon.Warning);
\r
364 if (tb_drc.Value != 0)
\r
365 value = ((tb_drc.Value - 1) / 10.0) + 1;
\r
367 // Create a new row for the Audio list based on the currently selected items in the dropdown.
\r
368 DataGridViewRow newTrack = new DataGridViewRow();
\r
369 newTrack.CreateCells(audioList);
\r
370 newTrack.Cells[0].Value = GetNewID().ToString();
\r
371 newTrack.Cells[1].Value = drp_audioTrack.Text;
\r
372 newTrack.Cells[2].Value = drp_audioEncoder.Text;
\r
373 newTrack.Cells[3].Value = drp_audioMix.Text;
\r
374 newTrack.Cells[4].Value = drp_audioSample.Text;
\r
375 newTrack.Cells[5].Value = drp_audioBitrate.Text;
\r
376 newTrack.Cells[6].Value = value.ToString();
\r
377 audioList.Rows.Add(newTrack);
\r
379 // The Audio List has changed to raise the event.
\r
380 if (this.AudioListChanged != null)
\r
381 this.AudioListChanged(this, new EventArgs());
\r
383 // Select the newly added track and select the control
\r
384 audioList.ClearSelection();
\r
385 audioList.Rows[audioList.Rows.Count - 1].Selected = true;
\r
386 audioList.Select();
\r
390 /// The Remove Track button event handler
\r
392 /// <param name="sender">
\r
395 /// <param name="e">
\r
398 private void btn_RemoveAudioTrack_Click(object sender, EventArgs e)
\r
406 /// The Audio List Move Up menu item
\r
408 /// <param name="sender">
\r
411 /// <param name="e">
\r
414 private void audioList_moveup_Click(object sender, EventArgs e)
\r
420 /// The audio list move down menu item
\r
422 /// <param name="sender">
\r
425 /// <param name="e">
\r
428 private void audioList_movedown_Click(object sender, EventArgs e)
\r
434 /// The audio list remove menu item
\r
436 /// <param name="sender">
\r
439 /// <param name="e">
\r
442 private void audioList_remove_Click(object sender, EventArgs e)
\r
447 // Private Functions
\r
450 /// Add track for preset
\r
452 /// <param name="item">
\r
455 private void AddTrackForPreset(DataGridViewRow item)
\r
457 audioList.Rows.Add(item);
\r
458 if (this.AudioListChanged != null)
\r
459 this.AudioListChanged(this, new EventArgs());
\r
463 /// Clear the audio list
\r
465 private void ClearAudioList()
\r
467 audioList.Rows.Clear();
\r
468 if (this.AudioListChanged != null)
\r
469 this.AudioListChanged(this, new EventArgs());
\r
473 /// Get a new ID for the next audio track
\r
478 private int GetNewID()
\r
480 return audioList.Rows.Count + 1;
\r
484 /// Remove an audio track from the list
\r
486 private void RemoveTrack()
\r
488 // Remove the Item and reselect the control if the following conditions are met.
\r
489 if (audioList.SelectedRows.Count != 0)
\r
491 // The Audio List is about to change so raise the event.
\r
492 if (this.AudioListChanged != null)
\r
493 this.AudioListChanged(this, new EventArgs());
\r
495 // Record the current selected index.
\r
496 int currentPosition = audioList.SelectedRows[0].Index;
\r
498 audioList.Rows.Remove(audioList.SelectedRows[0]);
\r
500 // Now reslect the correct item and give focus to the audio list.
\r
501 if (audioList.Rows.Count != 0)
\r
503 audioList.ClearSelection();
\r
504 if (currentPosition <= (audioList.Rows.Count - 1))
\r
505 audioList.Rows[currentPosition].Selected = true;
\r
506 else if (currentPosition > (audioList.Rows.Count - 1))
\r
507 audioList.Rows[audioList.Rows.Count - 1].Selected = true;
\r
509 audioList.Select();
\r
511 // Regenerate the ID numers
\r
512 ReGenerateListIDs();
\r
517 /// Move an audio track up or down the audio list
\r
519 /// <param name="up">
\r
522 private void MoveTrack(bool up)
\r
524 if (audioList.SelectedRows.Count == 0) return;
\r
526 DataGridViewRow item = audioList.SelectedRows[0];
\r
527 int index = item.Index;
\r
532 if (index < audioList.Rows.Count || (audioList.Rows.Count > index && index >= 0))
\r
534 audioList.Rows.Remove(item);
\r
535 audioList.Rows.Insert(index, item);
\r
536 audioList.ClearSelection();
\r
537 item.Selected = true;
\r
542 /// Regenerate all the audio track id's on the audio list
\r
544 private void ReGenerateListIDs()
\r
547 foreach (DataGridViewRow item in audioList.Rows)
\r
549 item.Cells[0].Value = i.ToString();
\r
555 /// Set the bitrate dropdown
\r
557 private void SetBitrate()
\r
560 drp_audioBitrate.Items.Remove("Auto");
\r
561 drp_audioBitrate.Items.Remove("192");
\r
562 drp_audioBitrate.Items.Remove("224");
\r
563 drp_audioBitrate.Items.Remove("256");
\r
564 drp_audioBitrate.Items.Remove("320");
\r
565 drp_audioBitrate.Items.Remove("384");
\r
566 drp_audioBitrate.Items.Remove("448");
\r
567 drp_audioBitrate.Items.Remove("768");
\r
569 switch (drp_audioEncoder.Text)
\r
572 max = drp_audioMix.Text.Contains("6 Channel") ? 768 : 320;
\r
577 case "Vorbis (vorbis)":
\r
580 case "AC3 Passthru":
\r
581 drp_audioBitrate.Items.Add("Auto");
\r
582 drp_audioBitrate.SelectedItem = "Auto";
\r
583 drp_audioSample.SelectedItem = "Auto";
\r
585 case "DTS Passthru":
\r
586 drp_audioBitrate.Items.Add("Auto");
\r
587 drp_audioBitrate.SelectedItem = "Auto";
\r
588 drp_audioSample.SelectedItem = "Auto";
\r
594 drp_audioBitrate.Items.Add("192");
\r
595 drp_audioBitrate.Items.Add("224");
\r
596 drp_audioBitrate.Items.Add("256");
\r
597 drp_audioBitrate.Items.Add("320");
\r
602 drp_audioBitrate.Items.Add("384");
\r
607 drp_audioBitrate.Items.Add("448");
\r
608 drp_audioBitrate.Items.Add("768");
\r
611 if (drp_audioBitrate.SelectedItem == null)
\r
612 drp_audioBitrate.SelectedIndex = drp_audioBitrate.Items.Count - 1;
\r
616 /// Set the mixdown dropdown
\r
618 private void SetMixDown()
\r
620 drp_audioMix.Items.Clear();
\r
621 drp_audioMix.Items.Add("Mono");
\r
622 drp_audioMix.Items.Add("Stereo");
\r
623 drp_audioMix.Items.Add("Dolby Surround");
\r
624 drp_audioMix.Items.Add("Dolby Pro Logic II");
\r
625 drp_audioMix.Items.Add("6 Channel Discrete");
\r
626 drp_audioMix.Items.Add("AC3 Passthru");
\r
627 drp_audioMix.Items.Add("DTS Passthru");
\r
629 drp_audioMix.SelectedItem = "Dolby Pro Logic II";
\r
631 switch (drp_audioEncoder.Text)
\r
634 drp_audioMix.Items.Remove("AC3 Passthru");
\r
635 drp_audioMix.Items.Remove("DTS Passthru");
\r
638 drp_audioMix.Items.Remove("6 Channel Discrete");
\r
639 drp_audioMix.Items.Remove("AC3 Passthru");
\r
640 drp_audioMix.Items.Remove("DTS Passthru");
\r
642 case "Vorbis (vorbis)":
\r
643 drp_audioMix.Items.Remove("AC3 Passthru");
\r
644 drp_audioMix.Items.Remove("DTS Passthru");
\r
646 case "AC3 Passthru":
\r
647 drp_audioMix.SelectedItem = "AC3 Passthru";
\r
649 case "DTS Passthru":
\r
650 drp_audioMix.SelectedItem = "DTS Passthru";
\r