2013-04-01 23:03:22 -04:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Xml.Serialization;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
|
|
namespace CUETools.Codecs
|
|
|
|
|
|
{
|
|
|
|
|
|
public class AudioEncoderSettings
|
|
|
|
|
|
{
|
|
|
|
|
|
public AudioEncoderSettings()
|
2013-04-07 20:41:58 -04:00
|
|
|
|
: this("", "")
|
2013-04-01 23:03:22 -04:00
|
|
|
|
{
|
2013-04-07 20:41:58 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public AudioEncoderSettings(AudioPCMConfig pcm)
|
|
|
|
|
|
: this("", "")
|
|
|
|
|
|
{
|
|
|
|
|
|
this.PCM = pcm;
|
2013-04-01 23:03:22 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2013-04-04 22:07:15 -04:00
|
|
|
|
public AudioEncoderSettings(string supported_modes, string default_mode)
|
2013-04-01 23:03:22 -04:00
|
|
|
|
{
|
|
|
|
|
|
// Iterate through each property and call ResetValue()
|
|
|
|
|
|
foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(this))
|
|
|
|
|
|
property.ResetValue(this);
|
2013-06-24 20:34:55 -04:00
|
|
|
|
this.m_supported_modes = supported_modes;
|
|
|
|
|
|
this.m_default_mode = default_mode;
|
2013-06-02 18:22:07 -04:00
|
|
|
|
if (default_mode == "")
|
|
|
|
|
|
GetSupportedModes(out default_mode);
|
2013-06-24 20:34:55 -04:00
|
|
|
|
this.EncoderMode = default_mode;
|
2013-04-01 23:03:22 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2013-04-08 23:11:03 -04:00
|
|
|
|
protected string m_supported_modes;
|
|
|
|
|
|
protected string m_default_mode;
|
2013-04-01 23:03:22 -04:00
|
|
|
|
|
2013-04-08 23:11:03 -04:00
|
|
|
|
public virtual string GetSupportedModes(out string defaultMode)
|
2013-04-01 23:03:22 -04:00
|
|
|
|
{
|
2013-04-08 23:11:03 -04:00
|
|
|
|
defaultMode = m_default_mode;
|
2013-04-04 22:07:15 -04:00
|
|
|
|
return this.m_supported_modes;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-04-07 20:41:58 -04:00
|
|
|
|
public AudioEncoderSettings Clone()
|
|
|
|
|
|
{
|
|
|
|
|
|
return this.MemberwiseClone() as AudioEncoderSettings;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-04-08 22:26:42 -04:00
|
|
|
|
public bool HasBrowsableAttributes()
|
|
|
|
|
|
{
|
|
|
|
|
|
bool hasBrowsable = false;
|
|
|
|
|
|
foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(this))
|
|
|
|
|
|
{
|
|
|
|
|
|
bool isBrowsable = true;
|
|
|
|
|
|
foreach (var attribute in property.Attributes)
|
|
|
|
|
|
{
|
|
|
|
|
|
var browsable = attribute as BrowsableAttribute;
|
|
|
|
|
|
isBrowsable &= browsable == null || browsable.Browsable;
|
|
|
|
|
|
}
|
|
|
|
|
|
hasBrowsable |= isBrowsable;
|
|
|
|
|
|
}
|
|
|
|
|
|
return hasBrowsable;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-06-19 03:40:43 -04:00
|
|
|
|
protected void SetDefaultValuesForMode()
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(this))
|
|
|
|
|
|
if (!property.CanResetValue(this))
|
|
|
|
|
|
foreach (var attribute in property.Attributes)
|
|
|
|
|
|
if (attribute is DefaultValueForModeAttribute)
|
|
|
|
|
|
{
|
|
|
|
|
|
var defaultValueForMode = attribute as DefaultValueForModeAttribute;
|
|
|
|
|
|
property.SetValue(this, defaultValueForMode.m_values[EncoderModeIndex]);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-04-07 20:41:58 -04:00
|
|
|
|
[Browsable(false)]
|
|
|
|
|
|
[XmlIgnore]
|
|
|
|
|
|
public AudioPCMConfig PCM
|
|
|
|
|
|
{
|
|
|
|
|
|
get;
|
|
|
|
|
|
set;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-04-04 22:07:15 -04:00
|
|
|
|
[Browsable(false)]
|
|
|
|
|
|
[DefaultValue(0)]
|
|
|
|
|
|
public int BlockSize
|
|
|
|
|
|
{
|
2013-04-07 20:41:58 -04:00
|
|
|
|
get;
|
|
|
|
|
|
set;
|
2013-04-04 22:07:15 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Browsable(false)]
|
2013-04-07 20:41:58 -04:00
|
|
|
|
[XmlIgnore]
|
2013-04-04 22:07:15 -04:00
|
|
|
|
[DefaultValue(4096)]
|
|
|
|
|
|
public int Padding
|
|
|
|
|
|
{
|
|
|
|
|
|
get;
|
|
|
|
|
|
set;
|
2013-04-01 23:03:22 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Browsable(false)]
|
2013-04-07 20:41:58 -04:00
|
|
|
|
[DefaultValue("")]
|
2013-04-01 23:03:22 -04:00
|
|
|
|
public string EncoderMode
|
|
|
|
|
|
{
|
|
|
|
|
|
get;
|
|
|
|
|
|
set;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[XmlIgnore]
|
|
|
|
|
|
[Browsable(false)]
|
|
|
|
|
|
public int EncoderModeIndex
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
2013-04-08 23:11:03 -04:00
|
|
|
|
string defaultMode;
|
|
|
|
|
|
string[] modes = this.GetSupportedModes(out defaultMode).Split(' ');
|
2013-04-01 23:03:22 -04:00
|
|
|
|
if (modes == null || modes.Length < 1)
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
for (int i = 0; i < modes.Length; i++)
|
|
|
|
|
|
if (modes[i] == this.EncoderMode)
|
|
|
|
|
|
return i;
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
2013-04-08 23:11:03 -04:00
|
|
|
|
string defaultMode;
|
|
|
|
|
|
string[] modes = this.GetSupportedModes(out defaultMode).Split(' ');
|
2013-04-01 23:03:22 -04:00
|
|
|
|
if (modes.Length == 0 && value < 0)
|
|
|
|
|
|
return;
|
|
|
|
|
|
if (value < 0 || value >= modes.Length)
|
2013-04-07 21:58:46 -04:00
|
|
|
|
throw new IndexOutOfRangeException();
|
2013-04-01 23:03:22 -04:00
|
|
|
|
this.EncoderMode = modes[value];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|