update to class getters/setters and meta module

rename factory functions.

class getters now send is_string parameter.

each property type for each class now has separate meta function.
This commit is contained in:
onyx-and-iris 2022-01-19 21:52:59 +00:00
parent 84d31d3d61
commit 8e03c4e53b
6 changed files with 101 additions and 87 deletions

View File

@ -2,26 +2,28 @@
class Bus {
[Int]$id
[Array]$bool_params
[Array]$float_params
# Constructor
Bus ([Int]$id)
{
$this.id = $id
$this.bool_params = @('mono', 'mute')
$this.float_params = @('gain')
AddPublicMembers($this)
AddBoolMembers -PARAMS @('mono', 'mute')
AddFloatMembers -PARAMS @('gain')
}
[Single] Getter($cmd) {
return Param_Get -PARAM $cmd -IS_STRING $false
}
[String] Getter_String($cmd) {
return Param_Get -PARAM $cmd -IS_STRING $true
}
[void] Setter($cmd, $set) {
Param_Set -PARAM $cmd -VALUE $set
}
[Single] Getter($cmd) {
return Param_Get -PARAM $cmd
}
[string] cmd ($arg) {
return "Bus[" + $this.id + "].$arg"
}
@ -47,7 +49,7 @@ class VirtualBus : Bus {
}
}
Function Buses {
Function Make_Buses {
[System.Collections.ArrayList]$bus = @()
0..$($layout.p_out + $layout.v_out -1) | ForEach-Object {
if ($_ -lt $layout.p_out) { [void]$bus.Add([PhysicalBus]::new($_)) }

View File

@ -1,25 +1,10 @@
. $PSScriptRoot\meta.ps1
class Special {
hidden AddPublicMembers($commands) {
$commands | ForEach-Object {
# Define getter
$GetterSignature = "`$this.Getter(`$this.cmd('{0}'))" -f $_
# Define setter
$SetterSignature = "`$this.Setter(`$this.cmd('{0}'))" -f $_
$AddMemberParams = @{
Name = $_
MemberType = 'ScriptProperty'
Value = [ScriptBlock]::Create($SetterSignature)
SecondValue = [ScriptBlock]::Create($GetterSignature)
}
$this | Add-Member @AddMemberParams
}
}
# Constructor
Special()
{
$this.AddPublicMembers(@('restart', 'shutdown', 'show'))
AddCommandMembers -PARAMS @('restart', 'shutdown', 'show')
}
[String] Getter($param) {

View File

@ -7,14 +7,14 @@ class MacroButton {
$this.id = $id
}
[void] Setter($set, $mode) {
MB_Set -ID $this.id -SET $set -MODE $mode
}
[int] Getter($mode) {
return MB_Get -ID $this.id -MODE $mode
}
[void] Setter($set, $mode) {
MB_Set -ID $this.id -SET $set -MODE $mode
}
hidden $_state = $($this | Add-Member ScriptProperty 'state' `
{
$this.Getter(1)
@ -46,7 +46,7 @@ class MacroButton {
)
}
Function Buttons {
Function Make_Buttons {
[System.Collections.ArrayList]$button = @()
0..69 | ForEach-Object {
[void]$button.Add([MacroButton]::new($_))

View File

@ -1,16 +1,25 @@
Function AddPublicMembers($obj) {
Function AddBoolMembers() {
param(
[String[]]$PARAMS
)
[HashTable]$Signatures = @{}
ForEach($param in $obj.bool_params) {
ForEach($param in $PARAMS) {
# Define getter
$Signatures["Getter"] = "`$this.Getter(`$this.cmd('{0}'))" -f $param
$Signatures["Getter"] = "[bool]`$this.Getter(`$this.cmd('{0}'))" -f $param
# Define setter
$Signatures["Setter"] = "param ( [Single]`$arg )`n`$this.Setter(`$this.cmd('{0}'), `$arg)" `
-f $param
Addmember
}
}
ForEach($param in $obj.float_params) {
Function AddFloatMembers() {
param(
[String[]]$PARAMS
)
[HashTable]$Signatures = @{}
ForEach($param in $PARAMS) {
# Define getter
$Signatures["Getter"] = "[math]::Round(`$this.Getter(`$this.cmd('{0}')), 1)" -f $param
# Define setter
@ -19,8 +28,14 @@ Function AddPublicMembers($obj) {
Addmember
}
ForEach($param in $obj.int_params) {
}
Function AddIntMembers() {
param(
[String[]]$PARAMS
)
[HashTable]$Signatures = @{}
ForEach($param in $PARAMS) {
# Define getter
$Signatures["Getter"] = "[Int]`$this.Getter(`$this.cmd('{0}'))" -f $param
# Define setter
@ -29,18 +44,51 @@ Function AddPublicMembers($obj) {
Addmember
}
}
ForEach($param in $obj.string_params) {
Function AddStringMembers() {
param(
[String[]]$PARAMS
)
[HashTable]$Signatures = @{}
ForEach($param in $PARAMS) {
# Define getter
$Signatures["Getter"] = "[String]`$this.Getter_String(`$this.cmd('{0}'))" -f $param
# Define setter
$Signatures["Setter"] = "param ( [String]`$arg )`n`$this.Setter(`$this.cmd('{0}'), `$arg)" `
-f $param
Addmember
}
}
Function AddCommandMembers() {
param(
[String[]]$PARAMS
)
[HashTable]$Signatures = @{}
ForEach($param in $PARAMS) {
# Define getter
$Signatures["Getter"] = "`$this.Getter(`$this.cmd('{0}'))" -f $_
# Define setter
$Signatures["Setter"] = "`$this.Setter(`$this.cmd('{0}'))" -f $_
Addmember
}
}
Function AddChannelMembers() {
$num_A = $layout.p_out
$num_B = $layout.v_out
[System.Collections.ArrayList]$channels = @()
1..$($num_A + $num_B) | ForEach-Object {
if($_ -le $num_A) {$channels.Add("A{0}" -f $_)} else {$channels.Add("B{0}" -f $($_ - $num_A))}
}
AddBoolMembers -PARAMS $channels
}
Function Addmember{
$AddMemberParams = @{
Name = $param
@ -48,5 +96,5 @@ Function Addmember{
Value = [ScriptBlock]::Create($Signatures["Getter"])
SecondValue = [ScriptBlock]::Create($Signatures["Setter"])
}
$obj | Add-Member @AddMemberParams
$this | Add-Member @AddMemberParams
}

View File

@ -2,46 +2,30 @@
class Strip {
[Int]$id
[Array]$string_params
[Array]$float_params
[System.Collections.ArrayList]$bool_params
[Array]$int_params
hidden SetChannelLayout($num_A, $num_B) {
1..$num_A | ForEach-Object {
$this.bool_params.Add("A{0}" -f $_)
}
1..$num_B | ForEach-Object {
$this.bool_params.Add("B{0}" -f $_)
}
}
# Constructor
Strip ([Int]$id, [Int]$num_A, [Int]$num_B)
Strip ([Int]$id)
{
$this.id = $id
$this.string_params = @('label')
$this.float_params = @('gain', 'comp', 'gate')
$this.int_params = @('limit')
$this.bool_params = @('mono', 'solo', 'mute')
$this.SetChannelLayout($num_A, $num_B)
AddPublicMembers($this)
}
AddBoolMembers -PARAMS @('mono', 'solo', 'mute')
AddFloatMembers -PARAMS @('gain', 'comp', 'gate')
AddIntMembers -PARAMS @('limit')
AddStringMembers -PARAMS @('label')
[void] Setter($cmd, $set) {
if( $this.string_params.Contains($cmd.Split('.')[1]) ) {
Param_Set_String -PARAM $cmd -VALUE $set
}
else { Param_Set -PARAM $cmd -VALUE $set }
AddChannelMembers
}
[Single] Getter($cmd) {
return Param_Get -PARAM $cmd
return Param_Get -PARAM $cmd -IS_STRING $false
}
[String] Getter_String($cmd) {
return Param_Get_String -PARAM $cmd
return Param_Get -PARAM $cmd -IS_STRING $true
}
[void] Setter($cmd, $set) {
Param_Set -PARAM $cmd -VALUE $set
}
[String] cmd ($arg) {
@ -59,7 +43,7 @@ class Strip {
hidden $_sr = $($this | Add-Member ScriptProperty 'sr' `
{
$this.Getter_String($this.cmd('device.sr'))
$this.Getter($this.cmd('device.sr'))
}`
{
return Write-Warning("ERROR: " + $this.cmd('device.sr') + " is read only")
@ -68,23 +52,23 @@ class Strip {
}
class PhysicalStrip : Strip {
PhysicalStrip ([Int]$id, [Int]$num_A, [Int]$num_B) : base ($id, $num_A, $num_B) {
PhysicalStrip ([Int]$id) : base ($id) {
}
}
class VirtualStrip : Strip {
VirtualStrip ([Int]$id, [Int]$num_A, [Int]$num_B) : base ($id, $num_A, $num_B) {
VirtualStrip ([Int]$id) : base ($id) {
}
}
Function Strips {
Function Make_Strips {
[System.Collections.ArrayList]$strip = @()
0..$($layout.p_in + $layout.v_in - 1) | ForEach-Object {
if ($_ -lt $layout.p_in) {
[void]$strip.Add([PhysicalStrip]::new($_, $layout.p_out, $layout.v_out))
[void]$strip.Add([PhysicalStrip]::new($_))
}
else { [void]$strip.Add([VirtualStrip]::new($_, $layout.p_out, $layout.v_out)) }
else { [void]$strip.Add([VirtualStrip]::new($_)) }
}
$strip
}

View File

@ -1,28 +1,23 @@
class Vban {
[int32]$id
[String]$direction
[Array]$stringparams
# Constructor
Vban($id)
{
$this.id = $id
$this.stringparams = @('name', 'ip')
}
[void] Setter($cmd, $set) {
if( $this.stringparams.Contains($cmd.Split('.')[2]) ) {
Param_Set_String -PARAM $cmd -VALUE $set
}
else { Param_Set -PARAM $cmd -VALUE $set }
}
[Single] Getter($cmd) {
return Param_Get -PARAM $cmd
return Param_Get -PARAM $cmd -IS_STRING $false
}
[String] Getter_String($cmd) {
return Param_Get_String -PARAM $cmd
return Param_Get -PARAM $cmd -IS_STRING $true
}
[void] Setter($cmd, $set) {
Param_Set -PARAM $cmd -VALUE $set
}
[String] cmd ($arg) {
@ -185,7 +180,7 @@ class VbanOutstream : Vban {
}
Function Vban {
Function Make_Vban {
[System.Collections.ArrayList]$instream = @()
[System.Collections.ArrayList]$outstream = @()