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:
@@ -1012,11 +1012,11 @@ namespace CUERipper
|
||||
{
|
||||
string defaultMode;
|
||||
encoder.settings.GetSupportedModes(out defaultMode);
|
||||
encoder.EncoderMode = defaultMode;
|
||||
encoder.settings.EncoderMode = defaultMode;
|
||||
}
|
||||
trackBarEncoderMode.Maximum = modes.Length - 1;
|
||||
trackBarEncoderMode.Value = encoder.EncoderModeIndex == -1 ? modes.Length - 1 : encoder.EncoderModeIndex;
|
||||
labelEncoderMode.Text = encoder.EncoderMode;
|
||||
labelEncoderMode.Text = encoder.settings.EncoderMode;
|
||||
labelEncoderMinMode.Text = modes[0];
|
||||
labelEncoderMaxMode.Text = modes[modes.Length - 1];
|
||||
trackBarEncoderMode.Visible = true;
|
||||
@@ -1044,8 +1044,8 @@ namespace CUERipper
|
||||
{
|
||||
CUEToolsUDC encoder = bnComboBoxEncoder.SelectedItem as CUEToolsUDC;
|
||||
string[] modes = encoder.SupportedModes;
|
||||
encoder.EncoderMode = modes[trackBarEncoderMode.Value];
|
||||
labelEncoderMode.Text = encoder.EncoderMode;
|
||||
encoder.settings.EncoderMode = modes[trackBarEncoderMode.Value];
|
||||
labelEncoderMode.Text = encoder.settings.EncoderMode;
|
||||
}
|
||||
|
||||
private void trackBarSecureMode_Scroll(object sender, EventArgs e)
|
||||
|
||||
@@ -12,6 +12,20 @@ namespace CUETools.Codecs
|
||||
{
|
||||
}
|
||||
|
||||
[DefaultValue(null)]
|
||||
public string Path
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[DefaultValue(null)]
|
||||
public string Parameters
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public string SupportedModes
|
||||
{
|
||||
get
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace CUETools.Codecs
|
||||
{
|
||||
public class UserDefinedWriter : IAudioDest
|
||||
{
|
||||
string _path, _encoder, _encoderParams, _encoderMode;
|
||||
string _path;
|
||||
Process _encoderProcess;
|
||||
WAVWriter wrt;
|
||||
CyclicBuffer outputBuffer = null;
|
||||
@@ -14,7 +14,7 @@ namespace CUETools.Codecs
|
||||
string tempFile = null;
|
||||
long _finalSampleCount = -1;
|
||||
bool closed = false;
|
||||
private AudioEncoderSettings m_settings;
|
||||
private UserDefinedEncoderSettings m_settings;
|
||||
|
||||
public long Position
|
||||
{
|
||||
@@ -40,24 +40,26 @@ namespace CUETools.Codecs
|
||||
|
||||
public string Path { get { return _path; } }
|
||||
|
||||
public UserDefinedWriter(string path, Stream IO, AudioEncoderSettings settings, string encoder, string encoderParams, string encoderMode, int padding)
|
||||
public UserDefinedWriter(string path, UserDefinedEncoderSettings settings)
|
||||
: this(path, null, settings)
|
||||
{
|
||||
m_settings = settings as AudioEncoderSettings;
|
||||
}
|
||||
|
||||
public UserDefinedWriter(string path, Stream IO, UserDefinedEncoderSettings settings)
|
||||
{
|
||||
m_settings = settings;
|
||||
_path = path;
|
||||
_encoder = encoder;
|
||||
_encoderParams = encoderParams;
|
||||
_encoderMode = encoderMode;
|
||||
useTempFile = _encoderParams.Contains("%I");
|
||||
useTempFile = m_settings.Parameters.Contains("%I");
|
||||
tempFile = path + ".tmp.wav";
|
||||
|
||||
_encoderProcess = new Process();
|
||||
_encoderProcess.StartInfo.FileName = _encoder;
|
||||
_encoderProcess.StartInfo.Arguments = _encoderParams.Replace("%O", "\"" + path + "\"").Replace("%M", encoderMode).Replace("%P", padding.ToString()).Replace("%I", "\"" + tempFile + "\"");
|
||||
_encoderProcess.StartInfo.FileName = m_settings.Path;
|
||||
_encoderProcess.StartInfo.Arguments = m_settings.Parameters.Replace("%O", "\"" + path + "\"").Replace("%M", m_settings.EncoderMode).Replace("%P", m_settings.Padding.ToString()).Replace("%I", "\"" + tempFile + "\"");
|
||||
_encoderProcess.StartInfo.CreateNoWindow = true;
|
||||
if (!useTempFile)
|
||||
_encoderProcess.StartInfo.RedirectStandardInput = true;
|
||||
_encoderProcess.StartInfo.UseShellExecute = false;
|
||||
if (!_encoderParams.Contains("%O"))
|
||||
if (!m_settings.Parameters.Contains("%O"))
|
||||
_encoderProcess.StartInfo.RedirectStandardOutput = true;
|
||||
if (useTempFile)
|
||||
{
|
||||
@@ -77,7 +79,7 @@ namespace CUETools.Codecs
|
||||
ex = _ex;
|
||||
}
|
||||
if (!started)
|
||||
throw new Exception(_encoder + ": " + (ex == null ? "please check the path" : ex.Message));
|
||||
throw new Exception(m_settings.Path + ": " + (ex == null ? "please check the path" : ex.Message));
|
||||
if (_encoderProcess.StartInfo.RedirectStandardOutput)
|
||||
{
|
||||
Stream outputStream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read);
|
||||
@@ -108,7 +110,7 @@ namespace CUETools.Codecs
|
||||
ex = _ex;
|
||||
}
|
||||
if (!started)
|
||||
throw new Exception(_encoder + ": " + (ex == null ? "please check the path" : ex.Message));
|
||||
throw new Exception(m_settings.Path + ": " + (ex == null ? "please check the path" : ex.Message));
|
||||
}
|
||||
wrt = null;
|
||||
if (!_encoderProcess.HasExited)
|
||||
@@ -118,7 +120,7 @@ namespace CUETools.Codecs
|
||||
if (outputBuffer != null)
|
||||
outputBuffer.Close();
|
||||
if (_encoderProcess.ExitCode != 0)
|
||||
throw new Exception(String.Format("{0} returned error code {1}", _encoder, _encoderProcess.ExitCode));
|
||||
throw new Exception(String.Format("{0} returned error code {1}", m_settings.Path, _encoderProcess.ExitCode));
|
||||
}
|
||||
|
||||
public void Delete()
|
||||
@@ -136,7 +138,7 @@ namespace CUETools.Codecs
|
||||
catch (IOException ex)
|
||||
{
|
||||
if (_encoderProcess.HasExited)
|
||||
throw new IOException(string.Format("{0} has exited prematurely with code {1}", _encoder, _encoderProcess.ExitCode), ex);
|
||||
throw new IOException(string.Format("{0} has exited prematurely with code {1}", m_settings.Path, _encoderProcess.ExitCode), ex);
|
||||
else
|
||||
throw ex;
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
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());
|
||||
}
|
||||
}
|
||||
sw.SaveText(string.Format("ExternalEncoder{0}Settings", nEncoders), tw.ToString());
|
||||
}
|
||||
nEncoders++;
|
||||
}
|
||||
@@ -478,44 +465,24 @@ 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)
|
||||
{
|
||||
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))
|
||||
using (TextReader reader = new StringReader(settings))
|
||||
encoder.settings = encoder.settingsSerializer.Deserialize(reader) as AudioEncoderSettings;
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int totalDecoders = sr.LoadInt32("ExternalDecoders", 0, null) ?? 0;
|
||||
for (int nDecoders = 0; nDecoders < totalDecoders; nDecoders++)
|
||||
|
||||
@@ -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;
|
||||
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)
|
||||
|
||||
@@ -2469,11 +2469,11 @@ namespace JDP
|
||||
{
|
||||
string defaultMode;
|
||||
encoder.settings.GetSupportedModes(out defaultMode);
|
||||
encoder.EncoderMode = defaultMode;
|
||||
encoder.settings.EncoderMode = defaultMode;
|
||||
}
|
||||
trackBarEncoderMode.Maximum = modes.Length - 1;
|
||||
trackBarEncoderMode.Value = encoder.EncoderModeIndex == -1 ? modes.Length - 1 : encoder.EncoderModeIndex;
|
||||
labelEncoderMode.Text = encoder.EncoderMode;
|
||||
labelEncoderMode.Text = encoder.settings.EncoderMode;
|
||||
labelEncoderMinMode.Text = modes[0];
|
||||
labelEncoderMaxMode.Text = modes[modes.Length - 1];
|
||||
trackBarEncoderMode.Visible = true;
|
||||
@@ -2487,8 +2487,8 @@ namespace JDP
|
||||
{
|
||||
CUEToolsUDC encoder = comboBoxEncoder.SelectedItem as CUEToolsUDC;
|
||||
string[] modes = encoder.SupportedModes;
|
||||
encoder.EncoderMode = modes[trackBarEncoderMode.Value];
|
||||
labelEncoderMode.Text = encoder.EncoderMode;
|
||||
encoder.settings.EncoderMode = modes[trackBarEncoderMode.Value];
|
||||
labelEncoderMode.Text = encoder.settings.EncoderMode;
|
||||
}
|
||||
|
||||
//private void toolStripButton1_Click(object sender, EventArgs e)
|
||||
|
||||
@@ -471,21 +471,13 @@ namespace JDP
|
||||
CUEToolsFormat format = _config.formats[encoder.extension]; // _config.formats.TryGetValue(encoder.extension, out format)
|
||||
labelEncoderExtension.Visible = true;
|
||||
comboBoxEncoderExtension.Visible = true;
|
||||
comboBoxEncoderExtension.Enabled = encoder.path != null;
|
||||
groupBoxExternalEncoder.Visible = encoder.path != null;
|
||||
comboBoxEncoderExtension.Enabled = encoder.CanBeDeleted;
|
||||
groupBoxExternalEncoder.Visible = encoder.CanBeDeleted;
|
||||
checkBoxEncoderLossless.Enabled = format != null && format.allowLossless && format.allowLossy;
|
||||
propertyGridEncoderSettings.Visible = !encoder.CanBeDeleted;
|
||||
propertyGridEncoderSettings.SelectedObject = encoder.CanBeDeleted ? null : encoder.settings;
|
||||
if (!checkBoxEncoderLossless.Enabled && format != null && encoder.Lossless != format.allowLossless)
|
||||
encoder.Lossless = format.allowLossless;
|
||||
if (encoder.settingsSerializer != null)
|
||||
{
|
||||
propertyGridEncoderSettings.Visible = encoder != null && encoder.settingsSerializer != null;
|
||||
propertyGridEncoderSettings.SelectedObject = encoder.settings;
|
||||
}
|
||||
else
|
||||
{
|
||||
propertyGridEncoderSettings.Visible = false;
|
||||
propertyGridEncoderSettings.SelectedObject = null;
|
||||
}
|
||||
foreach (KeyValuePair<string, CUEToolsFormat> fmtEntry in _config.formats)
|
||||
{
|
||||
CUEToolsFormat fmt = fmtEntry.Value;
|
||||
|
||||
Reference in New Issue
Block a user