Skip to content

Commit

Permalink
Merge pull request #68 from BarRaider/advanced_logic
Browse files Browse the repository at this point in the history
v2.1 - Advanced Queries + SD+ support
  • Loading branch information
BarRaider committed Jan 22, 2023
2 parents 2cb94cf + fbe91dc commit 524ee8e
Show file tree
Hide file tree
Showing 33 changed files with 1,228 additions and 362 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ VoiceMeeter integration and live feedback for the Elgato Stream Deck device.

**Author's website and contact information:** [https://barraider.com](https://barraider.com)

## New in v2.1
- **Advanced Queries Support** - The `Advanced Toggle` action's `Mode1 Check` now supports performing complex queries with `==` and `!=` as well as `AND/OR`.
- Example: `Strip[0].Mute AND Strip[1].Gain==7.5 AND Strip[2].device.name!="Elgato Wave"`

- 🆕 **Stream Deck+ Support **
- New `Gain Adjust` action allows you to control the volume of a Strip/Bus from the Dials. Pressing the dial will toggle mute.
- New `Setting Adjust` action allows you to control the main dials (Comp/Gate/Denoiser/Reverb/Delay...) from the Dials.
- The topmost "Title" property has been disabled and you can now use the (lower) Title Property's `-User Defined-` logic to put a manual title using the ` Title Prefix` field
- 64bit runtime optimization with VoiceMeeter's DLLs

## New in v1.9
- :new: **MacroButton support!** Toggle VoiceMeeter Macro Buttons from the Stream Deck
- Supports both "Toggle" mode and "PTT" mode.
Expand Down
20 changes: 13 additions & 7 deletions VoiceMeeter.sln
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.106
# Visual Studio Version 17
VisualStudioVersion = 17.4.33205.214
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VoiceMeeter", "VoiceMeeter\VoiceMeeter.csproj", "{A35FB18D-7867-4F77-A9F3-863BF6F18C6F}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VoiceMeeter", "VoiceMeeter\VoiceMeeter.csproj", "{0D702B80-1750-4153-9DCC-1594D2CD46CC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A35FB18D-7867-4F77-A9F3-863BF6F18C6F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A35FB18D-7867-4F77-A9F3-863BF6F18C6F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A35FB18D-7867-4F77-A9F3-863BF6F18C6F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A35FB18D-7867-4F77-A9F3-863BF6F18C6F}.Release|Any CPU.Build.0 = Release|Any CPU
{0D702B80-1750-4153-9DCC-1594D2CD46CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0D702B80-1750-4153-9DCC-1594D2CD46CC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0D702B80-1750-4153-9DCC-1594D2CD46CC}.Debug|x64.ActiveCfg = Debug|x64
{0D702B80-1750-4153-9DCC-1594D2CD46CC}.Debug|x64.Build.0 = Debug|x64
{0D702B80-1750-4153-9DCC-1594D2CD46CC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0D702B80-1750-4153-9DCC-1594D2CD46CC}.Release|Any CPU.Build.0 = Release|Any CPU
{0D702B80-1750-4153-9DCC-1594D2CD46CC}.Release|x64.ActiveCfg = Release|x64
{0D702B80-1750-4153-9DCC-1594D2CD46CC}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
18 changes: 9 additions & 9 deletions VoiceMeeter/Actions/VMAdvancedPTTAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace VoiceMeeter
{
[PluginActionId("com.barraider.vmadvancedptt")]
public class VMAdvancedPTTAction : PluginBase
public class VMAdvancedPTTAction : KeypadBase
{
private class PluginSettings
{
Expand Down Expand Up @@ -139,15 +139,12 @@ public async override void OnTick()
await Connection.SetImageAsync((String)null);
}


string titlePrefix = settings.TitlePrefix?.Replace(@"\n", "\n");
string value = String.Empty;
if (settings.TitleType == TitleTypeEnum.VMLive && !String.IsNullOrEmpty(settings.TitleParam))
{
string prefix = String.Empty;
if (!String.IsNullOrEmpty(settings.TitlePrefix))
{
prefix = settings.TitlePrefix.Replace(@"\n", "\n");
}

string value = VMManager.Instance.GetParam(settings.TitleParam);
value = VMManager.Instance.GetParam(settings.TitleParam);
if (!String.IsNullOrEmpty(settings.EnabledText) && !String.IsNullOrEmpty(value) && value == Constants.ENABLED_VALUE)
{
value = settings.EnabledText;
Expand All @@ -156,8 +153,11 @@ public async override void OnTick()
{
value = settings.DisabledText;
}
}

await Connection.SetTitleAsync($"{prefix}{value}");
if (!String.IsNullOrEmpty($"{titlePrefix}{value}"))
{
await Connection.SetTitleAsync($"{titlePrefix}{value}");
}
}

Expand Down
17 changes: 8 additions & 9 deletions VoiceMeeter/Actions/VMAdvancedPressAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace VoiceMeeter
{
[PluginActionId("com.barraider.vmadvanced")]
class VMAdvancedPressAction : PluginBase
class VMAdvancedPressAction : KeypadBase
{
private class PluginSettings
{
Expand Down Expand Up @@ -183,15 +183,11 @@ public async override void OnTick()
await Connection.SetImageAsync((String)null);
}

string titlePrefix = settings.TitlePrefix?.Replace(@"\n", "\n");
string value = String.Empty;
if (settings.TitleType == TitleTypeEnum.VMLive && !String.IsNullOrEmpty(settings.TitleParam))
{
string prefix = String.Empty;
if (!String.IsNullOrEmpty(settings.TitlePrefix))
{
prefix = settings.TitlePrefix.Replace(@"\n", "\n");
}

string value = VMManager.Instance.GetParam(settings.TitleParam);
value = VMManager.Instance.GetParam(settings.TitleParam);
if (!String.IsNullOrEmpty(settings.EnabledText) && !String.IsNullOrEmpty(value) && value == Constants.ENABLED_VALUE)
{
value = settings.EnabledText;
Expand All @@ -200,8 +196,11 @@ public async override void OnTick()
{
value = settings.DisabledText;
}
}

await Connection.SetTitleAsync($"{prefix}{value}");
if (!String.IsNullOrEmpty($"{titlePrefix}{value}"))
{
await Connection.SetTitleAsync($"{titlePrefix}{value}");
}
}

Expand Down
103 changes: 88 additions & 15 deletions VoiceMeeter/Actions/VMAdvancedToggle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace VoiceMeeter
// Subscriber: brandoncc2 x2 Gifted subs
//---------------------------------------------------
[PluginActionId("com.barraider.vmadvancedtoggle")]
class VMAdvancedToggleAction : PluginBase
class VMAdvancedToggleAction : KeypadBase
{
private class PluginSettings
{
Expand Down Expand Up @@ -100,6 +100,7 @@ public static PluginSettings CreateDefaultSettings()
#region Private members
private const string LOGICAL_AND = " AND ";
private const string LOGICAL_OR = " OR ";
private readonly string[] LOGICAL_COMP_OPERATORS = { "==", "!=" };

private readonly PluginSettings settings;
private bool didSetNotConnected = false;
Expand Down Expand Up @@ -136,7 +137,7 @@ public async override void KeyPressed(KeyPayload payload)
return;
}

bool isMode1 = IsMode1(true);
bool isMode1 = IsMode1LogicTrue(true, true);
if (isMode1) // Currently in Mode1, so run Mode2 commands
{
if (!String.IsNullOrEmpty(settings.Mode2Value))
Expand Down Expand Up @@ -182,7 +183,7 @@ public async override void OnTick()
}

// Set the image
if (!String.IsNullOrEmpty(settings.UserImage1) && IsMode1(false))
if (!String.IsNullOrEmpty(settings.UserImage1) && IsMode1LogicTrue(false, false))
{
await Connection.SetImageAsync(Tools.FileToBase64(settings.UserImage1.ToString(), true));
}
Expand All @@ -192,15 +193,11 @@ public async override void OnTick()
}

// Set the title
string titlePrefix = settings.TitlePrefix?.Replace(@"\n", "\n");
string value = String.Empty;
if (settings.TitleType == TitleTypeEnum.VMLive && !String.IsNullOrEmpty(settings.TitleParam))
{
string prefix = String.Empty;
if (!String.IsNullOrEmpty(settings.TitlePrefix))
{
prefix = settings.TitlePrefix.Replace(@"\n", "\n");
}

string value = VMManager.Instance.GetParam(settings.TitleParam);
value = VMManager.Instance.GetParam(settings.TitleParam);
if (!String.IsNullOrEmpty(settings.EnabledText) && !String.IsNullOrEmpty(value) && value == Constants.ENABLED_VALUE)
{
value = settings.EnabledText.Replace(@"\n", "\n"); ;
Expand All @@ -209,8 +206,11 @@ public async override void OnTick()
{
value = settings.DisabledText.Replace(@"\n", "\n"); ;
}
}

await Connection.SetTitleAsync($"{prefix}{value}");
if (!String.IsNullOrEmpty($"{titlePrefix}{value}"))
{
await Connection.SetTitleAsync($"{titlePrefix}{value}");
}
}

Expand All @@ -233,8 +233,14 @@ public async override void ReceivedSettings(ReceivedSettingsPayload payload)

#region Private Methods

private bool IsMode1(bool shouldLog)
private string RemoveQuotes(string str)
{
return str.Trim().Trim('"');
}

private bool IsMode1LogicTrue(bool shouldLog, bool keyPressed)
{

if (String.IsNullOrEmpty(settings.Mode1Param))
{
return false;
Expand All @@ -257,7 +263,7 @@ private bool IsMode1(bool shouldLog)
foreach (string clause in clauses)
{
// If even one of them is false, that's enough to return a false
if (!VMManager.Instance.GetParamBool(clause.Trim()))
if (!EvaluateClause(clause.Trim()))
{
if (shouldLog)
{
Expand All @@ -274,7 +280,7 @@ private bool IsMode1(bool shouldLog)
foreach (string clause in clauses)
{
// If ANY clause is true, that's enough to return a true
if (VMManager.Instance.GetParamBool(clause.Trim()))
if (EvaluateClause(clause.Trim()))
{
if (shouldLog)
{
Expand All @@ -287,7 +293,7 @@ private bool IsMode1(bool shouldLog)
}
else // Only one clause
{
return VMManager.Instance.GetParamBool(settings.Mode1Param);
return EvaluateClause(settings.Mode1Param);
}

}
Expand All @@ -312,6 +318,73 @@ private void InitializeSettings()
}
}

private bool EvaluateClause(string clause)
{
// TODO: Check if clause starts with $ and if so, split it and compare to clauses
if (LOGICAL_COMP_OPERATORS.Any(op => clause.Contains(op)))
{
return HandleEQClause(clause);
}
return VMManager.Instance.GetParamBool(clause);
}

private bool EvaluateEQClause(string splitSeperator, string clause)
{
var splitClause = clause.Split(new string[] { splitSeperator }, StringSplitOptions.RemoveEmptyEntries);

if (splitClause.Length != 2)
{
Logger.Instance.LogMessage(TracingLevel.ERROR, $"{this.GetType()} Invalid clause: {clause} with logical operator: {splitSeperator}");
return false;
}

string termValue = VMManager.Instance.GetParamString(splitClause[0].Trim());
string compareValue = RemoveQuotes(splitClause[1]);

// Normal string comparison
if (termValue == compareValue)
{
return true;
}

// Numeric comparison
if (double.TryParse(termValue, out double value1) && double.TryParse(compareValue, out double value2) && value1 == value2)
{
return true;
}

// Substring comparison
if (termValue.Length >= compareValue.Length && termValue.Substring(0,compareValue.Length) == compareValue)
{
return true;
}

return false;
}

private bool HandleEQClause(string clause)
{
// Figure out which logical operator we are using...
// Then split the string based on that

if (clause.Contains("=="))
{
bool result = EvaluateEQClause("==", clause);
return (result == true);
}
else if (clause.Contains("!="))
{
bool result = EvaluateEQClause("!=", clause);
return (result == false);
}
else
{
Logger.Instance.LogMessage(TracingLevel.ERROR, $"No matching comparison operator: only supports == and !=");
}

return false;
}

#endregion
}
}
Loading

0 comments on commit 524ee8e

Please sign in to comment.