Allow encoders of different formats to share the same name; Rename "libALAC", "libFlake" and "builtin wav" encoders to "cuetools"

This commit is contained in:
Grigory Chudov
2013-03-31 01:11:00 -04:00
parent f3dfb02b60
commit 1b7e9bf123
9 changed files with 38 additions and 57 deletions

View File

@@ -24,19 +24,18 @@ namespace CUETools.Processor
CUEToolsFormat fmt;
if (!extension.StartsWith(".") || !config.formats.TryGetValue(extension.Substring(1), out fmt))
throw new Exception("Unsupported audio type: " + path);
CUEToolsUDC decoder;
if (fmt.decoder == null || !config.decoders.TryGetValue(fmt.decoder, out decoder))
if (fmt.decoder == null)
throw new Exception("Unsupported audio type: " + path);
if (decoder.path != null)
return new UserDefinedReader(path, IO, decoder.path, decoder.parameters);
if (decoder.type == null)
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
{
object src = Activator.CreateInstance(decoder.type, path, IO);
object src = Activator.CreateInstance(fmt.decoder.type, path, IO);
if (src == null || !(src is IAudioSource))
throw new Exception("Unsupported audio type: " + path + ": " + decoder.type.FullName);
throw new Exception("Unsupported audio type: " + path + ": " + fmt.decoder.type.FullName);
return src as IAudioSource;
}
catch (System.Reflection.TargetInvocationException ex)

View File

@@ -185,8 +185,8 @@ namespace CUETools.Processor
formats.Add("tta", new CUEToolsFormat("tta", CUEToolsTagger.APEv2, true, false, false, false, true, encoders.GetDefault("tta", true), null, GetDefaultDecoder("tta")));
formats.Add("wav", new CUEToolsFormat("wav", CUEToolsTagger.TagLibSharp, true, false, true, false, true, encoders.GetDefault("wav", true), null, GetDefaultDecoder("wav")));
formats.Add("m4a", new CUEToolsFormat("m4a", CUEToolsTagger.TagLibSharp, true, true, false, false, true, encoders.GetDefault("m4a", true), encoders.GetDefault("m4a", false), GetDefaultDecoder("m4a")));
formats.Add("tak", new CUEToolsFormat("tak", CUEToolsTagger.APEv2, true, false, true, true, true, encoders.GetDefault("tak", true), null, "takc"));
formats.Add("wma", new CUEToolsFormat("wma", CUEToolsTagger.TagLibSharp, true, true, false, false, true, encoders.GetDefault("wma", true), null, "builtin wma"));
formats.Add("tak", new CUEToolsFormat("tak", CUEToolsTagger.APEv2, true, false, true, true, true, encoders.GetDefault("tak", true), null, GetDefaultDecoder("tak")));
formats.Add("wma", new CUEToolsFormat("wma", CUEToolsTagger.TagLibSharp, true, true, false, false, true, encoders.GetDefault("wma", true), null, GetDefaultDecoder("wma")));
formats.Add("mp3", new CUEToolsFormat("mp3", CUEToolsTagger.TagLibSharp, false, true, false, false, true, null, encoders.GetDefault("mp3", false), null));
formats.Add("ogg", new CUEToolsFormat("ogg", CUEToolsTagger.TagLibSharp, false, true, false, false, true, null, encoders.GetDefault("ogg", false), null));
@@ -366,7 +366,7 @@ return processor.Go();
sw.Save(string.Format("CustomFormat{0}Name", nFormats), format.Key);
sw.Save(string.Format("CustomFormat{0}EncoderLossless", nFormats), format.Value.encoderLossless == null ? "" : format.Value.encoderLossless.Name);
sw.Save(string.Format("CustomFormat{0}EncoderLossy", nFormats), format.Value.encoderLossy == null ? "" : format.Value.encoderLossy.Name);
sw.Save(string.Format("CustomFormat{0}Decoder", nFormats), format.Value.decoder);
sw.Save(string.Format("CustomFormat{0}Decoder", nFormats), format.Value.decoder == null ? "" : format.Value.decoder.Name);
sw.Save(string.Format("CustomFormat{0}Tagger", nFormats), (int)format.Value.tagger);
sw.Save(string.Format("CustomFormat{0}AllowLossless", nFormats), format.Value.allowLossless);
sw.Save(string.Format("CustomFormat{0}AllowLossy", nFormats), format.Value.allowLossy);
@@ -477,7 +477,7 @@ return processor.Go();
string default_mode = sr.Load(string.Format("ExternalEncoder{0}Mode", nEncoders)) ?? "";
CUEToolsUDC encoder;
if (name == null) continue;
if (!encoders.TryGetValue(name, out encoder))
if (!encoders.TryGetValue(extension, lossless, name, out encoder))
{
if (path == null || parameters == null || extension == null) continue;
encoders.Add(new CUEToolsUDC(name, extension, lossless, supported_modes, default_mode, path, parameters));
@@ -540,18 +540,20 @@ return processor.Go();
bool allowLossyWav = sr.LoadBoolean(string.Format("CustomFormat{0}AllowLossyWAV", nFormats)) ?? false;
bool allowEmbed = sr.LoadBoolean(string.Format("CustomFormat{0}AllowEmbed", nFormats)) ?? false;
CUEToolsFormat format;
CUEToolsUDC udcLossless, udcLossy;
if (encoderLossless == "" || !encoders.TryGetValue(encoderLossless, out udcLossless))
CUEToolsUDC udcLossless, udcLossy, udcDecoder;
if (encoderLossless == "" || !encoders.TryGetValue(extension, true, encoderLossless, out udcLossless))
udcLossless = encoders.GetDefault(extension, true);
if (encoderLossy == "" || !encoders.TryGetValue(encoderLossy, out udcLossy))
if (encoderLossy == "" || !encoders.TryGetValue(extension, false, encoderLossy, out udcLossy))
udcLossy = encoders.GetDefault(extension, false);
if (decoder == "" || !decoders.TryGetValue(decoder, out udcDecoder))
udcDecoder = GetDefaultDecoder(extension);
if (!formats.TryGetValue(extension, out format))
formats.Add(extension, new CUEToolsFormat(extension, tagger, allowLossless, allowLossy, allowLossyWav, allowEmbed, false, udcLossless, udcLossy, decoder));
formats.Add(extension, new CUEToolsFormat(extension, tagger, allowLossless, allowLossy, allowLossyWav, allowEmbed, false, udcLossless, udcLossy, udcDecoder));
else
{
format.encoderLossless = udcLossless;
format.encoderLossy = udcLossy;
format.decoder = decoder;
format.decoder = udcDecoder;
if (!format.builtin)
{
format.tagger = tagger;
@@ -603,13 +605,14 @@ return processor.Go();
trackFilenameFormat = "%tracknumber%. %title%";
}
public string GetDefaultDecoder(string extension)
public CUEToolsUDC GetDefaultDecoder(string extension)
{
//|| !config.decoders.TryGetValue(fmt.decoder, out decoder)
CUEToolsUDC result = null;
foreach (KeyValuePair<string, CUEToolsUDC> decoder in decoders)
if (decoder.Value.Extension == extension && (result == null || result.priority < decoder.Value.priority))
result = decoder.Value;
return result == null ? null : result.Name;
return result;
}
public IWebProxy GetProxy()

View File

@@ -12,7 +12,7 @@
bool _builtin,
CUEToolsUDC _encoderLossless,
CUEToolsUDC _encoderLossy,
string _decoder)
CUEToolsUDC _decoder)
{
extension = _extension;
tagger = _tagger;
@@ -39,7 +39,7 @@
public string extension;
public CUEToolsUDC encoderLossless;
public CUEToolsUDC encoderLossy;
public string decoder;
public CUEToolsUDC decoder;
public CUEToolsTagger tagger;
public bool allowLossless, allowLossy, allowLossyWAV, allowEmbed, builtin;
}

View File

@@ -13,20 +13,14 @@ namespace CUETools.Processor
private void OnAddingNew(object sender, AddingNewEventArgs e)
{
string name = "new";
CUEToolsUDC temp;
while (TryGetValue(name, out temp))
{
name += "(1)";
}
e.NewObject = new CUEToolsUDC(name, "wav", true, "", "", "", "");
e.NewObject = new CUEToolsUDC("new", "wav", true, "", "", "", "");
}
public bool TryGetValue(string name, out CUEToolsUDC result)
public bool TryGetValue(string extension, bool lossless, string name, out CUEToolsUDC result)
{
foreach (CUEToolsUDC udc in this)
{
if (udc.name == name)
if (udc.extension == extension && udc.lossless == lossless && udc.name == name)
{
result = udc;
return true;
@@ -48,18 +42,5 @@ namespace CUETools.Processor
}
return result;
}
public CUEToolsUDC this[string name]
{
get
{
CUEToolsUDC udc;
if (!TryGetValue(name, out udc))
{
throw new Exception("CUEToolsUDCList: member not found");
}
return udc;
}
}
}
}