Update base.ps1

param_set and param_set_string merged.
This commit is contained in:
onyx-and-iris 2022-01-19 21:53:49 +00:00
parent 8e03c4e53b
commit 9714b7cc7d

View File

@ -4,7 +4,7 @@
. $PSScriptRoot\bus.ps1 . $PSScriptRoot\bus.ps1
. $PSScriptRoot\macrobuttons.ps1 . $PSScriptRoot\macrobuttons.ps1
. $PSScriptRoot\vban.ps1 . $PSScriptRoot\vban.ps1
. $PSScriptRoot\special.ps1 . $PSScriptRoot\command.ps1
$global:layout = $null $global:layout = $null
@ -63,53 +63,14 @@ $Signature = @"
return $true return $true
} }
Function Param_Set_Multi { Function Param_Get {
param( param(
[HashTable]$HASH [String]$PARAM, [bool]$IS_STRING=$false
)
Start-Sleep -m 50
while(M_Dirty) { Start-Sleep -m 1 }
foreach ($key in $HASH.keys) {
$classobj , $m2, $m3 = $key.Split("_")
if ($m2 -match "^\d+$") {$index = [int]$m2} else {$index = [int]$m3}
foreach ($h in $HASH[$key].GetEnumerator()) {
$property = $h.Name
$value = $h.Value
if ($value -in ('False', 'True')) { [System.Convert]::ToBoolean($value) }
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 }
}
}
}
}
Function Param_Set_String {
param(
[String]$PARAM, [String]$VALUE
)
try {
$retval = [Int][Voicemeeter.Remote]::VBVMR_SetParameterStringA($PARAM, $VALUE)
if($retval) { Throw [CAPIError]::new($retval, $MyInvocation.MyCommand) }
}
catch [CAPIError] {
Write-Warning $_.Exception.ErrorMessage()
}
}
Function Param_Get_String {
param(
[String]$PARAM
) )
Start-Sleep -m 50 Start-Sleep -m 50
while(P_Dirty) { Start-Sleep -m 1 } while(P_Dirty) { Start-Sleep -m 1 }
if($IS_STRING) {
$BYTES = [System.Byte[]]::new(512) $BYTES = [System.Byte[]]::new(512)
try { try {
$retval = [Int][Voicemeeter.Remote]::VBVMR_GetParameterStringA($PARAM, $BYTES) $retval = [Int][Voicemeeter.Remote]::VBVMR_GetParameterStringA($PARAM, $BYTES)
@ -118,32 +79,9 @@ Function Param_Get_String {
catch [CAPIError] { catch [CAPIError] {
Write-Warning $_.Exception.ErrorMessage() Write-Warning $_.Exception.ErrorMessage()
} }
[System.Text.Encoding]::ASCII.GetString($BYTES).Trim([char]0) [System.Text.Encoding]::ASCII.GetString($BYTES).Trim([char]0)
}
Function Param_Set {
param(
[String]$PARAM, [Single]$VALUE
)
try {
$retval = [Int][Voicemeeter.Remote]::VBVMR_SetParameterFloat($PARAM, $VALUE)
if($retval) { Throw [CAPIError]::new($retval, $MyInvocation.MyCommand) }
} }
catch [CAPIError] { else {
Write-Warning $_.Exception.ErrorMessage()
}
}
Function Param_Get {
param(
[String]$PARAM
)
Start-Sleep -m 50
while(P_Dirty) { Start-Sleep -m 1 }
New-Variable -Name ptr -Value 0.0 New-Variable -Name ptr -Value 0.0
try { try {
$retval = [Int][Voicemeeter.Remote]::VBVMR_GetParameterFloat($PARAM, [ref]$ptr) $retval = [Int][Voicemeeter.Remote]::VBVMR_GetParameterFloat($PARAM, [ref]$ptr)
@ -153,8 +91,26 @@ Function Param_Get {
Write-Warning $_.Exception.ErrorMessage() Write-Warning $_.Exception.ErrorMessage()
} }
[Single]$ptr [Single]$ptr
}
} }
Function Param_Set {
param(
[String]$PARAM, [Object]$VALUE
)
try {
if($VALUE -is [String]) {
$retval = [Int][Voicemeeter.Remote]::VBVMR_SetParameterStringA($PARAM, $VALUE)
}
else {
$retval = [Int][Voicemeeter.Remote]::VBVMR_SetParameterFloat($PARAM, $VALUE)
}
if($retval) { Throw [CAPIError]::new($retval, $MyInvocation.MyCommand) }
}
catch [CAPIError] {
Write-Warning $_.Exception.ErrorMessage()
}
}
Function MB_Set { Function MB_Set {
param( param(
@ -169,7 +125,6 @@ Function MB_Set {
} }
} }
Function MB_Get { Function MB_Get {
param( param(
[Int64]$ID, [Int64]$MODE [Int64]$ID, [Int64]$MODE
@ -188,6 +143,29 @@ Function MB_Get {
[Int]$ptr [Int]$ptr
} }
Function Param_Set_Multi {
param(
[HashTable]$HASH
)
ForEach ($key in $HASH.keys) {
$classobj , $m2, $m3 = $key.Split("_")
if ($m2 -match "^\d+$") {$index = [int]$m2} else {$index = [int]$m3}
ForEach ($h in $HASH[$key].GetEnumerator()) {
$property = $h.Name
$value = $h.Value
if ($value -in ('False', 'True')) { [System.Convert]::ToBoolean($value) }
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 }
}
}
}
}
Function DefineVersion { Function DefineVersion {
param( param(
[Int]$TYPE [Int]$TYPE
@ -230,31 +208,30 @@ Function DefineVersion {
$global:layout = $layout $global:layout = $layout
} }
Function Login { Function Login {
param( param(
[String]$TYPE=$null [String]$KIND=$null
) )
try { try {
$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("VM NOT RUNNING") Write-Host("VM NOT RUNNING")
New-Variable -Name kind -Value 0 New-Variable -Name vm_exe -Value 0
Switch($TYPE) { Switch($KIND) {
'basic' { $kind = 1; Break} 'basic' { $vm_exe = 1; Break}
'banana' { $kind = 2; Break} 'banana' { $vm_exe = 2; Break}
'potato' { 'potato' {
if ([Environment]::Is64BitOperatingSystem) { if ([Environment]::Is64BitOperatingSystem) {
$kind = 6 $vm_exe = 6
} else { $kind = 3 } } else { $vm_exe = 3 }
Break Break
} }
Default { throw [LoginError]::new('Unknown Voicemeeter type') } Default { throw [LoginError]::new('Unknown Voicemeeter type') }
} }
$retval = [Int][Voicemeeter.Remote]::VBVMR_RunVoicemeeter([Int64]$kind) $retval = [Int][Voicemeeter.Remote]::VBVMR_RunVoicemeeter([Int64]$vm_exe)
if(-not $retval) { Write-Host("STARTING VOICEMEETER") } 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
@ -279,19 +256,16 @@ Function Login {
DefineVersion -TYPE $ptr DefineVersion -TYPE $ptr
} }
Function Logout { Function Logout {
Start-Sleep -m 20 Start-Sleep -m 20
$retval = [Int][Voicemeeter.Remote]::VBVMR_Logout() $retval = [Int][Voicemeeter.Remote]::VBVMR_Logout()
if(-not $retval) { Write-Host("LOGGED OUT") } if(-not $retval) { Write-Host("LOGGED OUT") }
} }
Function P_Dirty { Function P_Dirty {
[Bool][Voicemeeter.Remote]::VBVMR_IsParametersDirty() [Bool][Voicemeeter.Remote]::VBVMR_IsParametersDirty()
} }
Function M_Dirty { Function M_Dirty {
[Bool][Voicemeeter.Remote]::VBVMR_MacroButton_IsDirty() [Bool][Voicemeeter.Remote]::VBVMR_MacroButton_IsDirty()
} }