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
This commit is contained in:
onyx-and-iris 2023-08-16 02:52:12 +01:00
parent ff1bd5e6cc
commit 1397c14522
10 changed files with 127 additions and 93 deletions

View File

@ -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 {

View File

@ -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) }

View File

@ -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
}

View File

@ -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)")
}

View File

@ -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"
}

View File

@ -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")
}
}

View File

@ -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)
}
)
}

View File

@ -1,5 +1,3 @@
. $PSScriptRoot\meta.ps1
class IRecorder {
[Object]$remote

View File

@ -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"
}
}

View File

@ -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')