3 This file is part of the HandBrake source code.
\r
4 Homepage: <http://handbrake.fr>.
\r
5 It may be used under the terms of the GNU General Public License. */
\r
8 using System.Windows.Forms;
\r
10 namespace Handbrake.Controls
\r
12 public partial class AudioPanel : UserControl
\r
14 public event EventHandler AudioListChanged;
\r
18 InitializeComponent();
\r
19 drp_audioMix.SelectedIndex = 0;
\r
22 // Audio Track Options
\r
23 private void drp_audioTrack_SelectedIndexChanged(object sender, EventArgs e)
\r
25 if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)
\r
27 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[1].Text = drp_audioTrack.Text;
\r
28 lv_audioList.Select();
\r
31 private void drp_audenc_SelectedIndexChanged(object sender, EventArgs e)
\r
33 // Setup the widgets with the correct avail options
\r
34 if (drp_audioEncoder.Text.Contains("AAC"))
\r
45 // Configure the widgets with values
\r
46 if (drp_audioEncoder.Text.Contains("AC3") || drp_audioEncoder.Text.Contains("DTS"))
\r
48 drp_audioMix.Enabled = false;
\r
49 drp_audioBitrate.Enabled = false;
\r
50 drp_audioSample.Enabled = false;
\r
52 drp_audioMix.SelectedIndex = 0;
\r
53 drp_audioBitrate.SelectedIndex = 0;
\r
54 drp_audioSample.SelectedIndex = 0;
\r
58 drp_audioMix.Enabled = true;
\r
59 drp_audioBitrate.Enabled = true;
\r
60 drp_audioSample.Enabled = true;
\r
62 drp_audioMix.SelectedIndex = 0;
\r
63 drp_audioBitrate.SelectedIndex = 9;
\r
64 drp_audioSample.SelectedIndex = 0;
\r
67 // Update an item in the Audio list if required.
\r
68 if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)
\r
70 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[2].Text = drp_audioEncoder.Text;
\r
71 lv_audioList.Select();
\r
74 private void drp_audmix_SelectedIndexChanged(object sender, EventArgs e)
\r
76 if ((drp_audioEncoder.Text.Contains("AAC")) && (drp_audioMix.Text == "6 Channel Discrete"))
\r
78 else if ((drp_audioEncoder.Text.Contains("AAC")) && (drp_audioMix.Text != "6 Channel Discrete"))
\r
81 // Update an item in the Audio list if required.
\r
82 if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)
\r
84 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[3].Text = drp_audioMix.Text;
\r
85 lv_audioList.Select();
\r
88 private void drp_audsr_SelectedIndexChanged(object sender, EventArgs e)
\r
90 // Update an item in the Audio list if required.
\r
91 if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)
\r
93 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[4].Text = drp_audioSample.Text;
\r
94 lv_audioList.Select();
\r
97 private void drp_audbit_SelectedIndexChanged(object sender, EventArgs e)
\r
99 // Update an item in the Audio list if required.
\r
100 if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)
\r
102 if (drp_audioEncoder.Text.Contains("AC3"))
\r
103 drp_audioBitrate.SelectedItem = "Auto";
\r
104 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[5].Text = drp_audioBitrate.Text;
\r
105 lv_audioList.Select();
\r
108 private void tb_drc_Scroll(object sender, EventArgs e)
\r
111 if (tb_drc.Value == 0) value = 0;
\r
113 value = ((tb_drc.Value - 1) / 10.0) + 1;
\r
115 lbl_drc.Text = value.ToString();
\r
117 // Update an item in the Audio list if required.
\r
118 if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)
\r
120 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[6].Text = value.ToString();
\r
121 lv_audioList.Select();
\r
126 private void btn_addAudioTrack_Click(object sender, EventArgs e)
\r
129 if (tb_drc.Value != 0)
\r
130 value = ((tb_drc.Value - 1) / 10.0) + 1;
\r
132 // Create a new row for the Audio list based on the currently selected items in the dropdown.
\r
133 ListViewItem newTrack = new ListViewItem(getNewID().ToString());
\r
134 newTrack.SubItems.Add(drp_audioTrack.Text);
\r
135 newTrack.SubItems.Add(drp_audioEncoder.Text);
\r
136 newTrack.SubItems.Add(drp_audioMix.Text);
\r
137 newTrack.SubItems.Add(drp_audioSample.Text);
\r
138 newTrack.SubItems.Add(drp_audioBitrate.Text);
\r
139 newTrack.SubItems.Add(value.ToString());
\r
140 lv_audioList.Items.Add(newTrack);
\r
142 // The Audio List has changed to raise the event.
\r
143 if (this.AudioListChanged != null)
\r
144 this.AudioListChanged(this, new EventArgs());
\r
146 // Select the newly added track and select the control
\r
147 lv_audioList.Items[lv_audioList.Items.Count - 1].Selected = true;
\r
148 lv_audioList.Select();
\r
150 private void btn_RemoveAudioTrack_Click(object sender, EventArgs e)
\r
152 removeAudioTrack();
\r
156 private void audioList_moveup_Click(object sender, EventArgs e)
\r
158 if (lv_audioList.SelectedIndices.Count != 0)
\r
160 ListViewItem item = lv_audioList.SelectedItems[0];
\r
161 int index = item.Index;
\r
164 if (lv_audioList.Items.Count > index && index >= 0)
\r
166 lv_audioList.Items.Remove(item);
\r
167 lv_audioList.Items.Insert(index, item);
\r
168 item.Selected = true;
\r
169 lv_audioList.Focus();
\r
173 private void audioList_movedown_Click(object sender, EventArgs e)
\r
175 if (lv_audioList.SelectedIndices.Count != 0)
\r
177 ListViewItem item = lv_audioList.SelectedItems[0];
\r
178 int index = item.Index;
\r
181 if (index < lv_audioList.Items.Count)
\r
183 lv_audioList.Items.Remove(item);
\r
184 lv_audioList.Items.Insert(index, item);
\r
185 item.Selected = true;
\r
186 lv_audioList.Focus();
\r
190 private void audioList_remove_Click(object sender, EventArgs e)
\r
192 removeAudioTrack();
\r
194 private void removeAudioTrack()
\r
196 // Remove the Item and reselect the control if the following conditions are met.
\r
197 if (lv_audioList.SelectedItems.Count != 0)
\r
199 // The Audio List is about to change so raise the event.
\r
200 if (this.AudioListChanged != null)
\r
201 this.AudioListChanged(this, new EventArgs());
\r
203 // Record the current selected index.
\r
204 int currentPosition = lv_audioList.SelectedIndices[0];
\r
206 lv_audioList.Items.RemoveAt(lv_audioList.SelectedIndices[0]);
\r
208 // Now reslect the correct item and give focus to the audio list.
\r
209 if (lv_audioList.Items.Count != 0)
\r
211 if (currentPosition <= (lv_audioList.Items.Count - 1))
\r
212 lv_audioList.Items[currentPosition].Selected = true;
\r
213 else if (currentPosition > (lv_audioList.Items.Count - 1))
\r
214 lv_audioList.Items[lv_audioList.Items.Count - 1].Selected = true;
\r
216 lv_audioList.Select();
\r
218 // Regenerate the ID numers
\r
219 reGenerateListIDs();
\r
223 // Public Functions
\r
224 public void setTrackList(Parsing.Title selectedTitle)
\r
226 drp_audioTrack.Items.Clear();
\r
227 drp_audioTrack.Items.Add("Automatic");
\r
228 drp_audioTrack.Items.Add("None");
\r
229 drp_audioTrack.Items.AddRange(selectedTitle.AudioTracks.ToArray());
\r
231 // Handle Native Language and "Dub Foreign language audio" and "Use Foreign language audio and Subtitles" Options
\r
232 if (Properties.Settings.Default.NativeLanguage == "Any")
\r
233 drp_audioTrack.SelectedIndex = 0;
\r
236 if (Properties.Settings.Default.DubAudio) // "Dub Foreign language audio"
\r
239 foreach (object item in drp_audioTrack.Items)
\r
241 if (item.ToString().Contains(Properties.Settings.Default.NativeLanguage))
\r
243 drp_audioTrack.SelectedIndex = i;
\r
250 if (drp_audioTrack.SelectedItem != null)
\r
251 foreach (ListViewItem item in lv_audioList.Items)
\r
252 item.SubItems[1].Text = drp_audioTrack.SelectedItem.ToString();
\r
255 drp_audioTrack.SelectedIndex = 0;
\r
256 if (drp_audioTrack.SelectedItem != null)
\r
257 foreach (ListViewItem item in lv_audioList.Items)
\r
258 item.SubItems[1].Text = drp_audioTrack.SelectedItem.ToString();
\r
262 drp_audioTrack.SelectedIndex = 0; // "Use Foreign language audio and Subtitles"
\r
264 drp_audioMix.SelectedIndex = 0;
\r
266 public ListView getAudioPanel()
\r
268 return lv_audioList;
\r
270 public void setAudioByContainer(String path)
\r
272 if ((path.Contains("MP4")) || (path.Contains("M4V")))
\r
274 string oldval = drp_audioEncoder.Text;
\r
275 drp_audioEncoder.Items.Clear();
\r
276 drp_audioEncoder.Items.Add("AAC (faac)");
\r
277 drp_audioEncoder.Items.Add("AC3 Passthru");
\r
278 if ((oldval != "AAC (faac)") && (oldval != "AC3 Passthru"))
\r
279 drp_audioEncoder.SelectedIndex = 0;
\r
282 else if (path.Contains("MKV"))
\r
284 drp_audioEncoder.Items.Clear();
\r
285 drp_audioEncoder.Items.Add("AAC (faac)");
\r
286 drp_audioEncoder.Items.Add("MP3 (lame)");
\r
287 drp_audioEncoder.Items.Add("AC3 Passthru");
\r
288 drp_audioEncoder.Items.Add("DTS Passthru");
\r
289 drp_audioEncoder.Items.Add("Vorbis (vorbis)");
\r
291 if (drp_audioEncoder.Text == string.Empty)
\r
292 drp_audioEncoder.SelectedIndex = 0;
\r
295 // Make sure the table is updated with new audio codecs
\r
296 foreach (ListViewItem row in lv_audioList.Items)
\r
298 if (!drp_audioEncoder.Items.Contains(row.SubItems[2].Text))
\r
299 row.SubItems[2].Text = drp_audioEncoder.Items[0].ToString();
\r
302 public void addTrackForPreset(ListViewItem item)
\r
304 lv_audioList.Items.Add(item);
\r
305 if (this.AudioListChanged != null)
\r
306 this.AudioListChanged(this, new EventArgs());
\r
308 public void clearAudioList()
\r
310 lv_audioList.Items.Clear();
\r
311 if (this.AudioListChanged != null)
\r
312 this.AudioListChanged(this, new EventArgs());
\r
314 public int getNewID()
\r
316 return lv_audioList.Items.Count + 1;
\r
319 // Helper Functions
\r
320 private void reGenerateListIDs()
\r
323 foreach (ListViewItem item in lv_audioList.Items)
\r
325 item.SubItems[0].Text = i.ToString();
\r
329 private void setBitrate(int max)
\r
333 drp_audioBitrate.Items.Add("192");
\r
334 drp_audioBitrate.Items.Add("224");
\r
335 drp_audioBitrate.Items.Add("256");
\r
336 drp_audioBitrate.Items.Add("320");
\r
338 drp_audioBitrate.Items.Add("384");
\r
340 drp_audioBitrate.Items.Remove("384");
\r
344 drp_audioBitrate.Items.Remove("192");
\r
345 drp_audioBitrate.Items.Remove("224");
\r
346 drp_audioBitrate.Items.Remove("256");
\r
347 drp_audioBitrate.Items.Remove("320");
\r
348 drp_audioBitrate.Items.Remove("384");
\r
350 if (drp_audioBitrate.SelectedItem == null)
\r
351 drp_audioBitrate.SelectedIndex = drp_audioBitrate.Items.Count - 1;
\r
353 private void setMixDown(Boolean aac)
\r
355 drp_audioMix.Items.Clear();
\r
356 drp_audioMix.Items.Add("Automatic");
\r
358 drp_audioMix.Items.Add("Mono");
\r
359 drp_audioMix.Items.Add("Stereo");
\r
360 drp_audioMix.Items.Add("Dolby Surround");
\r
361 drp_audioMix.Items.Add("Dolby Pro Logic II");
\r
363 drp_audioMix.Items.Add("6 Channel Discrete");
\r
365 private void lv_audioList_SelectedIndexChanged(object sender, EventArgs e)
\r
367 // Set the dropdown controls based on the selected item in the Audio List.
\r
368 if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)
\r
370 drp_audioTrack.SelectedItem = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[1].Text;
\r
371 drp_audioEncoder.SelectedItem = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[2].Text;
\r
372 drp_audioMix.SelectedItem = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[3].Text;
\r
373 drp_audioSample.SelectedItem = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[4].Text;
\r
374 drp_audioBitrate.SelectedItem = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[5].Text;
\r
375 double drcValue; int drcCalculated;
\r
376 double.TryParse(lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[6].Text, out drcValue);
\r
377 if (drcValue == 0) drcCalculated = 0;
\r
379 drcValue = ((drcValue * 10) + 1) - 10;
\r
380 int.TryParse(drcValue.ToString(), out drcCalculated);
\r
381 tb_drc.Value = drcCalculated;
\r
382 lbl_drc.Text = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[6].Text;
\r
384 AudioTrackGroup.Text = "Selected Track: " + lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[0].Text;
\r
387 AudioTrackGroup.Text = "Selected Track: None (Click \"Add Track\" to add)";
\r