2021-04-29 20:23:02 +01:00
|
|
|
. $PSScriptRoot\errors.ps1
|
2022-06-25 23:12:02 +01:00
|
|
|
. $PSScriptRoot\binding.ps1
|
2021-04-28 18:21:32 +01:00
|
|
|
|
2022-10-27 21:20:03 +01:00
|
|
|
function Login {
|
2022-06-25 23:12:02 +01:00
|
|
|
param(
|
2022-12-18 04:29:41 +00:00
|
|
|
[string]$kindId
|
2022-06-25 23:12:02 +01:00
|
|
|
)
|
2023-08-16 16:36:43 +01:00
|
|
|
$retval = [int][Voicemeeter.Remote]::VBVMR_Login()
|
|
|
|
if ($retval -notin @(0, 1, -2)) {
|
|
|
|
throw [CAPIError]::new($retval, "VBVMR_Login")
|
2021-05-04 17:29:38 +01:00
|
|
|
}
|
2023-08-16 15:12:25 +01:00
|
|
|
|
|
|
|
switch ($retval) {
|
|
|
|
1 {
|
|
|
|
RunVoicemeeter -kindId $kindId
|
|
|
|
}
|
|
|
|
-2 {
|
2023-08-16 16:36:43 +01:00
|
|
|
throw [LoginError]::new("Login may only be called once per session.")
|
2023-08-16 15:12:25 +01:00
|
|
|
}
|
2021-05-04 17:29:38 +01:00
|
|
|
}
|
|
|
|
|
2022-06-25 23:12:02 +01:00
|
|
|
while (P_Dirty -or M_Dirty) { Start-Sleep -m 1 }
|
2023-08-16 02:52:12 +01:00
|
|
|
"Successfully logged into Voicemeeter [" + $(VmType).ToUpper() + "] Version " + $(VmVersion) | Write-Verbose
|
2022-06-25 23:12:02 +01:00
|
|
|
}
|
2021-04-28 17:38:36 +01:00
|
|
|
|
2022-10-27 21:20:03 +01:00
|
|
|
function Logout {
|
2022-06-25 23:12:02 +01:00
|
|
|
Start-Sleep -m 20
|
2023-08-16 16:36:43 +01:00
|
|
|
$retval = [int][Voicemeeter.Remote]::VBVMR_Logout()
|
|
|
|
if ($retval -notin @(0)) {
|
|
|
|
throw [CAPIError]::new($retval, "VBVMR_Logout")
|
2023-08-16 15:12:25 +01:00
|
|
|
}
|
|
|
|
if ($retval -eq 0) { "Sucessfully logged out" | Write-Verbose }
|
|
|
|
}
|
|
|
|
|
|
|
|
function RunVoicemeeter {
|
|
|
|
param(
|
|
|
|
[string]$kindId
|
|
|
|
)
|
|
|
|
$kinds = @{
|
|
|
|
"basic" = 1
|
|
|
|
"banana" = 2
|
|
|
|
"potato" = $(if ([Environment]::Is64BitOperatingSystem) { 6 } else { 3 })
|
|
|
|
}
|
|
|
|
|
2023-08-16 16:36:43 +01:00
|
|
|
$retval = [int][Voicemeeter.Remote]::VBVMR_RunVoicemeeter([int64]$kinds[$kindId])
|
|
|
|
if ($retval -notin @(0)) {
|
|
|
|
throw [CAPIError]::new($retval, "VBVMR_RunVoicemeeter")
|
2023-08-16 15:12:25 +01:00
|
|
|
}
|
|
|
|
"Voicemeeter Engine running but GUI not launched. Launching GUI now." | Write-Verbose
|
|
|
|
Start-Sleep -s 1
|
2022-10-27 21:20:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function P_Dirty {
|
2023-08-16 16:36:43 +01:00
|
|
|
$retval = [Voicemeeter.Remote]::VBVMR_IsParametersDirty()
|
|
|
|
if ($retval -notin @(0, 1)) {
|
|
|
|
throw [CAPIError]::new($retval, "VBVMR_RunVoicemeeter")
|
2023-08-16 15:12:25 +01:00
|
|
|
}
|
|
|
|
[bool]$retval
|
2022-06-25 23:12:02 +01:00
|
|
|
}
|
2021-04-28 17:38:36 +01:00
|
|
|
|
2022-10-27 21:20:03 +01:00
|
|
|
function M_Dirty {
|
2023-08-16 16:36:43 +01:00
|
|
|
$retval = [Voicemeeter.Remote]::VBVMR_MacroButton_IsDirty()
|
|
|
|
if ($retval -notin @(0, 1)) {
|
|
|
|
throw [CAPIError]::new($retval, "VBVMR_RunVoicemeeter")
|
2023-08-16 15:12:25 +01:00
|
|
|
}
|
|
|
|
[bool]$retval
|
2022-06-25 23:12:02 +01:00
|
|
|
}
|
2021-04-28 17:38:36 +01:00
|
|
|
|
2022-10-27 21:20:03 +01:00
|
|
|
function VmType {
|
|
|
|
New-Variable -Name ptr -Value 0
|
2023-08-16 16:36:43 +01:00
|
|
|
$retval = [int][Voicemeeter.Remote]::VBVMR_GetVoicemeeterType([ref]$ptr)
|
|
|
|
if ($retval -notin @(0)) {
|
|
|
|
throw [CAPIError]::new($retval, "VBVMR_GetVoicemeeterType")
|
2023-08-16 15:12:25 +01:00
|
|
|
}
|
2022-10-27 21:20:03 +01:00
|
|
|
switch ($ptr) {
|
|
|
|
1 { return "basic" }
|
|
|
|
2 { return "banana" }
|
|
|
|
3 { return "potato" }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-16 02:52:12 +01:00
|
|
|
function VmVersion {
|
2022-10-27 21:20:03 +01:00
|
|
|
New-Variable -Name ptr -Value 0
|
2023-08-16 16:36:43 +01:00
|
|
|
$retval = [int][Voicemeeter.Remote]::VBVMR_GetVoicemeeterVersion([ref]$ptr)
|
|
|
|
if ($retval -notin @(0)) {
|
|
|
|
throw [CAPIError]::new($retval, "VBVMR_GetVoicemeeterVersion")
|
2023-08-16 15:12:25 +01:00
|
|
|
}
|
2022-10-27 21:20:03 +01:00
|
|
|
$v1 = ($ptr -band 0xFF000000) -shr 24
|
|
|
|
$v2 = ($ptr -band 0x00FF0000) -shr 16
|
|
|
|
$v3 = ($ptr -band 0x0000FF00) -shr 8
|
|
|
|
$v4 = $ptr -band 0x000000FF
|
|
|
|
"$v1.$v2.$v3.$v4"
|
2021-05-04 17:29:38 +01:00
|
|
|
}
|
2021-04-28 17:38:36 +01:00
|
|
|
|
2022-06-25 23:12:02 +01:00
|
|
|
|
2022-10-27 21:20:03 +01:00
|
|
|
function Param_Get {
|
2021-04-28 17:38:36 +01:00
|
|
|
param(
|
2022-10-27 21:20:03 +01:00
|
|
|
[string]$PARAM, [bool]$IS_STRING = $false
|
2021-04-28 17:38:36 +01:00
|
|
|
)
|
2023-08-16 15:12:25 +01:00
|
|
|
Start-Sleep -m 20
|
2022-06-25 15:20:36 +01:00
|
|
|
while (P_Dirty) { Start-Sleep -m 1 }
|
2021-04-28 17:38:36 +01:00
|
|
|
|
2023-08-16 16:36:43 +01:00
|
|
|
if ($IS_STRING) {
|
|
|
|
$BYTES = [System.Byte[]]::new(512)
|
|
|
|
$retval = [int][Voicemeeter.Remote]::VBVMR_GetParameterStringA($PARAM, $BYTES)
|
|
|
|
if ($retval -notin @(0)) {
|
|
|
|
throw [CAPIError]::new($retval, "VBVMR_GetParameterStringA")
|
2022-01-19 21:53:49 +00:00
|
|
|
}
|
2023-08-16 16:36:43 +01:00
|
|
|
[System.Text.Encoding]::ASCII.GetString($BYTES).Trim([char]0)
|
2023-08-16 15:12:25 +01:00
|
|
|
}
|
2023-08-16 16:36:43 +01:00
|
|
|
else {
|
|
|
|
New-Variable -Name ptr -Value 0.0
|
|
|
|
$retval = [int][Voicemeeter.Remote]::VBVMR_GetParameterFloat($PARAM, [ref]$ptr)
|
|
|
|
if ($retval -notin @(0)) {
|
|
|
|
throw [CAPIError]::new($retval, "VBVMR_GetParameterFloat")
|
|
|
|
}
|
|
|
|
[single]$ptr
|
2021-04-29 20:23:02 +01:00
|
|
|
}
|
2021-04-28 17:38:36 +01:00
|
|
|
}
|
|
|
|
|
2022-10-27 21:20:03 +01:00
|
|
|
function Param_Set {
|
2021-04-28 17:38:36 +01:00
|
|
|
param(
|
2022-10-27 21:20:03 +01:00
|
|
|
[string]$PARAM, [Object]$VALUE
|
2021-04-28 17:38:36 +01:00
|
|
|
)
|
2023-08-16 16:36:43 +01:00
|
|
|
if ($VALUE -is [string]) {
|
|
|
|
$retval = [int][Voicemeeter.Remote]::VBVMR_SetParameterStringA($PARAM, $VALUE)
|
|
|
|
if ($retval -notin @(0)) {
|
|
|
|
throw [CAPIError]::new($retval, "VBVMR_SetParameterStringA")
|
2022-01-19 21:53:49 +00:00
|
|
|
}
|
2021-04-29 20:23:02 +01:00
|
|
|
}
|
2023-08-16 16:36:43 +01:00
|
|
|
else {
|
|
|
|
$retval = [int][Voicemeeter.Remote]::VBVMR_SetParameterFloat($PARAM, $VALUE)
|
|
|
|
if ($retval -notin @(0)) {
|
|
|
|
throw [CAPIError]::new($retval, "VBVMR_SetParameterFloat")
|
|
|
|
}
|
2021-04-29 20:23:02 +01:00
|
|
|
}
|
2021-04-28 17:38:36 +01:00
|
|
|
}
|
|
|
|
|
2022-10-27 21:20:03 +01:00
|
|
|
function MB_Set {
|
2021-04-28 17:38:36 +01:00
|
|
|
param(
|
2022-10-27 21:20:03 +01:00
|
|
|
[int64]$ID, [single]$SET, [int64]$MODE
|
2021-04-28 17:38:36 +01:00
|
|
|
)
|
2023-08-16 16:36:43 +01:00
|
|
|
$retval = [int][Voicemeeter.Remote]::VBVMR_MacroButton_SetStatus($ID, $SET, $MODE)
|
|
|
|
if ($retval -notin @(0)) {
|
|
|
|
throw [CAPIError]::new($retval, "VBVMR_MacroButton_SetStatus")
|
2021-04-29 20:23:02 +01:00
|
|
|
}
|
2021-04-28 17:38:36 +01:00
|
|
|
}
|
|
|
|
|
2022-10-27 21:20:03 +01:00
|
|
|
function MB_Get {
|
2021-04-28 17:38:36 +01:00
|
|
|
param(
|
2022-10-27 21:20:03 +01:00
|
|
|
[int64]$ID, [int64]$MODE
|
2021-04-28 17:38:36 +01:00
|
|
|
)
|
2023-08-16 15:12:25 +01:00
|
|
|
Start-Sleep -m 30
|
2022-06-25 15:20:36 +01:00
|
|
|
while (M_Dirty) { Start-Sleep -m 1 }
|
2021-04-28 17:38:36 +01:00
|
|
|
|
2021-04-29 20:23:02 +01:00
|
|
|
New-Variable -Name ptr -Value 0.0
|
2023-08-16 16:36:43 +01:00
|
|
|
$retval = [int][Voicemeeter.Remote]::VBVMR_MacroButton_GetStatus($ID, [ref]$ptr, $MODE)
|
|
|
|
if ($retval -notin @(0)) {
|
|
|
|
throw [CAPIError]::new($retval, $MyInvocation.MyCommand)
|
2021-04-29 20:23:02 +01:00
|
|
|
}
|
2022-10-27 21:20:03 +01:00
|
|
|
[int]$ptr
|
2021-04-28 17:38:36 +01:00
|
|
|
}
|
|
|
|
|
2022-10-27 21:20:03 +01:00
|
|
|
function Param_Set_Multi {
|
2022-01-19 21:53:49 +00:00
|
|
|
param(
|
2022-10-27 21:20:03 +01:00
|
|
|
[hashtable]$HASH
|
2022-01-19 21:53:49 +00:00
|
|
|
)
|
2022-10-27 21:20:03 +01:00
|
|
|
foreach ($key in $HASH.keys) {
|
|
|
|
$classobj, $m2, $m3 = $key.Split("_")
|
2022-06-25 15:20:36 +01:00
|
|
|
if ($m2 -match "^\d+$") { $index = [int]$m2 } else { $index = [int]$m3 }
|
2022-01-19 21:53:49 +00:00
|
|
|
|
2022-10-27 21:20:03 +01:00
|
|
|
foreach ($h in $HASH[$key].GetEnumerator()) {
|
2022-01-19 21:53:49 +00:00
|
|
|
$property = $h.Name
|
|
|
|
$value = $h.Value
|
|
|
|
if ($value -in ('False', 'True')) { [System.Convert]::ToBoolean($value) }
|
|
|
|
|
2022-10-27 21:20:03 +01:00
|
|
|
switch ($classobj) {
|
2022-01-19 21:53:49 +00:00
|
|
|
'strip' { $this.strip[$index].$property = $value }
|
|
|
|
'bus' { $this.bus[$index].$property = $value }
|
2022-06-25 15:20:36 +01:00
|
|
|
{ ($_ -eq 'button') -or ($_ -eq 'mb') } { $this.button[$index].$property = $value }
|
2022-01-19 21:53:49 +00:00
|
|
|
'vban' { $this.vban.$m2[$index].$property = $value }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-10-27 21:20:03 +01:00
|
|
|
|
|
|
|
function Set_By_Script {
|
|
|
|
param(
|
|
|
|
[string]$script
|
|
|
|
)
|
2023-08-16 16:36:43 +01:00
|
|
|
$retval = [int][Voicemeeter.Remote]::VBVMR_SetParameters($script)
|
|
|
|
if ($retval -notin @(0)) {
|
|
|
|
throw [CAPIError]::new($retval, "VBVMR_SetParameters")
|
2022-10-27 21:20:03 +01:00
|
|
|
}
|
|
|
|
}
|
2023-08-09 14:16:27 +01:00
|
|
|
|
|
|
|
function Get_Level {
|
|
|
|
param(
|
|
|
|
[int64]$MODE, [int64]$INDEX
|
|
|
|
)
|
|
|
|
New-Variable -Name ptr -Value 0.0
|
2023-08-16 16:36:43 +01:00
|
|
|
$retval = [int][Voicemeeter.Remote]::VBVMR_GetLevel($MODE, $INDEX, [ref]$ptr)
|
|
|
|
if ($retval -notin @(0)) {
|
|
|
|
throw [CAPIError]::new($retval, "VBVMR_GetLevel")
|
2023-08-09 14:16:27 +01:00
|
|
|
}
|
|
|
|
[float]$ptr
|
|
|
|
}
|