From 62c65e1c082ef76e595e97c9d05df97ef015944e Mon Sep 17 00:00:00 2001 From: onyx-and-iris <75868496+onyx-and-iris@users.noreply.github.com> Date: Thu, 27 Oct 2022 21:20:03 +0100 Subject: [PATCH] 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. --- lib/Voicemeeter.psm1 | 36 ++++++++--- lib/base.ps1 | 150 +++++++++++++++++++++++++------------------ lib/binding.ps1 | 8 ++- lib/bus.ps1 | 52 ++++++++------- lib/command.ps1 | 28 ++++---- lib/errors.ps1 | 16 ++--- lib/inst.ps1 | 4 +- lib/kinds.ps1 | 4 +- lib/macrobuttons.ps1 | 34 +++++----- lib/meta.ps1 | 55 ++++++++-------- lib/profiles.ps1 | 14 ++-- lib/recorder.ps1 | 28 ++++---- lib/strip.ps1 | 52 ++++++++------- lib/vban.ps1 | 108 ++++++++++++++++--------------- 14 files changed, 331 insertions(+), 258 deletions(-) diff --git a/lib/Voicemeeter.psm1 b/lib/Voicemeeter.psm1 index 72c0a43..fe187d2 100644 --- a/lib/Voicemeeter.psm1 +++ b/lib/Voicemeeter.psm1 @@ -18,23 +18,35 @@ class Remote { } [void] Setup() { - if (Setup_DLL) { - Login -KIND $this.kind.name - $this.profiles = Get_Profiles($this.kind.name) - $this.strip = Make_Strips($this) - $this.bus = Make_Buses($this) - $this.button = Make_Buttons - $this.vban = Make_Vban($this) - $this.command = Make_Command - $this.recorder = Make_Recorder($this) + if (!(Setup_DLL)) { + Exit } - else { Exit } + Login -KIND $this.kind.name + $this.profiles = Get_Profiles($this.kind.name) + $this.strip = Make_Strips($this) + $this.bus = Make_Buses($this) + $this.button = Make_Buttons + $this.vban = Make_Vban($this) + $this.command = Make_Command + $this.recorder = Make_Recorder($this) + } + + [string] ToString() { + return "Voicemeeter " + $this.kind.name.substring(0,1).toupper() + $this.kind.name.substring(1) } [void] Logout() { Logout } + [void] GetType() { + VmType + } + + [String] GetVersion() { + return Version + } + [void] Set_Profile([String]$config) { Set_Profile -DATA $this.profiles -CONF $config } @@ -55,6 +67,10 @@ class Remote { Param_Set_Multi -HASH $hash } + [void] SendText([String]$script) { + Set_By_Script -SCRIPT $script + } + [void] PDirty() { P_Dirty } [void] MDirty() { M_Dirty } diff --git a/lib/base.ps1 b/lib/base.ps1 index f38b5fa..5ec59ff 100644 --- a/lib/base.ps1 +++ b/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() + } +} diff --git a/lib/binding.ps1 b/lib/binding.ps1 index 684bb00..f3a3c86 100644 --- a/lib/binding.ps1 +++ b/lib/binding.ps1 @@ -1,4 +1,4 @@ -Function Setup_DLL { +function Setup_DLL { try { $vb_path = Get_VBPath @@ -7,7 +7,7 @@ Function Setup_DLL { } else { $dll = Join-Path -Path $vb_path -ChildPath ("VoicemeeterRemote" + ` - (& { If ([Environment]::Is64BitOperatingSystem) { "64" } Else { "" } }) + ` + (& { if ([Environment]::Is64BitOperatingSystem) { "64" } else { "" } }) + ` ".dll") } } @@ -25,6 +25,8 @@ Function Setup_DLL { public static extern int VBVMR_RunVoicemeeter(Int64 run); [DllImport(@"$dll")] public static extern int VBVMR_GetVoicemeeterType(ref int ptr); + [DllImport(@"$dll")] + public static extern int VBVMR_GetVoicemeeterVersion(ref int ptr); [DllImport(@"$dll")] public static extern int VBVMR_MacroButton_IsDirty(); @@ -51,4 +53,4 @@ Function Setup_DLL { Add-Type -MemberDefinition $Signature -Name Remote -Namespace Voicemeeter -PassThru | Out-Null return $true -} \ No newline at end of file +} diff --git a/lib/bus.ps1 b/lib/bus.ps1 index 5b1196b..8948ac4 100644 --- a/lib/bus.ps1 +++ b/lib/bus.ps1 @@ -1,44 +1,48 @@ . $PSScriptRoot\meta.ps1 class Bus { - [Int]$id + [int]$index [Object]$remote # Constructor - Bus ([Int]$id, [Object]$remote) { - $this.id = $id + Bus ([int]$index, [Object]$remote) { + $this.index = $index $this.remote = $remote AddBoolMembers -PARAMS @('mono', 'mute') AddStringMembers -PARAMS @('label') - AddFloatMembers -PARAMS @('gain') + AddFloatMembers -PARAMS @('gain', 'returnreverb', 'returndelay', 'returnfx1', 'returnfx2') - AddBusModeMembers -PARAMS @('normal', 'amix', 'bmix', 'repeat', 'composite', 'tvmix', 'upmix21', - 'upmix41', 'upmix61', 'centeronly', 'lfeonly', 'rearonly') + AddBusModeMembers -PARAMS @('normal', 'amix', 'bmix', 'repeat', 'composite', 'tvmix', 'upmix21') + AddBusModeMembers -PARAMS @('upmix41', 'upmix61', 'centeronly', 'lfeonly', 'rearonly') } - [Single] Getter($cmd) { + [string] ToString() { + return $this.GetType().Name + $this.index + } + + [single] Getter ($cmd) { return Param_Get -PARAM $cmd -IS_STRING $false } - [String] Getter_String($cmd) { + [string] Getter_String ($cmd) { return Param_Get -PARAM $cmd -IS_STRING $true } - [void] Setter($cmd, $set) { - Param_Set -PARAM $cmd -VALUE $set + [void] Setter ($cmd, $set) { + Param_Set -PARAM $cmd -Value $set } [string] cmd ($arg) { - return "Bus[" + $this.id + "].$arg" + return "Bus[" + $this.index + "].$arg" } hidden $_eq = $($this | Add-Member ScriptProperty 'eq' ` { [bool]$this.Getter($this.cmd('EQ.on')) - }` + } ` { - param ( $arg ) + param($arg) $this._eq = $this.Setter($this.cmd('EQ.on'), $arg) } ) @@ -46,50 +50,50 @@ class Bus { hidden $_eq_ab = $($this | Add-Member ScriptProperty 'eq_ab' ` { [bool]$this.Getter($this.cmd('eq.ab')) - }` + } ` { - param ( $arg ) + param($arg) $this._eq = $this.Setter($this.cmd('eq.ab'), $arg) } ) - [void] FadeTo([Single]$target, [int]$time) { + [void] FadeTo ([single]$target, [int]$time) { $this.Setter($this.cmd('FadeTo'), "($target, $time)") } - [void] FadeBy([Single]$target, [int]$time) { + [void] FadeBy ([single]$target, [int]$time) { $this.Setter($this.cmd('FadeBy'), "($target, $time)") } } class PhysicalBus : Bus { - PhysicalBus ([Int]$id, [Object]$remote) : base ($id, $remote) { + PhysicalBus ([int]$index, [Object]$remote) : base ($index, $remote) { } hidden $_device = $($this | Add-Member ScriptProperty 'device' ` { $this.Getter_String($this.cmd('device.name')) - }` + } ` { - return Write-Warning("ERROR: " + $this.cmd('device.name') + " is read only") + return Write-Warning ("ERROR: " + $this.cmd('device.name') + " is read only") } ) hidden $_sr = $($this | Add-Member ScriptProperty 'sr' ` { $this.Getter($this.cmd('device.sr')) - }` + } ` { - return Write-Warning("ERROR: " + $this.cmd('device.sr') + " is read only") + return Write-Warning ("ERROR: " + $this.cmd('device.sr') + " is read only") } ) } class VirtualBus : Bus { - VirtualBus ([Int]$id, [Object]$remote) : base ($id, $remote) { + VirtualBus ([int]$index, [Object]$remote) : base ($index, $remote) { } } -Function Make_Buses([Object]$remote) { +function Make_Buses ([Object]$remote) { [System.Collections.ArrayList]$bus = @() 0..$($remote.kind.p_out + $remote.kind.v_out - 1) | ForEach-Object { if ($_ -lt $remote.kind.p_out) { [void]$bus.Add([PhysicalBus]::new($_, $remote)) } diff --git a/lib/command.ps1 b/lib/command.ps1 index 2ec0443..cd75fb6 100644 --- a/lib/command.ps1 +++ b/lib/command.ps1 @@ -2,40 +2,44 @@ class Special { # Constructor - Special() { + Special () { AddActionMembers -PARAMS @('restart', 'shutdown', 'show') } - [Single] Getter($cmd) { + [string] ToString() { + return $this.GetType().Name + } + + [single] Getter ($cmd) { return Param_Get -PARAM $cmd -IS_STRING $false } - [void] Setter($param, $val) { + [void] Setter ($param, $val) { if ($val -is [Boolean]) { - Param_Set -PARAM $param -VALUE $(if ($val) { 1 } else { 0 }) + Param_Set -PARAM $param -Value $(if ($val) { 1 } else { 0 }) } else { - Param_Set -PARAM $param -VALUE $val + Param_Set -PARAM $param -Value $val } } - [String] cmd ($arg) { + [string] cmd ($arg) { return "Command.$arg" } hidden $_hide = $($this | Add-Member ScriptProperty 'hide' ` { $this._hide = $this.Setter($this.cmd('show'), $false) - }` + } ` {} ) hidden $_showvbanchat = $($this | Add-Member ScriptProperty 'showvbanchat' ` { $this.Getter($this.cmd('DialogShow.VBANCHAT')) - }` + } ` { - param( [bool]$arg ) + param([bool]$arg) $this._showvbanchat = $this.Setter($this.cmd('DialogShow.VBANCHAT'), $arg) } ) @@ -43,14 +47,14 @@ class Special { hidden $_lock = $($this | Add-Member ScriptProperty 'lock' ` { $this._lock = $this.Getter($this.cmd('lock')) - }` + } ` { - param( [bool]$arg ) + param([bool]$arg) $this._lock = $this.Setter($this.cmd('lock'), $arg) } ) } -Function Make_Command { +function Make_Command { return [Special]::new() } diff --git a/lib/errors.ps1 b/lib/errors.ps1 index 99b86eb..a3d659d 100644 --- a/lib/errors.ps1 +++ b/lib/errors.ps1 @@ -1,30 +1,30 @@ class VMRemoteErrors : Exception { - [String]$msg + [string]$msg - VMRemoteErrors([String]$msg) { + VMRemoteErrors ([string]$msg) { $this.msg = $msg } - [String] ErrorMessage() { + [string] ErrorMessage () { return $this.msg } } class LoginError : VMRemoteErrors { - LoginError([String]$msg) : Base([String]$msg) { + LoginError ([string]$msg) : base ([string]$msg) { } } class CAPIError : VMRemoteErrors { - [Int]$retval - [String]$caller + [int]$retval + [string]$caller - CAPIError([Int]$retval, [String]$caller) { + CAPIError ([int]$retval, [string]$caller) { $this.retval = $retval $this.caller = $caller } - [String] ErrorMessage() { + [string] ErrorMessage () { return "ERROR: CAPI return value: {0} in {1}" -f $this.retval, $this.caller } } diff --git a/lib/inst.ps1 b/lib/inst.ps1 index b7f90c5..d9a69a4 100644 --- a/lib/inst.ps1 +++ b/lib/inst.ps1 @@ -1,6 +1,6 @@ -Function Get_VBPath { +function Get_VBPath { $reg_path = "Registry::HKEY_LOCAL_MACHINE\Software" + ` - (& { If ([Environment]::Is64BitOperatingSystem) { "\WOW6432Node" } Else { "" } }) + ` + (& { if ([Environment]::Is64BitOperatingSystem) { "\WOW6432Node" } else { "" } }) + ` "\Microsoft\Windows\CurrentVersion\Uninstall" $vm_key = "\VB:Voicemeeter {17359A74-1236-5467}\" diff --git a/lib/kinds.ps1 b/lib/kinds.ps1 index 6b44ff9..b4c8bec 100644 --- a/lib/kinds.ps1 +++ b/lib/kinds.ps1 @@ -28,6 +28,6 @@ $KindMap = @{ }; } -Function GetKind([string]$kind_id) { +function GetKind ([string]$kind_id) { $KindMap[$kind_id] -} \ No newline at end of file +} diff --git a/lib/macrobuttons.ps1 b/lib/macrobuttons.ps1 index 3040d56..a0da08a 100644 --- a/lib/macrobuttons.ps1 +++ b/lib/macrobuttons.ps1 @@ -1,25 +1,29 @@ class MacroButton { - [int32]$id - + [int32]$index + # Constructor - MacroButton ([Int]$id) { - $this.id = $id + MacroButton ([int]$index) { + $this.index = $index } - [int] Getter($mode) { - return MB_Get -ID $this.id -MODE $mode + [string] ToString() { + return $this.GetType().Name + $this.index } - [void] Setter($set, $mode) { - MB_Set -ID $this.id -SET $set -MODE $mode + [int] Getter ($mode) { + return MB_Get -Id $this.index -Mode $mode + } + + [void] Setter ($set, $mode) { + MB_Set -Id $this.index -SET $set -Mode $mode } hidden $_state = $($this | Add-Member ScriptProperty 'state' ` { $this.Getter(1) - }` + } ` { - param ( $arg ) + param($arg) $this._state = $this.Setter($arg, 1) } ) @@ -27,9 +31,9 @@ class MacroButton { hidden $_stateonly = $($this | Add-Member ScriptProperty 'stateonly' ` { $this.Getter(2) - }` + } ` { - param ( $arg ) + param($arg) $this._stateonly = $this.Setter($arg, 2) } ) @@ -37,15 +41,15 @@ class MacroButton { hidden $_trigger = $($this | Add-Member ScriptProperty 'trigger' ` { $this.Getter(3) - }` + } ` { - param ( $arg ) + param($arg) $this._trigger = $this.Setter($arg, 3) } ) } -Function Make_Buttons { +function Make_Buttons { [System.Collections.ArrayList]$button = @() 0..79 | ForEach-Object { [void]$button.Add([MacroButton]::new($_)) diff --git a/lib/meta.ps1 b/lib/meta.ps1 index e79c04f..f7f75f3 100644 --- a/lib/meta.ps1 +++ b/lib/meta.ps1 @@ -1,25 +1,25 @@ -Function AddBoolMembers() { +function AddBoolMembers () { param( [String[]]$PARAMS ) - [HashTable]$Signatures = @{} - ForEach ($param in $PARAMS) { + [hashtable]$Signatures = @{} + foreach ($param in $PARAMS) { # Define getter $Signatures["Getter"] = "[bool]`$this.Getter(`$this.cmd('{0}'))" -f $param # Define setter - $Signatures["Setter"] = "param ( [Single]`$arg )`n`$this.Setter(`$this.cmd('{0}'), `$arg)" ` + $Signatures["Setter"] = "param ( [Single]`$arg )`n`$this.Setter(`$this.cmd('{0}'), `$arg)" ` -f $param Addmember } } -Function AddFloatMembers() { +function AddFloatMembers () { param( [String[]]$PARAMS ) - [HashTable]$Signatures = @{} - ForEach ($param in $PARAMS) { + [hashtable]$Signatures = @{} + foreach ($param in $PARAMS) { # Define getter $Signatures["Getter"] = "[math]::Round(`$this.Getter(`$this.cmd('{0}')), 1)" -f $param # Define setter @@ -30,12 +30,12 @@ Function AddFloatMembers() { } } -Function AddIntMembers() { +function AddIntMembers () { param( [String[]]$PARAMS ) - [HashTable]$Signatures = @{} - ForEach ($param in $PARAMS) { + [hashtable]$Signatures = @{} + foreach ($param in $PARAMS) { # Define getter $Signatures["Getter"] = "[Int]`$this.Getter(`$this.cmd('{0}'))" -f $param # Define setter @@ -46,12 +46,12 @@ Function AddIntMembers() { } } -Function AddStringMembers() { +function AddStringMembers () { param( [String[]]$PARAMS ) - [HashTable]$Signatures = @{} - ForEach ($param in $PARAMS) { + [hashtable]$Signatures = @{} + foreach ($param in $PARAMS) { # Define getter $Signatures["Getter"] = "[String]`$this.Getter_String(`$this.cmd('{0}'))" -f $param # Define setter @@ -59,15 +59,15 @@ Function AddStringMembers() { -f $param Addmember - } + } } -Function AddActionMembers() { +function AddActionMembers () { param( [String[]]$PARAMS ) - [HashTable]$Signatures = @{} - ForEach ($param in $PARAMS) { + [hashtable]$Signatures = @{} + foreach ($param in $PARAMS) { # Define getter $Signatures["Getter"] = "`$this.Setter(`$this.cmd('{0}'), `$true)" -f $param # Define setter @@ -77,7 +77,7 @@ Function AddActionMembers() { } } -Function AddChannelMembers() { +function AddChannelMembers () { $num_A = $this.remote.kind.p_out $num_B = $this.remote.kind.v_out @@ -89,8 +89,8 @@ Function AddChannelMembers() { AddBoolMembers -PARAMS $channels } -Function AddGainlayerMembers() { - [HashTable]$Signatures = @{} +function AddGainlayerMembers () { + [hashtable]$Signatures = @{} 0..7 | ForEach-Object { # Define getter $Signatures["Getter"] = "`$this.Getter(`$this.cmd('gainlayer[{0}]'))" -f $_ @@ -98,21 +98,22 @@ Function AddGainlayerMembers() { $Signatures["Setter"] = "param ( [Single]`$arg )`n`$this.Setter(`$this.cmd('gainlayer[{0}]'), `$arg)" ` -f $_ $param = "gainlayer{0}" -f $_ + $null = $param Addmember } } -Function AddBusModeMembers() { +function AddBusModeMembers () { param( [String[]]$PARAMS ) - [HashTable]$Signatures = @{} - ForEach ($param in $PARAMS) { + [hashtable]$Signatures = @{} + foreach ($param in $PARAMS) { # Define getter $Signatures["Getter"] = "[bool]`$this.Getter(`$this.cmd('mode.{0}'))" -f $param # Define setter - $Signatures["Setter"] = "param ( [Single]`$arg )`n`$this.Setter(`$this.cmd('mode.{0}'), `$arg)" ` + $Signatures["Setter"] = "param ( [Single]`$arg )`n`$this.Setter(`$this.cmd('mode.{0}'), `$arg)" ` -f $param $param = "mode_{0}" -f $param @@ -120,12 +121,12 @@ Function AddBusModeMembers() { } } -Function Addmember { +function Addmember { $AddMemberParams = @{ Name = $param MemberType = 'ScriptProperty' - Value = [ScriptBlock]::Create($Signatures["Getter"]) - SecondValue = [ScriptBlock]::Create($Signatures["Setter"]) + Value = [scriptblock]::Create($Signatures["Getter"]) + SecondValue = [scriptblock]::Create($Signatures["Setter"]) } $this | Add-Member @AddMemberParams } diff --git a/lib/profiles.ps1 b/lib/profiles.ps1 index ca84448..3563920 100644 --- a/lib/profiles.ps1 +++ b/lib/profiles.ps1 @@ -1,4 +1,4 @@ -Function Get_Profiles([String]$kind_id) { +function Get_Profiles ([string]$kind_id) { $basepath = Join-Path -Path $(Split-Path -Path $PSScriptRoot) -ChildPath "profiles" if (Test-Path $basepath) { $fullpath = Join-Path -Path $basepath -ChildPath $kind_id @@ -6,7 +6,7 @@ Function Get_Profiles([String]$kind_id) { else { return $null } $filenames = @(Get-ChildItem -Path $fullpath -Filter *.psd1 -Recurse -File) - [HashTable]$data = @{} + [hashtable]$data = @{} if ($filenames) { $filenames | ForEach-Object { (Join-Path -Path $fullpath -ChildPath $_) | ForEach-Object { @@ -15,23 +15,23 @@ Function Get_Profiles([String]$kind_id) { $data[$filename] = Import-PowerShellDataFile -Path $_ } } - return $data + return $data } return $null } -Function Set_Profile { +function Set_Profile { param( - [Object]$DATA, [String]$CONF + [Object]$DATA, [string]$CONF ) try { if ($null -eq $DATA -or -not $DATA.$CONF) { throw [VMRemoteErrors]::new("No profile named $CONF was loaded") } Param_Set_Multi -HASH $DATA.$CONF - Start-Sleep -m 1 + Start-Sleep -m 1 } catch [VMRemoteErrors] { Write-Warning $_.Exception.ErrorMessage() } -} \ No newline at end of file +} diff --git a/lib/recorder.ps1 b/lib/recorder.ps1 index e90abb9..477b742 100644 --- a/lib/recorder.ps1 +++ b/lib/recorder.ps1 @@ -3,45 +3,49 @@ class Recorder { [Object]$remote # Constructor - Recorder([Object]$remote) { + Recorder ([Object]$remote) { $this.remote = $remote - + AddActionMembers -PARAMS @('play', 'stop', 'pause', 'replay', 'record', 'ff', 'rew') AddChannelMembers } - [Single] Getter($cmd) { + [string] ToString() { + return $this.GetType().Name + } + + [single] Getter ($cmd) { return Param_Get -PARAM $cmd -IS_STRING $false } - [void] Setter($param, $val) { + [void] Setter ($param, $val) { if ($val -is [Boolean]) { - Param_Set -PARAM $param -VALUE $(if ($val) { 1 } else { 0 }) + Param_Set -PARAM $param -Value $(if ($val) { 1 } else { 0 }) } else { - Param_Set -PARAM $param -VALUE $val + Param_Set -PARAM $param -Value $val } } - [String] cmd ($arg) { + [string] cmd ($arg) { return "Recorder.$arg" } hidden $_loop = $($this | Add-Member ScriptProperty 'loop' ` { - return Write-Warning("ERROR: " + $this.cmd('mode.loop') + " is write only") - }` + return Write-Warning ("ERROR: " + $this.cmd('mode.loop') + " is write only") + } ` { - param( [bool]$arg ) + param([bool]$arg) $this._loop = $this.Setter($this.cmd('mode.loop'), $arg) } ) - [void] Load([String]$filename) { + [void] Load ([string]$filename) { $this.Setter($this.cmd('load'), $filename) } } -Function Make_Recorder([Object]$remote) { +function Make_Recorder ([Object]$remote) { return [Recorder]::new($remote) } diff --git a/lib/strip.ps1 b/lib/strip.ps1 index f3bef19..2f32320 100644 --- a/lib/strip.ps1 +++ b/lib/strip.ps1 @@ -1,84 +1,90 @@ . $PSScriptRoot\meta.ps1 class Strip { - [Int]$id + [int]$index [Object]$remote - Strip ([Int]$id, [Object]$remote) { - $this.id = $id + Strip ([int]$index, [Object]$remote) { + $this.index = $index $this.remote = $remote AddBoolMembers -PARAMS @('mono', 'solo', 'mute') AddIntMembers -PARAMS @('limit') - AddFloatMembers -PARAMS @('gain') + AddFloatMembers -PARAMS @('gain', 'pan_x', 'pan_y') AddStringMembers -PARAMS @('label') AddChannelMembers AddGainlayerMembers } - [Single] Getter($cmd) { + [string] ToString() { + return $this.GetType().Name + $this.index + } + + [single] Getter ($cmd) { return Param_Get -PARAM $cmd -IS_STRING $false } - [String] Getter_String($cmd) { + [string] Getter_String ($cmd) { return Param_Get -PARAM $cmd -IS_STRING $true } - [void] Setter($cmd, $val) { - Param_Set -PARAM $cmd -VALUE $val + [void] Setter ($cmd, $val) { + Param_Set -PARAM $cmd -Value $val } - [String] cmd ($arg) { - return "Strip[" + $this.id + "].$arg" + [string] cmd ($arg) { + return "Strip[" + $this.index + "].$arg" } - [void] FadeTo([Single]$target, [int]$time) { + [void] FadeTo ([single]$target, [int]$time) { $this.Setter($this.cmd('FadeTo'), "($target, $time)") } - [void] FadeBy([Single]$target, [int]$time) { + [void] FadeBy ([single]$target, [int]$time) { $this.Setter($this.cmd('FadeBy'), "($target, $time)") } } class PhysicalStrip : Strip { - PhysicalStrip ([Int]$id, [Object]$remote) : base ($id, $remote) { - AddFloatMembers -PARAMS @('comp', 'gate') + PhysicalStrip ([int]$index, [Object]$remote) : base ($index, $remote) { + AddFloatMembers -PARAMS @('comp', 'gate', 'color_x', 'color_y', 'fx_x', 'fx_y') + AddFloatMembers -PARAMS @('reverb', 'delay', 'fx1', 'fx2') + AddBoolMembers -PARAMS @('postreverb', 'postdelay', 'postfx1', 'postfx2') } - + hidden $_device = $($this | Add-Member ScriptProperty 'device' ` { $this.Getter_String($this.cmd('device.name')) - }` + } ` { - return Write-Warning("ERROR: " + $this.cmd('device.name') + " is read only") + return Write-Warning ("ERROR: " + $this.cmd('device.name') + " is read only") } ) hidden $_sr = $($this | Add-Member ScriptProperty 'sr' ` { $this.Getter($this.cmd('device.sr')) - }` + } ` { - return Write-Warning("ERROR: " + $this.cmd('device.sr') + " is read only") + return Write-Warning ("ERROR: " + $this.cmd('device.sr') + " is read only") } ) } class VirtualStrip : Strip { - VirtualStrip ([Int]$id, [Object]$remote) : base ($id, $remote) { + VirtualStrip ([int]$index, [Object]$remote) : base ($index, $remote) { AddBoolMembers -PARAMS @('mc') AddIntMembers -PARAMS @('k') } } -Function Make_Strips([Object]$remote) { +function Make_Strips ([Object]$remote) { [System.Collections.ArrayList]$strip = @() 0..$($remote.kind.p_in + $remote.kind.v_in - 1) | ForEach-Object { - if ($_ -lt $remote.kind.p_in) { - [void]$strip.Add([PhysicalStrip]::new($_, $remote)) + if ($_ -lt $remote.kind.p_in) { + [void]$strip.Add([PhysicalStrip]::new($_, $remote)) } else { [void]$strip.Add([VirtualStrip]::new($_, $remote)) } } diff --git a/lib/vban.ps1 b/lib/vban.ps1 index 0ac8912..166afa3 100644 --- a/lib/vban.ps1 +++ b/lib/vban.ps1 @@ -1,34 +1,38 @@ class Vban { - [int32]$id - [String]$direction + [int32]$index + [string]$direction # Constructor - Vban([Int]$id) { - $this.id = $id + Vban ([int]$index) { + $this.index = $index } - [Single] Getter($cmd) { + [string] ToString() { + return $this.GetType().Name + $this.index + } + + [single] Getter ($cmd) { return Param_Get -PARAM $cmd -IS_STRING $false } - [String] Getter_String($cmd) { + [string] Getter_String ($cmd) { return Param_Get -PARAM $cmd -IS_STRING $true } - [void] Setter($cmd, $set) { - Param_Set -PARAM $cmd -VALUE $set + [void] Setter ($cmd, $set) { + Param_Set -PARAM $cmd -Value $set } - [String] cmd ($arg) { - return "vban." + $this.direction + "stream[" + $this.id + "].$arg" + [string] cmd ($arg) { + return "vban." + $this.direction + "stream[" + $this.index + "].$arg" } hidden $_on = $($this | Add-Member ScriptProperty 'on' ` { $this.Getter($this.cmd('on')) - }` + } ` { - param ( [Bool]$arg ) + param([bool]$arg) $this._on = $this.Setter($this.cmd('on'), $arg) } ) @@ -36,9 +40,9 @@ class Vban { hidden $_name = $($this | Add-Member ScriptProperty 'name' ` { $this.Getter_String($this.cmd('name')) - }` + } ` { - param ( [String]$arg ) + param([string]$arg) $this._name = $this.Setter($this.cmd('name'), $arg) } ) @@ -46,9 +50,9 @@ class Vban { hidden $_ip = $($this | Add-Member ScriptProperty 'ip' ` { $this.Getter_String($this.cmd('ip')) - }` + } ` { - param ( [String]$arg ) + param([string]$arg) $this._ip = $this.Setter($this.cmd('ip'), $arg) } ) @@ -56,14 +60,14 @@ class Vban { hidden $_port = $($this | Add-Member ScriptProperty 'port' ` { $this.Getter($this.cmd('port')) - }` + } ` { - param ( [String]$arg ) - if ($arg -In 1024..65535) { + param([string]$arg) + if ($arg -in 1024..65535) { $this._port = $this.Setter($this.cmd('port'), $arg) } else { - Write-Warning('Expected value from 1024 to 65535') + Write-Warning ('Expected value from 1024 to 65535') } } ) @@ -71,17 +75,17 @@ class Vban { hidden $_sr = $($this | Add-Member ScriptProperty 'sr' ` { $this.Getter($this.cmd('sr')) - }` + } ` { - param ( [Int]$arg ) - if ($this.direction -eq "in") { Write-Warning('Error, read only value') } + param([int]$arg) + if ($this.direction -eq "in") { Write-Warning ('Error, read only value') } else { $opts = @(11025, 16000, 22050, 24000, 32000, 44100, 48000, 64000, 88200, 96000) if ($opts.Contains($arg)) { $this._port = $this.Setter($this.cmd('sr'), $arg) } else { - Write-Warning('Expected one of', $opts) + Write-Warning ('Expected one of', $opts) } } } @@ -90,16 +94,16 @@ class Vban { hidden $_channel = $($this | Add-Member ScriptProperty 'channel' ` { $this.Getter($this.cmd('channel')) - }` + } ` { - param ( [Int]$arg ) - if ($this.direction -eq "in") { Write-Warning('Error, read only value') } + param([int]$arg) + if ($this.direction -eq "in") { Write-Warning ('Error, read only value') } else { - if ($arg -In 1..8) { + if ($arg -in 1..8) { $this._channel = $this.Setter($this.cmd('channel'), $arg) } else { - Write-Warning('Expected value from 1 to 8') + Write-Warning ('Expected value from 1 to 8') } } } @@ -109,17 +113,17 @@ class Vban { { $val = if ($this.Getter($this.cmd('bit')) -eq 1) { 16 } else { 24 } return $val - }` + } ` { - param ( [Int]$arg ) - if ($this.direction -eq "in") { Write-Warning('Error, read only value') } + param([int]$arg) + if ($this.direction -eq "in") { Write-Warning ('Error, read only value') } else { if (@(16, 24).Contains($arg)) { $val = if ($arg -eq 16) { 1 } else { 2 } $this._bit = $this.Setter($this.cmd('bit'), $val) } else { - Write-Warning('Expected value 16 or 24') + Write-Warning ('Expected value 16 or 24') } } } @@ -128,16 +132,16 @@ class Vban { hidden $_quality = $($this | Add-Member ScriptProperty 'quality' ` { $this.Getter($this.cmd('quality')) - }` + } ` { - param ( [Int]$arg ) - if ($this.direction -eq "in") { Write-Warning('Error, read only value') } + param([int]$arg) + if ($this.direction -eq "in") { Write-Warning ('Error, read only value') } else { - if ($arg -In 0..4) { + if ($arg -in 0..4) { $this._quality = $this.Setter($this.cmd('quality'), $arg) } else { - Write-Warning('Expected value from 0 to 4') + Write-Warning ('Expected value from 0 to 4') } } } @@ -146,16 +150,16 @@ class Vban { hidden $_route = $($this | Add-Member ScriptProperty 'route' ` { $this.Getter($this.cmd('route')) - }` + } ` { - param ( [Int]$arg ) - if ($this.direction -eq "in") { Write-Warning('Error, read only value') } + param([int]$arg) + if ($this.direction -eq "in") { Write-Warning ('Error, read only value') } else { - if ($arg -In 0..8) { + if ($arg -in 0..8) { $this._route = $this.Setter($this.cmd('route'), $arg) } else { - Write-Warning('Expected value from 0 to 8') + Write-Warning ('Expected value from 0 to 8') } } } @@ -165,7 +169,7 @@ class Vban { class VbanInstream : Vban { # Constructor - VbanInstream ([Int]$id) : base ($id) { + VbanInstream ([int]$index) : base ($index) { $this.direction = "in" } } @@ -173,13 +177,13 @@ class VbanInstream : Vban { class VbanOutstream : Vban { # Constructor - VbanOutstream ([Int]$id) : base ($id) { + VbanOutstream ([int]$index) : base ($index) { $this.direction = "out" } } -Function Make_Vban([Object]$remote) { +function Make_Vban ([Object]$remote) { [System.Collections.ArrayList]$instream = @() [System.Collections.ArrayList]$outstream = @() @@ -190,17 +194,17 @@ Function Make_Vban([Object]$remote) { [void]$outstream.Add([VbanOutstream]::new($_)) } - $CustomObject = [PSCustomObject]@{ + $CustomObject = [pscustomobject]@{ instream = $instream outstream = $outstream - } - + } + $CustomObject | Add-Member ScriptProperty 'enable' ` { - return Write-Warning("ERROR: vban.enable is write only") - }` + return Write-Warning ("ERROR: vban.enable is write only") + } ` { - param( [bool]$arg ) + param([bool]$arg) Param_Set -PARAM 'vban.Enable' -Value $(if ($arg) { 1 } else { 0 }) }