From 770b9cf6631bc57ccd8175e645c8e27a3dc3f448 Mon Sep 17 00:00:00 2001 From: Onyx and Iris <75868496+onyx-and-iris@users.noreply.github.com> Date: Sun, 2 May 2021 17:32:04 +0100 Subject: [PATCH] add support for mb params in multi_set Add support for mb params in multi_set. Updated changelog to document addition --- CHANGELOG.md | 1 + example.ps1 | 18 +++++++++++++++++- lib/base.ps1 | 46 ++++++++++++++++++++++++++++++++++++---------- 3 files changed, 54 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ffe60a3..c00ab9c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ Before any minor/major patch is released all test units will be run to verify th - [x] Update tests to reflect changes - [x] Add logging + summary for tests - [x] Add info to README about powershellget, nuget and psgallery +- [x] Support other types of params in multi_set ## [1.3] - 2021-04-30 ### Added diff --git a/example.ps1 b/example.ps1 index 48e8bbf..6c43175 100644 --- a/example.ps1 +++ b/example.ps1 @@ -24,5 +24,21 @@ try { } $vmr.Set_Multi($hash) + + $hash = @{ + "mb_0.state" = $true + "mb_1.state" = $true + "mb_2.state" = $true + } + + $vmr.Set_Multi($hash) + + $hash = @{ + "mb_0.state" = $false + "mb_1.state" = $false + "mb_2.state" = $false + } + + $vmr.Set_Multi($hash) } -finally { $vmr.Logout() } \ No newline at end of file +finally { $vmr.Logout() } diff --git a/lib/base.ps1 b/lib/base.ps1 index 44cccca..b84a6f5 100644 --- a/lib/base.ps1 +++ b/lib/base.ps1 @@ -47,23 +47,49 @@ Function Param_Set_Multi { ) Start-Sleep -m 50 while(M_Dirty) { Start-Sleep -m 1 } - [string[]]$params = ($HASH | out-string -stream) -ne '' | Select-Object -Skip 2 - [String]$cmd = [String]::new(512) + $cmd_channel = [String]::new(512) + $cmd_mb = @( + ,@() + ) ForEach ($line in $params) { if($line.Trim() -Match "(^\w+)\[(\d)\].(\w+)\s+(\w+)") { - if($Matches[4] -eq "True") { $val = [String]1 } else { $val = [String]0 } - $cmd += "$($Matches[1])[$($Matches[2])].$($Matches[3])=$val;" + if($Matches[4] -eq "True") { $val = 1 } else { $val = 0 } + [String]$cmd_channel += "$($Matches[1])[$($Matches[2])].$($Matches[3])=$val;" + } + elseif($line.Trim() -Match "mb_(\d+).(\w+)\s+(\w+)") { + $id = $Matches[1] + if($Matches[2] -eq "state") { $mode = 1 } + elseif($Matches[2] -eq "stateonly") { $mode = 2 } + elseif($Matches[2] -eq "trigger") { $mode = 3 } + if($Matches[3] -eq "True") { $val = 1 } else { $val = 0 } + + $cmd_mb += , @($id, $val, $mode) } } - [String]$cmd = $cmd.SubString(1) - try { - $retval = [Int][Voicemeeter.Remote]::VBVMR_SetParameters($cmd) - if($retval) { Throw [CAPIError]::new($retval, $MyInvocation.MyCommand) } + [HashTable]$cmds = @{} + if(![string]::IsNullOrEmpty($cmd_channel)) { $cmds["channel"] = $cmd_channel } + if($cmd_mb.count -gt 0) { $cmds["mb"] = $cmd_mb } + + if($cmds.ContainsKey("channel")) { + $cmds["channel"] = $cmds["channel"] -replace '[^a-z0-9.\[\]=;]+' + if(![string]::IsNullOrEmpty($cmds["channel"])) { + try { + $retval = [Int][Voicemeeter.Remote]::VBVMR_SetParameters($cmds["channel"]) + if($retval) { Throw [CAPIError]::new($retval, $MyInvocation.MyCommand) } + } + catch [CAPIError] { + Write-Warning $_.Exception.ErrorMessage() + } + } } - catch [CAPIError] { - Write-Warning $_.Exception.ErrorMessage() + if($cmds.ContainsKey("mb")) { + $cmds["mb"] | ForEach-Object { + if($_.count -gt 0) { + MB_Set -ID $_[0] -SET $_[1] -MODE $_[2] + } + } } }