mirror of
https://github.com/onyx-and-iris/voicemeeter-api-powershell.git
synced 2026-04-18 21:43:32 +00:00
xy and fx parameters added to strip/bus classes.
GetType, GetVersion, SendText added to Remote class. Console output now written to Debug stream. ToString() method overriden for higher classes. formatter run through all files.
This commit is contained in:
150
lib/base.ps1
150
lib/base.ps1
@@ -9,73 +9,88 @@
|
||||
. $PSScriptRoot\command.ps1
|
||||
. $PSScriptRoot\recorder.ps1
|
||||
|
||||
Function Login {
|
||||
function Login {
|
||||
param(
|
||||
[String]$KIND = $null
|
||||
[string]$KIND = $null
|
||||
)
|
||||
try {
|
||||
$retval = [Int][Voicemeeter.Remote]::VBVMR_Login()
|
||||
if (-not $retval) { Write-Host("LOGGED IN") }
|
||||
$retval = [int][Voicemeeter.Remote]::VBVMR_Login()
|
||||
if (-not $retval) { "LOGGED IN" | Write-Verbose }
|
||||
elseif ($retval -eq 1) {
|
||||
Write-Host("VM NOT RUNNING")
|
||||
"VM NOT RUNNING" | Write-Verbose
|
||||
New-Variable -Name vm_exe -Value 0
|
||||
|
||||
Switch ($KIND) {
|
||||
'basic' { $vm_exe = 1; Break }
|
||||
'banana' { $vm_exe = 2; Break }
|
||||
switch ($KIND) {
|
||||
'basic' { $vm_exe = 1; break }
|
||||
'banana' { $vm_exe = 2; break }
|
||||
'potato' {
|
||||
if ([Environment]::Is64BitOperatingSystem) {
|
||||
$vm_exe = 6
|
||||
}
|
||||
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]$vm_exe)
|
||||
if (-not $retval) { Write-Host("STARTING VOICEMEETER") }
|
||||
else { Throw [CAPIError]::new($retval, $MyInvocation.MyCommand) }
|
||||
$retval = [int][Voicemeeter.Remote]::VBVMR_RunVoicemeeter([int64]$vm_exe)
|
||||
if (-not $retval) { "STARTING VOICEMEETER" | Write-Verbose }
|
||||
else { throw [CAPIError]::new($retval, $MyInvocation.MyCommand) }
|
||||
Start-Sleep -s 1
|
||||
}
|
||||
elseif ($retval -eq -2) {
|
||||
elseif ($retval -eq -2) {
|
||||
throw [LoginError]::new('Login may only be called once per session')
|
||||
}
|
||||
else { Exit }
|
||||
else { exit }
|
||||
}
|
||||
catch [LoginError], [CAPIError] {
|
||||
Write-Warning $_.Exception.ErrorMessage()
|
||||
}
|
||||
|
||||
while (P_Dirty -or M_Dirty) { Start-Sleep -m 1 }
|
||||
"VERSION:[" + $(VmType).ToUpper() + "]" | Write-Verbose
|
||||
}
|
||||
|
||||
function Logout {
|
||||
Start-Sleep -m 20
|
||||
$retval = [int][Voicemeeter.Remote]::VBVMR_Logout()
|
||||
if (-not $retval) { "LOGGED OUT" | Write-Verbose }
|
||||
}
|
||||
|
||||
function P_Dirty {
|
||||
[bool][Voicemeeter.Remote]::VBVMR_IsParametersDirty()
|
||||
}
|
||||
|
||||
function M_Dirty {
|
||||
[bool][Voicemeeter.Remote]::VBVMR_MacroButton_IsDirty()
|
||||
}
|
||||
|
||||
function VmType {
|
||||
New-Variable -Name ptr -Value 0
|
||||
$retval = [Int][Voicemeeter.Remote]::VBVMR_GetVoicemeeterType([ref]$ptr)
|
||||
if (-not $retval) {
|
||||
if ($ptr -eq 1) { Write-Host("VERSION:[BASIC]") }
|
||||
elseif ($ptr -eq 2) { Write-Host("VERSION:[BANANA]") }
|
||||
elseif ($ptr -eq 3) { Write-Host("VERSION:[POTATO]") }
|
||||
$retval = [int][Voicemeeter.Remote]::VBVMR_GetVoicemeeterType([ref]$ptr)
|
||||
if ($retval) { throw [CAPIError]::new($retval, $MyInvocation.MyCommand) }
|
||||
switch ($ptr) {
|
||||
1 { return "basic" }
|
||||
2 { return "banana" }
|
||||
3 { return "potato" }
|
||||
}
|
||||
}
|
||||
|
||||
Function Logout {
|
||||
Start-Sleep -m 20
|
||||
$retval = [Int][Voicemeeter.Remote]::VBVMR_Logout()
|
||||
if (-not $retval) { Write-Host("LOGGED OUT") }
|
||||
}
|
||||
|
||||
Function P_Dirty {
|
||||
[Bool][Voicemeeter.Remote]::VBVMR_IsParametersDirty()
|
||||
}
|
||||
|
||||
Function M_Dirty {
|
||||
[Bool][Voicemeeter.Remote]::VBVMR_MacroButton_IsDirty()
|
||||
function Version {
|
||||
New-Variable -Name ptr -Value 0
|
||||
$retval = [int][Voicemeeter.Remote]::VBVMR_GetVoicemeeterVersion([ref]$ptr)
|
||||
if ($retval) { throw [CAPIError]::new($retval, $MyInvocation.MyCommand) }
|
||||
$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"
|
||||
}
|
||||
|
||||
|
||||
Function Param_Get {
|
||||
function Param_Get {
|
||||
param(
|
||||
[String]$PARAM, [bool]$IS_STRING = $false
|
||||
[string]$PARAM, [bool]$IS_STRING = $false
|
||||
)
|
||||
Start-Sleep -m 50
|
||||
while (P_Dirty) { Start-Sleep -m 1 }
|
||||
@@ -83,90 +98,90 @@ Function Param_Get {
|
||||
if ($IS_STRING) {
|
||||
$BYTES = [System.Byte[]]::new(512)
|
||||
try {
|
||||
$retval = [Int][Voicemeeter.Remote]::VBVMR_GetParameterStringA($PARAM, $BYTES)
|
||||
if ($retval) { Throw [CAPIError]::new($retval, $MyInvocation.MyCommand) }
|
||||
$retval = [int][Voicemeeter.Remote]::VBVMR_GetParameterStringA($PARAM, $BYTES)
|
||||
if ($retval) { throw [CAPIError]::new($retval, $MyInvocation.MyCommand) }
|
||||
}
|
||||
catch [CAPIError] {
|
||||
Write-Warning $_.Exception.ErrorMessage()
|
||||
}
|
||||
[System.Text.Encoding]::ASCII.GetString($BYTES).Trim([char]0)
|
||||
[System.Text.Encoding]::ASCII.GetString($BYTES).Trim([char]0)
|
||||
}
|
||||
else {
|
||||
New-Variable -Name ptr -Value 0.0
|
||||
try {
|
||||
$retval = [Int][Voicemeeter.Remote]::VBVMR_GetParameterFloat($PARAM, [ref]$ptr)
|
||||
if ($retval) { Throw [CAPIError]::new($retval, $MyInvocation.MyCommand) }
|
||||
$retval = [int][Voicemeeter.Remote]::VBVMR_GetParameterFloat($PARAM, [ref]$ptr)
|
||||
if ($retval) { throw [CAPIError]::new($retval, $MyInvocation.MyCommand) }
|
||||
}
|
||||
catch [CAPIError] {
|
||||
Write-Warning $_.Exception.ErrorMessage()
|
||||
}
|
||||
[Single]$ptr
|
||||
[single]$ptr
|
||||
}
|
||||
}
|
||||
|
||||
Function Param_Set {
|
||||
function Param_Set {
|
||||
param(
|
||||
[String]$PARAM, [Object]$VALUE
|
||||
[string]$PARAM, [Object]$VALUE
|
||||
)
|
||||
try {
|
||||
if ($VALUE -is [String]) {
|
||||
$retval = [Int][Voicemeeter.Remote]::VBVMR_SetParameterStringA($PARAM, $VALUE)
|
||||
if ($VALUE -is [string]) {
|
||||
$retval = [int][Voicemeeter.Remote]::VBVMR_SetParameterStringA($PARAM, $VALUE)
|
||||
}
|
||||
else {
|
||||
$retval = [Int][Voicemeeter.Remote]::VBVMR_SetParameterFloat($PARAM, $VALUE)
|
||||
$retval = [int][Voicemeeter.Remote]::VBVMR_SetParameterFloat($PARAM, $VALUE)
|
||||
}
|
||||
if ($retval) { Throw [CAPIError]::new($retval, $MyInvocation.MyCommand) }
|
||||
if ($retval) { throw [CAPIError]::new($retval, $MyInvocation.MyCommand) }
|
||||
}
|
||||
catch [CAPIError] {
|
||||
Write-Warning $_.Exception.ErrorMessage()
|
||||
}
|
||||
}
|
||||
|
||||
Function MB_Set {
|
||||
function MB_Set {
|
||||
param(
|
||||
[Int64]$ID, [Single]$SET, [Int64]$MODE
|
||||
[int64]$ID, [single]$SET, [int64]$MODE
|
||||
)
|
||||
try {
|
||||
$retval = [Int][Voicemeeter.Remote]::VBVMR_MacroButton_SetStatus($ID, $SET, $MODE)
|
||||
if ($retval) { Throw [CAPIError]::new($retval, $MyInvocation.MyCommand) }
|
||||
$retval = [int][Voicemeeter.Remote]::VBVMR_MacroButton_SetStatus($ID, $SET, $MODE)
|
||||
if ($retval) { throw [CAPIError]::new($retval, $MyInvocation.MyCommand) }
|
||||
}
|
||||
catch [CAPIError] {
|
||||
Write-Warning $_.Exception.ErrorMessage()
|
||||
}
|
||||
}
|
||||
|
||||
Function MB_Get {
|
||||
function MB_Get {
|
||||
param(
|
||||
[Int64]$ID, [Int64]$MODE
|
||||
[int64]$ID, [int64]$MODE
|
||||
)
|
||||
Start-Sleep -m 50
|
||||
while (M_Dirty) { Start-Sleep -m 1 }
|
||||
|
||||
New-Variable -Name ptr -Value 0.0
|
||||
try {
|
||||
$retval = [Int][Voicemeeter.Remote]::VBVMR_MacroButton_GetStatus($ID, [ref]$ptr, $MODE)
|
||||
if ($retval) { Throw [CAPIError]::new($retval, $MyInvocation.MyCommand) }
|
||||
$retval = [int][Voicemeeter.Remote]::VBVMR_MacroButton_GetStatus($ID, [ref]$ptr, $MODE)
|
||||
if ($retval) { throw [CAPIError]::new($retval, $MyInvocation.MyCommand) }
|
||||
}
|
||||
catch [CAPIError] {
|
||||
Write-Warning $_.Exception.ErrorMessage()
|
||||
}
|
||||
[Int]$ptr
|
||||
[int]$ptr
|
||||
}
|
||||
|
||||
Function Param_Set_Multi {
|
||||
function Param_Set_Multi {
|
||||
param(
|
||||
[HashTable]$HASH
|
||||
[hashtable]$HASH
|
||||
)
|
||||
ForEach ($key in $HASH.keys) {
|
||||
$classobj , $m2, $m3 = $key.Split("_")
|
||||
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()) {
|
||||
foreach ($h in $HASH[$key].GetEnumerator()) {
|
||||
$property = $h.Name
|
||||
$value = $h.Value
|
||||
if ($value -in ('False', 'True')) { [System.Convert]::ToBoolean($value) }
|
||||
|
||||
Switch ($classobj) {
|
||||
switch ($classobj) {
|
||||
'strip' { $this.strip[$index].$property = $value }
|
||||
'bus' { $this.bus[$index].$property = $value }
|
||||
{ ($_ -eq 'button') -or ($_ -eq 'mb') } { $this.button[$index].$property = $value }
|
||||
@@ -175,3 +190,16 @@ Function Param_Set_Multi {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function Set_By_Script {
|
||||
param(
|
||||
[string]$script
|
||||
)
|
||||
try {
|
||||
$retval = [int][Voicemeeter.Remote]::VBVMR_SetParameters($script)
|
||||
if ($retval) { throw [CAPIError]::new($retval, $MyInvocation.MyCommand) }
|
||||
}
|
||||
catch [CAPIError] {
|
||||
Write-Warning $_.Exception.ErrorMessage()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user