mirror of
https://github.com/onyx-and-iris/voicemeeter-api-powershell.git
synced 2025-01-18 13:20:47 +00:00
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:
parent
84d31d3d61
commit
8e03c4e53b
22
lib/bus.ps1
22
lib/bus.ps1
@ -2,26 +2,28 @@
|
|||||||
|
|
||||||
class Bus {
|
class Bus {
|
||||||
[Int]$id
|
[Int]$id
|
||||||
[Array]$bool_params
|
|
||||||
[Array]$float_params
|
|
||||||
|
|
||||||
# Constructor
|
# Constructor
|
||||||
Bus ([Int]$id)
|
Bus ([Int]$id)
|
||||||
{
|
{
|
||||||
$this.id = $id
|
$this.id = $id
|
||||||
$this.bool_params = @('mono', 'mute')
|
|
||||||
$this.float_params = @('gain')
|
AddBoolMembers -PARAMS @('mono', 'mute')
|
||||||
AddPublicMembers($this)
|
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) {
|
[void] Setter($cmd, $set) {
|
||||||
Param_Set -PARAM $cmd -VALUE $set
|
Param_Set -PARAM $cmd -VALUE $set
|
||||||
}
|
}
|
||||||
|
|
||||||
[Single] Getter($cmd) {
|
|
||||||
return Param_Get -PARAM $cmd
|
|
||||||
}
|
|
||||||
|
|
||||||
[string] cmd ($arg) {
|
[string] cmd ($arg) {
|
||||||
return "Bus[" + $this.id + "].$arg"
|
return "Bus[" + $this.id + "].$arg"
|
||||||
}
|
}
|
||||||
@ -47,7 +49,7 @@ class VirtualBus : Bus {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Function Buses {
|
Function Make_Buses {
|
||||||
[System.Collections.ArrayList]$bus = @()
|
[System.Collections.ArrayList]$bus = @()
|
||||||
0..$($layout.p_out + $layout.v_out -1) | ForEach-Object {
|
0..$($layout.p_out + $layout.v_out -1) | ForEach-Object {
|
||||||
if ($_ -lt $layout.p_out) { [void]$bus.Add([PhysicalBus]::new($_)) }
|
if ($_ -lt $layout.p_out) { [void]$bus.Add([PhysicalBus]::new($_)) }
|
||||||
|
@ -1,25 +1,10 @@
|
|||||||
|
. $PSScriptRoot\meta.ps1
|
||||||
|
|
||||||
class Special {
|
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
|
# Constructor
|
||||||
Special()
|
Special()
|
||||||
{
|
{
|
||||||
$this.AddPublicMembers(@('restart', 'shutdown', 'show'))
|
AddCommandMembers -PARAMS @('restart', 'shutdown', 'show')
|
||||||
}
|
}
|
||||||
|
|
||||||
[String] Getter($param) {
|
[String] Getter($param) {
|
||||||
|
@ -7,14 +7,14 @@ class MacroButton {
|
|||||||
$this.id = $id
|
$this.id = $id
|
||||||
}
|
}
|
||||||
|
|
||||||
[void] Setter($set, $mode) {
|
|
||||||
MB_Set -ID $this.id -SET $set -MODE $mode
|
|
||||||
}
|
|
||||||
|
|
||||||
[int] Getter($mode) {
|
[int] Getter($mode) {
|
||||||
return MB_Get -ID $this.id -MODE $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' `
|
hidden $_state = $($this | Add-Member ScriptProperty 'state' `
|
||||||
{
|
{
|
||||||
$this.Getter(1)
|
$this.Getter(1)
|
||||||
@ -46,7 +46,7 @@ class MacroButton {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
Function Buttons {
|
Function Make_Buttons {
|
||||||
[System.Collections.ArrayList]$button = @()
|
[System.Collections.ArrayList]$button = @()
|
||||||
0..69 | ForEach-Object {
|
0..69 | ForEach-Object {
|
||||||
[void]$button.Add([MacroButton]::new($_))
|
[void]$button.Add([MacroButton]::new($_))
|
||||||
|
62
lib/meta.ps1
62
lib/meta.ps1
@ -1,16 +1,25 @@
|
|||||||
Function AddPublicMembers($obj) {
|
Function AddBoolMembers() {
|
||||||
|
param(
|
||||||
|
[String[]]$PARAMS
|
||||||
|
)
|
||||||
[HashTable]$Signatures = @{}
|
[HashTable]$Signatures = @{}
|
||||||
ForEach($param in $obj.bool_params) {
|
ForEach($param in $PARAMS) {
|
||||||
# Define getter
|
# Define getter
|
||||||
$Signatures["Getter"] = "`$this.Getter(`$this.cmd('{0}'))" -f $param
|
$Signatures["Getter"] = "[bool]`$this.Getter(`$this.cmd('{0}'))" -f $param
|
||||||
# Define setter
|
# 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
|
-f $param
|
||||||
|
|
||||||
Addmember
|
Addmember
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ForEach($param in $obj.float_params) {
|
Function AddFloatMembers() {
|
||||||
|
param(
|
||||||
|
[String[]]$PARAMS
|
||||||
|
)
|
||||||
|
[HashTable]$Signatures = @{}
|
||||||
|
ForEach($param in $PARAMS) {
|
||||||
# Define getter
|
# Define getter
|
||||||
$Signatures["Getter"] = "[math]::Round(`$this.Getter(`$this.cmd('{0}')), 1)" -f $param
|
$Signatures["Getter"] = "[math]::Round(`$this.Getter(`$this.cmd('{0}')), 1)" -f $param
|
||||||
# Define setter
|
# Define setter
|
||||||
@ -19,8 +28,14 @@ Function AddPublicMembers($obj) {
|
|||||||
|
|
||||||
Addmember
|
Addmember
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ForEach($param in $obj.int_params) {
|
Function AddIntMembers() {
|
||||||
|
param(
|
||||||
|
[String[]]$PARAMS
|
||||||
|
)
|
||||||
|
[HashTable]$Signatures = @{}
|
||||||
|
ForEach($param in $PARAMS) {
|
||||||
# Define getter
|
# Define getter
|
||||||
$Signatures["Getter"] = "[Int]`$this.Getter(`$this.cmd('{0}'))" -f $param
|
$Signatures["Getter"] = "[Int]`$this.Getter(`$this.cmd('{0}'))" -f $param
|
||||||
# Define setter
|
# Define setter
|
||||||
@ -29,8 +44,14 @@ Function AddPublicMembers($obj) {
|
|||||||
|
|
||||||
Addmember
|
Addmember
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ForEach($param in $obj.string_params) {
|
Function AddStringMembers() {
|
||||||
|
param(
|
||||||
|
[String[]]$PARAMS
|
||||||
|
)
|
||||||
|
[HashTable]$Signatures = @{}
|
||||||
|
ForEach($param in $PARAMS) {
|
||||||
# Define getter
|
# Define getter
|
||||||
$Signatures["Getter"] = "[String]`$this.Getter_String(`$this.cmd('{0}'))" -f $param
|
$Signatures["Getter"] = "[String]`$this.Getter_String(`$this.cmd('{0}'))" -f $param
|
||||||
# Define setter
|
# Define setter
|
||||||
@ -41,6 +62,33 @@ Function AddPublicMembers($obj) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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{
|
Function Addmember{
|
||||||
$AddMemberParams = @{
|
$AddMemberParams = @{
|
||||||
Name = $param
|
Name = $param
|
||||||
@ -48,5 +96,5 @@ Function Addmember{
|
|||||||
Value = [ScriptBlock]::Create($Signatures["Getter"])
|
Value = [ScriptBlock]::Create($Signatures["Getter"])
|
||||||
SecondValue = [ScriptBlock]::Create($Signatures["Setter"])
|
SecondValue = [ScriptBlock]::Create($Signatures["Setter"])
|
||||||
}
|
}
|
||||||
$obj | Add-Member @AddMemberParams
|
$this | Add-Member @AddMemberParams
|
||||||
}
|
}
|
||||||
|
@ -2,46 +2,30 @@
|
|||||||
|
|
||||||
class Strip {
|
class Strip {
|
||||||
[Int]$id
|
[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
|
# Constructor
|
||||||
Strip ([Int]$id, [Int]$num_A, [Int]$num_B)
|
Strip ([Int]$id)
|
||||||
{
|
{
|
||||||
$this.id = $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) {
|
AddChannelMembers
|
||||||
if( $this.string_params.Contains($cmd.Split('.')[1]) ) {
|
|
||||||
Param_Set_String -PARAM $cmd -VALUE $set
|
|
||||||
}
|
|
||||||
else { Param_Set -PARAM $cmd -VALUE $set }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Single] Getter($cmd) {
|
[Single] Getter($cmd) {
|
||||||
return Param_Get -PARAM $cmd
|
return Param_Get -PARAM $cmd -IS_STRING $false
|
||||||
}
|
}
|
||||||
|
|
||||||
[String] Getter_String($cmd) {
|
[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) {
|
[String] cmd ($arg) {
|
||||||
@ -59,7 +43,7 @@ class Strip {
|
|||||||
|
|
||||||
hidden $_sr = $($this | Add-Member ScriptProperty 'sr' `
|
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")
|
return Write-Warning("ERROR: " + $this.cmd('device.sr') + " is read only")
|
||||||
@ -68,23 +52,23 @@ class Strip {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class PhysicalStrip : 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 {
|
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 = @()
|
[System.Collections.ArrayList]$strip = @()
|
||||||
0..$($layout.p_in + $layout.v_in - 1) | ForEach-Object {
|
0..$($layout.p_in + $layout.v_in - 1) | ForEach-Object {
|
||||||
if ($_ -lt $layout.p_in) {
|
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
|
$strip
|
||||||
}
|
}
|
||||||
|
19
lib/vban.ps1
19
lib/vban.ps1
@ -1,28 +1,23 @@
|
|||||||
class Vban {
|
class Vban {
|
||||||
[int32]$id
|
[int32]$id
|
||||||
[String]$direction
|
[String]$direction
|
||||||
[Array]$stringparams
|
|
||||||
|
|
||||||
# Constructor
|
# Constructor
|
||||||
Vban($id)
|
Vban($id)
|
||||||
{
|
{
|
||||||
$this.id = $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) {
|
[Single] Getter($cmd) {
|
||||||
return Param_Get -PARAM $cmd
|
return Param_Get -PARAM $cmd -IS_STRING $false
|
||||||
}
|
}
|
||||||
|
|
||||||
[String] Getter_String($cmd) {
|
[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) {
|
[String] cmd ($arg) {
|
||||||
@ -185,7 +180,7 @@ class VbanOutstream : Vban {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Function Vban {
|
Function Make_Vban {
|
||||||
[System.Collections.ArrayList]$instream = @()
|
[System.Collections.ArrayList]$instream = @()
|
||||||
[System.Collections.ArrayList]$outstream = @()
|
[System.Collections.ArrayList]$outstream = @()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user