mirror of
https://github.com/claunia/cuetools.net.git
synced 2025-12-16 18:14:25 +00:00
Code cleanup: some lowlevel codec infrastructure moved
from CUETools.Processor to CUETools.Codecs
This commit is contained in:
@@ -74,6 +74,10 @@
|
||||
<Compile Include="CRC\CRC16CCITT.cs" />
|
||||
<Compile Include="CRC\CRC32.cs" />
|
||||
<Compile Include="CRC\CRC8.cs" />
|
||||
<Compile Include="CUEToolsFormat.cs" />
|
||||
<Compile Include="CUEToolsTagger.cs" />
|
||||
<Compile Include="CUEToolsUDC.cs" />
|
||||
<Compile Include="CUEToolsUDCList.cs" />
|
||||
<Compile Include="CyclicBuffer.cs" />
|
||||
<Compile Include="CyclicBufferInputStream.cs" />
|
||||
<Compile Include="CyclicBufferOutputStream.cs" />
|
||||
|
||||
44
CUETools.Codecs/CUEToolsFormat.cs
Normal file
44
CUETools.Codecs/CUEToolsFormat.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
namespace CUETools.Codecs
|
||||
{
|
||||
public class CUEToolsFormat
|
||||
{
|
||||
public CUEToolsFormat(
|
||||
string _extension,
|
||||
CUEToolsTagger _tagger,
|
||||
bool _allowLossless,
|
||||
bool _allowLossy,
|
||||
bool _allowEmbed,
|
||||
bool _builtin,
|
||||
CUEToolsUDC _encoderLossless,
|
||||
CUEToolsUDC _encoderLossy,
|
||||
CUEToolsUDC _decoder)
|
||||
{
|
||||
extension = _extension;
|
||||
tagger = _tagger;
|
||||
allowLossless = _allowLossless;
|
||||
allowLossy = _allowLossy;
|
||||
allowEmbed = _allowEmbed;
|
||||
builtin = _builtin;
|
||||
encoderLossless = _encoderLossless;
|
||||
encoderLossy = _encoderLossy;
|
||||
decoder = _decoder;
|
||||
}
|
||||
public string DotExtension
|
||||
{
|
||||
get
|
||||
{
|
||||
return "." + extension;
|
||||
}
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
return extension;
|
||||
}
|
||||
public string extension;
|
||||
public CUEToolsUDC encoderLossless;
|
||||
public CUEToolsUDC encoderLossy;
|
||||
public CUEToolsUDC decoder;
|
||||
public CUEToolsTagger tagger;
|
||||
public bool allowLossless, allowLossy, allowEmbed, builtin;
|
||||
}
|
||||
}
|
||||
9
CUETools.Codecs/CUEToolsTagger.cs
Normal file
9
CUETools.Codecs/CUEToolsTagger.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace CUETools.Codecs
|
||||
{
|
||||
public enum CUEToolsTagger
|
||||
{
|
||||
TagLibSharp = 0,
|
||||
APEv2 = 1,
|
||||
ID3v2 = 2,
|
||||
}
|
||||
}
|
||||
198
CUETools.Codecs/CUEToolsUDC.cs
Normal file
198
CUETools.Codecs/CUEToolsUDC.cs
Normal file
@@ -0,0 +1,198 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace CUETools.Codecs
|
||||
{
|
||||
public class CUEToolsUDC : INotifyPropertyChanged
|
||||
{
|
||||
public string name = "";
|
||||
public string extension = "wav";
|
||||
public string path = "";
|
||||
public string parameters = "";
|
||||
public Type type = null;
|
||||
public AudioEncoderSettings settings = null;
|
||||
public XmlSerializer settingsSerializer = null;
|
||||
public bool lossless = false;
|
||||
public int priority = 0;
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
public CUEToolsUDC(
|
||||
string _name,
|
||||
string _extension,
|
||||
bool _lossless,
|
||||
string _supported_modes,
|
||||
string _default_mode,
|
||||
string _path,
|
||||
string _parameters
|
||||
)
|
||||
{
|
||||
name = _name;
|
||||
extension = _extension;
|
||||
lossless = _lossless;
|
||||
priority = 0;
|
||||
path = null;
|
||||
parameters = null;
|
||||
type = typeof(UserDefinedWriter);
|
||||
settingsSerializer = new XmlSerializer(typeof(UserDefinedEncoderSettings));
|
||||
settings = new UserDefinedEncoderSettings() { SupportedModes = _supported_modes, EncoderMode = _default_mode, Path = _path, Parameters = _parameters };
|
||||
}
|
||||
|
||||
public CUEToolsUDC(AudioEncoderClassAttribute enc, Type enctype)
|
||||
{
|
||||
name = enc.EncoderName;
|
||||
extension = enc.Extension;
|
||||
lossless = enc.Lossless;
|
||||
priority = enc.Priority;
|
||||
path = null;
|
||||
parameters = null;
|
||||
type = enctype;
|
||||
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)
|
||||
{
|
||||
name = dec.DecoderName;
|
||||
extension = dec.Extension;
|
||||
lossless = true;
|
||||
priority = dec.Priority;
|
||||
path = null;
|
||||
parameters = null;
|
||||
type = dectype;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return name; }
|
||||
set { if (name == value) return; name = value; if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("Name")); }
|
||||
}
|
||||
public string FullName
|
||||
{
|
||||
get { return name + " [" + extension + "]"; }
|
||||
//set { name = value; if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("Name")); }
|
||||
}
|
||||
public string 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
|
||||
{
|
||||
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
|
||||
{
|
||||
get { return lossless; }
|
||||
set { lossless = value; if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("Lossless")); }
|
||||
}
|
||||
|
||||
public string Extension
|
||||
{
|
||||
get { return extension; }
|
||||
set
|
||||
{
|
||||
if (extension == value) return;
|
||||
if (type != null && type != typeof(UserDefinedWriter)) throw new InvalidOperationException();
|
||||
extension = value;
|
||||
if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("Extension"));
|
||||
}
|
||||
}
|
||||
|
||||
public string DotExtension
|
||||
{
|
||||
get { return "." + extension; }
|
||||
}
|
||||
|
||||
public string SupportedModesStr
|
||||
{
|
||||
get
|
||||
{
|
||||
string defaultMode;
|
||||
return this.settings.GetSupportedModes(out defaultMode);
|
||||
}
|
||||
set
|
||||
{
|
||||
var settings = this.settings as UserDefinedEncoderSettings;
|
||||
if (settings == null) throw new InvalidOperationException();
|
||||
settings.SupportedModes = value;
|
||||
if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("SupportedModesStr"));
|
||||
}
|
||||
}
|
||||
|
||||
public string[] SupportedModes
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.SupportedModesStr.Split(' ');
|
||||
}
|
||||
}
|
||||
|
||||
public int EncoderModeIndex
|
||||
{
|
||||
get
|
||||
{
|
||||
string[] modes = this.SupportedModes;
|
||||
if (modes == null || modes.Length < 2)
|
||||
return -1;
|
||||
for (int i = 0; i < modes.Length; i++)
|
||||
if (modes[i] == this.settings.EncoderMode)
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public bool CanBeDeleted
|
||||
{
|
||||
get
|
||||
{
|
||||
return type == null || type == typeof(UserDefinedWriter);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
51
CUETools.Codecs/CUEToolsUDCList.cs
Normal file
51
CUETools.Codecs/CUEToolsUDCList.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace CUETools.Codecs
|
||||
{
|
||||
public class CUEToolsUDCList : BindingList<CUEToolsUDC>
|
||||
{
|
||||
bool m_encoder;
|
||||
|
||||
public CUEToolsUDCList(bool encoder)
|
||||
: base()
|
||||
{
|
||||
AddingNew += OnAddingNew;
|
||||
m_encoder = encoder;
|
||||
}
|
||||
|
||||
private void OnAddingNew(object sender, AddingNewEventArgs e)
|
||||
{
|
||||
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)
|
||||
{
|
||||
foreach (CUEToolsUDC udc in this)
|
||||
{
|
||||
if (udc.extension == extension && udc.lossless == lossless && udc.name == name)
|
||||
{
|
||||
result = udc;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
result = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
public CUEToolsUDC GetDefault(string extension, bool lossless)
|
||||
{
|
||||
CUEToolsUDC result = null;
|
||||
foreach (CUEToolsUDC udc in this)
|
||||
{
|
||||
if (udc.extension == extension && udc.lossless == lossless && (result == null || result.priority < udc.priority))
|
||||
{
|
||||
result = udc;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user