mirror of
https://github.com/claunia/cuetools.net.git
synced 2025-12-16 18:14:25 +00:00
More refactoring: UserDefinedWriter is now a more typical IAudioDest, that has it's own UserDefinedEncoderSettings
This commit is contained in:
@@ -90,9 +90,7 @@ namespace CUETools.Processor
|
||||
settings.PCM = pcm;
|
||||
settings.Padding = padding;
|
||||
settings.Validate();
|
||||
if (encoder.path != null)
|
||||
dest = new UserDefinedWriter(path, null, settings, encoder.path, encoder.parameters, encoder.EncoderMode, padding);
|
||||
else if (encoder.type != null)
|
||||
if (encoder.type != null)
|
||||
{
|
||||
object o = Activator.CreateInstance(encoder.type, path, settings);
|
||||
if (o == null || !(o is IAudioDest))
|
||||
|
||||
@@ -151,7 +151,7 @@ namespace CUETools.Processor
|
||||
|
||||
language = Thread.CurrentThread.CurrentUICulture.Name;
|
||||
|
||||
encoders = new CUEToolsUDCList();
|
||||
encoders = new CUEToolsUDCList(true);
|
||||
foreach (Type type in CUEProcessorPlugins.encs)
|
||||
foreach (AudioEncoderClassAttribute enc in Attribute.GetCustomAttributes(type, typeof(AudioEncoderClassAttribute)))
|
||||
{
|
||||
@@ -163,7 +163,7 @@ namespace CUETools.Processor
|
||||
{
|
||||
}
|
||||
}
|
||||
decoders = new CUEToolsUDCList();
|
||||
decoders = new CUEToolsUDCList(false);
|
||||
foreach (Type type in CUEProcessorPlugins.decs)
|
||||
foreach (AudioDecoderClass dec in Attribute.GetCustomAttributes(type, typeof(AudioDecoderClass)))
|
||||
decoders.Add(new CUEToolsUDC(dec, type));
|
||||
@@ -333,24 +333,11 @@ return processor.Go();
|
||||
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);
|
||||
if (encoder.path != null)
|
||||
using (TextWriter tw = new StringWriter())
|
||||
using (XmlWriter xw = XmlTextWriter.Create(tw, xmlEmptySettings))
|
||||
{
|
||||
sw.Save(string.Format("ExternalEncoder{0}Modes", nEncoders), encoder.SupportedModesStr);
|
||||
sw.Save(string.Format("ExternalEncoder{0}Mode", nEncoders), encoder.EncoderMode);
|
||||
sw.Save(string.Format("ExternalEncoder{0}Path", nEncoders), encoder.path);
|
||||
sw.Save(string.Format("ExternalEncoder{0}Parameters", nEncoders), encoder.parameters);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (encoder.settingsSerializer != null)
|
||||
{
|
||||
using (TextWriter tw = new StringWriter())
|
||||
using (XmlWriter xw = XmlTextWriter.Create(tw, xmlEmptySettings))
|
||||
{
|
||||
encoder.settingsSerializer.Serialize(xw, encoder.settings, xmlEmptyNamespaces);
|
||||
sw.SaveText(string.Format("ExternalEncoder{0}Parameters", nEncoders), tw.ToString());
|
||||
}
|
||||
}
|
||||
encoder.settingsSerializer.Serialize(xw, encoder.settings, xmlEmptyNamespaces);
|
||||
sw.SaveText(string.Format("ExternalEncoder{0}Settings", nEncoders), tw.ToString());
|
||||
}
|
||||
nEncoders++;
|
||||
}
|
||||
@@ -478,42 +465,22 @@ return processor.Go();
|
||||
{
|
||||
string name = sr.Load(string.Format("ExternalEncoder{0}Name", nEncoders));
|
||||
string extension = sr.Load(string.Format("ExternalEncoder{0}Extension", nEncoders));
|
||||
string path = sr.Load(string.Format("ExternalEncoder{0}Path", nEncoders));
|
||||
string parameters = sr.Load(string.Format("ExternalEncoder{0}Parameters", nEncoders));
|
||||
string settings = sr.Load(string.Format("ExternalEncoder{0}Settings", nEncoders));
|
||||
bool lossless = sr.LoadBoolean(string.Format("ExternalEncoder{0}Lossless", nEncoders)) ?? true;
|
||||
string supported_modes = sr.Load(string.Format("ExternalEncoder{0}Modes", nEncoders)) ?? "";
|
||||
string default_mode = sr.Load(string.Format("ExternalEncoder{0}Mode", nEncoders)) ?? "";
|
||||
CUEToolsUDC encoder;
|
||||
if (name == null) continue;
|
||||
if (name == null || extension == null) continue;
|
||||
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));
|
||||
encoder = new CUEToolsUDC(name, extension, lossless, "", "", "", "");
|
||||
encoders.Add(encoder);
|
||||
}
|
||||
else if (version == 203)
|
||||
try
|
||||
{
|
||||
using (TextReader reader = new StringReader(settings))
|
||||
encoder.settings = encoder.settingsSerializer.Deserialize(reader) as AudioEncoderSettings;
|
||||
}
|
||||
catch
|
||||
{
|
||||
if (encoder.path != null)
|
||||
{
|
||||
if (path == null || parameters == null || extension == null) continue;
|
||||
encoder.extension = extension;
|
||||
encoder.path = path;
|
||||
encoder.lossless = lossless;
|
||||
encoder.parameters = parameters;
|
||||
encoder.SupportedModesStr = supported_modes;
|
||||
encoder.EncoderMode = default_mode;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (encoder.settingsSerializer != null && parameters != "")
|
||||
try
|
||||
{
|
||||
using (TextReader reader = new StringReader(parameters))
|
||||
encoder.settings = encoder.settingsSerializer.Deserialize(reader) as AudioEncoderSettings;
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,9 +17,6 @@ namespace CUETools.Processor
|
||||
public bool lossless = false;
|
||||
public int priority = 0;
|
||||
|
||||
private string supported_modes = "";
|
||||
private string default_mode = "";
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
public CUEToolsUDC(
|
||||
@@ -35,12 +32,12 @@ namespace CUETools.Processor
|
||||
name = _name;
|
||||
extension = _extension;
|
||||
lossless = _lossless;
|
||||
supported_modes = _supported_modes;
|
||||
default_mode = _default_mode;
|
||||
priority = 0;
|
||||
path = _path;
|
||||
parameters = _parameters;
|
||||
type = null;
|
||||
path = null;
|
||||
parameters = null;
|
||||
type = typeof(UserDefinedWriter);
|
||||
settingsSerializer = new XmlSerializer(typeof(UserDefinedEncoderSettings));
|
||||
settings = new UserDefinedEncoderSettings() { SupportedModes = _supported_modes, DefaultMode = _default_mode, Path = _path, Parameters = _parameters };
|
||||
}
|
||||
|
||||
public CUEToolsUDC(AudioEncoderClassAttribute enc, Type enctype)
|
||||
@@ -50,15 +47,28 @@ namespace CUETools.Processor
|
||||
lossless = enc.Lossless;
|
||||
priority = enc.Priority;
|
||||
path = null;
|
||||
parameters = "";
|
||||
parameters = null;
|
||||
type = enctype;
|
||||
settingsSerializer = null;
|
||||
settings = null;
|
||||
if (enc.Settings != null && typeof(AudioEncoderSettings).IsAssignableFrom(enc.Settings))
|
||||
{
|
||||
settingsSerializer = new XmlSerializer(enc.Settings);
|
||||
settings = Activator.CreateInstance(enc.Settings) as AudioEncoderSettings;
|
||||
}
|
||||
settingsSerializer = new XmlSerializer(enc.Settings);
|
||||
settings = Activator.CreateInstance(enc.Settings) as AudioEncoderSettings;
|
||||
if (settings == null)
|
||||
throw new InvalidOperationException("invalid codec");
|
||||
}
|
||||
|
||||
public CUEToolsUDC(
|
||||
string _name,
|
||||
string _extension,
|
||||
string _path,
|
||||
string _parameters
|
||||
)
|
||||
{
|
||||
name = _name;
|
||||
extension = _extension;
|
||||
lossless = true;
|
||||
priority = 0;
|
||||
path = _path;
|
||||
parameters = _parameters;
|
||||
type = null;
|
||||
}
|
||||
|
||||
public CUEToolsUDC(AudioDecoderClass dec, Type dectype)
|
||||
@@ -89,13 +99,33 @@ namespace CUETools.Processor
|
||||
}
|
||||
public string Path
|
||||
{
|
||||
get { return path; }
|
||||
set { path = value; if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("Path")); }
|
||||
get
|
||||
{
|
||||
var settings = this.settings as UserDefinedEncoderSettings;
|
||||
return settings == null ? path : settings.Path;
|
||||
}
|
||||
set
|
||||
{
|
||||
var settings = this.settings as UserDefinedEncoderSettings;
|
||||
if (settings == null) path = value;
|
||||
else settings.Path = value;
|
||||
if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("Path"));
|
||||
}
|
||||
}
|
||||
public string Parameters
|
||||
{
|
||||
get { return parameters; }
|
||||
set { parameters = value; if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("Parameters")); }
|
||||
get
|
||||
{
|
||||
var settings = this.settings as UserDefinedEncoderSettings;
|
||||
return settings == null ? parameters : settings.Parameters;
|
||||
}
|
||||
set
|
||||
{
|
||||
var settings = this.settings as UserDefinedEncoderSettings;
|
||||
if (settings == null) parameters = value;
|
||||
else settings.Parameters = value;
|
||||
if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("Parameters"));
|
||||
}
|
||||
}
|
||||
public bool Lossless
|
||||
{
|
||||
@@ -119,26 +149,14 @@ namespace CUETools.Processor
|
||||
get
|
||||
{
|
||||
string defaultMode;
|
||||
return this.settings == null ? this.supported_modes : this.settings.GetSupportedModes(out defaultMode);
|
||||
return this.settings.GetSupportedModes(out defaultMode);
|
||||
}
|
||||
set
|
||||
{
|
||||
if (this.settings != null) throw new NotSupportedException();
|
||||
supported_modes = value; if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("SupportedModesStr"));
|
||||
}
|
||||
}
|
||||
|
||||
public string EncoderMode
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.settings != null) return this.settings.EncoderMode;
|
||||
else return this.default_mode;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (this.settings != null) this.settings.EncoderMode = value;
|
||||
else this.default_mode = value;
|
||||
var settings = this.settings as UserDefinedEncoderSettings;
|
||||
if (settings == null) throw new InvalidOperationException();
|
||||
settings.SupportedModes = value;
|
||||
if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("SupportedModesStr"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,7 +176,7 @@ namespace CUETools.Processor
|
||||
if (modes == null || modes.Length < 2)
|
||||
return -1;
|
||||
for (int i = 0; i < modes.Length; i++)
|
||||
if (modes[i] == this.EncoderMode)
|
||||
if (modes[i] == this.settings.EncoderMode)
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
@@ -168,7 +186,7 @@ namespace CUETools.Processor
|
||||
{
|
||||
get
|
||||
{
|
||||
return path != null;
|
||||
return type == null || type == typeof(UserDefinedWriter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,15 +5,20 @@ namespace CUETools.Processor
|
||||
{
|
||||
public class CUEToolsUDCList : BindingList<CUEToolsUDC>
|
||||
{
|
||||
public CUEToolsUDCList()
|
||||
bool m_encoder;
|
||||
|
||||
public CUEToolsUDCList(bool encoder)
|
||||
: base()
|
||||
{
|
||||
AddingNew += OnAddingNew;
|
||||
m_encoder = encoder;
|
||||
}
|
||||
|
||||
private void OnAddingNew(object sender, AddingNewEventArgs e)
|
||||
{
|
||||
e.NewObject = new CUEToolsUDC("new", "wav", true, "", "", "", "");
|
||||
e.NewObject = m_encoder ?
|
||||
new CUEToolsUDC("new", "wav", true, "", "", "", "") :
|
||||
new CUEToolsUDC("new", "wav", "", "");
|
||||
}
|
||||
|
||||
public bool TryGetValue(string extension, bool lossless, string name, out CUEToolsUDC result)
|
||||
|
||||
Reference in New Issue
Block a user