/* Advanced Audio.cs This file is part of the HandBrake source code. Homepage: . It may be used under the terms of the GNU General Public License. */ namespace Handbrake.ToolWindows { using System; using System.Globalization; using System.Windows.Forms; using HandBrake.ApplicationServices.Model.Encoding; /// /// Advanced Audio Panel /// public partial class AdvancedAudio : Form { // Culture Info private static readonly CultureInfo Culture = new CultureInfo("en-US", false); /// /// Initializes a new instance of the class. /// public AdvancedAudio() { InitializeComponent(); } private AudioTrack track; /// /// Gets or sets the Audio Track to alter. /// public AudioTrack Track { get { return this.track; } set { this.track = value; if (this.track == null) { return; } // Set the Gain Control. if (track.Gain == 0) { gainTrackBar.Value = 21; // The centre point } else if (track.Gain > 0) { gainTrackBar.Value = 21 + track.Gain; } else if (track.Gain < 0) { gainTrackBar.Value = 20 - Math.Abs(track.Gain); } lbl_GainValue.Text = string.Format("{0} dB", track.Gain); // Set the DRC Control double drcValue = 0; int drcCalculated; if (track.DRC != 0) drcValue = ((track.DRC * 10) + 1) - 10; int.TryParse(drcValue.ToString(Culture), out drcCalculated); tb_drc.Value = drcCalculated; lbl_drc.Text = track.DRC.ToString(Culture); tb_drc.Enabled = track.TrackDisplay.Contains("(AC3)"); } } /// /// Close the window /// /// The Sender /// The Event Args private void btn_close_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.OK; this.Close(); } /// /// Set the Gain value for the audio track. /// /// The Sender /// The Event Arg private void gainTrackBar_Scroll(object sender, EventArgs e) { // Figure out the Gain. int gain = 0; if (gainTrackBar.Value == 21) { gain = 0; } else if (gainTrackBar.Value > 21) { gain = gainTrackBar.Value - 21; } else if (gainTrackBar.Value < 21) { gain = (-20 + gainTrackBar.Value); } lbl_GainValue.Text = string.Format("{0} dB", gain); // Figure out the DRC Value double drcValue = 0; int drcCalculated; if (track.DRC != 0) drcValue = ((track.DRC * 10) + 1) - 10; int.TryParse(drcValue.ToString(Culture), out drcCalculated); tb_drc.Value = drcCalculated; // Set the model. if (this.track == null) { return; } this.Track.Gain = gain; } /// /// The Dynamic Range Controller /// /// The Sender /// The Event Args private void tb_drc_Scroll(object sender, EventArgs e) { double value; if (tb_drc.Value == 0) value = 0; else value = ((tb_drc.Value - 1) / 10.0) + 1; lbl_drc.Text = value.ToString(Culture); track.DRC = value; } } }