Skip to content

Commit

Permalink
Changed to Parameters instead of Profile Actions.
Browse files Browse the repository at this point in the history
  • Loading branch information
oddbear committed Aug 7, 2022
1 parent 6c53d7b commit 5efe652
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 113 deletions.
73 changes: 43 additions & 30 deletions WaveLinkPlugin/Adjustments/InputMonitorMixAdjustment.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using ElgatoWaveSDK;
using ElgatoWaveSDK.Models;
Expand All @@ -16,59 +15,75 @@ class InputMonitorMixAdjustment : PluginDynamicAdjustment
public InputMonitorMixAdjustment()
: base(true)
{
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;
_plugin.AllChannelInfoFetched += PluginOnAllChannelInfoFetched;

_client = _plugin.Client;
_client.InputMixerChanged += InputMixerChanged;

return true;
}

protected override bool OnUnload()
{
_plugin.AllChannelInfoFetched -= PluginOnAllChannelInfoFetched;

_client.InputMixerChanged -= InputMixerChanged;

return true;
}

private void InputMixerChanged(object sender, ChannelInfo channelInfo)
private void PluginOnAllChannelInfoFetched(object sender, IEnumerable<ChannelInfo> channels)
{
if (channelInfo?.MixId is null)
if (channels is null)
return;

_states[channelInfo.MixId] = channelInfo;
}
var parameters = base.GetParameters()
.Select(parameter => parameter.Name)
.ToArray();

protected override PluginActionParameter[] GetParameters()
{
if (!_client.IsConnected)
return Array.Empty<PluginActionParameter>();
foreach (var channelInfo in channels)
{
if (channelInfo?.MixId is null)
continue;

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

_states[channelInfo.MixId] = channelInfo;

var monitorMixName = channelInfo.MixId;
if (string.IsNullOrWhiteSpace(monitorMixName))
continue;

if (parameters.Contains(monitorMixName))
continue;

base.AddParameter(channelInfo.MixId, channelInfo.MixerName, "Input Volume (Monitor)");
}
}

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

_states[channelInfo.MixId] = channelInfo;

base.ActionImageChanged(channelInfo.MixId);
}

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))

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

inputMix.IsLocalInMuted = !inputMix.IsLocalInMuted;
Expand All @@ -84,9 +99,8 @@ 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))

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

var volume = inputMix.LocalVolumeIn;
Expand All @@ -111,9 +125,8 @@ 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))

if (!_states.TryGetValue(actionParameter, out var inputMix))
return "-";

if (inputMix.IsLocalInMuted is true)
Expand Down
74 changes: 44 additions & 30 deletions WaveLinkPlugin/Adjustments/InputStreamMixAdjustment.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using ElgatoWaveSDK;
using ElgatoWaveSDK.Models;
Expand All @@ -16,58 +15,75 @@ class InputStreamMixAdjustment : PluginDynamicAdjustment
public InputStreamMixAdjustment()
: base(true)
{
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;
_plugin.AllChannelInfoFetched += PluginOnAllChannelInfoFetched;

_client = _plugin.Client;
_client.InputMixerChanged += InputMixerChanged;

return true;
}

protected override bool OnUnload()
{
_plugin.AllChannelInfoFetched -= PluginOnAllChannelInfoFetched;

_client.InputMixerChanged -= InputMixerChanged;

return true;
}
private void InputMixerChanged(object sender, ChannelInfo channelInfo)

private void PluginOnAllChannelInfoFetched(object sender, IEnumerable<ChannelInfo> channels)
{
if (channelInfo?.MixId is null)
if (channels is null)
return;

_states[channelInfo.MixId] = channelInfo;
var parameters = base.GetParameters()
.Select(parameter => parameter.Name)
.ToArray();

foreach (var channelInfo in channels)
{
if (channelInfo?.MixId is null)
continue;

if (_states.ContainsKey(channelInfo.MixId))
continue;

_states[channelInfo.MixId] = channelInfo;

var monitorMixName = channelInfo.MixId;
if (string.IsNullOrWhiteSpace(monitorMixName))
continue;

if (parameters.Contains(monitorMixName))
continue;

base.AddParameter(channelInfo.MixId, channelInfo.MixerName, "Input Volume (Stream)");
}
}

protected override PluginActionParameter[] GetParameters()
private void InputMixerChanged(object sender, ChannelInfo channelInfo)
{
if (!_client.IsConnected)
return Array.Empty<PluginActionParameter>();
if (channelInfo?.MixId is null)
return;

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

base.ActionImageChanged(channelInfo.MixId);
}

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))

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

inputMix.IsStreamInMuted = !inputMix.IsStreamInMuted;
Expand All @@ -83,9 +99,8 @@ 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))

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

var volume = inputMix.StreamVolumeIn;
Expand All @@ -110,9 +125,8 @@ 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))

if (!_states.TryGetValue(actionParameter, out var inputMix))
return "-";

if (inputMix.IsLocalInMuted is true)
Expand Down
5 changes: 4 additions & 1 deletion WaveLinkPlugin/Adjustments/OutputMonitorMixAdjustment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class OutputMonitorMixAdjustment : PluginDynamicAdjustment
private MonitoringState _state;

public OutputMonitorMixAdjustment()
: base("Monitor Mix Volume", "Adjustment for Monitor Mix Output Volume and Mute", "Outputs", true)
: base("Monitor Mix Volume", "Adjustment for Monitor Mix Output Volume and Mute", "Output Volume", true)
{
//
}
Expand All @@ -35,6 +35,9 @@ protected override bool OnUnload()

private void OutputMixerChanged(object sender, MonitoringState state)
{
if (state is null)
return;

_state = state;

base.AdjustmentValueChanged();
Expand Down
5 changes: 4 additions & 1 deletion WaveLinkPlugin/Adjustments/OutputStreamMixAdjustment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class OutputStreamMixAdjustment : PluginDynamicAdjustment
private MonitoringState _state;

public OutputStreamMixAdjustment()
: base("Stream Mix Volume", "Adjustment for Stream Mix Output Volume and Mute", "Outputs", true)
: base("Stream Mix Volume", "Adjustment for Stream Mix Output Volume and Mute", "Output Volume", true)
{
//
}
Expand All @@ -35,6 +35,9 @@ protected override bool OnUnload()

private void OutputMixerChanged(object sender, MonitoringState state)
{
if (state is null)
return;

_state = state;

base.AdjustmentValueChanged();
Expand Down
Loading

0 comments on commit 5efe652

Please sign in to comment.