From 4e9ff66640ecc114c8cfbfc61d70da2ad7bcd557 Mon Sep 17 00:00:00 2001 From: onyx Date: Sat, 12 Aug 2023 03:09:23 +0100 Subject: [PATCH] rework getters, setters in higher classes --- lib/Voicemeeter.psm1 | 6 +++--- lib/bus.ps1 | 8 ++++---- lib/command.ps1 | 16 ++++++++++------ lib/recorder.ps1 | 6 +++--- lib/strip.ps1 | 6 +++--- lib/vban.ps1 | 20 +++++++++++--------- 6 files changed, 34 insertions(+), 28 deletions(-) diff --git a/lib/Voicemeeter.psm1 b/lib/Voicemeeter.psm1 index bc8009f..1982030 100644 --- a/lib/Voicemeeter.psm1 +++ b/lib/Voicemeeter.psm1 @@ -75,7 +75,7 @@ class RemoteBasic : Remote { $this.bus = Make_Buses($this) $this.button = Make_Buttons $this.vban = Make_Vban($this) - $this.command = Make_Command + $this.command = Make_Command($this) } } @@ -92,7 +92,7 @@ class RemoteBanana : Remote { $this.bus = Make_Buses($this) $this.button = Make_Buttons $this.vban = Make_Vban($this) - $this.command = Make_Command + $this.command = Make_Command($this) $this.recorder = Make_Recorder($this) } } @@ -110,7 +110,7 @@ class RemotePotato : Remote { $this.bus = Make_Buses($this) $this.button = Make_Buttons $this.vban = Make_Vban($this) - $this.command = Make_Command + $this.command = Make_Command($this) $this.recorder = Make_Recorder($this) } } diff --git a/lib/bus.ps1 b/lib/bus.ps1 index 8bd6704..ae13cdf 100644 --- a/lib/bus.ps1 +++ b/lib/bus.ps1 @@ -18,15 +18,15 @@ class IBus { } [single] Getter ($param) { - return Param_Get -PARAM "$($this.identifier()).$param" -IS_STRING $false + return $this.remote.Getter("$($this.identifier()).$param") } [string] Getter_String ($param) { - return Param_Get -PARAM "$($this.identifier()).$param" -IS_STRING $true + return $this.remote.Getter_String("$($this.identifier()).$param") } - [void] Setter ($param, $set) { - Param_Set -PARAM "$($this.identifier()).$param" -Value $set + [void] Setter ($param, $val) { + $this.remote.Setter("$($this.identifier()).$param", $val) } } diff --git a/lib/command.ps1 b/lib/command.ps1 index 6df83c9..c09fdb4 100644 --- a/lib/command.ps1 +++ b/lib/command.ps1 @@ -2,8 +2,12 @@ . $PSScriptRoot\inst.ps1 class Special { - Special () { + [Object]$remote + + Special ([Object]$remote) { AddActionMembers -PARAMS @('restart', 'shutdown', 'show') + + $this.remote = $remote } [string] identifier () { @@ -15,15 +19,15 @@ class Special { } [single] Getter ($param) { - return Param_Get -PARAM "$($this.identifier()).$param" -IS_STRING $false + return $this.remote.Getter("$($this.identifier()).$param") } [void] Setter ($param, $val) { if ($val -is [Boolean]) { - Param_Set -PARAM "$($this.identifier()).$param" -Value $(if ($val) { 1 } else { 0 }) + $this.remote.Setter("$($this.identifier()).$param", $(if ($val) { 1 } else { 0 })) } else { - Param_Set -PARAM "$($this.identifier()).$param" -Value $val + $this.remote.Setter("$($this.identifier()).$param", $val) } } @@ -67,6 +71,6 @@ class Special { } } -function Make_Command { - return [Special]::new() +function Make_Command([Object]$remote) { + return [Special]::new($remote) } diff --git a/lib/recorder.ps1 b/lib/recorder.ps1 index 661b623..ceab302 100644 --- a/lib/recorder.ps1 +++ b/lib/recorder.ps1 @@ -8,15 +8,15 @@ class IRecorder { } [single] Getter ($param) { - return Param_Get -PARAM "$($this.identifier()).$param" -IS_STRING $false + return $this.remote.Getter("$($this.identifier()).$param") } [void] Setter ($param, $val) { if ($val -is [Boolean]) { - Param_Set -PARAM "$($this.identifier()).$param" -Value $(if ($val) { 1 } else { 0 }) + $this.remote.Setter("$($this.identifier()).$param", $(if ($val) { 1 } else { 0 })) } else { - Param_Set -PARAM "$($this.identifier()).$param" -Value $val + $this.remote.Setter("$($this.identifier()).$param", $val) } } } diff --git a/lib/strip.ps1 b/lib/strip.ps1 index 398e0d3..fcbb301 100644 --- a/lib/strip.ps1 +++ b/lib/strip.ps1 @@ -14,15 +14,15 @@ class IStrip { } [single] Getter ($param) { - return Param_Get -PARAM "$($this.identifier()).$param" -IS_STRING $false + return $this.remote.Getter("$($this.identifier()).$param") } [string] Getter_String ($param) { - return Param_Get -PARAM "$($this.identifier()).$param" -IS_STRING $true + return $this.remote.Getter_String("$($this.identifier()).$param") } [void] Setter ($param, $val) { - Param_Set -PARAM "$($this.identifier()).$param" -Value $val + $this.remote.Setter("$($this.identifier()).$param", $val) } } diff --git a/lib/vban.ps1 b/lib/vban.ps1 index d1c3a8f..3ac5e87 100644 --- a/lib/vban.ps1 +++ b/lib/vban.ps1 @@ -1,9 +1,11 @@ class IVban { [int32]$index + [Object]$remote [string]$direction - IVban ([int]$index, [string]$direction) { + IVban ([int]$index, [Object]$remote, [string]$direction) { $this.index = $index + $this.remote = $remote $this.direction = $direction } @@ -16,20 +18,20 @@ class IVban { } [single] Getter ($param) { - return Param_Get -PARAM "$($this.identifier()).$param" -IS_STRING $false + return $this.remote.Getter("$($this.identifier()).$param") } [string] Getter_String ($param) { - return Param_Get -PARAM "$($this.identifier()).$param" -IS_STRING $true + return $this.remote.Getter_String("$($this.identifier()).$param") } [void] Setter ($param, $val) { - Param_Set -PARAM "$($this.identifier()).$param" -Value $val + $this.remote.Setter("$($this.identifier()).$param", $val) } } class Vban : IVban { - Vban ([int]$index, [string]$direction) : base ($index, $direction) { + Vban ([int]$index, [Object]$remote, [string]$direction) : base ($index, $remote, $direction) { } hidden $_on = $($this | Add-Member ScriptProperty 'on' ` @@ -173,13 +175,13 @@ class Vban : IVban { class VbanInstream : Vban { - VbanInstream ([int]$index, [string]$direction) : base ($index, $direction) { + VbanInstream ([int]$index, [Object]$remote, [string]$direction) : base ($index, $remote, $direction) { } } class VbanOutstream : Vban { - VbanOutstream ([int]$index, [string]$direction) : base ($index, $direction) { + VbanOutstream ([int]$index, [Object]$remote, [string]$direction) : base ($index, $remote, $direction) { } } @@ -189,10 +191,10 @@ function Make_Vban ([Object]$remote) { [System.Collections.ArrayList]$outstream = @() 0..$($remote.kind.vban_in - 1) | ForEach-Object { - [void]$instream.Add([VbanInstream]::new($_, "in")) + [void]$instream.Add([VbanInstream]::new($_, $remote, "in")) } 0..$($remote.kind.vban_out - 1) | ForEach-Object { - [void]$outstream.Add([VbanOutstream]::new($_, "out")) + [void]$outstream.Add([VbanOutstream]::new($_, $remote, "out")) } $CustomObject = [pscustomobject]@{