2021-03-06 10:53:38 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Voicemeeter;
|
|
|
|
|
|
|
|
|
|
namespace MassiveKnob.Plugin.VoiceMeeter.RunMacro
|
|
|
|
|
{
|
|
|
|
|
public class VoiceMeeterRunMacroAction : IMassiveKnobAction
|
|
|
|
|
{
|
|
|
|
|
public Guid ActionId { get; } = new Guid("3bf41e96-9418-4a0e-ba5f-580e0b94dcce");
|
|
|
|
|
public MassiveKnobActionType ActionType { get; } = MassiveKnobActionType.InputDigital;
|
|
|
|
|
public string Name { get; } = Strings.RunMacroName;
|
|
|
|
|
public string Description { get; } = Strings.RunMacroDescription;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public IMassiveKnobActionInstance Create(ILogger logger)
|
|
|
|
|
{
|
|
|
|
|
return new Instance();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private class Instance : IMassiveKnobDigitalAction, IVoiceMeeterAction
|
|
|
|
|
{
|
|
|
|
|
private IMassiveKnobActionContext actionContext;
|
|
|
|
|
private VoiceMeeterRunMacroActionSettings settings;
|
2021-03-07 10:38:56 +01:00
|
|
|
|
private VoiceMeeterRunMacroActionSettingsViewModel viewModel;
|
2021-03-06 10:53:38 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void Initialize(IMassiveKnobActionContext context)
|
|
|
|
|
{
|
|
|
|
|
actionContext = context;
|
|
|
|
|
settings = context.GetSettings<VoiceMeeterRunMacroActionSettings>();
|
|
|
|
|
|
|
|
|
|
InstanceRegister.Register(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
InstanceRegister.Unregister(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public UserControl CreateSettingsControl()
|
|
|
|
|
{
|
2021-03-07 10:38:56 +01:00
|
|
|
|
viewModel = new VoiceMeeterRunMacroActionSettingsViewModel(settings);
|
2021-03-06 10:53:38 +01:00
|
|
|
|
viewModel.PropertyChanged += (sender, args) =>
|
|
|
|
|
{
|
|
|
|
|
if (!viewModel.IsSettingsProperty(args.PropertyName))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
actionContext.SetSettings(settings);
|
|
|
|
|
};
|
|
|
|
|
|
2021-03-07 10:38:56 +01:00
|
|
|
|
viewModel.Disposed += (sender, args) =>
|
|
|
|
|
{
|
|
|
|
|
if (sender == viewModel)
|
|
|
|
|
viewModel = null;
|
|
|
|
|
};
|
|
|
|
|
|
2021-03-06 10:53:38 +01:00
|
|
|
|
return new VoiceMeeterRunMacroActionSettingsView(viewModel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public async ValueTask DigitalChanged(bool on)
|
|
|
|
|
{
|
|
|
|
|
if (!on)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (settings.Version == RunVoicemeeterParam.None || string.IsNullOrEmpty(settings.Script))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
await InstanceRegister.InitializeVoicemeeter();
|
|
|
|
|
global::VoiceMeeter.Remote.SetParameters(settings.Script);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void VoiceMeeterVersionChanged()
|
|
|
|
|
{
|
2021-03-07 10:38:56 +01:00
|
|
|
|
viewModel?.VoiceMeeterVersionChanged();
|
2021-03-06 10:53:38 +01:00
|
|
|
|
actionContext.SetSettings(settings);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|