Skip to content

Commit

Permalink
Added Input Adjustments and Mute.
Browse files Browse the repository at this point in the history
  • Loading branch information
oddbear committed Aug 5, 2022
1 parent c18689c commit 044b4be
Show file tree
Hide file tree
Showing 5 changed files with 279 additions and 21 deletions.
127 changes: 127 additions & 0 deletions WaveLinkPlugin/Adjustments/InputMonitorMixAdjustment.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
using System;
using System.Collections.Generic;
using System.Linq;
using ElgatoWaveSDK;
using ElgatoWaveSDK.Models;

namespace Loupedeck.WaveLinkPlugin.Adjustments
{
class InputMonitorMixAdjustment : PluginDynamicAdjustment
{
private WaveLinkPlugin _plugin;
private ElgatoWaveClient _client;

private readonly Dictionary<string, ChannelInfo> _states;

public InputMonitorMixAdjustment()
: base(true, DeviceType.All)
{
this.DisplayName = "Input Monitor Volume";
this.GroupName = "";
this.Description = "Input Monitor Volume and mute";

this.MakeProfileAction("list;Input:");

_states = new Dictionary<string, ChannelInfo>();
}

protected override bool OnLoad()
{
_plugin = (WaveLinkPlugin)base.Plugin;
_client = _plugin.Client;

_client.InputMixerChanged += InputMixerChanged;

return true;
}

protected override bool OnUnload()
{
_client.InputMixerChanged -= InputMixerChanged;

return true;
}

private void InputMixerChanged(object sender, ChannelInfo channelInfo)
{
if (channelInfo?.MixId is null)
return;

_states[channelInfo.MixId] = channelInfo;
}

protected override PluginActionParameter[] GetParameters()
{
if (!_client.IsConnected)
return Array.Empty<PluginActionParameter>();

return _states.Values
.Select(channelInfo => new PluginActionParameter($"inputMonitor|{channelInfo.MixId}", channelInfo.MixerName, string.Empty))
.ToArray();
}


protected override void RunCommand(string actionParameter)
{
if (actionParameter is null || !_client.IsConnected)
return;

var mixId = actionParameter.Split('|')[1];

if(!_states.TryGetValue(mixId, out var inputMix))
return;

inputMix.IsLocalInMuted = !inputMix.IsLocalInMuted;
inputMix.IsLocalInMuted = _client.SetInputMixer(inputMix, MixType.LocalMix)
.GetAwaiter()
.GetResult()
?.IsLocalInMuted;

base.ActionImageChanged();
}

protected override void ApplyAdjustment(string actionParameter, int diff)
{
if (actionParameter is null || _states is null)
return;

var mixId = actionParameter.Split('|')[1];
if (!_states.TryGetValue(mixId, out var inputMix))
return;

var volume = inputMix.LocalVolumeIn;

volume += diff;

if (volume < 0)
volume = 0;

if (volume > 100)
volume = 100;

inputMix.LocalVolumeIn = volume;
inputMix.LocalVolumeIn = _client.SetInputMixer(inputMix, MixType.LocalMix)
.GetAwaiter().GetResult()
?.LocalVolumeIn;

base.AdjustmentValueChanged(actionParameter);
}

protected override string GetAdjustmentValue(string actionParameter)
{
if (actionParameter is null || _states is null)
return "-";

var mixId = actionParameter.Split('|')[1];
if (!_states.TryGetValue(mixId, out var inputMix))
return "-";

if (inputMix.IsLocalInMuted is true)
return "muted";

var volume = inputMix.LocalVolumeIn;

return $"{volume:0}";
}
}
}
126 changes: 126 additions & 0 deletions WaveLinkPlugin/Adjustments/InputStreamMixAdjustment.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
using System;
using System.Collections.Generic;
using System.Linq;
using ElgatoWaveSDK;
using ElgatoWaveSDK.Models;

namespace Loupedeck.WaveLinkPlugin.Adjustments
{
class InputStreamMixAdjustment : PluginDynamicAdjustment
{
private WaveLinkPlugin _plugin;
private ElgatoWaveClient _client;

private readonly Dictionary<string, ChannelInfo> _states;

public InputStreamMixAdjustment()
: base(true, DeviceType.All)
{
this.DisplayName = "Input Stream Volume";
this.GroupName = "";
this.Description = "Input Stream Volume and mute";

this.MakeProfileAction("list;Input:");

_states = new Dictionary<string, ChannelInfo>();
}

protected override bool OnLoad()
{
_plugin = (WaveLinkPlugin)base.Plugin;
_client = _plugin.Client;

_client.InputMixerChanged += InputMixerChanged;

return true;
}

protected override bool OnUnload()
{
_client.InputMixerChanged -= InputMixerChanged;

return true;
}

private void InputMixerChanged(object sender, ChannelInfo channelInfo)
{
if (channelInfo?.MixId is null)
return;

_states[channelInfo.MixId] = channelInfo;
}

protected override PluginActionParameter[] GetParameters()
{
if (!_client.IsConnected)
return Array.Empty<PluginActionParameter>();

return _states.Values
.Select(input => new PluginActionParameter($"inputStream|{input.MixId}", input.MixerName, string.Empty))
.ToArray();
}

protected override void RunCommand(string actionParameter)
{
if (actionParameter is null || !_client.IsConnected)
return;

var mixId = actionParameter.Split('|')[1];

if (!_states.TryGetValue(mixId, out var inputMix))
return;

inputMix.IsStreamInMuted = !inputMix.IsStreamInMuted;
inputMix.IsStreamInMuted = _client.SetInputMixer(inputMix, MixType.StreamMix)
.GetAwaiter()
.GetResult()
?.IsStreamInMuted;

base.ActionImageChanged();
}

protected override void ApplyAdjustment(string actionParameter, int diff)
{
if (actionParameter is null || _states is null)
return;

var mixId = actionParameter.Split('|')[1];
if (!_states.TryGetValue(mixId, out var inputMix))
return;

var volume = inputMix.StreamVolumeIn;

volume += diff;

if (volume < 0)
volume = 0;

if (volume > 100)
volume = 100;

inputMix.StreamVolumeIn = volume;
inputMix.StreamVolumeIn = _client.SetInputMixer(inputMix, MixType.StreamMix)
.GetAwaiter().GetResult()
?.StreamVolumeIn;

base.AdjustmentValueChanged(actionParameter);
}

protected override string GetAdjustmentValue(string actionParameter)
{
if (actionParameter is null || _states is null)
return "-";

var mixId = actionParameter.Split('|')[1];
if (!_states.TryGetValue(mixId, out var inputMix))
return "-";

if (inputMix.IsLocalInMuted is true)
return "muted";

var volume = inputMix.LocalVolumeIn;

return $"{volume:0}";
}
}
}
35 changes: 14 additions & 21 deletions WaveLinkPlugin/Commands/SetOutputMonitorMixCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,6 @@ private void LocalMonitorOutputChanged(object sender, string monitorMix)
//Needs to update all of them...
base.ActionImageChanged();
}

//------------------------------------
// Command: Get/Set Monitor mix
//------------------------------------
//var mixType = await client.GetSwitchState();
//client.SetMonitoringState(MixType.LocalMix); //Set listen (ear) to local mix
//client.SetMonitoringState(MixType.StreamMix); //Set listen (ear) to stream mix

protected override void RunCommand(string actionParameter)
{
if (actionParameter is null || !_client.IsConnected)
return;

var monitorMix = actionParameter.Split('|')[1];
_monitorMix = _client.SetMonitorMixOutput(monitorMix)
.GetAwaiter().GetResult()
.MonitorMix;

base.ActionImageChanged();
}

protected override PluginActionParameter[] GetParameters()
{
Expand All @@ -77,7 +57,7 @@ protected override PluginActionParameter[] GetParameters()
.GetResult()
//.MonitorMix //This is the selected one as string.
?.MonitorMixList;

if (monitorMixes is null)
return Array.Empty<PluginActionParameter>();

Expand All @@ -86,6 +66,19 @@ protected override PluginActionParameter[] GetParameters()
.Select(monitorMix => new PluginActionParameter($"monitorMix|{monitorMix}", monitorMix, string.Empty))
.ToArray();
}

protected override void RunCommand(string actionParameter)
{
if (actionParameter is null || !_client.IsConnected)
return;

var monitorMix = actionParameter.Split('|')[1];
_monitorMix = _client.SetMonitorMixOutput(monitorMix)
.GetAwaiter().GetResult()
.MonitorMix;

base.ActionImageChanged();
}

protected override BitmapImage GetCommandImage(string actionParameter, PluginImageSize imageSize)
{
Expand Down
10 changes: 10 additions & 0 deletions WaveLinkPlugin/WaveLinkPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ private async Task ConnectAsync()
var mixOutputList = await Client.GetMonitorMixOutputList();
if (mixOutputList?.MonitorMix != null)
Client.LocalMonitorOutputChanged?.Invoke(this, mixOutputList.MonitorMix);

var inputMixes = await Client.GetAllChannelInfo();
if (inputMixes != null)
{
foreach (var channelInfo in inputMixes)
{
Client.InputMixerChanged?.Invoke(this, channelInfo);
}
}

}
catch (Exception)
{
Expand Down
2 changes: 2 additions & 0 deletions WaveLinkPlugin/WaveLinkPlugin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Adjustments\InputMonitorMixAdjustment.cs" />
<Compile Include="Adjustments\InputStreamMixAdjustment.cs" />
<Compile Include="Adjustments\OutputMonitorMixAdjustment.cs" />
<Compile Include="Adjustments\OutputStreamMixAdjustment.cs" />
<Compile Include="Commands\SetOutputMonitorMixCommand.cs" />
Expand Down

0 comments on commit 044b4be

Please sign in to comment.