mirror of
https://github.com/claunia/cuetools.net.git
synced 2025-12-16 18:14:25 +00:00
Code cleanup; Reader classes renamed to Decoders, Writers to Encoders, every Decoder must have a corresponding Settings class now just like Encoders. UserDefinedEncoders renamed to CommandLineEncoders, etc.
This commit is contained in:
@@ -12,15 +12,15 @@ namespace CUETools.Codecs
|
||||
public class CUEToolsCodecsConfig
|
||||
{
|
||||
public Dictionary<string, CUEToolsFormat> formats;
|
||||
public CUEToolsUDCEncoderList encoders;
|
||||
public CUEToolsUDCDecoderList decoders;
|
||||
public EncoderListViewModel encoders;
|
||||
public DecoderListViewModel decoders;
|
||||
|
||||
public CUEToolsCodecsConfig(CUEToolsCodecsConfig src)
|
||||
{
|
||||
encoders = new CUEToolsUDCEncoderList();
|
||||
encoders = new EncoderListViewModel();
|
||||
foreach (var enc in src.encoders)
|
||||
encoders.Add(enc.Clone());
|
||||
decoders = new CUEToolsUDCDecoderList();
|
||||
decoders = new DecoderListViewModel();
|
||||
foreach (var dec in src.decoders)
|
||||
decoders.Add(dec.Clone());
|
||||
formats = new Dictionary<string, CUEToolsFormat>();
|
||||
@@ -30,7 +30,7 @@ namespace CUETools.Codecs
|
||||
|
||||
public CUEToolsCodecsConfig(List<Type> encs, List<Type> decs)
|
||||
{
|
||||
encoders = new CUEToolsUDCEncoderList();
|
||||
encoders = new EncoderListViewModel();
|
||||
foreach (Type type in encs)
|
||||
foreach (AudioEncoderClassAttribute enc in Attribute.GetCustomAttributes(type, typeof(AudioEncoderClassAttribute)))
|
||||
try
|
||||
@@ -42,7 +42,7 @@ namespace CUETools.Codecs
|
||||
System.Diagnostics.Trace.WriteLine(ex.Message);
|
||||
}
|
||||
|
||||
decoders = new CUEToolsUDCDecoderList();
|
||||
decoders = new DecoderListViewModel();
|
||||
foreach (Type type in decs)
|
||||
foreach (AudioDecoderClassAttribute dec in Attribute.GetCustomAttributes(type, typeof(AudioDecoderClassAttribute)))
|
||||
try
|
||||
@@ -66,8 +66,8 @@ namespace CUETools.Codecs
|
||||
encoders.Add(new AudioEncoderSettingsViewModel("nero aac", "m4a", false, "0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9", "0.4", "neroAacEnc.exe", "-q %M -if - -of %O"));
|
||||
encoders.Add(new AudioEncoderSettingsViewModel("qaac tvbr", "m4a", false, "10 20 30 40 50 60 70 80 90 100 110 127", "80", "qaac.exe", "-s -V %M -q 2 - -o %O"));
|
||||
|
||||
decoders.Add(new AudioDecoderSettingsViewModel(new CommandLineDecoderSettings("takc", "tak", "takc.exe", "-d %I -")));
|
||||
decoders.Add(new AudioDecoderSettingsViewModel(new CommandLineDecoderSettings("ffmpeg alac", "m4a", "ffmpeg.exe", "-v 0 -i %I -f wav -")));
|
||||
decoders.Add(new AudioDecoderSettingsViewModel(new CommandLine.DecoderSettings("takc", "tak", "takc.exe", "-d %I -")));
|
||||
decoders.Add(new AudioDecoderSettingsViewModel(new CommandLine.DecoderSettings("ffmpeg alac", "m4a", "ffmpeg.exe", "-v 0 -i %I -f wav -")));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -1,271 +0,0 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace CUETools.Codecs
|
||||
{
|
||||
[JsonObject(MemberSerialization.OptIn)]
|
||||
public class AudioEncoderSettingsViewModel : INotifyPropertyChanged
|
||||
{
|
||||
[JsonProperty]
|
||||
public AudioEncoderSettings settings = null;
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
[JsonConstructor]
|
||||
private AudioEncoderSettingsViewModel()
|
||||
{
|
||||
}
|
||||
|
||||
public AudioEncoderSettingsViewModel(
|
||||
string _name,
|
||||
string _extension,
|
||||
bool _lossless,
|
||||
string _supported_modes,
|
||||
string _default_mode,
|
||||
string _path,
|
||||
string _parameters
|
||||
)
|
||||
{
|
||||
settings = new CommandLineEncoderSettings() { name = _name, extension = _extension, SupportedModes = _supported_modes, EncoderMode = _default_mode, Path = _path, Parameters = _parameters, lossless = _lossless };
|
||||
}
|
||||
|
||||
public AudioEncoderSettingsViewModel(AudioEncoderClassAttribute enc)
|
||||
{
|
||||
settings = Activator.CreateInstance(enc.Settings) as AudioEncoderSettings;
|
||||
if (settings == null)
|
||||
throw new InvalidOperationException("invalid codec");
|
||||
}
|
||||
|
||||
public AudioEncoderSettingsViewModel Clone()
|
||||
{
|
||||
var res = this.MemberwiseClone() as AudioEncoderSettingsViewModel;
|
||||
if (settings != null) res.settings = settings.Clone();
|
||||
return res;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
|
||||
public string FullName => Name + " [" + Extension + "]";
|
||||
|
||||
public string Path
|
||||
{
|
||||
get
|
||||
{
|
||||
if (settings is CommandLineEncoderSettings)
|
||||
return (settings as CommandLineEncoderSettings).Path;
|
||||
return "";
|
||||
}
|
||||
set
|
||||
{
|
||||
var settings = this.settings as CommandLineEncoderSettings;
|
||||
if (settings == null) throw new InvalidOperationException();
|
||||
settings.Path = value;
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Path"));
|
||||
}
|
||||
}
|
||||
|
||||
public string Parameters
|
||||
{
|
||||
get
|
||||
{
|
||||
if (settings is CommandLineEncoderSettings)
|
||||
return (settings as CommandLineEncoderSettings).Parameters;
|
||||
return "";
|
||||
}
|
||||
set
|
||||
{
|
||||
var settings = this.settings as CommandLineEncoderSettings;
|
||||
if (settings == null) throw new InvalidOperationException();
|
||||
settings.Parameters = value;
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Parameters"));
|
||||
}
|
||||
}
|
||||
|
||||
public bool Lossless
|
||||
{
|
||||
get => settings.Lossless;
|
||||
set
|
||||
{
|
||||
var settings = this.settings as CommandLineEncoderSettings;
|
||||
if (settings == null) throw new InvalidOperationException();
|
||||
settings.lossless = value;
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Lossless"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public string Name
|
||||
{
|
||||
get => settings.Name;
|
||||
set
|
||||
{
|
||||
var settings = this.settings as CommandLineEncoderSettings;
|
||||
if (settings == null) throw new InvalidOperationException();
|
||||
settings.name = value;
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Name"));
|
||||
}
|
||||
}
|
||||
|
||||
public string Extension
|
||||
{
|
||||
get => settings.Extension;
|
||||
set
|
||||
{
|
||||
var settings = this.settings as CommandLineEncoderSettings;
|
||||
if (settings == null) throw new InvalidOperationException();
|
||||
settings.extension = value;
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Extension"));
|
||||
}
|
||||
}
|
||||
|
||||
public string DotExtension => "." + Extension;
|
||||
|
||||
public string SupportedModesStr
|
||||
{
|
||||
get
|
||||
{
|
||||
string defaultMode;
|
||||
return this.settings.GetSupportedModes(out defaultMode);
|
||||
}
|
||||
set
|
||||
{
|
||||
var settings = this.settings as CommandLineEncoderSettings;
|
||||
if (settings == null) throw new InvalidOperationException();
|
||||
settings.SupportedModes = value;
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("SupportedModesStr"));
|
||||
}
|
||||
}
|
||||
|
||||
public string[] SupportedModes => 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 => settings is CommandLineEncoderSettings;
|
||||
|
||||
public bool IsValid =>
|
||||
(settings != null)
|
||||
&& (settings is CommandLineEncoderSettings ? (settings as CommandLineEncoderSettings).Path != "" : true);
|
||||
}
|
||||
|
||||
[JsonObject(MemberSerialization.OptIn)]
|
||||
public class AudioDecoderSettingsViewModel : INotifyPropertyChanged
|
||||
{
|
||||
[JsonProperty]
|
||||
public AudioDecoderSettings decoderSettings = null;
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
[JsonConstructor]
|
||||
private AudioDecoderSettingsViewModel()
|
||||
{
|
||||
}
|
||||
|
||||
public AudioDecoderSettingsViewModel(AudioDecoderSettings settings)
|
||||
{
|
||||
decoderSettings = settings;
|
||||
}
|
||||
|
||||
public AudioDecoderSettingsViewModel Clone()
|
||||
{
|
||||
var res = this.MemberwiseClone() as AudioDecoderSettingsViewModel;
|
||||
if (decoderSettings != null) res.decoderSettings = decoderSettings.Clone();
|
||||
return res;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
|
||||
public string FullName => Name + " [" + Extension + "]";
|
||||
|
||||
public string Path
|
||||
{
|
||||
get
|
||||
{
|
||||
if (decoderSettings is CommandLineDecoderSettings)
|
||||
return (decoderSettings as CommandLineDecoderSettings).Path;
|
||||
return "";
|
||||
}
|
||||
set
|
||||
{
|
||||
if (decoderSettings is CommandLineDecoderSettings)
|
||||
(decoderSettings as CommandLineDecoderSettings).Path = value;
|
||||
else throw new InvalidOperationException();
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Path"));
|
||||
}
|
||||
}
|
||||
public string Parameters
|
||||
{
|
||||
get
|
||||
{
|
||||
if (decoderSettings is CommandLineDecoderSettings)
|
||||
return (decoderSettings as CommandLineDecoderSettings).Parameters;
|
||||
return "";
|
||||
}
|
||||
set
|
||||
{
|
||||
if (decoderSettings is CommandLineDecoderSettings)
|
||||
(decoderSettings as CommandLineDecoderSettings).Parameters = value;
|
||||
else throw new InvalidOperationException();
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Parameters"));
|
||||
}
|
||||
}
|
||||
|
||||
public bool Lossless
|
||||
{
|
||||
get => true;
|
||||
set {
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get => decoderSettings.Name;
|
||||
set
|
||||
{
|
||||
if (decoderSettings is CommandLineDecoderSettings)
|
||||
(decoderSettings as CommandLineDecoderSettings).name = value;
|
||||
else throw new InvalidOperationException();
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Name"));
|
||||
}
|
||||
}
|
||||
|
||||
public string Extension
|
||||
{
|
||||
get => decoderSettings.Extension;
|
||||
set
|
||||
{
|
||||
if (decoderSettings is CommandLineDecoderSettings)
|
||||
(decoderSettings as CommandLineDecoderSettings).extension = value;
|
||||
else throw new InvalidOperationException();
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Extension"));
|
||||
}
|
||||
}
|
||||
|
||||
public string DotExtension => "." + Extension;
|
||||
|
||||
public bool CanBeDeleted => decoderSettings is CommandLineDecoderSettings;
|
||||
|
||||
public bool IsValid =>
|
||||
(decoderSettings != null)
|
||||
&& (decoderSettings is CommandLineDecoderSettings ? (decoderSettings as CommandLineDecoderSettings).Path != "" : true);
|
||||
}
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace CUETools.Codecs
|
||||
{
|
||||
public class CUEToolsUDCEncoderList : BindingList<AudioEncoderSettingsViewModel>
|
||||
{
|
||||
public CUEToolsUDCEncoderList()
|
||||
: base()
|
||||
{
|
||||
AddingNew += OnAddingNew;
|
||||
}
|
||||
|
||||
private void OnAddingNew(object sender, AddingNewEventArgs e)
|
||||
{
|
||||
e.NewObject = new AudioEncoderSettingsViewModel("new", "wav", true, "", "", "", "");
|
||||
}
|
||||
|
||||
public bool TryGetValue(string extension, bool lossless, string name, out AudioEncoderSettingsViewModel result)
|
||||
{
|
||||
//result = this.Where(udc => udc.settings.Extension == extension && udc.settings.Lossless == lossless && udc.settings.Name == name).First();
|
||||
foreach (AudioEncoderSettingsViewModel udc in this)
|
||||
{
|
||||
if (udc.settings.Extension == extension && udc.settings.Lossless == lossless && udc.settings.Name == name)
|
||||
{
|
||||
result = udc;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
result = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
public AudioEncoderSettingsViewModel GetDefault(string extension, bool lossless)
|
||||
{
|
||||
AudioEncoderSettingsViewModel result = null;
|
||||
foreach (AudioEncoderSettingsViewModel udc in this)
|
||||
{
|
||||
if (udc.settings.Extension == extension && udc.settings.Lossless == lossless && (result == null || result.settings.Priority < udc.settings.Priority))
|
||||
{
|
||||
result = udc;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public class CUEToolsUDCDecoderList : BindingList<AudioDecoderSettingsViewModel>
|
||||
{
|
||||
public CUEToolsUDCDecoderList()
|
||||
: base()
|
||||
{
|
||||
AddingNew += OnAddingNew;
|
||||
}
|
||||
|
||||
private void OnAddingNew(object sender, AddingNewEventArgs e)
|
||||
{
|
||||
e.NewObject = new AudioDecoderSettingsViewModel(new CommandLineDecoderSettings("new", "wav", "", ""));
|
||||
}
|
||||
|
||||
public bool TryGetValue(string extension, bool lossless, string name, out AudioDecoderSettingsViewModel result)
|
||||
{
|
||||
foreach (AudioDecoderSettingsViewModel udc in this)
|
||||
{
|
||||
if (udc.decoderSettings.Extension == extension && udc.decoderSettings.Lossless == lossless && udc.decoderSettings.Name == name)
|
||||
{
|
||||
result = udc;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
result = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
public AudioDecoderSettingsViewModel GetDefault(string extension, bool lossless)
|
||||
{
|
||||
AudioDecoderSettingsViewModel result = null;
|
||||
foreach (AudioDecoderSettingsViewModel udc in this)
|
||||
{
|
||||
if (udc.decoderSettings.Extension == extension && udc.decoderSettings.Lossless == lossless && (result == null || result.decoderSettings.Priority < udc.decoderSettings.Priority))
|
||||
{
|
||||
result = udc;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,15 +2,15 @@
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
||||
namespace CUETools.Codecs
|
||||
namespace CUETools.Codecs.CommandLine
|
||||
{
|
||||
public class CommandLineDecoder : IAudioSource
|
||||
public class AudioDecoder : IAudioSource
|
||||
{
|
||||
string _path;
|
||||
Process _decoderProcess;
|
||||
WAV.AudioDecoder rdr;
|
||||
|
||||
private CommandLineDecoderSettings m_settings;
|
||||
private DecoderSettings m_settings;
|
||||
public AudioDecoderSettings Settings => m_settings;
|
||||
|
||||
public long Position
|
||||
@@ -56,7 +56,7 @@ namespace CUETools.Codecs
|
||||
|
||||
public string Path { get { return _path; } }
|
||||
|
||||
public CommandLineDecoder(CommandLineDecoderSettings settings, string path, Stream IO)
|
||||
public AudioDecoder(DecoderSettings settings, string path, Stream IO)
|
||||
{
|
||||
m_settings = settings;
|
||||
_path = path;
|
||||
@@ -2,9 +2,9 @@
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
||||
namespace CUETools.Codecs
|
||||
namespace CUETools.Codecs.CommandLine
|
||||
{
|
||||
public class CommandLineEncoder : IAudioDest
|
||||
public class AudioEncoder : IAudioDest
|
||||
{
|
||||
string _path;
|
||||
Process _encoderProcess;
|
||||
@@ -29,12 +29,12 @@ namespace CUETools.Codecs
|
||||
}
|
||||
|
||||
// !!!! Must not start the process in constructor, so that we can set CompressionLevel via Settings!
|
||||
private CommandLineEncoderSettings m_settings;
|
||||
private EncoderSettings m_settings;
|
||||
public AudioEncoderSettings Settings => m_settings;
|
||||
|
||||
public string Path { get { return _path; } }
|
||||
|
||||
public CommandLineEncoder(CommandLineEncoderSettings settings, string path, Stream IO = null)
|
||||
public AudioEncoder(EncoderSettings settings, string path, Stream IO = null)
|
||||
{
|
||||
m_settings = settings;
|
||||
_path = path;
|
||||
@@ -4,21 +4,21 @@ using System.Text;
|
||||
using System.ComponentModel;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace CUETools.Codecs
|
||||
namespace CUETools.Codecs.CommandLine
|
||||
{
|
||||
[JsonObject(MemberSerialization.OptIn)]
|
||||
public class CommandLineDecoderSettings : AudioDecoderSettings
|
||||
public class DecoderSettings : AudioDecoderSettings
|
||||
{
|
||||
public override string Name => name;
|
||||
|
||||
public override string Extension => extension;
|
||||
|
||||
public CommandLineDecoderSettings()
|
||||
public DecoderSettings()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
public CommandLineDecoderSettings(
|
||||
public DecoderSettings(
|
||||
string _name,
|
||||
string _extension,
|
||||
string _path,
|
||||
@@ -4,20 +4,20 @@ using System.Text;
|
||||
using System.ComponentModel;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace CUETools.Codecs
|
||||
namespace CUETools.Codecs.CommandLine
|
||||
{
|
||||
[JsonObject(MemberSerialization.OptIn)]
|
||||
public class CommandLineEncoderSettings : AudioEncoderSettings
|
||||
public class EncoderSettings : AudioEncoderSettings
|
||||
{
|
||||
public override string Name => name;
|
||||
|
||||
public override string Extension => extension;
|
||||
|
||||
public override Type EncoderType => typeof(CommandLineEncoder);
|
||||
public override Type EncoderType => typeof(AudioEncoder);
|
||||
|
||||
public override bool Lossless => lossless;
|
||||
|
||||
public CommandLineEncoderSettings()
|
||||
public EncoderSettings()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace CUETools.Codecs
|
||||
{
|
||||
public class DummyWriter : IAudioDest
|
||||
{
|
||||
AudioEncoderSettings m_settings;
|
||||
|
||||
public DummyWriter(string path, AudioEncoderSettings settings)
|
||||
{
|
||||
m_settings = settings;
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
}
|
||||
|
||||
public void Delete()
|
||||
{
|
||||
}
|
||||
|
||||
public long FinalSampleCount
|
||||
{
|
||||
set { }
|
||||
}
|
||||
|
||||
public AudioEncoderSettings Settings
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_settings;
|
||||
}
|
||||
}
|
||||
|
||||
public void Write(AudioBuffer buff)
|
||||
{
|
||||
}
|
||||
|
||||
public string Path { get { return null; } }
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace CUETools.Codecs
|
||||
namespace CUETools.Codecs.NULL
|
||||
{
|
||||
public class SilenceGenerator : IAudioSource
|
||||
public class AudioDecoder : IAudioSource
|
||||
{
|
||||
private long _sampleOffset, _sampleCount;
|
||||
private AudioPCMConfig pcm;
|
||||
@@ -28,7 +28,7 @@
|
||||
|
||||
public string Path { get { return null; } }
|
||||
|
||||
public SilenceGenerator(AudioPCMConfig pcm, long sampleCount, int sampleVal)
|
||||
public AudioDecoder(AudioPCMConfig pcm, long sampleCount, int sampleVal)
|
||||
{
|
||||
this._sampleVal = sampleVal;
|
||||
this._sampleOffset = 0;
|
||||
@@ -36,7 +36,7 @@
|
||||
this.pcm = pcm;
|
||||
}
|
||||
|
||||
public SilenceGenerator(long sampleCount)
|
||||
public AudioDecoder(long sampleCount)
|
||||
: this(AudioPCMConfig.RedBook, sampleCount, 0)
|
||||
{
|
||||
}
|
||||
35
CUETools.Codecs/NULL/AudioEncoder.cs
Normal file
35
CUETools.Codecs/NULL/AudioEncoder.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
|
||||
namespace CUETools.Codecs.NULL
|
||||
{
|
||||
public class AudioEncoder : IAudioDest
|
||||
{
|
||||
AudioEncoderSettings m_settings;
|
||||
|
||||
public AudioEncoder(string path, AudioEncoderSettings settings)
|
||||
{
|
||||
m_settings = settings;
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
}
|
||||
|
||||
public void Delete()
|
||||
{
|
||||
}
|
||||
|
||||
public long FinalSampleCount
|
||||
{
|
||||
set { }
|
||||
}
|
||||
|
||||
public AudioEncoderSettings Settings => m_settings;
|
||||
|
||||
public void Write(AudioBuffer buff)
|
||||
{
|
||||
}
|
||||
|
||||
public string Path => null;
|
||||
}
|
||||
}
|
||||
112
CUETools.Codecs/ViewModel/AudioDecoderSettingsViewModel.cs
Normal file
112
CUETools.Codecs/ViewModel/AudioDecoderSettingsViewModel.cs
Normal file
@@ -0,0 +1,112 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace CUETools.Codecs
|
||||
{
|
||||
[JsonObject(MemberSerialization.OptIn)]
|
||||
public class AudioDecoderSettingsViewModel : INotifyPropertyChanged
|
||||
{
|
||||
[JsonProperty]
|
||||
public AudioDecoderSettings decoderSettings = null;
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
[JsonConstructor]
|
||||
private AudioDecoderSettingsViewModel()
|
||||
{
|
||||
}
|
||||
|
||||
public AudioDecoderSettingsViewModel(AudioDecoderSettings settings)
|
||||
{
|
||||
decoderSettings = settings;
|
||||
}
|
||||
|
||||
public AudioDecoderSettingsViewModel Clone()
|
||||
{
|
||||
var res = this.MemberwiseClone() as AudioDecoderSettingsViewModel;
|
||||
if (decoderSettings != null) res.decoderSettings = decoderSettings.Clone();
|
||||
return res;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
|
||||
public string FullName => Name + " [" + Extension + "]";
|
||||
|
||||
public string Path
|
||||
{
|
||||
get
|
||||
{
|
||||
if (decoderSettings is CommandLine.DecoderSettings)
|
||||
return (decoderSettings as CommandLine.DecoderSettings).Path;
|
||||
return "";
|
||||
}
|
||||
set
|
||||
{
|
||||
if (decoderSettings is CommandLine.DecoderSettings)
|
||||
(decoderSettings as CommandLine.DecoderSettings).Path = value;
|
||||
else throw new InvalidOperationException();
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Path"));
|
||||
}
|
||||
}
|
||||
public string Parameters
|
||||
{
|
||||
get
|
||||
{
|
||||
if (decoderSettings is CommandLine.DecoderSettings)
|
||||
return (decoderSettings as CommandLine.DecoderSettings).Parameters;
|
||||
return "";
|
||||
}
|
||||
set
|
||||
{
|
||||
if (decoderSettings is CommandLine.DecoderSettings)
|
||||
(decoderSettings as CommandLine.DecoderSettings).Parameters = value;
|
||||
else throw new InvalidOperationException();
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Parameters"));
|
||||
}
|
||||
}
|
||||
|
||||
public bool Lossless
|
||||
{
|
||||
get => true;
|
||||
set {
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get => decoderSettings.Name;
|
||||
set
|
||||
{
|
||||
if (decoderSettings is CommandLine.DecoderSettings)
|
||||
(decoderSettings as CommandLine.DecoderSettings).name = value;
|
||||
else throw new InvalidOperationException();
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Name"));
|
||||
}
|
||||
}
|
||||
|
||||
public string Extension
|
||||
{
|
||||
get => decoderSettings.Extension;
|
||||
set
|
||||
{
|
||||
if (decoderSettings is CommandLine.DecoderSettings)
|
||||
(decoderSettings as CommandLine.DecoderSettings).extension = value;
|
||||
else throw new InvalidOperationException();
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Extension"));
|
||||
}
|
||||
}
|
||||
|
||||
public string DotExtension => "." + Extension;
|
||||
|
||||
public bool CanBeDeleted => decoderSettings is CommandLine.DecoderSettings;
|
||||
|
||||
public bool IsValid =>
|
||||
(decoderSettings != null)
|
||||
&& (decoderSettings is CommandLine.DecoderSettings ? (decoderSettings as CommandLine.DecoderSettings).Path != "" : true);
|
||||
}
|
||||
}
|
||||
165
CUETools.Codecs/ViewModel/AudioEncoderSettingsViewModel.cs
Normal file
165
CUETools.Codecs/ViewModel/AudioEncoderSettingsViewModel.cs
Normal file
@@ -0,0 +1,165 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace CUETools.Codecs
|
||||
{
|
||||
[JsonObject(MemberSerialization.OptIn)]
|
||||
public class AudioEncoderSettingsViewModel : INotifyPropertyChanged
|
||||
{
|
||||
[JsonProperty]
|
||||
public AudioEncoderSettings settings = null;
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
[JsonConstructor]
|
||||
private AudioEncoderSettingsViewModel()
|
||||
{
|
||||
}
|
||||
|
||||
public AudioEncoderSettingsViewModel(
|
||||
string _name,
|
||||
string _extension,
|
||||
bool _lossless,
|
||||
string _supported_modes,
|
||||
string _default_mode,
|
||||
string _path,
|
||||
string _parameters
|
||||
)
|
||||
{
|
||||
settings = new CommandLine.EncoderSettings() { name = _name, extension = _extension, SupportedModes = _supported_modes, EncoderMode = _default_mode, Path = _path, Parameters = _parameters, lossless = _lossless };
|
||||
}
|
||||
|
||||
public AudioEncoderSettingsViewModel(AudioEncoderClassAttribute enc)
|
||||
{
|
||||
settings = Activator.CreateInstance(enc.Settings) as AudioEncoderSettings;
|
||||
if (settings == null)
|
||||
throw new InvalidOperationException("invalid codec");
|
||||
}
|
||||
|
||||
public AudioEncoderSettingsViewModel Clone()
|
||||
{
|
||||
var res = this.MemberwiseClone() as AudioEncoderSettingsViewModel;
|
||||
if (settings != null) res.settings = settings.Clone();
|
||||
return res;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
|
||||
public string FullName => Name + " [" + Extension + "]";
|
||||
|
||||
public string Path
|
||||
{
|
||||
get
|
||||
{
|
||||
if (settings is CommandLine.EncoderSettings)
|
||||
return (settings as CommandLine.EncoderSettings).Path;
|
||||
return "";
|
||||
}
|
||||
set
|
||||
{
|
||||
var settings = this.settings as CommandLine.EncoderSettings;
|
||||
if (settings == null) throw new InvalidOperationException();
|
||||
settings.Path = value;
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Path"));
|
||||
}
|
||||
}
|
||||
|
||||
public string Parameters
|
||||
{
|
||||
get
|
||||
{
|
||||
if (settings is CommandLine.EncoderSettings)
|
||||
return (settings as CommandLine.EncoderSettings).Parameters;
|
||||
return "";
|
||||
}
|
||||
set
|
||||
{
|
||||
var settings = this.settings as CommandLine.EncoderSettings;
|
||||
if (settings == null) throw new InvalidOperationException();
|
||||
settings.Parameters = value;
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Parameters"));
|
||||
}
|
||||
}
|
||||
|
||||
public bool Lossless
|
||||
{
|
||||
get => settings.Lossless;
|
||||
set
|
||||
{
|
||||
var settings = this.settings as CommandLine.EncoderSettings;
|
||||
if (settings == null) throw new InvalidOperationException();
|
||||
settings.lossless = value;
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Lossless"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public string Name
|
||||
{
|
||||
get => settings.Name;
|
||||
set
|
||||
{
|
||||
var settings = this.settings as CommandLine.EncoderSettings;
|
||||
if (settings == null) throw new InvalidOperationException();
|
||||
settings.name = value;
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Name"));
|
||||
}
|
||||
}
|
||||
|
||||
public string Extension
|
||||
{
|
||||
get => settings.Extension;
|
||||
set
|
||||
{
|
||||
var settings = this.settings as CommandLine.EncoderSettings;
|
||||
if (settings == null) throw new InvalidOperationException();
|
||||
settings.extension = value;
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Extension"));
|
||||
}
|
||||
}
|
||||
|
||||
public string DotExtension => "." + Extension;
|
||||
|
||||
public string SupportedModesStr
|
||||
{
|
||||
get
|
||||
{
|
||||
string defaultMode;
|
||||
return this.settings.GetSupportedModes(out defaultMode);
|
||||
}
|
||||
set
|
||||
{
|
||||
var settings = this.settings as CommandLine.EncoderSettings;
|
||||
if (settings == null) throw new InvalidOperationException();
|
||||
settings.SupportedModes = value;
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("SupportedModesStr"));
|
||||
}
|
||||
}
|
||||
|
||||
public string[] SupportedModes => 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 => settings is CommandLine.EncoderSettings;
|
||||
|
||||
public bool IsValid =>
|
||||
(settings != null)
|
||||
&& (settings is CommandLine.EncoderSettings ? (settings as CommandLine.EncoderSettings).Path != "" : true);
|
||||
}
|
||||
}
|
||||
46
CUETools.Codecs/ViewModel/DecoderListViewModel.cs
Normal file
46
CUETools.Codecs/ViewModel/DecoderListViewModel.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace CUETools.Codecs
|
||||
{
|
||||
public class DecoderListViewModel : BindingList<AudioDecoderSettingsViewModel>
|
||||
{
|
||||
public DecoderListViewModel()
|
||||
: base()
|
||||
{
|
||||
AddingNew += OnAddingNew;
|
||||
}
|
||||
|
||||
private void OnAddingNew(object sender, AddingNewEventArgs e)
|
||||
{
|
||||
e.NewObject = new AudioDecoderSettingsViewModel(new CommandLine.DecoderSettings("new", "wav", "", ""));
|
||||
}
|
||||
|
||||
public bool TryGetValue(string extension, bool lossless, string name, out AudioDecoderSettingsViewModel result)
|
||||
{
|
||||
foreach (AudioDecoderSettingsViewModel udc in this)
|
||||
{
|
||||
if (udc.decoderSettings.Extension == extension && udc.decoderSettings.Lossless == lossless && udc.decoderSettings.Name == name)
|
||||
{
|
||||
result = udc;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
result = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
public AudioDecoderSettingsViewModel GetDefault(string extension, bool lossless)
|
||||
{
|
||||
AudioDecoderSettingsViewModel result = null;
|
||||
foreach (AudioDecoderSettingsViewModel udc in this)
|
||||
{
|
||||
if (udc.decoderSettings.Extension == extension && udc.decoderSettings.Lossless == lossless && (result == null || result.decoderSettings.Priority < udc.decoderSettings.Priority))
|
||||
{
|
||||
result = udc;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
47
CUETools.Codecs/ViewModel/EncoderListViewModel.cs
Normal file
47
CUETools.Codecs/ViewModel/EncoderListViewModel.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace CUETools.Codecs
|
||||
{
|
||||
public class EncoderListViewModel : BindingList<AudioEncoderSettingsViewModel>
|
||||
{
|
||||
public EncoderListViewModel()
|
||||
: base()
|
||||
{
|
||||
AddingNew += OnAddingNew;
|
||||
}
|
||||
|
||||
private void OnAddingNew(object sender, AddingNewEventArgs e)
|
||||
{
|
||||
e.NewObject = new AudioEncoderSettingsViewModel("new", "wav", true, "", "", "", "");
|
||||
}
|
||||
|
||||
public bool TryGetValue(string extension, bool lossless, string name, out AudioEncoderSettingsViewModel result)
|
||||
{
|
||||
//result = this.Where(udc => udc.settings.Extension == extension && udc.settings.Lossless == lossless && udc.settings.Name == name).First();
|
||||
foreach (AudioEncoderSettingsViewModel udc in this)
|
||||
{
|
||||
if (udc.settings.Extension == extension && udc.settings.Lossless == lossless && udc.settings.Name == name)
|
||||
{
|
||||
result = udc;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
result = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
public AudioEncoderSettingsViewModel GetDefault(string extension, bool lossless)
|
||||
{
|
||||
AudioEncoderSettingsViewModel result = null;
|
||||
foreach (AudioEncoderSettingsViewModel udc in this)
|
||||
{
|
||||
if (udc.settings.Extension == extension && udc.settings.Lossless == lossless && (result == null || result.settings.Priority < udc.settings.Priority))
|
||||
{
|
||||
result = udc;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,21 +3,6 @@ using System.IO;
|
||||
|
||||
namespace CUETools.Codecs.WAV
|
||||
{
|
||||
public class DecoderSettings : AudioDecoderSettings
|
||||
{
|
||||
public override string Name => "cuetools";
|
||||
|
||||
public override string Extension => "wav";
|
||||
|
||||
public override Type DecoderType => typeof(AudioDecoder);
|
||||
|
||||
public override int Priority => 2;
|
||||
|
||||
public DecoderSettings() : base() {}
|
||||
|
||||
public bool IgnoreChunkSizes;
|
||||
}
|
||||
|
||||
[AudioDecoderClass(typeof(DecoderSettings))]
|
||||
public class AudioDecoder : IAudioSource
|
||||
{
|
||||
19
CUETools.Codecs/WAV/DecoderSettings.cs
Normal file
19
CUETools.Codecs/WAV/DecoderSettings.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
|
||||
namespace CUETools.Codecs.WAV
|
||||
{
|
||||
public class DecoderSettings : AudioDecoderSettings
|
||||
{
|
||||
public override string Name => "cuetools";
|
||||
|
||||
public override string Extension => "wav";
|
||||
|
||||
public override Type DecoderType => typeof(AudioDecoder);
|
||||
|
||||
public override int Priority => 2;
|
||||
|
||||
public DecoderSettings() : base() { }
|
||||
|
||||
public bool IgnoreChunkSizes;
|
||||
}
|
||||
}
|
||||
@@ -244,7 +244,7 @@ namespace CUETools.FLACCL.cmd
|
||||
if (input_file == "-")
|
||||
audioSource = new Codecs.WAV.AudioDecoder(new Codecs.WAV.DecoderSettings() { IgnoreChunkSizes = true }, "", Console.OpenStandardInput());
|
||||
else if (input_file == "nul")
|
||||
audioSource = new SilenceGenerator(new AudioPCMConfig(input_bps, input_ch, input_rate), input_len, input_val);
|
||||
audioSource = new Codecs.NULL.AudioDecoder(new AudioPCMConfig(input_bps, input_ch, input_rate), input_len, input_val);
|
||||
else if (File.Exists(input_file) && Path.GetExtension(input_file) == ".wav")
|
||||
audioSource = new Codecs.WAV.AudioDecoder(new Codecs.WAV.DecoderSettings(), input_file);
|
||||
else if (File.Exists(input_file) && Path.GetExtension(input_file) == ".flac")
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace CUETools.Processor
|
||||
long len;
|
||||
if (!long.TryParse(slen, out len))
|
||||
len = CDImageLayout.TimeFromString(slen) * 588;
|
||||
return new SilenceGenerator(len);
|
||||
return new Codecs.NULL.AudioDecoder(len);
|
||||
}
|
||||
}
|
||||
if (extension == ".bin")
|
||||
@@ -51,7 +51,7 @@ namespace CUETools.Processor
|
||||
{
|
||||
IAudioDest dest;
|
||||
if (audioEncoderType == AudioEncoderType.NoAudio || extension == ".dummy")
|
||||
return new DummyWriter(path, new AudioEncoderSettings(pcm)) { FinalSampleCount = finalSampleCount };
|
||||
return new Codecs.NULL.AudioEncoder(path, new AudioEncoderSettings(pcm)) { FinalSampleCount = finalSampleCount };
|
||||
CUEToolsFormat fmt;
|
||||
if (!extension.StartsWith(".") || !config.formats.TryGetValue(extension.Substring(1), out fmt))
|
||||
throw new Exception("Unsupported audio type: " + path);
|
||||
|
||||
@@ -71,8 +71,8 @@ namespace CUETools.Processor
|
||||
public bool CopyAlbumArt { get; set; }
|
||||
public string ArLogFilenameFormat { get; set; }
|
||||
public string AlArtFilenameFormat { get; set; }
|
||||
public CUEToolsUDCEncoderList Encoders => encoders;
|
||||
public CUEToolsUDCDecoderList Decoders => decoders;
|
||||
public EncoderListViewModel Encoders => encoders;
|
||||
public DecoderListViewModel Decoders => decoders;
|
||||
|
||||
public CUEConfig()
|
||||
: base(CUEProcessorPlugins.encs, CUEProcessorPlugins.decs)
|
||||
@@ -312,9 +312,9 @@ namespace CUETools.Processor
|
||||
|
||||
int nDecoders = 0;
|
||||
foreach (var decoder in decoders)
|
||||
if (decoder.decoderSettings is CommandLineDecoderSettings)
|
||||
if (decoder.decoderSettings is Codecs.CommandLine.DecoderSettings)
|
||||
{
|
||||
var settings = decoder.decoderSettings as CommandLineDecoderSettings;
|
||||
var settings = decoder.decoderSettings as Codecs.CommandLine.DecoderSettings;
|
||||
sw.Save(string.Format("ExternalDecoder{0}Name", nDecoders), settings.Name);
|
||||
sw.Save(string.Format("ExternalDecoder{0}Extension", nDecoders), settings.Extension);
|
||||
sw.Save(string.Format("ExternalDecoder{0}Path", nDecoders), settings.Path);
|
||||
@@ -434,14 +434,14 @@ namespace CUETools.Processor
|
||||
try
|
||||
{
|
||||
var jsonObject = JsonConvert.DeserializeObject(sr.Load("Encoders"),
|
||||
typeof(CUEToolsUDCEncoderList),
|
||||
typeof(EncoderListViewModel),
|
||||
new JsonSerializerSettings {
|
||||
DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate,
|
||||
TypeNameHandling = TypeNameHandling.Auto
|
||||
});
|
||||
if (jsonObject as CUEToolsUDCEncoderList == null)
|
||||
if (jsonObject as EncoderListViewModel == null)
|
||||
throw new Exception();
|
||||
encoders = jsonObject as CUEToolsUDCEncoderList;
|
||||
encoders = jsonObject as EncoderListViewModel;
|
||||
encoders.Where(x => !x.IsValid).ToList().ForEach(x => encoders.Remove(x));
|
||||
AudioEncoderSettingsViewModel tmp;
|
||||
encodersBackup.Where(x => !encoders.TryGetValue(x.Extension, x.Lossless, x.Name, out tmp)).ToList().ForEach(x => encoders.Add(x));
|
||||
@@ -503,7 +503,7 @@ namespace CUETools.Processor
|
||||
string parameters = sr.Load(string.Format("ExternalDecoder{0}Parameters", nDecoders));
|
||||
AudioDecoderSettingsViewModel decoder;
|
||||
if (!decoders.TryGetValue(extension, true, name, out decoder))
|
||||
decoders.Add(new AudioDecoderSettingsViewModel(new CommandLineDecoderSettings(name, extension, path, parameters)));
|
||||
decoders.Add(new AudioDecoderSettingsViewModel(new Codecs.CommandLine.DecoderSettings(name, extension, path, parameters)));
|
||||
else
|
||||
{
|
||||
decoder.Extension = extension;
|
||||
|
||||
@@ -3972,7 +3972,7 @@ namespace CUETools.Processor
|
||||
|
||||
if (sourceInfo.Path == null)
|
||||
{
|
||||
audioSource = new SilenceGenerator(sourceInfo.Offset + sourceInfo.Length);
|
||||
audioSource = new Codecs.NULL.AudioDecoder(sourceInfo.Offset + sourceInfo.Length);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user