Code cleanup; Reader classes renamed to Decoders, Writers to Encoders, every Decoder must have a corresponding Settings class now just like Encoders. UserDefinedEncoders renamed to CommandLineEncoders, etc.

This commit is contained in:
Grigory Chudov
2018-03-24 12:15:49 -04:00
parent ca8bb2fff6
commit e1f8906170
65 changed files with 1713 additions and 1798 deletions

View File

@@ -25,12 +25,12 @@ namespace CUETools.Processor
throw new Exception("Unsupported audio type: " + path);
if (fmt.decoder == null)
throw new Exception("Unsupported audio type: " + path);
var settings = fmt.decoder.decoderSettings.Clone();
var settings = fmt.decoder.Settings.Clone();
try
{
object src = Activator.CreateInstance(fmt.decoder.decoderSettings.DecoderType, settings, path, IO);
object src = Activator.CreateInstance(fmt.decoder.Settings.DecoderType, settings, path, IO);
if (src == null || !(src is IAudioSource))
throw new Exception("Unsupported audio type: " + path + ": " + fmt.decoder.decoderSettings.DecoderType.FullName);
throw new Exception("Unsupported audio type: " + path + ": " + fmt.decoder.Settings.DecoderType.FullName);
return src as IAudioSource;
}
catch (System.Reflection.TargetInvocationException ex)
@@ -60,7 +60,7 @@ namespace CUETools.Processor
null;
if (encoder == null)
throw new Exception("Unsupported audio type: " + path);
var settings = encoder.settings.Clone();
var settings = encoder.Settings.Clone();
settings.PCM = pcm;
settings.Padding = padding;
object o;

View File

@@ -12,7 +12,7 @@ using System.Linq;
namespace CUETools.Processor
{
public class CUEConfig : CUEToolsCodecsConfig
public class CUEConfig
{
public uint fixOffsetMinimumConfidence;
public uint fixOffsetMinimumTracksPercent;
@@ -71,11 +71,12 @@ namespace CUETools.Processor
public bool CopyAlbumArt { get; set; }
public string ArLogFilenameFormat { get; set; }
public string AlArtFilenameFormat { get; set; }
public EncoderListViewModel Encoders => encoders;
public DecoderListViewModel Decoders => decoders;
public EncoderListViewModel Encoders => advanced.encodersViewModel;
public DecoderListViewModel Decoders => advanced.decodersViewModel;
public Dictionary<string, CUEToolsFormat> formats => advanced.formats;
public CUEConfig()
: base(CUEProcessorPlugins.encs, CUEProcessorPlugins.decs)
: base()
{
fixOffsetMinimumConfidence = 2;
fixOffsetMinimumTracksPercent = 51;
@@ -136,6 +137,7 @@ namespace CUETools.Processor
gapsHandling = CUEStyle.GapsAppended;
advanced = new CUEConfigAdvanced();
advanced.Init();
language = Thread.CurrentThread.CurrentUICulture.Name;
@@ -155,7 +157,6 @@ namespace CUETools.Processor
}
public CUEConfig(CUEConfig src)
: base(src)
{
fixOffsetMinimumConfidence = src.fixOffsetMinimumConfidence;
fixOffsetMinimumTracksPercent = src.fixOffsetMinimumTracksPercent;
@@ -296,33 +297,13 @@ namespace CUETools.Processor
sw.Save("AlArtFilenameFormat", AlArtFilenameFormat);
sw.SaveText("Advanced", JsonConvert.SerializeObject(advanced,
Newtonsoft.Json.Formatting.Indented,
new JsonSerializerSettings
{
DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate
}));
sw.SaveText("Encoders", JsonConvert.SerializeObject(encoders,
Newtonsoft.Json.Formatting.Indented,
new JsonSerializerSettings
{
DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate,
TypeNameHandling = TypeNameHandling.Auto
TypeNameHandling = TypeNameHandling.Auto,
}));
int nDecoders = 0;
foreach (var decoder in decoders)
if (decoder.decoderSettings is Codecs.CommandLine.DecoderSettings)
{
var settings = decoder.decoderSettings as Codecs.CommandLine.DecoderSettings;
sw.Save(string.Format("ExternalDecoder{0}Name", nDecoders), settings.Name);
sw.Save(string.Format("ExternalDecoder{0}Extension", nDecoders), settings.Extension);
sw.Save(string.Format("ExternalDecoder{0}Path", nDecoders), settings.Path);
sw.Save(string.Format("ExternalDecoder{0}Parameters", nDecoders), settings.Parameters);
nDecoders++;
}
sw.Save("ExternalDecoders", nDecoders);
int nFormats = 0;
foreach (KeyValuePair<string, CUEToolsFormat> format in formats)
{
@@ -415,100 +396,56 @@ namespace CUETools.Processor
separateDecodingThread = sr.LoadBoolean("SeparateDecodingThread") ?? separateDecodingThread;
try
var jsonConfig = sr.Load("Advanced");
if (jsonConfig != null)
{
var jsonObject = JsonConvert.DeserializeObject(sr.Load("Advanced"),
typeof(CUEConfigAdvanced),
new JsonSerializerSettings { DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate
});
if (jsonObject as CUEConfigAdvanced == null)
throw new Exception();
advanced = jsonObject as CUEConfigAdvanced;
}
catch (Exception ex)
{
System.Diagnostics.Trace.WriteLine(ex.Message);
}
var encodersBackup = encoders;
try
{
var jsonObject = JsonConvert.DeserializeObject(sr.Load("Encoders"),
typeof(EncoderListViewModel),
new JsonSerializerSettings {
DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate,
TypeNameHandling = TypeNameHandling.Auto
});
if (jsonObject as EncoderListViewModel == null)
throw new Exception();
encoders = jsonObject as EncoderListViewModel;
encoders.Where(x => !x.IsValid).ToList().ForEach(x => encoders.Remove(x));
AudioEncoderSettingsViewModel tmp;
encodersBackup.Where(x => !encoders.TryGetValue(x.Extension, x.Lossless, x.Name, out tmp)).ToList().ForEach(x => encoders.Add(x));
}
catch (Exception ex)
{
System.Diagnostics.Trace.WriteLine(ex.Message);
}
//int totalEncoders = sr.LoadInt32("ExternalEncoders", 0, null) ?? 0;
//for (int nEncoders = 0; nEncoders < totalEncoders; nEncoders++)
//{
// string name = sr.Load(string.Format("ExternalEncoder{0}Name", nEncoders));
// string extension = sr.Load(string.Format("ExternalEncoder{0}Extension", nEncoders));
// string settings = sr.Load(string.Format("ExternalEncoder{0}Settings", nEncoders));
// bool lossless = sr.LoadBoolean(string.Format("ExternalEncoder{0}Lossless", nEncoders)) ?? true;
// CUEToolsUDC encoder;
// if (name == null || extension == null) continue;
// if (!encoders.TryGetValue(extension, lossless, name, out encoder))
// {
// encoder = new CUEToolsUDC(name, extension, lossless, "", "", "", "");
// encoders.Add(encoder);
// }
// try
// {
// if (settings != null)
// {
// var encoderSettings = JsonConvert.DeserializeObject(settings,
// encoder.settings.GetType(),
// new JsonSerializerSettings { DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate });
// if (encoderSettings as AudioEncoderSettings == null)
// throw new Exception();
// encoder.settings = encoderSettings as AudioEncoderSettings;
// if (encoder.settings is UserDefinedEncoderSettings && (encoder.settings as UserDefinedEncoderSettings).Path == "")
// throw new Exception();
// }
// }
// catch (Exception ex)
// {
// System.Diagnostics.Trace.WriteLine(ex.Message);
// if (version == 203 && encoder.settings is UserDefinedEncoderSettings)
// {
// (encoder.settings as UserDefinedEncoderSettings).SupportedModes = sr.Load(string.Format("ExternalEncoder{0}Modes", nEncoders));
// (encoder.settings as UserDefinedEncoderSettings).EncoderMode = sr.Load(string.Format("ExternalEncoder{0}Mode", nEncoders));
// (encoder.settings as UserDefinedEncoderSettings).Path = sr.Load(string.Format("ExternalEncoder{0}Path", nEncoders));
// (encoder.settings as UserDefinedEncoderSettings).Parameters = sr.Load(string.Format("ExternalEncoder{0}Parameters", nEncoders));
// }
// else
// encoders.Remove(encoder);
// }
//}
int totalDecoders = sr.LoadInt32("ExternalDecoders", 0, null) ?? 0;
for (int nDecoders = 0; nDecoders < totalDecoders; nDecoders++)
{
string name = sr.Load(string.Format("ExternalDecoder{0}Name", nDecoders));
string extension = sr.Load(string.Format("ExternalDecoder{0}Extension", nDecoders));
string path = sr.Load(string.Format("ExternalDecoder{0}Path", nDecoders));
string parameters = sr.Load(string.Format("ExternalDecoder{0}Parameters", nDecoders));
AudioDecoderSettingsViewModel decoder;
if (!decoders.TryGetValue(extension, true, name, out decoder))
decoders.Add(new AudioDecoderSettingsViewModel(new Codecs.CommandLine.DecoderSettings(name, extension, path, parameters)));
else
var backup = advanced;
try
{
decoder.Extension = extension;
decoder.Path = path;
decoder.Parameters = parameters;
var jsonObject = JsonConvert.DeserializeObject(jsonConfig,
typeof(CUEConfigAdvanced),
new JsonSerializerSettings
{
DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate,
TypeNameHandling = TypeNameHandling.Auto,
});
if (jsonObject as CUEConfigAdvanced == null)
throw new Exception();
advanced = jsonObject as CUEConfigAdvanced;
// Add missing codecs
backup.encoders.Where(x => advanced.encoders
.FindAll(y => y.Extension == x.Extension && y.Lossless == x.Lossless && y.Name == x.Name).Count == 0)
.ToList().ForEach(x => advanced.encoders.Add(x));
backup.decoders.Where(x => advanced.decoders
.FindAll(y => y.Extension == x.Extension && y.Lossless == x.Lossless && y.Name == x.Name).Count == 0)
.ToList().ForEach(x => advanced.decoders.Add(x));
// Reset the ViewModel
advanced.encodersViewModel = new EncoderListViewModel(advanced.encoders);
advanced.decodersViewModel = new DecoderListViewModel(advanced.decoders);
// Reset the links in formats
foreach (var extension in formats.Keys)
{
var format = formats[extension];
AudioEncoderSettingsViewModel encoderLossless, encoderLossy;
AudioDecoderSettingsViewModel decoder;
if (format.encoderLossless == null || !Encoders.TryGetValue(extension, true, format.encoderLossless.Name, out encoderLossless))
encoderLossless = Encoders.GetDefault(extension, true);
if (format.encoderLossy == null || !Encoders.TryGetValue(extension, false, format.encoderLossy.Name, out encoderLossy))
encoderLossy = Encoders.GetDefault(extension, false);
if (format.decoder == null || !Decoders.TryGetValue(extension, true, format.decoder.Name, out decoder))
decoder = Decoders.GetDefault(extension, true);
format.encoderLossless = encoderLossless;
format.encoderLossy = encoderLossy;
format.decoder = decoder;
}
}
catch (Exception ex)
{
System.Diagnostics.Trace.WriteLine(ex.Message);
advanced = backup;
}
}
@@ -526,12 +463,12 @@ namespace CUETools.Processor
CUEToolsFormat format;
AudioEncoderSettingsViewModel udcLossless, udcLossy;
AudioDecoderSettingsViewModel udcDecoder;
if (encoderLossless == "" || !encoders.TryGetValue(extension, true, encoderLossless, out udcLossless))
udcLossless = encoders.GetDefault(extension, true);
if (encoderLossy == "" || !encoders.TryGetValue(extension, false, encoderLossy, out udcLossy))
udcLossy = encoders.GetDefault(extension, false);
if (decoder == "" || !decoders.TryGetValue(extension, true, decoder, out udcDecoder))
udcDecoder = decoders.GetDefault(extension, true);
if (encoderLossless == "" || !Encoders.TryGetValue(extension, true, encoderLossless, out udcLossless))
udcLossless = Encoders.GetDefault(extension, true);
if (encoderLossy == "" || !Encoders.TryGetValue(extension, false, encoderLossy, out udcLossy))
udcLossy = Encoders.GetDefault(extension, false);
if (decoder == "" || !Decoders.TryGetValue(extension, true, decoder, out udcDecoder))
udcDecoder = Decoders.GetDefault(extension, true);
if (!formats.TryGetValue(extension, out format))
formats.Add(extension, new CUEToolsFormat(extension, tagger, allowLossless, allowLossy, allowEmbed, false, udcLossless, udcLossy, udcDecoder));
else

View File

@@ -1,10 +1,11 @@
using System;
using CUETools.Codecs;
using System;
using System.ComponentModel;
namespace CUETools.Processor
{
[Serializable]
public class CUEConfigAdvanced
public class CUEConfigAdvanced : CUEToolsCodecsConfig
{
public enum ProxyMode
{
@@ -38,6 +39,11 @@ namespace CUETools.Processor
}
}
public void Init()
{
Init(CUEProcessorPlugins.encs, CUEProcessorPlugins.decs);
}
[DefaultValue("i"), Category("Freedb"), DisplayName("Email user")]
public string FreedbUser { get; set; }

View File

@@ -11,8 +11,8 @@ namespace CUETools.Processor
{
public static class CUEProcessorPlugins
{
public static List<Type> encs;
public static List<Type> decs;
public static List<AudioEncoderSettings> encs;
public static List<AudioDecoderSettings> decs;
public static List<Type> arcp;
public static List<string> arcp_fmt;
public static Type hdcd;
@@ -20,13 +20,13 @@ namespace CUETools.Processor
static CUEProcessorPlugins()
{
encs = new List<Type>();
decs = new List<Type>();
encs = new List<AudioEncoderSettings>();
decs = new List<AudioDecoderSettings>();
arcp = new List<Type>();
arcp_fmt = new List<string>();
encs.Add(typeof(CUETools.Codecs.WAV.AudioEncoder));
decs.Add(typeof(CUETools.Codecs.WAV.AudioDecoder));
encs.Add(new Codecs.WAV.EncoderSettings());
decs.Add(new Codecs.WAV.DecoderSettings());
//ApplicationSecurityInfo asi = new ApplicationSecurityInfo(AppDomain.CurrentDomain.ActivationContext);
//string arch = asi.ApplicationId.ProcessorArchitecture;
@@ -67,14 +67,14 @@ namespace CUETools.Processor
{
try
{
if (Attribute.GetCustomAttribute(type, typeof(AudioDecoderClassAttribute)) != null)
if (!type.IsClass || type.IsAbstract) continue;
if (type.GetInterface(typeof(IAudioDecoderSettings).Name) != null && type != typeof(AudioDecoderSettings))
{
decs.Add(type);
decs.Add(Activator.CreateInstance(type) as AudioDecoderSettings);
}
//if (type.IsClass && !type.IsAbstract && typeof(IAudioDest).IsAssignableFrom(type))
if (Attribute.GetCustomAttributes(type, typeof(AudioEncoderClassAttribute)).Length > 0)
if (type.GetInterface(typeof(IAudioEncoderSettings).Name) != null && type != typeof(AudioEncoderSettings))
{
encs.Add(type);
encs.Add(Activator.CreateInstance(type) as AudioEncoderSettings);
}
CompressionProviderClass archclass = Attribute.GetCustomAttribute(type, typeof(CompressionProviderClass)) as CompressionProviderClass;
if (archclass != null)
@@ -87,7 +87,7 @@ namespace CUETools.Processor
{
hdcd = type;
}
if (type.IsClass && !type.IsAbstract && typeof(ICDRipper).IsAssignableFrom(type))
if (type.GetInterface(typeof(ICDRipper).Name) != null)
{
ripper = type;
}

View File

@@ -788,7 +788,7 @@ namespace CUETools.Processor
else
{
TagLib.File fileInfo;
TagLib.UserDefined.AdditionalFileTypes.Config = _config;
TagLib.UserDefined.AdditionalFileTypes.Config = _config.advanced;
TagLib.File.IFileAbstraction file = new TagLib.File.LocalFileAbstraction(path);
fileInfo = TagLib.File.Create(file);
NameValueCollection tags = Tagging.Analyze(fileInfo);
@@ -2195,7 +2195,7 @@ namespace CUETools.Processor
}
else
{
TagLib.UserDefined.AdditionalFileTypes.Config = _config;
TagLib.UserDefined.AdditionalFileTypes.Config = _config.advanced;
TagLib.File.IFileAbstraction file = _isArchive
? (TagLib.File.IFileAbstraction)new ArchiveFileAbstraction(this, path)
: (TagLib.File.IFileAbstraction)new TagLib.File.LocalFileAbstraction(path);
@@ -2668,9 +2668,9 @@ namespace CUETools.Processor
if (_audioEncoderType != AudioEncoderType.NoAudio)
{
NameValueCollection tags = GenerateAlbumTags(bestOffset, OutputStyle == CUEStyle.SingleFileWithCUE, _ripperLog ?? _eacLog);
TagLib.UserDefined.AdditionalFileTypes.Config = _config;
TagLib.UserDefined.AdditionalFileTypes.Config = _config.advanced;
TagLib.File fileInfo = TagLib.File.Create(new TagLib.File.LocalFileAbstraction(_destPaths[0]));
if (Tagging.UpdateTags(fileInfo, tags, _config, _config.advanced.UseId3v24))
if (Tagging.UpdateTags(fileInfo, tags, _config.advanced, _config.advanced.UseId3v24))
{
TagLib.File sourceFileInfo = _tracks[0]._fileInfo ?? _fileInfo;
@@ -2754,9 +2754,9 @@ namespace CUETools.Processor
{
string path = _destPaths[iTrack + (htoaToFile ? 1 : 0)];
NameValueCollection tags = GenerateTrackTags(iTrack, bestOffset);
TagLib.UserDefined.AdditionalFileTypes.Config = _config;
TagLib.UserDefined.AdditionalFileTypes.Config = _config.advanced;
TagLib.File fileInfo = TagLib.File.Create(new TagLib.File.LocalFileAbstraction(path));
if (Tagging.UpdateTags(fileInfo, tags, _config, _config.advanced.UseId3v24))
if (Tagging.UpdateTags(fileInfo, tags, _config.advanced, _config.advanced.UseId3v24))
{
TagLib.File sourceFileInfo = _tracks[iTrack]._fileInfo ?? _fileInfo;
@@ -3033,7 +3033,7 @@ namespace CUETools.Processor
NameValueCollection tags = Tagging.Analyze(_fileInfo);
CleanupTags(tags, "ACCURATERIP");
GenerateAccurateRipTags(tags, bestOffset, -1);
if (Tagging.UpdateTags(_fileInfo, tags, _config, _config.advanced.UseId3v24))
if (Tagging.UpdateTags(_fileInfo, tags, _config.advanced, _config.advanced.UseId3v24))
_fileInfo.Save();
}
else if (_hasTrackFilenames)
@@ -3043,7 +3043,7 @@ namespace CUETools.Processor
NameValueCollection tags = Tagging.Analyze(_tracks[iTrack]._fileInfo);
CleanupTags(tags, "ACCURATERIP");
GenerateAccurateRipTags(tags, bestOffset, iTrack);
if (Tagging.UpdateTags(_tracks[iTrack]._fileInfo, tags, _config, _config.advanced.UseId3v24))
if (Tagging.UpdateTags(_tracks[iTrack]._fileInfo, tags, _config.advanced, _config.advanced.UseId3v24))
_tracks[iTrack]._fileInfo.Save();
}
}
@@ -3059,7 +3059,7 @@ namespace CUETools.Processor
CleanupTags(tags, "CTDBDISCCONFIDENCE");
CleanupTags(tags, "CTDBTRACKCONFIDENCE");
GenerateCTDBTags(tags, -1);
if (Tagging.UpdateTags(_fileInfo, tags, _config, _config.advanced.UseId3v24))
if (Tagging.UpdateTags(_fileInfo, tags, _config.advanced, _config.advanced.UseId3v24))
_fileInfo.Save();
}
else if (_hasTrackFilenames)
@@ -3070,7 +3070,7 @@ namespace CUETools.Processor
CleanupTags(tags, "CTDBDISCCONFIDENCE");
CleanupTags(tags, "CTDBTRACKCONFIDENCE");
GenerateCTDBTags(tags, iTrack);
if (Tagging.UpdateTags(_tracks[iTrack]._fileInfo, tags, _config, _config.advanced.UseId3v24))
if (Tagging.UpdateTags(_tracks[iTrack]._fileInfo, tags, _config.advanced, _config.advanced.UseId3v24))
_tracks[iTrack]._fileInfo.Save();
}
}
@@ -3687,7 +3687,7 @@ namespace CUETools.Processor
{
if (fileGroup.type == FileGroupInfoType.FileWithCUE)
{
TagLib.UserDefined.AdditionalFileTypes.Config = _config;
TagLib.UserDefined.AdditionalFileTypes.Config = _config.advanced;
TagLib.File.IFileAbstraction fileAbsraction = new TagLib.File.LocalFileAbstraction(fileGroup.main.FullName);
TagLib.File fileInfo = TagLib.File.Create(fileAbsraction);
return Tagging.Analyze(fileInfo).Get("CUESHEET");
@@ -4199,7 +4199,7 @@ namespace CUETools.Processor
string cueFound = null;
CDImageLayout tocFound = null;
TimeSpan dur = TimeSpan.Zero;
TagLib.UserDefined.AdditionalFileTypes.Config = _config;
TagLib.UserDefined.AdditionalFileTypes.Config = _config.advanced;
TagLib.File.IFileAbstraction fileAbsraction = new TagLib.File.LocalFileAbstraction(file.FullName);
try
{