From 3c978f14894b0cdfb44d21e721f0c33caa4819c1 Mon Sep 17 00:00:00 2001 From: onyx-and-iris <75868496+onyx-and-iris@users.noreply.github.com> Date: Thu, 6 Jan 2022 15:26:38 +0000 Subject: [PATCH] Update bus.ps1 eq property added. addpublicmembers removed. --- lib/bus.ps1 | 46 +++++++++++++--------------------------------- 1 file changed, 13 insertions(+), 33 deletions(-) diff --git a/lib/bus.ps1 b/lib/bus.ps1 index 01c25e9..298a2a3 100644 --- a/lib/bus.ps1 +++ b/lib/bus.ps1 @@ -1,47 +1,17 @@ +. $PSScriptRoot\meta.ps1 + class Bus { [int32]$id [Array]$bool_params [Array]$float_params - hidden AddPublicMembers() { - [HashTable]$Signatures = @{} - @($this.bool_params, $this.float_params) | ForEach-Object { - ForEach($param in $_) { - if($this.bool_params.Contains($param)) { - # Define getter - $Signatures["Getter"] = "`$this.Getter(`$this.cmd('{0}'))" -f $param - # Define setter - $Signatures["Setter"] = "param ( [Single]`$arg )`n`$this.Setter(`$this.cmd('{0}'), `$arg)" ` - -f $param - } - elseif($this.float_params.Contains($param)) { - # Define getter - $Signatures["Getter"] = "[math]::Round(`$this.Getter(`$this.cmd('{0}')), 1)" -f $param - # Define setter - $Signatures["Setter"] = "param ( [Single]`$arg )`n`$this.Setter(`$this.cmd('{0}'), `$arg)" ` - -f $param - } - - $GetterScriptBlock = [ScriptBlock]::Create($Signatures["Getter"]) - $SetterScriptBlock = [ScriptBlock]::Create($Signatures["Setter"]) - $AddMemberParams = @{ - Name = $param - MemberType = 'ScriptProperty' - Value = $GetterScriptBlock - SecondValue = $SetterScriptBlock - } - $this | Add-Member @AddMemberParams - } - } - } - # Constructor Bus ([Int]$id) { $this.id = $id $this.bool_params = @('mono', 'mute') $this.float_params = @('gain') - $this.AddPublicMembers() + AddPublicMembers($this) } [void] Setter($cmd, $set) { @@ -55,6 +25,16 @@ class Bus { [string] cmd ($arg) { return "Bus[" + $this.id + "].$arg" } + + hidden $_eq = $($this | Add-Member ScriptProperty 'eq' ` + { + $this.Getter($this.cmd('EQ.on')) + }` + { + param ( $arg ) + $this._eq = $this.Setter($this.cmd('EQ.on'), $arg) + } + ) } Function Buses {