mirror of
https://github.com/onyx-and-iris/voicemeeter-api-powershell.git
synced 2025-01-18 05:10:48 +00:00
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:
parent
1e4ab54447
commit
57e5368752
10
README.md
10
README.md
@ -87,8 +87,11 @@ try {
|
||||
strip_2 = @{mute = $true; mono = $true};
|
||||
bus_1 = @{mute = $true; mono = $true};
|
||||
|
||||
mb_34 = @{state = $true};
|
||||
mb_12 = @{trigger = $false};
|
||||
button_34 = @{state = $true};
|
||||
button_12 = @{trigger = $false};
|
||||
|
||||
vban_instream_3 = @{name = 'streamname'};
|
||||
vban_outstream_0 = @{on = $false};
|
||||
}
|
||||
|
||||
$vmr.Set_Multi($hash)
|
||||
@ -124,9 +127,8 @@ $vmr.button[5].trigger = $true
|
||||
```
|
||||
|
||||
### 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:
|
||||
- on: boolean
|
||||
- name: string
|
||||
|
71
lib/base.ps1
71
lib/base.ps1
@ -13,7 +13,7 @@ Function Setup_DLL {
|
||||
$vb_path = Get_VBPath
|
||||
|
||||
if([string]::IsNullOrWhiteSpace($vb_path)) {
|
||||
throw [VBPathError]::new("ERROR: Couldn't get Voicemeeter path")
|
||||
throw [VMRemoteErrors]::new("ERROR: Couldn't get Voicemeeter path")
|
||||
}
|
||||
else {
|
||||
$dll = Join-Path -Path $vb_path -ChildPath ("VoicemeeterRemote" + `
|
||||
@ -21,7 +21,7 @@ Function Setup_DLL {
|
||||
".dll")
|
||||
}
|
||||
}
|
||||
catch [VBPathError] {
|
||||
catch [VMRemoteErrors] {
|
||||
Write-Warning $_.Exception.ErrorMessage()
|
||||
return $false
|
||||
}
|
||||
@ -63,7 +63,6 @@ $Signature = @"
|
||||
return $true
|
||||
}
|
||||
|
||||
|
||||
Function Param_Set_Multi {
|
||||
param(
|
||||
[HashTable]$HASH
|
||||
@ -71,45 +70,21 @@ Function Param_Set_Multi {
|
||||
Start-Sleep -m 50
|
||||
while(M_Dirty) { Start-Sleep -m 1 }
|
||||
|
||||
$cmd_strip = [String]::new(512)
|
||||
$cmd_bus = [String]::new(512)
|
||||
foreach ($key in $HASH.keys) {
|
||||
$classobj , $m2, $m3 = $key.Split("_")
|
||||
if ($m2 -match "^\d+$") {$index = [int]$m2} else {$index = [int]$m3}
|
||||
|
||||
$textInfo = (Get-Culture).TextInfo
|
||||
ForEach($key in $HASH.keys) {
|
||||
$identifier = $key.Split("_")[0]
|
||||
$num = $key.Split("_")[1]
|
||||
$val = if($HASH.Item($key).values -eq "True") {1} else {0}
|
||||
foreach ($h in $HASH[$key].GetEnumerator()) {
|
||||
$property = $h.Name
|
||||
$value = $h.Value
|
||||
if ($value -in ('False', 'True')) { [System.Convert]::ToBoolean($value) }
|
||||
|
||||
if($identifier -eq "strip") {
|
||||
ForEach($k in $HASH.Item($key).keys) {
|
||||
$param = $textInfo.ToTitleCase($k)
|
||||
$cmd_strip += "Strip[$num].$param=$val;"
|
||||
}
|
||||
Switch($classobj) {
|
||||
'strip' { $this.strip[$index].$property = $value }
|
||||
'bus' { $this.bus[$index].$property = $value }
|
||||
{($_ -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()
|
||||
if(-not $retval) { Write-Host("LOGGED IN") }
|
||||
elseif($retval -eq 1) {
|
||||
Write-Host("VB NOT RUNNING")
|
||||
New-Variable -Name vbtype -Value 0
|
||||
Write-Host("VM NOT RUNNING")
|
||||
New-Variable -Name kind -Value 0
|
||||
|
||||
Switch($TYPE) {
|
||||
'basic' { $vbtype = 1; Break}
|
||||
'banana' { $vbtype = 2; Break}
|
||||
'basic' { $kind = 1; Break}
|
||||
'banana' { $kind = 2; Break}
|
||||
'potato' {
|
||||
if ([Environment]::Is64BitOperatingSystem) {
|
||||
$vbtype = 6
|
||||
} else { $vbtype = 3 }
|
||||
$kind = 6
|
||||
} else { $kind = 3 }
|
||||
Break
|
||||
}
|
||||
Default { throw [LoginError]::new('Unknown Voicemeeter type') }
|
||||
}
|
||||
|
||||
$retval = [Int][Voicemeeter.Remote]::VBVMR_RunVoicemeeter([Int64]$vbtype)
|
||||
if(-not $retval) { Write-Host("STARTING VB") }
|
||||
$retval = [Int][Voicemeeter.Remote]::VBVMR_RunVoicemeeter([Int64]$kind)
|
||||
if(-not $retval) { Write-Host("STARTING VOICEMEETER") }
|
||||
else { Throw [CAPIError]::new($retval, $MyInvocation.MyCommand) }
|
||||
Start-Sleep -s 1
|
||||
} elseif ($retval -eq -2) {
|
||||
throw [LoginError]::new('Login may only be called once per session')
|
||||
} else { Exit }
|
||||
}
|
||||
catch [LoginError], [CAPIError] {
|
||||
|
@ -1,7 +1,7 @@
|
||||
class VBPathError : Exception {
|
||||
class VMRemoteErrors : Exception {
|
||||
[String]$msg
|
||||
|
||||
VBPathError([String]$msg) {
|
||||
VMRemoteErrors([String]$msg) {
|
||||
$this.msg = $msg
|
||||
}
|
||||
|
||||
@ -10,19 +10,12 @@ class VBPathError : Exception {
|
||||
}
|
||||
}
|
||||
|
||||
class LoginError : Exception {
|
||||
[String]$msg
|
||||
|
||||
LoginError([String]$msg) {
|
||||
$this.msg = $msg
|
||||
}
|
||||
|
||||
[String] ErrorMessage() {
|
||||
return $this.msg
|
||||
class LoginError : VMRemoteErrors {
|
||||
LoginError([String]$msg) : Base([String]$msg) {
|
||||
}
|
||||
}
|
||||
|
||||
class CAPIError : Exception {
|
||||
class CAPIError : VMRemoteErrors {
|
||||
[Int]$retval
|
||||
[String]$caller
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user