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:
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user