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
13 using AudioTrack = Model.AudioTrack;
\r
15 public partial class AudioPanel : UserControl
\r
18 /// The audio list has changed
\r
20 public event EventHandler AudioListChanged;
\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 /// Get the audio panel
\r
36 /// <returns>A listview containing the audio tracks</returns>
\r
37 public ListView GetAudioPanel()
\r
39 return lv_audioList;
\r
43 /// Set the File Container. This funciton is used to limit the available options for each file container.
\r
45 /// <param name="path"></param>
\r
46 public void SetContainer(string path)
\r
48 string oldval = drp_audioEncoder.Text;
\r
49 if ((path.Contains("MP4")) || (path.Contains("M4V")))
\r
51 drp_audioEncoder.Items.Clear();
\r
52 drp_audioEncoder.Items.Add("AAC (faac)");
\r
53 drp_audioEncoder.Items.Add("AC3 Passthru");
\r
54 if ((oldval != "AAC (faac)") && (oldval != "AC3 Passthru"))
\r
55 drp_audioEncoder.SelectedIndex = 0;
\r
57 drp_audioEncoder.SelectedItem = oldval;
\r
59 else if (path.Contains("MKV"))
\r
61 drp_audioEncoder.Items.Clear();
\r
62 drp_audioEncoder.Items.Add("AAC (faac)");
\r
63 drp_audioEncoder.Items.Add("MP3 (lame)");
\r
64 drp_audioEncoder.Items.Add("AC3 Passthru");
\r
65 drp_audioEncoder.Items.Add("DTS Passthru");
\r
66 drp_audioEncoder.Items.Add("Vorbis (vorbis)");
\r
67 drp_audioEncoder.SelectedItem = oldval;
\r
69 if (drp_audioEncoder.Text == string.Empty)
\r
70 drp_audioEncoder.SelectedIndex = 0;
\r
73 // Make sure the table is updated with new audio codecs
\r
74 foreach (ListViewItem row in lv_audioList.Items)
\r
76 if (!drp_audioEncoder.Items.Contains(row.SubItems[2].Text))
\r
77 row.SubItems[2].Text = drp_audioEncoder.Items[0].ToString();
\r
82 /// Checks if the settings used required the .m4v (rather than .mp4) extension
\r
84 /// <returns></returns>
\r
85 public bool RequiresM4V()
\r
87 return lv_audioList.Items.Cast<ListViewItem>().Any(item => item.SubItems[2].Text.Contains("AC3"));
\r
91 /// Load an arraylist of AudioTrack items into the list.
\r
93 /// <param name="audioTracks"></param>
\r
94 public void LoadTracks(ArrayList audioTracks)
\r
98 if (audioTracks == null)
\r
101 foreach (AudioTrack track in audioTracks)
\r
103 ListViewItem newTrack = new ListViewItem(GetNewID().ToString());
\r
105 newTrack.SubItems.Add("Automatic");
\r
106 newTrack.SubItems.Add(track.Encoder);
\r
107 newTrack.SubItems.Add(track.MixDown);
\r
108 newTrack.SubItems.Add(track.SampleRate);
\r
109 newTrack.SubItems.Add(track.Encoder.Contains("AC3") ? "Auto" : track.Bitrate);
\r
110 newTrack.SubItems.Add(track.DRC);
\r
111 AddTrackForPreset(newTrack);
\r
116 /// Set the Track list dropdown from the parsed title captured during the scan
\r
118 /// <param name="selectedTitle"></param>
\r
119 public void SetTrackList(Title selectedTitle)
\r
121 drp_audioTrack.Items.Clear();
\r
122 drp_audioTrack.Items.Add("Automatic");
\r
123 drp_audioTrack.Items.Add("None");
\r
124 drp_audioTrack.Items.AddRange(selectedTitle.AudioTracks.ToArray());
\r
126 // Handle Native Language and "Dub Foreign language audio" and "Use Foreign language audio and Subtitles" Options
\r
127 if (Properties.Settings.Default.NativeLanguage == "Any")
\r
128 drp_audioTrack.SelectedIndex = drp_audioTrack.Items.Count >= 3 ? 2 : 0;
\r
131 if (Properties.Settings.Default.DubAudio) // "Dub Foreign language audio"
\r
134 foreach (object item in drp_audioTrack.Items)
\r
136 if (item.ToString().Contains(Properties.Settings.Default.NativeLanguage))
\r
138 drp_audioTrack.SelectedIndex = i;
\r
145 if (drp_audioTrack.SelectedItem != null)
\r
146 foreach (ListViewItem item in lv_audioList.Items)
\r
147 item.SubItems[1].Text = drp_audioTrack.SelectedItem.ToString();
\r
150 drp_audioTrack.SelectedIndex = 0;
\r
151 if (drp_audioTrack.SelectedItem != null)
\r
152 foreach (ListViewItem item in lv_audioList.Items)
\r
153 item.SubItems[1].Text = drp_audioTrack.SelectedItem.ToString();
\r
157 drp_audioTrack.SelectedIndex = drp_audioTrack.Items.Count >= 3 ? 2 : 0;
\r
158 // "Use Foreign language audio and Subtitles"
\r
162 // Control and ListView
\r
163 private void controlChanged(object sender, EventArgs e)
\r
165 Control ctl = (Control) sender;
\r
169 case "drp_audioTrack":
\r
170 if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)
\r
171 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[1].Text = drp_audioTrack.Text;
\r
173 case "drp_audioEncoder":
\r
177 // Configure the widgets with values
\r
178 if (drp_audioEncoder.Text.Contains("AC3") || drp_audioEncoder.Text.Contains("DTS"))
\r
180 drp_audioMix.Enabled =
\r
181 drp_audioBitrate.Enabled = drp_audioSample.Enabled = tb_drc.Enabled = false;
\r
182 lbl_bitrate.Enabled =
\r
184 lbl_drcHeader.Enabled = lbl_mixdown.Enabled = lbl_sampleRate.Enabled = false;
\r
188 drp_audioMix.Enabled =
\r
189 drp_audioBitrate.Enabled = drp_audioSample.Enabled = tb_drc.Enabled = true;
\r
190 lbl_bitrate.Enabled =
\r
192 lbl_drcHeader.Enabled = lbl_mixdown.Enabled = lbl_sampleRate.Enabled = true;
\r
195 // Update an item in the Audio list if required.
\r
196 if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)
\r
197 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[2].Text = drp_audioEncoder.Text;
\r
199 case "drp_audioMix":
\r
202 if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)
\r
203 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[3].Text = drp_audioMix.Text;
\r
205 case "drp_audioSample":
\r
206 if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)
\r
207 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[4].Text = drp_audioSample.Text;
\r
209 case "drp_audioBitrate":
\r
210 // Update an item in the Audio list if required.
\r
211 if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)
\r
212 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[5].Text = drp_audioBitrate.Text;
\r
216 if (tb_drc.Value == 0) value = 0;
\r
218 value = ((tb_drc.Value - 1)/10.0) + 1;
\r
220 lbl_drc.Text = value.ToString();
\r
222 // Update an item in the Audio list if required.
\r
223 if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)
\r
225 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[6].Text = value.ToString();
\r
226 lv_audioList.Select();
\r
231 lv_audioList.Select();
\r
234 private void lv_audioList_SelectedIndexChanged(object sender, EventArgs e)
\r
236 // Set the dropdown controls based on the selected item in the Audio List.
\r
237 if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)
\r
239 drp_audioTrack.SelectedItem = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[1].Text;
\r
240 drp_audioEncoder.SelectedItem = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[2].Text;
\r
241 drp_audioMix.SelectedItem = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[3].Text;
\r
242 drp_audioSample.SelectedItem = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[4].Text;
\r
243 drp_audioBitrate.SelectedItem = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[5].Text;
\r
246 double.TryParse(lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[6].Text, out drcValue);
\r
248 drcValue = ((drcValue*10) + 1) - 10;
\r
249 int.TryParse(drcValue.ToString(), out drcCalculated);
\r
250 tb_drc.Value = drcCalculated;
\r
251 lbl_drc.Text = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[6].Text;
\r
253 AudioTrackGroup.Text = "Selected Track: " +
\r
254 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[0].Text;
\r
257 AudioTrackGroup.Text = "Selected Track: None (Click \"Add Track\" to add)";
\r
261 private void btn_addAudioTrack_Click(object sender, EventArgs e)
\r
264 if (tb_drc.Value != 0)
\r
265 value = ((tb_drc.Value - 1)/10.0) + 1;
\r
267 // Create a new row for the Audio list based on the currently selected items in the dropdown.
\r
268 ListViewItem newTrack = new ListViewItem(GetNewID().ToString());
\r
269 newTrack.SubItems.Add(drp_audioTrack.Text);
\r
270 newTrack.SubItems.Add(drp_audioEncoder.Text);
\r
271 newTrack.SubItems.Add(drp_audioMix.Text);
\r
272 newTrack.SubItems.Add(drp_audioSample.Text);
\r
273 newTrack.SubItems.Add(drp_audioBitrate.Text);
\r
274 newTrack.SubItems.Add(value.ToString());
\r
275 lv_audioList.Items.Add(newTrack);
\r
277 // The Audio List has changed to raise the event.
\r
278 if (this.AudioListChanged != null)
\r
279 this.AudioListChanged(this, new EventArgs());
\r
281 // Select the newly added track and select the control
\r
282 lv_audioList.Items[lv_audioList.Items.Count - 1].Selected = true;
\r
283 lv_audioList.Select();
\r
286 private void btn_RemoveAudioTrack_Click(object sender, EventArgs e)
\r
292 private void audioList_moveup_Click(object sender, EventArgs e)
\r
297 private void audioList_movedown_Click(object sender, EventArgs e)
\r
302 private void audioList_remove_Click(object sender, EventArgs e)
\r
307 // Public Functions
\r
308 private void AddTrackForPreset(ListViewItem item)
\r
310 lv_audioList.Items.Add(item);
\r
311 if (this.AudioListChanged != null)
\r
312 this.AudioListChanged(this, new EventArgs());
\r
315 private void ClearAudioList()
\r
317 lv_audioList.Items.Clear();
\r
318 if (this.AudioListChanged != null)
\r
319 this.AudioListChanged(this, new EventArgs());
\r
322 private int GetNewID()
\r
324 return lv_audioList.Items.Count + 1;
\r
327 private void RemoveTrack()
\r
329 // Remove the Item and reselect the control if the following conditions are met.
\r
330 if (lv_audioList.SelectedItems.Count != 0)
\r
332 // The Audio List is about to change so raise the event.
\r
333 if (this.AudioListChanged != null)
\r
334 this.AudioListChanged(this, new EventArgs());
\r
336 // Record the current selected index.
\r
337 int currentPosition = lv_audioList.SelectedIndices[0];
\r
339 lv_audioList.Items.RemoveAt(lv_audioList.SelectedIndices[0]);
\r
341 // Now reslect the correct item and give focus to the audio list.
\r
342 if (lv_audioList.Items.Count != 0)
\r
344 if (currentPosition <= (lv_audioList.Items.Count - 1))
\r
345 lv_audioList.Items[currentPosition].Selected = true;
\r
346 else if (currentPosition > (lv_audioList.Items.Count - 1))
\r
347 lv_audioList.Items[lv_audioList.Items.Count - 1].Selected = true;
\r
349 lv_audioList.Select();
\r
351 // Regenerate the ID numers
\r
352 ReGenerateListIDs();
\r
356 private void MoveTrack(bool up)
\r
358 if (lv_audioList.SelectedIndices.Count == 0) return;
\r
360 ListViewItem item = lv_audioList.SelectedItems[0];
\r
361 int index = item.Index;
\r
366 if (index < lv_audioList.Items.Count || (lv_audioList.Items.Count > index && index >= 0))
\r
368 lv_audioList.Items.Remove(item);
\r
369 lv_audioList.Items.Insert(index, item);
\r
370 item.Selected = true;
\r
371 lv_audioList.Focus();
\r
375 private void ReGenerateListIDs()
\r
378 foreach (ListViewItem item in lv_audioList.Items)
\r
380 item.SubItems[0].Text = i.ToString();
\r
385 private void SetBitrate()
\r
388 drp_audioBitrate.Items.Remove("Auto");
\r
389 drp_audioBitrate.Items.Remove("192");
\r
390 drp_audioBitrate.Items.Remove("224");
\r
391 drp_audioBitrate.Items.Remove("256");
\r
392 drp_audioBitrate.Items.Remove("320");
\r
394 switch (drp_audioEncoder.Text)
\r
397 max = drp_audioMix.Text.Contains("6 Channel") ? 384 : 160;
\r
402 case "Vorbis (vorbis)":
\r
405 case "AC3 Passthru":
\r
406 drp_audioBitrate.Items.Add("Auto");
\r
407 drp_audioBitrate.SelectedItem = "Auto";
\r
408 drp_audioSample.SelectedItem = "Auto";
\r
410 case "DTS Passthru":
\r
411 drp_audioBitrate.Items.Add("Auto");
\r
412 drp_audioBitrate.SelectedItem = "Auto";
\r
413 drp_audioSample.SelectedItem = "Auto";
\r
419 drp_audioBitrate.Items.Add("192");
\r
420 drp_audioBitrate.Items.Add("224");
\r
421 drp_audioBitrate.Items.Add("256");
\r
422 drp_audioBitrate.Items.Add("320");
\r
424 drp_audioBitrate.Items.Add("384");
\r
426 drp_audioBitrate.Items.Remove("384");
\r
430 drp_audioBitrate.Items.Remove("192");
\r
431 drp_audioBitrate.Items.Remove("224");
\r
432 drp_audioBitrate.Items.Remove("256");
\r
433 drp_audioBitrate.Items.Remove("320");
\r
434 drp_audioBitrate.Items.Remove("384");
\r
437 if (drp_audioBitrate.SelectedItem == null)
\r
438 drp_audioBitrate.SelectedIndex = drp_audioBitrate.Items.Count - 1;
\r
441 private void SetMixDown()
\r
443 drp_audioMix.Items.Clear();
\r
444 drp_audioMix.Items.Add("Mono");
\r
445 drp_audioMix.Items.Add("Stereo");
\r
446 drp_audioMix.Items.Add("Dolby Surround");
\r
447 drp_audioMix.Items.Add("Dolby Pro Logic II");
\r
448 drp_audioMix.Items.Add("6 Channel Discrete");
\r
449 drp_audioMix.Items.Add("AC3 Passthru");
\r
450 drp_audioMix.Items.Add("DTS Passthru");
\r
452 drp_audioMix.SelectedItem = "Dolby Pro Logic II";
\r
454 switch (drp_audioEncoder.Text)
\r
457 drp_audioMix.Items.Remove("AC3 Passthru");
\r
458 drp_audioMix.Items.Remove("DTS Passthru");
\r
461 drp_audioMix.Items.Remove("Mono");
\r
462 drp_audioMix.Items.Remove("6 Channel Discrete");
\r
463 drp_audioMix.Items.Remove("AC3 Passthru");
\r
464 drp_audioMix.Items.Remove("DTS Passthru");
\r
466 case "Vorbis (vorbis)":
\r
467 drp_audioMix.Items.Remove("AC3 Passthru");
\r
468 drp_audioMix.Items.Remove("DTS Passthru");
\r
470 case "AC3 Passthru":
\r
471 drp_audioMix.SelectedItem = "AC3 Passthru";
\r
473 case "DTS Passthru":
\r
474 drp_audioMix.SelectedItem = "DTS Passthru";
\r