Cross Platform Application to allow control with a MIDI controller
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.4 KiB

// Author: Simon Gockner
// Created: 2021-04-10
// Copyright(c) 2021 SimonG. All Rights Reserved.
using System.Runtime.InteropServices;
using Lib.Audio.Interfaces;
using NAudio.CoreAudioApi;
namespace Lib.Audio
{
public class MasterControllable : IMasterControllable
{
private readonly AudioEndpointVolume _audioEndpointVolume;
private readonly string _name;
public MasterControllable(AudioEndpointVolume audioEndpointVolume, string name)
{
_audioEndpointVolume = audioEndpointVolume;
_name = name;
}
public void SetVolume(float volume)
{
try
{
_audioEndpointVolume.MasterVolumeLevelScalar = volume;
}
catch (InvalidComObjectException)
{
// MasterControllable? masterControllable = _controllableCollector.Controllables.OfType<MasterControllable>().FirstOrDefault(c => c.Equals(this));
// if (masterControllable != null)
// masterControllable._audioEndpointVolume.MasterVolumeLevelScalar = volume;
}
catch (COMException)
{
}
}
public void Mute() => _audioEndpointVolume.Mute = true;
public void UnMute() => _audioEndpointVolume.Mute = false;
public override string ToString() => _name;
}
}