Removed AudioEncoderSettings/AudioDecoderSettings classes, all of their functionality is now in IAudioEncoderSettings/IAudioDecoderSettings interfaces.

This commit is contained in:
Grigory Chudov
2018-03-25 17:24:27 -04:00
parent 50fcd93ab9
commit 320e75d709
98 changed files with 5274 additions and 4863 deletions

View File

@@ -15,45 +15,17 @@ namespace CUETools.Codecs
Type DecoderType { get; }
bool Lossless { get; }
int Priority { get; }
IAudioDecoderSettings Clone();
}
[JsonObject(MemberSerialization.OptIn)]
public class AudioDecoderSettings: IAudioDecoderSettings
public static class IAudioDecoderSettingsExtensions
{
[Browsable(false)]
public virtual string Name => null;
[Browsable(false)]
public virtual string Extension => null;
[Browsable(false)]
public virtual Type DecoderType => null;
[Browsable(false)]
public virtual bool Lossless => true;
[Browsable(false)]
public virtual int Priority => 0;
public AudioDecoderSettings()
{
// Iterate through each property and call ResetValue()
foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(this))
property.ResetValue(this);
}
public AudioDecoderSettings Clone()
{
return this.MemberwiseClone() as AudioDecoderSettings;
}
public bool HasBrowsableAttributes()
public static bool HasBrowsableAttributes(this IAudioDecoderSettings settings)
{
bool hasBrowsable = false;
foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(this))
foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(settings))
{
bool isBrowsable = true;
foreach (var attribute in property.Attributes)
@@ -65,5 +37,12 @@ namespace CUETools.Codecs
}
return hasBrowsable;
}
public static void Init(this IAudioDecoderSettings settings)
{
// Iterate through each property and call ResetValue()
foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(settings))
property.ResetValue(settings);
}
}
}

View File

@@ -4,6 +4,15 @@ using System.Collections.Generic;
using System.Text;
using Newtonsoft.Json;
#if NET20
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class
| AttributeTargets.Method)]
public sealed class ExtensionAttribute : Attribute { }
}
#endif
namespace CUETools.Codecs
{
public interface IAudioEncoderSettings
@@ -17,67 +26,28 @@ namespace CUETools.Codecs
bool Lossless { get; }
int Priority { get; }
string SupportedModes { get; }
string DefaultMode { get; }
string EncoderMode { get; set; }
AudioPCMConfig PCM { get; set; }
int BlockSize { get; set; }
int Padding { get; set; }
IAudioEncoderSettings Clone();
}
[JsonObject(MemberSerialization.OptIn)]
public class AudioEncoderSettings : IAudioEncoderSettings
public static class IAudioEncoderSettingsExtensions
{
[Browsable(false)]
public virtual string Name => null;
[Browsable(false)]
public virtual string Extension => null;
[Browsable(false)]
public virtual Type EncoderType => null;
[Browsable(false)]
public virtual bool Lossless => false;
[Browsable(false)]
public virtual int Priority => 0;
public AudioEncoderSettings()
: this("", "")
{
}
public AudioEncoderSettings(AudioPCMConfig pcm)
: this("", "")
{
this.PCM = pcm;
}
public AudioEncoderSettings(string supported_modes, string default_mode)
{
// Iterate through each property and call ResetValue()
foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(this))
property.ResetValue(this);
this.m_supported_modes = supported_modes;
this.m_default_mode = default_mode;
if (default_mode == "")
GetSupportedModes(out default_mode);
this.EncoderMode = default_mode;
}
protected string m_supported_modes;
protected string m_default_mode;
public virtual string GetSupportedModes(out string defaultMode)
{
defaultMode = m_default_mode;
return this.m_supported_modes;
}
public AudioEncoderSettings Clone()
{
return this.MemberwiseClone() as AudioEncoderSettings;
}
public bool HasBrowsableAttributes()
public static bool HasBrowsableAttributes(this IAudioEncoderSettings settings)
{
bool hasBrowsable = false;
foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(this))
foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(settings))
{
bool isBrowsable = true;
foreach (var attribute in property.Attributes)
@@ -90,101 +60,65 @@ namespace CUETools.Codecs
return hasBrowsable;
}
protected void SetDefaultValuesForMode()
public static int GetEncoderModeIndex(this IAudioEncoderSettings settings)
{
foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(this))
if (!property.CanResetValue(this))
return new List<string>(settings.SupportedModes.Split(' ')).FindIndex(m => m == settings.EncoderMode);
}
public static void SetEncoderModeIndex(this IAudioEncoderSettings settings, int value)
{
string[] modes = settings.SupportedModes.Split(' ');
if (modes.Length == 0 && value < 0)
return;
if (value < 0 || value >= modes.Length)
throw new IndexOutOfRangeException();
settings.EncoderMode = modes[value];
}
public static void SetDefaultValuesForMode(this IAudioEncoderSettings settings)
{
foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(settings))
if (!property.CanResetValue(settings))
foreach (var attribute in property.Attributes)
if (attribute is DefaultValueForModeAttribute)
{
var defaultValueForMode = attribute as DefaultValueForModeAttribute;
property.SetValue(this, defaultValueForMode.m_values[EncoderModeIndex]);
property.SetValue(settings, defaultValueForMode.m_values[settings.GetEncoderModeIndex()]);
}
}
public bool HasDefaultValuesForMode(int index)
public static bool HasDefaultValuesForMode(this IAudioEncoderSettings settings, int index)
{
bool res = true;
foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(this))
foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(settings))
foreach (var attribute in property.Attributes)
if (attribute is DefaultValueForModeAttribute)
{
var defaultValueForMode = attribute as DefaultValueForModeAttribute;
res &= property.GetValue(this).Equals(defaultValueForMode.m_values[index]);
res &= property.GetValue(settings).Equals(defaultValueForMode.m_values[index]);
}
return res;
}
public int GuessEncoderMode()
public static int GuessEncoderMode(this IAudioEncoderSettings settings)
{
string defaultMode;
string[] modes = this.GetSupportedModes(out defaultMode).Split(' ');
// return new List<string>(settings.SupportedModes.Split(' ')).FindIndex(m => settings.HasDefaultValuesForMode(m));
string[] modes = settings.SupportedModes.Split(' ');
if (modes == null || modes.Length < 1)
return -1;
for (int i = 0; i < modes.Length; i++)
if (HasDefaultValuesForMode(i))
if (settings.HasDefaultValuesForMode(i))
return i;
return -1;
}
[Browsable(false)]
public AudioPCMConfig PCM
public static void Init(this IAudioEncoderSettings settings, AudioPCMConfig pcm = null)
{
get;
set;
}
[Browsable(false)]
[DefaultValue(0)]
public int BlockSize
{
get;
set;
}
[Browsable(false)]
[DefaultValue(4096)]
public int Padding
{
get;
set;
}
[Browsable(false)]
[DefaultValue("")]
[JsonProperty]
public string EncoderMode
{
get;
set;
}
[Browsable(false)]
public int EncoderModeIndex
{
get
{
string defaultMode;
string[] modes = this.GetSupportedModes(out defaultMode).Split(' ');
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
{
string defaultMode;
string[] modes = this.GetSupportedModes(out defaultMode).Split(' ');
if (modes.Length == 0 && value < 0)
return;
if (value < 0 || value >= modes.Length)
throw new IndexOutOfRangeException();
this.EncoderMode = modes[value];
}
// Iterate through each property and call ResetValue()
foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(settings))
property.ResetValue(settings);
settings.EncoderMode = settings.DefaultMode;
settings.PCM = pcm;
}
}
}

View File

@@ -18,7 +18,7 @@ namespace CUETools.Codecs
private bool own;
private ThreadPriority priority;
public AudioDecoderSettings Settings { get { return null; } }
public IAudioDecoderSettings Settings => null;
public long Position
{

View File

@@ -14,8 +14,8 @@ namespace CUETools.Codecs
{
[JsonIgnore]
public Dictionary<string, CUEToolsFormat> formats;
public List<AudioEncoderSettings> encoders;
public List<AudioDecoderSettings> decoders;
public List<IAudioEncoderSettings> encoders;
public List<IAudioDecoderSettings> decoders;
[JsonIgnore]
public EncoderListViewModel encodersViewModel;
[JsonIgnore]
@@ -23,8 +23,8 @@ namespace CUETools.Codecs
public CUEToolsCodecsConfig()
{
encoders = new List<AudioEncoderSettings>();
decoders = new List<AudioDecoderSettings>();
encoders = new List<IAudioEncoderSettings>();
decoders = new List<IAudioDecoderSettings>();
encodersViewModel = new EncoderListViewModel(encoders);
decodersViewModel = new DecoderListViewModel(decoders);
formats = new Dictionary<string, CUEToolsFormat>();
@@ -32,8 +32,8 @@ namespace CUETools.Codecs
public CUEToolsCodecsConfig(CUEToolsCodecsConfig src)
{
encoders = new List<AudioEncoderSettings>();
decoders = new List<AudioDecoderSettings>();
encoders = new List<IAudioEncoderSettings>();
decoders = new List<IAudioDecoderSettings>();
src.encoders.ForEach(item => encoders.Add(item.Clone()));
src.decoders.ForEach(item => decoders.Add(item.Clone()));
encodersViewModel = new EncoderListViewModel(encoders);
@@ -43,10 +43,10 @@ namespace CUETools.Codecs
formats.Add(fmt.Key, fmt.Value.Clone(this));
}
public void Init(List<AudioEncoderSettings> src_encoders, List<AudioDecoderSettings> src_decoders)
public void Init(List<IAudioEncoderSettings> src_encoders, List<IAudioDecoderSettings> src_decoders)
{
encoders = new List<AudioEncoderSettings>();
decoders = new List<AudioDecoderSettings>();
encoders = new List<IAudioEncoderSettings>();
decoders = new List<IAudioDecoderSettings>();
src_encoders.ForEach(item => encoders.Add(item.Clone()));
src_decoders.ForEach(item => decoders.Add(item.Clone()));
@@ -74,16 +74,16 @@ namespace CUETools.Codecs
decodersViewModel = new DecoderListViewModel(decoders);
formats = new Dictionary<string, CUEToolsFormat>();
formats.Add("flac", new CUEToolsFormat("flac", CUEToolsTagger.TagLibSharp, true, false, true, true, encodersViewModel.GetDefault("flac", true), null, decodersViewModel.GetDefault("flac", true)));
formats.Add("wv", new CUEToolsFormat("wv", CUEToolsTagger.TagLibSharp, true, false, true, true, encodersViewModel.GetDefault("wv", true), null, decodersViewModel.GetDefault("wv", true)));
formats.Add("ape", new CUEToolsFormat("ape", CUEToolsTagger.TagLibSharp, true, false, true, true, encodersViewModel.GetDefault("ape", true), null, decodersViewModel.GetDefault("ape", true)));
formats.Add("tta", new CUEToolsFormat("tta", CUEToolsTagger.APEv2, true, false, false, true, encodersViewModel.GetDefault("tta", true), null, decodersViewModel.GetDefault("tta", true)));
formats.Add("m2ts", new CUEToolsFormat("m2ts", CUEToolsTagger.APEv2, true, false, false, true, null, null, decodersViewModel.GetDefault("m2ts", true)));
formats.Add("mpls", new CUEToolsFormat("mpls", CUEToolsTagger.APEv2, true, false, false, true, null, null, decodersViewModel.GetDefault("mpls", true)));
formats.Add("wav", new CUEToolsFormat("wav", CUEToolsTagger.TagLibSharp, true, false, false, true, encodersViewModel.GetDefault("wav", true), null, decodersViewModel.GetDefault("wav", true)));
formats.Add("m4a", new CUEToolsFormat("m4a", CUEToolsTagger.TagLibSharp, true, true, false, true, encodersViewModel.GetDefault("m4a", true), encodersViewModel.GetDefault("m4a", false), decodersViewModel.GetDefault("m4a", true)));
formats.Add("tak", new CUEToolsFormat("tak", CUEToolsTagger.APEv2, true, false, true, true, encodersViewModel.GetDefault("tak", true), null, decodersViewModel.GetDefault("tak", true)));
formats.Add("wma", new CUEToolsFormat("wma", CUEToolsTagger.TagLibSharp, true, true, false, true, encodersViewModel.GetDefault("wma", true), encodersViewModel.GetDefault("wma", false), decodersViewModel.GetDefault("wma", true)));
formats.Add("flac", new CUEToolsFormat("flac", CUEToolsTagger.TagLibSharp, true, false, true, true, encodersViewModel.GetDefault("flac", true), null, decodersViewModel.GetDefault("flac")));
formats.Add("wv", new CUEToolsFormat("wv", CUEToolsTagger.TagLibSharp, true, false, true, true, encodersViewModel.GetDefault("wv", true), null, decodersViewModel.GetDefault("wv")));
formats.Add("ape", new CUEToolsFormat("ape", CUEToolsTagger.TagLibSharp, true, false, true, true, encodersViewModel.GetDefault("ape", true), null, decodersViewModel.GetDefault("ape")));
formats.Add("tta", new CUEToolsFormat("tta", CUEToolsTagger.APEv2, true, false, false, true, encodersViewModel.GetDefault("tta", true), null, decodersViewModel.GetDefault("tta")));
formats.Add("m2ts", new CUEToolsFormat("m2ts", CUEToolsTagger.APEv2, true, false, false, true, null, null, decodersViewModel.GetDefault("m2ts")));
formats.Add("mpls", new CUEToolsFormat("mpls", CUEToolsTagger.APEv2, true, false, false, true, null, null, decodersViewModel.GetDefault("mpls")));
formats.Add("wav", new CUEToolsFormat("wav", CUEToolsTagger.TagLibSharp, true, false, false, true, encodersViewModel.GetDefault("wav", true), null, decodersViewModel.GetDefault("wav")));
formats.Add("m4a", new CUEToolsFormat("m4a", CUEToolsTagger.TagLibSharp, true, true, false, true, encodersViewModel.GetDefault("m4a", true), encodersViewModel.GetDefault("m4a", false), decodersViewModel.GetDefault("m4a")));
formats.Add("tak", new CUEToolsFormat("tak", CUEToolsTagger.APEv2, true, false, true, true, encodersViewModel.GetDefault("tak", true), null, decodersViewModel.GetDefault("tak")));
formats.Add("wma", new CUEToolsFormat("wma", CUEToolsTagger.TagLibSharp, true, true, false, true, encodersViewModel.GetDefault("wma", true), encodersViewModel.GetDefault("wma", false), decodersViewModel.GetDefault("wma")));
formats.Add("mp3", new CUEToolsFormat("mp3", CUEToolsTagger.TagLibSharp, false, true, false, true, null, encodersViewModel.GetDefault("mp3", false), null));
formats.Add("ogg", new CUEToolsFormat("ogg", CUEToolsTagger.TagLibSharp, false, true, false, true, null, encodersViewModel.GetDefault("ogg", false), null));
formats.Add("opus", new CUEToolsFormat("opus", CUEToolsTagger.TagLibSharp, false, true, false, true, null, encodersViewModel.GetDefault("opus", false), null));

View File

@@ -34,7 +34,7 @@
public CUEToolsFormat Clone(CUEToolsCodecsConfig cfg)
{
var res = this.MemberwiseClone() as CUEToolsFormat;
if (decoder != null) cfg.decodersViewModel.TryGetValue(decoder.Settings.Extension, decoder.Lossless, decoder.Settings.Name, out res.decoder);
if (decoder != null) cfg.decodersViewModel.TryGetValue(decoder.Settings.Extension, decoder.Settings.Name, out res.decoder);
if (encoderLossy != null) cfg.encodersViewModel.TryGetValue(encoderLossy.Settings.Extension, encoderLossy.Lossless, encoderLossy.Settings.Name, out res.encoderLossy);
if (encoderLossless != null) cfg.encodersViewModel.TryGetValue(encoderLossless.Settings.Extension, encoderLossless.Lossless, encoderLossless.Settings.Name, out res.encoderLossless);
return res;

View File

@@ -11,7 +11,7 @@ namespace CUETools.Codecs.CommandLine
WAV.AudioDecoder rdr;
private DecoderSettings m_settings;
public AudioDecoderSettings Settings => m_settings;
public IAudioDecoderSettings Settings => m_settings;
public long Position
{

View File

@@ -30,7 +30,7 @@ namespace CUETools.Codecs.CommandLine
// !!!! Must not start the process in constructor, so that we can set CompressionLevel via Settings!
private EncoderSettings m_settings;
public AudioEncoderSettings Settings => m_settings;
public IAudioEncoderSettings Settings => m_settings;
public string Path { get { return _path; } }

View File

@@ -7,37 +7,48 @@ using Newtonsoft.Json;
namespace CUETools.Codecs.CommandLine
{
[JsonObject(MemberSerialization.OptIn)]
public class DecoderSettings : AudioDecoderSettings
public class DecoderSettings : IAudioDecoderSettings
{
public override string Name => name;
#region IAudioDecoderSettings implementation
[DefaultValue("")]
[JsonProperty]
public string Name { get; set; }
public override string Extension => extension;
[DefaultValue("")]
[JsonProperty]
public string Extension { get; set; }
[Browsable(false)]
public Type DecoderType => typeof(AudioDecoder);
[Browsable(false)]
public int Priority => 2;
public IAudioDecoderSettings Clone()
{
return MemberwiseClone() as IAudioDecoderSettings;
}
#endregion
public DecoderSettings()
: base()
{
this.Init();
}
public DecoderSettings(
string _name,
string _extension,
string _path,
string _parameters)
string name,
string extension,
string path,
string parameters)
: base()
{
name = _name;
extension = _extension;
Path = _path;
Parameters = _parameters;
Name = name;
Extension = extension;
Path = path;
Parameters = parameters;
}
[JsonProperty]
public string name;
[JsonProperty]
public string extension;
[DefaultValue(null)]
[DefaultValue("")]
[JsonProperty]
public string Path
{
@@ -45,7 +56,7 @@ namespace CUETools.Codecs.CommandLine
set;
}
[DefaultValue(null)]
[DefaultValue("")]
[JsonProperty]
public string Parameters
{

View File

@@ -7,50 +7,79 @@ using Newtonsoft.Json;
namespace CUETools.Codecs.CommandLine
{
[JsonObject(MemberSerialization.OptIn)]
public class EncoderSettings : AudioEncoderSettings
public class EncoderSettings : IAudioEncoderSettings
{
public override string Name => name;
#region IAudioEncoderSettings implementation
[DefaultValue("")]
[JsonProperty]
public string Name { get; set; }
public override string Extension => extension;
[DefaultValue("")]
[JsonProperty]
public string Extension { get; set; }
public override Type EncoderType => typeof(AudioEncoder);
[Browsable(false)]
public Type EncoderType => typeof(AudioEncoder);
public override bool Lossless => lossless;
[JsonProperty]
public bool Lossless { get; set; }
[Browsable(false)]
public int Priority => 0;
[DefaultValue("")]
[JsonProperty]
public string SupportedModes { get; set; }
public string DefaultMode => EncoderMode;
[Browsable(false)]
[DefaultValue("")]
[JsonProperty]
public string EncoderMode { get; set; }
[Browsable(false)]
public AudioPCMConfig PCM { get; set; }
[Browsable(false)]
public int BlockSize { get; set; }
[Browsable(false)]
[DefaultValue(4096)]
public int Padding { get; set; }
public IAudioEncoderSettings Clone()
{
return MemberwiseClone() as IAudioEncoderSettings;
}
#endregion
public EncoderSettings()
: base()
{
this.Init();
}
public EncoderSettings(
string _name,
string _extension,
bool _lossless,
string _supported_modes,
string _default_mode,
string _path,
string _parameters
string name,
string extension,
bool lossless,
string supportedModes,
string defaultMode,
string path,
string parameters
)
{
name = _name;
extension = _extension;
lossless = _lossless;
SupportedModes = _supported_modes;
EncoderMode = _default_mode;
Path = _path;
Parameters = _parameters;
this.Init();
Name = name;
Extension = extension;
Lossless = lossless;
SupportedModes = supportedModes;
Path = path;
EncoderMode = defaultMode;
Parameters = parameters;
}
[JsonProperty]
public string name;
[JsonProperty]
public string extension;
[JsonProperty]
public bool lossless;
[DefaultValue(null)]
[DefaultValue("")]
[JsonProperty]
public string Path
{
@@ -58,25 +87,12 @@ namespace CUETools.Codecs.CommandLine
set;
}
[DefaultValue(null)]
[DefaultValue("")]
[JsonProperty]
public string Parameters
{
get;
set;
}
[JsonProperty]
public string SupportedModes
{
get
{
return m_supported_modes;
}
set
{
m_supported_modes = value;
}
}
}
}

View File

@@ -2,7 +2,7 @@
{
public interface IAudioDest
{
AudioEncoderSettings Settings { get; }
IAudioEncoderSettings Settings { get; }
string Path { get; }
long FinalSampleCount { set; }

View File

@@ -2,7 +2,7 @@
{
public interface IAudioSource
{
AudioDecoderSettings Settings { get; }
IAudioDecoderSettings Settings { get; }
AudioPCMConfig PCM { get; }
string Path { get; }

View File

@@ -6,7 +6,7 @@
private AudioPCMConfig pcm;
private int _sampleVal;
public AudioDecoderSettings Settings { get { return null; } }
public IAudioDecoderSettings Settings => null;
public long Length
{

View File

@@ -4,9 +4,9 @@ namespace CUETools.Codecs.NULL
{
public class AudioEncoder : IAudioDest
{
AudioEncoderSettings m_settings;
IAudioEncoderSettings m_settings;
public AudioEncoder(string path, AudioEncoderSettings settings)
public AudioEncoder(string path, IAudioEncoderSettings settings)
{
m_settings = settings;
}
@@ -24,7 +24,7 @@ namespace CUETools.Codecs.NULL
set { }
}
public AudioEncoderSettings Settings => m_settings;
public IAudioEncoderSettings Settings => m_settings;
public void Write(AudioBuffer buff)
{

View File

@@ -8,7 +8,7 @@ namespace CUETools.Codecs
public class AudioDecoderSettingsViewModel : INotifyPropertyChanged
{
[JsonProperty]
public AudioDecoderSettings Settings = null;
public IAudioDecoderSettings Settings = null;
public event PropertyChangedEventHandler PropertyChanged;
@@ -17,7 +17,7 @@ namespace CUETools.Codecs
{
}
public AudioDecoderSettingsViewModel(AudioDecoderSettings settings)
public AudioDecoderSettingsViewModel(IAudioDecoderSettings settings)
{
this.Settings = settings;
}
@@ -62,21 +62,13 @@ namespace CUETools.Codecs
}
}
public bool Lossless
{
get => true;
set {
throw new InvalidOperationException();
}
}
public string Name
{
get => Settings.Name;
set
{
if (Settings is CommandLine.DecoderSettings)
(Settings as CommandLine.DecoderSettings).name = value;
(Settings as CommandLine.DecoderSettings).Name = value;
else throw new InvalidOperationException();
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Name"));
}
@@ -88,7 +80,7 @@ namespace CUETools.Codecs
set
{
if (Settings is CommandLine.DecoderSettings)
(Settings as CommandLine.DecoderSettings).extension = value;
(Settings as CommandLine.DecoderSettings).Extension = value;
else throw new InvalidOperationException();
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Extension"));
}

View File

@@ -8,7 +8,7 @@ namespace CUETools.Codecs
public class AudioEncoderSettingsViewModel : INotifyPropertyChanged
{
[JsonProperty]
public AudioEncoderSettings Settings = null;
public IAudioEncoderSettings Settings = null;
public event PropertyChangedEventHandler PropertyChanged;
@@ -17,7 +17,7 @@ namespace CUETools.Codecs
{
}
public AudioEncoderSettingsViewModel(AudioEncoderSettings settings)
public AudioEncoderSettingsViewModel(IAudioEncoderSettings settings)
{
this.Settings = settings;
}
@@ -70,7 +70,7 @@ namespace CUETools.Codecs
{
var settings = this.Settings as CommandLine.EncoderSettings;
if (settings == null) throw new InvalidOperationException();
settings.lossless = value;
settings.Lossless = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Lossless"));
}
}
@@ -83,7 +83,7 @@ namespace CUETools.Codecs
{
var settings = this.Settings as CommandLine.EncoderSettings;
if (settings == null) throw new InvalidOperationException();
settings.name = value;
settings.Name = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Name"));
}
}
@@ -95,36 +95,30 @@ namespace CUETools.Codecs
{
var settings = this.Settings as CommandLine.EncoderSettings;
if (settings == null) throw new InvalidOperationException();
settings.extension = value;
settings.Extension = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Extension"));
}
}
public string DotExtension => "." + Extension;
public string SupportedModesStr
public string SupportedModes
{
get
{
string defaultMode;
return this.Settings.GetSupportedModes(out defaultMode);
}
get => Settings.SupportedModes;
set
{
var settings = this.Settings as CommandLine.EncoderSettings;
if (settings == null) throw new InvalidOperationException();
settings.SupportedModes = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("SupportedModesStr"));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("SupportedModes"));
}
}
public string[] SupportedModes => this.SupportedModesStr.Split(' ');
public int EncoderModeIndex
{
get
{
string[] modes = this.SupportedModes;
string[] modes = this.SupportedModes.Split(' ');
if (modes == null || modes.Length < 2)
return -1;
for (int i = 0; i < modes.Length; i++)

View File

@@ -6,9 +6,9 @@ namespace CUETools.Codecs
{
public class DecoderListViewModel : BindingList<AudioDecoderSettingsViewModel>
{
private List<AudioDecoderSettings> model;
private List<IAudioDecoderSettings> model;
public DecoderListViewModel(List<AudioDecoderSettings> model)
public DecoderListViewModel(List<IAudioDecoderSettings> model)
: base()
{
this.model = model;
@@ -23,11 +23,11 @@ namespace CUETools.Codecs
e.NewObject = new AudioDecoderSettingsViewModel(item);
}
public bool TryGetValue(string extension, bool lossless, string name, out AudioDecoderSettingsViewModel result)
public bool TryGetValue(string extension, string name, out AudioDecoderSettingsViewModel result)
{
foreach (AudioDecoderSettingsViewModel udc in this)
{
if (udc.Settings.Extension == extension && udc.Settings.Lossless == lossless && udc.Settings.Name == name)
if (udc.Settings.Extension == extension && udc.Settings.Name == name)
{
result = udc;
return true;
@@ -37,12 +37,12 @@ namespace CUETools.Codecs
return false;
}
public AudioDecoderSettingsViewModel GetDefault(string extension, bool lossless)
public AudioDecoderSettingsViewModel GetDefault(string extension)
{
AudioDecoderSettingsViewModel result = null;
foreach (AudioDecoderSettingsViewModel udc in this)
{
if (udc.Settings.Extension == extension && udc.Settings.Lossless == lossless && (result == null || result.Settings.Priority < udc.Settings.Priority))
if (udc.Settings.Extension == extension && (result == null || result.Settings.Priority < udc.Settings.Priority))
{
result = udc;
}

View File

@@ -6,9 +6,9 @@ namespace CUETools.Codecs
{
public class EncoderListViewModel : BindingList<AudioEncoderSettingsViewModel>
{
private List<AudioEncoderSettings> model;
private List<IAudioEncoderSettings> model;
public EncoderListViewModel(List<AudioEncoderSettings> model)
public EncoderListViewModel(List<IAudioEncoderSettings> model)
: base()
{
this.model = model;

View File

@@ -14,7 +14,7 @@ namespace CUETools.Codecs.WAV
string _path;
private DecoderSettings m_settings;
public AudioDecoderSettings Settings => m_settings;
public IAudioDecoderSettings Settings => m_settings;
public long Position
{

View File

@@ -30,7 +30,7 @@ namespace CUETools.Codecs.WAV
}
private EncoderSettings m_settings;
public AudioEncoderSettings Settings => m_settings;
public IAudioEncoderSettings Settings => m_settings;
public string Path { get { return _path; } }

View File

@@ -1,19 +1,36 @@
using System;
using Newtonsoft.Json;
using System;
using System.ComponentModel;
namespace CUETools.Codecs.WAV
{
public class DecoderSettings : AudioDecoderSettings
[JsonObject(MemberSerialization.OptIn)]
public class DecoderSettings : IAudioDecoderSettings
{
public override string Name => "cuetools";
#region IAudioDecoderSettings implementation
[Browsable(false)]
public string Extension => "wav";
public override string Extension => "wav";
[Browsable(false)]
public string Name => "cuetools";
public override Type DecoderType => typeof(AudioDecoder);
[Browsable(false)]
public Type DecoderType => typeof(AudioDecoder);
public override int Priority => 2;
[Browsable(false)]
public int Priority => 2;
public DecoderSettings() : base() { }
public IAudioDecoderSettings Clone()
{
return MemberwiseClone() as IAudioDecoderSettings;
}
#endregion
public bool IgnoreChunkSizes;
public DecoderSettings()
{
this.Init();
}
public bool IgnoreChunkSizes { get; set; }
}
}

View File

@@ -1,29 +1,64 @@
using System;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
namespace CUETools.Codecs.WAV
{
public class EncoderSettings : AudioEncoderSettings
[JsonObject(MemberSerialization.OptIn)]
public class EncoderSettings : IAudioEncoderSettings
{
public override string Extension => "wav";
#region IAudioEncoderSettings implementation
[Browsable(false)]
public string Extension => "wav";
public override string Name => "cuetools";
[Browsable(false)]
public string Name => "cuetools";
public override Type EncoderType => typeof(WAV.AudioEncoder);
[Browsable(false)]
public Type EncoderType => typeof(WAV.AudioEncoder);
public override int Priority => 10;
[Browsable(false)]
public bool Lossless => true;
public override bool Lossless => true;
[Browsable(false)]
public int Priority => 10;
[Browsable(false)]
public string SupportedModes => "";
[Browsable(false)]
public string DefaultMode => "";
[Browsable(false)]
[DefaultValue("")]
public string EncoderMode { get; set; }
[Browsable(false)]
public AudioPCMConfig PCM { get; set; }
[Browsable(false)]
public int BlockSize { get; set; }
[Browsable(false)]
[DefaultValue(4096)]
public int Padding { get; set; }
public IAudioEncoderSettings Clone()
{
return MemberwiseClone() as IAudioEncoderSettings;
}
#endregion
public EncoderSettings()
: this(null)
{
this.Init();
}
public EncoderSettings(AudioPCMConfig pcm)
: base(pcm)
{
this.Init(pcm);
}
}
}