From 1397c14522efc6ecdf8ad78e8e8b28507ce7928a Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Wed, 16 Aug 2023 02:52:12 +0100 Subject: [PATCH] debug statements added to getters and setters made some rearrangements to the dot sourcing ButtonTypes enum added to macrobuttons.ps1 login string now includes version number Test-RegistryValue added to inst.ps1 --- lib/Voicemeeter.psm1 | 24 +++++++++++++---- lib/base.ps1 | 62 +++++++++++++++++++------------------------- lib/binding.ps1 | 23 ++++++---------- lib/bus.ps1 | 26 ++++++++++++------- lib/command.ps1 | 7 +++-- lib/inst.ps1 | 11 +++++--- lib/macrobuttons.ps1 | 24 +++++++++++------ lib/recorder.ps1 | 2 -- lib/strip.ps1 | 18 +++++++++---- lib/vban.ps1 | 23 +++++++++++----- 10 files changed, 127 insertions(+), 93 deletions(-) diff --git a/lib/Voicemeeter.psm1 b/lib/Voicemeeter.psm1 index 1982030..a57898a 100644 --- a/lib/Voicemeeter.psm1 +++ b/lib/Voicemeeter.psm1 @@ -1,14 +1,22 @@ -. $PSScriptRoot\kinds.ps1 +. $PSScriptRoot\errors.ps1 +. $PSScriptRoot\meta.ps1 . $PSScriptRoot\base.ps1 +. $PSScriptRoot\kinds.ps1 +. $PSScriptRoot\strip.ps1 +. $PSScriptRoot\bus.ps1 +. $PSScriptRoot\macrobuttons.ps1 +. $PSScriptRoot\vban.ps1 +. $PSScriptRoot\command.ps1 +. $PSScriptRoot\recorder.ps1 +. $PSScriptRoot\profiles.ps1 class Remote { + [String]$vmpath [Hashtable]$kind [Object]$profiles Remote ([String]$kindId) { - if (!(Setup_DLL)) { - Exit -1 - } + $this.vmpath = Setup_DLL $this.kind = GetKind($kindId) $this.profiles = Get_Profiles($this.kind.name) } @@ -31,7 +39,7 @@ class Remote { } [String] GetVersion() { - return Version + return VmVersion } [void] Set_Profile([String]$config) { @@ -147,6 +155,12 @@ Function Connect-Voicemeeter { Write-Warning $_.Exception.ErrorMessage() throw } + catch [VMRemoteError] { + $_.Exception.ErrorMessage() | Write-Warning + if ($_.Exception.ErrorMessage() -eq "Couldn't get Voicemeeter path") { + Exit -1 + } + } } Function Disconnect-Voicemeeter { diff --git a/lib/base.ps1 b/lib/base.ps1 index 543fd94..de763cd 100644 --- a/lib/base.ps1 +++ b/lib/base.ps1 @@ -1,13 +1,5 @@ . $PSScriptRoot\errors.ps1 . $PSScriptRoot\binding.ps1 -. $PSScriptRoot\profiles.ps1 -. $PSScriptRoot\inst.ps1 -. $PSScriptRoot\strip.ps1 -. $PSScriptRoot\bus.ps1 -. $PSScriptRoot\macrobuttons.ps1 -. $PSScriptRoot\vban.ps1 -. $PSScriptRoot\command.ps1 -. $PSScriptRoot\recorder.ps1 function Login { param( @@ -15,46 +7,46 @@ function Login { ) try { $retval = [int][Voicemeeter.Remote]::VBVMR_Login() - if (-not $retval) { - "LOGGED IN" | Write-Verbose - } - elseif ($retval -eq 1) { - "VM NOT RUNNING" | Write-Verbose - New-Variable -Name vmExe -Value 0 + if ($retval -ne 0) { + switch ($retval) { + 1 { + New-Variable -Name vmExe -Value 0 - if ( $kindId -eq "basic" ) { $vmExe = 1 } - elseif ( $kindId -eq "banana" ) { $vmExe = 2 } - elseif ( $kindId -eq "potato" ) { - $vmExe = $(if ([Environment]::Is64BitOperatingSystem) { 6 } else { 3 }) - } + if ( $kindId -eq "basic" ) { $vmExe = 1 } + elseif ( $kindId -eq "banana" ) { $vmExe = 2 } + elseif ( $kindId -eq "potato" ) { + $vmExe = $(if ([Environment]::Is64BitOperatingSystem) { 6 } else { 3 }) + } - $retval = [int][Voicemeeter.Remote]::VBVMR_RunVoicemeeter([int64]$vmExe) - if (-not $retval) { - "STARTING VOICEMEETER" | Write-Verbose - Start-Sleep -s 1 + $retval = [int][Voicemeeter.Remote]::VBVMR_RunVoicemeeter([int64]$vmExe) + if (-not $retval) { + "Voicemeeter Engine running but GUI not launched. Launching GUI now." | Write-Verbose + Start-Sleep -s 1 + } + else { + throw [CAPIError]::new($retval, $MyInvocation.MyCommand) + } + } + -2 { + throw [LoginError]::new('Login may only be called once per session') + } + default { throw [CAPIError]::new($retval, $MyInvocation.MyCommand) } } - else { - throw [CAPIError]::new($retval, $MyInvocation.MyCommand) - } - } - elseif ($retval -eq -2) { - throw [LoginError]::new('login may only be called once per session') - } - else { throw [CAPIError]::new($retval, $MyInvocation.MyCommand) } + } } catch [LoginError] { - Write-Warning "$($_.Exception.ErrorMessage()). Fatal error, exiting..." + "$($_.Exception.ErrorMessage()). Fatal error, exiting..." | Write-Warning exit -2 } while (P_Dirty -or M_Dirty) { Start-Sleep -m 1 } - "VERSION:[" + $(VmType).ToUpper() + "]" | Write-Verbose + "Successfully logged into Voicemeeter [" + $(VmType).ToUpper() + "] Version " + $(VmVersion) | Write-Verbose } function Logout { Start-Sleep -m 20 $retval = [int][Voicemeeter.Remote]::VBVMR_Logout() - if (-not $retval) { "LOGGED OUT" | Write-Verbose } + if ($retval -eq 0) { "Sucessfully logged out" | Write-Verbose } } function P_Dirty { @@ -76,7 +68,7 @@ function VmType { } } -function Version { +function VmVersion { New-Variable -Name ptr -Value 0 $retval = [int][Voicemeeter.Remote]::VBVMR_GetVoicemeeterVersion([ref]$ptr) if ($retval) { throw [CAPIError]::new($retval, $MyInvocation.MyCommand) } diff --git a/lib/binding.ps1 b/lib/binding.ps1 index 83fe3cf..d77804e 100644 --- a/lib/binding.ps1 +++ b/lib/binding.ps1 @@ -1,18 +1,11 @@ -function Setup_DLL { - try { - $vb_path = Get_VMPath +. $PSScriptRoot\inst.ps1 - if ([string]::IsNullOrWhiteSpace($vb_path)) { - throw [VMRemoteError]::new("couldn't get Voicemeeter path") - } - $dll = Join-Path -Path $vb_path -ChildPath ("VoicemeeterRemote" + ` - (& { if ([Environment]::Is64BitOperatingSystem) { "64" } else { "" } }) + ` - ".dll") - } - catch [VMRemoteError] { - Write-Warning $_.Exception.ErrorMessage() - return $false - } +function Setup_DLL { + $VMPATH = Get_VMPath + + $dll = Join-Path -Path $VMPATH -ChildPath ("VoicemeeterRemote" + ` + (& { if ([Environment]::Is64BitOperatingSystem) { "64" } else { "" } }) + ` + ".dll") $Signature = @" [DllImport(@"$dll")] @@ -53,5 +46,5 @@ function Setup_DLL { "@ Add-Type -MemberDefinition $Signature -Name Remote -Namespace Voicemeeter -PassThru | Out-Null - return $true + return $VMPATH } diff --git a/lib/bus.ps1 b/lib/bus.ps1 index ae13cdf..1c6357e 100644 --- a/lib/bus.ps1 +++ b/lib/bus.ps1 @@ -1,5 +1,3 @@ -. $PSScriptRoot\meta.ps1 - class IBus { [int]$index [Object]$remote @@ -13,20 +11,26 @@ class IBus { return "Bus[" + $this.index + "]" } - [string] ToString() { - return $this.GetType().Name + $this.index - } - [single] Getter ($param) { - return $this.remote.Getter("$($this.identifier()).$param") + $this.ToString() + " Getter: $($this.Cmd($param))" | Write-Debug + return $this.remote.Getter($this.Cmd($param)) } [string] Getter_String ($param) { - return $this.remote.Getter_String("$($this.identifier()).$param") + $this.ToString() + " Getter_String: $($this.Cmd($param))" | Write-Debug + return $this.remote.Getter_String($this.Cmd($param)) } [void] Setter ($param, $val) { - $this.remote.Setter("$($this.identifier()).$param", $val) + $this.ToString() + " Setter: $($this.Cmd($param))=$val" | Write-Debug + $this.remote.Setter($this.Cmd($param), $val) + } + + [string] Cmd ($param) { + if ([string]::IsNullOrEmpty($param)) { + return $this.identifier() + } + return "$($this.identifier()).$param" } } @@ -45,6 +49,10 @@ class Bus : IBus { $this.levels = [BusLevels]::new($index, $remote) } + [string] ToString() { + return $this.GetType().Name + $this.index + } + [void] FadeTo ([single]$target, [int]$time) { $this.Setter('FadeTo', "($target, $time)") } diff --git a/lib/command.ps1 b/lib/command.ps1 index c09fdb4..00309c1 100644 --- a/lib/command.ps1 +++ b/lib/command.ps1 @@ -1,6 +1,3 @@ -. $PSScriptRoot\meta.ps1 -. $PSScriptRoot\inst.ps1 - class Special { [Object]$remote @@ -32,10 +29,12 @@ class Special { } [void] RunMacrobuttons() { - Start-Process -FilePath $(Join-Path -Path $(Get_VMPath) -ChildPath "VoicemeeterMacroButtons.exe") + "Launching the MacroButtons app" | Write-Verbose + Start-Process -FilePath $(Join-Path -Path $this.remote.vmpath -ChildPath "VoicemeeterMacroButtons.exe") } [void] CloseMacrobuttons() { + "Closing the MacroButtons app" | Write-Verbose Stop-Process -Name "VoicemeeterMacroButtons" } diff --git a/lib/inst.ps1 b/lib/inst.ps1 index 93f0e5b..01ecb95 100644 --- a/lib/inst.ps1 +++ b/lib/inst.ps1 @@ -1,8 +1,13 @@ function Get_VMPath { - $reg_path = "Registry::HKEY_LOCAL_MACHINE\Software" + ` + $REG_KEY = "Registry::HKEY_LOCAL_MACHINE\Software" + ` (& { if ([Environment]::Is64BitOperatingSystem) { "\WOW6432Node" } else { "" } }) + ` "\Microsoft\Windows\CurrentVersion\Uninstall" - $vm_key = "\VB:Voicemeeter {17359A74-1236-5467}\" + $VM_KEY = "\VB:Voicemeeter {17359A74-1236-5467}\" - return $(Get-ItemPropertyValue -Path ($reg_path + $vm_key) -Name UninstallString | Split-Path -Parent) + try { + return $(Get-ItemPropertyValue -Path ($REG_KEY + $VM_KEY) -Name UninstallString | Split-Path -Parent) + } + catch { + throw [VMRemoteError]::new("Couldn't get Voicemeeter path") + } } diff --git a/lib/macrobuttons.ps1 b/lib/macrobuttons.ps1 index f95e373..2d312a5 100644 --- a/lib/macrobuttons.ps1 +++ b/lib/macrobuttons.ps1 @@ -1,3 +1,9 @@ +enum ButtonTypes { + State = 1 + StateOnly = 2 + Trigger = 3 +} + class MacroButton { [int32]$index @@ -10,40 +16,42 @@ class MacroButton { } [int] Getter ($mode) { + "Button[$($this.index)].$([ButtonTypes].GetEnumName($mode))" | Write-Debug return MB_Get -Id $this.index -Mode $mode } - [void] Setter ($set, $mode) { - MB_Set -Id $this.index -SET $set -Mode $mode + [void] Setter ($val, $mode) { + "Button[$($this.index)].$([ButtonTypes].GetEnumName($mode))=$val" | Write-Debug + MB_Set -Id $this.index -SET $val -Mode $mode } hidden $_state = $($this | Add-Member ScriptProperty 'state' ` { - [bool]$this.Getter(1) + [bool]$this.Getter([ButtonTypes]::State) } ` { param($arg) - $this._state = $this.Setter($arg, 1) + $this._state = $this.Setter($arg, [ButtonTypes]::State) } ) hidden $_stateonly = $($this | Add-Member ScriptProperty 'stateonly' ` { - [bool]$this.Getter(2) + [bool]$this.Getter([ButtonTypes]::StateOnly) } ` { param($arg) - $this._stateonly = $this.Setter($arg, 2) + $this._stateonly = $this.Setter($arg, [ButtonTypes]::StateOnly) } ) hidden $_trigger = $($this | Add-Member ScriptProperty 'trigger' ` { - [bool]$this.Getter(3) + [bool]$this.Getter([ButtonTypes]::Trigger) } ` { param($arg) - $this._trigger = $this.Setter($arg, 3) + $this._trigger = $this.Setter($arg, [ButtonTypes]::Trigger) } ) } diff --git a/lib/recorder.ps1 b/lib/recorder.ps1 index 194333a..da8c54d 100644 --- a/lib/recorder.ps1 +++ b/lib/recorder.ps1 @@ -1,5 +1,3 @@ -. $PSScriptRoot\meta.ps1 - class IRecorder { [Object]$remote diff --git a/lib/strip.ps1 b/lib/strip.ps1 index fcbb301..94f762f 100644 --- a/lib/strip.ps1 +++ b/lib/strip.ps1 @@ -1,5 +1,3 @@ -. $PSScriptRoot\meta.ps1 - class IStrip { [int]$index [Object]$remote @@ -14,15 +12,25 @@ class IStrip { } [single] Getter ($param) { - return $this.remote.Getter("$($this.identifier()).$param") + $this.Cmd($param) | Write-Debug + return $this.remote.Getter($this.Cmd($param)) } [string] Getter_String ($param) { - return $this.remote.Getter_String("$($this.identifier()).$param") + $this.Cmd($param) | Write-Debug + return $this.remote.Getter_String($this.Cmd($param)) } [void] Setter ($param, $val) { - $this.remote.Setter("$($this.identifier()).$param", $val) + "$($this.Cmd($param))=$val" | Write-Debug + $this.remote.Setter($this.Cmd($param), $val) + } + + [string] Cmd ($param) { + if ([string]::IsNullOrEmpty($param)) { + return $this.identifier() + } + return "$($this.identifier()).$param" } } diff --git a/lib/vban.ps1 b/lib/vban.ps1 index 18e784f..e827c55 100644 --- a/lib/vban.ps1 +++ b/lib/vban.ps1 @@ -13,20 +13,25 @@ class IVban { return "vban." + $this.direction + "stream[" + $this.index + "]" } - [string] ToString() { - return $this.GetType().Name + $this.index - } - [single] Getter ($param) { - return $this.remote.Getter("$($this.identifier()).$param") + return $this.remote.Getter($this.Cmd($param)) } [string] Getter_String ($param) { - return $this.remote.Getter_String("$($this.identifier()).$param") + $this.Cmd($param) | Write-Debug + return $this.remote.Getter_String($this.Cmd($param)) } [void] Setter ($param, $val) { - $this.remote.Setter("$($this.identifier()).$param", $val) + "$($this.Cmd($param))=$val" | Write-Debug + $this.remote.Setter($this.Cmd($param), $val) + } + + [string] Cmd ($param) { + if ([string]::IsNullOrEmpty($param)) { + return $this.identifier() + } + return "$($this.identifier()).$param" } } @@ -34,6 +39,10 @@ class Vban : IVban { Vban ([int]$index, [Object]$remote, [string]$direction) : base ($index, $remote, $direction) { } + [string] ToString() { + return $this.GetType().Name + $this.index + } + hidden $_on = $($this | Add-Member ScriptProperty 'on' ` { $this.Getter('on')