update to error classes, rework Param_Set_Multi

Added VMRemoteErrors.
Other error classes now subclass VMRemoteErrors.

rework Function Param_Set_Multi

added throw LoginError object on multiple login attempts (still crashing the powershell window during testing if in same powershell fork)

update readme to include vban_instream, vban_outstream example in set parameters by hash. macrobutton in hash can now use key button or mb.
This commit is contained in:
onyx-and-iris 2022-01-19 05:16:28 +00:00
parent 1e4ab54447
commit 57e5368752
3 changed files with 35 additions and 63 deletions

View File

@ -87,8 +87,11 @@ try {
strip_2 = @{mute = $true; mono = $true}; strip_2 = @{mute = $true; mono = $true};
bus_1 = @{mute = $true; mono = $true}; bus_1 = @{mute = $true; mono = $true};
mb_34 = @{state = $true}; button_34 = @{state = $true};
mb_12 = @{trigger = $false}; button_12 = @{trigger = $false};
vban_instream_3 = @{name = 'streamname'};
vban_outstream_0 = @{on = $false};
} }
$vmr.Set_Multi($hash) $vmr.Set_Multi($hash)
@ -124,9 +127,8 @@ $vmr.button[5].trigger = $true
``` ```
### VBAN ### VBAN
#### vmr.vban.enable - vmr.vban.enable: Toggle VBAN on or off. Accepts a boolean value.
Toggle VBAN on or off. Accepts a boolean value.
For each vban in/out stream the following parameters are defined: For each vban in/out stream the following parameters are defined:
- on: boolean - on: boolean
- name: string - name: string

View File

@ -13,7 +13,7 @@ Function Setup_DLL {
$vb_path = Get_VBPath $vb_path = Get_VBPath
if([string]::IsNullOrWhiteSpace($vb_path)) { if([string]::IsNullOrWhiteSpace($vb_path)) {
throw [VBPathError]::new("ERROR: Couldn't get Voicemeeter path") throw [VMRemoteErrors]::new("ERROR: Couldn't get Voicemeeter path")
} }
else { else {
$dll = Join-Path -Path $vb_path -ChildPath ("VoicemeeterRemote" + ` $dll = Join-Path -Path $vb_path -ChildPath ("VoicemeeterRemote" + `
@ -21,7 +21,7 @@ Function Setup_DLL {
".dll") ".dll")
} }
} }
catch [VBPathError] { catch [VMRemoteErrors] {
Write-Warning $_.Exception.ErrorMessage() Write-Warning $_.Exception.ErrorMessage()
return $false return $false
} }
@ -63,7 +63,6 @@ $Signature = @"
return $true return $true
} }
Function Param_Set_Multi { Function Param_Set_Multi {
param( param(
[HashTable]$HASH [HashTable]$HASH
@ -71,45 +70,21 @@ Function Param_Set_Multi {
Start-Sleep -m 50 Start-Sleep -m 50
while(M_Dirty) { Start-Sleep -m 1 } while(M_Dirty) { Start-Sleep -m 1 }
$cmd_strip = [String]::new(512) foreach ($key in $HASH.keys) {
$cmd_bus = [String]::new(512) $classobj , $m2, $m3 = $key.Split("_")
if ($m2 -match "^\d+$") {$index = [int]$m2} else {$index = [int]$m3}
$textInfo = (Get-Culture).TextInfo foreach ($h in $HASH[$key].GetEnumerator()) {
ForEach($key in $HASH.keys) { $property = $h.Name
$identifier = $key.Split("_")[0] $value = $h.Value
$num = $key.Split("_")[1] if ($value -in ('False', 'True')) { [System.Convert]::ToBoolean($value) }
$val = if($HASH.Item($key).values -eq "True") {1} else {0}
if($identifier -eq "strip") { Switch($classobj) {
ForEach($k in $HASH.Item($key).keys) { 'strip' { $this.strip[$index].$property = $value }
$param = $textInfo.ToTitleCase($k) 'bus' { $this.bus[$index].$property = $value }
$cmd_strip += "Strip[$num].$param=$val;" {($_ -eq 'button') -or ($_ -eq 'mb')} { $this.button[$index].$property = $value }
} 'vban' { $this.vban.$m2[$index].$property = $value }
} }
elseif($identifier -eq "bus") {
ForEach($k in $HASH.Item($key).keys) {
$param = $textInfo.ToTitleCase($k)
$cmd_bus += "Bus[$num].$param=$val;"
}
}
elseif($identifier -eq "mb") {
ForEach($k in $HASH.Item($key).keys) {
if($k -eq "state") { $mode = 1 }
elseif($k -eq "stateonly") { $mode = 2 }
elseif($k -eq "trigger") { $mode = 3 }
MB_Set -ID $num -SET $val -MODE $mode
}
}
}
@($cmd_bus, $cmd_strip) | ForEach-Object {
try {
$retval = [Int][Voicemeeter.Remote]::VBVMR_SetParameters($_.Substring(1))
if($retval) { Throw [CAPIError]::new($retval, $MyInvocation.MyCommand) }
}
catch [CAPIError] {
Write-Warning $_.Exception.ErrorMessage()
} }
} }
} }
@ -264,25 +239,27 @@ Function Login {
$retval = [Int][Voicemeeter.Remote]::VBVMR_Login() $retval = [Int][Voicemeeter.Remote]::VBVMR_Login()
if(-not $retval) { Write-Host("LOGGED IN") } if(-not $retval) { Write-Host("LOGGED IN") }
elseif($retval -eq 1) { elseif($retval -eq 1) {
Write-Host("VB NOT RUNNING") Write-Host("VM NOT RUNNING")
New-Variable -Name vbtype -Value 0 New-Variable -Name kind -Value 0
Switch($TYPE) { Switch($TYPE) {
'basic' { $vbtype = 1; Break} 'basic' { $kind = 1; Break}
'banana' { $vbtype = 2; Break} 'banana' { $kind = 2; Break}
'potato' { 'potato' {
if ([Environment]::Is64BitOperatingSystem) { if ([Environment]::Is64BitOperatingSystem) {
$vbtype = 6 $kind = 6
} else { $vbtype = 3 } } else { $kind = 3 }
Break Break
} }
Default { throw [LoginError]::new('Unknown Voicemeeter type') } Default { throw [LoginError]::new('Unknown Voicemeeter type') }
} }
$retval = [Int][Voicemeeter.Remote]::VBVMR_RunVoicemeeter([Int64]$vbtype) $retval = [Int][Voicemeeter.Remote]::VBVMR_RunVoicemeeter([Int64]$kind)
if(-not $retval) { Write-Host("STARTING VB") } if(-not $retval) { Write-Host("STARTING VOICEMEETER") }
else { Throw [CAPIError]::new($retval, $MyInvocation.MyCommand) } else { Throw [CAPIError]::new($retval, $MyInvocation.MyCommand) }
Start-Sleep -s 1 Start-Sleep -s 1
} elseif ($retval -eq -2) {
throw [LoginError]::new('Login may only be called once per session')
} else { Exit } } else { Exit }
} }
catch [LoginError], [CAPIError] { catch [LoginError], [CAPIError] {

View File

@ -1,7 +1,7 @@
class VBPathError : Exception { class VMRemoteErrors : Exception {
[String]$msg [String]$msg
VBPathError([String]$msg) { VMRemoteErrors([String]$msg) {
$this.msg = $msg $this.msg = $msg
} }
@ -10,19 +10,12 @@ class VBPathError : Exception {
} }
} }
class LoginError : Exception { class LoginError : VMRemoteErrors {
[String]$msg LoginError([String]$msg) : Base([String]$msg) {
LoginError([String]$msg) {
$this.msg = $msg
}
[String] ErrorMessage() {
return $this.msg
} }
} }
class CAPIError : Exception { class CAPIError : VMRemoteErrors {
[Int]$retval [Int]$retval
[String]$caller [String]$caller