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

@@ -42,7 +42,7 @@ namespace CUETools.Codecs.ALAC
public bool DoVerify { get; set; }
}
[AudioEncoderClass("libALAC", "m4a", true, "0 1 2 3 4 5 6 7 8 9 10", "3", 1, typeof(ALACWriterSettings))]
[AudioEncoderClass("cuetools", "m4a", true, "0 1 2 3 4 5 6 7 8 9 10", "3", 1, typeof(ALACWriterSettings))]
public class ALACWriter : IAudioDest
{
Stream _IO = null;

View File

@@ -48,7 +48,7 @@ namespace CUETools.Codecs.FLAKE
public bool DoMD5 { get; set; }
}
[AudioEncoderClass("libFlake", "flac", true, "0 1 2 3 4 5 6 7 8 9 10 11", "7", 4, typeof(FlakeWriterSettings))]
[AudioEncoderClass("cuetools", "flac", true, "0 1 2 3 4 5 6 7 8 9 10 11", "7", 4, typeof(FlakeWriterSettings))]
//[AudioEncoderClass("libFlake nonsub", "flac", true, "9 10 11", "9", 3, typeof(FlakeWriterSettings))]
public class FlakeWriter : IAudioDest
{

View File

@@ -27,7 +27,7 @@ using System.Runtime.InteropServices;
namespace CUETools.Codecs.WMA
{
[AudioDecoderClass("builtin wma", "wma")]
[AudioDecoderClass("windows", "wma")]
public class WMAReader : IAudioSource
{
IWMSyncReader m_syncReader;

View File

@@ -4,7 +4,7 @@ using System.IO;
namespace CUETools.Codecs
{
[AudioEncoderClass("builtin wav", "wav", true, "", "", 10, typeof(object))]
[AudioEncoderClass("cuetools", "wav", true, "", "", 10, typeof(object))]
public class WAVWriter : IAudioDest
{
private Stream _IO;

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;
}
}
}
}

View File

@@ -384,12 +384,12 @@ namespace JDP
break;
}
}
List<string> encodersToRemove = new List<string>();
foreach (CUEToolsUDC encoder in _config.encoders)
var encodersToRemove = new List<CUEToolsUDC>();
foreach (var encoder in _config.encoders)
if (encoder.extension == format.extension)
encodersToRemove.Add(encoder.name);
foreach (string encoder in encodersToRemove)
_config.encoders.Remove(_config.encoders[encoder]);
encodersToRemove.Add(encoder);
foreach (var encoder in encodersToRemove)
_config.encoders.Remove(encoder);
comboBoxEncoderExtension.Items.Remove(format.extension);
comboBoxDecoderExtension.Items.Remove(format.extension);
_config.formats.Remove(format.extension);
@@ -424,7 +424,7 @@ namespace JDP
comboFormatDecoder.Items.Clear();
foreach (KeyValuePair<string, CUEToolsUDC> decoder in _config.decoders)
if (decoder.Value.extension == format.extension)
comboFormatDecoder.Items.Add(decoder.Key);
comboFormatDecoder.Items.Add(decoder.Value);
comboFormatDecoder.SelectedItem = format.decoder;
comboFormatDecoder.Enabled = format.allowLossless;
@@ -454,7 +454,7 @@ namespace JDP
format.encoderLossless = (CUEToolsUDC)comboFormatLosslessEncoder.SelectedItem;
format.encoderLossy = (CUEToolsUDC)comboFormatLossyEncoder.SelectedItem;
format.decoder = (string)comboFormatDecoder.SelectedItem;
format.decoder = (CUEToolsUDC)comboFormatDecoder.SelectedItem;
if (!format.builtin)
{
format.tagger = (CUEToolsTagger)comboBoxFormatTagger.SelectedItem;
@@ -565,7 +565,7 @@ namespace JDP
if (listViewFormats.SelectedItems.Count > 0)
listViewFormats.SelectedItems[0].Selected = false;
CUEToolsFormat format;
if (_config.formats.TryGetValue(decoder.extension, out format) && format.decoder == decoder.name)
if (_config.formats.TryGetValue(decoder.extension, out format) && format.decoder == decoder)
format.decoder = null;
decoder.extension = (string)comboBoxDecoderExtension.SelectedItem;
}
@@ -588,8 +588,6 @@ namespace JDP
decoder = (CUEToolsUDC)listViewDecoders.Items[e.Item].Tag;
if (listViewFormats.SelectedItems.Count > 0)
listViewFormats.SelectedItems[0].Selected = false;
if (_config.formats[decoder.extension].decoder == decoder.name)
_config.formats[decoder.extension].decoder = e.Label;
_config.decoders.Remove(decoder.name);
decoder.name = e.Label;
_config.decoders.Add(decoder.name, decoder);
@@ -626,7 +624,7 @@ namespace JDP
CUEToolsUDC decoder = (CUEToolsUDC)listViewDecoders.SelectedItems[0].Tag;
if (decoder.path == null)
return;
if (_config.formats[decoder.extension].decoder == decoder.name)
if (_config.formats[decoder.extension].decoder == decoder)
_config.formats[decoder.extension].decoder = null;
_config.decoders.Remove(decoder.name);
listViewDecoders.Items.Remove(listViewDecoders.SelectedItems[0]);