mirror of
https://github.com/claunia/cuetools.net.git
synced 2025-12-16 18:14:25 +00:00
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:
@@ -19,22 +19,18 @@ namespace CUETools.Processor
|
||||
}
|
||||
}
|
||||
if (extension == ".bin")
|
||||
return new WAVReader(path, IO, AudioPCMConfig.RedBook);
|
||||
return new Codecs.WAV.AudioDecoder(new Codecs.WAV.DecoderSettings(), path, IO, AudioPCMConfig.RedBook);
|
||||
CUEToolsFormat fmt;
|
||||
if (!extension.StartsWith(".") || !config.formats.TryGetValue(extension.Substring(1), out fmt))
|
||||
throw new Exception("Unsupported audio type: " + path);
|
||||
if (fmt.decoder == null)
|
||||
throw new Exception("Unsupported audio type: " + path);
|
||||
if (fmt.decoder.path != null)
|
||||
return new UserDefinedReader(path, IO, fmt.decoder.path, fmt.decoder.parameters);
|
||||
if (fmt.decoder.type == null)
|
||||
throw new Exception("Unsupported audio type: " + path);
|
||||
|
||||
try
|
||||
var settings = fmt.decoder.decoderSettings.Clone();
|
||||
try
|
||||
{
|
||||
object src = Activator.CreateInstance(fmt.decoder.type, path, IO);
|
||||
object src = Activator.CreateInstance(fmt.decoder.decoderSettings.DecoderType, settings, path, IO);
|
||||
if (src == null || !(src is IAudioSource))
|
||||
throw new Exception("Unsupported audio type: " + path + ": " + fmt.decoder.type.FullName);
|
||||
throw new Exception("Unsupported audio type: " + path + ": " + fmt.decoder.decoderSettings.DecoderType.FullName);
|
||||
return src as IAudioSource;
|
||||
}
|
||||
catch (System.Reflection.TargetInvocationException ex)
|
||||
@@ -59,7 +55,7 @@ namespace CUETools.Processor
|
||||
CUEToolsFormat fmt;
|
||||
if (!extension.StartsWith(".") || !config.formats.TryGetValue(extension.Substring(1), out fmt))
|
||||
throw new Exception("Unsupported audio type: " + path);
|
||||
CUEToolsUDC encoder = audioEncoderType == AudioEncoderType.Lossless ? fmt.encoderLossless :
|
||||
AudioEncoderSettingsViewModel encoder = audioEncoderType == AudioEncoderType.Lossless ? fmt.encoderLossless :
|
||||
audioEncoderType == AudioEncoderType.Lossy ? fmt.encoderLossy :
|
||||
null;
|
||||
if (encoder == null)
|
||||
@@ -70,14 +66,14 @@ namespace CUETools.Processor
|
||||
object o;
|
||||
try
|
||||
{
|
||||
o = Activator.CreateInstance(encoder.type, path, settings);
|
||||
o = Activator.CreateInstance(settings.EncoderType, settings, path, null);
|
||||
}
|
||||
catch (System.Reflection.TargetInvocationException ex)
|
||||
{
|
||||
throw ex.InnerException;
|
||||
}
|
||||
if (o == null || !(o is IAudioDest))
|
||||
throw new Exception("Unsupported audio type: " + path + ": " + encoder.type.FullName);
|
||||
throw new Exception("Unsupported audio type: " + path + ": " + settings.EncoderType.FullName);
|
||||
dest = o as IAudioDest;
|
||||
dest.FinalSampleCount = finalSampleCount;
|
||||
return dest;
|
||||
|
||||
@@ -5,17 +5,15 @@ using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
using CUETools.Codecs;
|
||||
using CUETools.Processor.Settings;
|
||||
using Newtonsoft.Json;
|
||||
using System.Linq;
|
||||
|
||||
namespace CUETools.Processor
|
||||
{
|
||||
public class CUEConfig : CUEToolsCodecsConfig
|
||||
{
|
||||
public readonly static XmlSerializerNamespaces xmlEmptyNamespaces = new XmlSerializerNamespaces(new XmlQualifiedName[] { XmlQualifiedName.Empty });
|
||||
public readonly static XmlWriterSettings xmlEmptySettings = new XmlWriterSettings { Indent = true, OmitXmlDeclaration = true };
|
||||
|
||||
public uint fixOffsetMinimumConfidence;
|
||||
public uint fixOffsetMinimumTracksPercent;
|
||||
public uint encodeWhenConfidence;
|
||||
@@ -73,14 +71,8 @@ namespace CUETools.Processor
|
||||
public bool CopyAlbumArt { get; set; }
|
||||
public string ArLogFilenameFormat { get; set; }
|
||||
public string AlArtFilenameFormat { get; set; }
|
||||
public CUEToolsUDCList Encoders
|
||||
{
|
||||
get { return encoders; }
|
||||
}
|
||||
public CUEToolsUDCList Decoders
|
||||
{
|
||||
get { return decoders; }
|
||||
}
|
||||
public CUEToolsUDCEncoderList Encoders => encoders;
|
||||
public CUEToolsUDCDecoderList Decoders => decoders;
|
||||
|
||||
public CUEConfig()
|
||||
: base(CUEProcessorPlugins.encs, CUEProcessorPlugins.decs)
|
||||
@@ -303,37 +295,30 @@ namespace CUETools.Processor
|
||||
sw.Save("ArLogFilenameFormat", ArLogFilenameFormat);
|
||||
sw.Save("AlArtFilenameFormat", AlArtFilenameFormat);
|
||||
|
||||
using (TextWriter tw = new StringWriter())
|
||||
using (XmlWriter xw = XmlTextWriter.Create(tw, xmlEmptySettings))
|
||||
{
|
||||
CUEConfigAdvanced.serializer.Serialize(xw, advanced, xmlEmptyNamespaces);
|
||||
sw.SaveText("Advanced", tw.ToString());
|
||||
}
|
||||
|
||||
int nEncoders = 0;
|
||||
foreach (CUEToolsUDC encoder in encoders)
|
||||
{
|
||||
sw.Save(string.Format("ExternalEncoder{0}Name", nEncoders), encoder.name);
|
||||
sw.Save(string.Format("ExternalEncoder{0}Extension", nEncoders), encoder.extension);
|
||||
sw.Save(string.Format("ExternalEncoder{0}Lossless", nEncoders), encoder.lossless);
|
||||
using (TextWriter tw = new StringWriter())
|
||||
using (XmlWriter xw = XmlTextWriter.Create(tw, xmlEmptySettings))
|
||||
sw.SaveText("Advanced", JsonConvert.SerializeObject(advanced,
|
||||
Newtonsoft.Json.Formatting.Indented,
|
||||
new JsonSerializerSettings
|
||||
{
|
||||
encoder.settingsSerializer.Serialize(xw, encoder.settings, xmlEmptyNamespaces);
|
||||
sw.SaveText(string.Format("ExternalEncoder{0}Settings", nEncoders), tw.ToString());
|
||||
}
|
||||
nEncoders++;
|
||||
}
|
||||
sw.Save("ExternalEncoders", nEncoders);
|
||||
DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate
|
||||
}));
|
||||
|
||||
sw.SaveText("Encoders", JsonConvert.SerializeObject(encoders,
|
||||
Newtonsoft.Json.Formatting.Indented,
|
||||
new JsonSerializerSettings
|
||||
{
|
||||
DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate,
|
||||
TypeNameHandling = TypeNameHandling.Auto
|
||||
}));
|
||||
|
||||
int nDecoders = 0;
|
||||
foreach (var decoder in decoders)
|
||||
if (decoder.path != null)
|
||||
if (decoder.decoderSettings is CommandLineDecoderSettings)
|
||||
{
|
||||
sw.Save(string.Format("ExternalDecoder{0}Name", nDecoders), decoder.Name);
|
||||
sw.Save(string.Format("ExternalDecoder{0}Extension", nDecoders), decoder.extension);
|
||||
sw.Save(string.Format("ExternalDecoder{0}Path", nDecoders), decoder.path);
|
||||
sw.Save(string.Format("ExternalDecoder{0}Parameters", nDecoders), decoder.parameters);
|
||||
var settings = decoder.decoderSettings as CommandLineDecoderSettings;
|
||||
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);
|
||||
@@ -432,48 +417,82 @@ namespace CUETools.Processor
|
||||
|
||||
try
|
||||
{
|
||||
using (TextReader reader = new StringReader(sr.Load("Advanced")))
|
||||
advanced = CUEConfigAdvanced.serializer.Deserialize(reader) as CUEConfigAdvanced;
|
||||
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);
|
||||
}
|
||||
|
||||
int totalEncoders = sr.LoadInt32("ExternalEncoders", 0, null) ?? 0;
|
||||
for (int nEncoders = 0; nEncoders < totalEncoders; nEncoders++)
|
||||
var encodersBackup = encoders;
|
||||
try
|
||||
{
|
||||
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
|
||||
{
|
||||
using (TextReader reader = new StringReader(settings))
|
||||
encoder.settings = encoder.settingsSerializer.Deserialize(reader) as AudioEncoderSettings;
|
||||
if (encoder.settings is UserDefinedEncoderSettings && (encoder.settings as UserDefinedEncoderSettings).Path == "")
|
||||
throw new Exception();
|
||||
}
|
||||
catch
|
||||
{
|
||||
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);
|
||||
}
|
||||
var jsonObject = JsonConvert.DeserializeObject(sr.Load("Encoders"),
|
||||
typeof(CUEToolsUDCEncoderList),
|
||||
new JsonSerializerSettings {
|
||||
DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate,
|
||||
TypeNameHandling = TypeNameHandling.Auto
|
||||
});
|
||||
if (jsonObject as CUEToolsUDCEncoderList == null)
|
||||
throw new Exception();
|
||||
encoders = jsonObject as CUEToolsUDCEncoderList;
|
||||
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++)
|
||||
@@ -482,14 +501,14 @@ namespace CUETools.Processor
|
||||
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));
|
||||
CUEToolsUDC decoder;
|
||||
AudioDecoderSettingsViewModel decoder;
|
||||
if (!decoders.TryGetValue(extension, true, name, out decoder))
|
||||
decoders.Add(new CUEToolsUDC(name, extension, path, parameters));
|
||||
decoders.Add(new AudioDecoderSettingsViewModel(new CommandLineDecoderSettings(name, extension, path, parameters)));
|
||||
else
|
||||
{
|
||||
decoder.extension = extension;
|
||||
decoder.path = path;
|
||||
decoder.parameters = parameters;
|
||||
decoder.Extension = extension;
|
||||
decoder.Path = path;
|
||||
decoder.Parameters = parameters;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -505,7 +524,8 @@ namespace CUETools.Processor
|
||||
bool allowLossy = sr.LoadBoolean(string.Format("CustomFormat{0}AllowLossy", nFormats)) ?? false;
|
||||
bool allowEmbed = sr.LoadBoolean(string.Format("CustomFormat{0}AllowEmbed", nFormats)) ?? false;
|
||||
CUEToolsFormat format;
|
||||
CUEToolsUDC udcLossless, udcLossy, udcDecoder;
|
||||
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))
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace CUETools.Processor
|
||||
{
|
||||
@@ -39,7 +38,6 @@ namespace CUETools.Processor
|
||||
}
|
||||
}
|
||||
|
||||
internal static XmlSerializer serializer = new XmlSerializer(typeof(CUEConfigAdvanced));
|
||||
[DefaultValue("i"), Category("Freedb"), DisplayName("Email user")]
|
||||
public string FreedbUser { get; set; }
|
||||
|
||||
@@ -64,9 +62,9 @@ namespace CUETools.Processor
|
||||
[DefaultValue(true), Category("Tagging"), DisplayName("Cache metadata")]
|
||||
public bool CacheMetadata { get; set; }
|
||||
|
||||
[DefaultValue(new string[] { "folder.jpg", "cover.jpg", "albumart.jpg", "thumbnail.jpg", "albumartlarge.jpg", "front.jpg", "%album%.jpg" })]
|
||||
[DefaultValue("folder.jpg;cover.jpg;albumart.jpg;thumbnail.jpg;albumartlarge.jpg;front.jpg;%album%.jpg")]
|
||||
[Category("Cover Art"), DisplayName("Cover Art Files")]
|
||||
public string[] CoverArtFiles { get; set; }
|
||||
public string CoverArtFiles { get; set; }
|
||||
|
||||
[DefaultValue(true)]
|
||||
[Category("Cover Art"), DisplayName("Cover Art Extended Search")]
|
||||
|
||||
@@ -25,8 +25,8 @@ namespace CUETools.Processor
|
||||
arcp = new List<Type>();
|
||||
arcp_fmt = new List<string>();
|
||||
|
||||
encs.Add(typeof(CUETools.Codecs.WAVWriter));
|
||||
decs.Add(typeof(CUETools.Codecs.WAVReader));
|
||||
encs.Add(typeof(CUETools.Codecs.WAV.AudioEncoder));
|
||||
decs.Add(typeof(CUETools.Codecs.WAV.AudioDecoder));
|
||||
|
||||
//ApplicationSecurityInfo asi = new ApplicationSecurityInfo(AppDomain.CurrentDomain.ActivationContext);
|
||||
//string arch = asi.ApplicationId.ProcessorArchitecture;
|
||||
@@ -67,7 +67,7 @@ namespace CUETools.Processor
|
||||
{
|
||||
try
|
||||
{
|
||||
if (Attribute.GetCustomAttribute(type, typeof(AudioDecoderClass)) != null)
|
||||
if (Attribute.GetCustomAttribute(type, typeof(AudioDecoderClassAttribute)) != null)
|
||||
{
|
||||
decs.Add(type);
|
||||
}
|
||||
|
||||
@@ -2918,7 +2918,7 @@ namespace CUETools.Processor
|
||||
}
|
||||
if ((_config.extractAlbumArt || _config.embedAlbumArt) && !_isCD)
|
||||
{
|
||||
foreach (string tpl in _config.advanced.CoverArtFiles)
|
||||
foreach (string tpl in _config.advanced.CoverArtFiles.Split(';'))
|
||||
{
|
||||
string name = tpl.Replace("%album%", Metadata.Title).Replace("%artist%", Metadata.Artist);
|
||||
string imgPath = Path.Combine(_isArchive ? _archiveCUEpath : _inputDir, name);
|
||||
@@ -2939,7 +2939,7 @@ namespace CUETools.Processor
|
||||
{
|
||||
List<string> allfiles = new List<string>(Directory.GetFiles(_inputDir, "*.jpg", SearchOption.AllDirectories));
|
||||
// TODO: archive case
|
||||
foreach (string tpl in _config.advanced.CoverArtFiles)
|
||||
foreach (string tpl in _config.advanced.CoverArtFiles.Split(';'))
|
||||
{
|
||||
string name = tpl.Replace("%album%", Metadata.Title).Replace("%artist%", Metadata.Artist);
|
||||
List<string> matching = allfiles.FindAll(s => Path.GetFileName(s) == name);
|
||||
|
||||
@@ -22,6 +22,10 @@
|
||||
</ProjectReference>
|
||||
</ItemDefinitionGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="11.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CUETools.AccurateRip\CUETools.AccurateRip.csproj" />
|
||||
<ProjectReference Include="..\CUETools.CDImage\CUETools.CDImage.csproj" />
|
||||
|
||||
Reference in New Issue
Block a user