1
0
mirror of synced 2024-11-23 00:03:51 +00:00
MassiveKnob/Windows/MassiveKnob.Plugin.CoreAudio/GetMuted/DeviceGetMutedAction.cs
Mark van Renswoude 543b55f3ba Added support for analog outputs (basic PWM) to Arduino Sketch
Added support for binding digital output actions to analog outputs
Fixed a few NullReferenceExceptions
Fixed Serial "Connecting..." state
Fixed update issues when multiple VoiceMeeter output actions are configured
Fixed VoiceMeeter Remote not logging out
2021-03-08 20:18:47 +01:00

89 lines
3.0 KiB
C#

using System;
using System.Windows.Controls;
using AudioSwitcher.AudioApi;
using MassiveKnob.Plugin.CoreAudio.OSD;
using Microsoft.Extensions.Logging;
namespace MassiveKnob.Plugin.CoreAudio.GetMuted
{
public class DeviceGetMutedAction : IMassiveKnobAction
{
public Guid ActionId { get; } = new Guid("86646ca7-f472-4c5a-8d0f-7e5d2d162ab9");
public MassiveKnobActionType ActionType { get; } = MassiveKnobActionType.OutputDigital;
public string Name { get; } = Strings.GetMutedName;
public string Description { get; } = Strings.GetMutedDescription;
public IMassiveKnobActionInstance Create(ILogger logger)
{
return new Instance();
}
private class Instance : IMassiveKnobActionInstance
{
private IMassiveKnobActionContext actionContext;
private DeviceGetMutedActionSettings settings;
private IDevice playbackDevice;
private IDisposable deviceChanged;
public void Initialize(IMassiveKnobActionContext context)
{
actionContext = context;
settings = context.GetSettings<DeviceGetMutedActionSettings>();
ApplySettings();
}
public void Dispose()
{
deviceChanged?.Dispose();
}
private void ApplySettings()
{
if (playbackDevice == null || playbackDevice.Id != settings.DeviceId)
{
var coreAudioController = CoreAudioControllerInstance.Acquire();
playbackDevice = settings.DeviceId.HasValue
? coreAudioController.GetDevice(settings.DeviceId.Value)
: null;
deviceChanged?.Dispose();
deviceChanged = playbackDevice?.MuteChanged.Subscribe(MuteChanged);
}
if (playbackDevice != null)
actionContext.SetDigitalOutput(settings.Inverted ? !playbackDevice.IsMuted : playbackDevice.IsMuted);
}
public UserControl CreateSettingsControl()
{
var viewModel = new DeviceGetMutedActionSettingsViewModel(settings);
viewModel.PropertyChanged += (sender, args) =>
{
if (!viewModel.IsSettingsProperty(args.PropertyName))
return;
actionContext.SetSettings(settings);
ApplySettings();
};
return new DeviceGetMutedActionSettingsView(viewModel);
}
private void MuteChanged(DeviceMuteChangedArgs args)
{
actionContext.SetDigitalOutput(settings.Inverted ? !args.IsMuted : args.IsMuted);
if (settings.OSD)
OSDManager.Show(args.Device);
}
}
}
}