2021-02-21 13:04:24 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Controls;
|
2021-02-24 08:05:11 +00:00
|
|
|
|
using AudioSwitcher.AudioApi;
|
2021-02-24 18:35:01 +00:00
|
|
|
|
using MassiveKnob.Plugin.CoreAudio.OSD;
|
2021-02-21 13:04:24 +00:00
|
|
|
|
|
2021-02-24 18:35:01 +00:00
|
|
|
|
namespace MassiveKnob.Plugin.CoreAudio.SetMuted
|
2021-02-21 13:04:24 +00:00
|
|
|
|
{
|
2021-02-24 18:35:01 +00:00
|
|
|
|
public class DeviceSetMutedAction : IMassiveKnobAction
|
2021-02-21 13:04:24 +00:00
|
|
|
|
{
|
2021-02-24 18:35:01 +00:00
|
|
|
|
public Guid ActionId { get; } = new Guid("032eb405-a1df-4178-b2d5-6cf556305a8c");
|
|
|
|
|
public MassiveKnobActionType ActionType { get; } = MassiveKnobActionType.InputDigital;
|
|
|
|
|
public string Name { get; } = Strings.SetMutedName;
|
|
|
|
|
public string Description { get; } = Strings.SetMutedDescription;
|
2021-02-21 13:04:24 +00:00
|
|
|
|
|
|
|
|
|
|
2021-02-24 08:05:11 +00:00
|
|
|
|
public IMassiveKnobActionInstance Create()
|
2021-02-21 13:04:24 +00:00
|
|
|
|
{
|
2021-02-24 08:05:11 +00:00
|
|
|
|
return new Instance();
|
2021-02-21 13:04:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-02-24 18:35:01 +00:00
|
|
|
|
private class Instance : IMassiveKnobDigitalAction
|
2021-02-21 13:04:24 +00:00
|
|
|
|
{
|
2021-02-24 08:05:11 +00:00
|
|
|
|
private IMassiveKnobActionContext actionContext;
|
2021-02-24 18:35:01 +00:00
|
|
|
|
private DeviceSetMutedActionSettings settings;
|
2021-02-24 08:05:11 +00:00
|
|
|
|
private IDevice playbackDevice;
|
2021-02-21 13:04:24 +00:00
|
|
|
|
|
2021-02-24 08:05:11 +00:00
|
|
|
|
|
|
|
|
|
public void Initialize(IMassiveKnobActionContext context)
|
2021-02-21 13:04:24 +00:00
|
|
|
|
{
|
2021-02-24 08:05:11 +00:00
|
|
|
|
actionContext = context;
|
2021-02-24 18:35:01 +00:00
|
|
|
|
settings = context.GetSettings<DeviceSetMutedActionSettings>();
|
2021-02-24 08:05:11 +00:00
|
|
|
|
ApplySettings();
|
2021-02-21 13:04:24 +00:00
|
|
|
|
}
|
2021-02-24 08:05:11 +00:00
|
|
|
|
|
2021-02-21 13:04:24 +00:00
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-24 08:05:11 +00:00
|
|
|
|
|
|
|
|
|
private void ApplySettings()
|
2021-02-21 13:04:24 +00:00
|
|
|
|
{
|
2021-02-24 08:05:11 +00:00
|
|
|
|
var coreAudioController = CoreAudioControllerInstance.Acquire();
|
|
|
|
|
playbackDevice = settings.DeviceId.HasValue ? coreAudioController.GetDevice(settings.DeviceId.Value) : null;
|
2021-02-21 13:04:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-02-24 08:05:11 +00:00
|
|
|
|
public UserControl CreateSettingsControl()
|
2021-02-21 13:04:24 +00:00
|
|
|
|
{
|
2021-02-24 18:35:01 +00:00
|
|
|
|
var viewModel = new DeviceSetMutedActionSettingsViewModel(settings);
|
2021-02-24 08:05:11 +00:00
|
|
|
|
viewModel.PropertyChanged += (sender, args) =>
|
|
|
|
|
{
|
|
|
|
|
if (!viewModel.IsSettingsProperty(args.PropertyName))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
actionContext.SetSettings(settings);
|
|
|
|
|
ApplySettings();
|
|
|
|
|
};
|
2021-02-21 13:04:24 +00:00
|
|
|
|
|
2021-02-24 18:35:01 +00:00
|
|
|
|
return new DeviceSetMutedActionSettingsView(viewModel);
|
2021-02-24 08:05:11 +00:00
|
|
|
|
}
|
2021-02-21 13:04:24 +00:00
|
|
|
|
|
2021-02-24 08:05:11 +00:00
|
|
|
|
|
2021-02-24 18:35:01 +00:00
|
|
|
|
public async ValueTask DigitalChanged(bool on)
|
2021-02-24 08:05:11 +00:00
|
|
|
|
{
|
|
|
|
|
if (playbackDevice == null)
|
|
|
|
|
return;
|
2021-02-24 18:35:01 +00:00
|
|
|
|
|
|
|
|
|
if (settings.Toggle)
|
|
|
|
|
{
|
|
|
|
|
if (!on)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
await playbackDevice.SetMuteAsync(!playbackDevice.IsMuted);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
await playbackDevice.SetMuteAsync(settings.SetInverted ? !on : on);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (settings.OSD)
|
|
|
|
|
OSDManager.Show(playbackDevice);
|
2021-02-24 08:05:11 +00:00
|
|
|
|
}
|
2021-02-21 13:04:24 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|