2018-03-23 19:26:26 -04:00
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
using System;
|
2011-10-24 11:38:10 +00:00
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
|
|
2013-06-05 03:02:43 -04:00
|
|
|
|
namespace CUETools.Codecs
|
2011-10-24 11:38:10 +00:00
|
|
|
|
{
|
2018-03-23 19:26:26 -04:00
|
|
|
|
[JsonObject(MemberSerialization.OptIn)]
|
|
|
|
|
|
public class AudioEncoderSettingsViewModel : INotifyPropertyChanged
|
2011-10-24 11:38:10 +00:00
|
|
|
|
{
|
2018-03-23 19:26:26 -04:00
|
|
|
|
[JsonProperty]
|
2013-04-01 23:03:22 -04:00
|
|
|
|
public AudioEncoderSettings settings = null;
|
2011-10-24 11:38:10 +00:00
|
|
|
|
|
|
|
|
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
|
|
|
|
|
2018-03-23 19:26:26 -04:00
|
|
|
|
[JsonConstructor]
|
|
|
|
|
|
private AudioEncoderSettingsViewModel()
|
2011-10-24 11:38:10 +00:00
|
|
|
|
{
|
2013-04-09 20:51:13 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-03-23 19:26:26 -04:00
|
|
|
|
public AudioEncoderSettingsViewModel(
|
2013-04-09 20:51:13 -04:00
|
|
|
|
string _name,
|
|
|
|
|
|
string _extension,
|
2018-03-23 19:26:26 -04:00
|
|
|
|
bool _lossless,
|
|
|
|
|
|
string _supported_modes,
|
|
|
|
|
|
string _default_mode,
|
2013-04-09 20:51:13 -04:00
|
|
|
|
string _path,
|
|
|
|
|
|
string _parameters
|
|
|
|
|
|
)
|
|
|
|
|
|
{
|
2018-03-23 19:26:26 -04:00
|
|
|
|
settings = new CommandLineEncoderSettings() { name = _name, extension = _extension, SupportedModes = _supported_modes, EncoderMode = _default_mode, Path = _path, Parameters = _parameters, lossless = _lossless };
|
2011-10-24 11:38:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-03-23 19:26:26 -04:00
|
|
|
|
public AudioEncoderSettingsViewModel(AudioEncoderClassAttribute enc)
|
2011-10-24 11:38:10 +00:00
|
|
|
|
{
|
2018-03-23 19:26:26 -04:00
|
|
|
|
settings = Activator.CreateInstance(enc.Settings) as AudioEncoderSettings;
|
|
|
|
|
|
if (settings == null)
|
|
|
|
|
|
throw new InvalidOperationException("invalid codec");
|
2011-10-24 11:38:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-03-23 19:26:26 -04:00
|
|
|
|
public AudioEncoderSettingsViewModel Clone()
|
2014-11-30 18:31:07 -05:00
|
|
|
|
{
|
2018-03-23 19:26:26 -04:00
|
|
|
|
var res = this.MemberwiseClone() as AudioEncoderSettingsViewModel;
|
2014-11-30 18:31:07 -05:00
|
|
|
|
if (settings != null) res.settings = settings.Clone();
|
|
|
|
|
|
return res;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2011-10-24 11:38:10 +00:00
|
|
|
|
public override string ToString()
|
|
|
|
|
|
{
|
2018-03-23 19:26:26 -04:00
|
|
|
|
return Name;
|
2011-10-24 11:38:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-03-23 19:26:26 -04:00
|
|
|
|
public string FullName => Name + " [" + Extension + "]";
|
|
|
|
|
|
|
2011-10-24 11:38:10 +00:00
|
|
|
|
public string Path
|
|
|
|
|
|
{
|
2013-04-09 20:51:13 -04:00
|
|
|
|
get
|
|
|
|
|
|
{
|
2018-03-23 19:26:26 -04:00
|
|
|
|
if (settings is CommandLineEncoderSettings)
|
|
|
|
|
|
return (settings as CommandLineEncoderSettings).Path;
|
|
|
|
|
|
return "";
|
2013-04-09 20:51:13 -04:00
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
2018-03-23 19:26:26 -04:00
|
|
|
|
var settings = this.settings as CommandLineEncoderSettings;
|
|
|
|
|
|
if (settings == null) throw new InvalidOperationException();
|
|
|
|
|
|
settings.Path = value;
|
|
|
|
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Path"));
|
2013-04-09 20:51:13 -04:00
|
|
|
|
}
|
2011-10-24 11:38:10 +00:00
|
|
|
|
}
|
2018-03-23 19:26:26 -04:00
|
|
|
|
|
2011-10-24 11:38:10 +00:00
|
|
|
|
public string Parameters
|
|
|
|
|
|
{
|
2013-04-09 20:51:13 -04:00
|
|
|
|
get
|
|
|
|
|
|
{
|
2018-03-23 19:26:26 -04:00
|
|
|
|
if (settings is CommandLineEncoderSettings)
|
|
|
|
|
|
return (settings as CommandLineEncoderSettings).Parameters;
|
|
|
|
|
|
return "";
|
2013-04-09 20:51:13 -04:00
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
2018-03-23 19:26:26 -04:00
|
|
|
|
var settings = this.settings as CommandLineEncoderSettings;
|
|
|
|
|
|
if (settings == null) throw new InvalidOperationException();
|
|
|
|
|
|
settings.Parameters = value;
|
|
|
|
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Parameters"));
|
2013-04-09 20:51:13 -04:00
|
|
|
|
}
|
2011-10-24 11:38:10 +00:00
|
|
|
|
}
|
2018-03-23 19:26:26 -04:00
|
|
|
|
|
2011-10-24 11:38:10 +00:00
|
|
|
|
public bool Lossless
|
|
|
|
|
|
{
|
2018-03-23 19:26:26 -04:00
|
|
|
|
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"));
|
|
|
|
|
|
}
|
2011-10-24 11:38:10 +00:00
|
|
|
|
}
|
2013-04-18 22:48:48 -04:00
|
|
|
|
|
2018-03-23 19:26:26 -04:00
|
|
|
|
|
|
|
|
|
|
public string Name
|
2011-10-24 11:38:10 +00:00
|
|
|
|
{
|
2018-03-23 19:26:26 -04:00
|
|
|
|
get => settings.Name;
|
2013-04-18 22:48:48 -04:00
|
|
|
|
set
|
|
|
|
|
|
{
|
2018-03-23 19:26:26 -04:00
|
|
|
|
var settings = this.settings as CommandLineEncoderSettings;
|
|
|
|
|
|
if (settings == null) throw new InvalidOperationException();
|
|
|
|
|
|
settings.name = value;
|
|
|
|
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Name"));
|
2013-04-18 22:48:48 -04:00
|
|
|
|
}
|
2011-10-24 11:38:10 +00:00
|
|
|
|
}
|
2018-03-23 19:26:26 -04:00
|
|
|
|
|
|
|
|
|
|
public string Extension
|
2011-10-24 11:38:10 +00:00
|
|
|
|
{
|
2018-03-23 19:26:26 -04:00
|
|
|
|
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"));
|
|
|
|
|
|
}
|
2011-10-24 11:38:10 +00:00
|
|
|
|
}
|
2018-03-23 19:26:26 -04:00
|
|
|
|
|
|
|
|
|
|
public string DotExtension => "." + Extension;
|
|
|
|
|
|
|
2011-10-24 11:38:10 +00:00
|
|
|
|
public string SupportedModesStr
|
|
|
|
|
|
{
|
2013-04-01 23:03:22 -04:00
|
|
|
|
get
|
|
|
|
|
|
{
|
2013-04-08 23:11:03 -04:00
|
|
|
|
string defaultMode;
|
2013-04-09 20:51:13 -04:00
|
|
|
|
return this.settings.GetSupportedModes(out defaultMode);
|
2013-04-01 23:03:22 -04:00
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
2018-03-23 19:26:26 -04:00
|
|
|
|
var settings = this.settings as CommandLineEncoderSettings;
|
2013-04-09 20:51:13 -04:00
|
|
|
|
if (settings == null) throw new InvalidOperationException();
|
|
|
|
|
|
settings.SupportedModes = value;
|
2018-03-23 19:26:26 -04:00
|
|
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("SupportedModesStr"));
|
2013-04-01 23:03:22 -04:00
|
|
|
|
}
|
2011-10-24 11:38:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-03-23 19:26:26 -04:00
|
|
|
|
public string[] SupportedModes => this.SupportedModesStr.Split(' ');
|
2011-10-24 11:38:10 +00:00
|
|
|
|
|
2013-04-08 23:11:03 -04:00
|
|
|
|
public int EncoderModeIndex
|
2011-10-24 11:38:10 +00:00
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
2013-04-01 23:03:22 -04:00
|
|
|
|
string[] modes = this.SupportedModes;
|
2011-10-24 11:38:10 +00:00
|
|
|
|
if (modes == null || modes.Length < 2)
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
for (int i = 0; i < modes.Length; i++)
|
2013-04-09 20:51:13 -04:00
|
|
|
|
if (modes[i] == this.settings.EncoderMode)
|
2011-10-24 11:38:10 +00:00
|
|
|
|
return i;
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-03-23 19:26:26 -04:00
|
|
|
|
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
|
2011-10-24 11:38:10 +00:00
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
2018-03-23 19:26:26 -04:00
|
|
|
|
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"));
|
2011-10-24 11:38:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-03-23 19:26:26 -04:00
|
|
|
|
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);
|
2011-10-24 11:38:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|