2021-03-07 10:38:56 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2021-03-06 10:53:38 +01:00
|
|
|
|
using System.ComponentModel;
|
2021-03-07 10:38:56 +01:00
|
|
|
|
using System.Linq;
|
2021-03-06 10:53:38 +01:00
|
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
|
using Voicemeeter;
|
|
|
|
|
|
|
|
|
|
namespace MassiveKnob.Plugin.VoiceMeeter.Base
|
|
|
|
|
{
|
|
|
|
|
public class BaseVoiceMeeterSettingsViewModel<T> : BaseVoiceMeeterSettingsViewModel where T : BaseVoiceMeeterSettings
|
|
|
|
|
{
|
|
|
|
|
protected new T Settings => (T)base.Settings;
|
|
|
|
|
|
|
|
|
|
public BaseVoiceMeeterSettingsViewModel(T settings) : base(settings)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-03-07 10:38:56 +01:00
|
|
|
|
public class BaseVoiceMeeterSettingsViewModel : INotifyPropertyChanged, IDisposable
|
2021-03-06 10:53:38 +01:00
|
|
|
|
{
|
|
|
|
|
protected readonly BaseVoiceMeeterSettings Settings;
|
|
|
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
2021-03-07 10:38:56 +01:00
|
|
|
|
public event EventHandler Disposed;
|
2021-03-06 10:53:38 +01:00
|
|
|
|
|
|
|
|
|
// ReSharper disable UnusedMember.Global - used by WPF Binding
|
|
|
|
|
public IList<VoiceMeeterVersionViewModel> Versions { get; }
|
|
|
|
|
|
|
|
|
|
private VoiceMeeterVersionViewModel selectedVersion;
|
|
|
|
|
public VoiceMeeterVersionViewModel SelectedVersion
|
|
|
|
|
{
|
|
|
|
|
get => selectedVersion;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value == selectedVersion)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
selectedVersion = value;
|
|
|
|
|
OnPropertyChanged();
|
|
|
|
|
|
|
|
|
|
Settings.Version = value?.Version ?? RunVoicemeeterParam.None;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// ReSharper restore UnusedMember.Global
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public BaseVoiceMeeterSettingsViewModel(BaseVoiceMeeterSettings settings)
|
|
|
|
|
{
|
|
|
|
|
Settings = settings;
|
|
|
|
|
|
|
|
|
|
Versions = new List<VoiceMeeterVersionViewModel>
|
|
|
|
|
{
|
|
|
|
|
new VoiceMeeterVersionViewModel(RunVoicemeeterParam.Voicemeeter, "VoiceMeeter Standard"),
|
|
|
|
|
new VoiceMeeterVersionViewModel(RunVoicemeeterParam.VoicemeeterBanana, "VoiceMeeter Banana"),
|
|
|
|
|
new VoiceMeeterVersionViewModel(RunVoicemeeterParam.VoicemeeterPotato, "VoiceMeeter Potato")
|
|
|
|
|
};
|
2021-03-07 10:38:56 +01:00
|
|
|
|
|
|
|
|
|
UpdateSelectedVersion();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void UpdateSelectedVersion()
|
|
|
|
|
{
|
|
|
|
|
selectedVersion = Versions.SingleOrDefault(v => v.Version == Settings.Version) ?? Versions.First();
|
2021-03-06 10:53:38 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public virtual bool IsSettingsProperty(string propertyName)
|
|
|
|
|
{
|
|
|
|
|
// SelectedVersion already trigger a VoiceMeeterVersionChanged for all instances,
|
|
|
|
|
// which causes the settings to be stored
|
|
|
|
|
return propertyName != nameof(Versions) && propertyName != nameof(SelectedVersion);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-03-07 10:38:56 +01:00
|
|
|
|
public virtual void VoiceMeeterVersionChanged()
|
|
|
|
|
{
|
|
|
|
|
UpdateSelectedVersion();
|
|
|
|
|
OnDependantPropertyChanged(nameof(SelectedVersion));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-03-06 10:53:38 +01:00
|
|
|
|
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
|
|
|
|
{
|
|
|
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
|
|
|
}
|
2021-03-07 10:38:56 +01:00
|
|
|
|
|
|
|
|
|
protected virtual void OnDependantPropertyChanged(string propertyName)
|
|
|
|
|
{
|
|
|
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public virtual void Dispose()
|
|
|
|
|
{
|
|
|
|
|
Disposed?.Invoke(this, EventArgs.Empty);
|
|
|
|
|
}
|
2021-03-06 10:53:38 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class VoiceMeeterVersionViewModel
|
|
|
|
|
{
|
|
|
|
|
public RunVoicemeeterParam Version { get; }
|
|
|
|
|
public string DisplayName { get; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public VoiceMeeterVersionViewModel(RunVoicemeeterParam version, string displayName)
|
|
|
|
|
{
|
|
|
|
|
Version = version;
|
|
|
|
|
DisplayName = displayName;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|