Update vban.ps1

- vban.port
- on -> AddBoolMembers
- name, ip -> AddStringMembers
- cast getters to types
- correct read-only/write-only
- correct route range
This commit is contained in:
pblivingston 2025-11-28 03:18:44 -05:00
parent b92a2422a7
commit 90e9dcd06c

View File

@ -3,48 +3,21 @@ class Vban : IRemote {
Vban ([int]$index, [Object]$remote, [string]$direction) : base ($index, $remote) { Vban ([int]$index, [Object]$remote, [string]$direction) : base ($index, $remote) {
$this.direction = $direction $this.direction = $direction
AddBoolMembers -PARAMS @('on')
AddStringMembers -PARAMS @('name', 'ip')
} }
[string] identifier () { [string] identifier () {
return 'vban.' + $this.direction + 'stream[' + $this.index + ']' return 'vban.' + $this.direction + 'stream[' + $this.index + ']'
} }
hidden $_on = $($this | Add-Member ScriptProperty 'on' `
{
$this.Getter('on')
} `
{
param([bool]$arg)
$this._on = $this.Setter('on', $arg)
}
)
hidden $_name = $($this | Add-Member ScriptProperty 'name' `
{
$this.Getter_String('name')
} `
{
param([string]$arg)
$this._name = $this.Setter('name', $arg)
}
)
hidden $_ip = $($this | Add-Member ScriptProperty 'ip' `
{
$this.Getter_String('ip')
} `
{
param([string]$arg)
$this._ip = $this.Setter('ip', $arg)
}
)
hidden $_port = $($this | Add-Member ScriptProperty 'port' ` hidden $_port = $($this | Add-Member ScriptProperty 'port' `
{ {
$this.Getter('port') [int]$this.Getter('port')
} ` } `
{ {
param([string]$arg) param([int]$arg)
if ($arg -ge 1024 -and $arg -le 65535) { if ($arg -ge 1024 -and $arg -le 65535) {
$this._port = $this.Setter('port', $arg) $this._port = $this.Setter('port', $arg)
} }
@ -56,7 +29,7 @@ class Vban : IRemote {
hidden $_sr = $($this | Add-Member ScriptProperty 'sr' ` hidden $_sr = $($this | Add-Member ScriptProperty 'sr' `
{ {
$this.Getter('sr') [int]$this.Getter('sr')
} ` } `
{ {
param([int]$arg) param([int]$arg)
@ -64,7 +37,7 @@ class Vban : IRemote {
else { else {
$opts = @(11025, 16000, 22050, 24000, 32000, 44100, 48000, 64000, 88200, 96000) $opts = @(11025, 16000, 22050, 24000, 32000, 44100, 48000, 64000, 88200, 96000)
if ($opts.Contains($arg)) { if ($opts.Contains($arg)) {
$this._port = $this.Setter('sr', $arg) $this._sr = $this.Setter('sr', $arg)
} }
else { else {
Write-Warning ('Expected one of', $opts) Write-Warning ('Expected one of', $opts)
@ -75,7 +48,7 @@ class Vban : IRemote {
hidden $_channel = $($this | Add-Member ScriptProperty 'channel' ` hidden $_channel = $($this | Add-Member ScriptProperty 'channel' `
{ {
$this.Getter('channel') [int]$this.Getter('channel')
} ` } `
{ {
param([int]$arg) param([int]$arg)
@ -113,12 +86,10 @@ class Vban : IRemote {
hidden $_quality = $($this | Add-Member ScriptProperty 'quality' ` hidden $_quality = $($this | Add-Member ScriptProperty 'quality' `
{ {
$this.Getter('quality') [int]$this.Getter('quality')
} ` } `
{ {
param([int]$arg) param([int]$arg)
if ($this.direction -eq 'in') { Write-Warning ('Error, read only value') }
else {
if ($arg -ge 0 -and $arg -le 4) { if ($arg -ge 0 -and $arg -le 4) {
$this._quality = $this.Setter('quality', $arg) $this._quality = $this.Setter('quality', $arg)
} }
@ -126,23 +97,20 @@ class Vban : IRemote {
Write-Warning ('Expected value from 0 to 4') Write-Warning ('Expected value from 0 to 4')
} }
} }
}
) )
hidden $_route = $($this | Add-Member ScriptProperty 'route' ` hidden $_route = $($this | Add-Member ScriptProperty 'route' `
{ {
$this.Getter('route') [int]$this.Getter('route')
} ` } `
{ {
param([int]$arg) param([int]$arg)
if ($this.direction -eq 'in') { Write-Warning ('Error, read only value') } $rt = $this.remote.kind['p_' + $this.direction] + $this.remote.kind['v_' + $this.direction] - 1
else { if ($arg -ge 0 -and $arg -le $rt) {
if ($arg -ge 0 -and $arg -le 8) {
$this._route = $this.Setter('route', $arg) $this._route = $this.Setter('route', $arg)
} }
else { else {
Write-Warning ('Expected value from 0 to 8') Write-Warning ("Expected value from 0 to $rt")
}
} }
} }
) )
@ -179,11 +147,25 @@ function Make_Vban ([Object]$remote) {
$CustomObject | Add-Member ScriptProperty 'enable' ` $CustomObject | Add-Member ScriptProperty 'enable' `
{ {
return Write-Warning ('ERROR: vban.enable is write only') return [bool]( Param_Get -PARAM 'vban.enable' )
} ` } `
{ {
param([bool]$arg) param([bool]$arg)
Param_Set -PARAM 'vban.Enable' -Value $(if ($arg) { 1 } else { 0 }) Param_Set -PARAM 'vban.enable' -Value $(if ($arg) { 1 } else { 0 })
}
$CustomObject | Add-Member ScriptProperty 'port' `
{
return [int]( Param_Get -PARAM 'vban.instream[0].port' )
} `
{
param([int]$arg)
if ($arg -ge 1024 -and $arg -le 65535) {
Param_Set -PARAM 'vban.instream[0].port' -Value $arg
}
else {
Write-Warning ('Expected value from 1024 to 65535')
}
} }
$CustomObject $CustomObject